lottie.min.js 575 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. const svgNS = 'http://www.w3.org/2000/svg';
  4. let locationHref = '';
  5. let _useWebWorker = false;
  6. const initialDefaultFrame = -999999;
  7. const setWebWorker = (flag) => { _useWebWorker = !!flag; };
  8. const getWebWorker = () => _useWebWorker;
  9. const setLocationHref = (value) => { locationHref = value; };
  10. const getLocationHref = () => locationHref;
  11. function createTag(type) {
  12. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  13. return document.createElement(type);
  14. }
  15. function extendPrototype(sources, destination) {
  16. var i;
  17. var len = sources.length;
  18. var sourcePrototype;
  19. for (i = 0; i < len; i += 1) {
  20. sourcePrototype = sources[i].prototype;
  21. for (var attr in sourcePrototype) {
  22. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  23. }
  24. }
  25. }
  26. function getDescriptor(object, prop) {
  27. return Object.getOwnPropertyDescriptor(object, prop);
  28. }
  29. function createProxyFunction(prototype) {
  30. function ProxyFunction() {}
  31. ProxyFunction.prototype = prototype;
  32. return ProxyFunction;
  33. }
  34. // import Howl from '../../3rd_party/howler';
  35. const audioControllerFactory = (function () {
  36. function AudioController(audioFactory) {
  37. this.audios = [];
  38. this.audioFactory = audioFactory;
  39. this._volume = 1;
  40. this._isMuted = false;
  41. }
  42. AudioController.prototype = {
  43. addAudio: function (audio) {
  44. this.audios.push(audio);
  45. },
  46. pause: function () {
  47. var i;
  48. var len = this.audios.length;
  49. for (i = 0; i < len; i += 1) {
  50. this.audios[i].pause();
  51. }
  52. },
  53. resume: function () {
  54. var i;
  55. var len = this.audios.length;
  56. for (i = 0; i < len; i += 1) {
  57. this.audios[i].resume();
  58. }
  59. },
  60. setRate: function (rateValue) {
  61. var i;
  62. var len = this.audios.length;
  63. for (i = 0; i < len; i += 1) {
  64. this.audios[i].setRate(rateValue);
  65. }
  66. },
  67. createAudio: function (assetPath) {
  68. if (this.audioFactory) {
  69. return this.audioFactory(assetPath);
  70. } if (window.Howl) {
  71. return new window.Howl({
  72. src: [assetPath],
  73. });
  74. }
  75. return {
  76. isPlaying: false,
  77. play: function () { this.isPlaying = true; },
  78. seek: function () { this.isPlaying = false; },
  79. playing: function () {},
  80. rate: function () {},
  81. setVolume: function () {},
  82. };
  83. },
  84. setAudioFactory: function (audioFactory) {
  85. this.audioFactory = audioFactory;
  86. },
  87. setVolume: function (value) {
  88. this._volume = value;
  89. this._updateVolume();
  90. },
  91. mute: function () {
  92. this._isMuted = true;
  93. this._updateVolume();
  94. },
  95. unmute: function () {
  96. this._isMuted = false;
  97. this._updateVolume();
  98. },
  99. getVolume: function () {
  100. return this._volume;
  101. },
  102. _updateVolume: function () {
  103. var i;
  104. var len = this.audios.length;
  105. for (i = 0; i < len; i += 1) {
  106. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  107. }
  108. },
  109. };
  110. return function () {
  111. return new AudioController();
  112. };
  113. }());
  114. const createTypedArray = (function () {
  115. function createRegularArray(type, len) {
  116. var i = 0;
  117. var arr = [];
  118. var value;
  119. switch (type) {
  120. case 'int16':
  121. case 'uint8c':
  122. value = 1;
  123. break;
  124. default:
  125. value = 1.1;
  126. break;
  127. }
  128. for (i = 0; i < len; i += 1) {
  129. arr.push(value);
  130. }
  131. return arr;
  132. }
  133. function createTypedArrayFactory(type, len) {
  134. if (type === 'float32') {
  135. return new Float32Array(len);
  136. } if (type === 'int16') {
  137. return new Int16Array(len);
  138. } if (type === 'uint8c') {
  139. return new Uint8ClampedArray(len);
  140. }
  141. return createRegularArray(type, len);
  142. }
  143. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  144. return createTypedArrayFactory;
  145. }
  146. return createRegularArray;
  147. }());
  148. function createSizedArray(len) {
  149. return Array.apply(null, { length: len });
  150. }
  151. let subframeEnabled = true;
  152. let expressionsPlugin = null;
  153. let expressionsInterfaces = null;
  154. let idPrefix$1 = '';
  155. const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  156. let _shouldRoundValues = false;
  157. const bmPow = Math.pow;
  158. const bmSqrt = Math.sqrt;
  159. const bmFloor = Math.floor;
  160. const bmMax = Math.max;
  161. const bmMin = Math.min;
  162. const BMMath = {};
  163. (function () {
  164. 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'];
  165. var i;
  166. var len = propertyNames.length;
  167. for (i = 0; i < len; i += 1) {
  168. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  169. }
  170. }());
  171. function ProjectInterface$1() { return {}; }
  172. BMMath.random = Math.random;
  173. BMMath.abs = function (val) {
  174. var tOfVal = typeof val;
  175. if (tOfVal === 'object' && val.length) {
  176. var absArr = createSizedArray(val.length);
  177. var i;
  178. var len = val.length;
  179. for (i = 0; i < len; i += 1) {
  180. absArr[i] = Math.abs(val[i]);
  181. }
  182. return absArr;
  183. }
  184. return Math.abs(val);
  185. };
  186. let defaultCurveSegments = 150;
  187. const degToRads = Math.PI / 180;
  188. const roundCorner = 0.5519;
  189. function roundValues(flag) {
  190. _shouldRoundValues = !!flag;
  191. }
  192. function bmRnd(value) {
  193. if (_shouldRoundValues) {
  194. return Math.round(value);
  195. }
  196. return value;
  197. }
  198. function styleDiv(element) {
  199. element.style.position = 'absolute';
  200. element.style.top = 0;
  201. element.style.left = 0;
  202. element.style.display = 'block';
  203. element.style.transformOrigin = '0 0';
  204. element.style.webkitTransformOrigin = '0 0';
  205. element.style.backfaceVisibility = 'visible';
  206. element.style.webkitBackfaceVisibility = 'visible';
  207. element.style.transformStyle = 'preserve-3d';
  208. element.style.webkitTransformStyle = 'preserve-3d';
  209. element.style.mozTransformStyle = 'preserve-3d';
  210. }
  211. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  212. this.type = type;
  213. this.currentTime = currentTime;
  214. this.totalTime = totalTime;
  215. this.direction = frameMultiplier < 0 ? -1 : 1;
  216. }
  217. function BMCompleteEvent(type, frameMultiplier) {
  218. this.type = type;
  219. this.direction = frameMultiplier < 0 ? -1 : 1;
  220. }
  221. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  222. this.type = type;
  223. this.currentLoop = currentLoop;
  224. this.totalLoops = totalLoops;
  225. this.direction = frameMultiplier < 0 ? -1 : 1;
  226. }
  227. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  228. this.type = type;
  229. this.firstFrame = firstFrame;
  230. this.totalFrames = totalFrames;
  231. }
  232. function BMDestroyEvent(type, target) {
  233. this.type = type;
  234. this.target = target;
  235. }
  236. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  237. this.type = 'renderFrameError';
  238. this.nativeError = nativeError;
  239. this.currentTime = currentTime;
  240. }
  241. function BMConfigErrorEvent(nativeError) {
  242. this.type = 'configError';
  243. this.nativeError = nativeError;
  244. }
  245. function BMAnimationConfigErrorEvent(type, nativeError) {
  246. this.type = type;
  247. this.nativeError = nativeError;
  248. }
  249. const createElementID = (function () {
  250. var _count = 0;
  251. return function createID() {
  252. _count += 1;
  253. return idPrefix$1 + '__lottie_element_' + _count;
  254. };
  255. }());
  256. function HSVtoRGB(h, s, v) {
  257. var r;
  258. var g;
  259. var b;
  260. var i;
  261. var f;
  262. var p;
  263. var q;
  264. var t;
  265. i = Math.floor(h * 6);
  266. f = h * 6 - i;
  267. p = v * (1 - s);
  268. q = v * (1 - f * s);
  269. t = v * (1 - (1 - f) * s);
  270. switch (i % 6) {
  271. case 0: r = v; g = t; b = p; break;
  272. case 1: r = q; g = v; b = p; break;
  273. case 2: r = p; g = v; b = t; break;
  274. case 3: r = p; g = q; b = v; break;
  275. case 4: r = t; g = p; b = v; break;
  276. case 5: r = v; g = p; b = q; break;
  277. default: break;
  278. }
  279. return [r,
  280. g,
  281. b];
  282. }
  283. function RGBtoHSV(r, g, b) {
  284. var max = Math.max(r, g, b);
  285. var min = Math.min(r, g, b);
  286. var d = max - min;
  287. var h;
  288. var s = (max === 0 ? 0 : d / max);
  289. var v = max / 255;
  290. switch (max) {
  291. case min: h = 0; break;
  292. case r: h = (g - b) + d * (g < b ? 6 : 0); h /= 6 * d; break;
  293. case g: h = (b - r) + d * 2; h /= 6 * d; break;
  294. case b: h = (r - g) + d * 4; h /= 6 * d; break;
  295. default: break;
  296. }
  297. return [
  298. h,
  299. s,
  300. v,
  301. ];
  302. }
  303. function addSaturationToRGB(color, offset) {
  304. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  305. hsv[1] += offset;
  306. if (hsv[1] > 1) {
  307. hsv[1] = 1;
  308. } else if (hsv[1] <= 0) {
  309. hsv[1] = 0;
  310. }
  311. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  312. }
  313. function addBrightnessToRGB(color, offset) {
  314. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  315. hsv[2] += offset;
  316. if (hsv[2] > 1) {
  317. hsv[2] = 1;
  318. } else if (hsv[2] < 0) {
  319. hsv[2] = 0;
  320. }
  321. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  322. }
  323. function addHueToRGB(color, offset) {
  324. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  325. hsv[0] += offset / 360;
  326. if (hsv[0] > 1) {
  327. hsv[0] -= 1;
  328. } else if (hsv[0] < 0) {
  329. hsv[0] += 1;
  330. }
  331. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  332. }
  333. const rgbToHex = (function () {
  334. var colorMap = [];
  335. var i;
  336. var hex;
  337. for (i = 0; i < 256; i += 1) {
  338. hex = i.toString(16);
  339. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  340. }
  341. return function (r, g, b) {
  342. if (r < 0) {
  343. r = 0;
  344. }
  345. if (g < 0) {
  346. g = 0;
  347. }
  348. if (b < 0) {
  349. b = 0;
  350. }
  351. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  352. };
  353. }());
  354. const setSubframeEnabled = (flag) => { subframeEnabled = !!flag; };
  355. const getSubframeEnabled = () => subframeEnabled;
  356. const setExpressionsPlugin = (value) => { expressionsPlugin = value; };
  357. const getExpressionsPlugin = () => expressionsPlugin;
  358. const setExpressionInterfaces = (value) => { expressionsInterfaces = value; };
  359. const getExpressionInterfaces = () => expressionsInterfaces;
  360. const setDefaultCurveSegments = (value) => { defaultCurveSegments = value; };
  361. const getDefaultCurveSegments = () => defaultCurveSegments;
  362. const setIdPrefix = (value) => { idPrefix$1 = value; };
  363. const getIdPrefix = () => idPrefix$1;
  364. function createNS(type) {
  365. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  366. return document.createElementNS(svgNS, type);
  367. }
  368. const dataManager = (function () {
  369. var _counterId = 1;
  370. var processes = [];
  371. var workerFn;
  372. var workerInstance;
  373. var workerProxy = {
  374. onmessage: function () {
  375. },
  376. postMessage: function (path) {
  377. workerFn({
  378. data: path,
  379. });
  380. },
  381. };
  382. var _workerSelf = {
  383. postMessage: function (data) {
  384. workerProxy.onmessage({
  385. data: data,
  386. });
  387. },
  388. };
  389. function createWorker(fn) {
  390. if (window.Worker && window.Blob && getWebWorker()) {
  391. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  392. // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  393. var url = URL.createObjectURL(blob);
  394. return new Worker(url);
  395. }
  396. workerFn = fn;
  397. return workerProxy;
  398. }
  399. function setupWorker() {
  400. if (!workerInstance) {
  401. workerInstance = createWorker(function workerStart(e) {
  402. function dataFunctionManager() {
  403. function completeLayers(layers, comps) {
  404. var layerData;
  405. var i;
  406. var len = layers.length;
  407. var j;
  408. var jLen;
  409. var k;
  410. var kLen;
  411. for (i = 0; i < len; i += 1) {
  412. layerData = layers[i];
  413. if (('ks' in layerData) && !layerData.completed) {
  414. layerData.completed = true;
  415. if (layerData.hasMask) {
  416. var maskProps = layerData.masksProperties;
  417. jLen = maskProps.length;
  418. for (j = 0; j < jLen; j += 1) {
  419. if (maskProps[j].pt.k.i) {
  420. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  421. } else {
  422. kLen = maskProps[j].pt.k.length;
  423. for (k = 0; k < kLen; k += 1) {
  424. if (maskProps[j].pt.k[k].s) {
  425. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  426. }
  427. if (maskProps[j].pt.k[k].e) {
  428. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  429. }
  430. }
  431. }
  432. }
  433. }
  434. if (layerData.ty === 0) {
  435. layerData.layers = findCompLayers(layerData.refId, comps);
  436. completeLayers(layerData.layers, comps);
  437. } else if (layerData.ty === 4) {
  438. completeShapes(layerData.shapes);
  439. } else if (layerData.ty === 5) {
  440. completeText(layerData);
  441. }
  442. }
  443. }
  444. }
  445. function completeChars(chars, assets) {
  446. if (chars) {
  447. var i = 0;
  448. var len = chars.length;
  449. for (i = 0; i < len; i += 1) {
  450. if (chars[i].t === 1) {
  451. // var compData = findComp(chars[i].data.refId, assets);
  452. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
  453. // chars[i].data.ip = 0;
  454. // chars[i].data.op = 99999;
  455. // chars[i].data.st = 0;
  456. // chars[i].data.sr = 1;
  457. // chars[i].w = compData.w;
  458. // chars[i].data.ks = {
  459. // a: { k: [0, 0, 0], a: 0 },
  460. // p: { k: [0, -compData.h, 0], a: 0 },
  461. // r: { k: 0, a: 0 },
  462. // s: { k: [100, 100], a: 0 },
  463. // o: { k: 100, a: 0 },
  464. // };
  465. completeLayers(chars[i].data.layers, assets);
  466. }
  467. }
  468. }
  469. }
  470. function findComp(id, comps) {
  471. var i = 0;
  472. var len = comps.length;
  473. while (i < len) {
  474. if (comps[i].id === id) {
  475. return comps[i];
  476. }
  477. i += 1;
  478. }
  479. return null;
  480. }
  481. function findCompLayers(id, comps) {
  482. var comp = findComp(id, comps);
  483. if (comp) {
  484. if (!comp.layers.__used) {
  485. comp.layers.__used = true;
  486. return comp.layers;
  487. }
  488. return JSON.parse(JSON.stringify(comp.layers));
  489. }
  490. return null;
  491. }
  492. function completeShapes(arr) {
  493. var i;
  494. var len = arr.length;
  495. var j;
  496. var jLen;
  497. for (i = len - 1; i >= 0; i -= 1) {
  498. if (arr[i].ty === 'sh') {
  499. if (arr[i].ks.k.i) {
  500. convertPathsToAbsoluteValues(arr[i].ks.k);
  501. } else {
  502. jLen = arr[i].ks.k.length;
  503. for (j = 0; j < jLen; j += 1) {
  504. if (arr[i].ks.k[j].s) {
  505. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  506. }
  507. if (arr[i].ks.k[j].e) {
  508. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  509. }
  510. }
  511. }
  512. } else if (arr[i].ty === 'gr') {
  513. completeShapes(arr[i].it);
  514. }
  515. }
  516. }
  517. function convertPathsToAbsoluteValues(path) {
  518. var i;
  519. var len = path.i.length;
  520. for (i = 0; i < len; i += 1) {
  521. path.i[i][0] += path.v[i][0];
  522. path.i[i][1] += path.v[i][1];
  523. path.o[i][0] += path.v[i][0];
  524. path.o[i][1] += path.v[i][1];
  525. }
  526. }
  527. function checkVersion(minimum, animVersionString) {
  528. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  529. if (minimum[0] > animVersion[0]) {
  530. return true;
  531. } if (animVersion[0] > minimum[0]) {
  532. return false;
  533. }
  534. if (minimum[1] > animVersion[1]) {
  535. return true;
  536. } if (animVersion[1] > minimum[1]) {
  537. return false;
  538. }
  539. if (minimum[2] > animVersion[2]) {
  540. return true;
  541. } if (animVersion[2] > minimum[2]) {
  542. return false;
  543. }
  544. return null;
  545. }
  546. var checkText = (function () {
  547. var minimumVersion = [4, 4, 14];
  548. function updateTextLayer(textLayer) {
  549. var documentData = textLayer.t.d;
  550. textLayer.t.d = {
  551. k: [
  552. {
  553. s: documentData,
  554. t: 0,
  555. },
  556. ],
  557. };
  558. }
  559. function iterateLayers(layers) {
  560. var i;
  561. var len = layers.length;
  562. for (i = 0; i < len; i += 1) {
  563. if (layers[i].ty === 5) {
  564. updateTextLayer(layers[i]);
  565. }
  566. }
  567. }
  568. return function (animationData) {
  569. if (checkVersion(minimumVersion, animationData.v)) {
  570. iterateLayers(animationData.layers);
  571. if (animationData.assets) {
  572. var i;
  573. var len = animationData.assets.length;
  574. for (i = 0; i < len; i += 1) {
  575. if (animationData.assets[i].layers) {
  576. iterateLayers(animationData.assets[i].layers);
  577. }
  578. }
  579. }
  580. }
  581. };
  582. }());
  583. var checkChars = (function () {
  584. var minimumVersion = [4, 7, 99];
  585. return function (animationData) {
  586. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  587. var i;
  588. var len = animationData.chars.length;
  589. for (i = 0; i < len; i += 1) {
  590. var charData = animationData.chars[i];
  591. if (charData.data && charData.data.shapes) {
  592. completeShapes(charData.data.shapes);
  593. charData.data.ip = 0;
  594. charData.data.op = 99999;
  595. charData.data.st = 0;
  596. charData.data.sr = 1;
  597. charData.data.ks = {
  598. p: { k: [0, 0], a: 0 },
  599. s: { k: [100, 100], a: 0 },
  600. a: { k: [0, 0], a: 0 },
  601. r: { k: 0, a: 0 },
  602. o: { k: 100, a: 0 },
  603. };
  604. if (!animationData.chars[i].t) {
  605. charData.data.shapes.push(
  606. {
  607. ty: 'no',
  608. }
  609. );
  610. charData.data.shapes[0].it.push(
  611. {
  612. p: { k: [0, 0], a: 0 },
  613. s: { k: [100, 100], a: 0 },
  614. a: { k: [0, 0], a: 0 },
  615. r: { k: 0, a: 0 },
  616. o: { k: 100, a: 0 },
  617. sk: { k: 0, a: 0 },
  618. sa: { k: 0, a: 0 },
  619. ty: 'tr',
  620. }
  621. );
  622. }
  623. }
  624. }
  625. }
  626. };
  627. }());
  628. var checkPathProperties = (function () {
  629. var minimumVersion = [5, 7, 15];
  630. function updateTextLayer(textLayer) {
  631. var pathData = textLayer.t.p;
  632. if (typeof pathData.a === 'number') {
  633. pathData.a = {
  634. a: 0,
  635. k: pathData.a,
  636. };
  637. }
  638. if (typeof pathData.p === 'number') {
  639. pathData.p = {
  640. a: 0,
  641. k: pathData.p,
  642. };
  643. }
  644. if (typeof pathData.r === 'number') {
  645. pathData.r = {
  646. a: 0,
  647. k: pathData.r,
  648. };
  649. }
  650. }
  651. function iterateLayers(layers) {
  652. var i;
  653. var len = layers.length;
  654. for (i = 0; i < len; i += 1) {
  655. if (layers[i].ty === 5) {
  656. updateTextLayer(layers[i]);
  657. }
  658. }
  659. }
  660. return function (animationData) {
  661. if (checkVersion(minimumVersion, animationData.v)) {
  662. iterateLayers(animationData.layers);
  663. if (animationData.assets) {
  664. var i;
  665. var len = animationData.assets.length;
  666. for (i = 0; i < len; i += 1) {
  667. if (animationData.assets[i].layers) {
  668. iterateLayers(animationData.assets[i].layers);
  669. }
  670. }
  671. }
  672. }
  673. };
  674. }());
  675. var checkColors = (function () {
  676. var minimumVersion = [4, 1, 9];
  677. function iterateShapes(shapes) {
  678. var i;
  679. var len = shapes.length;
  680. var j;
  681. var jLen;
  682. for (i = 0; i < len; i += 1) {
  683. if (shapes[i].ty === 'gr') {
  684. iterateShapes(shapes[i].it);
  685. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  686. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  687. jLen = shapes[i].c.k.length;
  688. for (j = 0; j < jLen; j += 1) {
  689. if (shapes[i].c.k[j].s) {
  690. shapes[i].c.k[j].s[0] /= 255;
  691. shapes[i].c.k[j].s[1] /= 255;
  692. shapes[i].c.k[j].s[2] /= 255;
  693. shapes[i].c.k[j].s[3] /= 255;
  694. }
  695. if (shapes[i].c.k[j].e) {
  696. shapes[i].c.k[j].e[0] /= 255;
  697. shapes[i].c.k[j].e[1] /= 255;
  698. shapes[i].c.k[j].e[2] /= 255;
  699. shapes[i].c.k[j].e[3] /= 255;
  700. }
  701. }
  702. } else {
  703. shapes[i].c.k[0] /= 255;
  704. shapes[i].c.k[1] /= 255;
  705. shapes[i].c.k[2] /= 255;
  706. shapes[i].c.k[3] /= 255;
  707. }
  708. }
  709. }
  710. }
  711. function iterateLayers(layers) {
  712. var i;
  713. var len = layers.length;
  714. for (i = 0; i < len; i += 1) {
  715. if (layers[i].ty === 4) {
  716. iterateShapes(layers[i].shapes);
  717. }
  718. }
  719. }
  720. return function (animationData) {
  721. if (checkVersion(minimumVersion, animationData.v)) {
  722. iterateLayers(animationData.layers);
  723. if (animationData.assets) {
  724. var i;
  725. var len = animationData.assets.length;
  726. for (i = 0; i < len; i += 1) {
  727. if (animationData.assets[i].layers) {
  728. iterateLayers(animationData.assets[i].layers);
  729. }
  730. }
  731. }
  732. }
  733. };
  734. }());
  735. var checkShapes = (function () {
  736. var minimumVersion = [4, 4, 18];
  737. function completeClosingShapes(arr) {
  738. var i;
  739. var len = arr.length;
  740. var j;
  741. var jLen;
  742. for (i = len - 1; i >= 0; i -= 1) {
  743. if (arr[i].ty === 'sh') {
  744. if (arr[i].ks.k.i) {
  745. arr[i].ks.k.c = arr[i].closed;
  746. } else {
  747. jLen = arr[i].ks.k.length;
  748. for (j = 0; j < jLen; j += 1) {
  749. if (arr[i].ks.k[j].s) {
  750. arr[i].ks.k[j].s[0].c = arr[i].closed;
  751. }
  752. if (arr[i].ks.k[j].e) {
  753. arr[i].ks.k[j].e[0].c = arr[i].closed;
  754. }
  755. }
  756. }
  757. } else if (arr[i].ty === 'gr') {
  758. completeClosingShapes(arr[i].it);
  759. }
  760. }
  761. }
  762. function iterateLayers(layers) {
  763. var layerData;
  764. var i;
  765. var len = layers.length;
  766. var j;
  767. var jLen;
  768. var k;
  769. var kLen;
  770. for (i = 0; i < len; i += 1) {
  771. layerData = layers[i];
  772. if (layerData.hasMask) {
  773. var maskProps = layerData.masksProperties;
  774. jLen = maskProps.length;
  775. for (j = 0; j < jLen; j += 1) {
  776. if (maskProps[j].pt.k.i) {
  777. maskProps[j].pt.k.c = maskProps[j].cl;
  778. } else {
  779. kLen = maskProps[j].pt.k.length;
  780. for (k = 0; k < kLen; k += 1) {
  781. if (maskProps[j].pt.k[k].s) {
  782. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  783. }
  784. if (maskProps[j].pt.k[k].e) {
  785. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  786. }
  787. }
  788. }
  789. }
  790. }
  791. if (layerData.ty === 4) {
  792. completeClosingShapes(layerData.shapes);
  793. }
  794. }
  795. }
  796. return function (animationData) {
  797. if (checkVersion(minimumVersion, animationData.v)) {
  798. iterateLayers(animationData.layers);
  799. if (animationData.assets) {
  800. var i;
  801. var len = animationData.assets.length;
  802. for (i = 0; i < len; i += 1) {
  803. if (animationData.assets[i].layers) {
  804. iterateLayers(animationData.assets[i].layers);
  805. }
  806. }
  807. }
  808. }
  809. };
  810. }());
  811. function completeData(animationData) {
  812. if (animationData.__complete) {
  813. return;
  814. }
  815. checkColors(animationData);
  816. checkText(animationData);
  817. checkChars(animationData);
  818. checkPathProperties(animationData);
  819. checkShapes(animationData);
  820. completeLayers(animationData.layers, animationData.assets);
  821. completeChars(animationData.chars, animationData.assets);
  822. animationData.__complete = true;
  823. }
  824. function completeText(data) {
  825. if (data.t.a.length === 0 && !('m' in data.t.p)) {
  826. // data.singleShape = true;
  827. }
  828. }
  829. var moduleOb = {};
  830. moduleOb.completeData = completeData;
  831. moduleOb.checkColors = checkColors;
  832. moduleOb.checkChars = checkChars;
  833. moduleOb.checkPathProperties = checkPathProperties;
  834. moduleOb.checkShapes = checkShapes;
  835. moduleOb.completeLayers = completeLayers;
  836. return moduleOb;
  837. }
  838. if (!_workerSelf.dataManager) {
  839. _workerSelf.dataManager = dataFunctionManager();
  840. }
  841. if (!_workerSelf.assetLoader) {
  842. _workerSelf.assetLoader = (function () {
  843. function formatResponse(xhr) {
  844. // using typeof doubles the time of execution of this method,
  845. // so if available, it's better to use the header to validate the type
  846. var contentTypeHeader = xhr.getResponseHeader('content-type');
  847. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  848. return xhr.response;
  849. }
  850. if (xhr.response && typeof xhr.response === 'object') {
  851. return xhr.response;
  852. } if (xhr.response && typeof xhr.response === 'string') {
  853. return JSON.parse(xhr.response);
  854. } if (xhr.responseText) {
  855. return JSON.parse(xhr.responseText);
  856. }
  857. return null;
  858. }
  859. function loadAsset(path, fullPath, callback, errorCallback) {
  860. var response;
  861. var xhr = new XMLHttpRequest();
  862. // set responseType after calling open or IE will break.
  863. try {
  864. // This crashes on Android WebView prior to KitKat
  865. xhr.responseType = 'json';
  866. } catch (err) {} // eslint-disable-line no-empty
  867. xhr.onreadystatechange = function () {
  868. if (xhr.readyState === 4) {
  869. if (xhr.status === 200) {
  870. response = formatResponse(xhr);
  871. callback(response);
  872. } else {
  873. try {
  874. response = formatResponse(xhr);
  875. callback(response);
  876. } catch (err) {
  877. if (errorCallback) {
  878. errorCallback(err);
  879. }
  880. }
  881. }
  882. }
  883. };
  884. try {
  885. // Hack to workaround banner validation
  886. xhr.open(['G', 'E', 'T'].join(''), path, true);
  887. } catch (error) {
  888. // Hack to workaround banner validation
  889. xhr.open(['G', 'E', 'T'].join(''), fullPath + '/' + path, true);
  890. }
  891. xhr.send();
  892. }
  893. return {
  894. load: loadAsset,
  895. };
  896. }());
  897. }
  898. if (e.data.type === 'loadAnimation') {
  899. _workerSelf.assetLoader.load(
  900. e.data.path,
  901. e.data.fullPath,
  902. function (data) {
  903. _workerSelf.dataManager.completeData(data);
  904. _workerSelf.postMessage({
  905. id: e.data.id,
  906. payload: data,
  907. status: 'success',
  908. });
  909. },
  910. function () {
  911. _workerSelf.postMessage({
  912. id: e.data.id,
  913. status: 'error',
  914. });
  915. }
  916. );
  917. } else if (e.data.type === 'complete') {
  918. var animation = e.data.animation;
  919. _workerSelf.dataManager.completeData(animation);
  920. _workerSelf.postMessage({
  921. id: e.data.id,
  922. payload: animation,
  923. status: 'success',
  924. });
  925. } else if (e.data.type === 'loadData') {
  926. _workerSelf.assetLoader.load(
  927. e.data.path,
  928. e.data.fullPath,
  929. function (data) {
  930. _workerSelf.postMessage({
  931. id: e.data.id,
  932. payload: data,
  933. status: 'success',
  934. });
  935. },
  936. function () {
  937. _workerSelf.postMessage({
  938. id: e.data.id,
  939. status: 'error',
  940. });
  941. }
  942. );
  943. }
  944. });
  945. workerInstance.onmessage = function (event) {
  946. var data = event.data;
  947. var id = data.id;
  948. var process = processes[id];
  949. processes[id] = null;
  950. if (data.status === 'success') {
  951. process.onComplete(data.payload);
  952. } else if (process.onError) {
  953. process.onError();
  954. }
  955. };
  956. }
  957. }
  958. function createProcess(onComplete, onError) {
  959. _counterId += 1;
  960. var id = 'processId_' + _counterId;
  961. processes[id] = {
  962. onComplete: onComplete,
  963. onError: onError,
  964. };
  965. return id;
  966. }
  967. function loadAnimation(path, onComplete, onError) {
  968. setupWorker();
  969. var processId = createProcess(onComplete, onError);
  970. workerInstance.postMessage({
  971. type: 'loadAnimation',
  972. path: path,
  973. fullPath: window.location.origin + window.location.pathname,
  974. id: processId,
  975. });
  976. }
  977. function loadData(path, onComplete, onError) {
  978. setupWorker();
  979. var processId = createProcess(onComplete, onError);
  980. workerInstance.postMessage({
  981. type: 'loadData',
  982. path: path,
  983. fullPath: window.location.origin + window.location.pathname,
  984. id: processId,
  985. });
  986. }
  987. function completeAnimation(anim, onComplete, onError) {
  988. setupWorker();
  989. var processId = createProcess(onComplete, onError);
  990. workerInstance.postMessage({
  991. type: 'complete',
  992. animation: anim,
  993. id: processId,
  994. });
  995. }
  996. return {
  997. loadAnimation: loadAnimation,
  998. loadData: loadData,
  999. completeAnimation: completeAnimation,
  1000. };
  1001. }());
  1002. const ImagePreloader = (function () {
  1003. var proxyImage = (function () {
  1004. var canvas = createTag('canvas');
  1005. canvas.width = 1;
  1006. canvas.height = 1;
  1007. var ctx = canvas.getContext('2d');
  1008. ctx.fillStyle = 'rgba(0,0,0,0)';
  1009. ctx.fillRect(0, 0, 1, 1);
  1010. return canvas;
  1011. }());
  1012. function imageLoaded() {
  1013. this.loadedAssets += 1;
  1014. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1015. if (this.imagesLoadedCb) {
  1016. this.imagesLoadedCb(null);
  1017. }
  1018. }
  1019. }
  1020. function footageLoaded() {
  1021. this.loadedFootagesCount += 1;
  1022. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1023. if (this.imagesLoadedCb) {
  1024. this.imagesLoadedCb(null);
  1025. }
  1026. }
  1027. }
  1028. function getAssetsPath(assetData, assetsPath, originalPath) {
  1029. var path = '';
  1030. if (assetData.e) {
  1031. path = assetData.p;
  1032. } else if (assetsPath) {
  1033. var imagePath = assetData.p;
  1034. if (imagePath.indexOf('images/') !== -1) {
  1035. imagePath = imagePath.split('/')[1];
  1036. }
  1037. path = assetsPath + imagePath;
  1038. } else {
  1039. path = originalPath;
  1040. path += assetData.u ? assetData.u : '';
  1041. path += assetData.p;
  1042. }
  1043. return path;
  1044. }
  1045. function testImageLoaded(img) {
  1046. var _count = 0;
  1047. var intervalId = setInterval(function () {
  1048. var box = img.getBBox();
  1049. if (box.width || _count > 500) {
  1050. this._imageLoaded();
  1051. clearInterval(intervalId);
  1052. }
  1053. _count += 1;
  1054. }.bind(this), 50);
  1055. }
  1056. function createImageData(assetData) {
  1057. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1058. var img = createNS('image');
  1059. if (isSafari) {
  1060. this.testImageLoaded(img);
  1061. } else {
  1062. img.addEventListener('load', this._imageLoaded, false);
  1063. }
  1064. img.addEventListener('error', function () {
  1065. ob.img = proxyImage;
  1066. this._imageLoaded();
  1067. }.bind(this), false);
  1068. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1069. if (this._elementHelper.append) {
  1070. this._elementHelper.append(img);
  1071. } else {
  1072. this._elementHelper.appendChild(img);
  1073. }
  1074. var ob = {
  1075. img: img,
  1076. assetData: assetData,
  1077. };
  1078. return ob;
  1079. }
  1080. function createImgData(assetData) {
  1081. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1082. var img = createTag('img');
  1083. img.crossOrigin = 'anonymous';
  1084. img.addEventListener('load', this._imageLoaded, false);
  1085. img.addEventListener('error', function () {
  1086. ob.img = proxyImage;
  1087. this._imageLoaded();
  1088. }.bind(this), false);
  1089. img.src = path;
  1090. var ob = {
  1091. img: img,
  1092. assetData: assetData,
  1093. };
  1094. return ob;
  1095. }
  1096. function createFootageData(data) {
  1097. var ob = {
  1098. assetData: data,
  1099. };
  1100. var path = getAssetsPath(data, this.assetsPath, this.path);
  1101. dataManager.loadData(path, function (footageData) {
  1102. ob.img = footageData;
  1103. this._footageLoaded();
  1104. }.bind(this), function () {
  1105. ob.img = {};
  1106. this._footageLoaded();
  1107. }.bind(this));
  1108. return ob;
  1109. }
  1110. function loadAssets(assets, cb) {
  1111. this.imagesLoadedCb = cb;
  1112. var i;
  1113. var len = assets.length;
  1114. for (i = 0; i < len; i += 1) {
  1115. if (!assets[i].layers) {
  1116. if (!assets[i].t || assets[i].t === 'seq') {
  1117. this.totalImages += 1;
  1118. this.images.push(this._createImageData(assets[i]));
  1119. } else if (assets[i].t === 3) {
  1120. this.totalFootages += 1;
  1121. this.images.push(this.createFootageData(assets[i]));
  1122. }
  1123. }
  1124. }
  1125. }
  1126. function setPath(path) {
  1127. this.path = path || '';
  1128. }
  1129. function setAssetsPath(path) {
  1130. this.assetsPath = path || '';
  1131. }
  1132. function getAsset(assetData) {
  1133. var i = 0;
  1134. var len = this.images.length;
  1135. while (i < len) {
  1136. if (this.images[i].assetData === assetData) {
  1137. return this.images[i].img;
  1138. }
  1139. i += 1;
  1140. }
  1141. return null;
  1142. }
  1143. function destroy() {
  1144. this.imagesLoadedCb = null;
  1145. this.images.length = 0;
  1146. }
  1147. function loadedImages() {
  1148. return this.totalImages === this.loadedAssets;
  1149. }
  1150. function loadedFootages() {
  1151. return this.totalFootages === this.loadedFootagesCount;
  1152. }
  1153. function setCacheType(type, elementHelper) {
  1154. if (type === 'svg') {
  1155. this._elementHelper = elementHelper;
  1156. this._createImageData = this.createImageData.bind(this);
  1157. } else {
  1158. this._createImageData = this.createImgData.bind(this);
  1159. }
  1160. }
  1161. function ImagePreloaderFactory() {
  1162. this._imageLoaded = imageLoaded.bind(this);
  1163. this._footageLoaded = footageLoaded.bind(this);
  1164. this.testImageLoaded = testImageLoaded.bind(this);
  1165. this.createFootageData = createFootageData.bind(this);
  1166. this.assetsPath = '';
  1167. this.path = '';
  1168. this.totalImages = 0;
  1169. this.totalFootages = 0;
  1170. this.loadedAssets = 0;
  1171. this.loadedFootagesCount = 0;
  1172. this.imagesLoadedCb = null;
  1173. this.images = [];
  1174. }
  1175. ImagePreloaderFactory.prototype = {
  1176. loadAssets: loadAssets,
  1177. setAssetsPath: setAssetsPath,
  1178. setPath: setPath,
  1179. loadedImages: loadedImages,
  1180. loadedFootages: loadedFootages,
  1181. destroy: destroy,
  1182. getAsset: getAsset,
  1183. createImgData: createImgData,
  1184. createImageData: createImageData,
  1185. imageLoaded: imageLoaded,
  1186. footageLoaded: footageLoaded,
  1187. setCacheType: setCacheType,
  1188. };
  1189. return ImagePreloaderFactory;
  1190. }());
  1191. function BaseEvent() {}
  1192. BaseEvent.prototype = {
  1193. triggerEvent: function (eventName, args) {
  1194. if (this._cbs[eventName]) {
  1195. var callbacks = this._cbs[eventName];
  1196. for (var i = 0; i < callbacks.length; i += 1) {
  1197. callbacks[i](args);
  1198. }
  1199. }
  1200. },
  1201. addEventListener: function (eventName, callback) {
  1202. if (!this._cbs[eventName]) {
  1203. this._cbs[eventName] = [];
  1204. }
  1205. this._cbs[eventName].push(callback);
  1206. return function () {
  1207. this.removeEventListener(eventName, callback);
  1208. }.bind(this);
  1209. },
  1210. removeEventListener: function (eventName, callback) {
  1211. if (!callback) {
  1212. this._cbs[eventName] = null;
  1213. } else if (this._cbs[eventName]) {
  1214. var i = 0;
  1215. var len = this._cbs[eventName].length;
  1216. while (i < len) {
  1217. if (this._cbs[eventName][i] === callback) {
  1218. this._cbs[eventName].splice(i, 1);
  1219. i -= 1;
  1220. len -= 1;
  1221. }
  1222. i += 1;
  1223. }
  1224. if (!this._cbs[eventName].length) {
  1225. this._cbs[eventName] = null;
  1226. }
  1227. }
  1228. },
  1229. };
  1230. const markerParser = (
  1231. function () {
  1232. function parsePayloadLines(payload) {
  1233. var lines = payload.split('\r\n');
  1234. var keys = {};
  1235. var line;
  1236. var keysCount = 0;
  1237. for (var i = 0; i < lines.length; i += 1) {
  1238. line = lines[i].split(':');
  1239. if (line.length === 2) {
  1240. keys[line[0]] = line[1].trim();
  1241. keysCount += 1;
  1242. }
  1243. }
  1244. if (keysCount === 0) {
  1245. throw new Error();
  1246. }
  1247. return keys;
  1248. }
  1249. return function (_markers) {
  1250. var markers = [];
  1251. for (var i = 0; i < _markers.length; i += 1) {
  1252. var _marker = _markers[i];
  1253. var markerData = {
  1254. time: _marker.tm,
  1255. duration: _marker.dr,
  1256. };
  1257. try {
  1258. markerData.payload = JSON.parse(_markers[i].cm);
  1259. } catch (_) {
  1260. try {
  1261. markerData.payload = parsePayloadLines(_markers[i].cm);
  1262. } catch (__) {
  1263. markerData.payload = {
  1264. name: _markers[i].cm,
  1265. };
  1266. }
  1267. }
  1268. markers.push(markerData);
  1269. }
  1270. return markers;
  1271. };
  1272. }());
  1273. const ProjectInterface = (function () {
  1274. function registerComposition(comp) {
  1275. this.compositions.push(comp);
  1276. }
  1277. return function () {
  1278. function _thisProjectFunction(name) {
  1279. var i = 0;
  1280. var len = this.compositions.length;
  1281. while (i < len) {
  1282. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1283. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1284. this.compositions[i].prepareFrame(this.currentFrame);
  1285. }
  1286. return this.compositions[i].compInterface;
  1287. }
  1288. i += 1;
  1289. }
  1290. return null;
  1291. }
  1292. _thisProjectFunction.compositions = [];
  1293. _thisProjectFunction.currentFrame = 0;
  1294. _thisProjectFunction.registerComposition = registerComposition;
  1295. return _thisProjectFunction;
  1296. };
  1297. }());
  1298. const renderers = {};
  1299. const registerRenderer = (key, value) => {
  1300. renderers[key] = value;
  1301. };
  1302. function getRenderer(key) {
  1303. return renderers[key];
  1304. }
  1305. function getRegisteredRenderer() {
  1306. // Returns canvas by default for compatibility
  1307. if (renderers.canvas) {
  1308. return 'canvas';
  1309. }
  1310. // Returns any renderer that is registered
  1311. for (const key in renderers) {
  1312. if (renderers[key]) {
  1313. return key;
  1314. }
  1315. }
  1316. return '';
  1317. }
  1318. const AnimationItem = function () {
  1319. this._cbs = [];
  1320. this.name = '';
  1321. this.path = '';
  1322. this.isLoaded = false;
  1323. this.currentFrame = 0;
  1324. this.currentRawFrame = 0;
  1325. this.firstFrame = 0;
  1326. this.totalFrames = 0;
  1327. this.frameRate = 0;
  1328. this.frameMult = 0;
  1329. this.playSpeed = 1;
  1330. this.playDirection = 1;
  1331. this.playCount = 0;
  1332. this.animationData = {};
  1333. this.assets = [];
  1334. this.isPaused = true;
  1335. this.autoplay = false;
  1336. this.loop = true;
  1337. this.renderer = null;
  1338. this.animationID = createElementID();
  1339. this.assetsPath = '';
  1340. this.timeCompleted = 0;
  1341. this.segmentPos = 0;
  1342. this.isSubframeEnabled = getSubframeEnabled();
  1343. this.segments = [];
  1344. this._idle = true;
  1345. this._completedLoop = false;
  1346. this.projectInterface = ProjectInterface();
  1347. this.imagePreloader = new ImagePreloader();
  1348. this.audioController = audioControllerFactory();
  1349. this.markers = [];
  1350. this.configAnimation = this.configAnimation.bind(this);
  1351. this.onSetupError = this.onSetupError.bind(this);
  1352. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1353. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1354. this.expressionsPlugin = getExpressionsPlugin();
  1355. };
  1356. extendPrototype([BaseEvent], AnimationItem);
  1357. AnimationItem.prototype.setParams = function (params) {
  1358. if (params.wrapper || params.container) {
  1359. this.wrapper = params.wrapper || params.container;
  1360. }
  1361. var animType = 'svg';
  1362. if (params.animType) {
  1363. animType = params.animType;
  1364. } else if (params.renderer) {
  1365. animType = params.renderer;
  1366. }
  1367. const RendererClass = getRenderer(animType);
  1368. this.renderer = new RendererClass(this, params.rendererSettings);
  1369. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1370. this.renderer.setProjectInterface(this.projectInterface);
  1371. this.animType = animType;
  1372. if (params.loop === ''
  1373. || params.loop === null
  1374. || params.loop === undefined
  1375. || params.loop === true) {
  1376. this.loop = true;
  1377. } else if (params.loop === false) {
  1378. this.loop = false;
  1379. } else {
  1380. this.loop = parseInt(params.loop, 10);
  1381. }
  1382. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1383. this.name = params.name ? params.name : '';
  1384. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1385. this.assetsPath = params.assetsPath;
  1386. this.initialSegment = params.initialSegment;
  1387. if (params.audioFactory) {
  1388. this.audioController.setAudioFactory(params.audioFactory);
  1389. }
  1390. if (params.animationData) {
  1391. this.setupAnimation(params.animationData);
  1392. } else if (params.path) {
  1393. if (params.path.lastIndexOf('\\') !== -1) {
  1394. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1395. } else {
  1396. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1397. }
  1398. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1399. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1400. dataManager.loadAnimation(
  1401. params.path,
  1402. this.configAnimation,
  1403. this.onSetupError
  1404. );
  1405. }
  1406. };
  1407. AnimationItem.prototype.onSetupError = function () {
  1408. this.trigger('data_failed');
  1409. };
  1410. AnimationItem.prototype.setupAnimation = function (data) {
  1411. dataManager.completeAnimation(
  1412. data,
  1413. this.configAnimation
  1414. );
  1415. };
  1416. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1417. if (animationData) {
  1418. if (typeof animationData !== 'object') {
  1419. animationData = JSON.parse(animationData);
  1420. }
  1421. }
  1422. var params = {
  1423. wrapper: wrapper,
  1424. animationData: animationData,
  1425. };
  1426. var wrapperAttributes = wrapper.attributes;
  1427. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1428. ? wrapperAttributes.getNamedItem('data-animation-path').value
  1429. : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1430. ? wrapperAttributes.getNamedItem('data-bm-path').value
  1431. : wrapperAttributes.getNamedItem('bm-path')
  1432. ? wrapperAttributes.getNamedItem('bm-path').value
  1433. : '';
  1434. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1435. ? wrapperAttributes.getNamedItem('data-anim-type').value
  1436. : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1437. ? wrapperAttributes.getNamedItem('data-bm-type').value
  1438. : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1439. ? wrapperAttributes.getNamedItem('bm-type').value
  1440. : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1441. ? wrapperAttributes.getNamedItem('data-bm-renderer').value
  1442. : wrapperAttributes.getNamedItem('bm-renderer')
  1443. ? wrapperAttributes.getNamedItem('bm-renderer').value
  1444. : getRegisteredRenderer() || 'canvas';
  1445. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1446. ? wrapperAttributes.getNamedItem('data-anim-loop').value
  1447. : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1448. ? wrapperAttributes.getNamedItem('data-bm-loop').value
  1449. : wrapperAttributes.getNamedItem('bm-loop')
  1450. ? wrapperAttributes.getNamedItem('bm-loop').value
  1451. : '';
  1452. if (loop === 'false') {
  1453. params.loop = false;
  1454. } else if (loop === 'true') {
  1455. params.loop = true;
  1456. } else if (loop !== '') {
  1457. params.loop = parseInt(loop, 10);
  1458. }
  1459. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1460. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value
  1461. : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1462. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value
  1463. : wrapperAttributes.getNamedItem('bm-autoplay')
  1464. ? wrapperAttributes.getNamedItem('bm-autoplay').value
  1465. : true;
  1466. params.autoplay = autoplay !== 'false';
  1467. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1468. ? wrapperAttributes.getNamedItem('data-name').value
  1469. : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1470. ? wrapperAttributes.getNamedItem('data-bm-name').value
  1471. : wrapperAttributes.getNamedItem('bm-name')
  1472. ? wrapperAttributes.getNamedItem('bm-name').value
  1473. : '';
  1474. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1475. ? wrapperAttributes.getNamedItem('data-anim-prerender').value
  1476. : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1477. ? wrapperAttributes.getNamedItem('data-bm-prerender').value
  1478. : wrapperAttributes.getNamedItem('bm-prerender')
  1479. ? wrapperAttributes.getNamedItem('bm-prerender').value
  1480. : '';
  1481. if (prerender === 'false') {
  1482. params.prerender = false;
  1483. }
  1484. if (!params.path) {
  1485. this.trigger('destroy');
  1486. } else {
  1487. this.setParams(params);
  1488. }
  1489. };
  1490. AnimationItem.prototype.includeLayers = function (data) {
  1491. if (data.op > this.animationData.op) {
  1492. this.animationData.op = data.op;
  1493. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1494. }
  1495. var layers = this.animationData.layers;
  1496. var i;
  1497. var len = layers.length;
  1498. var newLayers = data.layers;
  1499. var j;
  1500. var jLen = newLayers.length;
  1501. for (j = 0; j < jLen; j += 1) {
  1502. i = 0;
  1503. while (i < len) {
  1504. if (layers[i].id === newLayers[j].id) {
  1505. layers[i] = newLayers[j];
  1506. break;
  1507. }
  1508. i += 1;
  1509. }
  1510. }
  1511. if (data.chars || data.fonts) {
  1512. this.renderer.globalData.fontManager.addChars(data.chars);
  1513. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1514. }
  1515. if (data.assets) {
  1516. len = data.assets.length;
  1517. for (i = 0; i < len; i += 1) {
  1518. this.animationData.assets.push(data.assets[i]);
  1519. }
  1520. }
  1521. this.animationData.__complete = false;
  1522. dataManager.completeAnimation(
  1523. this.animationData,
  1524. this.onSegmentComplete
  1525. );
  1526. };
  1527. AnimationItem.prototype.onSegmentComplete = function (data) {
  1528. this.animationData = data;
  1529. var expressionsPlugin = getExpressionsPlugin();
  1530. if (expressionsPlugin) {
  1531. expressionsPlugin.initExpressions(this);
  1532. }
  1533. this.loadNextSegment();
  1534. };
  1535. AnimationItem.prototype.loadNextSegment = function () {
  1536. var segments = this.animationData.segments;
  1537. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1538. this.trigger('data_ready');
  1539. this.timeCompleted = this.totalFrames;
  1540. return;
  1541. }
  1542. var segment = segments.shift();
  1543. this.timeCompleted = segment.time * this.frameRate;
  1544. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1545. this.segmentPos += 1;
  1546. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1547. this.trigger('data_failed');
  1548. }.bind(this));
  1549. };
  1550. AnimationItem.prototype.loadSegments = function () {
  1551. var segments = this.animationData.segments;
  1552. if (!segments) {
  1553. this.timeCompleted = this.totalFrames;
  1554. }
  1555. this.loadNextSegment();
  1556. };
  1557. AnimationItem.prototype.imagesLoaded = function () {
  1558. this.trigger('loaded_images');
  1559. this.checkLoaded();
  1560. };
  1561. AnimationItem.prototype.preloadImages = function () {
  1562. this.imagePreloader.setAssetsPath(this.assetsPath);
  1563. this.imagePreloader.setPath(this.path);
  1564. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1565. };
  1566. AnimationItem.prototype.configAnimation = function (animData) {
  1567. if (!this.renderer) {
  1568. return;
  1569. }
  1570. try {
  1571. this.animationData = animData;
  1572. if (this.initialSegment) {
  1573. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1574. this.firstFrame = Math.round(this.initialSegment[0]);
  1575. } else {
  1576. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1577. this.firstFrame = Math.round(this.animationData.ip);
  1578. }
  1579. this.renderer.configAnimation(animData);
  1580. if (!animData.assets) {
  1581. animData.assets = [];
  1582. }
  1583. this.assets = this.animationData.assets;
  1584. this.frameRate = this.animationData.fr;
  1585. this.frameMult = this.animationData.fr / 1000;
  1586. this.renderer.searchExtraCompositions(animData.assets);
  1587. this.markers = markerParser(animData.markers || []);
  1588. this.trigger('config_ready');
  1589. this.preloadImages();
  1590. this.loadSegments();
  1591. this.updaFrameModifier();
  1592. this.waitForFontsLoaded();
  1593. if (this.isPaused) {
  1594. this.audioController.pause();
  1595. }
  1596. } catch (error) {
  1597. this.triggerConfigError(error);
  1598. }
  1599. };
  1600. AnimationItem.prototype.waitForFontsLoaded = function () {
  1601. if (!this.renderer) {
  1602. return;
  1603. }
  1604. if (this.renderer.globalData.fontManager.isLoaded) {
  1605. this.checkLoaded();
  1606. } else {
  1607. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1608. }
  1609. };
  1610. AnimationItem.prototype.checkLoaded = function () {
  1611. if (!this.isLoaded
  1612. && this.renderer.globalData.fontManager.isLoaded
  1613. && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas')
  1614. && (this.imagePreloader.loadedFootages())
  1615. ) {
  1616. this.isLoaded = true;
  1617. var expressionsPlugin = getExpressionsPlugin();
  1618. if (expressionsPlugin) {
  1619. expressionsPlugin.initExpressions(this);
  1620. }
  1621. this.renderer.initItems();
  1622. setTimeout(function () {
  1623. this.trigger('DOMLoaded');
  1624. }.bind(this), 0);
  1625. this.gotoFrame();
  1626. if (this.autoplay) {
  1627. this.play();
  1628. }
  1629. }
  1630. };
  1631. AnimationItem.prototype.resize = function (width, height) {
  1632. // Adding this validation for backwards compatibility in case an event object was being passed down
  1633. var _width = typeof width === 'number' ? width : undefined;
  1634. var _height = typeof height === 'number' ? height : undefined;
  1635. this.renderer.updateContainerSize(_width, _height);
  1636. };
  1637. AnimationItem.prototype.setSubframe = function (flag) {
  1638. this.isSubframeEnabled = !!flag;
  1639. };
  1640. AnimationItem.prototype.gotoFrame = function () {
  1641. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1642. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1643. this.currentFrame = this.timeCompleted;
  1644. }
  1645. this.trigger('enterFrame');
  1646. this.renderFrame();
  1647. this.trigger('drawnFrame');
  1648. };
  1649. AnimationItem.prototype.renderFrame = function () {
  1650. if (this.isLoaded === false || !this.renderer) {
  1651. return;
  1652. }
  1653. try {
  1654. if (this.expressionsPlugin) {
  1655. this.expressionsPlugin.resetFrame();
  1656. }
  1657. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1658. } catch (error) {
  1659. this.triggerRenderFrameError(error);
  1660. }
  1661. };
  1662. AnimationItem.prototype.play = function (name) {
  1663. if (name && this.name !== name) {
  1664. return;
  1665. }
  1666. if (this.isPaused === true) {
  1667. this.isPaused = false;
  1668. this.trigger('_play');
  1669. this.audioController.resume();
  1670. if (this._idle) {
  1671. this._idle = false;
  1672. this.trigger('_active');
  1673. }
  1674. }
  1675. };
  1676. AnimationItem.prototype.pause = function (name) {
  1677. if (name && this.name !== name) {
  1678. return;
  1679. }
  1680. if (this.isPaused === false) {
  1681. this.isPaused = true;
  1682. this.trigger('_pause');
  1683. this._idle = true;
  1684. this.trigger('_idle');
  1685. this.audioController.pause();
  1686. }
  1687. };
  1688. AnimationItem.prototype.togglePause = function (name) {
  1689. if (name && this.name !== name) {
  1690. return;
  1691. }
  1692. if (this.isPaused === true) {
  1693. this.play();
  1694. } else {
  1695. this.pause();
  1696. }
  1697. };
  1698. AnimationItem.prototype.stop = function (name) {
  1699. if (name && this.name !== name) {
  1700. return;
  1701. }
  1702. this.pause();
  1703. this.playCount = 0;
  1704. this._completedLoop = false;
  1705. this.setCurrentRawFrameValue(0);
  1706. };
  1707. AnimationItem.prototype.getMarkerData = function (markerName) {
  1708. var marker;
  1709. for (var i = 0; i < this.markers.length; i += 1) {
  1710. marker = this.markers[i];
  1711. if (marker.payload && marker.payload.name === markerName) {
  1712. return marker;
  1713. }
  1714. }
  1715. return null;
  1716. };
  1717. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1718. if (name && this.name !== name) {
  1719. return;
  1720. }
  1721. var numValue = Number(value);
  1722. if (isNaN(numValue)) {
  1723. var marker = this.getMarkerData(value);
  1724. if (marker) {
  1725. this.goToAndStop(marker.time, true);
  1726. }
  1727. } else if (isFrame) {
  1728. this.setCurrentRawFrameValue(value);
  1729. } else {
  1730. this.setCurrentRawFrameValue(value * this.frameModifier);
  1731. }
  1732. this.pause();
  1733. };
  1734. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1735. if (name && this.name !== name) {
  1736. return;
  1737. }
  1738. var numValue = Number(value);
  1739. if (isNaN(numValue)) {
  1740. var marker = this.getMarkerData(value);
  1741. if (marker) {
  1742. if (!marker.duration) {
  1743. this.goToAndStop(marker.time, true);
  1744. } else {
  1745. this.playSegments([marker.time, marker.time + marker.duration], true);
  1746. }
  1747. }
  1748. } else {
  1749. this.goToAndStop(numValue, isFrame, name);
  1750. }
  1751. this.play();
  1752. };
  1753. AnimationItem.prototype.advanceTime = function (value) {
  1754. if (this.isPaused === true || this.isLoaded === false) {
  1755. return;
  1756. }
  1757. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1758. var _isComplete = false;
  1759. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1760. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1761. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1762. if (!this.loop || this.playCount === this.loop) {
  1763. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1764. _isComplete = true;
  1765. nextValue = this.totalFrames - 1;
  1766. }
  1767. } else if (nextValue >= this.totalFrames) {
  1768. this.playCount += 1;
  1769. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1770. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1771. this._completedLoop = true;
  1772. this.trigger('loopComplete');
  1773. }
  1774. } else {
  1775. this.setCurrentRawFrameValue(nextValue);
  1776. }
  1777. } else if (nextValue < 0) {
  1778. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1779. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) { // eslint-disable-line no-plusplus
  1780. this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames));
  1781. if (!this._completedLoop) {
  1782. this._completedLoop = true;
  1783. } else {
  1784. this.trigger('loopComplete');
  1785. }
  1786. } else {
  1787. _isComplete = true;
  1788. nextValue = 0;
  1789. }
  1790. }
  1791. } else {
  1792. this.setCurrentRawFrameValue(nextValue);
  1793. }
  1794. if (_isComplete) {
  1795. this.setCurrentRawFrameValue(nextValue);
  1796. this.pause();
  1797. this.trigger('complete');
  1798. }
  1799. };
  1800. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1801. this.playCount = 0;
  1802. if (arr[1] < arr[0]) {
  1803. if (this.frameModifier > 0) {
  1804. if (this.playSpeed < 0) {
  1805. this.setSpeed(-this.playSpeed);
  1806. } else {
  1807. this.setDirection(-1);
  1808. }
  1809. }
  1810. this.totalFrames = arr[0] - arr[1];
  1811. this.timeCompleted = this.totalFrames;
  1812. this.firstFrame = arr[1];
  1813. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1814. } else if (arr[1] > arr[0]) {
  1815. if (this.frameModifier < 0) {
  1816. if (this.playSpeed < 0) {
  1817. this.setSpeed(-this.playSpeed);
  1818. } else {
  1819. this.setDirection(1);
  1820. }
  1821. }
  1822. this.totalFrames = arr[1] - arr[0];
  1823. this.timeCompleted = this.totalFrames;
  1824. this.firstFrame = arr[0];
  1825. this.setCurrentRawFrameValue(0.001 + offset);
  1826. }
  1827. this.trigger('segmentStart');
  1828. };
  1829. AnimationItem.prototype.setSegment = function (init, end) {
  1830. var pendingFrame = -1;
  1831. if (this.isPaused) {
  1832. if (this.currentRawFrame + this.firstFrame < init) {
  1833. pendingFrame = init;
  1834. } else if (this.currentRawFrame + this.firstFrame > end) {
  1835. pendingFrame = end - init;
  1836. }
  1837. }
  1838. this.firstFrame = init;
  1839. this.totalFrames = end - init;
  1840. this.timeCompleted = this.totalFrames;
  1841. if (pendingFrame !== -1) {
  1842. this.goToAndStop(pendingFrame, true);
  1843. }
  1844. };
  1845. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1846. if (forceFlag) {
  1847. this.segments.length = 0;
  1848. }
  1849. if (typeof arr[0] === 'object') {
  1850. var i;
  1851. var len = arr.length;
  1852. for (i = 0; i < len; i += 1) {
  1853. this.segments.push(arr[i]);
  1854. }
  1855. } else {
  1856. this.segments.push(arr);
  1857. }
  1858. if (this.segments.length && forceFlag) {
  1859. this.adjustSegment(this.segments.shift(), 0);
  1860. }
  1861. if (this.isPaused) {
  1862. this.play();
  1863. }
  1864. };
  1865. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1866. this.segments.length = 0;
  1867. this.segments.push([this.animationData.ip, this.animationData.op]);
  1868. if (forceFlag) {
  1869. this.checkSegments(0);
  1870. }
  1871. };
  1872. AnimationItem.prototype.checkSegments = function (offset) {
  1873. if (this.segments.length) {
  1874. this.adjustSegment(this.segments.shift(), offset);
  1875. return true;
  1876. }
  1877. return false;
  1878. };
  1879. AnimationItem.prototype.destroy = function (name) {
  1880. if ((name && this.name !== name) || !this.renderer) {
  1881. return;
  1882. }
  1883. this.renderer.destroy();
  1884. this.imagePreloader.destroy();
  1885. this.trigger('destroy');
  1886. this._cbs = null;
  1887. this.onEnterFrame = null;
  1888. this.onLoopComplete = null;
  1889. this.onComplete = null;
  1890. this.onSegmentStart = null;
  1891. this.onDestroy = null;
  1892. this.renderer = null;
  1893. this.expressionsPlugin = null;
  1894. this.imagePreloader = null;
  1895. this.projectInterface = null;
  1896. };
  1897. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1898. this.currentRawFrame = value;
  1899. this.gotoFrame();
  1900. };
  1901. AnimationItem.prototype.setSpeed = function (val) {
  1902. this.playSpeed = val;
  1903. this.updaFrameModifier();
  1904. };
  1905. AnimationItem.prototype.setDirection = function (val) {
  1906. this.playDirection = val < 0 ? -1 : 1;
  1907. this.updaFrameModifier();
  1908. };
  1909. AnimationItem.prototype.setLoop = function (isLooping) {
  1910. this.loop = isLooping;
  1911. };
  1912. AnimationItem.prototype.setVolume = function (val, name) {
  1913. if (name && this.name !== name) {
  1914. return;
  1915. }
  1916. this.audioController.setVolume(val);
  1917. };
  1918. AnimationItem.prototype.getVolume = function () {
  1919. return this.audioController.getVolume();
  1920. };
  1921. AnimationItem.prototype.mute = function (name) {
  1922. if (name && this.name !== name) {
  1923. return;
  1924. }
  1925. this.audioController.mute();
  1926. };
  1927. AnimationItem.prototype.unmute = function (name) {
  1928. if (name && this.name !== name) {
  1929. return;
  1930. }
  1931. this.audioController.unmute();
  1932. };
  1933. AnimationItem.prototype.updaFrameModifier = function () {
  1934. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1935. this.audioController.setRate(this.playSpeed * this.playDirection);
  1936. };
  1937. AnimationItem.prototype.getPath = function () {
  1938. return this.path;
  1939. };
  1940. AnimationItem.prototype.getAssetsPath = function (assetData) {
  1941. var path = '';
  1942. if (assetData.e) {
  1943. path = assetData.p;
  1944. } else if (this.assetsPath) {
  1945. var imagePath = assetData.p;
  1946. if (imagePath.indexOf('images/') !== -1) {
  1947. imagePath = imagePath.split('/')[1];
  1948. }
  1949. path = this.assetsPath + imagePath;
  1950. } else {
  1951. path = this.path;
  1952. path += assetData.u ? assetData.u : '';
  1953. path += assetData.p;
  1954. }
  1955. return path;
  1956. };
  1957. AnimationItem.prototype.getAssetData = function (id) {
  1958. var i = 0;
  1959. var len = this.assets.length;
  1960. while (i < len) {
  1961. if (id === this.assets[i].id) {
  1962. return this.assets[i];
  1963. }
  1964. i += 1;
  1965. }
  1966. return null;
  1967. };
  1968. AnimationItem.prototype.hide = function () {
  1969. this.renderer.hide();
  1970. };
  1971. AnimationItem.prototype.show = function () {
  1972. this.renderer.show();
  1973. };
  1974. AnimationItem.prototype.getDuration = function (isFrame) {
  1975. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  1976. };
  1977. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  1978. try {
  1979. var element = this.renderer.getElementByPath(path);
  1980. element.updateDocumentData(documentData, index);
  1981. } catch (error) {
  1982. // TODO: decide how to handle catch case
  1983. }
  1984. };
  1985. AnimationItem.prototype.trigger = function (name) {
  1986. if (this._cbs && this._cbs[name]) {
  1987. switch (name) {
  1988. case 'enterFrame':
  1989. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  1990. break;
  1991. case 'drawnFrame':
  1992. this.drawnFrameEvent.currentTime = this.currentFrame;
  1993. this.drawnFrameEvent.totalTime = this.totalFrames;
  1994. this.drawnFrameEvent.direction = this.frameModifier;
  1995. this.triggerEvent(name, this.drawnFrameEvent);
  1996. break;
  1997. case 'loopComplete':
  1998. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  1999. break;
  2000. case 'complete':
  2001. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  2002. break;
  2003. case 'segmentStart':
  2004. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2005. break;
  2006. case 'destroy':
  2007. this.triggerEvent(name, new BMDestroyEvent(name, this));
  2008. break;
  2009. default:
  2010. this.triggerEvent(name);
  2011. }
  2012. }
  2013. if (name === 'enterFrame' && this.onEnterFrame) {
  2014. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  2015. }
  2016. if (name === 'loopComplete' && this.onLoopComplete) {
  2017. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2018. }
  2019. if (name === 'complete' && this.onComplete) {
  2020. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  2021. }
  2022. if (name === 'segmentStart' && this.onSegmentStart) {
  2023. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2024. }
  2025. if (name === 'destroy' && this.onDestroy) {
  2026. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  2027. }
  2028. };
  2029. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  2030. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2031. this.triggerEvent('error', error);
  2032. if (this.onError) {
  2033. this.onError.call(this, error);
  2034. }
  2035. };
  2036. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2037. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2038. this.triggerEvent('error', error);
  2039. if (this.onError) {
  2040. this.onError.call(this, error);
  2041. }
  2042. };
  2043. const animationManager = (function () {
  2044. var moduleOb = {};
  2045. var registeredAnimations = [];
  2046. var initTime = 0;
  2047. var len = 0;
  2048. var playingAnimationsNum = 0;
  2049. var _stopped = true;
  2050. var _isFrozen = false;
  2051. function removeElement(ev) {
  2052. var i = 0;
  2053. var animItem = ev.target;
  2054. while (i < len) {
  2055. if (registeredAnimations[i].animation === animItem) {
  2056. registeredAnimations.splice(i, 1);
  2057. i -= 1;
  2058. len -= 1;
  2059. if (!animItem.isPaused) {
  2060. subtractPlayingCount();
  2061. }
  2062. }
  2063. i += 1;
  2064. }
  2065. }
  2066. function registerAnimation(element, animationData) {
  2067. if (!element) {
  2068. return null;
  2069. }
  2070. var i = 0;
  2071. while (i < len) {
  2072. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2073. return registeredAnimations[i].animation;
  2074. }
  2075. i += 1;
  2076. }
  2077. var animItem = new AnimationItem();
  2078. setupAnimation(animItem, element);
  2079. animItem.setData(element, animationData);
  2080. return animItem;
  2081. }
  2082. function getRegisteredAnimations() {
  2083. var i;
  2084. var lenAnims = registeredAnimations.length;
  2085. var animations = [];
  2086. for (i = 0; i < lenAnims; i += 1) {
  2087. animations.push(registeredAnimations[i].animation);
  2088. }
  2089. return animations;
  2090. }
  2091. function addPlayingCount() {
  2092. playingAnimationsNum += 1;
  2093. activate();
  2094. }
  2095. function subtractPlayingCount() {
  2096. playingAnimationsNum -= 1;
  2097. }
  2098. function setupAnimation(animItem, element) {
  2099. animItem.addEventListener('destroy', removeElement);
  2100. animItem.addEventListener('_active', addPlayingCount);
  2101. animItem.addEventListener('_idle', subtractPlayingCount);
  2102. registeredAnimations.push({ elem: element, animation: animItem });
  2103. len += 1;
  2104. }
  2105. function loadAnimation(params) {
  2106. var animItem = new AnimationItem();
  2107. setupAnimation(animItem, null);
  2108. animItem.setParams(params);
  2109. return animItem;
  2110. }
  2111. function setSpeed(val, animation) {
  2112. var i;
  2113. for (i = 0; i < len; i += 1) {
  2114. registeredAnimations[i].animation.setSpeed(val, animation);
  2115. }
  2116. }
  2117. function setDirection(val, animation) {
  2118. var i;
  2119. for (i = 0; i < len; i += 1) {
  2120. registeredAnimations[i].animation.setDirection(val, animation);
  2121. }
  2122. }
  2123. function play(animation) {
  2124. var i;
  2125. for (i = 0; i < len; i += 1) {
  2126. registeredAnimations[i].animation.play(animation);
  2127. }
  2128. }
  2129. function resume(nowTime) {
  2130. var elapsedTime = nowTime - initTime;
  2131. var i;
  2132. for (i = 0; i < len; i += 1) {
  2133. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2134. }
  2135. initTime = nowTime;
  2136. if (playingAnimationsNum && !_isFrozen) {
  2137. window.requestAnimationFrame(resume);
  2138. } else {
  2139. _stopped = true;
  2140. }
  2141. }
  2142. function first(nowTime) {
  2143. initTime = nowTime;
  2144. window.requestAnimationFrame(resume);
  2145. }
  2146. function pause(animation) {
  2147. var i;
  2148. for (i = 0; i < len; i += 1) {
  2149. registeredAnimations[i].animation.pause(animation);
  2150. }
  2151. }
  2152. function goToAndStop(value, isFrame, animation) {
  2153. var i;
  2154. for (i = 0; i < len; i += 1) {
  2155. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2156. }
  2157. }
  2158. function stop(animation) {
  2159. var i;
  2160. for (i = 0; i < len; i += 1) {
  2161. registeredAnimations[i].animation.stop(animation);
  2162. }
  2163. }
  2164. function togglePause(animation) {
  2165. var i;
  2166. for (i = 0; i < len; i += 1) {
  2167. registeredAnimations[i].animation.togglePause(animation);
  2168. }
  2169. }
  2170. function destroy(animation) {
  2171. var i;
  2172. for (i = (len - 1); i >= 0; i -= 1) {
  2173. registeredAnimations[i].animation.destroy(animation);
  2174. }
  2175. }
  2176. function searchAnimations(animationData, standalone, renderer) {
  2177. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')),
  2178. [].slice.call(document.getElementsByClassName('bodymovin')));
  2179. var i;
  2180. var lenAnims = animElements.length;
  2181. for (i = 0; i < lenAnims; i += 1) {
  2182. if (renderer) {
  2183. animElements[i].setAttribute('data-bm-type', renderer);
  2184. }
  2185. registerAnimation(animElements[i], animationData);
  2186. }
  2187. if (standalone && lenAnims === 0) {
  2188. if (!renderer) {
  2189. renderer = 'svg';
  2190. }
  2191. var body = document.getElementsByTagName('body')[0];
  2192. body.innerText = '';
  2193. var div = createTag('div');
  2194. div.style.width = '100%';
  2195. div.style.height = '100%';
  2196. div.setAttribute('data-bm-type', renderer);
  2197. body.appendChild(div);
  2198. registerAnimation(div, animationData);
  2199. }
  2200. }
  2201. function resize() {
  2202. var i;
  2203. for (i = 0; i < len; i += 1) {
  2204. registeredAnimations[i].animation.resize();
  2205. }
  2206. }
  2207. function activate() {
  2208. if (!_isFrozen && playingAnimationsNum) {
  2209. if (_stopped) {
  2210. window.requestAnimationFrame(first);
  2211. _stopped = false;
  2212. }
  2213. }
  2214. }
  2215. function freeze() {
  2216. _isFrozen = true;
  2217. }
  2218. function unfreeze() {
  2219. _isFrozen = false;
  2220. activate();
  2221. }
  2222. function setVolume(val, animation) {
  2223. var i;
  2224. for (i = 0; i < len; i += 1) {
  2225. registeredAnimations[i].animation.setVolume(val, animation);
  2226. }
  2227. }
  2228. function mute(animation) {
  2229. var i;
  2230. for (i = 0; i < len; i += 1) {
  2231. registeredAnimations[i].animation.mute(animation);
  2232. }
  2233. }
  2234. function unmute(animation) {
  2235. var i;
  2236. for (i = 0; i < len; i += 1) {
  2237. registeredAnimations[i].animation.unmute(animation);
  2238. }
  2239. }
  2240. moduleOb.registerAnimation = registerAnimation;
  2241. moduleOb.loadAnimation = loadAnimation;
  2242. moduleOb.setSpeed = setSpeed;
  2243. moduleOb.setDirection = setDirection;
  2244. moduleOb.play = play;
  2245. moduleOb.pause = pause;
  2246. moduleOb.stop = stop;
  2247. moduleOb.togglePause = togglePause;
  2248. moduleOb.searchAnimations = searchAnimations;
  2249. moduleOb.resize = resize;
  2250. // moduleOb.start = start;
  2251. moduleOb.goToAndStop = goToAndStop;
  2252. moduleOb.destroy = destroy;
  2253. moduleOb.freeze = freeze;
  2254. moduleOb.unfreeze = unfreeze;
  2255. moduleOb.setVolume = setVolume;
  2256. moduleOb.mute = mute;
  2257. moduleOb.unmute = unmute;
  2258. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2259. return moduleOb;
  2260. }());
  2261. /* eslint-disable */
  2262. const BezierFactory = (function () {
  2263. /**
  2264. * BezierEasing - use bezier curve for transition easing function
  2265. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2266. *
  2267. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2268. * Usage:
  2269. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2270. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2271. *
  2272. */
  2273. var ob = {};
  2274. ob.getBezierEasing = getBezierEasing;
  2275. var beziers = {};
  2276. function getBezierEasing(a, b, c, d, nm) {
  2277. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2278. if (beziers[str]) {
  2279. return beziers[str];
  2280. }
  2281. var bezEasing = new BezierEasing([a, b, c, d]);
  2282. beziers[str] = bezEasing;
  2283. return bezEasing;
  2284. }
  2285. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2286. var NEWTON_ITERATIONS = 4;
  2287. var NEWTON_MIN_SLOPE = 0.001;
  2288. var SUBDIVISION_PRECISION = 0.0000001;
  2289. var SUBDIVISION_MAX_ITERATIONS = 10;
  2290. var kSplineTableSize = 11;
  2291. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2292. var float32ArraySupported = typeof Float32Array === 'function';
  2293. function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
  2294. function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
  2295. function C(aA1) { return 3.0 * aA1; }
  2296. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2297. function calcBezier(aT, aA1, aA2) {
  2298. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2299. }
  2300. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2301. function getSlope(aT, aA1, aA2) {
  2302. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2303. }
  2304. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2305. var currentX,
  2306. currentT,
  2307. i = 0;
  2308. do {
  2309. currentT = aA + (aB - aA) / 2.0;
  2310. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2311. if (currentX > 0.0) {
  2312. aB = currentT;
  2313. } else {
  2314. aA = currentT;
  2315. }
  2316. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2317. return currentT;
  2318. }
  2319. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2320. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2321. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2322. if (currentSlope === 0.0) return aGuessT;
  2323. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2324. aGuessT -= currentX / currentSlope;
  2325. }
  2326. return aGuessT;
  2327. }
  2328. /**
  2329. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2330. */
  2331. function BezierEasing(points) {
  2332. this._p = points;
  2333. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2334. this._precomputed = false;
  2335. this.get = this.get.bind(this);
  2336. }
  2337. BezierEasing.prototype = {
  2338. get: function (x) {
  2339. var mX1 = this._p[0],
  2340. mY1 = this._p[1],
  2341. mX2 = this._p[2],
  2342. mY2 = this._p[3];
  2343. if (!this._precomputed) this._precompute();
  2344. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2345. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2346. if (x === 0) return 0;
  2347. if (x === 1) return 1;
  2348. return calcBezier(this._getTForX(x), mY1, mY2);
  2349. },
  2350. // Private part
  2351. _precompute: function () {
  2352. var mX1 = this._p[0],
  2353. mY1 = this._p[1],
  2354. mX2 = this._p[2],
  2355. mY2 = this._p[3];
  2356. this._precomputed = true;
  2357. if (mX1 !== mY1 || mX2 !== mY2) { this._calcSampleValues(); }
  2358. },
  2359. _calcSampleValues: function () {
  2360. var mX1 = this._p[0],
  2361. mX2 = this._p[2];
  2362. for (var i = 0; i < kSplineTableSize; ++i) {
  2363. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2364. }
  2365. },
  2366. /**
  2367. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2368. */
  2369. _getTForX: function (aX) {
  2370. var mX1 = this._p[0],
  2371. mX2 = this._p[2],
  2372. mSampleValues = this._mSampleValues;
  2373. var intervalStart = 0.0;
  2374. var currentSample = 1;
  2375. var lastSample = kSplineTableSize - 1;
  2376. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2377. intervalStart += kSampleStepSize;
  2378. }
  2379. --currentSample;
  2380. // Interpolate to provide an initial guess for t
  2381. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2382. var guessForT = intervalStart + dist * kSampleStepSize;
  2383. var initialSlope = getSlope(guessForT, mX1, mX2);
  2384. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2385. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2386. } if (initialSlope === 0.0) {
  2387. return guessForT;
  2388. }
  2389. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2390. },
  2391. };
  2392. return ob;
  2393. }());
  2394. const pooling = (function () {
  2395. function double(arr) {
  2396. return arr.concat(createSizedArray(arr.length));
  2397. }
  2398. return {
  2399. double: double,
  2400. };
  2401. }());
  2402. const poolFactory = (function () {
  2403. return function (initialLength, _create, _release) {
  2404. var _length = 0;
  2405. var _maxLength = initialLength;
  2406. var pool = createSizedArray(_maxLength);
  2407. var ob = {
  2408. newElement: newElement,
  2409. release: release,
  2410. };
  2411. function newElement() {
  2412. var element;
  2413. if (_length) {
  2414. _length -= 1;
  2415. element = pool[_length];
  2416. } else {
  2417. element = _create();
  2418. }
  2419. return element;
  2420. }
  2421. function release(element) {
  2422. if (_length === _maxLength) {
  2423. pool = pooling.double(pool);
  2424. _maxLength *= 2;
  2425. }
  2426. if (_release) {
  2427. _release(element);
  2428. }
  2429. pool[_length] = element;
  2430. _length += 1;
  2431. }
  2432. return ob;
  2433. };
  2434. }());
  2435. const bezierLengthPool = (function () {
  2436. function create() {
  2437. return {
  2438. addedLength: 0,
  2439. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2440. lengths: createTypedArray('float32', getDefaultCurveSegments()),
  2441. };
  2442. }
  2443. return poolFactory(8, create);
  2444. }());
  2445. const segmentsLengthPool = (function () {
  2446. function create() {
  2447. return {
  2448. lengths: [],
  2449. totalLength: 0,
  2450. };
  2451. }
  2452. function release(element) {
  2453. var i;
  2454. var len = element.lengths.length;
  2455. for (i = 0; i < len; i += 1) {
  2456. bezierLengthPool.release(element.lengths[i]);
  2457. }
  2458. element.lengths.length = 0;
  2459. }
  2460. return poolFactory(8, create, release);
  2461. }());
  2462. function bezFunction() {
  2463. var math = Math;
  2464. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2465. var det1 = (x1 * y2) + (y1 * x3) + (x2 * y3) - (x3 * y2) - (y3 * x1) - (x2 * y1);
  2466. return det1 > -0.001 && det1 < 0.001;
  2467. }
  2468. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2469. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2470. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2471. }
  2472. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2473. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2474. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2475. var diffDist;
  2476. if (dist1 > dist2) {
  2477. if (dist1 > dist3) {
  2478. diffDist = dist1 - dist2 - dist3;
  2479. } else {
  2480. diffDist = dist3 - dist2 - dist1;
  2481. }
  2482. } else if (dist3 > dist2) {
  2483. diffDist = dist3 - dist2 - dist1;
  2484. } else {
  2485. diffDist = dist2 - dist1 - dist3;
  2486. }
  2487. return diffDist > -0.0001 && diffDist < 0.0001;
  2488. }
  2489. var getBezierLength = (function () {
  2490. return function (pt1, pt2, pt3, pt4) {
  2491. var curveSegments = getDefaultCurveSegments();
  2492. var k;
  2493. var i;
  2494. var len;
  2495. var ptCoord;
  2496. var perc;
  2497. var addedLength = 0;
  2498. var ptDistance;
  2499. var point = [];
  2500. var lastPoint = [];
  2501. var lengthData = bezierLengthPool.newElement();
  2502. len = pt3.length;
  2503. for (k = 0; k < curveSegments; k += 1) {
  2504. perc = k / (curveSegments - 1);
  2505. ptDistance = 0;
  2506. for (i = 0; i < len; i += 1) {
  2507. 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];
  2508. point[i] = ptCoord;
  2509. if (lastPoint[i] !== null) {
  2510. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2511. }
  2512. lastPoint[i] = point[i];
  2513. }
  2514. if (ptDistance) {
  2515. ptDistance = bmSqrt(ptDistance);
  2516. addedLength += ptDistance;
  2517. }
  2518. lengthData.percents[k] = perc;
  2519. lengthData.lengths[k] = addedLength;
  2520. }
  2521. lengthData.addedLength = addedLength;
  2522. return lengthData;
  2523. };
  2524. }());
  2525. function getSegmentsLength(shapeData) {
  2526. var segmentsLength = segmentsLengthPool.newElement();
  2527. var closed = shapeData.c;
  2528. var pathV = shapeData.v;
  2529. var pathO = shapeData.o;
  2530. var pathI = shapeData.i;
  2531. var i;
  2532. var len = shapeData._length;
  2533. var lengths = segmentsLength.lengths;
  2534. var totalLength = 0;
  2535. for (i = 0; i < len - 1; i += 1) {
  2536. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2537. totalLength += lengths[i].addedLength;
  2538. }
  2539. if (closed && len) {
  2540. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2541. totalLength += lengths[i].addedLength;
  2542. }
  2543. segmentsLength.totalLength = totalLength;
  2544. return segmentsLength;
  2545. }
  2546. function BezierData(length) {
  2547. this.segmentLength = 0;
  2548. this.points = new Array(length);
  2549. }
  2550. function PointData(partial, point) {
  2551. this.partialLength = partial;
  2552. this.point = point;
  2553. }
  2554. var buildBezierData = (function () {
  2555. var storedData = {};
  2556. return function (pt1, pt2, pt3, pt4) {
  2557. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2558. if (!storedData[bezierName]) {
  2559. var curveSegments = getDefaultCurveSegments();
  2560. var k;
  2561. var i;
  2562. var len;
  2563. var ptCoord;
  2564. var perc;
  2565. var addedLength = 0;
  2566. var ptDistance;
  2567. var point;
  2568. var lastPoint = null;
  2569. 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])) {
  2570. curveSegments = 2;
  2571. }
  2572. var bezierData = new BezierData(curveSegments);
  2573. len = pt3.length;
  2574. for (k = 0; k < curveSegments; k += 1) {
  2575. point = createSizedArray(len);
  2576. perc = k / (curveSegments - 1);
  2577. ptDistance = 0;
  2578. for (i = 0; i < len; i += 1) {
  2579. 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];
  2580. point[i] = ptCoord;
  2581. if (lastPoint !== null) {
  2582. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2583. }
  2584. }
  2585. ptDistance = bmSqrt(ptDistance);
  2586. addedLength += ptDistance;
  2587. bezierData.points[k] = new PointData(ptDistance, point);
  2588. lastPoint = point;
  2589. }
  2590. bezierData.segmentLength = addedLength;
  2591. storedData[bezierName] = bezierData;
  2592. }
  2593. return storedData[bezierName];
  2594. };
  2595. }());
  2596. function getDistancePerc(perc, bezierData) {
  2597. var percents = bezierData.percents;
  2598. var lengths = bezierData.lengths;
  2599. var len = percents.length;
  2600. var initPos = bmFloor((len - 1) * perc);
  2601. var lengthPos = perc * bezierData.addedLength;
  2602. var lPerc = 0;
  2603. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2604. return percents[initPos];
  2605. }
  2606. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2607. var flag = true;
  2608. while (flag) {
  2609. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2610. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2611. flag = false;
  2612. } else {
  2613. initPos += dir;
  2614. }
  2615. if (initPos < 0 || initPos >= len - 1) {
  2616. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2617. if (initPos === len - 1) {
  2618. return percents[initPos];
  2619. }
  2620. flag = false;
  2621. }
  2622. }
  2623. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2624. }
  2625. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2626. var t1 = getDistancePerc(percent, bezierData);
  2627. var u1 = 1 - t1;
  2628. 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;
  2629. 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;
  2630. return [ptX, ptY];
  2631. }
  2632. var bezierSegmentPoints = createTypedArray('float32', 8);
  2633. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2634. if (startPerc < 0) {
  2635. startPerc = 0;
  2636. } else if (startPerc > 1) {
  2637. startPerc = 1;
  2638. }
  2639. var t0 = getDistancePerc(startPerc, bezierData);
  2640. endPerc = endPerc > 1 ? 1 : endPerc;
  2641. var t1 = getDistancePerc(endPerc, bezierData);
  2642. var i;
  2643. var len = pt1.length;
  2644. var u0 = 1 - t0;
  2645. var u1 = 1 - t1;
  2646. var u0u0u0 = u0 * u0 * u0;
  2647. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2648. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2649. var t0t0t0 = t0 * t0 * t0;
  2650. //
  2651. var u0u0u1 = u0 * u0 * u1;
  2652. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2653. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2654. var t0t0t1 = t0 * t0 * t1;
  2655. //
  2656. var u0u1u1 = u0 * u1 * u1;
  2657. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2658. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2659. var t0t1t1 = t0 * t1 * t1;
  2660. //
  2661. var u1u1u1 = u1 * u1 * u1;
  2662. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2663. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2664. var t1t1t1 = t1 * t1 * t1;
  2665. for (i = 0; i < len; i += 1) {
  2666. 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
  2667. 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
  2668. 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
  2669. 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
  2670. }
  2671. return bezierSegmentPoints;
  2672. }
  2673. return {
  2674. getSegmentsLength: getSegmentsLength,
  2675. getNewSegment: getNewSegment,
  2676. getPointInSegment: getPointInSegment,
  2677. buildBezierData: buildBezierData,
  2678. pointOnLine2D: pointOnLine2D,
  2679. pointOnLine3D: pointOnLine3D,
  2680. };
  2681. }
  2682. const bez = bezFunction();
  2683. var initFrame = initialDefaultFrame;
  2684. var mathAbs = Math.abs;
  2685. function interpolateValue(frameNum, caching) {
  2686. var offsetTime = this.offsetTime;
  2687. var newValue;
  2688. if (this.propType === 'multidimensional') {
  2689. newValue = createTypedArray('float32', this.pv.length);
  2690. }
  2691. var iterationIndex = caching.lastIndex;
  2692. var i = iterationIndex;
  2693. var len = this.keyframes.length - 1;
  2694. var flag = true;
  2695. var keyData;
  2696. var nextKeyData;
  2697. var keyframeMetadata;
  2698. while (flag) {
  2699. keyData = this.keyframes[i];
  2700. nextKeyData = this.keyframes[i + 1];
  2701. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2702. if (keyData.h) {
  2703. keyData = nextKeyData;
  2704. }
  2705. iterationIndex = 0;
  2706. break;
  2707. }
  2708. if ((nextKeyData.t - offsetTime) > frameNum) {
  2709. iterationIndex = i;
  2710. break;
  2711. }
  2712. if (i < len - 1) {
  2713. i += 1;
  2714. } else {
  2715. iterationIndex = 0;
  2716. flag = false;
  2717. }
  2718. }
  2719. keyframeMetadata = this.keyframesMetadata[i] || {};
  2720. var k;
  2721. var kLen;
  2722. var perc;
  2723. var jLen;
  2724. var j;
  2725. var fnc;
  2726. var nextKeyTime = nextKeyData.t - offsetTime;
  2727. var keyTime = keyData.t - offsetTime;
  2728. var endValue;
  2729. if (keyData.to) {
  2730. if (!keyframeMetadata.bezierData) {
  2731. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2732. }
  2733. var bezierData = keyframeMetadata.bezierData;
  2734. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2735. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2736. kLen = bezierData.points[ind].point.length;
  2737. for (k = 0; k < kLen; k += 1) {
  2738. newValue[k] = bezierData.points[ind].point[k];
  2739. }
  2740. // caching._lastKeyframeIndex = -1;
  2741. } else {
  2742. if (keyframeMetadata.__fnct) {
  2743. fnc = keyframeMetadata.__fnct;
  2744. } else {
  2745. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2746. keyframeMetadata.__fnct = fnc;
  2747. }
  2748. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2749. var distanceInLine = bezierData.segmentLength * perc;
  2750. var segmentPerc;
  2751. var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0;
  2752. j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0;
  2753. flag = true;
  2754. jLen = bezierData.points.length;
  2755. while (flag) {
  2756. addedLength += bezierData.points[j].partialLength;
  2757. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2758. kLen = bezierData.points[j].point.length;
  2759. for (k = 0; k < kLen; k += 1) {
  2760. newValue[k] = bezierData.points[j].point[k];
  2761. }
  2762. break;
  2763. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2764. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2765. kLen = bezierData.points[j].point.length;
  2766. for (k = 0; k < kLen; k += 1) {
  2767. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2768. }
  2769. break;
  2770. }
  2771. if (j < jLen - 1) {
  2772. j += 1;
  2773. } else {
  2774. flag = false;
  2775. }
  2776. }
  2777. caching._lastPoint = j;
  2778. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2779. caching._lastKeyframeIndex = i;
  2780. }
  2781. } else {
  2782. var outX;
  2783. var outY;
  2784. var inX;
  2785. var inY;
  2786. var keyValue;
  2787. len = keyData.s.length;
  2788. endValue = nextKeyData.s || keyData.e;
  2789. if (this.sh && keyData.h !== 1) {
  2790. if (frameNum >= nextKeyTime) {
  2791. newValue[0] = endValue[0];
  2792. newValue[1] = endValue[1];
  2793. newValue[2] = endValue[2];
  2794. } else if (frameNum <= keyTime) {
  2795. newValue[0] = keyData.s[0];
  2796. newValue[1] = keyData.s[1];
  2797. newValue[2] = keyData.s[2];
  2798. } else {
  2799. var quatStart = createQuaternion(keyData.s);
  2800. var quatEnd = createQuaternion(endValue);
  2801. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2802. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2803. }
  2804. } else {
  2805. for (i = 0; i < len; i += 1) {
  2806. if (keyData.h !== 1) {
  2807. if (frameNum >= nextKeyTime) {
  2808. perc = 1;
  2809. } else if (frameNum < keyTime) {
  2810. perc = 0;
  2811. } else {
  2812. if (keyData.o.x.constructor === Array) {
  2813. if (!keyframeMetadata.__fnct) {
  2814. keyframeMetadata.__fnct = [];
  2815. }
  2816. if (!keyframeMetadata.__fnct[i]) {
  2817. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2818. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2819. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2820. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2821. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2822. keyframeMetadata.__fnct[i] = fnc;
  2823. } else {
  2824. fnc = keyframeMetadata.__fnct[i];
  2825. }
  2826. } else if (!keyframeMetadata.__fnct) {
  2827. outX = keyData.o.x;
  2828. outY = keyData.o.y;
  2829. inX = keyData.i.x;
  2830. inY = keyData.i.y;
  2831. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2832. keyData.keyframeMetadata = fnc;
  2833. } else {
  2834. fnc = keyframeMetadata.__fnct;
  2835. }
  2836. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2837. }
  2838. }
  2839. endValue = nextKeyData.s || keyData.e;
  2840. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2841. if (this.propType === 'multidimensional') {
  2842. newValue[i] = keyValue;
  2843. } else {
  2844. newValue = keyValue;
  2845. }
  2846. }
  2847. }
  2848. }
  2849. caching.lastIndex = iterationIndex;
  2850. return newValue;
  2851. }
  2852. // based on @Toji's https://github.com/toji/gl-matrix/
  2853. function slerp(a, b, t) {
  2854. var out = [];
  2855. var ax = a[0];
  2856. var ay = a[1];
  2857. var az = a[2];
  2858. var aw = a[3];
  2859. var bx = b[0];
  2860. var by = b[1];
  2861. var bz = b[2];
  2862. var bw = b[3];
  2863. var omega;
  2864. var cosom;
  2865. var sinom;
  2866. var scale0;
  2867. var scale1;
  2868. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2869. if (cosom < 0.0) {
  2870. cosom = -cosom;
  2871. bx = -bx;
  2872. by = -by;
  2873. bz = -bz;
  2874. bw = -bw;
  2875. }
  2876. if ((1.0 - cosom) > 0.000001) {
  2877. omega = Math.acos(cosom);
  2878. sinom = Math.sin(omega);
  2879. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2880. scale1 = Math.sin(t * omega) / sinom;
  2881. } else {
  2882. scale0 = 1.0 - t;
  2883. scale1 = t;
  2884. }
  2885. out[0] = scale0 * ax + scale1 * bx;
  2886. out[1] = scale0 * ay + scale1 * by;
  2887. out[2] = scale0 * az + scale1 * bz;
  2888. out[3] = scale0 * aw + scale1 * bw;
  2889. return out;
  2890. }
  2891. function quaternionToEuler(out, quat) {
  2892. var qx = quat[0];
  2893. var qy = quat[1];
  2894. var qz = quat[2];
  2895. var qw = quat[3];
  2896. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2897. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2898. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2899. out[0] = heading / degToRads;
  2900. out[1] = attitude / degToRads;
  2901. out[2] = bank / degToRads;
  2902. }
  2903. function createQuaternion(values) {
  2904. var heading = values[0] * degToRads;
  2905. var attitude = values[1] * degToRads;
  2906. var bank = values[2] * degToRads;
  2907. var c1 = Math.cos(heading / 2);
  2908. var c2 = Math.cos(attitude / 2);
  2909. var c3 = Math.cos(bank / 2);
  2910. var s1 = Math.sin(heading / 2);
  2911. var s2 = Math.sin(attitude / 2);
  2912. var s3 = Math.sin(bank / 2);
  2913. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2914. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2915. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2916. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2917. return [x, y, z, w];
  2918. }
  2919. function getValueAtCurrentTime() {
  2920. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2921. var initTime = this.keyframes[0].t - this.offsetTime;
  2922. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2923. if (!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))) {
  2924. if (this._caching.lastFrame >= frameNum) {
  2925. this._caching._lastKeyframeIndex = -1;
  2926. this._caching.lastIndex = 0;
  2927. }
  2928. var renderResult = this.interpolateValue(frameNum, this._caching);
  2929. this.pv = renderResult;
  2930. }
  2931. this._caching.lastFrame = frameNum;
  2932. return this.pv;
  2933. }
  2934. function setVValue(val) {
  2935. var multipliedValue;
  2936. if (this.propType === 'unidimensional') {
  2937. multipliedValue = val * this.mult;
  2938. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  2939. this.v = multipliedValue;
  2940. this._mdf = true;
  2941. }
  2942. } else {
  2943. var i = 0;
  2944. var len = this.v.length;
  2945. while (i < len) {
  2946. multipliedValue = val[i] * this.mult;
  2947. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  2948. this.v[i] = multipliedValue;
  2949. this._mdf = true;
  2950. }
  2951. i += 1;
  2952. }
  2953. }
  2954. }
  2955. function processEffectsSequence() {
  2956. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  2957. return;
  2958. }
  2959. if (this.lock) {
  2960. this.setVValue(this.pv);
  2961. return;
  2962. }
  2963. this.lock = true;
  2964. this._mdf = this._isFirstFrame;
  2965. var i;
  2966. var len = this.effectsSequence.length;
  2967. var finalValue = this.kf ? this.pv : this.data.k;
  2968. for (i = 0; i < len; i += 1) {
  2969. finalValue = this.effectsSequence[i](finalValue);
  2970. }
  2971. this.setVValue(finalValue);
  2972. this._isFirstFrame = false;
  2973. this.lock = false;
  2974. this.frameId = this.elem.globalData.frameId;
  2975. }
  2976. function addEffect(effectFunction) {
  2977. this.effectsSequence.push(effectFunction);
  2978. this.container.addDynamicProperty(this);
  2979. }
  2980. function ValueProperty(elem, data, mult, container) {
  2981. this.propType = 'unidimensional';
  2982. this.mult = mult || 1;
  2983. this.data = data;
  2984. this.v = mult ? data.k * mult : data.k;
  2985. this.pv = data.k;
  2986. this._mdf = false;
  2987. this.elem = elem;
  2988. this.container = container;
  2989. this.comp = elem.comp;
  2990. this.k = false;
  2991. this.kf = false;
  2992. this.vel = 0;
  2993. this.effectsSequence = [];
  2994. this._isFirstFrame = true;
  2995. this.getValue = processEffectsSequence;
  2996. this.setVValue = setVValue;
  2997. this.addEffect = addEffect;
  2998. }
  2999. function MultiDimensionalProperty(elem, data, mult, container) {
  3000. this.propType = 'multidimensional';
  3001. this.mult = mult || 1;
  3002. this.data = data;
  3003. this._mdf = false;
  3004. this.elem = elem;
  3005. this.container = container;
  3006. this.comp = elem.comp;
  3007. this.k = false;
  3008. this.kf = false;
  3009. this.frameId = -1;
  3010. var i;
  3011. var len = data.k.length;
  3012. this.v = createTypedArray('float32', len);
  3013. this.pv = createTypedArray('float32', len);
  3014. this.vel = createTypedArray('float32', len);
  3015. for (i = 0; i < len; i += 1) {
  3016. this.v[i] = data.k[i] * this.mult;
  3017. this.pv[i] = data.k[i];
  3018. }
  3019. this._isFirstFrame = true;
  3020. this.effectsSequence = [];
  3021. this.getValue = processEffectsSequence;
  3022. this.setVValue = setVValue;
  3023. this.addEffect = addEffect;
  3024. }
  3025. function KeyframedValueProperty(elem, data, mult, container) {
  3026. this.propType = 'unidimensional';
  3027. this.keyframes = data.k;
  3028. this.keyframesMetadata = [];
  3029. this.offsetTime = elem.data.st;
  3030. this.frameId = -1;
  3031. this._caching = {
  3032. lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1,
  3033. };
  3034. this.k = true;
  3035. this.kf = true;
  3036. this.data = data;
  3037. this.mult = mult || 1;
  3038. this.elem = elem;
  3039. this.container = container;
  3040. this.comp = elem.comp;
  3041. this.v = initFrame;
  3042. this.pv = initFrame;
  3043. this._isFirstFrame = true;
  3044. this.getValue = processEffectsSequence;
  3045. this.setVValue = setVValue;
  3046. this.interpolateValue = interpolateValue;
  3047. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3048. this.addEffect = addEffect;
  3049. }
  3050. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3051. this.propType = 'multidimensional';
  3052. var i;
  3053. var len = data.k.length;
  3054. var s;
  3055. var e;
  3056. var to;
  3057. var ti;
  3058. for (i = 0; i < len - 1; i += 1) {
  3059. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3060. s = data.k[i].s;
  3061. e = data.k[i + 1].s;
  3062. to = data.k[i].to;
  3063. ti = data.k[i].ti;
  3064. 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]))) {
  3065. data.k[i].to = null;
  3066. data.k[i].ti = null;
  3067. }
  3068. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3069. if (s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) {
  3070. data.k[i].to = null;
  3071. data.k[i].ti = null;
  3072. }
  3073. }
  3074. }
  3075. }
  3076. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3077. this.data = data;
  3078. this.keyframes = data.k;
  3079. this.keyframesMetadata = [];
  3080. this.offsetTime = elem.data.st;
  3081. this.k = true;
  3082. this.kf = true;
  3083. this._isFirstFrame = true;
  3084. this.mult = mult || 1;
  3085. this.elem = elem;
  3086. this.container = container;
  3087. this.comp = elem.comp;
  3088. this.getValue = processEffectsSequence;
  3089. this.setVValue = setVValue;
  3090. this.interpolateValue = interpolateValue;
  3091. this.frameId = -1;
  3092. var arrLen = data.k[0].s.length;
  3093. this.v = createTypedArray('float32', arrLen);
  3094. this.pv = createTypedArray('float32', arrLen);
  3095. for (i = 0; i < arrLen; i += 1) {
  3096. this.v[i] = initFrame;
  3097. this.pv[i] = initFrame;
  3098. }
  3099. this._caching = { lastFrame: initFrame, lastIndex: 0, value: createTypedArray('float32', arrLen) };
  3100. this.addEffect = addEffect;
  3101. }
  3102. const PropertyFactory = (function () {
  3103. function getProp(elem, data, type, mult, container) {
  3104. if (data.sid) {
  3105. data = elem.globalData.slotManager.getProp(data);
  3106. }
  3107. var p;
  3108. if (!data.k.length) {
  3109. p = new ValueProperty(elem, data, mult, container);
  3110. } else if (typeof (data.k[0]) === 'number') {
  3111. p = new MultiDimensionalProperty(elem, data, mult, container);
  3112. } else {
  3113. switch (type) {
  3114. case 0:
  3115. p = new KeyframedValueProperty(elem, data, mult, container);
  3116. break;
  3117. case 1:
  3118. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3119. break;
  3120. default:
  3121. break;
  3122. }
  3123. }
  3124. if (p.effectsSequence.length) {
  3125. container.addDynamicProperty(p);
  3126. }
  3127. return p;
  3128. }
  3129. var ob = {
  3130. getProp: getProp,
  3131. };
  3132. return ob;
  3133. }());
  3134. function DynamicPropertyContainer() {}
  3135. DynamicPropertyContainer.prototype = {
  3136. addDynamicProperty: function (prop) {
  3137. if (this.dynamicProperties.indexOf(prop) === -1) {
  3138. this.dynamicProperties.push(prop);
  3139. this.container.addDynamicProperty(this);
  3140. this._isAnimated = true;
  3141. }
  3142. },
  3143. iterateDynamicProperties: function () {
  3144. this._mdf = false;
  3145. var i;
  3146. var len = this.dynamicProperties.length;
  3147. for (i = 0; i < len; i += 1) {
  3148. this.dynamicProperties[i].getValue();
  3149. if (this.dynamicProperties[i]._mdf) {
  3150. this._mdf = true;
  3151. }
  3152. }
  3153. },
  3154. initDynamicPropertyContainer: function (container) {
  3155. this.container = container;
  3156. this.dynamicProperties = [];
  3157. this._mdf = false;
  3158. this._isAnimated = false;
  3159. },
  3160. };
  3161. const pointPool = (function () {
  3162. function create() {
  3163. return createTypedArray('float32', 2);
  3164. }
  3165. return poolFactory(8, create);
  3166. }());
  3167. function ShapePath() {
  3168. this.c = false;
  3169. this._length = 0;
  3170. this._maxLength = 8;
  3171. this.v = createSizedArray(this._maxLength);
  3172. this.o = createSizedArray(this._maxLength);
  3173. this.i = createSizedArray(this._maxLength);
  3174. }
  3175. ShapePath.prototype.setPathData = function (closed, len) {
  3176. this.c = closed;
  3177. this.setLength(len);
  3178. var i = 0;
  3179. while (i < len) {
  3180. this.v[i] = pointPool.newElement();
  3181. this.o[i] = pointPool.newElement();
  3182. this.i[i] = pointPool.newElement();
  3183. i += 1;
  3184. }
  3185. };
  3186. ShapePath.prototype.setLength = function (len) {
  3187. while (this._maxLength < len) {
  3188. this.doubleArrayLength();
  3189. }
  3190. this._length = len;
  3191. };
  3192. ShapePath.prototype.doubleArrayLength = function () {
  3193. this.v = this.v.concat(createSizedArray(this._maxLength));
  3194. this.i = this.i.concat(createSizedArray(this._maxLength));
  3195. this.o = this.o.concat(createSizedArray(this._maxLength));
  3196. this._maxLength *= 2;
  3197. };
  3198. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3199. var arr;
  3200. this._length = Math.max(this._length, pos + 1);
  3201. if (this._length >= this._maxLength) {
  3202. this.doubleArrayLength();
  3203. }
  3204. switch (type) {
  3205. case 'v':
  3206. arr = this.v;
  3207. break;
  3208. case 'i':
  3209. arr = this.i;
  3210. break;
  3211. case 'o':
  3212. arr = this.o;
  3213. break;
  3214. default:
  3215. arr = [];
  3216. break;
  3217. }
  3218. if (!arr[pos] || (arr[pos] && !replace)) {
  3219. arr[pos] = pointPool.newElement();
  3220. }
  3221. arr[pos][0] = x;
  3222. arr[pos][1] = y;
  3223. };
  3224. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3225. this.setXYAt(vX, vY, 'v', pos, replace);
  3226. this.setXYAt(oX, oY, 'o', pos, replace);
  3227. this.setXYAt(iX, iY, 'i', pos, replace);
  3228. };
  3229. ShapePath.prototype.reverse = function () {
  3230. var newPath = new ShapePath();
  3231. newPath.setPathData(this.c, this._length);
  3232. var vertices = this.v;
  3233. var outPoints = this.o;
  3234. var inPoints = this.i;
  3235. var init = 0;
  3236. if (this.c) {
  3237. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3238. init = 1;
  3239. }
  3240. var cnt = this._length - 1;
  3241. var len = this._length;
  3242. var i;
  3243. for (i = init; i < len; i += 1) {
  3244. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3245. cnt -= 1;
  3246. }
  3247. return newPath;
  3248. };
  3249. ShapePath.prototype.length = function () {
  3250. return this._length;
  3251. };
  3252. const shapePool = (function () {
  3253. function create() {
  3254. return new ShapePath();
  3255. }
  3256. function release(shapePath) {
  3257. var len = shapePath._length;
  3258. var i;
  3259. for (i = 0; i < len; i += 1) {
  3260. pointPool.release(shapePath.v[i]);
  3261. pointPool.release(shapePath.i[i]);
  3262. pointPool.release(shapePath.o[i]);
  3263. shapePath.v[i] = null;
  3264. shapePath.i[i] = null;
  3265. shapePath.o[i] = null;
  3266. }
  3267. shapePath._length = 0;
  3268. shapePath.c = false;
  3269. }
  3270. function clone(shape) {
  3271. var cloned = factory.newElement();
  3272. var i;
  3273. var len = shape._length === undefined ? shape.v.length : shape._length;
  3274. cloned.setLength(len);
  3275. cloned.c = shape.c;
  3276. for (i = 0; i < len; i += 1) {
  3277. 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);
  3278. }
  3279. return cloned;
  3280. }
  3281. var factory = poolFactory(4, create, release);
  3282. factory.clone = clone;
  3283. return factory;
  3284. }());
  3285. function ShapeCollection() {
  3286. this._length = 0;
  3287. this._maxLength = 4;
  3288. this.shapes = createSizedArray(this._maxLength);
  3289. }
  3290. ShapeCollection.prototype.addShape = function (shapeData) {
  3291. if (this._length === this._maxLength) {
  3292. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3293. this._maxLength *= 2;
  3294. }
  3295. this.shapes[this._length] = shapeData;
  3296. this._length += 1;
  3297. };
  3298. ShapeCollection.prototype.releaseShapes = function () {
  3299. var i;
  3300. for (i = 0; i < this._length; i += 1) {
  3301. shapePool.release(this.shapes[i]);
  3302. }
  3303. this._length = 0;
  3304. };
  3305. const shapeCollectionPool = (function () {
  3306. var ob = {
  3307. newShapeCollection: newShapeCollection,
  3308. release: release,
  3309. };
  3310. var _length = 0;
  3311. var _maxLength = 4;
  3312. var pool = createSizedArray(_maxLength);
  3313. function newShapeCollection() {
  3314. var shapeCollection;
  3315. if (_length) {
  3316. _length -= 1;
  3317. shapeCollection = pool[_length];
  3318. } else {
  3319. shapeCollection = new ShapeCollection();
  3320. }
  3321. return shapeCollection;
  3322. }
  3323. function release(shapeCollection) {
  3324. var i;
  3325. var len = shapeCollection._length;
  3326. for (i = 0; i < len; i += 1) {
  3327. shapePool.release(shapeCollection.shapes[i]);
  3328. }
  3329. shapeCollection._length = 0;
  3330. if (_length === _maxLength) {
  3331. pool = pooling.double(pool);
  3332. _maxLength *= 2;
  3333. }
  3334. pool[_length] = shapeCollection;
  3335. _length += 1;
  3336. }
  3337. return ob;
  3338. }());
  3339. const ShapePropertyFactory = (function () {
  3340. var initFrame = -999999;
  3341. function interpolateShape(frameNum, previousValue, caching) {
  3342. var iterationIndex = caching.lastIndex;
  3343. var keyPropS;
  3344. var keyPropE;
  3345. var isHold;
  3346. var j;
  3347. var k;
  3348. var jLen;
  3349. var kLen;
  3350. var perc;
  3351. var vertexValue;
  3352. var kf = this.keyframes;
  3353. if (frameNum < kf[0].t - this.offsetTime) {
  3354. keyPropS = kf[0].s[0];
  3355. isHold = true;
  3356. iterationIndex = 0;
  3357. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3358. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3359. /* if(kf[kf.length - 1].s){
  3360. keyPropS = kf[kf.length - 1].s[0];
  3361. }else{
  3362. keyPropS = kf[kf.length - 2].e[0];
  3363. } */
  3364. isHold = true;
  3365. } else {
  3366. var i = iterationIndex;
  3367. var len = kf.length - 1;
  3368. var flag = true;
  3369. var keyData;
  3370. var nextKeyData;
  3371. var keyframeMetadata;
  3372. while (flag) {
  3373. keyData = kf[i];
  3374. nextKeyData = kf[i + 1];
  3375. if ((nextKeyData.t - this.offsetTime) > frameNum) {
  3376. break;
  3377. }
  3378. if (i < len - 1) {
  3379. i += 1;
  3380. } else {
  3381. flag = false;
  3382. }
  3383. }
  3384. keyframeMetadata = this.keyframesMetadata[i] || {};
  3385. isHold = keyData.h === 1;
  3386. iterationIndex = i;
  3387. if (!isHold) {
  3388. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3389. perc = 1;
  3390. } else if (frameNum < keyData.t - this.offsetTime) {
  3391. perc = 0;
  3392. } else {
  3393. var fnc;
  3394. if (keyframeMetadata.__fnct) {
  3395. fnc = keyframeMetadata.__fnct;
  3396. } else {
  3397. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3398. keyframeMetadata.__fnct = fnc;
  3399. }
  3400. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / ((nextKeyData.t - this.offsetTime) - (keyData.t - this.offsetTime)));
  3401. }
  3402. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3403. }
  3404. keyPropS = keyData.s[0];
  3405. }
  3406. jLen = previousValue._length;
  3407. kLen = keyPropS.i[0].length;
  3408. caching.lastIndex = iterationIndex;
  3409. for (j = 0; j < jLen; j += 1) {
  3410. for (k = 0; k < kLen; k += 1) {
  3411. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3412. previousValue.i[j][k] = vertexValue;
  3413. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3414. previousValue.o[j][k] = vertexValue;
  3415. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3416. previousValue.v[j][k] = vertexValue;
  3417. }
  3418. }
  3419. }
  3420. function interpolateShapeCurrentTime() {
  3421. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3422. var initTime = this.keyframes[0].t - this.offsetTime;
  3423. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3424. var lastFrame = this._caching.lastFrame;
  3425. if (!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))) {
  3426. /// /
  3427. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3428. this.interpolateShape(frameNum, this.pv, this._caching);
  3429. /// /
  3430. }
  3431. this._caching.lastFrame = frameNum;
  3432. return this.pv;
  3433. }
  3434. function resetShape() {
  3435. this.paths = this.localShapeCollection;
  3436. }
  3437. function shapesEqual(shape1, shape2) {
  3438. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3439. return false;
  3440. }
  3441. var i;
  3442. var len = shape1._length;
  3443. for (i = 0; i < len; i += 1) {
  3444. if (shape1.v[i][0] !== shape2.v[i][0]
  3445. || shape1.v[i][1] !== shape2.v[i][1]
  3446. || shape1.o[i][0] !== shape2.o[i][0]
  3447. || shape1.o[i][1] !== shape2.o[i][1]
  3448. || shape1.i[i][0] !== shape2.i[i][0]
  3449. || shape1.i[i][1] !== shape2.i[i][1]) {
  3450. return false;
  3451. }
  3452. }
  3453. return true;
  3454. }
  3455. function setVValue(newPath) {
  3456. if (!shapesEqual(this.v, newPath)) {
  3457. this.v = shapePool.clone(newPath);
  3458. this.localShapeCollection.releaseShapes();
  3459. this.localShapeCollection.addShape(this.v);
  3460. this._mdf = true;
  3461. this.paths = this.localShapeCollection;
  3462. }
  3463. }
  3464. function processEffectsSequence() {
  3465. if (this.elem.globalData.frameId === this.frameId) {
  3466. return;
  3467. } if (!this.effectsSequence.length) {
  3468. this._mdf = false;
  3469. return;
  3470. }
  3471. if (this.lock) {
  3472. this.setVValue(this.pv);
  3473. return;
  3474. }
  3475. this.lock = true;
  3476. this._mdf = false;
  3477. var finalValue;
  3478. if (this.kf) {
  3479. finalValue = this.pv;
  3480. } else if (this.data.ks) {
  3481. finalValue = this.data.ks.k;
  3482. } else {
  3483. finalValue = this.data.pt.k;
  3484. }
  3485. var i;
  3486. var len = this.effectsSequence.length;
  3487. for (i = 0; i < len; i += 1) {
  3488. finalValue = this.effectsSequence[i](finalValue);
  3489. }
  3490. this.setVValue(finalValue);
  3491. this.lock = false;
  3492. this.frameId = this.elem.globalData.frameId;
  3493. }
  3494. function ShapeProperty(elem, data, type) {
  3495. this.propType = 'shape';
  3496. this.comp = elem.comp;
  3497. this.container = elem;
  3498. this.elem = elem;
  3499. this.data = data;
  3500. this.k = false;
  3501. this.kf = false;
  3502. this._mdf = false;
  3503. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3504. this.v = shapePool.clone(pathData);
  3505. this.pv = shapePool.clone(this.v);
  3506. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3507. this.paths = this.localShapeCollection;
  3508. this.paths.addShape(this.v);
  3509. this.reset = resetShape;
  3510. this.effectsSequence = [];
  3511. }
  3512. function addEffect(effectFunction) {
  3513. this.effectsSequence.push(effectFunction);
  3514. this.container.addDynamicProperty(this);
  3515. }
  3516. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3517. ShapeProperty.prototype.getValue = processEffectsSequence;
  3518. ShapeProperty.prototype.setVValue = setVValue;
  3519. ShapeProperty.prototype.addEffect = addEffect;
  3520. function KeyframedShapeProperty(elem, data, type) {
  3521. this.propType = 'shape';
  3522. this.comp = elem.comp;
  3523. this.elem = elem;
  3524. this.container = elem;
  3525. this.offsetTime = elem.data.st;
  3526. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3527. this.keyframesMetadata = [];
  3528. this.k = true;
  3529. this.kf = true;
  3530. var len = this.keyframes[0].s[0].i.length;
  3531. this.v = shapePool.newElement();
  3532. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3533. this.pv = shapePool.clone(this.v);
  3534. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3535. this.paths = this.localShapeCollection;
  3536. this.paths.addShape(this.v);
  3537. this.lastFrame = initFrame;
  3538. this.reset = resetShape;
  3539. this._caching = { lastFrame: initFrame, lastIndex: 0 };
  3540. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3541. }
  3542. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3543. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3544. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3545. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3546. var EllShapeProperty = (function () {
  3547. var cPoint = roundCorner;
  3548. function EllShapePropertyFactory(elem, data) {
  3549. this.v = shapePool.newElement();
  3550. this.v.setPathData(true, 4);
  3551. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3552. this.paths = this.localShapeCollection;
  3553. this.localShapeCollection.addShape(this.v);
  3554. this.d = data.d;
  3555. this.elem = elem;
  3556. this.comp = elem.comp;
  3557. this.frameId = -1;
  3558. this.initDynamicPropertyContainer(elem);
  3559. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3560. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3561. if (this.dynamicProperties.length) {
  3562. this.k = true;
  3563. } else {
  3564. this.k = false;
  3565. this.convertEllToPath();
  3566. }
  3567. }
  3568. EllShapePropertyFactory.prototype = {
  3569. reset: resetShape,
  3570. getValue: function () {
  3571. if (this.elem.globalData.frameId === this.frameId) {
  3572. return;
  3573. }
  3574. this.frameId = this.elem.globalData.frameId;
  3575. this.iterateDynamicProperties();
  3576. if (this._mdf) {
  3577. this.convertEllToPath();
  3578. }
  3579. },
  3580. convertEllToPath: function () {
  3581. var p0 = this.p.v[0];
  3582. var p1 = this.p.v[1];
  3583. var s0 = this.s.v[0] / 2;
  3584. var s1 = this.s.v[1] / 2;
  3585. var _cw = this.d !== 3;
  3586. var _v = this.v;
  3587. _v.v[0][0] = p0;
  3588. _v.v[0][1] = p1 - s1;
  3589. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3590. _v.v[1][1] = p1;
  3591. _v.v[2][0] = p0;
  3592. _v.v[2][1] = p1 + s1;
  3593. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3594. _v.v[3][1] = p1;
  3595. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3596. _v.i[0][1] = p1 - s1;
  3597. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3598. _v.i[1][1] = p1 - s1 * cPoint;
  3599. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3600. _v.i[2][1] = p1 + s1;
  3601. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3602. _v.i[3][1] = p1 + s1 * cPoint;
  3603. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3604. _v.o[0][1] = p1 - s1;
  3605. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3606. _v.o[1][1] = p1 + s1 * cPoint;
  3607. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3608. _v.o[2][1] = p1 + s1;
  3609. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3610. _v.o[3][1] = p1 - s1 * cPoint;
  3611. },
  3612. };
  3613. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3614. return EllShapePropertyFactory;
  3615. }());
  3616. var StarShapeProperty = (function () {
  3617. function StarShapePropertyFactory(elem, data) {
  3618. this.v = shapePool.newElement();
  3619. this.v.setPathData(true, 0);
  3620. this.elem = elem;
  3621. this.comp = elem.comp;
  3622. this.data = data;
  3623. this.frameId = -1;
  3624. this.d = data.d;
  3625. this.initDynamicPropertyContainer(elem);
  3626. if (data.sy === 1) {
  3627. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3628. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3629. this.convertToPath = this.convertStarToPath;
  3630. } else {
  3631. this.convertToPath = this.convertPolygonToPath;
  3632. }
  3633. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3634. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3635. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3636. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3637. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3638. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3639. this.localShapeCollection.addShape(this.v);
  3640. this.paths = this.localShapeCollection;
  3641. if (this.dynamicProperties.length) {
  3642. this.k = true;
  3643. } else {
  3644. this.k = false;
  3645. this.convertToPath();
  3646. }
  3647. }
  3648. StarShapePropertyFactory.prototype = {
  3649. reset: resetShape,
  3650. getValue: function () {
  3651. if (this.elem.globalData.frameId === this.frameId) {
  3652. return;
  3653. }
  3654. this.frameId = this.elem.globalData.frameId;
  3655. this.iterateDynamicProperties();
  3656. if (this._mdf) {
  3657. this.convertToPath();
  3658. }
  3659. },
  3660. convertStarToPath: function () {
  3661. var numPts = Math.floor(this.pt.v) * 2;
  3662. var angle = (Math.PI * 2) / numPts;
  3663. /* this.v.v.length = numPts;
  3664. this.v.i.length = numPts;
  3665. this.v.o.length = numPts; */
  3666. var longFlag = true;
  3667. var longRad = this.or.v;
  3668. var shortRad = this.ir.v;
  3669. var longRound = this.os.v;
  3670. var shortRound = this.is.v;
  3671. var longPerimSegment = (2 * Math.PI * longRad) / (numPts * 2);
  3672. var shortPerimSegment = (2 * Math.PI * shortRad) / (numPts * 2);
  3673. var i;
  3674. var rad;
  3675. var roundness;
  3676. var perimSegment;
  3677. var currentAng = -Math.PI / 2;
  3678. currentAng += this.r.v;
  3679. var dir = this.data.d === 3 ? -1 : 1;
  3680. this.v._length = 0;
  3681. for (i = 0; i < numPts; i += 1) {
  3682. rad = longFlag ? longRad : shortRad;
  3683. roundness = longFlag ? longRound : shortRound;
  3684. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3685. var x = rad * Math.cos(currentAng);
  3686. var y = rad * Math.sin(currentAng);
  3687. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3688. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3689. x += +this.p.v[0];
  3690. y += +this.p.v[1];
  3691. 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);
  3692. /* this.v.v[i] = [x,y];
  3693. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3694. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3695. this.v._length = numPts; */
  3696. longFlag = !longFlag;
  3697. currentAng += angle * dir;
  3698. }
  3699. },
  3700. convertPolygonToPath: function () {
  3701. var numPts = Math.floor(this.pt.v);
  3702. var angle = (Math.PI * 2) / numPts;
  3703. var rad = this.or.v;
  3704. var roundness = this.os.v;
  3705. var perimSegment = (2 * Math.PI * rad) / (numPts * 4);
  3706. var i;
  3707. var currentAng = -Math.PI * 0.5;
  3708. var dir = this.data.d === 3 ? -1 : 1;
  3709. currentAng += this.r.v;
  3710. this.v._length = 0;
  3711. for (i = 0; i < numPts; i += 1) {
  3712. var x = rad * Math.cos(currentAng);
  3713. var y = rad * Math.sin(currentAng);
  3714. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3715. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3716. x += +this.p.v[0];
  3717. y += +this.p.v[1];
  3718. 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);
  3719. currentAng += angle * dir;
  3720. }
  3721. this.paths.length = 0;
  3722. this.paths[0] = this.v;
  3723. },
  3724. };
  3725. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3726. return StarShapePropertyFactory;
  3727. }());
  3728. var RectShapeProperty = (function () {
  3729. function RectShapePropertyFactory(elem, data) {
  3730. this.v = shapePool.newElement();
  3731. this.v.c = true;
  3732. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3733. this.localShapeCollection.addShape(this.v);
  3734. this.paths = this.localShapeCollection;
  3735. this.elem = elem;
  3736. this.comp = elem.comp;
  3737. this.frameId = -1;
  3738. this.d = data.d;
  3739. this.initDynamicPropertyContainer(elem);
  3740. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3741. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3742. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3743. if (this.dynamicProperties.length) {
  3744. this.k = true;
  3745. } else {
  3746. this.k = false;
  3747. this.convertRectToPath();
  3748. }
  3749. }
  3750. RectShapePropertyFactory.prototype = {
  3751. convertRectToPath: function () {
  3752. var p0 = this.p.v[0];
  3753. var p1 = this.p.v[1];
  3754. var v0 = this.s.v[0] / 2;
  3755. var v1 = this.s.v[1] / 2;
  3756. var round = bmMin(v0, v1, this.r.v);
  3757. var cPoint = round * (1 - roundCorner);
  3758. this.v._length = 0;
  3759. if (this.d === 2 || this.d === 1) {
  3760. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3761. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3762. if (round !== 0) {
  3763. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3764. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3765. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3766. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3767. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3768. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3769. } else {
  3770. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3771. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3772. }
  3773. } else {
  3774. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3775. if (round !== 0) {
  3776. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3777. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3778. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3779. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3780. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3781. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3782. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3783. } else {
  3784. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3785. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3786. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3787. }
  3788. }
  3789. },
  3790. getValue: function () {
  3791. if (this.elem.globalData.frameId === this.frameId) {
  3792. return;
  3793. }
  3794. this.frameId = this.elem.globalData.frameId;
  3795. this.iterateDynamicProperties();
  3796. if (this._mdf) {
  3797. this.convertRectToPath();
  3798. }
  3799. },
  3800. reset: resetShape,
  3801. };
  3802. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3803. return RectShapePropertyFactory;
  3804. }());
  3805. function getShapeProp(elem, data, type) {
  3806. var prop;
  3807. if (type === 3 || type === 4) {
  3808. var dataProp = type === 3 ? data.pt : data.ks;
  3809. var keys = dataProp.k;
  3810. if (keys.length) {
  3811. prop = new KeyframedShapeProperty(elem, data, type);
  3812. } else {
  3813. prop = new ShapeProperty(elem, data, type);
  3814. }
  3815. } else if (type === 5) {
  3816. prop = new RectShapeProperty(elem, data);
  3817. } else if (type === 6) {
  3818. prop = new EllShapeProperty(elem, data);
  3819. } else if (type === 7) {
  3820. prop = new StarShapeProperty(elem, data);
  3821. }
  3822. if (prop.k) {
  3823. elem.addDynamicProperty(prop);
  3824. }
  3825. return prop;
  3826. }
  3827. function getConstructorFunction() {
  3828. return ShapeProperty;
  3829. }
  3830. function getKeyframedConstructorFunction() {
  3831. return KeyframedShapeProperty;
  3832. }
  3833. var ob = {};
  3834. ob.getShapeProp = getShapeProp;
  3835. ob.getConstructorFunction = getConstructorFunction;
  3836. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3837. return ob;
  3838. }());
  3839. /*!
  3840. Transformation Matrix v2.0
  3841. (c) Epistemex 2014-2015
  3842. www.epistemex.com
  3843. By Ken Fyrstenberg
  3844. Contributions by leeoniya.
  3845. License: MIT, header required.
  3846. */
  3847. /**
  3848. * 2D transformation matrix object initialized with identity matrix.
  3849. *
  3850. * The matrix can synchronize a canvas context by supplying the context
  3851. * as an argument, or later apply current absolute transform to an
  3852. * existing context.
  3853. *
  3854. * All values are handled as floating point values.
  3855. *
  3856. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3857. * @prop {number} a - scale x
  3858. * @prop {number} b - shear y
  3859. * @prop {number} c - shear x
  3860. * @prop {number} d - scale y
  3861. * @prop {number} e - translate x
  3862. * @prop {number} f - translate y
  3863. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3864. * @constructor
  3865. */
  3866. const Matrix = (function () {
  3867. var _cos = Math.cos;
  3868. var _sin = Math.sin;
  3869. var _tan = Math.tan;
  3870. var _rnd = Math.round;
  3871. function reset() {
  3872. this.props[0] = 1;
  3873. this.props[1] = 0;
  3874. this.props[2] = 0;
  3875. this.props[3] = 0;
  3876. this.props[4] = 0;
  3877. this.props[5] = 1;
  3878. this.props[6] = 0;
  3879. this.props[7] = 0;
  3880. this.props[8] = 0;
  3881. this.props[9] = 0;
  3882. this.props[10] = 1;
  3883. this.props[11] = 0;
  3884. this.props[12] = 0;
  3885. this.props[13] = 0;
  3886. this.props[14] = 0;
  3887. this.props[15] = 1;
  3888. return this;
  3889. }
  3890. function rotate(angle) {
  3891. if (angle === 0) {
  3892. return this;
  3893. }
  3894. var mCos = _cos(angle);
  3895. var mSin = _sin(angle);
  3896. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3897. }
  3898. function rotateX(angle) {
  3899. if (angle === 0) {
  3900. return this;
  3901. }
  3902. var mCos = _cos(angle);
  3903. var mSin = _sin(angle);
  3904. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3905. }
  3906. function rotateY(angle) {
  3907. if (angle === 0) {
  3908. return this;
  3909. }
  3910. var mCos = _cos(angle);
  3911. var mSin = _sin(angle);
  3912. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3913. }
  3914. function rotateZ(angle) {
  3915. if (angle === 0) {
  3916. return this;
  3917. }
  3918. var mCos = _cos(angle);
  3919. var mSin = _sin(angle);
  3920. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3921. }
  3922. function shear(sx, sy) {
  3923. return this._t(1, sy, sx, 1, 0, 0);
  3924. }
  3925. function skew(ax, ay) {
  3926. return this.shear(_tan(ax), _tan(ay));
  3927. }
  3928. function skewFromAxis(ax, angle) {
  3929. var mCos = _cos(angle);
  3930. var mSin = _sin(angle);
  3931. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3932. ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3933. ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3934. // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  3935. }
  3936. function scale(sx, sy, sz) {
  3937. if (!sz && sz !== 0) {
  3938. sz = 1;
  3939. }
  3940. if (sx === 1 && sy === 1 && sz === 1) {
  3941. return this;
  3942. }
  3943. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  3944. }
  3945. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  3946. this.props[0] = a;
  3947. this.props[1] = b;
  3948. this.props[2] = c;
  3949. this.props[3] = d;
  3950. this.props[4] = e;
  3951. this.props[5] = f;
  3952. this.props[6] = g;
  3953. this.props[7] = h;
  3954. this.props[8] = i;
  3955. this.props[9] = j;
  3956. this.props[10] = k;
  3957. this.props[11] = l;
  3958. this.props[12] = m;
  3959. this.props[13] = n;
  3960. this.props[14] = o;
  3961. this.props[15] = p;
  3962. return this;
  3963. }
  3964. function translate(tx, ty, tz) {
  3965. tz = tz || 0;
  3966. if (tx !== 0 || ty !== 0 || tz !== 0) {
  3967. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  3968. }
  3969. return this;
  3970. }
  3971. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  3972. var _p = this.props;
  3973. 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) {
  3974. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  3975. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  3976. _p[12] = _p[12] * a2 + _p[15] * m2;
  3977. _p[13] = _p[13] * f2 + _p[15] * n2;
  3978. _p[14] = _p[14] * k2 + _p[15] * o2;
  3979. _p[15] *= p2;
  3980. // }
  3981. this._identityCalculated = false;
  3982. return this;
  3983. }
  3984. var a1 = _p[0];
  3985. var b1 = _p[1];
  3986. var c1 = _p[2];
  3987. var d1 = _p[3];
  3988. var e1 = _p[4];
  3989. var f1 = _p[5];
  3990. var g1 = _p[6];
  3991. var h1 = _p[7];
  3992. var i1 = _p[8];
  3993. var j1 = _p[9];
  3994. var k1 = _p[10];
  3995. var l1 = _p[11];
  3996. var m1 = _p[12];
  3997. var n1 = _p[13];
  3998. var o1 = _p[14];
  3999. var p1 = _p[15];
  4000. /* matrix order (canvas compatible):
  4001. * ace
  4002. * bdf
  4003. * 001
  4004. */
  4005. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  4006. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  4007. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  4008. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  4009. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  4010. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  4011. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  4012. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  4013. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  4014. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  4015. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  4016. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  4017. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  4018. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  4019. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  4020. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  4021. this._identityCalculated = false;
  4022. return this;
  4023. }
  4024. function multiply(matrix) {
  4025. var matrixProps = matrix.props;
  4026. return this.transform(
  4027. matrixProps[0],
  4028. matrixProps[1],
  4029. matrixProps[2],
  4030. matrixProps[3],
  4031. matrixProps[4],
  4032. matrixProps[5],
  4033. matrixProps[6],
  4034. matrixProps[7],
  4035. matrixProps[8],
  4036. matrixProps[9],
  4037. matrixProps[10],
  4038. matrixProps[11],
  4039. matrixProps[12],
  4040. matrixProps[13],
  4041. matrixProps[14],
  4042. matrixProps[15]
  4043. );
  4044. }
  4045. function isIdentity() {
  4046. if (!this._identityCalculated) {
  4047. 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);
  4048. this._identityCalculated = true;
  4049. }
  4050. return this._identity;
  4051. }
  4052. function equals(matr) {
  4053. var i = 0;
  4054. while (i < 16) {
  4055. if (matr.props[i] !== this.props[i]) {
  4056. return false;
  4057. }
  4058. i += 1;
  4059. }
  4060. return true;
  4061. }
  4062. function clone(matr) {
  4063. var i;
  4064. for (i = 0; i < 16; i += 1) {
  4065. matr.props[i] = this.props[i];
  4066. }
  4067. return matr;
  4068. }
  4069. function cloneFromProps(props) {
  4070. var i;
  4071. for (i = 0; i < 16; i += 1) {
  4072. this.props[i] = props[i];
  4073. }
  4074. }
  4075. function applyToPoint(x, y, z) {
  4076. return {
  4077. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4078. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4079. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4080. };
  4081. /* return {
  4082. x: x * me.a + y * me.c + me.e,
  4083. y: x * me.b + y * me.d + me.f
  4084. }; */
  4085. }
  4086. function applyToX(x, y, z) {
  4087. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4088. }
  4089. function applyToY(x, y, z) {
  4090. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4091. }
  4092. function applyToZ(x, y, z) {
  4093. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4094. }
  4095. function getInverseMatrix() {
  4096. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4097. var a = this.props[5] / determinant;
  4098. var b = -this.props[1] / determinant;
  4099. var c = -this.props[4] / determinant;
  4100. var d = this.props[0] / determinant;
  4101. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4102. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4103. var inverseMatrix = new Matrix();
  4104. inverseMatrix.props[0] = a;
  4105. inverseMatrix.props[1] = b;
  4106. inverseMatrix.props[4] = c;
  4107. inverseMatrix.props[5] = d;
  4108. inverseMatrix.props[12] = e;
  4109. inverseMatrix.props[13] = f;
  4110. return inverseMatrix;
  4111. }
  4112. function inversePoint(pt) {
  4113. var inverseMatrix = this.getInverseMatrix();
  4114. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4115. }
  4116. function inversePoints(pts) {
  4117. var i;
  4118. var len = pts.length;
  4119. var retPts = [];
  4120. for (i = 0; i < len; i += 1) {
  4121. retPts[i] = inversePoint(pts[i]);
  4122. }
  4123. return retPts;
  4124. }
  4125. function applyToTriplePoints(pt1, pt2, pt3) {
  4126. var arr = createTypedArray('float32', 6);
  4127. if (this.isIdentity()) {
  4128. arr[0] = pt1[0];
  4129. arr[1] = pt1[1];
  4130. arr[2] = pt2[0];
  4131. arr[3] = pt2[1];
  4132. arr[4] = pt3[0];
  4133. arr[5] = pt3[1];
  4134. } else {
  4135. var p0 = this.props[0];
  4136. var p1 = this.props[1];
  4137. var p4 = this.props[4];
  4138. var p5 = this.props[5];
  4139. var p12 = this.props[12];
  4140. var p13 = this.props[13];
  4141. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4142. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4143. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4144. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4145. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4146. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4147. }
  4148. return arr;
  4149. }
  4150. function applyToPointArray(x, y, z) {
  4151. var arr;
  4152. if (this.isIdentity()) {
  4153. arr = [x, y, z];
  4154. } else {
  4155. arr = [
  4156. x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4157. x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4158. x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4159. ];
  4160. }
  4161. return arr;
  4162. }
  4163. function applyToPointStringified(x, y) {
  4164. if (this.isIdentity()) {
  4165. return x + ',' + y;
  4166. }
  4167. var _p = this.props;
  4168. 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;
  4169. }
  4170. function toCSS() {
  4171. // 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.
  4172. /* if(this.isIdentity()) {
  4173. return '';
  4174. } */
  4175. var i = 0;
  4176. var props = this.props;
  4177. var cssValue = 'matrix3d(';
  4178. var v = 10000;
  4179. while (i < 16) {
  4180. cssValue += _rnd(props[i] * v) / v;
  4181. cssValue += i === 15 ? ')' : ',';
  4182. i += 1;
  4183. }
  4184. return cssValue;
  4185. }
  4186. function roundMatrixProperty(val) {
  4187. var v = 10000;
  4188. if ((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
  4189. return _rnd(val * v) / v;
  4190. }
  4191. return val;
  4192. }
  4193. function to2dCSS() {
  4194. // 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.
  4195. /* if(this.isIdentity()) {
  4196. return '';
  4197. } */
  4198. var props = this.props;
  4199. var _a = roundMatrixProperty(props[0]);
  4200. var _b = roundMatrixProperty(props[1]);
  4201. var _c = roundMatrixProperty(props[4]);
  4202. var _d = roundMatrixProperty(props[5]);
  4203. var _e = roundMatrixProperty(props[12]);
  4204. var _f = roundMatrixProperty(props[13]);
  4205. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4206. }
  4207. return function () {
  4208. this.reset = reset;
  4209. this.rotate = rotate;
  4210. this.rotateX = rotateX;
  4211. this.rotateY = rotateY;
  4212. this.rotateZ = rotateZ;
  4213. this.skew = skew;
  4214. this.skewFromAxis = skewFromAxis;
  4215. this.shear = shear;
  4216. this.scale = scale;
  4217. this.setTransform = setTransform;
  4218. this.translate = translate;
  4219. this.transform = transform;
  4220. this.multiply = multiply;
  4221. this.applyToPoint = applyToPoint;
  4222. this.applyToX = applyToX;
  4223. this.applyToY = applyToY;
  4224. this.applyToZ = applyToZ;
  4225. this.applyToPointArray = applyToPointArray;
  4226. this.applyToTriplePoints = applyToTriplePoints;
  4227. this.applyToPointStringified = applyToPointStringified;
  4228. this.toCSS = toCSS;
  4229. this.to2dCSS = to2dCSS;
  4230. this.clone = clone;
  4231. this.cloneFromProps = cloneFromProps;
  4232. this.equals = equals;
  4233. this.inversePoints = inversePoints;
  4234. this.inversePoint = inversePoint;
  4235. this.getInverseMatrix = getInverseMatrix;
  4236. this._t = this.transform;
  4237. this.isIdentity = isIdentity;
  4238. this._identity = true;
  4239. this._identityCalculated = false;
  4240. this.props = createTypedArray('float32', 16);
  4241. this.reset();
  4242. };
  4243. }());
  4244. const lottie = {};
  4245. var standalone = '__[STANDALONE]__';
  4246. var animationData = '__[ANIMATIONDATA]__';
  4247. var renderer = '';
  4248. function setLocation(href) {
  4249. setLocationHref(href);
  4250. }
  4251. function searchAnimations() {
  4252. if (standalone === true) {
  4253. animationManager.searchAnimations(animationData, standalone, renderer);
  4254. } else {
  4255. animationManager.searchAnimations();
  4256. }
  4257. }
  4258. function setSubframeRendering(flag) {
  4259. setSubframeEnabled(flag);
  4260. }
  4261. function setPrefix(prefix) {
  4262. setIdPrefix(prefix);
  4263. }
  4264. function loadAnimation(params) {
  4265. if (standalone === true) {
  4266. params.animationData = JSON.parse(animationData);
  4267. }
  4268. return animationManager.loadAnimation(params);
  4269. }
  4270. function setQuality(value) {
  4271. if (typeof value === 'string') {
  4272. switch (value) {
  4273. case 'high':
  4274. setDefaultCurveSegments(200);
  4275. break;
  4276. default:
  4277. case 'medium':
  4278. setDefaultCurveSegments(50);
  4279. break;
  4280. case 'low':
  4281. setDefaultCurveSegments(10);
  4282. break;
  4283. }
  4284. } else if (!isNaN(value) && value > 1) {
  4285. setDefaultCurveSegments(value);
  4286. }
  4287. if (getDefaultCurveSegments() >= 50) {
  4288. roundValues(false);
  4289. } else {
  4290. roundValues(true);
  4291. }
  4292. }
  4293. function inBrowser() {
  4294. return typeof navigator !== 'undefined';
  4295. }
  4296. function installPlugin(type, plugin) {
  4297. if (type === 'expressions') {
  4298. setExpressionsPlugin(plugin);
  4299. }
  4300. }
  4301. function getFactory(name) {
  4302. switch (name) {
  4303. case 'propertyFactory':
  4304. return PropertyFactory;
  4305. case 'shapePropertyFactory':
  4306. return ShapePropertyFactory;
  4307. case 'matrix':
  4308. return Matrix;
  4309. default:
  4310. return null;
  4311. }
  4312. }
  4313. lottie.play = animationManager.play;
  4314. lottie.pause = animationManager.pause;
  4315. lottie.setLocationHref = setLocation;
  4316. lottie.togglePause = animationManager.togglePause;
  4317. lottie.setSpeed = animationManager.setSpeed;
  4318. lottie.setDirection = animationManager.setDirection;
  4319. lottie.stop = animationManager.stop;
  4320. lottie.searchAnimations = searchAnimations;
  4321. lottie.registerAnimation = animationManager.registerAnimation;
  4322. lottie.loadAnimation = loadAnimation;
  4323. lottie.setSubframeRendering = setSubframeRendering;
  4324. lottie.resize = animationManager.resize;
  4325. // lottie.start = start;
  4326. lottie.goToAndStop = animationManager.goToAndStop;
  4327. lottie.destroy = animationManager.destroy;
  4328. lottie.setQuality = setQuality;
  4329. lottie.inBrowser = inBrowser;
  4330. lottie.installPlugin = installPlugin;
  4331. lottie.freeze = animationManager.freeze;
  4332. lottie.unfreeze = animationManager.unfreeze;
  4333. lottie.setVolume = animationManager.setVolume;
  4334. lottie.mute = animationManager.mute;
  4335. lottie.unmute = animationManager.unmute;
  4336. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4337. lottie.useWebWorker = setWebWorker;
  4338. lottie.setIDPrefix = setPrefix;
  4339. lottie.__getFactory = getFactory;
  4340. lottie.version = '[[BM_VERSION]]';
  4341. function checkReady() {
  4342. if (document.readyState === 'complete') {
  4343. clearInterval(readyStateCheckInterval);
  4344. searchAnimations();
  4345. }
  4346. }
  4347. function getQueryVariable(variable) {
  4348. var vars = queryString.split('&');
  4349. for (var i = 0; i < vars.length; i += 1) {
  4350. var pair = vars[i].split('=');
  4351. if (decodeURIComponent(pair[0]) == variable) { // eslint-disable-line eqeqeq
  4352. return decodeURIComponent(pair[1]);
  4353. }
  4354. }
  4355. return null;
  4356. }
  4357. var queryString = '';
  4358. if (standalone) {
  4359. var scripts = document.getElementsByTagName('script');
  4360. var index = scripts.length - 1;
  4361. var myScript = scripts[index] || {
  4362. src: '',
  4363. };
  4364. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4365. renderer = getQueryVariable('renderer');
  4366. }
  4367. var readyStateCheckInterval = setInterval(checkReady, 100);
  4368. // this adds bodymovin to the window object for backwards compatibility
  4369. try {
  4370. if (!(typeof exports === 'object' && typeof module !== 'undefined')
  4371. && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4372. ) {
  4373. window.bodymovin = lottie;
  4374. }
  4375. } catch (err) {
  4376. //
  4377. }
  4378. const ShapeModifiers = (function () {
  4379. var ob = {};
  4380. var modifiers = {};
  4381. ob.registerModifier = registerModifier;
  4382. ob.getModifier = getModifier;
  4383. function registerModifier(nm, factory) {
  4384. if (!modifiers[nm]) {
  4385. modifiers[nm] = factory;
  4386. }
  4387. }
  4388. function getModifier(nm, elem, data) {
  4389. return new modifiers[nm](elem, data);
  4390. }
  4391. return ob;
  4392. }());
  4393. function ShapeModifier() {}
  4394. ShapeModifier.prototype.initModifierProperties = function () {};
  4395. ShapeModifier.prototype.addShapeToModifier = function () {};
  4396. ShapeModifier.prototype.addShape = function (data) {
  4397. if (!this.closed) {
  4398. // 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.
  4399. data.sh.container.addDynamicProperty(data.sh);
  4400. var shapeData = { shape: data.sh, data: data, localShapeCollection: shapeCollectionPool.newShapeCollection() };
  4401. this.shapes.push(shapeData);
  4402. this.addShapeToModifier(shapeData);
  4403. if (this._isAnimated) {
  4404. data.setAsAnimated();
  4405. }
  4406. }
  4407. };
  4408. ShapeModifier.prototype.init = function (elem, data) {
  4409. this.shapes = [];
  4410. this.elem = elem;
  4411. this.initDynamicPropertyContainer(elem);
  4412. this.initModifierProperties(elem, data);
  4413. this.frameId = initialDefaultFrame;
  4414. this.closed = false;
  4415. this.k = false;
  4416. if (this.dynamicProperties.length) {
  4417. this.k = true;
  4418. } else {
  4419. this.getValue(true);
  4420. }
  4421. };
  4422. ShapeModifier.prototype.processKeys = function () {
  4423. if (this.elem.globalData.frameId === this.frameId) {
  4424. return;
  4425. }
  4426. this.frameId = this.elem.globalData.frameId;
  4427. this.iterateDynamicProperties();
  4428. };
  4429. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4430. function TrimModifier() {
  4431. }
  4432. extendPrototype([ShapeModifier], TrimModifier);
  4433. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4434. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4435. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4436. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4437. this.sValue = 0;
  4438. this.eValue = 0;
  4439. this.getValue = this.processKeys;
  4440. this.m = data.m;
  4441. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4442. };
  4443. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4444. shapeData.pathsData = [];
  4445. };
  4446. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4447. var segments = [];
  4448. if (e <= 1) {
  4449. segments.push({
  4450. s: s,
  4451. e: e,
  4452. });
  4453. } else if (s >= 1) {
  4454. segments.push({
  4455. s: s - 1,
  4456. e: e - 1,
  4457. });
  4458. } else {
  4459. segments.push({
  4460. s: s,
  4461. e: 1,
  4462. });
  4463. segments.push({
  4464. s: 0,
  4465. e: e - 1,
  4466. });
  4467. }
  4468. var shapeSegments = [];
  4469. var i;
  4470. var len = segments.length;
  4471. var segmentOb;
  4472. for (i = 0; i < len; i += 1) {
  4473. segmentOb = segments[i];
  4474. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4475. var shapeS;
  4476. var shapeE;
  4477. if (segmentOb.s * totalModifierLength <= addedLength) {
  4478. shapeS = 0;
  4479. } else {
  4480. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4481. }
  4482. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4483. shapeE = 1;
  4484. } else {
  4485. shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength);
  4486. }
  4487. shapeSegments.push([shapeS, shapeE]);
  4488. }
  4489. }
  4490. if (!shapeSegments.length) {
  4491. shapeSegments.push([0, 0]);
  4492. }
  4493. return shapeSegments;
  4494. };
  4495. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4496. var i;
  4497. var len = pathsData.length;
  4498. for (i = 0; i < len; i += 1) {
  4499. segmentsLengthPool.release(pathsData[i]);
  4500. }
  4501. pathsData.length = 0;
  4502. return pathsData;
  4503. };
  4504. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4505. var s;
  4506. var e;
  4507. if (this._mdf || _isFirstFrame) {
  4508. var o = (this.o.v % 360) / 360;
  4509. if (o < 0) {
  4510. o += 1;
  4511. }
  4512. if (this.s.v > 1) {
  4513. s = 1 + o;
  4514. } else if (this.s.v < 0) {
  4515. s = 0 + o;
  4516. } else {
  4517. s = this.s.v + o;
  4518. }
  4519. if (this.e.v > 1) {
  4520. e = 1 + o;
  4521. } else if (this.e.v < 0) {
  4522. e = 0 + o;
  4523. } else {
  4524. e = this.e.v + o;
  4525. }
  4526. if (s > e) {
  4527. var _s = s;
  4528. s = e;
  4529. e = _s;
  4530. }
  4531. s = Math.round(s * 10000) * 0.0001;
  4532. e = Math.round(e * 10000) * 0.0001;
  4533. this.sValue = s;
  4534. this.eValue = e;
  4535. } else {
  4536. s = this.sValue;
  4537. e = this.eValue;
  4538. }
  4539. var shapePaths;
  4540. var i;
  4541. var len = this.shapes.length;
  4542. var j;
  4543. var jLen;
  4544. var pathsData;
  4545. var pathData;
  4546. var totalShapeLength;
  4547. var totalModifierLength = 0;
  4548. if (e === s) {
  4549. for (i = 0; i < len; i += 1) {
  4550. this.shapes[i].localShapeCollection.releaseShapes();
  4551. this.shapes[i].shape._mdf = true;
  4552. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4553. if (this._mdf) {
  4554. this.shapes[i].pathsData.length = 0;
  4555. }
  4556. }
  4557. } else if (!((e === 1 && s === 0) || (e === 0 && s === 1))) {
  4558. var segments = [];
  4559. var shapeData;
  4560. var localShapeCollection;
  4561. for (i = 0; i < len; i += 1) {
  4562. shapeData = this.shapes[i];
  4563. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4564. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4565. shapeData.shape.paths = shapeData.localShapeCollection;
  4566. } else {
  4567. shapePaths = shapeData.shape.paths;
  4568. jLen = shapePaths._length;
  4569. totalShapeLength = 0;
  4570. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4571. totalShapeLength = shapeData.totalShapeLength;
  4572. } else {
  4573. pathsData = this.releasePathsData(shapeData.pathsData);
  4574. for (j = 0; j < jLen; j += 1) {
  4575. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4576. pathsData.push(pathData);
  4577. totalShapeLength += pathData.totalLength;
  4578. }
  4579. shapeData.totalShapeLength = totalShapeLength;
  4580. shapeData.pathsData = pathsData;
  4581. }
  4582. totalModifierLength += totalShapeLength;
  4583. shapeData.shape._mdf = true;
  4584. }
  4585. }
  4586. var shapeS = s;
  4587. var shapeE = e;
  4588. var addedLength = 0;
  4589. var edges;
  4590. for (i = len - 1; i >= 0; i -= 1) {
  4591. shapeData = this.shapes[i];
  4592. if (shapeData.shape._mdf) {
  4593. localShapeCollection = shapeData.localShapeCollection;
  4594. localShapeCollection.releaseShapes();
  4595. // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4596. if (this.m === 2 && len > 1) {
  4597. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4598. addedLength += shapeData.totalShapeLength;
  4599. } else {
  4600. edges = [[shapeS, shapeE]];
  4601. }
  4602. jLen = edges.length;
  4603. for (j = 0; j < jLen; j += 1) {
  4604. shapeS = edges[j][0];
  4605. shapeE = edges[j][1];
  4606. segments.length = 0;
  4607. if (shapeE <= 1) {
  4608. segments.push({
  4609. s: shapeData.totalShapeLength * shapeS,
  4610. e: shapeData.totalShapeLength * shapeE,
  4611. });
  4612. } else if (shapeS >= 1) {
  4613. segments.push({
  4614. s: shapeData.totalShapeLength * (shapeS - 1),
  4615. e: shapeData.totalShapeLength * (shapeE - 1),
  4616. });
  4617. } else {
  4618. segments.push({
  4619. s: shapeData.totalShapeLength * shapeS,
  4620. e: shapeData.totalShapeLength,
  4621. });
  4622. segments.push({
  4623. s: 0,
  4624. e: shapeData.totalShapeLength * (shapeE - 1),
  4625. });
  4626. }
  4627. var newShapesData = this.addShapes(shapeData, segments[0]);
  4628. if (segments[0].s !== segments[0].e) {
  4629. if (segments.length > 1) {
  4630. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4631. if (lastShapeInCollection.c) {
  4632. var lastShape = newShapesData.pop();
  4633. this.addPaths(newShapesData, localShapeCollection);
  4634. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4635. } else {
  4636. this.addPaths(newShapesData, localShapeCollection);
  4637. newShapesData = this.addShapes(shapeData, segments[1]);
  4638. }
  4639. }
  4640. this.addPaths(newShapesData, localShapeCollection);
  4641. }
  4642. }
  4643. shapeData.shape.paths = localShapeCollection;
  4644. }
  4645. }
  4646. } else if (this._mdf) {
  4647. for (i = 0; i < len; i += 1) {
  4648. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4649. // Don't remove this even if it's losing cached info.
  4650. this.shapes[i].pathsData.length = 0;
  4651. this.shapes[i].shape._mdf = true;
  4652. }
  4653. }
  4654. };
  4655. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4656. var i;
  4657. var len = newPaths.length;
  4658. for (i = 0; i < len; i += 1) {
  4659. localShapeCollection.addShape(newPaths[i]);
  4660. }
  4661. };
  4662. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4663. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4664. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4665. if (newShape) {
  4666. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4667. }
  4668. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4669. };
  4670. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4671. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4672. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4673. if (newShape) {
  4674. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4675. }
  4676. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4677. };
  4678. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4679. var pathsData = shapeData.pathsData;
  4680. var shapePaths = shapeData.shape.paths.shapes;
  4681. var i;
  4682. var len = shapeData.shape.paths._length;
  4683. var j;
  4684. var jLen;
  4685. var addedLength = 0;
  4686. var currentLengthData;
  4687. var segmentCount;
  4688. var lengths;
  4689. var segment;
  4690. var shapes = [];
  4691. var initPos;
  4692. var newShape = true;
  4693. if (!shapePath) {
  4694. shapePath = shapePool.newElement();
  4695. segmentCount = 0;
  4696. initPos = 0;
  4697. } else {
  4698. segmentCount = shapePath._length;
  4699. initPos = shapePath._length;
  4700. }
  4701. shapes.push(shapePath);
  4702. for (i = 0; i < len; i += 1) {
  4703. lengths = pathsData[i].lengths;
  4704. shapePath.c = shapePaths[i].c;
  4705. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4706. for (j = 1; j < jLen; j += 1) {
  4707. currentLengthData = lengths[j - 1];
  4708. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4709. addedLength += currentLengthData.addedLength;
  4710. shapePath.c = false;
  4711. } else if (addedLength > shapeSegment.e) {
  4712. shapePath.c = false;
  4713. break;
  4714. } else {
  4715. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4716. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4717. newShape = false;
  4718. } else {
  4719. 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]);
  4720. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4721. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4722. newShape = false;
  4723. shapePath.c = false;
  4724. }
  4725. addedLength += currentLengthData.addedLength;
  4726. segmentCount += 1;
  4727. }
  4728. }
  4729. if (shapePaths[i].c && lengths.length) {
  4730. currentLengthData = lengths[j - 1];
  4731. if (addedLength <= shapeSegment.e) {
  4732. var segmentLength = lengths[j - 1].addedLength;
  4733. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4734. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4735. newShape = false;
  4736. } else {
  4737. 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]);
  4738. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4739. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4740. newShape = false;
  4741. shapePath.c = false;
  4742. }
  4743. } else {
  4744. shapePath.c = false;
  4745. }
  4746. addedLength += currentLengthData.addedLength;
  4747. segmentCount += 1;
  4748. }
  4749. if (shapePath._length) {
  4750. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4751. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4752. }
  4753. if (addedLength > shapeSegment.e) {
  4754. break;
  4755. }
  4756. if (i < len - 1) {
  4757. shapePath = shapePool.newElement();
  4758. newShape = true;
  4759. shapes.push(shapePath);
  4760. segmentCount = 0;
  4761. }
  4762. }
  4763. return shapes;
  4764. };
  4765. function PuckerAndBloatModifier() {}
  4766. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4767. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4768. this.getValue = this.processKeys;
  4769. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4770. this._isAnimated = !!this.amount.effectsSequence.length;
  4771. };
  4772. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4773. var percent = amount / 100;
  4774. var centerPoint = [0, 0];
  4775. var pathLength = path._length;
  4776. var i = 0;
  4777. for (i = 0; i < pathLength; i += 1) {
  4778. centerPoint[0] += path.v[i][0];
  4779. centerPoint[1] += path.v[i][1];
  4780. }
  4781. centerPoint[0] /= pathLength;
  4782. centerPoint[1] /= pathLength;
  4783. var clonedPath = shapePool.newElement();
  4784. clonedPath.c = path.c;
  4785. var vX;
  4786. var vY;
  4787. var oX;
  4788. var oY;
  4789. var iX;
  4790. var iY;
  4791. for (i = 0; i < pathLength; i += 1) {
  4792. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4793. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4794. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4795. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4796. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4797. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4798. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4799. }
  4800. return clonedPath;
  4801. };
  4802. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4803. var shapePaths;
  4804. var i;
  4805. var len = this.shapes.length;
  4806. var j;
  4807. var jLen;
  4808. var amount = this.amount.v;
  4809. if (amount !== 0) {
  4810. var shapeData;
  4811. var localShapeCollection;
  4812. for (i = 0; i < len; i += 1) {
  4813. shapeData = this.shapes[i];
  4814. localShapeCollection = shapeData.localShapeCollection;
  4815. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4816. localShapeCollection.releaseShapes();
  4817. shapeData.shape._mdf = true;
  4818. shapePaths = shapeData.shape.paths.shapes;
  4819. jLen = shapeData.shape.paths._length;
  4820. for (j = 0; j < jLen; j += 1) {
  4821. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4822. }
  4823. }
  4824. shapeData.shape.paths = shapeData.localShapeCollection;
  4825. }
  4826. }
  4827. if (!this.dynamicProperties.length) {
  4828. this._mdf = false;
  4829. }
  4830. };
  4831. const TransformPropertyFactory = (function () {
  4832. var defaultVector = [0, 0];
  4833. function applyToMatrix(mat) {
  4834. var _mdf = this._mdf;
  4835. this.iterateDynamicProperties();
  4836. this._mdf = this._mdf || _mdf;
  4837. if (this.a) {
  4838. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4839. }
  4840. if (this.s) {
  4841. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4842. }
  4843. if (this.sk) {
  4844. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4845. }
  4846. if (this.r) {
  4847. mat.rotate(-this.r.v);
  4848. } else {
  4849. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4850. .rotateY(this.or.v[1])
  4851. .rotateX(this.or.v[0]);
  4852. }
  4853. if (this.data.p.s) {
  4854. if (this.data.p.z) {
  4855. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4856. } else {
  4857. mat.translate(this.px.v, this.py.v, 0);
  4858. }
  4859. } else {
  4860. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4861. }
  4862. }
  4863. function processKeys(forceRender) {
  4864. if (this.elem.globalData.frameId === this.frameId) {
  4865. return;
  4866. }
  4867. if (this._isDirty) {
  4868. this.precalculateMatrix();
  4869. this._isDirty = false;
  4870. }
  4871. this.iterateDynamicProperties();
  4872. if (this._mdf || forceRender) {
  4873. var frameRate;
  4874. this.v.cloneFromProps(this.pre.props);
  4875. if (this.appliedTransformations < 1) {
  4876. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4877. }
  4878. if (this.appliedTransformations < 2) {
  4879. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4880. }
  4881. if (this.sk && this.appliedTransformations < 3) {
  4882. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4883. }
  4884. if (this.r && this.appliedTransformations < 4) {
  4885. this.v.rotate(-this.r.v);
  4886. } else if (!this.r && this.appliedTransformations < 4) {
  4887. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4888. .rotateY(this.or.v[1])
  4889. .rotateX(this.or.v[0]);
  4890. }
  4891. if (this.autoOriented) {
  4892. var v1;
  4893. var v2;
  4894. frameRate = this.elem.globalData.frameRate;
  4895. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4896. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4897. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4898. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4899. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4900. v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0);
  4901. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4902. } else {
  4903. v1 = this.p.pv;
  4904. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4905. }
  4906. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4907. v1 = [];
  4908. v2 = [];
  4909. var px = this.px;
  4910. var py = this.py;
  4911. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4912. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4913. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4914. v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate, 0);
  4915. v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate, 0);
  4916. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4917. v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate), 0);
  4918. v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate), 0);
  4919. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4920. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4921. } else {
  4922. v1 = [px.pv, py.pv];
  4923. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4924. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4925. }
  4926. } else {
  4927. v2 = defaultVector;
  4928. v1 = v2;
  4929. }
  4930. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4931. }
  4932. if (this.data.p && this.data.p.s) {
  4933. if (this.data.p.z) {
  4934. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4935. } else {
  4936. this.v.translate(this.px.v, this.py.v, 0);
  4937. }
  4938. } else {
  4939. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4940. }
  4941. }
  4942. this.frameId = this.elem.globalData.frameId;
  4943. }
  4944. function precalculateMatrix() {
  4945. this.appliedTransformations = 0;
  4946. this.pre.reset();
  4947. if (!this.a.effectsSequence.length) {
  4948. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4949. this.appliedTransformations = 1;
  4950. } else {
  4951. return;
  4952. }
  4953. if (!this.s.effectsSequence.length) {
  4954. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4955. this.appliedTransformations = 2;
  4956. } else {
  4957. return;
  4958. }
  4959. if (this.sk) {
  4960. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  4961. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  4962. this.appliedTransformations = 3;
  4963. } else {
  4964. return;
  4965. }
  4966. }
  4967. if (this.r) {
  4968. if (!this.r.effectsSequence.length) {
  4969. this.pre.rotate(-this.r.v);
  4970. this.appliedTransformations = 4;
  4971. }
  4972. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  4973. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4974. .rotateY(this.or.v[1])
  4975. .rotateX(this.or.v[0]);
  4976. this.appliedTransformations = 4;
  4977. }
  4978. }
  4979. function autoOrient() {
  4980. //
  4981. // var prevP = this.getValueAtTime();
  4982. }
  4983. function addDynamicProperty(prop) {
  4984. this._addDynamicProperty(prop);
  4985. this.elem.addDynamicProperty(prop);
  4986. this._isDirty = true;
  4987. }
  4988. function TransformProperty(elem, data, container) {
  4989. this.elem = elem;
  4990. this.frameId = -1;
  4991. this.propType = 'transform';
  4992. this.data = data;
  4993. this.v = new Matrix();
  4994. // Precalculated matrix with non animated properties
  4995. this.pre = new Matrix();
  4996. this.appliedTransformations = 0;
  4997. this.initDynamicPropertyContainer(container || elem);
  4998. if (data.p && data.p.s) {
  4999. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  5000. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  5001. if (data.p.z) {
  5002. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  5003. }
  5004. } else {
  5005. this.p = PropertyFactory.getProp(elem, data.p || { k: [0, 0, 0] }, 1, 0, this);
  5006. }
  5007. if (data.rx) {
  5008. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  5009. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  5010. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  5011. if (data.or.k[0].ti) {
  5012. var i;
  5013. var len = data.or.k.length;
  5014. for (i = 0; i < len; i += 1) {
  5015. data.or.k[i].to = null;
  5016. data.or.k[i].ti = null;
  5017. }
  5018. }
  5019. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  5020. // sh Indicates it needs to be capped between -180 and 180
  5021. this.or.sh = true;
  5022. } else {
  5023. this.r = PropertyFactory.getProp(elem, data.r || { k: 0 }, 0, degToRads, this);
  5024. }
  5025. if (data.sk) {
  5026. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  5027. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  5028. }
  5029. this.a = PropertyFactory.getProp(elem, data.a || { k: [0, 0, 0] }, 1, 0, this);
  5030. this.s = PropertyFactory.getProp(elem, data.s || { k: [100, 100, 100] }, 1, 0.01, this);
  5031. // 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.
  5032. if (data.o) {
  5033. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  5034. } else {
  5035. this.o = { _mdf: false, v: 1 };
  5036. }
  5037. this._isDirty = true;
  5038. if (!this.dynamicProperties.length) {
  5039. this.getValue(true);
  5040. }
  5041. }
  5042. TransformProperty.prototype = {
  5043. applyToMatrix: applyToMatrix,
  5044. getValue: processKeys,
  5045. precalculateMatrix: precalculateMatrix,
  5046. autoOrient: autoOrient,
  5047. };
  5048. extendPrototype([DynamicPropertyContainer], TransformProperty);
  5049. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  5050. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  5051. function getTransformProperty(elem, data, container) {
  5052. return new TransformProperty(elem, data, container);
  5053. }
  5054. return {
  5055. getTransformProperty: getTransformProperty,
  5056. };
  5057. }());
  5058. function RepeaterModifier() {}
  5059. extendPrototype([ShapeModifier], RepeaterModifier);
  5060. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5061. this.getValue = this.processKeys;
  5062. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5063. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5064. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5065. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5066. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5067. this.data = data;
  5068. if (!this.dynamicProperties.length) {
  5069. this.getValue(true);
  5070. }
  5071. this._isAnimated = !!this.dynamicProperties.length;
  5072. this.pMatrix = new Matrix();
  5073. this.rMatrix = new Matrix();
  5074. this.sMatrix = new Matrix();
  5075. this.tMatrix = new Matrix();
  5076. this.matrix = new Matrix();
  5077. };
  5078. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5079. var dir = inv ? -1 : 1;
  5080. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5081. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5082. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5083. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5084. rMatrix.rotate(-transform.r.v * dir * perc);
  5085. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5086. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5087. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5088. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5089. };
  5090. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5091. this.elem = elem;
  5092. this.arr = arr;
  5093. this.pos = pos;
  5094. this.elemsData = elemsData;
  5095. this._currentCopies = 0;
  5096. this._elements = [];
  5097. this._groups = [];
  5098. this.frameId = -1;
  5099. this.initDynamicPropertyContainer(elem);
  5100. this.initModifierProperties(elem, arr[pos]);
  5101. while (pos > 0) {
  5102. pos -= 1;
  5103. // this._elements.unshift(arr.splice(pos,1)[0]);
  5104. this._elements.unshift(arr[pos]);
  5105. }
  5106. if (this.dynamicProperties.length) {
  5107. this.k = true;
  5108. } else {
  5109. this.getValue(true);
  5110. }
  5111. };
  5112. RepeaterModifier.prototype.resetElements = function (elements) {
  5113. var i;
  5114. var len = elements.length;
  5115. for (i = 0; i < len; i += 1) {
  5116. elements[i]._processed = false;
  5117. if (elements[i].ty === 'gr') {
  5118. this.resetElements(elements[i].it);
  5119. }
  5120. }
  5121. };
  5122. RepeaterModifier.prototype.cloneElements = function (elements) {
  5123. var newElements = JSON.parse(JSON.stringify(elements));
  5124. this.resetElements(newElements);
  5125. return newElements;
  5126. };
  5127. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5128. var i;
  5129. var len = elements.length;
  5130. for (i = 0; i < len; i += 1) {
  5131. elements[i]._render = renderFlag;
  5132. if (elements[i].ty === 'gr') {
  5133. this.changeGroupRender(elements[i].it, renderFlag);
  5134. }
  5135. }
  5136. };
  5137. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5138. var items;
  5139. var itemsTransform;
  5140. var i;
  5141. var dir;
  5142. var cont;
  5143. var hasReloaded = false;
  5144. if (this._mdf || _isFirstFrame) {
  5145. var copies = Math.ceil(this.c.v);
  5146. if (this._groups.length < copies) {
  5147. while (this._groups.length < copies) {
  5148. var group = {
  5149. it: this.cloneElements(this._elements),
  5150. ty: 'gr',
  5151. };
  5152. group.it.push({
  5153. 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',
  5154. });
  5155. this.arr.splice(0, 0, group);
  5156. this._groups.splice(0, 0, group);
  5157. this._currentCopies += 1;
  5158. }
  5159. this.elem.reloadShapes();
  5160. hasReloaded = true;
  5161. }
  5162. cont = 0;
  5163. var renderFlag;
  5164. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5165. renderFlag = cont < copies;
  5166. this._groups[i]._render = renderFlag;
  5167. this.changeGroupRender(this._groups[i].it, renderFlag);
  5168. if (!renderFlag) {
  5169. var elems = this.elemsData[i].it;
  5170. var transformData = elems[elems.length - 1];
  5171. if (transformData.transform.op.v !== 0) {
  5172. transformData.transform.op._mdf = true;
  5173. transformData.transform.op.v = 0;
  5174. } else {
  5175. transformData.transform.op._mdf = false;
  5176. }
  5177. }
  5178. cont += 1;
  5179. }
  5180. this._currentCopies = copies;
  5181. /// /
  5182. var offset = this.o.v;
  5183. var offsetModulo = offset % 1;
  5184. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5185. var pProps = this.pMatrix.props;
  5186. var rProps = this.rMatrix.props;
  5187. var sProps = this.sMatrix.props;
  5188. this.pMatrix.reset();
  5189. this.rMatrix.reset();
  5190. this.sMatrix.reset();
  5191. this.tMatrix.reset();
  5192. this.matrix.reset();
  5193. var iteration = 0;
  5194. if (offset > 0) {
  5195. while (iteration < roundOffset) {
  5196. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5197. iteration += 1;
  5198. }
  5199. if (offsetModulo) {
  5200. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5201. iteration += offsetModulo;
  5202. }
  5203. } else if (offset < 0) {
  5204. while (iteration > roundOffset) {
  5205. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5206. iteration -= 1;
  5207. }
  5208. if (offsetModulo) {
  5209. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5210. iteration -= offsetModulo;
  5211. }
  5212. }
  5213. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5214. dir = this.data.m === 1 ? 1 : -1;
  5215. cont = this._currentCopies;
  5216. var j;
  5217. var jLen;
  5218. while (cont) {
  5219. items = this.elemsData[i].it;
  5220. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5221. jLen = itemsTransform.length;
  5222. items[items.length - 1].transform.mProps._mdf = true;
  5223. items[items.length - 1].transform.op._mdf = true;
  5224. items[items.length - 1].transform.op.v = this._currentCopies === 1
  5225. ? this.so.v
  5226. : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5227. if (iteration !== 0) {
  5228. if ((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)) {
  5229. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5230. }
  5231. 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]);
  5232. 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]);
  5233. 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]);
  5234. for (j = 0; j < jLen; j += 1) {
  5235. itemsTransform[j] = this.matrix.props[j];
  5236. }
  5237. this.matrix.reset();
  5238. } else {
  5239. this.matrix.reset();
  5240. for (j = 0; j < jLen; j += 1) {
  5241. itemsTransform[j] = this.matrix.props[j];
  5242. }
  5243. }
  5244. iteration += 1;
  5245. cont -= 1;
  5246. i += dir;
  5247. }
  5248. } else {
  5249. cont = this._currentCopies;
  5250. i = 0;
  5251. dir = 1;
  5252. while (cont) {
  5253. items = this.elemsData[i].it;
  5254. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5255. items[items.length - 1].transform.mProps._mdf = false;
  5256. items[items.length - 1].transform.op._mdf = false;
  5257. cont -= 1;
  5258. i += dir;
  5259. }
  5260. }
  5261. return hasReloaded;
  5262. };
  5263. RepeaterModifier.prototype.addShape = function () {};
  5264. function RoundCornersModifier() {}
  5265. extendPrototype([ShapeModifier], RoundCornersModifier);
  5266. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5267. this.getValue = this.processKeys;
  5268. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5269. this._isAnimated = !!this.rd.effectsSequence.length;
  5270. };
  5271. RoundCornersModifier.prototype.processPath = function (path, round) {
  5272. var clonedPath = shapePool.newElement();
  5273. clonedPath.c = path.c;
  5274. var i;
  5275. var len = path._length;
  5276. var currentV;
  5277. var currentI;
  5278. var currentO;
  5279. var closerV;
  5280. var distance;
  5281. var newPosPerc;
  5282. var index = 0;
  5283. var vX;
  5284. var vY;
  5285. var oX;
  5286. var oY;
  5287. var iX;
  5288. var iY;
  5289. for (i = 0; i < len; i += 1) {
  5290. currentV = path.v[i];
  5291. currentO = path.o[i];
  5292. currentI = path.i[i];
  5293. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5294. if ((i === 0 || i === len - 1) && !path.c) {
  5295. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5296. /* clonedPath.v[index] = currentV;
  5297. clonedPath.o[index] = currentO;
  5298. clonedPath.i[index] = currentI; */
  5299. index += 1;
  5300. } else {
  5301. if (i === 0) {
  5302. closerV = path.v[len - 1];
  5303. } else {
  5304. closerV = path.v[i - 1];
  5305. }
  5306. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5307. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5308. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5309. vX = iX;
  5310. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5311. vY = iY;
  5312. oX = vX - (vX - currentV[0]) * roundCorner;
  5313. oY = vY - (vY - currentV[1]) * roundCorner;
  5314. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5315. index += 1;
  5316. if (i === len - 1) {
  5317. closerV = path.v[0];
  5318. } else {
  5319. closerV = path.v[i + 1];
  5320. }
  5321. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5322. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5323. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5324. vX = oX;
  5325. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5326. vY = oY;
  5327. iX = vX - (vX - currentV[0]) * roundCorner;
  5328. iY = vY - (vY - currentV[1]) * roundCorner;
  5329. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5330. index += 1;
  5331. }
  5332. } else {
  5333. 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);
  5334. index += 1;
  5335. }
  5336. }
  5337. return clonedPath;
  5338. };
  5339. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5340. var shapePaths;
  5341. var i;
  5342. var len = this.shapes.length;
  5343. var j;
  5344. var jLen;
  5345. var rd = this.rd.v;
  5346. if (rd !== 0) {
  5347. var shapeData;
  5348. var localShapeCollection;
  5349. for (i = 0; i < len; i += 1) {
  5350. shapeData = this.shapes[i];
  5351. localShapeCollection = shapeData.localShapeCollection;
  5352. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5353. localShapeCollection.releaseShapes();
  5354. shapeData.shape._mdf = true;
  5355. shapePaths = shapeData.shape.paths.shapes;
  5356. jLen = shapeData.shape.paths._length;
  5357. for (j = 0; j < jLen; j += 1) {
  5358. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5359. }
  5360. }
  5361. shapeData.shape.paths = shapeData.localShapeCollection;
  5362. }
  5363. }
  5364. if (!this.dynamicProperties.length) {
  5365. this._mdf = false;
  5366. }
  5367. };
  5368. function floatEqual(a, b) {
  5369. return Math.abs(a - b) * 100000 <= Math.min(Math.abs(a), Math.abs(b));
  5370. }
  5371. function floatZero(f) {
  5372. return Math.abs(f) <= 0.00001;
  5373. }
  5374. function lerp(p0, p1, amount) {
  5375. return p0 * (1 - amount) + p1 * amount;
  5376. }
  5377. function lerpPoint(p0, p1, amount) {
  5378. return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
  5379. }
  5380. function quadRoots(a, b, c) {
  5381. // no root
  5382. if (a === 0) return [];
  5383. var s = b * b - 4 * a * c;
  5384. // Complex roots
  5385. if (s < 0) return [];
  5386. var singleRoot = -b / (2 * a);
  5387. // 1 root
  5388. if (s === 0) return [singleRoot];
  5389. var delta = Math.sqrt(s) / (2 * a);
  5390. // 2 roots
  5391. return [singleRoot - delta, singleRoot + delta];
  5392. }
  5393. function polynomialCoefficients(p0, p1, p2, p3) {
  5394. return [
  5395. -p0 + 3 * p1 - 3 * p2 + p3,
  5396. 3 * p0 - 6 * p1 + 3 * p2,
  5397. -3 * p0 + 3 * p1,
  5398. p0,
  5399. ];
  5400. }
  5401. function singlePoint(p) {
  5402. return new PolynomialBezier(p, p, p, p, false);
  5403. }
  5404. function PolynomialBezier(p0, p1, p2, p3, linearize) {
  5405. if (linearize && pointEqual(p0, p1)) {
  5406. p1 = lerpPoint(p0, p3, 1 / 3);
  5407. }
  5408. if (linearize && pointEqual(p2, p3)) {
  5409. p2 = lerpPoint(p0, p3, 2 / 3);
  5410. }
  5411. var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
  5412. var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
  5413. this.a = [coeffx[0], coeffy[0]];
  5414. this.b = [coeffx[1], coeffy[1]];
  5415. this.c = [coeffx[2], coeffy[2]];
  5416. this.d = [coeffx[3], coeffy[3]];
  5417. this.points = [p0, p1, p2, p3];
  5418. }
  5419. PolynomialBezier.prototype.point = function (t) {
  5420. return [
  5421. (((this.a[0] * t) + this.b[0]) * t + this.c[0]) * t + this.d[0],
  5422. (((this.a[1] * t) + this.b[1]) * t + this.c[1]) * t + this.d[1],
  5423. ];
  5424. };
  5425. PolynomialBezier.prototype.derivative = function (t) {
  5426. return [
  5427. (3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0],
  5428. (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1],
  5429. ];
  5430. };
  5431. PolynomialBezier.prototype.tangentAngle = function (t) {
  5432. var p = this.derivative(t);
  5433. return Math.atan2(p[1], p[0]);
  5434. };
  5435. PolynomialBezier.prototype.normalAngle = function (t) {
  5436. var p = this.derivative(t);
  5437. return Math.atan2(p[0], p[1]);
  5438. };
  5439. PolynomialBezier.prototype.inflectionPoints = function () {
  5440. var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
  5441. if (floatZero(denom)) return [];
  5442. var tcusp = (-0.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1])) / denom;
  5443. var square = tcusp * tcusp - ((1 / 3) * (this.b[1] * this.c[0] - this.b[0] * this.c[1])) / denom;
  5444. if (square < 0) return [];
  5445. var root = Math.sqrt(square);
  5446. if (floatZero(root)) {
  5447. if (root > 0 && root < 1) return [tcusp];
  5448. return [];
  5449. }
  5450. return [tcusp - root, tcusp + root].filter(function (r) { return r > 0 && r < 1; });
  5451. };
  5452. PolynomialBezier.prototype.split = function (t) {
  5453. if (t <= 0) return [singlePoint(this.points[0]), this];
  5454. if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
  5455. var p10 = lerpPoint(this.points[0], this.points[1], t);
  5456. var p11 = lerpPoint(this.points[1], this.points[2], t);
  5457. var p12 = lerpPoint(this.points[2], this.points[3], t);
  5458. var p20 = lerpPoint(p10, p11, t);
  5459. var p21 = lerpPoint(p11, p12, t);
  5460. var p3 = lerpPoint(p20, p21, t);
  5461. return [
  5462. new PolynomialBezier(this.points[0], p10, p20, p3, true),
  5463. new PolynomialBezier(p3, p21, p12, this.points[3], true),
  5464. ];
  5465. };
  5466. function extrema(bez, comp) {
  5467. var min = bez.points[0][comp];
  5468. var max = bez.points[bez.points.length - 1][comp];
  5469. if (min > max) {
  5470. var e = max;
  5471. max = min;
  5472. min = e;
  5473. }
  5474. // Derivative roots to find min/max
  5475. var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
  5476. for (var i = 0; i < f.length; i += 1) {
  5477. if (f[i] > 0 && f[i] < 1) {
  5478. var val = bez.point(f[i])[comp];
  5479. if (val < min) min = val;
  5480. else if (val > max) max = val;
  5481. }
  5482. }
  5483. return {
  5484. min: min,
  5485. max: max,
  5486. };
  5487. }
  5488. PolynomialBezier.prototype.bounds = function () {
  5489. return {
  5490. x: extrema(this, 0),
  5491. y: extrema(this, 1),
  5492. };
  5493. };
  5494. PolynomialBezier.prototype.boundingBox = function () {
  5495. var bounds = this.bounds();
  5496. return {
  5497. left: bounds.x.min,
  5498. right: bounds.x.max,
  5499. top: bounds.y.min,
  5500. bottom: bounds.y.max,
  5501. width: bounds.x.max - bounds.x.min,
  5502. height: bounds.y.max - bounds.y.min,
  5503. cx: (bounds.x.max + bounds.x.min) / 2,
  5504. cy: (bounds.y.max + bounds.y.min) / 2,
  5505. };
  5506. };
  5507. function intersectData(bez, t1, t2) {
  5508. var box = bez.boundingBox();
  5509. return {
  5510. cx: box.cx,
  5511. cy: box.cy,
  5512. width: box.width,
  5513. height: box.height,
  5514. bez: bez,
  5515. t: (t1 + t2) / 2,
  5516. t1: t1,
  5517. t2: t2,
  5518. };
  5519. }
  5520. function splitData(data) {
  5521. var split = data.bez.split(0.5);
  5522. return [
  5523. intersectData(split[0], data.t1, data.t),
  5524. intersectData(split[1], data.t, data.t2),
  5525. ];
  5526. }
  5527. function boxIntersect(b1, b2) {
  5528. return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width
  5529. && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
  5530. }
  5531. function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
  5532. if (!boxIntersect(d1, d2)) return;
  5533. if (depth >= maxRecursion || (d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance)) {
  5534. intersections.push([d1.t, d2.t]);
  5535. return;
  5536. }
  5537. var d1s = splitData(d1);
  5538. var d2s = splitData(d2);
  5539. intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5540. intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5541. intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5542. intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5543. }
  5544. PolynomialBezier.prototype.intersections = function (other, tolerance, maxRecursion) {
  5545. if (tolerance === undefined) tolerance = 2;
  5546. if (maxRecursion === undefined) maxRecursion = 7;
  5547. var intersections = [];
  5548. intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
  5549. return intersections;
  5550. };
  5551. PolynomialBezier.shapeSegment = function (shapePath, index) {
  5552. var nextIndex = (index + 1) % shapePath.length();
  5553. return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
  5554. };
  5555. PolynomialBezier.shapeSegmentInverted = function (shapePath, index) {
  5556. var nextIndex = (index + 1) % shapePath.length();
  5557. return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
  5558. };
  5559. function crossProduct(a, b) {
  5560. return [
  5561. a[1] * b[2] - a[2] * b[1],
  5562. a[2] * b[0] - a[0] * b[2],
  5563. a[0] * b[1] - a[1] * b[0],
  5564. ];
  5565. }
  5566. function lineIntersection(start1, end1, start2, end2) {
  5567. var v1 = [start1[0], start1[1], 1];
  5568. var v2 = [end1[0], end1[1], 1];
  5569. var v3 = [start2[0], start2[1], 1];
  5570. var v4 = [end2[0], end2[1], 1];
  5571. var r = crossProduct(
  5572. crossProduct(v1, v2),
  5573. crossProduct(v3, v4)
  5574. );
  5575. if (floatZero(r[2])) return null;
  5576. return [r[0] / r[2], r[1] / r[2]];
  5577. }
  5578. function polarOffset(p, angle, length) {
  5579. return [
  5580. p[0] + Math.cos(angle) * length,
  5581. p[1] - Math.sin(angle) * length,
  5582. ];
  5583. }
  5584. function pointDistance(p1, p2) {
  5585. return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
  5586. }
  5587. function pointEqual(p1, p2) {
  5588. return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
  5589. }
  5590. function ZigZagModifier() {}
  5591. extendPrototype([ShapeModifier], ZigZagModifier);
  5592. ZigZagModifier.prototype.initModifierProperties = function (elem, data) {
  5593. this.getValue = this.processKeys;
  5594. this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
  5595. this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5596. this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
  5597. this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
  5598. };
  5599. function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
  5600. var angO = angle - Math.PI / 2;
  5601. var angI = angle + Math.PI / 2;
  5602. var px = point[0] + Math.cos(angle) * direction * amplitude;
  5603. var py = point[1] - Math.sin(angle) * direction * amplitude;
  5604. outputBezier.setTripleAt(
  5605. px,
  5606. py,
  5607. px + Math.cos(angO) * outAmplitude,
  5608. py - Math.sin(angO) * outAmplitude,
  5609. px + Math.cos(angI) * inAmplitude,
  5610. py - Math.sin(angI) * inAmplitude,
  5611. outputBezier.length()
  5612. );
  5613. }
  5614. function getPerpendicularVector(pt1, pt2) {
  5615. var vector = [
  5616. pt2[0] - pt1[0],
  5617. pt2[1] - pt1[1],
  5618. ];
  5619. var rot = -Math.PI * 0.5;
  5620. var rotatedVector = [
  5621. Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1],
  5622. Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1],
  5623. ];
  5624. return rotatedVector;
  5625. }
  5626. function getProjectingAngle(path, cur) {
  5627. var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
  5628. var nextIndex = (cur + 1) % path.length();
  5629. var prevPoint = path.v[prevIndex];
  5630. var nextPoint = path.v[nextIndex];
  5631. var pVector = getPerpendicularVector(prevPoint, nextPoint);
  5632. return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
  5633. }
  5634. function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
  5635. var angle = getProjectingAngle(path, cur);
  5636. var point = path.v[cur % path._length];
  5637. var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
  5638. var nextPoint = path.v[(cur + 1) % path._length];
  5639. var prevDist = pointType === 2
  5640. ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2))
  5641. : 0;
  5642. var nextDist = pointType === 2
  5643. ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2))
  5644. : 0;
  5645. setPoint(
  5646. outputBezier,
  5647. path.v[cur % path._length],
  5648. angle,
  5649. direction,
  5650. amplitude,
  5651. nextDist / ((frequency + 1) * 2),
  5652. prevDist / ((frequency + 1) * 2),
  5653. pointType
  5654. );
  5655. }
  5656. function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
  5657. for (var i = 0; i < frequency; i += 1) {
  5658. var t = (i + 1) / (frequency + 1);
  5659. var dist = pointType === 2
  5660. ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2))
  5661. : 0;
  5662. var angle = segment.normalAngle(t);
  5663. var point = segment.point(t);
  5664. setPoint(
  5665. outputBezier,
  5666. point,
  5667. angle,
  5668. direction,
  5669. amplitude,
  5670. dist / ((frequency + 1) * 2),
  5671. dist / ((frequency + 1) * 2),
  5672. pointType
  5673. );
  5674. direction = -direction;
  5675. }
  5676. return direction;
  5677. }
  5678. ZigZagModifier.prototype.processPath = function (path, amplitude, frequency, pointType) {
  5679. var count = path._length;
  5680. var clonedPath = shapePool.newElement();
  5681. clonedPath.c = path.c;
  5682. if (!path.c) {
  5683. count -= 1;
  5684. }
  5685. if (count === 0) return clonedPath;
  5686. var direction = -1;
  5687. var segment = PolynomialBezier.shapeSegment(path, 0);
  5688. zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
  5689. for (var i = 0; i < count; i += 1) {
  5690. direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
  5691. if (i === count - 1 && !path.c) {
  5692. segment = null;
  5693. } else {
  5694. segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
  5695. }
  5696. zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
  5697. }
  5698. return clonedPath;
  5699. };
  5700. ZigZagModifier.prototype.processShapes = function (_isFirstFrame) {
  5701. var shapePaths;
  5702. var i;
  5703. var len = this.shapes.length;
  5704. var j;
  5705. var jLen;
  5706. var amplitude = this.amplitude.v;
  5707. var frequency = Math.max(0, Math.round(this.frequency.v));
  5708. var pointType = this.pointsType.v;
  5709. if (amplitude !== 0) {
  5710. var shapeData;
  5711. var localShapeCollection;
  5712. for (i = 0; i < len; i += 1) {
  5713. shapeData = this.shapes[i];
  5714. localShapeCollection = shapeData.localShapeCollection;
  5715. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5716. localShapeCollection.releaseShapes();
  5717. shapeData.shape._mdf = true;
  5718. shapePaths = shapeData.shape.paths.shapes;
  5719. jLen = shapeData.shape.paths._length;
  5720. for (j = 0; j < jLen; j += 1) {
  5721. localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
  5722. }
  5723. }
  5724. shapeData.shape.paths = shapeData.localShapeCollection;
  5725. }
  5726. }
  5727. if (!this.dynamicProperties.length) {
  5728. this._mdf = false;
  5729. }
  5730. };
  5731. function linearOffset(p1, p2, amount) {
  5732. var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
  5733. return [
  5734. polarOffset(p1, angle, amount),
  5735. polarOffset(p2, angle, amount),
  5736. ];
  5737. }
  5738. function offsetSegment(segment, amount) {
  5739. var p0; var p1a; var p1b; var p2b; var p2a; var
  5740. p3;
  5741. var e;
  5742. e = linearOffset(segment.points[0], segment.points[1], amount);
  5743. p0 = e[0];
  5744. p1a = e[1];
  5745. e = linearOffset(segment.points[1], segment.points[2], amount);
  5746. p1b = e[0];
  5747. p2b = e[1];
  5748. e = linearOffset(segment.points[2], segment.points[3], amount);
  5749. p2a = e[0];
  5750. p3 = e[1];
  5751. var p1 = lineIntersection(p0, p1a, p1b, p2b);
  5752. if (p1 === null) p1 = p1a;
  5753. var p2 = lineIntersection(p2a, p3, p1b, p2b);
  5754. if (p2 === null) p2 = p2a;
  5755. return new PolynomialBezier(p0, p1, p2, p3);
  5756. }
  5757. function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
  5758. var p0 = seg1.points[3];
  5759. var p1 = seg2.points[0];
  5760. // Bevel
  5761. if (lineJoin === 3) return p0;
  5762. // Connected, they don't need a joint
  5763. if (pointEqual(p0, p1)) return p0;
  5764. // Round
  5765. if (lineJoin === 2) {
  5766. var angleOut = -seg1.tangentAngle(1);
  5767. var angleIn = -seg2.tangentAngle(0) + Math.PI;
  5768. var center = lineIntersection(
  5769. p0,
  5770. polarOffset(p0, angleOut + Math.PI / 2, 100),
  5771. p1,
  5772. polarOffset(p1, angleOut + Math.PI / 2, 100)
  5773. );
  5774. var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
  5775. var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
  5776. outputBezier.setXYAt(tan[0], tan[1], 'o', outputBezier.length() - 1);
  5777. tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
  5778. outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
  5779. return p1;
  5780. }
  5781. // Miter
  5782. var t0 = pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2];
  5783. var t1 = pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1];
  5784. var intersection = lineIntersection(t0, p0, p1, t1);
  5785. if (intersection && pointDistance(intersection, p0) < miterLimit) {
  5786. outputBezier.setTripleAt(
  5787. intersection[0],
  5788. intersection[1],
  5789. intersection[0],
  5790. intersection[1],
  5791. intersection[0],
  5792. intersection[1],
  5793. outputBezier.length()
  5794. );
  5795. return intersection;
  5796. }
  5797. return p0;
  5798. }
  5799. function getIntersection(a, b) {
  5800. const intersect = a.intersections(b);
  5801. if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
  5802. if (intersect.length) return intersect[0];
  5803. return null;
  5804. }
  5805. function pruneSegmentIntersection(a, b) {
  5806. var outa = a.slice();
  5807. var outb = b.slice();
  5808. var intersect = getIntersection(a[a.length - 1], b[0]);
  5809. if (intersect) {
  5810. outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
  5811. outb[0] = b[0].split(intersect[1])[1];
  5812. }
  5813. if (a.length > 1 && b.length > 1) {
  5814. intersect = getIntersection(a[0], b[b.length - 1]);
  5815. if (intersect) {
  5816. return [
  5817. [a[0].split(intersect[0])[0]],
  5818. [b[b.length - 1].split(intersect[1])[1]],
  5819. ];
  5820. }
  5821. }
  5822. return [outa, outb];
  5823. }
  5824. function pruneIntersections(segments) {
  5825. var e;
  5826. for (var i = 1; i < segments.length; i += 1) {
  5827. e = pruneSegmentIntersection(segments[i - 1], segments[i]);
  5828. segments[i - 1] = e[0];
  5829. segments[i] = e[1];
  5830. }
  5831. if (segments.length > 1) {
  5832. e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
  5833. segments[segments.length - 1] = e[0];
  5834. segments[0] = e[1];
  5835. }
  5836. return segments;
  5837. }
  5838. function offsetSegmentSplit(segment, amount) {
  5839. /*
  5840. We split each bezier segment into smaller pieces based
  5841. on inflection points, this ensures the control point
  5842. polygon is convex.
  5843. (A cubic bezier can have none, one, or two inflection points)
  5844. */
  5845. var flex = segment.inflectionPoints();
  5846. var left;
  5847. var right;
  5848. var split;
  5849. var mid;
  5850. if (flex.length === 0) {
  5851. return [offsetSegment(segment, amount)];
  5852. }
  5853. if (flex.length === 1 || floatEqual(flex[1], 1)) {
  5854. split = segment.split(flex[0]);
  5855. left = split[0];
  5856. right = split[1];
  5857. return [
  5858. offsetSegment(left, amount),
  5859. offsetSegment(right, amount),
  5860. ];
  5861. }
  5862. split = segment.split(flex[0]);
  5863. left = split[0];
  5864. var t = (flex[1] - flex[0]) / (1 - flex[0]);
  5865. split = split[1].split(t);
  5866. mid = split[0];
  5867. right = split[1];
  5868. return [
  5869. offsetSegment(left, amount),
  5870. offsetSegment(mid, amount),
  5871. offsetSegment(right, amount),
  5872. ];
  5873. }
  5874. function OffsetPathModifier() {}
  5875. extendPrototype([ShapeModifier], OffsetPathModifier);
  5876. OffsetPathModifier.prototype.initModifierProperties = function (elem, data) {
  5877. this.getValue = this.processKeys;
  5878. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  5879. this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
  5880. this.lineJoin = data.lj;
  5881. this._isAnimated = this.amount.effectsSequence.length !== 0;
  5882. };
  5883. OffsetPathModifier.prototype.processPath = function (inputBezier, amount, lineJoin, miterLimit) {
  5884. var outputBezier = shapePool.newElement();
  5885. outputBezier.c = inputBezier.c;
  5886. var count = inputBezier.length();
  5887. if (!inputBezier.c) {
  5888. count -= 1;
  5889. }
  5890. var i; var j; var segment;
  5891. var multiSegments = [];
  5892. for (i = 0; i < count; i += 1) {
  5893. segment = PolynomialBezier.shapeSegment(inputBezier, i);
  5894. multiSegments.push(offsetSegmentSplit(segment, amount));
  5895. }
  5896. if (!inputBezier.c) {
  5897. for (i = count - 1; i >= 0; i -= 1) {
  5898. segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
  5899. multiSegments.push(offsetSegmentSplit(segment, amount));
  5900. }
  5901. }
  5902. multiSegments = pruneIntersections(multiSegments);
  5903. // Add bezier segments to the output and apply line joints
  5904. var lastPoint = null;
  5905. var lastSeg = null;
  5906. for (i = 0; i < multiSegments.length; i += 1) {
  5907. var multiSegment = multiSegments[i];
  5908. if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
  5909. lastSeg = multiSegment[multiSegment.length - 1];
  5910. for (j = 0; j < multiSegment.length; j += 1) {
  5911. segment = multiSegment[j];
  5912. if (lastPoint && pointEqual(segment.points[0], lastPoint)) {
  5913. outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], 'o', outputBezier.length() - 1);
  5914. } else {
  5915. outputBezier.setTripleAt(
  5916. segment.points[0][0],
  5917. segment.points[0][1],
  5918. segment.points[1][0],
  5919. segment.points[1][1],
  5920. segment.points[0][0],
  5921. segment.points[0][1],
  5922. outputBezier.length()
  5923. );
  5924. }
  5925. outputBezier.setTripleAt(
  5926. segment.points[3][0],
  5927. segment.points[3][1],
  5928. segment.points[3][0],
  5929. segment.points[3][1],
  5930. segment.points[2][0],
  5931. segment.points[2][1],
  5932. outputBezier.length()
  5933. );
  5934. lastPoint = segment.points[3];
  5935. }
  5936. }
  5937. if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
  5938. return outputBezier;
  5939. };
  5940. OffsetPathModifier.prototype.processShapes = function (_isFirstFrame) {
  5941. var shapePaths;
  5942. var i;
  5943. var len = this.shapes.length;
  5944. var j;
  5945. var jLen;
  5946. var amount = this.amount.v;
  5947. var miterLimit = this.miterLimit.v;
  5948. var lineJoin = this.lineJoin;
  5949. if (amount !== 0) {
  5950. var shapeData;
  5951. var localShapeCollection;
  5952. for (i = 0; i < len; i += 1) {
  5953. shapeData = this.shapes[i];
  5954. localShapeCollection = shapeData.localShapeCollection;
  5955. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5956. localShapeCollection.releaseShapes();
  5957. shapeData.shape._mdf = true;
  5958. shapePaths = shapeData.shape.paths.shapes;
  5959. jLen = shapeData.shape.paths._length;
  5960. for (j = 0; j < jLen; j += 1) {
  5961. localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
  5962. }
  5963. }
  5964. shapeData.shape.paths = shapeData.localShapeCollection;
  5965. }
  5966. }
  5967. if (!this.dynamicProperties.length) {
  5968. this._mdf = false;
  5969. }
  5970. };
  5971. function getFontProperties(fontData) {
  5972. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5973. var fWeight = 'normal'; var
  5974. fStyle = 'normal';
  5975. var len = styles.length;
  5976. var styleName;
  5977. for (var i = 0; i < len; i += 1) {
  5978. styleName = styles[i].toLowerCase();
  5979. switch (styleName) {
  5980. case 'italic':
  5981. fStyle = 'italic';
  5982. break;
  5983. case 'bold':
  5984. fWeight = '700';
  5985. break;
  5986. case 'black':
  5987. fWeight = '900';
  5988. break;
  5989. case 'medium':
  5990. fWeight = '500';
  5991. break;
  5992. case 'regular':
  5993. case 'normal':
  5994. fWeight = '400';
  5995. break;
  5996. case 'light':
  5997. case 'thin':
  5998. fWeight = '200';
  5999. break;
  6000. default:
  6001. break;
  6002. }
  6003. }
  6004. return {
  6005. style: fStyle,
  6006. weight: fontData.fWeight || fWeight,
  6007. };
  6008. }
  6009. const FontManager = (function () {
  6010. var maxWaitingTime = 5000;
  6011. var emptyChar = {
  6012. w: 0,
  6013. size: 0,
  6014. shapes: [],
  6015. data: {
  6016. shapes: [],
  6017. },
  6018. };
  6019. var combinedCharacters = [];
  6020. // Hindi characters
  6021. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366,
  6022. 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379,
  6023. 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  6024. var BLACK_FLAG_CODE_POINT = 127988;
  6025. var CANCEL_TAG_CODE_POINT = 917631;
  6026. var A_TAG_CODE_POINT = 917601;
  6027. var Z_TAG_CODE_POINT = 917626;
  6028. var VARIATION_SELECTOR_16_CODE_POINT = 65039;
  6029. var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
  6030. var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
  6031. var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
  6032. var surrogateModifiers = [
  6033. 'd83cdffb',
  6034. 'd83cdffc',
  6035. 'd83cdffd',
  6036. 'd83cdffe',
  6037. 'd83cdfff',
  6038. ];
  6039. function trimFontOptions(font) {
  6040. var familyArray = font.split(',');
  6041. var i;
  6042. var len = familyArray.length;
  6043. var enabledFamilies = [];
  6044. for (i = 0; i < len; i += 1) {
  6045. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  6046. enabledFamilies.push(familyArray[i]);
  6047. }
  6048. }
  6049. return enabledFamilies.join(',');
  6050. }
  6051. function setUpNode(font, family) {
  6052. var parentNode = createTag('span');
  6053. // Node is invisible to screen readers.
  6054. parentNode.setAttribute('aria-hidden', true);
  6055. parentNode.style.fontFamily = family;
  6056. var node = createTag('span');
  6057. // Characters that vary significantly among different fonts
  6058. node.innerText = 'giItT1WQy@!-/#';
  6059. // Visible - so we can measure it - but not on the screen
  6060. parentNode.style.position = 'absolute';
  6061. parentNode.style.left = '-10000px';
  6062. parentNode.style.top = '-10000px';
  6063. // Large font size makes even subtle changes obvious
  6064. parentNode.style.fontSize = '300px';
  6065. // Reset any font properties
  6066. parentNode.style.fontVariant = 'normal';
  6067. parentNode.style.fontStyle = 'normal';
  6068. parentNode.style.fontWeight = 'normal';
  6069. parentNode.style.letterSpacing = '0';
  6070. parentNode.appendChild(node);
  6071. document.body.appendChild(parentNode);
  6072. // Remember width with no applied web font
  6073. var width = node.offsetWidth;
  6074. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  6075. return { node: node, w: width, parent: parentNode };
  6076. }
  6077. function checkLoadedFonts() {
  6078. var i;
  6079. var len = this.fonts.length;
  6080. var node;
  6081. var w;
  6082. var loadedCount = len;
  6083. for (i = 0; i < len; i += 1) {
  6084. if (this.fonts[i].loaded) {
  6085. loadedCount -= 1;
  6086. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  6087. this.fonts[i].loaded = true;
  6088. } else {
  6089. node = this.fonts[i].monoCase.node;
  6090. w = this.fonts[i].monoCase.w;
  6091. if (node.offsetWidth !== w) {
  6092. loadedCount -= 1;
  6093. this.fonts[i].loaded = true;
  6094. } else {
  6095. node = this.fonts[i].sansCase.node;
  6096. w = this.fonts[i].sansCase.w;
  6097. if (node.offsetWidth !== w) {
  6098. loadedCount -= 1;
  6099. this.fonts[i].loaded = true;
  6100. }
  6101. }
  6102. if (this.fonts[i].loaded) {
  6103. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  6104. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  6105. }
  6106. }
  6107. }
  6108. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  6109. setTimeout(this.checkLoadedFontsBinded, 20);
  6110. } else {
  6111. setTimeout(this.setIsLoadedBinded, 10);
  6112. }
  6113. }
  6114. function createHelper(fontData, def) {
  6115. var engine = (document.body && def) ? 'svg' : 'canvas';
  6116. var helper;
  6117. var fontProps = getFontProperties(fontData);
  6118. if (engine === 'svg') {
  6119. var tHelper = createNS('text');
  6120. tHelper.style.fontSize = '100px';
  6121. // tHelper.style.fontFamily = fontData.fFamily;
  6122. tHelper.setAttribute('font-family', fontData.fFamily);
  6123. tHelper.setAttribute('font-style', fontProps.style);
  6124. tHelper.setAttribute('font-weight', fontProps.weight);
  6125. tHelper.textContent = '1';
  6126. if (fontData.fClass) {
  6127. tHelper.style.fontFamily = 'inherit';
  6128. tHelper.setAttribute('class', fontData.fClass);
  6129. } else {
  6130. tHelper.style.fontFamily = fontData.fFamily;
  6131. }
  6132. def.appendChild(tHelper);
  6133. helper = tHelper;
  6134. } else {
  6135. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  6136. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  6137. helper = tCanvasHelper;
  6138. }
  6139. function measure(text) {
  6140. if (engine === 'svg') {
  6141. helper.textContent = text;
  6142. return helper.getComputedTextLength();
  6143. }
  6144. return helper.measureText(text).width;
  6145. }
  6146. return {
  6147. measureText: measure,
  6148. };
  6149. }
  6150. function addFonts(fontData, defs) {
  6151. if (!fontData) {
  6152. this.isLoaded = true;
  6153. return;
  6154. }
  6155. if (this.chars) {
  6156. this.isLoaded = true;
  6157. this.fonts = fontData.list;
  6158. return;
  6159. }
  6160. if (!document.body) {
  6161. this.isLoaded = true;
  6162. fontData.list.forEach((data) => {
  6163. data.helper = createHelper(data);
  6164. data.cache = {};
  6165. });
  6166. this.fonts = fontData.list;
  6167. return;
  6168. }
  6169. var fontArr = fontData.list;
  6170. var i;
  6171. var len = fontArr.length;
  6172. var _pendingFonts = len;
  6173. for (i = 0; i < len; i += 1) {
  6174. var shouldLoadFont = true;
  6175. var loadedSelector;
  6176. var j;
  6177. fontArr[i].loaded = false;
  6178. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  6179. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  6180. if (!fontArr[i].fPath) {
  6181. fontArr[i].loaded = true;
  6182. _pendingFonts -= 1;
  6183. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  6184. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  6185. if (loadedSelector.length > 0) {
  6186. shouldLoadFont = false;
  6187. }
  6188. if (shouldLoadFont) {
  6189. var s = createTag('style');
  6190. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  6191. s.setAttribute('f-origin', fontArr[i].origin);
  6192. s.setAttribute('f-family', fontArr[i].fFamily);
  6193. s.type = 'text/css';
  6194. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  6195. defs.appendChild(s);
  6196. }
  6197. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  6198. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  6199. for (j = 0; j < loadedSelector.length; j += 1) {
  6200. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  6201. // Font is already loaded
  6202. shouldLoadFont = false;
  6203. }
  6204. }
  6205. if (shouldLoadFont) {
  6206. var l = createTag('link');
  6207. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  6208. l.setAttribute('f-origin', fontArr[i].origin);
  6209. l.type = 'text/css';
  6210. l.rel = 'stylesheet';
  6211. l.href = fontArr[i].fPath;
  6212. document.body.appendChild(l);
  6213. }
  6214. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  6215. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  6216. for (j = 0; j < loadedSelector.length; j += 1) {
  6217. if (fontArr[i].fPath === loadedSelector[j].src) {
  6218. // Font is already loaded
  6219. shouldLoadFont = false;
  6220. }
  6221. }
  6222. if (shouldLoadFont) {
  6223. var sc = createTag('link');
  6224. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  6225. sc.setAttribute('f-origin', fontArr[i].origin);
  6226. sc.setAttribute('rel', 'stylesheet');
  6227. sc.setAttribute('href', fontArr[i].fPath);
  6228. defs.appendChild(sc);
  6229. }
  6230. }
  6231. fontArr[i].helper = createHelper(fontArr[i], defs);
  6232. fontArr[i].cache = {};
  6233. this.fonts.push(fontArr[i]);
  6234. }
  6235. if (_pendingFonts === 0) {
  6236. this.isLoaded = true;
  6237. } else {
  6238. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  6239. // Adding this timeout seems to fix it
  6240. setTimeout(this.checkLoadedFonts.bind(this), 100);
  6241. }
  6242. }
  6243. function addChars(chars) {
  6244. if (!chars) {
  6245. return;
  6246. }
  6247. if (!this.chars) {
  6248. this.chars = [];
  6249. }
  6250. var i;
  6251. var len = chars.length;
  6252. var j;
  6253. var jLen = this.chars.length;
  6254. var found;
  6255. for (i = 0; i < len; i += 1) {
  6256. j = 0;
  6257. found = false;
  6258. while (j < jLen) {
  6259. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  6260. found = true;
  6261. }
  6262. j += 1;
  6263. }
  6264. if (!found) {
  6265. this.chars.push(chars[i]);
  6266. jLen += 1;
  6267. }
  6268. }
  6269. }
  6270. function getCharData(char, style, font) {
  6271. var i = 0;
  6272. var len = this.chars.length;
  6273. while (i < len) {
  6274. if (this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  6275. return this.chars[i];
  6276. }
  6277. i += 1;
  6278. }
  6279. if (((typeof char === 'string' && char.charCodeAt(0) !== 13) || !char)
  6280. && console
  6281. && console.warn // eslint-disable-line no-console
  6282. && !this._warned
  6283. ) {
  6284. this._warned = true;
  6285. console.warn('Missing character from exported characters list: ', char, style, font); // eslint-disable-line no-console
  6286. }
  6287. return emptyChar;
  6288. }
  6289. function measureText(char, fontName, size) {
  6290. var fontData = this.getFontByName(fontName);
  6291. // Using the char instead of char.charCodeAt(0)
  6292. // to avoid collisions between equal chars
  6293. var index = char;
  6294. if (!fontData.cache[index]) {
  6295. var tHelper = fontData.helper;
  6296. if (char === ' ') {
  6297. var doubleSize = tHelper.measureText('|' + char + '|');
  6298. var singleSize = tHelper.measureText('||');
  6299. fontData.cache[index] = (doubleSize - singleSize) / 100;
  6300. } else {
  6301. fontData.cache[index] = tHelper.measureText(char) / 100;
  6302. }
  6303. }
  6304. return fontData.cache[index] * size;
  6305. }
  6306. function getFontByName(name) {
  6307. var i = 0;
  6308. var len = this.fonts.length;
  6309. while (i < len) {
  6310. if (this.fonts[i].fName === name) {
  6311. return this.fonts[i];
  6312. }
  6313. i += 1;
  6314. }
  6315. return this.fonts[0];
  6316. }
  6317. function getCodePoint(string) {
  6318. var codePoint = 0;
  6319. var first = string.charCodeAt(0);
  6320. if (first >= 0xD800 && first <= 0xDBFF) {
  6321. var second = string.charCodeAt(1);
  6322. if (second >= 0xDC00 && second <= 0xDFFF) {
  6323. codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  6324. }
  6325. }
  6326. return codePoint;
  6327. }
  6328. // Skin tone modifiers
  6329. function isModifier(firstCharCode, secondCharCode) {
  6330. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  6331. return surrogateModifiers.indexOf(sum) !== -1;
  6332. }
  6333. function isZeroWidthJoiner(charCode) {
  6334. return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
  6335. }
  6336. // This codepoint may change the appearance of the preceding character.
  6337. // If that is a symbol, dingbat or emoji, U+FE0F forces it to be rendered
  6338. // as a colorful image as compared to a monochrome text variant.
  6339. function isVariationSelector(charCode) {
  6340. return charCode === VARIATION_SELECTOR_16_CODE_POINT;
  6341. }
  6342. // The regional indicator symbols are a set of 26 alphabetic Unicode
  6343. /// characters (A–Z) intended to be used to encode ISO 3166-1 alpha-2
  6344. // two-letter country codes in a way that allows optional special treatment.
  6345. function isRegionalCode(string) {
  6346. var codePoint = getCodePoint(string);
  6347. if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) {
  6348. return true;
  6349. }
  6350. return false;
  6351. }
  6352. // Some Emoji implementations represent combinations of
  6353. // two “regional indicator” letters as a single flag symbol.
  6354. function isFlagEmoji(string) {
  6355. return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
  6356. }
  6357. function isCombinedCharacter(char) {
  6358. return combinedCharacters.indexOf(char) !== -1;
  6359. }
  6360. // Regional flags start with a BLACK_FLAG_CODE_POINT
  6361. // folowed by 5 chars in the TAG range
  6362. // and end with a CANCEL_TAG_CODE_POINT
  6363. function isRegionalFlag(text, index) {
  6364. var codePoint = getCodePoint(text.substr(index, 2));
  6365. if (codePoint !== BLACK_FLAG_CODE_POINT) {
  6366. return false;
  6367. }
  6368. var count = 0;
  6369. index += 2;
  6370. while (count < 5) {
  6371. codePoint = getCodePoint(text.substr(index, 2));
  6372. if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) {
  6373. return false;
  6374. }
  6375. count += 1;
  6376. index += 2;
  6377. }
  6378. return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
  6379. }
  6380. function setIsLoaded() {
  6381. this.isLoaded = true;
  6382. }
  6383. var Font = function () {
  6384. this.fonts = [];
  6385. this.chars = null;
  6386. this.typekitLoaded = 0;
  6387. this.isLoaded = false;
  6388. this._warned = false;
  6389. this.initTime = Date.now();
  6390. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  6391. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  6392. };
  6393. Font.isModifier = isModifier;
  6394. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  6395. Font.isFlagEmoji = isFlagEmoji;
  6396. Font.isRegionalCode = isRegionalCode;
  6397. Font.isCombinedCharacter = isCombinedCharacter;
  6398. Font.isRegionalFlag = isRegionalFlag;
  6399. Font.isVariationSelector = isVariationSelector;
  6400. Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
  6401. var fontPrototype = {
  6402. addChars: addChars,
  6403. addFonts: addFonts,
  6404. getCharData: getCharData,
  6405. getFontByName: getFontByName,
  6406. measureText: measureText,
  6407. checkLoadedFonts: checkLoadedFonts,
  6408. setIsLoaded: setIsLoaded,
  6409. };
  6410. Font.prototype = fontPrototype;
  6411. return Font;
  6412. }());
  6413. function SlotManager(animationData) {
  6414. this.animationData = animationData;
  6415. }
  6416. SlotManager.prototype.getProp = function (data) {
  6417. if (this.animationData.slots
  6418. && this.animationData.slots[data.sid]
  6419. ) {
  6420. return Object.assign(data, this.animationData.slots[data.sid].p);
  6421. }
  6422. return data;
  6423. };
  6424. function slotFactory(animationData) {
  6425. return new SlotManager(animationData);
  6426. }
  6427. function RenderableElement() {
  6428. }
  6429. RenderableElement.prototype = {
  6430. initRenderable: function () {
  6431. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6432. this.isInRange = false;
  6433. // layer's display state
  6434. this.hidden = false;
  6435. // If layer's transparency equals 0, it can be hidden
  6436. this.isTransparent = false;
  6437. // list of animated components
  6438. this.renderableComponents = [];
  6439. },
  6440. addRenderableComponent: function (component) {
  6441. if (this.renderableComponents.indexOf(component) === -1) {
  6442. this.renderableComponents.push(component);
  6443. }
  6444. },
  6445. removeRenderableComponent: function (component) {
  6446. if (this.renderableComponents.indexOf(component) !== -1) {
  6447. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6448. }
  6449. },
  6450. prepareRenderableFrame: function (num) {
  6451. this.checkLayerLimits(num);
  6452. },
  6453. checkTransparency: function () {
  6454. if (this.finalTransform.mProp.o.v <= 0) {
  6455. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  6456. this.isTransparent = true;
  6457. this.hide();
  6458. }
  6459. } else if (this.isTransparent) {
  6460. this.isTransparent = false;
  6461. this.show();
  6462. }
  6463. },
  6464. /**
  6465. * @function
  6466. * Initializes frame related properties.
  6467. *
  6468. * @param {number} num
  6469. * current frame number in Layer's time
  6470. *
  6471. */
  6472. checkLayerLimits: function (num) {
  6473. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  6474. if (this.isInRange !== true) {
  6475. this.globalData._mdf = true;
  6476. this._mdf = true;
  6477. this.isInRange = true;
  6478. this.show();
  6479. }
  6480. } else if (this.isInRange !== false) {
  6481. this.globalData._mdf = true;
  6482. this.isInRange = false;
  6483. this.hide();
  6484. }
  6485. },
  6486. renderRenderable: function () {
  6487. var i;
  6488. var len = this.renderableComponents.length;
  6489. for (i = 0; i < len; i += 1) {
  6490. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6491. }
  6492. /* this.maskManager.renderFrame(this.finalTransform.mat);
  6493. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  6494. },
  6495. sourceRectAtTime: function () {
  6496. return {
  6497. top: 0,
  6498. left: 0,
  6499. width: 100,
  6500. height: 100,
  6501. };
  6502. },
  6503. getLayerSize: function () {
  6504. if (this.data.ty === 5) {
  6505. return { w: this.data.textData.width, h: this.data.textData.height };
  6506. }
  6507. return { w: this.data.width, h: this.data.height };
  6508. },
  6509. };
  6510. const getBlendMode = (function () {
  6511. var blendModeEnums = {
  6512. 0: 'source-over',
  6513. 1: 'multiply',
  6514. 2: 'screen',
  6515. 3: 'overlay',
  6516. 4: 'darken',
  6517. 5: 'lighten',
  6518. 6: 'color-dodge',
  6519. 7: 'color-burn',
  6520. 8: 'hard-light',
  6521. 9: 'soft-light',
  6522. 10: 'difference',
  6523. 11: 'exclusion',
  6524. 12: 'hue',
  6525. 13: 'saturation',
  6526. 14: 'color',
  6527. 15: 'luminosity',
  6528. };
  6529. return function (mode) {
  6530. return blendModeEnums[mode] || '';
  6531. };
  6532. }());
  6533. function SliderEffect(data, elem, container) {
  6534. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6535. }
  6536. function AngleEffect(data, elem, container) {
  6537. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6538. }
  6539. function ColorEffect(data, elem, container) {
  6540. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6541. }
  6542. function PointEffect(data, elem, container) {
  6543. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6544. }
  6545. function LayerIndexEffect(data, elem, container) {
  6546. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6547. }
  6548. function MaskIndexEffect(data, elem, container) {
  6549. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6550. }
  6551. function CheckboxEffect(data, elem, container) {
  6552. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6553. }
  6554. function NoValueEffect() {
  6555. this.p = {};
  6556. }
  6557. function EffectsManager(data, element) {
  6558. var effects = data.ef || [];
  6559. this.effectElements = [];
  6560. var i;
  6561. var len = effects.length;
  6562. var effectItem;
  6563. for (i = 0; i < len; i += 1) {
  6564. effectItem = new GroupEffect(effects[i], element);
  6565. this.effectElements.push(effectItem);
  6566. }
  6567. }
  6568. function GroupEffect(data, element) {
  6569. this.init(data, element);
  6570. }
  6571. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6572. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6573. GroupEffect.prototype.init = function (data, element) {
  6574. this.data = data;
  6575. this.effectElements = [];
  6576. this.initDynamicPropertyContainer(element);
  6577. var i;
  6578. var len = this.data.ef.length;
  6579. var eff;
  6580. var effects = this.data.ef;
  6581. for (i = 0; i < len; i += 1) {
  6582. eff = null;
  6583. switch (effects[i].ty) {
  6584. case 0:
  6585. eff = new SliderEffect(effects[i], element, this);
  6586. break;
  6587. case 1:
  6588. eff = new AngleEffect(effects[i], element, this);
  6589. break;
  6590. case 2:
  6591. eff = new ColorEffect(effects[i], element, this);
  6592. break;
  6593. case 3:
  6594. eff = new PointEffect(effects[i], element, this);
  6595. break;
  6596. case 4:
  6597. case 7:
  6598. eff = new CheckboxEffect(effects[i], element, this);
  6599. break;
  6600. case 10:
  6601. eff = new LayerIndexEffect(effects[i], element, this);
  6602. break;
  6603. case 11:
  6604. eff = new MaskIndexEffect(effects[i], element, this);
  6605. break;
  6606. case 5:
  6607. eff = new EffectsManager(effects[i], element, this);
  6608. break;
  6609. // case 6:
  6610. default:
  6611. eff = new NoValueEffect(effects[i], element, this);
  6612. break;
  6613. }
  6614. if (eff) {
  6615. this.effectElements.push(eff);
  6616. }
  6617. }
  6618. };
  6619. function BaseElement() {
  6620. }
  6621. BaseElement.prototype = {
  6622. checkMasks: function () {
  6623. if (!this.data.hasMask) {
  6624. return false;
  6625. }
  6626. var i = 0;
  6627. var len = this.data.masksProperties.length;
  6628. while (i < len) {
  6629. if ((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) {
  6630. return true;
  6631. }
  6632. i += 1;
  6633. }
  6634. return false;
  6635. },
  6636. initExpressions: function () {
  6637. const expressionsInterfaces = getExpressionInterfaces();
  6638. if (!expressionsInterfaces) {
  6639. return;
  6640. }
  6641. const LayerExpressionInterface = expressionsInterfaces('layer');
  6642. const EffectsExpressionInterface = expressionsInterfaces('effects');
  6643. const ShapeExpressionInterface = expressionsInterfaces('shape');
  6644. const TextExpressionInterface = expressionsInterfaces('text');
  6645. const CompExpressionInterface = expressionsInterfaces('comp');
  6646. this.layerInterface = LayerExpressionInterface(this);
  6647. if (this.data.hasMask && this.maskManager) {
  6648. this.layerInterface.registerMaskInterface(this.maskManager);
  6649. }
  6650. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
  6651. this.layerInterface.registerEffectsInterface(effectsInterface);
  6652. if (this.data.ty === 0 || this.data.xt) {
  6653. this.compInterface = CompExpressionInterface(this);
  6654. } else if (this.data.ty === 4) {
  6655. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
  6656. this.layerInterface.content = this.layerInterface.shapeInterface;
  6657. } else if (this.data.ty === 5) {
  6658. this.layerInterface.textInterface = TextExpressionInterface(this);
  6659. this.layerInterface.text = this.layerInterface.textInterface;
  6660. }
  6661. },
  6662. setBlendMode: function () {
  6663. var blendModeValue = getBlendMode(this.data.bm);
  6664. var elem = this.baseElement || this.layerElement;
  6665. elem.style['mix-blend-mode'] = blendModeValue;
  6666. },
  6667. initBaseData: function (data, globalData, comp) {
  6668. this.globalData = globalData;
  6669. this.comp = comp;
  6670. this.data = data;
  6671. this.layerId = createElementID();
  6672. // Stretch factor for old animations missing this property.
  6673. if (!this.data.sr) {
  6674. this.data.sr = 1;
  6675. }
  6676. // effects manager
  6677. this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
  6678. },
  6679. getType: function () {
  6680. return this.type;
  6681. },
  6682. sourceRectAtTime: function () {},
  6683. };
  6684. /**
  6685. * @file
  6686. * Handles element's layer frame update.
  6687. * Checks layer in point and out point
  6688. *
  6689. */
  6690. function FrameElement() {}
  6691. FrameElement.prototype = {
  6692. /**
  6693. * @function
  6694. * Initializes frame related properties.
  6695. *
  6696. */
  6697. initFrame: function () {
  6698. // set to true when inpoint is rendered
  6699. this._isFirstFrame = false;
  6700. // list of animated properties
  6701. this.dynamicProperties = [];
  6702. // If layer has been modified in current tick this will be true
  6703. this._mdf = false;
  6704. },
  6705. /**
  6706. * @function
  6707. * Calculates all dynamic values
  6708. *
  6709. * @param {number} num
  6710. * current frame number in Layer's time
  6711. * @param {boolean} isVisible
  6712. * if layers is currently in range
  6713. *
  6714. */
  6715. prepareProperties: function (num, isVisible) {
  6716. var i;
  6717. var len = this.dynamicProperties.length;
  6718. for (i = 0; i < len; i += 1) {
  6719. if (isVisible || (this._isParent && this.dynamicProperties[i].propType === 'transform')) {
  6720. this.dynamicProperties[i].getValue();
  6721. if (this.dynamicProperties[i]._mdf) {
  6722. this.globalData._mdf = true;
  6723. this._mdf = true;
  6724. }
  6725. }
  6726. }
  6727. },
  6728. addDynamicProperty: function (prop) {
  6729. if (this.dynamicProperties.indexOf(prop) === -1) {
  6730. this.dynamicProperties.push(prop);
  6731. }
  6732. },
  6733. };
  6734. function FootageElement(data, globalData, comp) {
  6735. this.initFrame();
  6736. this.initRenderable();
  6737. this.assetData = globalData.getAssetData(data.refId);
  6738. this.footageData = globalData.imageLoader.getAsset(this.assetData);
  6739. this.initBaseData(data, globalData, comp);
  6740. }
  6741. FootageElement.prototype.prepareFrame = function () {
  6742. };
  6743. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  6744. FootageElement.prototype.getBaseElement = function () {
  6745. return null;
  6746. };
  6747. FootageElement.prototype.renderFrame = function () {
  6748. };
  6749. FootageElement.prototype.destroy = function () {
  6750. };
  6751. FootageElement.prototype.initExpressions = function () {
  6752. const expressionsInterfaces = getExpressionInterfaces();
  6753. if (!expressionsInterfaces) {
  6754. return;
  6755. }
  6756. const FootageInterface = expressionsInterfaces('footage');
  6757. this.layerInterface = FootageInterface(this);
  6758. };
  6759. FootageElement.prototype.getFootageData = function () {
  6760. return this.footageData;
  6761. };
  6762. function AudioElement(data, globalData, comp) {
  6763. this.initFrame();
  6764. this.initRenderable();
  6765. this.assetData = globalData.getAssetData(data.refId);
  6766. this.initBaseData(data, globalData, comp);
  6767. this._isPlaying = false;
  6768. this._canPlay = false;
  6769. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6770. this.audio = this.globalData.audioController.createAudio(assetPath);
  6771. this._currentTime = 0;
  6772. this.globalData.audioController.addAudio(this);
  6773. this._volumeMultiplier = 1;
  6774. this._volume = 1;
  6775. this._previousVolume = null;
  6776. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  6777. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : { k: [100] }, 1, 0.01, this);
  6778. }
  6779. AudioElement.prototype.prepareFrame = function (num) {
  6780. this.prepareRenderableFrame(num, true);
  6781. this.prepareProperties(num, true);
  6782. if (!this.tm._placeholder) {
  6783. var timeRemapped = this.tm.v;
  6784. this._currentTime = timeRemapped;
  6785. } else {
  6786. this._currentTime = num / this.data.sr;
  6787. }
  6788. this._volume = this.lv.v[0];
  6789. var totalVolume = this._volume * this._volumeMultiplier;
  6790. if (this._previousVolume !== totalVolume) {
  6791. this._previousVolume = totalVolume;
  6792. this.audio.volume(totalVolume);
  6793. }
  6794. };
  6795. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  6796. AudioElement.prototype.renderFrame = function () {
  6797. if (this.isInRange && this._canPlay) {
  6798. if (!this._isPlaying) {
  6799. this.audio.play();
  6800. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6801. this._isPlaying = true;
  6802. } else if (!this.audio.playing()
  6803. || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1
  6804. ) {
  6805. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6806. }
  6807. }
  6808. };
  6809. AudioElement.prototype.show = function () {
  6810. // this.audio.play()
  6811. };
  6812. AudioElement.prototype.hide = function () {
  6813. this.audio.pause();
  6814. this._isPlaying = false;
  6815. };
  6816. AudioElement.prototype.pause = function () {
  6817. this.audio.pause();
  6818. this._isPlaying = false;
  6819. this._canPlay = false;
  6820. };
  6821. AudioElement.prototype.resume = function () {
  6822. this._canPlay = true;
  6823. };
  6824. AudioElement.prototype.setRate = function (rateValue) {
  6825. this.audio.rate(rateValue);
  6826. };
  6827. AudioElement.prototype.volume = function (volumeValue) {
  6828. this._volumeMultiplier = volumeValue;
  6829. this._previousVolume = volumeValue * this._volume;
  6830. this.audio.volume(this._previousVolume);
  6831. };
  6832. AudioElement.prototype.getBaseElement = function () {
  6833. return null;
  6834. };
  6835. AudioElement.prototype.destroy = function () {
  6836. };
  6837. AudioElement.prototype.sourceRectAtTime = function () {
  6838. };
  6839. AudioElement.prototype.initExpressions = function () {
  6840. };
  6841. function BaseRenderer() {}
  6842. BaseRenderer.prototype.checkLayers = function (num) {
  6843. var i;
  6844. var len = this.layers.length;
  6845. var data;
  6846. this.completeLayers = true;
  6847. for (i = len - 1; i >= 0; i -= 1) {
  6848. if (!this.elements[i]) {
  6849. data = this.layers[i];
  6850. if (data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st)) {
  6851. this.buildItem(i);
  6852. }
  6853. }
  6854. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  6855. }
  6856. this.checkPendingElements();
  6857. };
  6858. BaseRenderer.prototype.createItem = function (layer) {
  6859. switch (layer.ty) {
  6860. case 2:
  6861. return this.createImage(layer);
  6862. case 0:
  6863. return this.createComp(layer);
  6864. case 1:
  6865. return this.createSolid(layer);
  6866. case 3:
  6867. return this.createNull(layer);
  6868. case 4:
  6869. return this.createShape(layer);
  6870. case 5:
  6871. return this.createText(layer);
  6872. case 6:
  6873. return this.createAudio(layer);
  6874. case 13:
  6875. return this.createCamera(layer);
  6876. case 15:
  6877. return this.createFootage(layer);
  6878. default:
  6879. return this.createNull(layer);
  6880. }
  6881. };
  6882. BaseRenderer.prototype.createCamera = function () {
  6883. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  6884. };
  6885. BaseRenderer.prototype.createAudio = function (data) {
  6886. return new AudioElement(data, this.globalData, this);
  6887. };
  6888. BaseRenderer.prototype.createFootage = function (data) {
  6889. return new FootageElement(data, this.globalData, this);
  6890. };
  6891. BaseRenderer.prototype.buildAllItems = function () {
  6892. var i;
  6893. var len = this.layers.length;
  6894. for (i = 0; i < len; i += 1) {
  6895. this.buildItem(i);
  6896. }
  6897. this.checkPendingElements();
  6898. };
  6899. BaseRenderer.prototype.includeLayers = function (newLayers) {
  6900. this.completeLayers = false;
  6901. var i;
  6902. var len = newLayers.length;
  6903. var j;
  6904. var jLen = this.layers.length;
  6905. for (i = 0; i < len; i += 1) {
  6906. j = 0;
  6907. while (j < jLen) {
  6908. if (this.layers[j].id === newLayers[i].id) {
  6909. this.layers[j] = newLayers[i];
  6910. break;
  6911. }
  6912. j += 1;
  6913. }
  6914. }
  6915. };
  6916. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  6917. this.globalData.projectInterface = pInterface;
  6918. };
  6919. BaseRenderer.prototype.initItems = function () {
  6920. if (!this.globalData.progressiveLoad) {
  6921. this.buildAllItems();
  6922. }
  6923. };
  6924. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  6925. var elements = this.elements;
  6926. var layers = this.layers;
  6927. var i = 0;
  6928. var len = layers.length;
  6929. while (i < len) {
  6930. if (layers[i].ind == parentName) { // eslint-disable-line eqeqeq
  6931. if (!elements[i] || elements[i] === true) {
  6932. this.buildItem(i);
  6933. this.addPendingElement(element);
  6934. } else {
  6935. hierarchy.push(elements[i]);
  6936. elements[i].setAsParent();
  6937. if (layers[i].parent !== undefined) {
  6938. this.buildElementParenting(element, layers[i].parent, hierarchy);
  6939. } else {
  6940. element.setHierarchy(hierarchy);
  6941. }
  6942. }
  6943. }
  6944. i += 1;
  6945. }
  6946. };
  6947. BaseRenderer.prototype.addPendingElement = function (element) {
  6948. this.pendingElements.push(element);
  6949. };
  6950. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  6951. var i;
  6952. var len = assets.length;
  6953. for (i = 0; i < len; i += 1) {
  6954. if (assets[i].xt) {
  6955. var comp = this.createComp(assets[i]);
  6956. comp.initExpressions();
  6957. this.globalData.projectInterface.registerComposition(comp);
  6958. }
  6959. }
  6960. };
  6961. BaseRenderer.prototype.getElementById = function (ind) {
  6962. var i;
  6963. var len = this.elements.length;
  6964. for (i = 0; i < len; i += 1) {
  6965. if (this.elements[i].data.ind === ind) {
  6966. return this.elements[i];
  6967. }
  6968. }
  6969. return null;
  6970. };
  6971. BaseRenderer.prototype.getElementByPath = function (path) {
  6972. var pathValue = path.shift();
  6973. var element;
  6974. if (typeof pathValue === 'number') {
  6975. element = this.elements[pathValue];
  6976. } else {
  6977. var i;
  6978. var len = this.elements.length;
  6979. for (i = 0; i < len; i += 1) {
  6980. if (this.elements[i].data.nm === pathValue) {
  6981. element = this.elements[i];
  6982. break;
  6983. }
  6984. }
  6985. }
  6986. if (path.length === 0) {
  6987. return element;
  6988. }
  6989. return element.getElementByPath(path);
  6990. };
  6991. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  6992. this.globalData.fontManager = new FontManager();
  6993. this.globalData.slotManager = slotFactory(animData);
  6994. this.globalData.fontManager.addChars(animData.chars);
  6995. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  6996. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  6997. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  6998. this.globalData.imageLoader = this.animationItem.imagePreloader;
  6999. this.globalData.audioController = this.animationItem.audioController;
  7000. this.globalData.frameId = 0;
  7001. this.globalData.frameRate = animData.fr;
  7002. this.globalData.nm = animData.nm;
  7003. this.globalData.compSize = {
  7004. w: animData.w,
  7005. h: animData.h,
  7006. };
  7007. };
  7008. var effectTypes = {
  7009. TRANSFORM_EFFECT: 'transformEFfect',
  7010. };
  7011. function TransformElement() {}
  7012. TransformElement.prototype = {
  7013. initTransform: function () {
  7014. var mat = new Matrix();
  7015. this.finalTransform = {
  7016. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : { o: 0 },
  7017. _matMdf: false,
  7018. _localMatMdf: false,
  7019. _opMdf: false,
  7020. mat: mat,
  7021. localMat: mat,
  7022. localOpacity: 1,
  7023. };
  7024. if (this.data.ao) {
  7025. this.finalTransform.mProp.autoOriented = true;
  7026. }
  7027. // TODO: check TYPE 11: Guided elements
  7028. if (this.data.ty !== 11) {
  7029. // this.createElements();
  7030. }
  7031. },
  7032. renderTransform: function () {
  7033. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  7034. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  7035. if (this.hierarchy) {
  7036. var mat;
  7037. var finalMat = this.finalTransform.mat;
  7038. var i = 0;
  7039. var len = this.hierarchy.length;
  7040. // Checking if any of the transformation matrices in the hierarchy chain has changed.
  7041. if (!this.finalTransform._matMdf) {
  7042. while (i < len) {
  7043. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  7044. this.finalTransform._matMdf = true;
  7045. break;
  7046. }
  7047. i += 1;
  7048. }
  7049. }
  7050. if (this.finalTransform._matMdf) {
  7051. mat = this.finalTransform.mProp.v.props;
  7052. finalMat.cloneFromProps(mat);
  7053. for (i = 0; i < len; i += 1) {
  7054. finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
  7055. }
  7056. }
  7057. }
  7058. if (this.finalTransform._matMdf) {
  7059. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7060. }
  7061. if (this.finalTransform._opMdf) {
  7062. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7063. }
  7064. },
  7065. renderLocalTransform: function () {
  7066. if (this.localTransforms) {
  7067. var i = 0;
  7068. var len = this.localTransforms.length;
  7069. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7070. if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) {
  7071. while (i < len) {
  7072. if (this.localTransforms[i]._mdf) {
  7073. this.finalTransform._localMatMdf = true;
  7074. }
  7075. if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
  7076. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7077. this.finalTransform._opMdf = true;
  7078. }
  7079. i += 1;
  7080. }
  7081. }
  7082. if (this.finalTransform._localMatMdf) {
  7083. var localMat = this.finalTransform.localMat;
  7084. this.localTransforms[0].matrix.clone(localMat);
  7085. for (i = 1; i < len; i += 1) {
  7086. var lmat = this.localTransforms[i].matrix;
  7087. localMat.multiply(lmat);
  7088. }
  7089. localMat.multiply(this.finalTransform.mat);
  7090. }
  7091. if (this.finalTransform._opMdf) {
  7092. var localOp = this.finalTransform.localOpacity;
  7093. for (i = 0; i < len; i += 1) {
  7094. localOp *= this.localTransforms[i].opacity * 0.01;
  7095. }
  7096. this.finalTransform.localOpacity = localOp;
  7097. }
  7098. }
  7099. },
  7100. searchEffectTransforms: function () {
  7101. if (this.renderableEffectsManager) {
  7102. var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  7103. if (transformEffects.length) {
  7104. this.localTransforms = [];
  7105. this.finalTransform.localMat = new Matrix();
  7106. var i = 0;
  7107. var len = transformEffects.length;
  7108. for (i = 0; i < len; i += 1) {
  7109. this.localTransforms.push(transformEffects[i]);
  7110. }
  7111. }
  7112. }
  7113. },
  7114. globalToLocal: function (pt) {
  7115. var transforms = [];
  7116. transforms.push(this.finalTransform);
  7117. var flag = true;
  7118. var comp = this.comp;
  7119. while (flag) {
  7120. if (comp.finalTransform) {
  7121. if (comp.data.hasMask) {
  7122. transforms.splice(0, 0, comp.finalTransform);
  7123. }
  7124. comp = comp.comp;
  7125. } else {
  7126. flag = false;
  7127. }
  7128. }
  7129. var i;
  7130. var len = transforms.length;
  7131. var ptNew;
  7132. for (i = 0; i < len; i += 1) {
  7133. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  7134. // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7135. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7136. }
  7137. return pt;
  7138. },
  7139. mHelper: new Matrix(),
  7140. };
  7141. function MaskElement(data, element, globalData) {
  7142. this.data = data;
  7143. this.element = element;
  7144. this.globalData = globalData;
  7145. this.storedData = [];
  7146. this.masksProperties = this.data.masksProperties || [];
  7147. this.maskElement = null;
  7148. var defs = this.globalData.defs;
  7149. var i;
  7150. var len = this.masksProperties ? this.masksProperties.length : 0;
  7151. this.viewData = createSizedArray(len);
  7152. this.solidPath = '';
  7153. var path;
  7154. var properties = this.masksProperties;
  7155. var count = 0;
  7156. var currentMasks = [];
  7157. var j;
  7158. var jLen;
  7159. var layerId = createElementID();
  7160. var rect;
  7161. var expansor;
  7162. var feMorph;
  7163. var x;
  7164. var maskType = 'clipPath';
  7165. var maskRef = 'clip-path';
  7166. for (i = 0; i < len; i += 1) {
  7167. if ((properties[i].mode !== 'a' && properties[i].mode !== 'n') || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7168. maskType = 'mask';
  7169. maskRef = 'mask';
  7170. }
  7171. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7172. rect = createNS('rect');
  7173. rect.setAttribute('fill', '#ffffff');
  7174. rect.setAttribute('width', this.element.comp.data.w || 0);
  7175. rect.setAttribute('height', this.element.comp.data.h || 0);
  7176. currentMasks.push(rect);
  7177. } else {
  7178. rect = null;
  7179. }
  7180. path = createNS('path');
  7181. if (properties[i].mode === 'n') {
  7182. // TODO move this to a factory or to a constructor
  7183. this.viewData[i] = {
  7184. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7185. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7186. elem: path,
  7187. lastPath: '',
  7188. };
  7189. defs.appendChild(path);
  7190. } else {
  7191. count += 1;
  7192. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7193. path.setAttribute('clip-rule', 'nonzero');
  7194. var filterID;
  7195. if (properties[i].x.k !== 0) {
  7196. maskType = 'mask';
  7197. maskRef = 'mask';
  7198. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7199. filterID = createElementID();
  7200. expansor = createNS('filter');
  7201. expansor.setAttribute('id', filterID);
  7202. feMorph = createNS('feMorphology');
  7203. feMorph.setAttribute('operator', 'erode');
  7204. feMorph.setAttribute('in', 'SourceGraphic');
  7205. feMorph.setAttribute('radius', '0');
  7206. expansor.appendChild(feMorph);
  7207. defs.appendChild(expansor);
  7208. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7209. } else {
  7210. feMorph = null;
  7211. x = null;
  7212. }
  7213. // TODO move this to a factory or to a constructor
  7214. this.storedData[i] = {
  7215. elem: path,
  7216. x: x,
  7217. expan: feMorph,
  7218. lastPath: '',
  7219. lastOperator: '',
  7220. filterId: filterID,
  7221. lastRadius: 0,
  7222. };
  7223. if (properties[i].mode === 'i') {
  7224. jLen = currentMasks.length;
  7225. var g = createNS('g');
  7226. for (j = 0; j < jLen; j += 1) {
  7227. g.appendChild(currentMasks[j]);
  7228. }
  7229. var mask = createNS('mask');
  7230. mask.setAttribute('mask-type', 'alpha');
  7231. mask.setAttribute('id', layerId + '_' + count);
  7232. mask.appendChild(path);
  7233. defs.appendChild(mask);
  7234. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7235. currentMasks.length = 0;
  7236. currentMasks.push(g);
  7237. } else {
  7238. currentMasks.push(path);
  7239. }
  7240. if (properties[i].inv && !this.solidPath) {
  7241. this.solidPath = this.createLayerSolidPath();
  7242. }
  7243. // TODO move this to a factory or to a constructor
  7244. this.viewData[i] = {
  7245. elem: path,
  7246. lastPath: '',
  7247. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7248. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7249. invRect: rect,
  7250. };
  7251. if (!this.viewData[i].prop.k) {
  7252. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7253. }
  7254. }
  7255. }
  7256. this.maskElement = createNS(maskType);
  7257. len = currentMasks.length;
  7258. for (i = 0; i < len; i += 1) {
  7259. this.maskElement.appendChild(currentMasks[i]);
  7260. }
  7261. if (count > 0) {
  7262. this.maskElement.setAttribute('id', layerId);
  7263. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7264. defs.appendChild(this.maskElement);
  7265. }
  7266. if (this.viewData.length) {
  7267. this.element.addRenderableComponent(this);
  7268. }
  7269. }
  7270. MaskElement.prototype.getMaskProperty = function (pos) {
  7271. return this.viewData[pos].prop;
  7272. };
  7273. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7274. var finalMat = this.element.finalTransform.mat;
  7275. var i;
  7276. var len = this.masksProperties.length;
  7277. for (i = 0; i < len; i += 1) {
  7278. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7279. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7280. }
  7281. if (this.viewData[i].op._mdf || isFirstFrame) {
  7282. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7283. }
  7284. if (this.masksProperties[i].mode !== 'n') {
  7285. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7286. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7287. }
  7288. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7289. var feMorph = this.storedData[i].expan;
  7290. if (this.storedData[i].x.v < 0) {
  7291. if (this.storedData[i].lastOperator !== 'erode') {
  7292. this.storedData[i].lastOperator = 'erode';
  7293. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7294. }
  7295. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7296. } else {
  7297. if (this.storedData[i].lastOperator !== 'dilate') {
  7298. this.storedData[i].lastOperator = 'dilate';
  7299. this.storedData[i].elem.setAttribute('filter', null);
  7300. }
  7301. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7302. }
  7303. }
  7304. }
  7305. }
  7306. };
  7307. MaskElement.prototype.getMaskelement = function () {
  7308. return this.maskElement;
  7309. };
  7310. MaskElement.prototype.createLayerSolidPath = function () {
  7311. var path = 'M0,0 ';
  7312. path += ' h' + this.globalData.compSize.w;
  7313. path += ' v' + this.globalData.compSize.h;
  7314. path += ' h-' + this.globalData.compSize.w;
  7315. path += ' v-' + this.globalData.compSize.h + ' ';
  7316. return path;
  7317. };
  7318. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7319. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7320. var i;
  7321. var len;
  7322. len = pathNodes._length;
  7323. for (i = 1; i < len; i += 1) {
  7324. // 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];
  7325. 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];
  7326. }
  7327. // 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];
  7328. if (pathNodes.c && len > 1) {
  7329. 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];
  7330. }
  7331. // pathNodes.__renderedString = pathString;
  7332. if (viewData.lastPath !== pathString) {
  7333. var pathShapeValue = '';
  7334. if (viewData.elem) {
  7335. if (pathNodes.c) {
  7336. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7337. }
  7338. viewData.elem.setAttribute('d', pathShapeValue);
  7339. }
  7340. viewData.lastPath = pathString;
  7341. }
  7342. };
  7343. MaskElement.prototype.destroy = function () {
  7344. this.element = null;
  7345. this.globalData = null;
  7346. this.maskElement = null;
  7347. this.data = null;
  7348. this.masksProperties = null;
  7349. };
  7350. const filtersFactory = (function () {
  7351. var ob = {};
  7352. ob.createFilter = createFilter;
  7353. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7354. function createFilter(filId, skipCoordinates) {
  7355. var fil = createNS('filter');
  7356. fil.setAttribute('id', filId);
  7357. if (skipCoordinates !== true) {
  7358. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7359. fil.setAttribute('x', '0%');
  7360. fil.setAttribute('y', '0%');
  7361. fil.setAttribute('width', '100%');
  7362. fil.setAttribute('height', '100%');
  7363. }
  7364. return fil;
  7365. }
  7366. function createAlphaToLuminanceFilter() {
  7367. var feColorMatrix = createNS('feColorMatrix');
  7368. feColorMatrix.setAttribute('type', 'matrix');
  7369. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7370. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7371. return feColorMatrix;
  7372. }
  7373. return ob;
  7374. }());
  7375. const featureSupport = (function () {
  7376. var ob = {
  7377. maskType: true,
  7378. svgLumaHidden: true,
  7379. offscreenCanvas: typeof OffscreenCanvas !== 'undefined',
  7380. };
  7381. 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)) {
  7382. ob.maskType = false;
  7383. }
  7384. if (/firefox/i.test(navigator.userAgent)) {
  7385. ob.svgLumaHidden = false;
  7386. }
  7387. return ob;
  7388. }());
  7389. var registeredEffects$1 = {};
  7390. var idPrefix = 'filter_result_';
  7391. function SVGEffects(elem) {
  7392. var i;
  7393. var source = 'SourceGraphic';
  7394. var len = elem.data.ef ? elem.data.ef.length : 0;
  7395. var filId = createElementID();
  7396. var fil = filtersFactory.createFilter(filId, true);
  7397. var count = 0;
  7398. this.filters = [];
  7399. var filterManager;
  7400. for (i = 0; i < len; i += 1) {
  7401. filterManager = null;
  7402. var type = elem.data.ef[i].ty;
  7403. if (registeredEffects$1[type]) {
  7404. var Effect = registeredEffects$1[type].effect;
  7405. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7406. source = idPrefix + count;
  7407. if (registeredEffects$1[type].countsAsEffect) {
  7408. count += 1;
  7409. }
  7410. }
  7411. if (filterManager) {
  7412. this.filters.push(filterManager);
  7413. }
  7414. }
  7415. if (count) {
  7416. elem.globalData.defs.appendChild(fil);
  7417. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7418. }
  7419. if (this.filters.length) {
  7420. elem.addRenderableComponent(this);
  7421. }
  7422. }
  7423. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7424. var i;
  7425. var len = this.filters.length;
  7426. for (i = 0; i < len; i += 1) {
  7427. this.filters[i].renderFrame(_isFirstFrame);
  7428. }
  7429. };
  7430. SVGEffects.prototype.getEffects = function (type) {
  7431. var i;
  7432. var len = this.filters.length;
  7433. var effects = [];
  7434. for (i = 0; i < len; i += 1) {
  7435. if (this.filters[i].type === type) {
  7436. effects.push(this.filters[i]);
  7437. }
  7438. }
  7439. return effects;
  7440. };
  7441. function registerEffect$1(id, effect, countsAsEffect) {
  7442. registeredEffects$1[id] = {
  7443. effect,
  7444. countsAsEffect,
  7445. };
  7446. }
  7447. function SVGBaseElement() {
  7448. }
  7449. SVGBaseElement.prototype = {
  7450. initRendererElement: function () {
  7451. this.layerElement = createNS('g');
  7452. },
  7453. createContainerElements: function () {
  7454. this.matteElement = createNS('g');
  7455. this.transformedElement = this.layerElement;
  7456. this.maskedElement = this.layerElement;
  7457. this._sizeChanged = false;
  7458. var layerElementParent = null;
  7459. // If this layer acts as a mask for the following layer
  7460. if (this.data.td) {
  7461. this.matteMasks = {};
  7462. var gg = createNS('g');
  7463. gg.setAttribute('id', this.layerId);
  7464. gg.appendChild(this.layerElement);
  7465. layerElementParent = gg;
  7466. this.globalData.defs.appendChild(gg);
  7467. } else if (this.data.tt) {
  7468. this.matteElement.appendChild(this.layerElement);
  7469. layerElementParent = this.matteElement;
  7470. this.baseElement = this.matteElement;
  7471. } else {
  7472. this.baseElement = this.layerElement;
  7473. }
  7474. if (this.data.ln) {
  7475. this.layerElement.setAttribute('id', this.data.ln);
  7476. }
  7477. if (this.data.cl) {
  7478. this.layerElement.setAttribute('class', this.data.cl);
  7479. }
  7480. // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7481. if (this.data.ty === 0 && !this.data.hd) {
  7482. var cp = createNS('clipPath');
  7483. var pt = createNS('path');
  7484. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7485. var clipId = createElementID();
  7486. cp.setAttribute('id', clipId);
  7487. cp.appendChild(pt);
  7488. this.globalData.defs.appendChild(cp);
  7489. if (this.checkMasks()) {
  7490. var cpGroup = createNS('g');
  7491. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7492. cpGroup.appendChild(this.layerElement);
  7493. this.transformedElement = cpGroup;
  7494. if (layerElementParent) {
  7495. layerElementParent.appendChild(this.transformedElement);
  7496. } else {
  7497. this.baseElement = this.transformedElement;
  7498. }
  7499. } else {
  7500. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7501. }
  7502. }
  7503. if (this.data.bm !== 0) {
  7504. this.setBlendMode();
  7505. }
  7506. },
  7507. renderElement: function () {
  7508. if (this.finalTransform._localMatMdf) {
  7509. this.transformedElement.setAttribute('transform', this.finalTransform.localMat.to2dCSS());
  7510. }
  7511. if (this.finalTransform._opMdf) {
  7512. this.transformedElement.setAttribute('opacity', this.finalTransform.localOpacity);
  7513. }
  7514. },
  7515. destroyBaseElement: function () {
  7516. this.layerElement = null;
  7517. this.matteElement = null;
  7518. this.maskManager.destroy();
  7519. },
  7520. getBaseElement: function () {
  7521. if (this.data.hd) {
  7522. return null;
  7523. }
  7524. return this.baseElement;
  7525. },
  7526. createRenderableComponents: function () {
  7527. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7528. this.renderableEffectsManager = new SVGEffects(this);
  7529. this.searchEffectTransforms();
  7530. },
  7531. getMatte: function (matteType) {
  7532. // This should not be a common case. But for backward compatibility, we'll create the matte object.
  7533. // It solves animations that have two consecutive layers marked as matte masks.
  7534. // Which is an undefined behavior in AE.
  7535. if (!this.matteMasks) {
  7536. this.matteMasks = {};
  7537. }
  7538. if (!this.matteMasks[matteType]) {
  7539. var id = this.layerId + '_' + matteType;
  7540. var filId;
  7541. var fil;
  7542. var useElement;
  7543. var gg;
  7544. if (matteType === 1 || matteType === 3) {
  7545. var masker = createNS('mask');
  7546. masker.setAttribute('id', id);
  7547. masker.setAttribute('mask-type', matteType === 3 ? 'luminance' : 'alpha');
  7548. useElement = createNS('use');
  7549. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7550. masker.appendChild(useElement);
  7551. this.globalData.defs.appendChild(masker);
  7552. if (!featureSupport.maskType && matteType === 1) {
  7553. masker.setAttribute('mask-type', 'luminance');
  7554. filId = createElementID();
  7555. fil = filtersFactory.createFilter(filId);
  7556. this.globalData.defs.appendChild(fil);
  7557. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7558. gg = createNS('g');
  7559. gg.appendChild(useElement);
  7560. masker.appendChild(gg);
  7561. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7562. }
  7563. } else if (matteType === 2) {
  7564. var maskGroup = createNS('mask');
  7565. maskGroup.setAttribute('id', id);
  7566. maskGroup.setAttribute('mask-type', 'alpha');
  7567. var maskGrouper = createNS('g');
  7568. maskGroup.appendChild(maskGrouper);
  7569. filId = createElementID();
  7570. fil = filtersFactory.createFilter(filId);
  7571. /// /
  7572. var feCTr = createNS('feComponentTransfer');
  7573. feCTr.setAttribute('in', 'SourceGraphic');
  7574. fil.appendChild(feCTr);
  7575. var feFunc = createNS('feFuncA');
  7576. feFunc.setAttribute('type', 'table');
  7577. feFunc.setAttribute('tableValues', '1.0 0.0');
  7578. feCTr.appendChild(feFunc);
  7579. /// /
  7580. this.globalData.defs.appendChild(fil);
  7581. var alphaRect = createNS('rect');
  7582. alphaRect.setAttribute('width', this.comp.data.w);
  7583. alphaRect.setAttribute('height', this.comp.data.h);
  7584. alphaRect.setAttribute('x', '0');
  7585. alphaRect.setAttribute('y', '0');
  7586. alphaRect.setAttribute('fill', '#ffffff');
  7587. alphaRect.setAttribute('opacity', '0');
  7588. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7589. maskGrouper.appendChild(alphaRect);
  7590. useElement = createNS('use');
  7591. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7592. maskGrouper.appendChild(useElement);
  7593. if (!featureSupport.maskType) {
  7594. maskGroup.setAttribute('mask-type', 'luminance');
  7595. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7596. gg = createNS('g');
  7597. maskGrouper.appendChild(alphaRect);
  7598. gg.appendChild(this.layerElement);
  7599. maskGrouper.appendChild(gg);
  7600. }
  7601. this.globalData.defs.appendChild(maskGroup);
  7602. }
  7603. this.matteMasks[matteType] = id;
  7604. }
  7605. return this.matteMasks[matteType];
  7606. },
  7607. setMatte: function (id) {
  7608. if (!this.matteElement) {
  7609. return;
  7610. }
  7611. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7612. },
  7613. };
  7614. /**
  7615. * @file
  7616. * Handles AE's layer parenting property.
  7617. *
  7618. */
  7619. function HierarchyElement() {}
  7620. HierarchyElement.prototype = {
  7621. /**
  7622. * @function
  7623. * Initializes hierarchy properties
  7624. *
  7625. */
  7626. initHierarchy: function () {
  7627. // element's parent list
  7628. this.hierarchy = [];
  7629. // if element is parent of another layer _isParent will be true
  7630. this._isParent = false;
  7631. this.checkParenting();
  7632. },
  7633. /**
  7634. * @function
  7635. * Sets layer's hierarchy.
  7636. * @param {array} hierarch
  7637. * layer's parent list
  7638. *
  7639. */
  7640. setHierarchy: function (hierarchy) {
  7641. this.hierarchy = hierarchy;
  7642. },
  7643. /**
  7644. * @function
  7645. * Sets layer as parent.
  7646. *
  7647. */
  7648. setAsParent: function () {
  7649. this._isParent = true;
  7650. },
  7651. /**
  7652. * @function
  7653. * Searches layer's parenting chain
  7654. *
  7655. */
  7656. checkParenting: function () {
  7657. if (this.data.parent !== undefined) {
  7658. this.comp.buildElementParenting(this, this.data.parent, []);
  7659. }
  7660. },
  7661. };
  7662. function RenderableDOMElement() {}
  7663. (function () {
  7664. var _prototype = {
  7665. initElement: function (data, globalData, comp) {
  7666. this.initFrame();
  7667. this.initBaseData(data, globalData, comp);
  7668. this.initTransform(data, globalData, comp);
  7669. this.initHierarchy();
  7670. this.initRenderable();
  7671. this.initRendererElement();
  7672. this.createContainerElements();
  7673. this.createRenderableComponents();
  7674. this.createContent();
  7675. this.hide();
  7676. },
  7677. hide: function () {
  7678. // console.log('HIDE', this);
  7679. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7680. var elem = this.baseElement || this.layerElement;
  7681. elem.style.display = 'none';
  7682. this.hidden = true;
  7683. }
  7684. },
  7685. show: function () {
  7686. // console.log('SHOW', this);
  7687. if (this.isInRange && !this.isTransparent) {
  7688. if (!this.data.hd) {
  7689. var elem = this.baseElement || this.layerElement;
  7690. elem.style.display = 'block';
  7691. }
  7692. this.hidden = false;
  7693. this._isFirstFrame = true;
  7694. }
  7695. },
  7696. renderFrame: function () {
  7697. // If it is exported as hidden (data.hd === true) no need to render
  7698. // If it is not visible no need to render
  7699. if (this.data.hd || this.hidden) {
  7700. return;
  7701. }
  7702. this.renderTransform();
  7703. this.renderRenderable();
  7704. this.renderLocalTransform();
  7705. this.renderElement();
  7706. this.renderInnerContent();
  7707. if (this._isFirstFrame) {
  7708. this._isFirstFrame = false;
  7709. }
  7710. },
  7711. renderInnerContent: function () {},
  7712. prepareFrame: function (num) {
  7713. this._mdf = false;
  7714. this.prepareRenderableFrame(num);
  7715. this.prepareProperties(num, this.isInRange);
  7716. this.checkTransparency();
  7717. },
  7718. destroy: function () {
  7719. this.innerElem = null;
  7720. this.destroyBaseElement();
  7721. },
  7722. };
  7723. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  7724. }());
  7725. function IImageElement(data, globalData, comp) {
  7726. this.assetData = globalData.getAssetData(data.refId);
  7727. if (this.assetData && this.assetData.sid) {
  7728. this.assetData = globalData.slotManager.getProp(this.assetData);
  7729. }
  7730. this.initElement(data, globalData, comp);
  7731. this.sourceRect = {
  7732. top: 0, left: 0, width: this.assetData.w, height: this.assetData.h,
  7733. };
  7734. }
  7735. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  7736. IImageElement.prototype.createContent = function () {
  7737. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7738. this.innerElem = createNS('image');
  7739. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  7740. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  7741. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7742. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  7743. this.layerElement.appendChild(this.innerElem);
  7744. };
  7745. IImageElement.prototype.sourceRectAtTime = function () {
  7746. return this.sourceRect;
  7747. };
  7748. function ProcessedElement(element, position) {
  7749. this.elem = element;
  7750. this.pos = position;
  7751. }
  7752. function IShapeElement() {
  7753. }
  7754. IShapeElement.prototype = {
  7755. addShapeToModifiers: function (data) {
  7756. var i;
  7757. var len = this.shapeModifiers.length;
  7758. for (i = 0; i < len; i += 1) {
  7759. this.shapeModifiers[i].addShape(data);
  7760. }
  7761. },
  7762. isShapeInAnimatedModifiers: function (data) {
  7763. var i = 0;
  7764. var len = this.shapeModifiers.length;
  7765. while (i < len) {
  7766. if (this.shapeModifiers[i].isAnimatedWithShape(data)) {
  7767. return true;
  7768. }
  7769. }
  7770. return false;
  7771. },
  7772. renderModifiers: function () {
  7773. if (!this.shapeModifiers.length) {
  7774. return;
  7775. }
  7776. var i;
  7777. var len = this.shapes.length;
  7778. for (i = 0; i < len; i += 1) {
  7779. this.shapes[i].sh.reset();
  7780. }
  7781. len = this.shapeModifiers.length;
  7782. var shouldBreakProcess;
  7783. for (i = len - 1; i >= 0; i -= 1) {
  7784. shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame);
  7785. // workaround to fix cases where a repeater resets the shape so the following processes get called twice
  7786. // TODO: find a better solution for this
  7787. if (shouldBreakProcess) {
  7788. break;
  7789. }
  7790. }
  7791. },
  7792. searchProcessedElement: function (elem) {
  7793. var elements = this.processedElements;
  7794. var i = 0;
  7795. var len = elements.length;
  7796. while (i < len) {
  7797. if (elements[i].elem === elem) {
  7798. return elements[i].pos;
  7799. }
  7800. i += 1;
  7801. }
  7802. return 0;
  7803. },
  7804. addProcessedElement: function (elem, pos) {
  7805. var elements = this.processedElements;
  7806. var i = elements.length;
  7807. while (i) {
  7808. i -= 1;
  7809. if (elements[i].elem === elem) {
  7810. elements[i].pos = pos;
  7811. return;
  7812. }
  7813. }
  7814. elements.push(new ProcessedElement(elem, pos));
  7815. },
  7816. prepareFrame: function (num) {
  7817. this.prepareRenderableFrame(num);
  7818. this.prepareProperties(num, this.isInRange);
  7819. },
  7820. };
  7821. const lineCapEnum = {
  7822. 1: 'butt',
  7823. 2: 'round',
  7824. 3: 'square',
  7825. };
  7826. const lineJoinEnum = {
  7827. 1: 'miter',
  7828. 2: 'round',
  7829. 3: 'bevel',
  7830. };
  7831. function SVGShapeData(transformers, level, shape) {
  7832. this.caches = [];
  7833. this.styles = [];
  7834. this.transformers = transformers;
  7835. this.lStr = '';
  7836. this.sh = shape;
  7837. this.lvl = level;
  7838. // TODO find if there are some cases where _isAnimated can be false.
  7839. // For now, since shapes add up with other shapes. They have to be calculated every time.
  7840. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  7841. this._isAnimated = !!shape.k;
  7842. // TODO: commenting this for now since all shapes are animated
  7843. var i = 0;
  7844. var len = transformers.length;
  7845. while (i < len) {
  7846. if (transformers[i].mProps.dynamicProperties.length) {
  7847. this._isAnimated = true;
  7848. break;
  7849. }
  7850. i += 1;
  7851. }
  7852. }
  7853. SVGShapeData.prototype.setAsAnimated = function () {
  7854. this._isAnimated = true;
  7855. };
  7856. function SVGStyleData(data, level) {
  7857. this.data = data;
  7858. this.type = data.ty;
  7859. this.d = '';
  7860. this.lvl = level;
  7861. this._mdf = false;
  7862. this.closed = data.hd === true;
  7863. this.pElem = createNS('path');
  7864. this.msElem = null;
  7865. }
  7866. SVGStyleData.prototype.reset = function () {
  7867. this.d = '';
  7868. this._mdf = false;
  7869. };
  7870. function DashProperty(elem, data, renderer, container) {
  7871. this.elem = elem;
  7872. this.frameId = -1;
  7873. this.dataProps = createSizedArray(data.length);
  7874. this.renderer = renderer;
  7875. this.k = false;
  7876. this.dashStr = '';
  7877. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  7878. this.dashoffset = createTypedArray('float32', 1);
  7879. this.initDynamicPropertyContainer(container);
  7880. var i;
  7881. var len = data.length || 0;
  7882. var prop;
  7883. for (i = 0; i < len; i += 1) {
  7884. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  7885. this.k = prop.k || this.k;
  7886. this.dataProps[i] = { n: data[i].n, p: prop };
  7887. }
  7888. if (!this.k) {
  7889. this.getValue(true);
  7890. }
  7891. this._isAnimated = this.k;
  7892. }
  7893. DashProperty.prototype.getValue = function (forceRender) {
  7894. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  7895. return;
  7896. }
  7897. this.frameId = this.elem.globalData.frameId;
  7898. this.iterateDynamicProperties();
  7899. this._mdf = this._mdf || forceRender;
  7900. if (this._mdf) {
  7901. var i = 0;
  7902. var len = this.dataProps.length;
  7903. if (this.renderer === 'svg') {
  7904. this.dashStr = '';
  7905. }
  7906. for (i = 0; i < len; i += 1) {
  7907. if (this.dataProps[i].n !== 'o') {
  7908. if (this.renderer === 'svg') {
  7909. this.dashStr += ' ' + this.dataProps[i].p.v;
  7910. } else {
  7911. this.dashArray[i] = this.dataProps[i].p.v;
  7912. }
  7913. } else {
  7914. this.dashoffset[0] = this.dataProps[i].p.v;
  7915. }
  7916. }
  7917. }
  7918. };
  7919. extendPrototype([DynamicPropertyContainer], DashProperty);
  7920. function SVGStrokeStyleData(elem, data, styleOb) {
  7921. this.initDynamicPropertyContainer(elem);
  7922. this.getValue = this.iterateDynamicProperties;
  7923. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7924. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  7925. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  7926. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7927. this.style = styleOb;
  7928. this._isAnimated = !!this._isAnimated;
  7929. }
  7930. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  7931. function SVGFillStyleData(elem, data, styleOb) {
  7932. this.initDynamicPropertyContainer(elem);
  7933. this.getValue = this.iterateDynamicProperties;
  7934. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7935. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7936. this.style = styleOb;
  7937. }
  7938. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  7939. function SVGNoStyleData(elem, data, styleOb) {
  7940. this.initDynamicPropertyContainer(elem);
  7941. this.getValue = this.iterateDynamicProperties;
  7942. this.style = styleOb;
  7943. }
  7944. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  7945. function GradientProperty(elem, data, container) {
  7946. this.data = data;
  7947. this.c = createTypedArray('uint8c', data.p * 4);
  7948. var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p * 4) : data.k.k.length - data.p * 4;
  7949. this.o = createTypedArray('float32', cLength);
  7950. this._cmdf = false;
  7951. this._omdf = false;
  7952. this._collapsable = this.checkCollapsable();
  7953. this._hasOpacity = cLength;
  7954. this.initDynamicPropertyContainer(container);
  7955. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  7956. this.k = this.prop.k;
  7957. this.getValue(true);
  7958. }
  7959. GradientProperty.prototype.comparePoints = function (values, points) {
  7960. var i = 0;
  7961. var len = this.o.length / 2;
  7962. var diff;
  7963. while (i < len) {
  7964. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  7965. if (diff > 0.01) {
  7966. return false;
  7967. }
  7968. i += 1;
  7969. }
  7970. return true;
  7971. };
  7972. GradientProperty.prototype.checkCollapsable = function () {
  7973. if (this.o.length / 2 !== this.c.length / 4) {
  7974. return false;
  7975. }
  7976. if (this.data.k.k[0].s) {
  7977. var i = 0;
  7978. var len = this.data.k.k.length;
  7979. while (i < len) {
  7980. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  7981. return false;
  7982. }
  7983. i += 1;
  7984. }
  7985. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  7986. return false;
  7987. }
  7988. return true;
  7989. };
  7990. GradientProperty.prototype.getValue = function (forceRender) {
  7991. this.prop.getValue();
  7992. this._mdf = false;
  7993. this._cmdf = false;
  7994. this._omdf = false;
  7995. if (this.prop._mdf || forceRender) {
  7996. var i;
  7997. var len = this.data.p * 4;
  7998. var mult;
  7999. var val;
  8000. for (i = 0; i < len; i += 1) {
  8001. mult = i % 4 === 0 ? 100 : 255;
  8002. val = Math.round(this.prop.v[i] * mult);
  8003. if (this.c[i] !== val) {
  8004. this.c[i] = val;
  8005. this._cmdf = !forceRender;
  8006. }
  8007. }
  8008. if (this.o.length) {
  8009. len = this.prop.v.length;
  8010. for (i = this.data.p * 4; i < len; i += 1) {
  8011. mult = i % 2 === 0 ? 100 : 1;
  8012. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  8013. if (this.o[i - this.data.p * 4] !== val) {
  8014. this.o[i - this.data.p * 4] = val;
  8015. this._omdf = !forceRender;
  8016. }
  8017. }
  8018. }
  8019. this._mdf = !forceRender;
  8020. }
  8021. };
  8022. extendPrototype([DynamicPropertyContainer], GradientProperty);
  8023. function SVGGradientFillStyleData(elem, data, styleOb) {
  8024. this.initDynamicPropertyContainer(elem);
  8025. this.getValue = this.iterateDynamicProperties;
  8026. this.initGradientData(elem, data, styleOb);
  8027. }
  8028. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  8029. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8030. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  8031. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  8032. this.h = PropertyFactory.getProp(elem, data.h || { k: 0 }, 0, 0.01, this);
  8033. this.a = PropertyFactory.getProp(elem, data.a || { k: 0 }, 0, degToRads, this);
  8034. this.g = new GradientProperty(elem, data.g, this);
  8035. this.style = styleOb;
  8036. this.stops = [];
  8037. this.setGradientData(styleOb.pElem, data);
  8038. this.setGradientOpacity(data, styleOb);
  8039. this._isAnimated = !!this._isAnimated;
  8040. };
  8041. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  8042. var gradientId = createElementID();
  8043. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8044. gfill.setAttribute('id', gradientId);
  8045. gfill.setAttribute('spreadMethod', 'pad');
  8046. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8047. var stops = [];
  8048. var stop;
  8049. var j;
  8050. var jLen;
  8051. jLen = data.g.p * 4;
  8052. for (j = 0; j < jLen; j += 4) {
  8053. stop = createNS('stop');
  8054. gfill.appendChild(stop);
  8055. stops.push(stop);
  8056. }
  8057. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  8058. this.gf = gfill;
  8059. this.cst = stops;
  8060. };
  8061. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  8062. if (this.g._hasOpacity && !this.g._collapsable) {
  8063. var stop;
  8064. var j;
  8065. var jLen;
  8066. var mask = createNS('mask');
  8067. var maskElement = createNS('path');
  8068. mask.appendChild(maskElement);
  8069. var opacityId = createElementID();
  8070. var maskId = createElementID();
  8071. mask.setAttribute('id', maskId);
  8072. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8073. opFill.setAttribute('id', opacityId);
  8074. opFill.setAttribute('spreadMethod', 'pad');
  8075. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8076. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8077. var stops = this.stops;
  8078. for (j = data.g.p * 4; j < jLen; j += 2) {
  8079. stop = createNS('stop');
  8080. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8081. opFill.appendChild(stop);
  8082. stops.push(stop);
  8083. }
  8084. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8085. if (data.ty === 'gs') {
  8086. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8087. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8088. if (data.lj === 1) {
  8089. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8090. }
  8091. }
  8092. this.of = opFill;
  8093. this.ms = mask;
  8094. this.ost = stops;
  8095. this.maskId = maskId;
  8096. styleOb.msElem = maskElement;
  8097. }
  8098. };
  8099. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8100. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8101. this.initDynamicPropertyContainer(elem);
  8102. this.getValue = this.iterateDynamicProperties;
  8103. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8104. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8105. this.initGradientData(elem, data, styleOb);
  8106. this._isAnimated = !!this._isAnimated;
  8107. }
  8108. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8109. function ShapeGroupData() {
  8110. this.it = [];
  8111. this.prevViewData = [];
  8112. this.gr = createNS('g');
  8113. }
  8114. function SVGTransformData(mProps, op, container) {
  8115. this.transform = {
  8116. mProps: mProps,
  8117. op: op,
  8118. container: container,
  8119. };
  8120. this.elements = [];
  8121. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8122. }
  8123. const buildShapeString = function (pathNodes, length, closed, mat) {
  8124. if (length === 0) {
  8125. return '';
  8126. }
  8127. var _o = pathNodes.o;
  8128. var _i = pathNodes.i;
  8129. var _v = pathNodes.v;
  8130. var i;
  8131. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8132. for (i = 1; i < length; i += 1) {
  8133. 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]);
  8134. }
  8135. if (closed && length) {
  8136. 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]);
  8137. shapeString += 'z';
  8138. }
  8139. return shapeString;
  8140. };
  8141. const SVGElementsRenderer = (function () {
  8142. var _identityMatrix = new Matrix();
  8143. var _matrixHelper = new Matrix();
  8144. var ob = {
  8145. createRenderFunction: createRenderFunction,
  8146. };
  8147. function createRenderFunction(data) {
  8148. switch (data.ty) {
  8149. case 'fl':
  8150. return renderFill;
  8151. case 'gf':
  8152. return renderGradient;
  8153. case 'gs':
  8154. return renderGradientStroke;
  8155. case 'st':
  8156. return renderStroke;
  8157. case 'sh':
  8158. case 'el':
  8159. case 'rc':
  8160. case 'sr':
  8161. return renderPath;
  8162. case 'tr':
  8163. return renderContentTransform;
  8164. case 'no':
  8165. return renderNoop;
  8166. default:
  8167. return null;
  8168. }
  8169. }
  8170. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8171. if (isFirstFrame || itemData.transform.op._mdf) {
  8172. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8173. }
  8174. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8175. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8176. }
  8177. }
  8178. function renderNoop() {
  8179. }
  8180. function renderPath(styleData, itemData, isFirstFrame) {
  8181. var j;
  8182. var jLen;
  8183. var pathStringTransformed;
  8184. var redraw;
  8185. var pathNodes;
  8186. var l;
  8187. var lLen = itemData.styles.length;
  8188. var lvl = itemData.lvl;
  8189. var paths;
  8190. var mat;
  8191. var iterations;
  8192. var k;
  8193. for (l = 0; l < lLen; l += 1) {
  8194. redraw = itemData.sh._mdf || isFirstFrame;
  8195. if (itemData.styles[l].lvl < lvl) {
  8196. mat = _matrixHelper.reset();
  8197. iterations = lvl - itemData.styles[l].lvl;
  8198. k = itemData.transformers.length - 1;
  8199. while (!redraw && iterations > 0) {
  8200. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8201. iterations -= 1;
  8202. k -= 1;
  8203. }
  8204. if (redraw) {
  8205. iterations = lvl - itemData.styles[l].lvl;
  8206. k = itemData.transformers.length - 1;
  8207. while (iterations > 0) {
  8208. mat.multiply(itemData.transformers[k].mProps.v);
  8209. iterations -= 1;
  8210. k -= 1;
  8211. }
  8212. }
  8213. } else {
  8214. mat = _identityMatrix;
  8215. }
  8216. paths = itemData.sh.paths;
  8217. jLen = paths._length;
  8218. if (redraw) {
  8219. pathStringTransformed = '';
  8220. for (j = 0; j < jLen; j += 1) {
  8221. pathNodes = paths.shapes[j];
  8222. if (pathNodes && pathNodes._length) {
  8223. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8224. }
  8225. }
  8226. itemData.caches[l] = pathStringTransformed;
  8227. } else {
  8228. pathStringTransformed = itemData.caches[l];
  8229. }
  8230. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8231. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8232. }
  8233. }
  8234. function renderFill(styleData, itemData, isFirstFrame) {
  8235. var styleElem = itemData.style;
  8236. if (itemData.c._mdf || isFirstFrame) {
  8237. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8238. }
  8239. if (itemData.o._mdf || isFirstFrame) {
  8240. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8241. }
  8242. }
  8243. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8244. renderGradient(styleData, itemData, isFirstFrame);
  8245. renderStroke(styleData, itemData, isFirstFrame);
  8246. }
  8247. function renderGradient(styleData, itemData, isFirstFrame) {
  8248. var gfill = itemData.gf;
  8249. var hasOpacity = itemData.g._hasOpacity;
  8250. var pt1 = itemData.s.v;
  8251. var pt2 = itemData.e.v;
  8252. if (itemData.o._mdf || isFirstFrame) {
  8253. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8254. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8255. }
  8256. if (itemData.s._mdf || isFirstFrame) {
  8257. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8258. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8259. gfill.setAttribute(attr1, pt1[0]);
  8260. gfill.setAttribute(attr2, pt1[1]);
  8261. if (hasOpacity && !itemData.g._collapsable) {
  8262. itemData.of.setAttribute(attr1, pt1[0]);
  8263. itemData.of.setAttribute(attr2, pt1[1]);
  8264. }
  8265. }
  8266. var stops;
  8267. var i;
  8268. var len;
  8269. var stop;
  8270. if (itemData.g._cmdf || isFirstFrame) {
  8271. stops = itemData.cst;
  8272. var cValues = itemData.g.c;
  8273. len = stops.length;
  8274. for (i = 0; i < len; i += 1) {
  8275. stop = stops[i];
  8276. stop.setAttribute('offset', cValues[i * 4] + '%');
  8277. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8278. }
  8279. }
  8280. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8281. var oValues = itemData.g.o;
  8282. if (itemData.g._collapsable) {
  8283. stops = itemData.cst;
  8284. } else {
  8285. stops = itemData.ost;
  8286. }
  8287. len = stops.length;
  8288. for (i = 0; i < len; i += 1) {
  8289. stop = stops[i];
  8290. if (!itemData.g._collapsable) {
  8291. stop.setAttribute('offset', oValues[i * 2] + '%');
  8292. }
  8293. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8294. }
  8295. }
  8296. if (styleData.t === 1) {
  8297. if (itemData.e._mdf || isFirstFrame) {
  8298. gfill.setAttribute('x2', pt2[0]);
  8299. gfill.setAttribute('y2', pt2[1]);
  8300. if (hasOpacity && !itemData.g._collapsable) {
  8301. itemData.of.setAttribute('x2', pt2[0]);
  8302. itemData.of.setAttribute('y2', pt2[1]);
  8303. }
  8304. }
  8305. } else {
  8306. var rad;
  8307. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8308. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8309. gfill.setAttribute('r', rad);
  8310. if (hasOpacity && !itemData.g._collapsable) {
  8311. itemData.of.setAttribute('r', rad);
  8312. }
  8313. }
  8314. if (itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8315. if (!rad) {
  8316. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8317. }
  8318. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8319. var percent = itemData.h.v;
  8320. if (percent >= 1) {
  8321. percent = 0.99;
  8322. } else if (percent <= -1) {
  8323. percent = -0.99;
  8324. }
  8325. var dist = rad * percent;
  8326. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8327. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8328. gfill.setAttribute('fx', x);
  8329. gfill.setAttribute('fy', y);
  8330. if (hasOpacity && !itemData.g._collapsable) {
  8331. itemData.of.setAttribute('fx', x);
  8332. itemData.of.setAttribute('fy', y);
  8333. }
  8334. }
  8335. // gfill.setAttribute('fy','200');
  8336. }
  8337. }
  8338. function renderStroke(styleData, itemData, isFirstFrame) {
  8339. var styleElem = itemData.style;
  8340. var d = itemData.d;
  8341. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8342. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8343. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8344. }
  8345. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8346. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8347. }
  8348. if (itemData.o._mdf || isFirstFrame) {
  8349. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8350. }
  8351. if (itemData.w._mdf || isFirstFrame) {
  8352. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8353. if (styleElem.msElem) {
  8354. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8355. }
  8356. }
  8357. }
  8358. return ob;
  8359. }());
  8360. function SVGShapeElement(data, globalData, comp) {
  8361. // List of drawable elements
  8362. this.shapes = [];
  8363. // Full shape data
  8364. this.shapesData = data.shapes;
  8365. // List of styles that will be applied to shapes
  8366. this.stylesList = [];
  8367. // List of modifiers that will be applied to shapes
  8368. this.shapeModifiers = [];
  8369. // List of items in shape tree
  8370. this.itemsData = [];
  8371. // List of items in previous shape tree
  8372. this.processedElements = [];
  8373. // List of animated components
  8374. this.animatedContents = [];
  8375. this.initElement(data, globalData, comp);
  8376. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8377. // List of elements that have been created
  8378. this.prevViewData = [];
  8379. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8380. }
  8381. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8382. SVGShapeElement.prototype.initSecondaryElement = function () {
  8383. };
  8384. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8385. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8386. SVGShapeElement.prototype.createContent = function () {
  8387. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8388. this.filterUniqueShapes();
  8389. };
  8390. /*
  8391. This method searches for multiple shapes that affect a single element and one of them is animated
  8392. */
  8393. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8394. var i;
  8395. var len = this.shapes.length;
  8396. var shape;
  8397. var j;
  8398. var jLen = this.stylesList.length;
  8399. var style;
  8400. var tempShapes = [];
  8401. var areAnimated = false;
  8402. for (j = 0; j < jLen; j += 1) {
  8403. style = this.stylesList[j];
  8404. areAnimated = false;
  8405. tempShapes.length = 0;
  8406. for (i = 0; i < len; i += 1) {
  8407. shape = this.shapes[i];
  8408. if (shape.styles.indexOf(style) !== -1) {
  8409. tempShapes.push(shape);
  8410. areAnimated = shape._isAnimated || areAnimated;
  8411. }
  8412. }
  8413. if (tempShapes.length > 1 && areAnimated) {
  8414. this.setShapesAsAnimated(tempShapes);
  8415. }
  8416. }
  8417. };
  8418. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8419. var i;
  8420. var len = shapes.length;
  8421. for (i = 0; i < len; i += 1) {
  8422. shapes[i].setAsAnimated();
  8423. }
  8424. };
  8425. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8426. // TODO: prevent drawing of hidden styles
  8427. var elementData;
  8428. var styleOb = new SVGStyleData(data, level);
  8429. var pathElement = styleOb.pElem;
  8430. if (data.ty === 'st') {
  8431. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8432. } else if (data.ty === 'fl') {
  8433. elementData = new SVGFillStyleData(this, data, styleOb);
  8434. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8435. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8436. elementData = new GradientConstructor(this, data, styleOb);
  8437. this.globalData.defs.appendChild(elementData.gf);
  8438. if (elementData.maskId) {
  8439. this.globalData.defs.appendChild(elementData.ms);
  8440. this.globalData.defs.appendChild(elementData.of);
  8441. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8442. }
  8443. } else if (data.ty === 'no') {
  8444. elementData = new SVGNoStyleData(this, data, styleOb);
  8445. }
  8446. if (data.ty === 'st' || data.ty === 'gs') {
  8447. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8448. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8449. pathElement.setAttribute('fill-opacity', '0');
  8450. if (data.lj === 1) {
  8451. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8452. }
  8453. }
  8454. if (data.r === 2) {
  8455. pathElement.setAttribute('fill-rule', 'evenodd');
  8456. }
  8457. if (data.ln) {
  8458. pathElement.setAttribute('id', data.ln);
  8459. }
  8460. if (data.cl) {
  8461. pathElement.setAttribute('class', data.cl);
  8462. }
  8463. if (data.bm) {
  8464. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8465. }
  8466. this.stylesList.push(styleOb);
  8467. this.addToAnimatedContents(data, elementData);
  8468. return elementData;
  8469. };
  8470. SVGShapeElement.prototype.createGroupElement = function (data) {
  8471. var elementData = new ShapeGroupData();
  8472. if (data.ln) {
  8473. elementData.gr.setAttribute('id', data.ln);
  8474. }
  8475. if (data.cl) {
  8476. elementData.gr.setAttribute('class', data.cl);
  8477. }
  8478. if (data.bm) {
  8479. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8480. }
  8481. return elementData;
  8482. };
  8483. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8484. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8485. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8486. this.addToAnimatedContents(data, elementData);
  8487. return elementData;
  8488. };
  8489. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8490. var ty = 4;
  8491. if (data.ty === 'rc') {
  8492. ty = 5;
  8493. } else if (data.ty === 'el') {
  8494. ty = 6;
  8495. } else if (data.ty === 'sr') {
  8496. ty = 7;
  8497. }
  8498. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8499. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8500. this.shapes.push(elementData);
  8501. this.addShapeToModifiers(elementData);
  8502. this.addToAnimatedContents(data, elementData);
  8503. return elementData;
  8504. };
  8505. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8506. var i = 0;
  8507. var len = this.animatedContents.length;
  8508. while (i < len) {
  8509. if (this.animatedContents[i].element === element) {
  8510. return;
  8511. }
  8512. i += 1;
  8513. }
  8514. this.animatedContents.push({
  8515. fn: SVGElementsRenderer.createRenderFunction(data),
  8516. element: element,
  8517. data: data,
  8518. });
  8519. };
  8520. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8521. var arr = elementData.styles;
  8522. var j;
  8523. var jLen = this.stylesList.length;
  8524. for (j = 0; j < jLen; j += 1) {
  8525. if (!this.stylesList[j].closed) {
  8526. arr.push(this.stylesList[j]);
  8527. }
  8528. }
  8529. };
  8530. SVGShapeElement.prototype.reloadShapes = function () {
  8531. this._isFirstFrame = true;
  8532. var i;
  8533. var len = this.itemsData.length;
  8534. for (i = 0; i < len; i += 1) {
  8535. this.prevViewData[i] = this.itemsData[i];
  8536. }
  8537. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8538. this.filterUniqueShapes();
  8539. len = this.dynamicProperties.length;
  8540. for (i = 0; i < len; i += 1) {
  8541. this.dynamicProperties[i].getValue();
  8542. }
  8543. this.renderModifiers();
  8544. };
  8545. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8546. var ownTransformers = [].concat(transformers);
  8547. var i;
  8548. var len = arr.length - 1;
  8549. var j;
  8550. var jLen;
  8551. var ownStyles = [];
  8552. var ownModifiers = [];
  8553. var currentTransform;
  8554. var modifier;
  8555. var processedPos;
  8556. for (i = len; i >= 0; i -= 1) {
  8557. processedPos = this.searchProcessedElement(arr[i]);
  8558. if (!processedPos) {
  8559. arr[i]._render = render;
  8560. } else {
  8561. itemsData[i] = prevViewData[processedPos - 1];
  8562. }
  8563. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8564. if (!processedPos) {
  8565. itemsData[i] = this.createStyleElement(arr[i], level);
  8566. } else {
  8567. itemsData[i].style.closed = false;
  8568. }
  8569. if (arr[i]._render) {
  8570. if (itemsData[i].style.pElem.parentNode !== container) {
  8571. container.appendChild(itemsData[i].style.pElem);
  8572. }
  8573. }
  8574. ownStyles.push(itemsData[i].style);
  8575. } else if (arr[i].ty === 'gr') {
  8576. if (!processedPos) {
  8577. itemsData[i] = this.createGroupElement(arr[i]);
  8578. } else {
  8579. jLen = itemsData[i].it.length;
  8580. for (j = 0; j < jLen; j += 1) {
  8581. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8582. }
  8583. }
  8584. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8585. if (arr[i]._render) {
  8586. if (itemsData[i].gr.parentNode !== container) {
  8587. container.appendChild(itemsData[i].gr);
  8588. }
  8589. }
  8590. } else if (arr[i].ty === 'tr') {
  8591. if (!processedPos) {
  8592. itemsData[i] = this.createTransformElement(arr[i], container);
  8593. }
  8594. currentTransform = itemsData[i].transform;
  8595. ownTransformers.push(currentTransform);
  8596. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8597. if (!processedPos) {
  8598. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8599. }
  8600. this.setElementStyles(itemsData[i]);
  8601. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'ms' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  8602. if (!processedPos) {
  8603. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8604. modifier.init(this, arr[i]);
  8605. itemsData[i] = modifier;
  8606. this.shapeModifiers.push(modifier);
  8607. } else {
  8608. modifier = itemsData[i];
  8609. modifier.closed = false;
  8610. }
  8611. ownModifiers.push(modifier);
  8612. } else if (arr[i].ty === 'rp') {
  8613. if (!processedPos) {
  8614. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8615. itemsData[i] = modifier;
  8616. modifier.init(this, arr, i, itemsData);
  8617. this.shapeModifiers.push(modifier);
  8618. render = false;
  8619. } else {
  8620. modifier = itemsData[i];
  8621. modifier.closed = true;
  8622. }
  8623. ownModifiers.push(modifier);
  8624. }
  8625. this.addProcessedElement(arr[i], i + 1);
  8626. }
  8627. len = ownStyles.length;
  8628. for (i = 0; i < len; i += 1) {
  8629. ownStyles[i].closed = true;
  8630. }
  8631. len = ownModifiers.length;
  8632. for (i = 0; i < len; i += 1) {
  8633. ownModifiers[i].closed = true;
  8634. }
  8635. };
  8636. SVGShapeElement.prototype.renderInnerContent = function () {
  8637. this.renderModifiers();
  8638. var i;
  8639. var len = this.stylesList.length;
  8640. for (i = 0; i < len; i += 1) {
  8641. this.stylesList[i].reset();
  8642. }
  8643. this.renderShape();
  8644. for (i = 0; i < len; i += 1) {
  8645. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8646. if (this.stylesList[i].msElem) {
  8647. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  8648. // Adding M0 0 fixes same mask bug on all browsers
  8649. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8650. }
  8651. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8652. }
  8653. }
  8654. };
  8655. SVGShapeElement.prototype.renderShape = function () {
  8656. var i;
  8657. var len = this.animatedContents.length;
  8658. var animatedContent;
  8659. for (i = 0; i < len; i += 1) {
  8660. animatedContent = this.animatedContents[i];
  8661. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8662. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8663. }
  8664. }
  8665. };
  8666. SVGShapeElement.prototype.destroy = function () {
  8667. this.destroyBaseElement();
  8668. this.shapesData = null;
  8669. this.itemsData = null;
  8670. };
  8671. function LetterProps(o, sw, sc, fc, m, p) {
  8672. this.o = o;
  8673. this.sw = sw;
  8674. this.sc = sc;
  8675. this.fc = fc;
  8676. this.m = m;
  8677. this.p = p;
  8678. this._mdf = {
  8679. o: true,
  8680. sw: !!sw,
  8681. sc: !!sc,
  8682. fc: !!fc,
  8683. m: true,
  8684. p: true,
  8685. };
  8686. }
  8687. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  8688. this._mdf.o = false;
  8689. this._mdf.sw = false;
  8690. this._mdf.sc = false;
  8691. this._mdf.fc = false;
  8692. this._mdf.m = false;
  8693. this._mdf.p = false;
  8694. var updated = false;
  8695. if (this.o !== o) {
  8696. this.o = o;
  8697. this._mdf.o = true;
  8698. updated = true;
  8699. }
  8700. if (this.sw !== sw) {
  8701. this.sw = sw;
  8702. this._mdf.sw = true;
  8703. updated = true;
  8704. }
  8705. if (this.sc !== sc) {
  8706. this.sc = sc;
  8707. this._mdf.sc = true;
  8708. updated = true;
  8709. }
  8710. if (this.fc !== fc) {
  8711. this.fc = fc;
  8712. this._mdf.fc = true;
  8713. updated = true;
  8714. }
  8715. if (this.m !== m) {
  8716. this.m = m;
  8717. this._mdf.m = true;
  8718. updated = true;
  8719. }
  8720. 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])) {
  8721. this.p = p;
  8722. this._mdf.p = true;
  8723. updated = true;
  8724. }
  8725. return updated;
  8726. };
  8727. function TextProperty(elem, data) {
  8728. this._frameId = initialDefaultFrame;
  8729. this.pv = '';
  8730. this.v = '';
  8731. this.kf = false;
  8732. this._isFirstFrame = true;
  8733. this._mdf = false;
  8734. if (data.d && data.d.sid) {
  8735. data.d = elem.globalData.slotManager.getProp(data.d);
  8736. }
  8737. this.data = data;
  8738. this.elem = elem;
  8739. this.comp = this.elem.comp;
  8740. this.keysIndex = 0;
  8741. this.canResize = false;
  8742. this.minimumFontSize = 1;
  8743. this.effectsSequence = [];
  8744. this.currentData = {
  8745. ascent: 0,
  8746. boxWidth: this.defaultBoxWidth,
  8747. f: '',
  8748. fStyle: '',
  8749. fWeight: '',
  8750. fc: '',
  8751. j: '',
  8752. justifyOffset: '',
  8753. l: [],
  8754. lh: 0,
  8755. lineWidths: [],
  8756. ls: '',
  8757. of: '',
  8758. s: '',
  8759. sc: '',
  8760. sw: 0,
  8761. t: 0,
  8762. tr: 0,
  8763. sz: 0,
  8764. ps: null,
  8765. fillColorAnim: false,
  8766. strokeColorAnim: false,
  8767. strokeWidthAnim: false,
  8768. yOffset: 0,
  8769. finalSize: 0,
  8770. finalText: [],
  8771. finalLineHeight: 0,
  8772. __complete: false,
  8773. };
  8774. this.copyData(this.currentData, this.data.d.k[0].s);
  8775. if (!this.searchProperty()) {
  8776. this.completeTextData(this.currentData);
  8777. }
  8778. }
  8779. TextProperty.prototype.defaultBoxWidth = [0, 0];
  8780. TextProperty.prototype.copyData = function (obj, data) {
  8781. for (var s in data) {
  8782. if (Object.prototype.hasOwnProperty.call(data, s)) {
  8783. obj[s] = data[s];
  8784. }
  8785. }
  8786. return obj;
  8787. };
  8788. TextProperty.prototype.setCurrentData = function (data) {
  8789. if (!data.__complete) {
  8790. this.completeTextData(data);
  8791. }
  8792. this.currentData = data;
  8793. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  8794. this._mdf = true;
  8795. };
  8796. TextProperty.prototype.searchProperty = function () {
  8797. return this.searchKeyframes();
  8798. };
  8799. TextProperty.prototype.searchKeyframes = function () {
  8800. this.kf = this.data.d.k.length > 1;
  8801. if (this.kf) {
  8802. this.addEffect(this.getKeyframeValue.bind(this));
  8803. }
  8804. return this.kf;
  8805. };
  8806. TextProperty.prototype.addEffect = function (effectFunction) {
  8807. this.effectsSequence.push(effectFunction);
  8808. this.elem.addDynamicProperty(this);
  8809. };
  8810. TextProperty.prototype.getValue = function (_finalValue) {
  8811. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  8812. return;
  8813. }
  8814. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  8815. var currentValue = this.currentData;
  8816. var currentIndex = this.keysIndex;
  8817. if (this.lock) {
  8818. this.setCurrentData(this.currentData);
  8819. return;
  8820. }
  8821. this.lock = true;
  8822. this._mdf = false;
  8823. var i; var
  8824. len = this.effectsSequence.length;
  8825. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  8826. for (i = 0; i < len; i += 1) {
  8827. // Checking if index changed to prevent creating a new object every time the expression updates.
  8828. if (currentIndex !== this.keysIndex) {
  8829. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  8830. } else {
  8831. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  8832. }
  8833. }
  8834. if (currentValue !== finalValue) {
  8835. this.setCurrentData(finalValue);
  8836. }
  8837. this.v = this.currentData;
  8838. this.pv = this.v;
  8839. this.lock = false;
  8840. this.frameId = this.elem.globalData.frameId;
  8841. };
  8842. TextProperty.prototype.getKeyframeValue = function () {
  8843. var textKeys = this.data.d.k;
  8844. var frameNum = this.elem.comp.renderedFrame;
  8845. var i = 0; var
  8846. len = textKeys.length;
  8847. while (i <= len - 1) {
  8848. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  8849. break;
  8850. }
  8851. i += 1;
  8852. }
  8853. if (this.keysIndex !== i) {
  8854. this.keysIndex = i;
  8855. }
  8856. return this.data.d.k[this.keysIndex].s;
  8857. };
  8858. TextProperty.prototype.buildFinalText = function (text) {
  8859. var charactersArray = [];
  8860. var i = 0;
  8861. var len = text.length;
  8862. var charCode;
  8863. var secondCharCode;
  8864. var shouldCombine = false;
  8865. var shouldCombineNext = false;
  8866. var currentChars = '';
  8867. while (i < len) {
  8868. shouldCombine = shouldCombineNext;
  8869. shouldCombineNext = false;
  8870. charCode = text.charCodeAt(i);
  8871. currentChars = text.charAt(i);
  8872. if (FontManager.isCombinedCharacter(charCode)) {
  8873. shouldCombine = true;
  8874. // It's a potential surrogate pair (this is the High surrogate)
  8875. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  8876. if (FontManager.isRegionalFlag(text, i)) {
  8877. currentChars = text.substr(i, 14);
  8878. } else {
  8879. secondCharCode = text.charCodeAt(i + 1);
  8880. // It's a surrogate pair (this is the Low surrogate)
  8881. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  8882. if (FontManager.isModifier(charCode, secondCharCode)) {
  8883. currentChars = text.substr(i, 2);
  8884. shouldCombine = true;
  8885. } else if (FontManager.isFlagEmoji(text.substr(i, 4))) {
  8886. currentChars = text.substr(i, 4);
  8887. } else {
  8888. currentChars = text.substr(i, 2);
  8889. }
  8890. }
  8891. }
  8892. } else if (charCode > 0xDBFF) {
  8893. secondCharCode = text.charCodeAt(i + 1);
  8894. if (FontManager.isVariationSelector(charCode)) {
  8895. shouldCombine = true;
  8896. }
  8897. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  8898. shouldCombine = true;
  8899. shouldCombineNext = true;
  8900. }
  8901. if (shouldCombine) {
  8902. charactersArray[charactersArray.length - 1] += currentChars;
  8903. shouldCombine = false;
  8904. } else {
  8905. charactersArray.push(currentChars);
  8906. }
  8907. i += currentChars.length;
  8908. }
  8909. return charactersArray;
  8910. };
  8911. TextProperty.prototype.completeTextData = function (documentData) {
  8912. documentData.__complete = true;
  8913. var fontManager = this.elem.globalData.fontManager;
  8914. var data = this.data;
  8915. var letters = [];
  8916. var i; var
  8917. len;
  8918. var newLineFlag; var index = 0; var
  8919. val;
  8920. var anchorGrouping = data.m.g;
  8921. var currentSize = 0; var currentPos = 0; var currentLine = 0; var
  8922. lineWidths = [];
  8923. var lineWidth = 0;
  8924. var maxLineWidth = 0;
  8925. var j; var
  8926. jLen;
  8927. var fontData = fontManager.getFontByName(documentData.f);
  8928. var charData; var
  8929. cLength = 0;
  8930. var fontProps = getFontProperties(fontData);
  8931. documentData.fWeight = fontProps.weight;
  8932. documentData.fStyle = fontProps.style;
  8933. documentData.finalSize = documentData.s;
  8934. documentData.finalText = this.buildFinalText(documentData.t);
  8935. len = documentData.finalText.length;
  8936. documentData.finalLineHeight = documentData.lh;
  8937. var trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8938. var charCode;
  8939. if (documentData.sz) {
  8940. var flag = true;
  8941. var boxWidth = documentData.sz[0];
  8942. var boxHeight = documentData.sz[1];
  8943. var currentHeight; var
  8944. finalText;
  8945. while (flag) {
  8946. finalText = this.buildFinalText(documentData.t);
  8947. currentHeight = 0;
  8948. lineWidth = 0;
  8949. len = finalText.length;
  8950. trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8951. var lastSpaceIndex = -1;
  8952. for (i = 0; i < len; i += 1) {
  8953. charCode = finalText[i].charCodeAt(0);
  8954. newLineFlag = false;
  8955. if (finalText[i] === ' ') {
  8956. lastSpaceIndex = i;
  8957. } else if (charCode === 13 || charCode === 3) {
  8958. lineWidth = 0;
  8959. newLineFlag = true;
  8960. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8961. }
  8962. if (fontManager.chars) {
  8963. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  8964. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  8965. } else {
  8966. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  8967. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  8968. }
  8969. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  8970. if (lastSpaceIndex === -1) {
  8971. len += 1;
  8972. } else {
  8973. i = lastSpaceIndex;
  8974. }
  8975. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8976. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r');
  8977. // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  8978. lastSpaceIndex = -1;
  8979. lineWidth = 0;
  8980. } else {
  8981. lineWidth += cLength;
  8982. lineWidth += trackingOffset;
  8983. }
  8984. }
  8985. currentHeight += (fontData.ascent * documentData.finalSize) / 100;
  8986. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  8987. documentData.finalSize -= 1;
  8988. documentData.finalLineHeight = (documentData.finalSize * documentData.lh) / documentData.s;
  8989. } else {
  8990. documentData.finalText = finalText;
  8991. len = documentData.finalText.length;
  8992. flag = false;
  8993. }
  8994. }
  8995. }
  8996. lineWidth = -trackingOffset;
  8997. cLength = 0;
  8998. var uncollapsedSpaces = 0;
  8999. var currentChar;
  9000. for (i = 0; i < len; i += 1) {
  9001. newLineFlag = false;
  9002. currentChar = documentData.finalText[i];
  9003. charCode = currentChar.charCodeAt(0);
  9004. if (charCode === 13 || charCode === 3) {
  9005. uncollapsedSpaces = 0;
  9006. lineWidths.push(lineWidth);
  9007. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9008. lineWidth = -2 * trackingOffset;
  9009. val = '';
  9010. newLineFlag = true;
  9011. currentLine += 1;
  9012. } else {
  9013. val = currentChar;
  9014. }
  9015. if (fontManager.chars) {
  9016. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  9017. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  9018. } else {
  9019. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9020. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  9021. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9022. }
  9023. //
  9024. if (currentChar === ' ') {
  9025. uncollapsedSpaces += cLength + trackingOffset;
  9026. } else {
  9027. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  9028. uncollapsedSpaces = 0;
  9029. }
  9030. letters.push({
  9031. l: cLength, an: cLength, add: currentSize, n: newLineFlag, anIndexes: [], val: val, line: currentLine, animatorJustifyOffset: 0,
  9032. });
  9033. if (anchorGrouping == 2) { // eslint-disable-line eqeqeq
  9034. currentSize += cLength;
  9035. if (val === '' || val === ' ' || i === len - 1) {
  9036. if (val === '' || val === ' ') {
  9037. currentSize -= cLength;
  9038. }
  9039. while (currentPos <= i) {
  9040. letters[currentPos].an = currentSize;
  9041. letters[currentPos].ind = index;
  9042. letters[currentPos].extra = cLength;
  9043. currentPos += 1;
  9044. }
  9045. index += 1;
  9046. currentSize = 0;
  9047. }
  9048. } else if (anchorGrouping == 3) { // eslint-disable-line eqeqeq
  9049. currentSize += cLength;
  9050. if (val === '' || i === len - 1) {
  9051. if (val === '') {
  9052. currentSize -= cLength;
  9053. }
  9054. while (currentPos <= i) {
  9055. letters[currentPos].an = currentSize;
  9056. letters[currentPos].ind = index;
  9057. letters[currentPos].extra = cLength;
  9058. currentPos += 1;
  9059. }
  9060. currentSize = 0;
  9061. index += 1;
  9062. }
  9063. } else {
  9064. letters[index].ind = index;
  9065. letters[index].extra = 0;
  9066. index += 1;
  9067. }
  9068. }
  9069. documentData.l = letters;
  9070. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9071. lineWidths.push(lineWidth);
  9072. if (documentData.sz) {
  9073. documentData.boxWidth = documentData.sz[0];
  9074. documentData.justifyOffset = 0;
  9075. } else {
  9076. documentData.boxWidth = maxLineWidth;
  9077. switch (documentData.j) {
  9078. case 1:
  9079. documentData.justifyOffset = -documentData.boxWidth;
  9080. break;
  9081. case 2:
  9082. documentData.justifyOffset = -documentData.boxWidth / 2;
  9083. break;
  9084. default:
  9085. documentData.justifyOffset = 0;
  9086. }
  9087. }
  9088. documentData.lineWidths = lineWidths;
  9089. var animators = data.a; var animatorData; var
  9090. letterData;
  9091. jLen = animators.length;
  9092. var based; var ind; var
  9093. indexes = [];
  9094. for (j = 0; j < jLen; j += 1) {
  9095. animatorData = animators[j];
  9096. if (animatorData.a.sc) {
  9097. documentData.strokeColorAnim = true;
  9098. }
  9099. if (animatorData.a.sw) {
  9100. documentData.strokeWidthAnim = true;
  9101. }
  9102. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9103. documentData.fillColorAnim = true;
  9104. }
  9105. ind = 0;
  9106. based = animatorData.s.b;
  9107. for (i = 0; i < len; i += 1) {
  9108. letterData = letters[i];
  9109. letterData.anIndexes[j] = ind;
  9110. 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
  9111. if (animatorData.s.rn === 1) {
  9112. indexes.push(ind);
  9113. }
  9114. ind += 1;
  9115. }
  9116. }
  9117. data.a[j].s.totalChars = ind;
  9118. var currentInd = -1; var
  9119. newInd;
  9120. if (animatorData.s.rn === 1) {
  9121. for (i = 0; i < len; i += 1) {
  9122. letterData = letters[i];
  9123. if (currentInd != letterData.anIndexes[j]) { // eslint-disable-line eqeqeq
  9124. currentInd = letterData.anIndexes[j];
  9125. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9126. }
  9127. letterData.anIndexes[j] = newInd;
  9128. }
  9129. }
  9130. }
  9131. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9132. documentData.ls = documentData.ls || 0;
  9133. documentData.ascent = (fontData.ascent * documentData.finalSize) / 100;
  9134. };
  9135. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9136. index = index === undefined ? this.keysIndex : index;
  9137. var dData = this.copyData({}, this.data.d.k[index].s);
  9138. dData = this.copyData(dData, newData);
  9139. this.data.d.k[index].s = dData;
  9140. this.recalculate(index);
  9141. this.setCurrentData(dData);
  9142. this.elem.addDynamicProperty(this);
  9143. };
  9144. TextProperty.prototype.recalculate = function (index) {
  9145. var dData = this.data.d.k[index].s;
  9146. dData.__complete = false;
  9147. this.keysIndex = 0;
  9148. this._isFirstFrame = true;
  9149. this.getValue(dData);
  9150. };
  9151. TextProperty.prototype.canResizeFont = function (_canResize) {
  9152. this.canResize = _canResize;
  9153. this.recalculate(this.keysIndex);
  9154. this.elem.addDynamicProperty(this);
  9155. };
  9156. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9157. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9158. this.recalculate(this.keysIndex);
  9159. this.elem.addDynamicProperty(this);
  9160. };
  9161. const TextSelectorProp = (function () {
  9162. var max = Math.max;
  9163. var min = Math.min;
  9164. var floor = Math.floor;
  9165. function TextSelectorPropFactory(elem, data) {
  9166. this._currentTextLength = -1;
  9167. this.k = false;
  9168. this.data = data;
  9169. this.elem = elem;
  9170. this.comp = elem.comp;
  9171. this.finalS = 0;
  9172. this.finalE = 0;
  9173. this.initDynamicPropertyContainer(elem);
  9174. this.s = PropertyFactory.getProp(elem, data.s || { k: 0 }, 0, 0, this);
  9175. if ('e' in data) {
  9176. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9177. } else {
  9178. this.e = { v: 100 };
  9179. }
  9180. this.o = PropertyFactory.getProp(elem, data.o || { k: 0 }, 0, 0, this);
  9181. this.xe = PropertyFactory.getProp(elem, data.xe || { k: 0 }, 0, 0, this);
  9182. this.ne = PropertyFactory.getProp(elem, data.ne || { k: 0 }, 0, 0, this);
  9183. this.sm = PropertyFactory.getProp(elem, data.sm || { k: 100 }, 0, 0, this);
  9184. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9185. if (!this.dynamicProperties.length) {
  9186. this.getValue();
  9187. }
  9188. }
  9189. TextSelectorPropFactory.prototype = {
  9190. getMult: function (ind) {
  9191. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9192. this.getValue();
  9193. }
  9194. var x1 = 0;
  9195. var y1 = 0;
  9196. var x2 = 1;
  9197. var y2 = 1;
  9198. if (this.ne.v > 0) {
  9199. x1 = this.ne.v / 100.0;
  9200. } else {
  9201. y1 = -this.ne.v / 100.0;
  9202. }
  9203. if (this.xe.v > 0) {
  9204. x2 = 1.0 - this.xe.v / 100.0;
  9205. } else {
  9206. y2 = 1.0 + this.xe.v / 100.0;
  9207. }
  9208. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9209. var mult = 0;
  9210. var s = this.finalS;
  9211. var e = this.finalE;
  9212. var type = this.data.sh;
  9213. if (type === 2) {
  9214. if (e === s) {
  9215. mult = ind >= e ? 1 : 0;
  9216. } else {
  9217. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9218. }
  9219. mult = easer(mult);
  9220. } else if (type === 3) {
  9221. if (e === s) {
  9222. mult = ind >= e ? 0 : 1;
  9223. } else {
  9224. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9225. }
  9226. mult = easer(mult);
  9227. } else if (type === 4) {
  9228. if (e === s) {
  9229. mult = 0;
  9230. } else {
  9231. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9232. if (mult < 0.5) {
  9233. mult *= 2;
  9234. } else {
  9235. mult = 1 - 2 * (mult - 0.5);
  9236. }
  9237. }
  9238. mult = easer(mult);
  9239. } else if (type === 5) {
  9240. if (e === s) {
  9241. mult = 0;
  9242. } else {
  9243. var tot = e - s;
  9244. /* ind += 0.5;
  9245. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9246. ind = min(max(0, ind + 0.5 - s), e - s);
  9247. var x = -tot / 2 + ind;
  9248. var a = tot / 2;
  9249. mult = Math.sqrt(1 - (x * x) / (a * a));
  9250. }
  9251. mult = easer(mult);
  9252. } else if (type === 6) {
  9253. if (e === s) {
  9254. mult = 0;
  9255. } else {
  9256. ind = min(max(0, ind + 0.5 - s), e - s);
  9257. mult = (1 + (Math.cos((Math.PI + Math.PI * 2 * (ind) / (e - s))))) / 2; // eslint-disable-line
  9258. }
  9259. mult = easer(mult);
  9260. } else {
  9261. if (ind >= floor(s)) {
  9262. if (ind - s < 0) {
  9263. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9264. } else {
  9265. mult = max(0, min(e - ind, 1));
  9266. }
  9267. }
  9268. mult = easer(mult);
  9269. }
  9270. // Smoothness implementation.
  9271. // The smoothness represents a reduced range of the original [0; 1] range.
  9272. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9273. // Steps are:
  9274. // - find the lower value of the new range (threshold)
  9275. // - if multiplier is smaller than that value, floor it to 0
  9276. // - if it is larger,
  9277. // - subtract the threshold
  9278. // - divide it by the smoothness (this will return the range to [0; 1])
  9279. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9280. if (this.sm.v !== 100) {
  9281. var smoothness = this.sm.v * 0.01;
  9282. if (smoothness === 0) {
  9283. smoothness = 0.00000001;
  9284. }
  9285. var threshold = 0.5 - smoothness * 0.5;
  9286. if (mult < threshold) {
  9287. mult = 0;
  9288. } else {
  9289. mult = (mult - threshold) / smoothness;
  9290. if (mult > 1) {
  9291. mult = 1;
  9292. }
  9293. }
  9294. }
  9295. return mult * this.a.v;
  9296. },
  9297. getValue: function (newCharsFlag) {
  9298. this.iterateDynamicProperties();
  9299. this._mdf = newCharsFlag || this._mdf;
  9300. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9301. if (newCharsFlag && this.data.r === 2) {
  9302. this.e.v = this._currentTextLength;
  9303. }
  9304. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9305. var o = this.o.v / divisor;
  9306. var s = this.s.v / divisor + o;
  9307. var e = (this.e.v / divisor) + o;
  9308. if (s > e) {
  9309. var _s = s;
  9310. s = e;
  9311. e = _s;
  9312. }
  9313. this.finalS = s;
  9314. this.finalE = e;
  9315. },
  9316. };
  9317. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9318. function getTextSelectorProp(elem, data, arr) {
  9319. return new TextSelectorPropFactory(elem, data, arr);
  9320. }
  9321. return {
  9322. getTextSelectorProp: getTextSelectorProp,
  9323. };
  9324. }());
  9325. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9326. var defaultData = { propType: false };
  9327. var getProp = PropertyFactory.getProp;
  9328. var textAnimatorAnimatables = animatorProps.a;
  9329. this.a = {
  9330. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9331. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9332. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9333. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9334. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9335. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9336. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9337. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9338. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9339. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9340. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9341. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9342. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9343. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9344. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9345. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData,
  9346. };
  9347. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9348. this.s.t = animatorProps.s.t;
  9349. }
  9350. function TextAnimatorProperty(textData, renderType, elem) {
  9351. this._isFirstFrame = true;
  9352. this._hasMaskedPath = false;
  9353. this._frameId = -1;
  9354. this._textData = textData;
  9355. this._renderType = renderType;
  9356. this._elem = elem;
  9357. this._animatorsData = createSizedArray(this._textData.a.length);
  9358. this._pathData = {};
  9359. this._moreOptions = {
  9360. alignment: {},
  9361. };
  9362. this.renderedLetters = [];
  9363. this.lettersChangedFlag = false;
  9364. this.initDynamicPropertyContainer(elem);
  9365. }
  9366. TextAnimatorProperty.prototype.searchProperties = function () {
  9367. var i;
  9368. var len = this._textData.a.length;
  9369. var animatorProps;
  9370. var getProp = PropertyFactory.getProp;
  9371. for (i = 0; i < len; i += 1) {
  9372. animatorProps = this._textData.a[i];
  9373. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9374. }
  9375. if (this._textData.p && 'm' in this._textData.p) {
  9376. this._pathData = {
  9377. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9378. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9379. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9380. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9381. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9382. m: this._elem.maskManager.getMaskProperty(this._textData.p.m),
  9383. };
  9384. this._hasMaskedPath = true;
  9385. } else {
  9386. this._hasMaskedPath = false;
  9387. }
  9388. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9389. };
  9390. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9391. this.lettersChangedFlag = lettersChangedFlag;
  9392. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9393. return;
  9394. }
  9395. this._isFirstFrame = false;
  9396. var alignment = this._moreOptions.alignment.v;
  9397. var animators = this._animatorsData;
  9398. var textData = this._textData;
  9399. var matrixHelper = this.mHelper;
  9400. var renderType = this._renderType;
  9401. var renderedLettersCount = this.renderedLetters.length;
  9402. var xPos;
  9403. var yPos;
  9404. var i;
  9405. var len;
  9406. var letters = documentData.l;
  9407. var pathInfo;
  9408. var currentLength;
  9409. var currentPoint;
  9410. var segmentLength;
  9411. var flag;
  9412. var pointInd;
  9413. var segmentInd;
  9414. var prevPoint;
  9415. var points;
  9416. var segments;
  9417. var partialLength;
  9418. var totalLength;
  9419. var perc;
  9420. var tanAngle;
  9421. var mask;
  9422. if (this._hasMaskedPath) {
  9423. mask = this._pathData.m;
  9424. if (!this._pathData.n || this._pathData._mdf) {
  9425. var paths = mask.v;
  9426. if (this._pathData.r.v) {
  9427. paths = paths.reverse();
  9428. }
  9429. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9430. pathInfo = {
  9431. tLength: 0,
  9432. segments: [],
  9433. };
  9434. len = paths._length - 1;
  9435. var bezierData;
  9436. totalLength = 0;
  9437. for (i = 0; i < len; i += 1) {
  9438. bezierData = bez.buildBezierData(paths.v[i],
  9439. paths.v[i + 1],
  9440. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9441. [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9442. pathInfo.tLength += bezierData.segmentLength;
  9443. pathInfo.segments.push(bezierData);
  9444. totalLength += bezierData.segmentLength;
  9445. }
  9446. i = len;
  9447. if (mask.v.c) {
  9448. bezierData = bez.buildBezierData(paths.v[i],
  9449. paths.v[0],
  9450. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9451. [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9452. pathInfo.tLength += bezierData.segmentLength;
  9453. pathInfo.segments.push(bezierData);
  9454. totalLength += bezierData.segmentLength;
  9455. }
  9456. this._pathData.pi = pathInfo;
  9457. }
  9458. pathInfo = this._pathData.pi;
  9459. currentLength = this._pathData.f.v;
  9460. segmentInd = 0;
  9461. pointInd = 1;
  9462. segmentLength = 0;
  9463. flag = true;
  9464. segments = pathInfo.segments;
  9465. if (currentLength < 0 && mask.v.c) {
  9466. if (pathInfo.tLength < Math.abs(currentLength)) {
  9467. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9468. }
  9469. segmentInd = segments.length - 1;
  9470. points = segments[segmentInd].points;
  9471. pointInd = points.length - 1;
  9472. while (currentLength < 0) {
  9473. currentLength += points[pointInd].partialLength;
  9474. pointInd -= 1;
  9475. if (pointInd < 0) {
  9476. segmentInd -= 1;
  9477. points = segments[segmentInd].points;
  9478. pointInd = points.length - 1;
  9479. }
  9480. }
  9481. }
  9482. points = segments[segmentInd].points;
  9483. prevPoint = points[pointInd - 1];
  9484. currentPoint = points[pointInd];
  9485. partialLength = currentPoint.partialLength;
  9486. }
  9487. len = letters.length;
  9488. xPos = 0;
  9489. yPos = 0;
  9490. var yOff = documentData.finalSize * 1.2 * 0.714;
  9491. var firstLine = true;
  9492. var animatorProps;
  9493. var animatorSelector;
  9494. var j;
  9495. var jLen;
  9496. var letterValue;
  9497. jLen = animators.length;
  9498. var mult;
  9499. var ind = -1;
  9500. var offf;
  9501. var xPathPos;
  9502. var yPathPos;
  9503. var initPathPos = currentLength;
  9504. var initSegmentInd = segmentInd;
  9505. var initPointInd = pointInd;
  9506. var currentLine = -1;
  9507. var elemOpacity;
  9508. var sc;
  9509. var sw;
  9510. var fc;
  9511. var k;
  9512. var letterSw;
  9513. var letterSc;
  9514. var letterFc;
  9515. var letterM = '';
  9516. var letterP = this.defaultPropsArray;
  9517. var letterO;
  9518. //
  9519. if (documentData.j === 2 || documentData.j === 1) {
  9520. var animatorJustifyOffset = 0;
  9521. var animatorFirstCharOffset = 0;
  9522. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9523. var lastIndex = 0;
  9524. var isNewLine = true;
  9525. for (i = 0; i < len; i += 1) {
  9526. if (letters[i].n) {
  9527. if (animatorJustifyOffset) {
  9528. animatorJustifyOffset += animatorFirstCharOffset;
  9529. }
  9530. while (lastIndex < i) {
  9531. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9532. lastIndex += 1;
  9533. }
  9534. animatorJustifyOffset = 0;
  9535. isNewLine = true;
  9536. } else {
  9537. for (j = 0; j < jLen; j += 1) {
  9538. animatorProps = animators[j].a;
  9539. if (animatorProps.t.propType) {
  9540. if (isNewLine && documentData.j === 2) {
  9541. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9542. }
  9543. animatorSelector = animators[j].s;
  9544. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9545. if (mult.length) {
  9546. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9547. } else {
  9548. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9549. }
  9550. }
  9551. }
  9552. isNewLine = false;
  9553. }
  9554. }
  9555. if (animatorJustifyOffset) {
  9556. animatorJustifyOffset += animatorFirstCharOffset;
  9557. }
  9558. while (lastIndex < i) {
  9559. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9560. lastIndex += 1;
  9561. }
  9562. }
  9563. //
  9564. for (i = 0; i < len; i += 1) {
  9565. matrixHelper.reset();
  9566. elemOpacity = 1;
  9567. if (letters[i].n) {
  9568. xPos = 0;
  9569. yPos += documentData.yOffset;
  9570. yPos += firstLine ? 1 : 0;
  9571. currentLength = initPathPos;
  9572. firstLine = false;
  9573. if (this._hasMaskedPath) {
  9574. segmentInd = initSegmentInd;
  9575. pointInd = initPointInd;
  9576. points = segments[segmentInd].points;
  9577. prevPoint = points[pointInd - 1];
  9578. currentPoint = points[pointInd];
  9579. partialLength = currentPoint.partialLength;
  9580. segmentLength = 0;
  9581. }
  9582. letterM = '';
  9583. letterFc = '';
  9584. letterSw = '';
  9585. letterO = '';
  9586. letterP = this.defaultPropsArray;
  9587. } else {
  9588. if (this._hasMaskedPath) {
  9589. if (currentLine !== letters[i].line) {
  9590. switch (documentData.j) {
  9591. case 1:
  9592. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9593. break;
  9594. case 2:
  9595. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9596. break;
  9597. default:
  9598. break;
  9599. }
  9600. currentLine = letters[i].line;
  9601. }
  9602. if (ind !== letters[i].ind) {
  9603. if (letters[ind]) {
  9604. currentLength += letters[ind].extra;
  9605. }
  9606. currentLength += letters[i].an / 2;
  9607. ind = letters[i].ind;
  9608. }
  9609. currentLength += (alignment[0] * letters[i].an) * 0.005;
  9610. var animatorOffset = 0;
  9611. for (j = 0; j < jLen; j += 1) {
  9612. animatorProps = animators[j].a;
  9613. if (animatorProps.p.propType) {
  9614. animatorSelector = animators[j].s;
  9615. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9616. if (mult.length) {
  9617. animatorOffset += animatorProps.p.v[0] * mult[0];
  9618. } else {
  9619. animatorOffset += animatorProps.p.v[0] * mult;
  9620. }
  9621. }
  9622. if (animatorProps.a.propType) {
  9623. animatorSelector = animators[j].s;
  9624. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9625. if (mult.length) {
  9626. animatorOffset += animatorProps.a.v[0] * mult[0];
  9627. } else {
  9628. animatorOffset += animatorProps.a.v[0] * mult;
  9629. }
  9630. }
  9631. }
  9632. flag = true;
  9633. // Force alignment only works with a single line for now
  9634. if (this._pathData.a.v) {
  9635. 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);
  9636. currentLength += this._pathData.f.v;
  9637. }
  9638. while (flag) {
  9639. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9640. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9641. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9642. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9643. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, -(alignment[1] * yOff) * 0.01);
  9644. flag = false;
  9645. } else if (points) {
  9646. segmentLength += currentPoint.partialLength;
  9647. pointInd += 1;
  9648. if (pointInd >= points.length) {
  9649. pointInd = 0;
  9650. segmentInd += 1;
  9651. if (!segments[segmentInd]) {
  9652. if (mask.v.c) {
  9653. pointInd = 0;
  9654. segmentInd = 0;
  9655. points = segments[segmentInd].points;
  9656. } else {
  9657. segmentLength -= currentPoint.partialLength;
  9658. points = null;
  9659. }
  9660. } else {
  9661. points = segments[segmentInd].points;
  9662. }
  9663. }
  9664. if (points) {
  9665. prevPoint = currentPoint;
  9666. currentPoint = points[pointInd];
  9667. partialLength = currentPoint.partialLength;
  9668. }
  9669. }
  9670. }
  9671. offf = letters[i].an / 2 - letters[i].add;
  9672. matrixHelper.translate(-offf, 0, 0);
  9673. } else {
  9674. offf = letters[i].an / 2 - letters[i].add;
  9675. matrixHelper.translate(-offf, 0, 0);
  9676. // Grouping alignment
  9677. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, (-alignment[1] * yOff) * 0.01, 0);
  9678. }
  9679. for (j = 0; j < jLen; j += 1) {
  9680. animatorProps = animators[j].a;
  9681. if (animatorProps.t.propType) {
  9682. animatorSelector = animators[j].s;
  9683. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9684. // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9685. if (xPos !== 0 || documentData.j !== 0) {
  9686. if (this._hasMaskedPath) {
  9687. if (mult.length) {
  9688. currentLength += animatorProps.t.v * mult[0];
  9689. } else {
  9690. currentLength += animatorProps.t.v * mult;
  9691. }
  9692. } else if (mult.length) {
  9693. xPos += animatorProps.t.v * mult[0];
  9694. } else {
  9695. xPos += animatorProps.t.v * mult;
  9696. }
  9697. }
  9698. }
  9699. }
  9700. if (documentData.strokeWidthAnim) {
  9701. sw = documentData.sw || 0;
  9702. }
  9703. if (documentData.strokeColorAnim) {
  9704. if (documentData.sc) {
  9705. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  9706. } else {
  9707. sc = [0, 0, 0];
  9708. }
  9709. }
  9710. if (documentData.fillColorAnim && documentData.fc) {
  9711. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  9712. }
  9713. for (j = 0; j < jLen; j += 1) {
  9714. animatorProps = animators[j].a;
  9715. if (animatorProps.a.propType) {
  9716. animatorSelector = animators[j].s;
  9717. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9718. if (mult.length) {
  9719. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  9720. } else {
  9721. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  9722. }
  9723. }
  9724. }
  9725. for (j = 0; j < jLen; j += 1) {
  9726. animatorProps = animators[j].a;
  9727. if (animatorProps.s.propType) {
  9728. animatorSelector = animators[j].s;
  9729. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9730. if (mult.length) {
  9731. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult[0]), 1 + ((animatorProps.s.v[1] - 1) * mult[1]), 1);
  9732. } else {
  9733. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult), 1 + ((animatorProps.s.v[1] - 1) * mult), 1);
  9734. }
  9735. }
  9736. }
  9737. for (j = 0; j < jLen; j += 1) {
  9738. animatorProps = animators[j].a;
  9739. animatorSelector = animators[j].s;
  9740. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9741. if (animatorProps.sk.propType) {
  9742. if (mult.length) {
  9743. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  9744. } else {
  9745. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  9746. }
  9747. }
  9748. if (animatorProps.r.propType) {
  9749. if (mult.length) {
  9750. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  9751. } else {
  9752. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  9753. }
  9754. }
  9755. if (animatorProps.ry.propType) {
  9756. if (mult.length) {
  9757. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  9758. } else {
  9759. matrixHelper.rotateY(animatorProps.ry.v * mult);
  9760. }
  9761. }
  9762. if (animatorProps.rx.propType) {
  9763. if (mult.length) {
  9764. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  9765. } else {
  9766. matrixHelper.rotateX(animatorProps.rx.v * mult);
  9767. }
  9768. }
  9769. if (animatorProps.o.propType) {
  9770. if (mult.length) {
  9771. elemOpacity += ((animatorProps.o.v) * mult[0] - elemOpacity) * mult[0];
  9772. } else {
  9773. elemOpacity += ((animatorProps.o.v) * mult - elemOpacity) * mult;
  9774. }
  9775. }
  9776. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  9777. if (mult.length) {
  9778. sw += animatorProps.sw.v * mult[0];
  9779. } else {
  9780. sw += animatorProps.sw.v * mult;
  9781. }
  9782. }
  9783. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  9784. for (k = 0; k < 3; k += 1) {
  9785. if (mult.length) {
  9786. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  9787. } else {
  9788. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  9789. }
  9790. }
  9791. }
  9792. if (documentData.fillColorAnim && documentData.fc) {
  9793. if (animatorProps.fc.propType) {
  9794. for (k = 0; k < 3; k += 1) {
  9795. if (mult.length) {
  9796. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  9797. } else {
  9798. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  9799. }
  9800. }
  9801. }
  9802. if (animatorProps.fh.propType) {
  9803. if (mult.length) {
  9804. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  9805. } else {
  9806. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  9807. }
  9808. }
  9809. if (animatorProps.fs.propType) {
  9810. if (mult.length) {
  9811. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  9812. } else {
  9813. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  9814. }
  9815. }
  9816. if (animatorProps.fb.propType) {
  9817. if (mult.length) {
  9818. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  9819. } else {
  9820. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  9821. }
  9822. }
  9823. }
  9824. }
  9825. for (j = 0; j < jLen; j += 1) {
  9826. animatorProps = animators[j].a;
  9827. if (animatorProps.p.propType) {
  9828. animatorSelector = animators[j].s;
  9829. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9830. if (this._hasMaskedPath) {
  9831. if (mult.length) {
  9832. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  9833. } else {
  9834. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9835. }
  9836. } else if (mult.length) {
  9837. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  9838. } else {
  9839. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9840. }
  9841. }
  9842. }
  9843. if (documentData.strokeWidthAnim) {
  9844. letterSw = sw < 0 ? 0 : sw;
  9845. }
  9846. if (documentData.strokeColorAnim) {
  9847. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  9848. }
  9849. if (documentData.fillColorAnim && documentData.fc) {
  9850. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  9851. }
  9852. if (this._hasMaskedPath) {
  9853. matrixHelper.translate(0, -documentData.ls);
  9854. matrixHelper.translate(0, (alignment[1] * yOff) * 0.01 + yPos, 0);
  9855. if (this._pathData.p.v) {
  9856. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  9857. var rot = (Math.atan(tanAngle) * 180) / Math.PI;
  9858. if (currentPoint.point[0] < prevPoint.point[0]) {
  9859. rot += 180;
  9860. }
  9861. matrixHelper.rotate((-rot * Math.PI) / 180);
  9862. }
  9863. matrixHelper.translate(xPathPos, yPathPos, 0);
  9864. currentLength -= (alignment[0] * letters[i].an) * 0.005;
  9865. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  9866. currentLength += letters[i].an / 2;
  9867. currentLength += (documentData.tr * 0.001) * documentData.finalSize;
  9868. }
  9869. } else {
  9870. matrixHelper.translate(xPos, yPos, 0);
  9871. if (documentData.ps) {
  9872. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  9873. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9874. }
  9875. switch (documentData.j) {
  9876. case 1:
  9877. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  9878. break;
  9879. case 2:
  9880. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  9881. break;
  9882. default:
  9883. break;
  9884. }
  9885. matrixHelper.translate(0, -documentData.ls);
  9886. matrixHelper.translate(offf, 0, 0);
  9887. matrixHelper.translate((alignment[0] * letters[i].an) * 0.005, (alignment[1] * yOff) * 0.01, 0);
  9888. xPos += letters[i].l + (documentData.tr * 0.001) * documentData.finalSize;
  9889. }
  9890. if (renderType === 'html') {
  9891. letterM = matrixHelper.toCSS();
  9892. } else if (renderType === 'svg') {
  9893. letterM = matrixHelper.to2dCSS();
  9894. } else {
  9895. 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]];
  9896. }
  9897. letterO = elemOpacity;
  9898. }
  9899. if (renderedLettersCount <= i) {
  9900. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  9901. this.renderedLetters.push(letterValue);
  9902. renderedLettersCount += 1;
  9903. this.lettersChangedFlag = true;
  9904. } else {
  9905. letterValue = this.renderedLetters[i];
  9906. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  9907. }
  9908. }
  9909. };
  9910. TextAnimatorProperty.prototype.getValue = function () {
  9911. if (this._elem.globalData.frameId === this._frameId) {
  9912. return;
  9913. }
  9914. this._frameId = this._elem.globalData.frameId;
  9915. this.iterateDynamicProperties();
  9916. };
  9917. TextAnimatorProperty.prototype.mHelper = new Matrix();
  9918. TextAnimatorProperty.prototype.defaultPropsArray = [];
  9919. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  9920. function ITextElement() {
  9921. }
  9922. ITextElement.prototype.initElement = function (data, globalData, comp) {
  9923. this.lettersChangedFlag = true;
  9924. this.initFrame();
  9925. this.initBaseData(data, globalData, comp);
  9926. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  9927. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  9928. this.initTransform(data, globalData, comp);
  9929. this.initHierarchy();
  9930. this.initRenderable();
  9931. this.initRendererElement();
  9932. this.createContainerElements();
  9933. this.createRenderableComponents();
  9934. this.createContent();
  9935. this.hide();
  9936. this.textAnimator.searchProperties(this.dynamicProperties);
  9937. };
  9938. ITextElement.prototype.prepareFrame = function (num) {
  9939. this._mdf = false;
  9940. this.prepareRenderableFrame(num);
  9941. this.prepareProperties(num, this.isInRange);
  9942. };
  9943. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  9944. var j;
  9945. var jLen = shapes.length;
  9946. var pathNodes;
  9947. var shapeStr = '';
  9948. for (j = 0; j < jLen; j += 1) {
  9949. if (shapes[j].ty === 'sh') {
  9950. pathNodes = shapes[j].ks.k;
  9951. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  9952. }
  9953. }
  9954. return shapeStr;
  9955. };
  9956. ITextElement.prototype.updateDocumentData = function (newData, index) {
  9957. this.textProperty.updateDocumentData(newData, index);
  9958. };
  9959. ITextElement.prototype.canResizeFont = function (_canResize) {
  9960. this.textProperty.canResizeFont(_canResize);
  9961. };
  9962. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  9963. this.textProperty.setMinimumFontSize(_fontSize);
  9964. };
  9965. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  9966. if (documentData.ps) {
  9967. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9968. }
  9969. matrixHelper.translate(0, -documentData.ls, 0);
  9970. switch (documentData.j) {
  9971. case 1:
  9972. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  9973. break;
  9974. case 2:
  9975. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  9976. break;
  9977. default:
  9978. break;
  9979. }
  9980. matrixHelper.translate(xPos, yPos, 0);
  9981. };
  9982. ITextElement.prototype.buildColor = function (colorData) {
  9983. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  9984. };
  9985. ITextElement.prototype.emptyProp = new LetterProps();
  9986. ITextElement.prototype.destroy = function () {
  9987. };
  9988. ITextElement.prototype.validateText = function () {
  9989. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  9990. this.buildNewText();
  9991. this.textProperty._isFirstFrame = false;
  9992. this.textProperty._mdf = false;
  9993. }
  9994. };
  9995. var emptyShapeData = {
  9996. shapes: [],
  9997. };
  9998. function SVGTextLottieElement(data, globalData, comp) {
  9999. this.textSpans = [];
  10000. this.renderType = 'svg';
  10001. this.initElement(data, globalData, comp);
  10002. }
  10003. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  10004. SVGTextLottieElement.prototype.createContent = function () {
  10005. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  10006. this.textContainer = createNS('text');
  10007. }
  10008. };
  10009. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  10010. var i = 0;
  10011. var len = textArray.length;
  10012. var textContents = [];
  10013. var currentTextContent = '';
  10014. while (i < len) {
  10015. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  10016. textContents.push(currentTextContent);
  10017. currentTextContent = '';
  10018. } else {
  10019. currentTextContent += textArray[i];
  10020. }
  10021. i += 1;
  10022. }
  10023. textContents.push(currentTextContent);
  10024. return textContents;
  10025. };
  10026. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  10027. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  10028. // but since text internal content gets only rendered once and then it's never rerendered,
  10029. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  10030. // Avoiding cloning is preferred since cloning each character shape data is expensive
  10031. if (data.shapes && data.shapes.length) {
  10032. var shape = data.shapes[0];
  10033. if (shape.it) {
  10034. var shapeItem = shape.it[shape.it.length - 1];
  10035. if (shapeItem.s) {
  10036. shapeItem.s.k[0] = scale;
  10037. shapeItem.s.k[1] = scale;
  10038. }
  10039. }
  10040. }
  10041. return data;
  10042. };
  10043. SVGTextLottieElement.prototype.buildNewText = function () {
  10044. this.addDynamicProperty(this);
  10045. var i;
  10046. var len;
  10047. var documentData = this.textProperty.currentData;
  10048. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  10049. if (documentData.fc) {
  10050. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  10051. } else {
  10052. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  10053. }
  10054. if (documentData.sc) {
  10055. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  10056. this.layerElement.setAttribute('stroke-width', documentData.sw);
  10057. }
  10058. this.layerElement.setAttribute('font-size', documentData.finalSize);
  10059. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10060. if (fontData.fClass) {
  10061. this.layerElement.setAttribute('class', fontData.fClass);
  10062. } else {
  10063. this.layerElement.setAttribute('font-family', fontData.fFamily);
  10064. var fWeight = documentData.fWeight;
  10065. var fStyle = documentData.fStyle;
  10066. this.layerElement.setAttribute('font-style', fStyle);
  10067. this.layerElement.setAttribute('font-weight', fWeight);
  10068. }
  10069. this.layerElement.setAttribute('aria-label', documentData.t);
  10070. var letters = documentData.l || [];
  10071. var usesGlyphs = !!this.globalData.fontManager.chars;
  10072. len = letters.length;
  10073. var tSpan;
  10074. var matrixHelper = this.mHelper;
  10075. var shapeStr = '';
  10076. var singleShape = this.data.singleShape;
  10077. var xPos = 0;
  10078. var yPos = 0;
  10079. var firstLine = true;
  10080. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10081. if (singleShape && !usesGlyphs && !documentData.sz) {
  10082. var tElement = this.textContainer;
  10083. var justify = 'start';
  10084. switch (documentData.j) {
  10085. case 1:
  10086. justify = 'end';
  10087. break;
  10088. case 2:
  10089. justify = 'middle';
  10090. break;
  10091. default:
  10092. justify = 'start';
  10093. break;
  10094. }
  10095. tElement.setAttribute('text-anchor', justify);
  10096. tElement.setAttribute('letter-spacing', trackingOffset);
  10097. var textContent = this.buildTextContents(documentData.finalText);
  10098. len = textContent.length;
  10099. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10100. for (i = 0; i < len; i += 1) {
  10101. tSpan = this.textSpans[i].span || createNS('tspan');
  10102. tSpan.textContent = textContent[i];
  10103. tSpan.setAttribute('x', 0);
  10104. tSpan.setAttribute('y', yPos);
  10105. tSpan.style.display = 'inherit';
  10106. tElement.appendChild(tSpan);
  10107. if (!this.textSpans[i]) {
  10108. this.textSpans[i] = {
  10109. span: null,
  10110. glyph: null,
  10111. };
  10112. }
  10113. this.textSpans[i].span = tSpan;
  10114. yPos += documentData.finalLineHeight;
  10115. }
  10116. this.layerElement.appendChild(tElement);
  10117. } else {
  10118. var cachedSpansLength = this.textSpans.length;
  10119. var charData;
  10120. for (i = 0; i < len; i += 1) {
  10121. if (!this.textSpans[i]) {
  10122. this.textSpans[i] = {
  10123. span: null,
  10124. childSpan: null,
  10125. glyph: null,
  10126. };
  10127. }
  10128. if (!usesGlyphs || !singleShape || i === 0) {
  10129. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10130. if (cachedSpansLength <= i) {
  10131. tSpan.setAttribute('stroke-linecap', 'butt');
  10132. tSpan.setAttribute('stroke-linejoin', 'round');
  10133. tSpan.setAttribute('stroke-miterlimit', '4');
  10134. this.textSpans[i].span = tSpan;
  10135. if (usesGlyphs) {
  10136. var childSpan = createNS('g');
  10137. tSpan.appendChild(childSpan);
  10138. this.textSpans[i].childSpan = childSpan;
  10139. }
  10140. this.textSpans[i].span = tSpan;
  10141. this.layerElement.appendChild(tSpan);
  10142. }
  10143. tSpan.style.display = 'inherit';
  10144. }
  10145. matrixHelper.reset();
  10146. if (singleShape) {
  10147. if (letters[i].n) {
  10148. xPos = -trackingOffset;
  10149. yPos += documentData.yOffset;
  10150. yPos += firstLine ? 1 : 0;
  10151. firstLine = false;
  10152. }
  10153. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10154. xPos += letters[i].l || 0;
  10155. // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10156. xPos += trackingOffset;
  10157. }
  10158. if (usesGlyphs) {
  10159. charData = this.globalData.fontManager.getCharData(
  10160. documentData.finalText[i],
  10161. fontData.fStyle,
  10162. this.globalData.fontManager.getFontByName(documentData.f).fFamily
  10163. );
  10164. var glyphElement;
  10165. // t === 1 means the character has been replaced with an animated shaped
  10166. if (charData.t === 1) {
  10167. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10168. } else {
  10169. var data = emptyShapeData;
  10170. if (charData.data && charData.data.shapes) {
  10171. data = this.buildShapeData(charData.data, documentData.finalSize);
  10172. }
  10173. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10174. }
  10175. if (this.textSpans[i].glyph) {
  10176. var glyph = this.textSpans[i].glyph;
  10177. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10178. glyph.destroy();
  10179. }
  10180. this.textSpans[i].glyph = glyphElement;
  10181. glyphElement._debug = true;
  10182. glyphElement.prepareFrame(0);
  10183. glyphElement.renderFrame();
  10184. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
  10185. // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10186. // this might have issues with strokes and might need a different solution
  10187. if (charData.t === 1) {
  10188. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10189. }
  10190. } else {
  10191. if (singleShape) {
  10192. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10193. }
  10194. tSpan.textContent = letters[i].val;
  10195. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10196. }
  10197. //
  10198. }
  10199. if (singleShape && tSpan) {
  10200. tSpan.setAttribute('d', shapeStr);
  10201. }
  10202. }
  10203. while (i < this.textSpans.length) {
  10204. this.textSpans[i].span.style.display = 'none';
  10205. i += 1;
  10206. }
  10207. this._sizeChanged = true;
  10208. };
  10209. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10210. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10211. this.renderInnerContent();
  10212. if (this._sizeChanged) {
  10213. this._sizeChanged = false;
  10214. var textBox = this.layerElement.getBBox();
  10215. this.bbox = {
  10216. top: textBox.y,
  10217. left: textBox.x,
  10218. width: textBox.width,
  10219. height: textBox.height,
  10220. };
  10221. }
  10222. return this.bbox;
  10223. };
  10224. SVGTextLottieElement.prototype.getValue = function () {
  10225. var i;
  10226. var len = this.textSpans.length;
  10227. var glyphElement;
  10228. this.renderedFrame = this.comp.renderedFrame;
  10229. for (i = 0; i < len; i += 1) {
  10230. glyphElement = this.textSpans[i].glyph;
  10231. if (glyphElement) {
  10232. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10233. if (glyphElement._mdf) {
  10234. this._mdf = true;
  10235. }
  10236. }
  10237. }
  10238. };
  10239. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10240. this.validateText();
  10241. if (!this.data.singleShape || this._mdf) {
  10242. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10243. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10244. this._sizeChanged = true;
  10245. var i;
  10246. var len;
  10247. var renderedLetters = this.textAnimator.renderedLetters;
  10248. var letters = this.textProperty.currentData.l;
  10249. len = letters.length;
  10250. var renderedLetter;
  10251. var textSpan;
  10252. var glyphElement;
  10253. for (i = 0; i < len; i += 1) {
  10254. if (!letters[i].n) {
  10255. renderedLetter = renderedLetters[i];
  10256. textSpan = this.textSpans[i].span;
  10257. glyphElement = this.textSpans[i].glyph;
  10258. if (glyphElement) {
  10259. glyphElement.renderFrame();
  10260. }
  10261. if (renderedLetter._mdf.m) {
  10262. textSpan.setAttribute('transform', renderedLetter.m);
  10263. }
  10264. if (renderedLetter._mdf.o) {
  10265. textSpan.setAttribute('opacity', renderedLetter.o);
  10266. }
  10267. if (renderedLetter._mdf.sw) {
  10268. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10269. }
  10270. if (renderedLetter._mdf.sc) {
  10271. textSpan.setAttribute('stroke', renderedLetter.sc);
  10272. }
  10273. if (renderedLetter._mdf.fc) {
  10274. textSpan.setAttribute('fill', renderedLetter.fc);
  10275. }
  10276. }
  10277. }
  10278. }
  10279. }
  10280. };
  10281. function ISolidElement(data, globalData, comp) {
  10282. this.initElement(data, globalData, comp);
  10283. }
  10284. extendPrototype([IImageElement], ISolidElement);
  10285. ISolidElement.prototype.createContent = function () {
  10286. var rect = createNS('rect');
  10287. /// /rect.style.width = this.data.sw;
  10288. /// /rect.style.height = this.data.sh;
  10289. /// /rect.style.fill = this.data.sc;
  10290. rect.setAttribute('width', this.data.sw);
  10291. rect.setAttribute('height', this.data.sh);
  10292. rect.setAttribute('fill', this.data.sc);
  10293. this.layerElement.appendChild(rect);
  10294. };
  10295. function NullElement(data, globalData, comp) {
  10296. this.initFrame();
  10297. this.initBaseData(data, globalData, comp);
  10298. this.initFrame();
  10299. this.initTransform(data, globalData, comp);
  10300. this.initHierarchy();
  10301. }
  10302. NullElement.prototype.prepareFrame = function (num) {
  10303. this.prepareProperties(num, true);
  10304. };
  10305. NullElement.prototype.renderFrame = function () {
  10306. };
  10307. NullElement.prototype.getBaseElement = function () {
  10308. return null;
  10309. };
  10310. NullElement.prototype.destroy = function () {
  10311. };
  10312. NullElement.prototype.sourceRectAtTime = function () {
  10313. };
  10314. NullElement.prototype.hide = function () {
  10315. };
  10316. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10317. function SVGRendererBase() {
  10318. }
  10319. extendPrototype([BaseRenderer], SVGRendererBase);
  10320. SVGRendererBase.prototype.createNull = function (data) {
  10321. return new NullElement(data, this.globalData, this);
  10322. };
  10323. SVGRendererBase.prototype.createShape = function (data) {
  10324. return new SVGShapeElement(data, this.globalData, this);
  10325. };
  10326. SVGRendererBase.prototype.createText = function (data) {
  10327. return new SVGTextLottieElement(data, this.globalData, this);
  10328. };
  10329. SVGRendererBase.prototype.createImage = function (data) {
  10330. return new IImageElement(data, this.globalData, this);
  10331. };
  10332. SVGRendererBase.prototype.createSolid = function (data) {
  10333. return new ISolidElement(data, this.globalData, this);
  10334. };
  10335. SVGRendererBase.prototype.configAnimation = function (animData) {
  10336. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10337. this.svgElement.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  10338. if (this.renderConfig.viewBoxSize) {
  10339. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10340. } else {
  10341. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10342. }
  10343. if (!this.renderConfig.viewBoxOnly) {
  10344. this.svgElement.setAttribute('width', animData.w);
  10345. this.svgElement.setAttribute('height', animData.h);
  10346. this.svgElement.style.width = '100%';
  10347. this.svgElement.style.height = '100%';
  10348. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10349. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10350. }
  10351. if (this.renderConfig.width) {
  10352. this.svgElement.setAttribute('width', this.renderConfig.width);
  10353. }
  10354. if (this.renderConfig.height) {
  10355. this.svgElement.setAttribute('height', this.renderConfig.height);
  10356. }
  10357. if (this.renderConfig.className) {
  10358. this.svgElement.setAttribute('class', this.renderConfig.className);
  10359. }
  10360. if (this.renderConfig.id) {
  10361. this.svgElement.setAttribute('id', this.renderConfig.id);
  10362. }
  10363. if (this.renderConfig.focusable !== undefined) {
  10364. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10365. }
  10366. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio);
  10367. // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10368. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10369. this.animationItem.wrapper.appendChild(this.svgElement);
  10370. // Mask animation
  10371. var defs = this.globalData.defs;
  10372. this.setupGlobalData(animData, defs);
  10373. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10374. this.data = animData;
  10375. var maskElement = createNS('clipPath');
  10376. var rect = createNS('rect');
  10377. rect.setAttribute('width', animData.w);
  10378. rect.setAttribute('height', animData.h);
  10379. rect.setAttribute('x', 0);
  10380. rect.setAttribute('y', 0);
  10381. var maskId = createElementID();
  10382. maskElement.setAttribute('id', maskId);
  10383. maskElement.appendChild(rect);
  10384. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10385. defs.appendChild(maskElement);
  10386. this.layers = animData.layers;
  10387. this.elements = createSizedArray(animData.layers.length);
  10388. };
  10389. SVGRendererBase.prototype.destroy = function () {
  10390. if (this.animationItem.wrapper) {
  10391. this.animationItem.wrapper.innerText = '';
  10392. }
  10393. this.layerElement = null;
  10394. this.globalData.defs = null;
  10395. var i;
  10396. var len = this.layers ? this.layers.length : 0;
  10397. for (i = 0; i < len; i += 1) {
  10398. if (this.elements[i] && this.elements[i].destroy) {
  10399. this.elements[i].destroy();
  10400. }
  10401. }
  10402. this.elements.length = 0;
  10403. this.destroyed = true;
  10404. this.animationItem = null;
  10405. };
  10406. SVGRendererBase.prototype.updateContainerSize = function () {
  10407. };
  10408. SVGRendererBase.prototype.findIndexByInd = function (ind) {
  10409. var i = 0;
  10410. var len = this.layers.length;
  10411. for (i = 0; i < len; i += 1) {
  10412. if (this.layers[i].ind === ind) {
  10413. return i;
  10414. }
  10415. }
  10416. return -1;
  10417. };
  10418. SVGRendererBase.prototype.buildItem = function (pos) {
  10419. var elements = this.elements;
  10420. if (elements[pos] || this.layers[pos].ty === 99) {
  10421. return;
  10422. }
  10423. elements[pos] = true;
  10424. var element = this.createItem(this.layers[pos]);
  10425. elements[pos] = element;
  10426. if (getExpressionsPlugin()) {
  10427. if (this.layers[pos].ty === 0) {
  10428. this.globalData.projectInterface.registerComposition(element);
  10429. }
  10430. element.initExpressions();
  10431. }
  10432. this.appendElementInPos(element, pos);
  10433. if (this.layers[pos].tt) {
  10434. var elementIndex = ('tp' in this.layers[pos])
  10435. ? this.findIndexByInd(this.layers[pos].tp)
  10436. : pos - 1;
  10437. if (elementIndex === -1) {
  10438. return;
  10439. }
  10440. if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
  10441. this.buildItem(elementIndex);
  10442. this.addPendingElement(element);
  10443. } else {
  10444. var matteElement = elements[elementIndex];
  10445. var matteMask = matteElement.getMatte(this.layers[pos].tt);
  10446. element.setMatte(matteMask);
  10447. }
  10448. }
  10449. };
  10450. SVGRendererBase.prototype.checkPendingElements = function () {
  10451. while (this.pendingElements.length) {
  10452. var element = this.pendingElements.pop();
  10453. element.checkParenting();
  10454. if (element.data.tt) {
  10455. var i = 0;
  10456. var len = this.elements.length;
  10457. while (i < len) {
  10458. if (this.elements[i] === element) {
  10459. var elementIndex = 'tp' in element.data
  10460. ? this.findIndexByInd(element.data.tp)
  10461. : i - 1;
  10462. var matteElement = this.elements[elementIndex];
  10463. var matteMask = matteElement.getMatte(this.layers[i].tt);
  10464. element.setMatte(matteMask);
  10465. break;
  10466. }
  10467. i += 1;
  10468. }
  10469. }
  10470. }
  10471. };
  10472. SVGRendererBase.prototype.renderFrame = function (num) {
  10473. if (this.renderedFrame === num || this.destroyed) {
  10474. return;
  10475. }
  10476. if (num === null) {
  10477. num = this.renderedFrame;
  10478. } else {
  10479. this.renderedFrame = num;
  10480. }
  10481. // console.log('-------');
  10482. // console.log('FRAME ',num);
  10483. this.globalData.frameNum = num;
  10484. this.globalData.frameId += 1;
  10485. this.globalData.projectInterface.currentFrame = num;
  10486. this.globalData._mdf = false;
  10487. var i;
  10488. var len = this.layers.length;
  10489. if (!this.completeLayers) {
  10490. this.checkLayers(num);
  10491. }
  10492. for (i = len - 1; i >= 0; i -= 1) {
  10493. if (this.completeLayers || this.elements[i]) {
  10494. this.elements[i].prepareFrame(num - this.layers[i].st);
  10495. }
  10496. }
  10497. if (this.globalData._mdf) {
  10498. for (i = 0; i < len; i += 1) {
  10499. if (this.completeLayers || this.elements[i]) {
  10500. this.elements[i].renderFrame();
  10501. }
  10502. }
  10503. }
  10504. };
  10505. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10506. var newElement = element.getBaseElement();
  10507. if (!newElement) {
  10508. return;
  10509. }
  10510. var i = 0;
  10511. var nextElement;
  10512. while (i < pos) {
  10513. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10514. nextElement = this.elements[i].getBaseElement();
  10515. }
  10516. i += 1;
  10517. }
  10518. if (nextElement) {
  10519. this.layerElement.insertBefore(newElement, nextElement);
  10520. } else {
  10521. this.layerElement.appendChild(newElement);
  10522. }
  10523. };
  10524. SVGRendererBase.prototype.hide = function () {
  10525. this.layerElement.style.display = 'none';
  10526. };
  10527. SVGRendererBase.prototype.show = function () {
  10528. this.layerElement.style.display = 'block';
  10529. };
  10530. function ICompElement() {}
  10531. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10532. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10533. this.initFrame();
  10534. this.initBaseData(data, globalData, comp);
  10535. this.initTransform(data, globalData, comp);
  10536. this.initRenderable();
  10537. this.initHierarchy();
  10538. this.initRendererElement();
  10539. this.createContainerElements();
  10540. this.createRenderableComponents();
  10541. if (this.data.xt || !globalData.progressiveLoad) {
  10542. this.buildAllItems();
  10543. }
  10544. this.hide();
  10545. };
  10546. /* ICompElement.prototype.hide = function(){
  10547. if(!this.hidden){
  10548. this.hideElement();
  10549. var i,len = this.elements.length;
  10550. for( i = 0; i < len; i+=1 ){
  10551. if(this.elements[i]){
  10552. this.elements[i].hide();
  10553. }
  10554. }
  10555. }
  10556. }; */
  10557. ICompElement.prototype.prepareFrame = function (num) {
  10558. this._mdf = false;
  10559. this.prepareRenderableFrame(num);
  10560. this.prepareProperties(num, this.isInRange);
  10561. if (!this.isInRange && !this.data.xt) {
  10562. return;
  10563. }
  10564. if (!this.tm._placeholder) {
  10565. var timeRemapped = this.tm.v;
  10566. if (timeRemapped === this.data.op) {
  10567. timeRemapped = this.data.op - 1;
  10568. }
  10569. this.renderedFrame = timeRemapped;
  10570. } else {
  10571. this.renderedFrame = num / this.data.sr;
  10572. }
  10573. var i;
  10574. var len = this.elements.length;
  10575. if (!this.completeLayers) {
  10576. this.checkLayers(this.renderedFrame);
  10577. }
  10578. // This iteration needs to be backwards because of how expressions connect between each other
  10579. for (i = len - 1; i >= 0; i -= 1) {
  10580. if (this.completeLayers || this.elements[i]) {
  10581. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10582. if (this.elements[i]._mdf) {
  10583. this._mdf = true;
  10584. }
  10585. }
  10586. }
  10587. };
  10588. ICompElement.prototype.renderInnerContent = function () {
  10589. var i;
  10590. var len = this.layers.length;
  10591. for (i = 0; i < len; i += 1) {
  10592. if (this.completeLayers || this.elements[i]) {
  10593. this.elements[i].renderFrame();
  10594. }
  10595. }
  10596. };
  10597. ICompElement.prototype.setElements = function (elems) {
  10598. this.elements = elems;
  10599. };
  10600. ICompElement.prototype.getElements = function () {
  10601. return this.elements;
  10602. };
  10603. ICompElement.prototype.destroyElements = function () {
  10604. var i;
  10605. var len = this.layers.length;
  10606. for (i = 0; i < len; i += 1) {
  10607. if (this.elements[i]) {
  10608. this.elements[i].destroy();
  10609. }
  10610. }
  10611. };
  10612. ICompElement.prototype.destroy = function () {
  10613. this.destroyElements();
  10614. this.destroyBaseElement();
  10615. };
  10616. function SVGCompElement(data, globalData, comp) {
  10617. this.layers = data.layers;
  10618. this.supports3d = true;
  10619. this.completeLayers = false;
  10620. this.pendingElements = [];
  10621. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10622. this.initElement(data, globalData, comp);
  10623. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  10624. }
  10625. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10626. SVGCompElement.prototype.createComp = function (data) {
  10627. return new SVGCompElement(data, this.globalData, this);
  10628. };
  10629. function SVGRenderer(animationItem, config) {
  10630. this.animationItem = animationItem;
  10631. this.layers = null;
  10632. this.renderedFrame = -1;
  10633. this.svgElement = createNS('svg');
  10634. var ariaLabel = '';
  10635. if (config && config.title) {
  10636. var titleElement = createNS('title');
  10637. var titleId = createElementID();
  10638. titleElement.setAttribute('id', titleId);
  10639. titleElement.textContent = config.title;
  10640. this.svgElement.appendChild(titleElement);
  10641. ariaLabel += titleId;
  10642. }
  10643. if (config && config.description) {
  10644. var descElement = createNS('desc');
  10645. var descId = createElementID();
  10646. descElement.setAttribute('id', descId);
  10647. descElement.textContent = config.description;
  10648. this.svgElement.appendChild(descElement);
  10649. ariaLabel += ' ' + descId;
  10650. }
  10651. if (ariaLabel) {
  10652. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10653. }
  10654. var defs = createNS('defs');
  10655. this.svgElement.appendChild(defs);
  10656. var maskElement = createNS('g');
  10657. this.svgElement.appendChild(maskElement);
  10658. this.layerElement = maskElement;
  10659. this.renderConfig = {
  10660. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  10661. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  10662. contentVisibility: (config && config.contentVisibility) || 'visible',
  10663. progressiveLoad: (config && config.progressiveLoad) || false,
  10664. hideOnTransparent: !((config && config.hideOnTransparent === false)),
  10665. viewBoxOnly: (config && config.viewBoxOnly) || false,
  10666. viewBoxSize: (config && config.viewBoxSize) || false,
  10667. className: (config && config.className) || '',
  10668. id: (config && config.id) || '',
  10669. focusable: config && config.focusable,
  10670. filterSize: {
  10671. width: (config && config.filterSize && config.filterSize.width) || '100%',
  10672. height: (config && config.filterSize && config.filterSize.height) || '100%',
  10673. x: (config && config.filterSize && config.filterSize.x) || '0%',
  10674. y: (config && config.filterSize && config.filterSize.y) || '0%',
  10675. },
  10676. width: (config && config.width),
  10677. height: (config && config.height),
  10678. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  10679. };
  10680. this.globalData = {
  10681. _mdf: false,
  10682. frameNum: -1,
  10683. defs: defs,
  10684. renderConfig: this.renderConfig,
  10685. };
  10686. this.elements = [];
  10687. this.pendingElements = [];
  10688. this.destroyed = false;
  10689. this.rendererType = 'svg';
  10690. }
  10691. extendPrototype([SVGRendererBase], SVGRenderer);
  10692. SVGRenderer.prototype.createComp = function (data) {
  10693. return new SVGCompElement(data, this.globalData, this);
  10694. };
  10695. function ShapeTransformManager() {
  10696. this.sequences = {};
  10697. this.sequenceList = [];
  10698. this.transform_key_count = 0;
  10699. }
  10700. ShapeTransformManager.prototype = {
  10701. addTransformSequence: function (transforms) {
  10702. var i;
  10703. var len = transforms.length;
  10704. var key = '_';
  10705. for (i = 0; i < len; i += 1) {
  10706. key += transforms[i].transform.key + '_';
  10707. }
  10708. var sequence = this.sequences[key];
  10709. if (!sequence) {
  10710. sequence = {
  10711. transforms: [].concat(transforms),
  10712. finalTransform: new Matrix(),
  10713. _mdf: false,
  10714. };
  10715. this.sequences[key] = sequence;
  10716. this.sequenceList.push(sequence);
  10717. }
  10718. return sequence;
  10719. },
  10720. processSequence: function (sequence, isFirstFrame) {
  10721. var i = 0;
  10722. var len = sequence.transforms.length;
  10723. var _mdf = isFirstFrame;
  10724. while (i < len && !isFirstFrame) {
  10725. if (sequence.transforms[i].transform.mProps._mdf) {
  10726. _mdf = true;
  10727. break;
  10728. }
  10729. i += 1;
  10730. }
  10731. if (_mdf) {
  10732. sequence.finalTransform.reset();
  10733. for (i = len - 1; i >= 0; i -= 1) {
  10734. sequence.finalTransform.multiply(sequence.transforms[i].transform.mProps.v);
  10735. }
  10736. }
  10737. sequence._mdf = _mdf;
  10738. },
  10739. processSequences: function (isFirstFrame) {
  10740. var i;
  10741. var len = this.sequenceList.length;
  10742. for (i = 0; i < len; i += 1) {
  10743. this.processSequence(this.sequenceList[i], isFirstFrame);
  10744. }
  10745. },
  10746. getNewKey: function () {
  10747. this.transform_key_count += 1;
  10748. return '_' + this.transform_key_count;
  10749. },
  10750. };
  10751. var lumaLoader = (function () {
  10752. var id = '__lottie_element_luma_buffer';
  10753. var lumaBuffer = null;
  10754. var lumaBufferCtx = null;
  10755. var svg = null;
  10756. // This alternate solution has a slight delay before the filter is applied, resulting in a flicker on the first frame.
  10757. // Keeping this here for reference, and in the future, if offscreen canvas supports url filters, this can be used.
  10758. // For now, neither of them work for offscreen canvas, so canvas workers can't support the luma track matte mask.
  10759. // Naming it solution 2 to mark the extra comment lines.
  10760. /*
  10761. var svgString = [
  10762. '<svg xmlns="http://www.w3.org/2000/svg">',
  10763. '<filter id="' + id + '">',
  10764. '<feColorMatrix type="matrix" color-interpolation-filters="sRGB" values="',
  10765. '0.3, 0.3, 0.3, 0, 0, ',
  10766. '0.3, 0.3, 0.3, 0, 0, ',
  10767. '0.3, 0.3, 0.3, 0, 0, ',
  10768. '0.3, 0.3, 0.3, 0, 0',
  10769. '"/>',
  10770. '</filter>',
  10771. '</svg>',
  10772. ].join('');
  10773. var blob = new Blob([svgString], { type: 'image/svg+xml' });
  10774. var url = URL.createObjectURL(blob);
  10775. */
  10776. function createLumaSvgFilter() {
  10777. var _svg = createNS('svg');
  10778. var fil = createNS('filter');
  10779. var matrix = createNS('feColorMatrix');
  10780. fil.setAttribute('id', id);
  10781. matrix.setAttribute('type', 'matrix');
  10782. matrix.setAttribute('color-interpolation-filters', 'sRGB');
  10783. matrix.setAttribute('values', '0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0');
  10784. fil.appendChild(matrix);
  10785. _svg.appendChild(fil);
  10786. _svg.setAttribute('id', id + '_svg');
  10787. if (featureSupport.svgLumaHidden) {
  10788. _svg.style.display = 'none';
  10789. }
  10790. return _svg;
  10791. }
  10792. function loadLuma() {
  10793. if (!lumaBuffer) {
  10794. svg = createLumaSvgFilter();
  10795. document.body.appendChild(svg);
  10796. lumaBuffer = createTag('canvas');
  10797. lumaBufferCtx = lumaBuffer.getContext('2d');
  10798. // lumaBufferCtx.filter = `url('${url}#__lottie_element_luma_buffer')`; // part of solution 2
  10799. lumaBufferCtx.filter = 'url(#' + id + ')';
  10800. lumaBufferCtx.fillStyle = 'rgba(0,0,0,0)';
  10801. lumaBufferCtx.fillRect(0, 0, 1, 1);
  10802. }
  10803. }
  10804. function getLuma(canvas) {
  10805. if (!lumaBuffer) {
  10806. loadLuma();
  10807. }
  10808. lumaBuffer.width = canvas.width;
  10809. lumaBuffer.height = canvas.height;
  10810. // lumaBufferCtx.filter = `url('${url}#__lottie_element_luma_buffer')`; // part of solution 2
  10811. lumaBufferCtx.filter = 'url(#' + id + ')';
  10812. return lumaBuffer;
  10813. }
  10814. return {
  10815. load: loadLuma,
  10816. get: getLuma,
  10817. };
  10818. });
  10819. function createCanvas(width, height) {
  10820. if (featureSupport.offscreenCanvas) {
  10821. return new OffscreenCanvas(width, height);
  10822. }
  10823. var canvas = createTag('canvas');
  10824. canvas.width = width;
  10825. canvas.height = height;
  10826. return canvas;
  10827. }
  10828. const assetLoader = (function () {
  10829. return {
  10830. loadLumaCanvas: lumaLoader.load,
  10831. getLumaCanvas: lumaLoader.get,
  10832. createCanvas: createCanvas,
  10833. };
  10834. }());
  10835. var registeredEffects = {};
  10836. function CVEffects(elem) {
  10837. var i;
  10838. var len = elem.data.ef ? elem.data.ef.length : 0;
  10839. this.filters = [];
  10840. var filterManager;
  10841. for (i = 0; i < len; i += 1) {
  10842. filterManager = null;
  10843. var type = elem.data.ef[i].ty;
  10844. if (registeredEffects[type]) {
  10845. var Effect = registeredEffects[type].effect;
  10846. filterManager = new Effect(elem.effectsManager.effectElements[i], elem);
  10847. }
  10848. if (filterManager) {
  10849. this.filters.push(filterManager);
  10850. }
  10851. }
  10852. if (this.filters.length) {
  10853. elem.addRenderableComponent(this);
  10854. }
  10855. }
  10856. CVEffects.prototype.renderFrame = function (_isFirstFrame) {
  10857. var i;
  10858. var len = this.filters.length;
  10859. for (i = 0; i < len; i += 1) {
  10860. this.filters[i].renderFrame(_isFirstFrame);
  10861. }
  10862. };
  10863. CVEffects.prototype.getEffects = function (type) {
  10864. var i;
  10865. var len = this.filters.length;
  10866. var effects = [];
  10867. for (i = 0; i < len; i += 1) {
  10868. if (this.filters[i].type === type) {
  10869. effects.push(this.filters[i]);
  10870. }
  10871. }
  10872. return effects;
  10873. };
  10874. function registerEffect(id, effect) {
  10875. registeredEffects[id] = {
  10876. effect,
  10877. };
  10878. }
  10879. function CVMaskElement(data, element) {
  10880. this.data = data;
  10881. this.element = element;
  10882. this.masksProperties = this.data.masksProperties || [];
  10883. this.viewData = createSizedArray(this.masksProperties.length);
  10884. var i;
  10885. var len = this.masksProperties.length;
  10886. var hasMasks = false;
  10887. for (i = 0; i < len; i += 1) {
  10888. if (this.masksProperties[i].mode !== 'n') {
  10889. hasMasks = true;
  10890. }
  10891. this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element, this.masksProperties[i], 3);
  10892. }
  10893. this.hasMasks = hasMasks;
  10894. if (hasMasks) {
  10895. this.element.addRenderableComponent(this);
  10896. }
  10897. }
  10898. CVMaskElement.prototype.renderFrame = function () {
  10899. if (!this.hasMasks) {
  10900. return;
  10901. }
  10902. var transform = this.element.finalTransform.mat;
  10903. var ctx = this.element.canvasContext;
  10904. var i;
  10905. var len = this.masksProperties.length;
  10906. var pt;
  10907. var pts;
  10908. var data;
  10909. ctx.beginPath();
  10910. for (i = 0; i < len; i += 1) {
  10911. if (this.masksProperties[i].mode !== 'n') {
  10912. if (this.masksProperties[i].inv) {
  10913. ctx.moveTo(0, 0);
  10914. ctx.lineTo(this.element.globalData.compSize.w, 0);
  10915. ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h);
  10916. ctx.lineTo(0, this.element.globalData.compSize.h);
  10917. ctx.lineTo(0, 0);
  10918. }
  10919. data = this.viewData[i].v;
  10920. pt = transform.applyToPointArray(data.v[0][0], data.v[0][1], 0);
  10921. ctx.moveTo(pt[0], pt[1]);
  10922. var j;
  10923. var jLen = data._length;
  10924. for (j = 1; j < jLen; j += 1) {
  10925. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]);
  10926. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  10927. }
  10928. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]);
  10929. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  10930. }
  10931. }
  10932. this.element.globalData.renderer.save(true);
  10933. ctx.clip();
  10934. };
  10935. CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty;
  10936. CVMaskElement.prototype.destroy = function () {
  10937. this.element = null;
  10938. };
  10939. function CVBaseElement() {
  10940. }
  10941. var operationsMap = {
  10942. 1: 'source-in',
  10943. 2: 'source-out',
  10944. 3: 'source-in',
  10945. 4: 'source-out',
  10946. };
  10947. CVBaseElement.prototype = {
  10948. createElements: function () {},
  10949. initRendererElement: function () {},
  10950. createContainerElements: function () {
  10951. // If the layer is masked we will use two buffers to store each different states of the drawing
  10952. // This solution is not ideal for several reason. But unfortunately, because of the recursive
  10953. // nature of the render tree, it's the only simple way to make sure one inner mask doesn't override an outer mask.
  10954. // TODO: try to reduce the size of these buffers to the size of the composition contaning the layer
  10955. // It might be challenging because the layer most likely is transformed in some way
  10956. if (this.data.tt >= 1) {
  10957. this.buffers = [];
  10958. var canvasContext = this.globalData.canvasContext;
  10959. var bufferCanvas = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
  10960. this.buffers.push(bufferCanvas);
  10961. var bufferCanvas2 = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
  10962. this.buffers.push(bufferCanvas2);
  10963. if (this.data.tt >= 3 && !document._isProxy) {
  10964. assetLoader.loadLumaCanvas();
  10965. }
  10966. }
  10967. this.canvasContext = this.globalData.canvasContext;
  10968. this.transformCanvas = this.globalData.transformCanvas;
  10969. this.renderableEffectsManager = new CVEffects(this);
  10970. this.searchEffectTransforms();
  10971. },
  10972. createContent: function () {},
  10973. setBlendMode: function () {
  10974. var globalData = this.globalData;
  10975. if (globalData.blendMode !== this.data.bm) {
  10976. globalData.blendMode = this.data.bm;
  10977. var blendModeValue = getBlendMode(this.data.bm);
  10978. globalData.canvasContext.globalCompositeOperation = blendModeValue;
  10979. }
  10980. },
  10981. createRenderableComponents: function () {
  10982. this.maskManager = new CVMaskElement(this.data, this);
  10983. this.transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  10984. },
  10985. hideElement: function () {
  10986. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  10987. this.hidden = true;
  10988. }
  10989. },
  10990. showElement: function () {
  10991. if (this.isInRange && !this.isTransparent) {
  10992. this.hidden = false;
  10993. this._isFirstFrame = true;
  10994. this.maskManager._isFirstFrame = true;
  10995. }
  10996. },
  10997. clearCanvas: function (canvasContext) {
  10998. canvasContext.clearRect(
  10999. this.transformCanvas.tx,
  11000. this.transformCanvas.ty,
  11001. this.transformCanvas.w * this.transformCanvas.sx,
  11002. this.transformCanvas.h * this.transformCanvas.sy
  11003. );
  11004. },
  11005. prepareLayer: function () {
  11006. if (this.data.tt >= 1) {
  11007. var buffer = this.buffers[0];
  11008. var bufferCtx = buffer.getContext('2d');
  11009. this.clearCanvas(bufferCtx);
  11010. // on the first buffer we store the current state of the global drawing
  11011. bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11012. // The next four lines are to clear the canvas
  11013. // TODO: Check if there is a way to clear the canvas without resetting the transform
  11014. this.currentTransform = this.canvasContext.getTransform();
  11015. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11016. this.clearCanvas(this.canvasContext);
  11017. this.canvasContext.setTransform(this.currentTransform);
  11018. }
  11019. },
  11020. exitLayer: function () {
  11021. if (this.data.tt >= 1) {
  11022. var buffer = this.buffers[1];
  11023. // On the second buffer we store the current state of the global drawing
  11024. // that only contains the content of this layer
  11025. // (if it is a composition, it also includes the nested layers)
  11026. var bufferCtx = buffer.getContext('2d');
  11027. this.clearCanvas(bufferCtx);
  11028. bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11029. // We clear the canvas again
  11030. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11031. this.clearCanvas(this.canvasContext);
  11032. this.canvasContext.setTransform(this.currentTransform);
  11033. // We draw the mask
  11034. const mask = this.comp.getElementById('tp' in this.data ? this.data.tp : this.data.ind - 1);
  11035. mask.renderFrame(true);
  11036. // We draw the second buffer (that contains the content of this layer)
  11037. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11038. // If the mask is a Luma matte, we need to do two extra painting operations
  11039. // the _isProxy check is to avoid drawing a fake canvas in workers that will throw an error
  11040. if (this.data.tt >= 3 && !document._isProxy) {
  11041. // We copy the painted mask to a buffer that has a color matrix filter applied to it
  11042. // that applies the rgb values to the alpha channel
  11043. var lumaBuffer = assetLoader.getLumaCanvas(this.canvasContext.canvas);
  11044. var lumaBufferCtx = lumaBuffer.getContext('2d');
  11045. lumaBufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11046. this.clearCanvas(this.canvasContext);
  11047. // we repaint the context with the mask applied to it
  11048. this.canvasContext.drawImage(lumaBuffer, 0, 0);
  11049. }
  11050. this.canvasContext.globalCompositeOperation = operationsMap[this.data.tt];
  11051. this.canvasContext.drawImage(buffer, 0, 0);
  11052. // We finally draw the first buffer (that contains the content of the global drawing)
  11053. // We use destination-over to draw the global drawing below the current layer
  11054. this.canvasContext.globalCompositeOperation = 'destination-over';
  11055. this.canvasContext.drawImage(this.buffers[0], 0, 0);
  11056. this.canvasContext.setTransform(this.currentTransform);
  11057. // We reset the globalCompositeOperation to source-over, the standard type of operation
  11058. this.canvasContext.globalCompositeOperation = 'source-over';
  11059. }
  11060. },
  11061. renderFrame: function (forceRender) {
  11062. if (this.hidden || this.data.hd) {
  11063. return;
  11064. }
  11065. if (this.data.td === 1 && !forceRender) {
  11066. return;
  11067. }
  11068. this.renderTransform();
  11069. this.renderRenderable();
  11070. this.renderLocalTransform();
  11071. this.setBlendMode();
  11072. var forceRealStack = this.data.ty === 0;
  11073. this.prepareLayer();
  11074. this.globalData.renderer.save(forceRealStack);
  11075. this.globalData.renderer.ctxTransform(this.finalTransform.localMat.props);
  11076. this.globalData.renderer.ctxOpacity(this.finalTransform.localOpacity);
  11077. this.renderInnerContent();
  11078. this.globalData.renderer.restore(forceRealStack);
  11079. this.exitLayer();
  11080. if (this.maskManager.hasMasks) {
  11081. this.globalData.renderer.restore(true);
  11082. }
  11083. if (this._isFirstFrame) {
  11084. this._isFirstFrame = false;
  11085. }
  11086. },
  11087. destroy: function () {
  11088. this.canvasContext = null;
  11089. this.data = null;
  11090. this.globalData = null;
  11091. this.maskManager.destroy();
  11092. },
  11093. mHelper: new Matrix(),
  11094. };
  11095. CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement;
  11096. CVBaseElement.prototype.show = CVBaseElement.prototype.showElement;
  11097. function CVShapeData(element, data, styles, transformsManager) {
  11098. this.styledShapes = [];
  11099. this.tr = [0, 0, 0, 0, 0, 0];
  11100. var ty = 4;
  11101. if (data.ty === 'rc') {
  11102. ty = 5;
  11103. } else if (data.ty === 'el') {
  11104. ty = 6;
  11105. } else if (data.ty === 'sr') {
  11106. ty = 7;
  11107. }
  11108. this.sh = ShapePropertyFactory.getShapeProp(element, data, ty, element);
  11109. var i;
  11110. var len = styles.length;
  11111. var styledShape;
  11112. for (i = 0; i < len; i += 1) {
  11113. if (!styles[i].closed) {
  11114. styledShape = {
  11115. transforms: transformsManager.addTransformSequence(styles[i].transforms),
  11116. trNodes: [],
  11117. };
  11118. this.styledShapes.push(styledShape);
  11119. styles[i].elements.push(styledShape);
  11120. }
  11121. }
  11122. }
  11123. CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated;
  11124. function CVShapeElement(data, globalData, comp) {
  11125. this.shapes = [];
  11126. this.shapesData = data.shapes;
  11127. this.stylesList = [];
  11128. this.itemsData = [];
  11129. this.prevViewData = [];
  11130. this.shapeModifiers = [];
  11131. this.processedElements = [];
  11132. this.transformsManager = new ShapeTransformManager();
  11133. this.initElement(data, globalData, comp);
  11134. }
  11135. extendPrototype([BaseElement, TransformElement, CVBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableElement], CVShapeElement);
  11136. CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement;
  11137. CVShapeElement.prototype.transformHelper = { opacity: 1, _opMdf: false };
  11138. CVShapeElement.prototype.dashResetter = [];
  11139. CVShapeElement.prototype.createContent = function () {
  11140. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11141. };
  11142. CVShapeElement.prototype.createStyleElement = function (data, transforms) {
  11143. var styleElem = {
  11144. data: data,
  11145. type: data.ty,
  11146. preTransforms: this.transformsManager.addTransformSequence(transforms),
  11147. transforms: [],
  11148. elements: [],
  11149. closed: data.hd === true,
  11150. };
  11151. var elementData = {};
  11152. if (data.ty === 'fl' || data.ty === 'st') {
  11153. elementData.c = PropertyFactory.getProp(this, data.c, 1, 255, this);
  11154. if (!elementData.c.k) {
  11155. styleElem.co = 'rgb(' + bmFloor(elementData.c.v[0]) + ',' + bmFloor(elementData.c.v[1]) + ',' + bmFloor(elementData.c.v[2]) + ')';
  11156. }
  11157. } else if (data.ty === 'gf' || data.ty === 'gs') {
  11158. elementData.s = PropertyFactory.getProp(this, data.s, 1, null, this);
  11159. elementData.e = PropertyFactory.getProp(this, data.e, 1, null, this);
  11160. elementData.h = PropertyFactory.getProp(this, data.h || { k: 0 }, 0, 0.01, this);
  11161. elementData.a = PropertyFactory.getProp(this, data.a || { k: 0 }, 0, degToRads, this);
  11162. elementData.g = new GradientProperty(this, data.g, this);
  11163. }
  11164. elementData.o = PropertyFactory.getProp(this, data.o, 0, 0.01, this);
  11165. if (data.ty === 'st' || data.ty === 'gs') {
  11166. styleElem.lc = lineCapEnum[data.lc || 2];
  11167. styleElem.lj = lineJoinEnum[data.lj || 2];
  11168. if (data.lj == 1) { // eslint-disable-line eqeqeq
  11169. styleElem.ml = data.ml;
  11170. }
  11171. elementData.w = PropertyFactory.getProp(this, data.w, 0, null, this);
  11172. if (!elementData.w.k) {
  11173. styleElem.wi = elementData.w.v;
  11174. }
  11175. if (data.d) {
  11176. var d = new DashProperty(this, data.d, 'canvas', this);
  11177. elementData.d = d;
  11178. if (!elementData.d.k) {
  11179. styleElem.da = elementData.d.dashArray;
  11180. styleElem.do = elementData.d.dashoffset[0];
  11181. }
  11182. }
  11183. } else {
  11184. styleElem.r = data.r === 2 ? 'evenodd' : 'nonzero';
  11185. }
  11186. this.stylesList.push(styleElem);
  11187. elementData.style = styleElem;
  11188. return elementData;
  11189. };
  11190. CVShapeElement.prototype.createGroupElement = function () {
  11191. var elementData = {
  11192. it: [],
  11193. prevViewData: [],
  11194. };
  11195. return elementData;
  11196. };
  11197. CVShapeElement.prototype.createTransformElement = function (data) {
  11198. var elementData = {
  11199. transform: {
  11200. opacity: 1,
  11201. _opMdf: false,
  11202. key: this.transformsManager.getNewKey(),
  11203. op: PropertyFactory.getProp(this, data.o, 0, 0.01, this),
  11204. mProps: TransformPropertyFactory.getTransformProperty(this, data, this),
  11205. },
  11206. };
  11207. return elementData;
  11208. };
  11209. CVShapeElement.prototype.createShapeElement = function (data) {
  11210. var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager);
  11211. this.shapes.push(elementData);
  11212. this.addShapeToModifiers(elementData);
  11213. return elementData;
  11214. };
  11215. CVShapeElement.prototype.reloadShapes = function () {
  11216. this._isFirstFrame = true;
  11217. var i;
  11218. var len = this.itemsData.length;
  11219. for (i = 0; i < len; i += 1) {
  11220. this.prevViewData[i] = this.itemsData[i];
  11221. }
  11222. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11223. len = this.dynamicProperties.length;
  11224. for (i = 0; i < len; i += 1) {
  11225. this.dynamicProperties[i].getValue();
  11226. }
  11227. this.renderModifiers();
  11228. this.transformsManager.processSequences(this._isFirstFrame);
  11229. };
  11230. CVShapeElement.prototype.addTransformToStyleList = function (transform) {
  11231. var i;
  11232. var len = this.stylesList.length;
  11233. for (i = 0; i < len; i += 1) {
  11234. if (!this.stylesList[i].closed) {
  11235. this.stylesList[i].transforms.push(transform);
  11236. }
  11237. }
  11238. };
  11239. CVShapeElement.prototype.removeTransformFromStyleList = function () {
  11240. var i;
  11241. var len = this.stylesList.length;
  11242. for (i = 0; i < len; i += 1) {
  11243. if (!this.stylesList[i].closed) {
  11244. this.stylesList[i].transforms.pop();
  11245. }
  11246. }
  11247. };
  11248. CVShapeElement.prototype.closeStyles = function (styles) {
  11249. var i;
  11250. var len = styles.length;
  11251. for (i = 0; i < len; i += 1) {
  11252. styles[i].closed = true;
  11253. }
  11254. };
  11255. CVShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, shouldRender, transforms) {
  11256. var i;
  11257. var len = arr.length - 1;
  11258. var j;
  11259. var jLen;
  11260. var ownStyles = [];
  11261. var ownModifiers = [];
  11262. var processedPos;
  11263. var modifier;
  11264. var currentTransform;
  11265. var ownTransforms = [].concat(transforms);
  11266. for (i = len; i >= 0; i -= 1) {
  11267. processedPos = this.searchProcessedElement(arr[i]);
  11268. if (!processedPos) {
  11269. arr[i]._shouldRender = shouldRender;
  11270. } else {
  11271. itemsData[i] = prevViewData[processedPos - 1];
  11272. }
  11273. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs') {
  11274. if (!processedPos) {
  11275. itemsData[i] = this.createStyleElement(arr[i], ownTransforms);
  11276. } else {
  11277. itemsData[i].style.closed = false;
  11278. }
  11279. ownStyles.push(itemsData[i].style);
  11280. } else if (arr[i].ty === 'gr') {
  11281. if (!processedPos) {
  11282. itemsData[i] = this.createGroupElement(arr[i]);
  11283. } else {
  11284. jLen = itemsData[i].it.length;
  11285. for (j = 0; j < jLen; j += 1) {
  11286. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  11287. }
  11288. }
  11289. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, shouldRender, ownTransforms);
  11290. } else if (arr[i].ty === 'tr') {
  11291. if (!processedPos) {
  11292. currentTransform = this.createTransformElement(arr[i]);
  11293. itemsData[i] = currentTransform;
  11294. }
  11295. ownTransforms.push(itemsData[i]);
  11296. this.addTransformToStyleList(itemsData[i]);
  11297. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  11298. if (!processedPos) {
  11299. itemsData[i] = this.createShapeElement(arr[i]);
  11300. }
  11301. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  11302. if (!processedPos) {
  11303. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11304. modifier.init(this, arr[i]);
  11305. itemsData[i] = modifier;
  11306. this.shapeModifiers.push(modifier);
  11307. } else {
  11308. modifier = itemsData[i];
  11309. modifier.closed = false;
  11310. }
  11311. ownModifiers.push(modifier);
  11312. } else if (arr[i].ty === 'rp') {
  11313. if (!processedPos) {
  11314. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11315. itemsData[i] = modifier;
  11316. modifier.init(this, arr, i, itemsData);
  11317. this.shapeModifiers.push(modifier);
  11318. shouldRender = false;
  11319. } else {
  11320. modifier = itemsData[i];
  11321. modifier.closed = true;
  11322. }
  11323. ownModifiers.push(modifier);
  11324. }
  11325. this.addProcessedElement(arr[i], i + 1);
  11326. }
  11327. this.removeTransformFromStyleList();
  11328. this.closeStyles(ownStyles);
  11329. len = ownModifiers.length;
  11330. for (i = 0; i < len; i += 1) {
  11331. ownModifiers[i].closed = true;
  11332. }
  11333. };
  11334. CVShapeElement.prototype.renderInnerContent = function () {
  11335. this.transformHelper.opacity = 1;
  11336. this.transformHelper._opMdf = false;
  11337. this.renderModifiers();
  11338. this.transformsManager.processSequences(this._isFirstFrame);
  11339. this.renderShape(this.transformHelper, this.shapesData, this.itemsData, true);
  11340. };
  11341. CVShapeElement.prototype.renderShapeTransform = function (parentTransform, groupTransform) {
  11342. if (parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) {
  11343. groupTransform.opacity = parentTransform.opacity;
  11344. groupTransform.opacity *= groupTransform.op.v;
  11345. groupTransform._opMdf = true;
  11346. }
  11347. };
  11348. CVShapeElement.prototype.drawLayer = function () {
  11349. var i;
  11350. var len = this.stylesList.length;
  11351. var j;
  11352. var jLen;
  11353. var k;
  11354. var kLen;
  11355. var elems;
  11356. var nodes;
  11357. var renderer = this.globalData.renderer;
  11358. var ctx = this.globalData.canvasContext;
  11359. var type;
  11360. var currentStyle;
  11361. for (i = 0; i < len; i += 1) {
  11362. currentStyle = this.stylesList[i];
  11363. type = currentStyle.type;
  11364. // Skipping style when
  11365. // Stroke width equals 0
  11366. // style should not be rendered (extra unused repeaters)
  11367. // current opacity equals 0
  11368. // global opacity equals 0
  11369. if (!(((type === 'st' || type === 'gs') && currentStyle.wi === 0) || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0)) {
  11370. renderer.save();
  11371. elems = currentStyle.elements;
  11372. if (type === 'st' || type === 'gs') {
  11373. renderer.ctxStrokeStyle(type === 'st' ? currentStyle.co : currentStyle.grd);
  11374. // ctx.strokeStyle = type === 'st' ? currentStyle.co : currentStyle.grd;
  11375. renderer.ctxLineWidth(currentStyle.wi);
  11376. // ctx.lineWidth = currentStyle.wi;
  11377. renderer.ctxLineCap(currentStyle.lc);
  11378. // ctx.lineCap = currentStyle.lc;
  11379. renderer.ctxLineJoin(currentStyle.lj);
  11380. // ctx.lineJoin = currentStyle.lj;
  11381. renderer.ctxMiterLimit(currentStyle.ml || 0);
  11382. // ctx.miterLimit = currentStyle.ml || 0;
  11383. } else {
  11384. renderer.ctxFillStyle(type === 'fl' ? currentStyle.co : currentStyle.grd);
  11385. // ctx.fillStyle = type === 'fl' ? currentStyle.co : currentStyle.grd;
  11386. }
  11387. renderer.ctxOpacity(currentStyle.coOp);
  11388. if (type !== 'st' && type !== 'gs') {
  11389. ctx.beginPath();
  11390. }
  11391. renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props);
  11392. jLen = elems.length;
  11393. for (j = 0; j < jLen; j += 1) {
  11394. if (type === 'st' || type === 'gs') {
  11395. ctx.beginPath();
  11396. if (currentStyle.da) {
  11397. ctx.setLineDash(currentStyle.da);
  11398. ctx.lineDashOffset = currentStyle.do;
  11399. }
  11400. }
  11401. nodes = elems[j].trNodes;
  11402. kLen = nodes.length;
  11403. for (k = 0; k < kLen; k += 1) {
  11404. if (nodes[k].t === 'm') {
  11405. ctx.moveTo(nodes[k].p[0], nodes[k].p[1]);
  11406. } else if (nodes[k].t === 'c') {
  11407. 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]);
  11408. } else {
  11409. ctx.closePath();
  11410. }
  11411. }
  11412. if (type === 'st' || type === 'gs') {
  11413. // ctx.stroke();
  11414. renderer.ctxStroke();
  11415. if (currentStyle.da) {
  11416. ctx.setLineDash(this.dashResetter);
  11417. }
  11418. }
  11419. }
  11420. if (type !== 'st' && type !== 'gs') {
  11421. // ctx.fill(currentStyle.r);
  11422. this.globalData.renderer.ctxFill(currentStyle.r);
  11423. }
  11424. renderer.restore();
  11425. }
  11426. }
  11427. };
  11428. CVShapeElement.prototype.renderShape = function (parentTransform, items, data, isMain) {
  11429. var i;
  11430. var len = items.length - 1;
  11431. var groupTransform;
  11432. groupTransform = parentTransform;
  11433. for (i = len; i >= 0; i -= 1) {
  11434. if (items[i].ty === 'tr') {
  11435. groupTransform = data[i].transform;
  11436. this.renderShapeTransform(parentTransform, groupTransform);
  11437. } else if (items[i].ty === 'sh' || items[i].ty === 'el' || items[i].ty === 'rc' || items[i].ty === 'sr') {
  11438. this.renderPath(items[i], data[i]);
  11439. } else if (items[i].ty === 'fl') {
  11440. this.renderFill(items[i], data[i], groupTransform);
  11441. } else if (items[i].ty === 'st') {
  11442. this.renderStroke(items[i], data[i], groupTransform);
  11443. } else if (items[i].ty === 'gf' || items[i].ty === 'gs') {
  11444. this.renderGradientFill(items[i], data[i], groupTransform);
  11445. } else if (items[i].ty === 'gr') {
  11446. this.renderShape(groupTransform, items[i].it, data[i].it);
  11447. } else if (items[i].ty === 'tm') {
  11448. //
  11449. }
  11450. }
  11451. if (isMain) {
  11452. this.drawLayer();
  11453. }
  11454. };
  11455. CVShapeElement.prototype.renderStyledShape = function (styledShape, shape) {
  11456. if (this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) {
  11457. var shapeNodes = styledShape.trNodes;
  11458. var paths = shape.paths;
  11459. var i;
  11460. var len;
  11461. var j;
  11462. var jLen = paths._length;
  11463. shapeNodes.length = 0;
  11464. var groupTransformMat = styledShape.transforms.finalTransform;
  11465. for (j = 0; j < jLen; j += 1) {
  11466. var pathNodes = paths.shapes[j];
  11467. if (pathNodes && pathNodes.v) {
  11468. len = pathNodes._length;
  11469. for (i = 1; i < len; i += 1) {
  11470. if (i === 1) {
  11471. shapeNodes.push({
  11472. t: 'm',
  11473. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0),
  11474. });
  11475. }
  11476. shapeNodes.push({
  11477. t: 'c',
  11478. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i]),
  11479. });
  11480. }
  11481. if (len === 1) {
  11482. shapeNodes.push({
  11483. t: 'm',
  11484. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0),
  11485. });
  11486. }
  11487. if (pathNodes.c && len) {
  11488. shapeNodes.push({
  11489. t: 'c',
  11490. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0]),
  11491. });
  11492. shapeNodes.push({
  11493. t: 'z',
  11494. });
  11495. }
  11496. }
  11497. }
  11498. styledShape.trNodes = shapeNodes;
  11499. }
  11500. };
  11501. CVShapeElement.prototype.renderPath = function (pathData, itemData) {
  11502. if (pathData.hd !== true && pathData._shouldRender) {
  11503. var i;
  11504. var len = itemData.styledShapes.length;
  11505. for (i = 0; i < len; i += 1) {
  11506. this.renderStyledShape(itemData.styledShapes[i], itemData.sh);
  11507. }
  11508. }
  11509. };
  11510. CVShapeElement.prototype.renderFill = function (styleData, itemData, groupTransform) {
  11511. var styleElem = itemData.style;
  11512. if (itemData.c._mdf || this._isFirstFrame) {
  11513. styleElem.co = 'rgb('
  11514. + bmFloor(itemData.c.v[0]) + ','
  11515. + bmFloor(itemData.c.v[1]) + ','
  11516. + bmFloor(itemData.c.v[2]) + ')';
  11517. }
  11518. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11519. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11520. }
  11521. };
  11522. CVShapeElement.prototype.renderGradientFill = function (styleData, itemData, groupTransform) {
  11523. var styleElem = itemData.style;
  11524. var grd;
  11525. if (!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || (styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf))) {
  11526. var ctx = this.globalData.canvasContext;
  11527. var pt1 = itemData.s.v;
  11528. var pt2 = itemData.e.v;
  11529. if (styleData.t === 1) {
  11530. grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]);
  11531. } else {
  11532. var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  11533. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  11534. var percent = itemData.h.v;
  11535. if (percent >= 1) {
  11536. percent = 0.99;
  11537. } else if (percent <= -1) {
  11538. percent = -0.99;
  11539. }
  11540. var dist = rad * percent;
  11541. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  11542. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  11543. grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad);
  11544. }
  11545. var i;
  11546. var len = styleData.g.p;
  11547. var cValues = itemData.g.c;
  11548. var opacity = 1;
  11549. for (i = 0; i < len; i += 1) {
  11550. if (itemData.g._hasOpacity && itemData.g._collapsable) {
  11551. opacity = itemData.g.o[i * 2 + 1];
  11552. }
  11553. grd.addColorStop(cValues[i * 4] / 100, 'rgba(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ',' + opacity + ')');
  11554. }
  11555. styleElem.grd = grd;
  11556. }
  11557. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11558. };
  11559. CVShapeElement.prototype.renderStroke = function (styleData, itemData, groupTransform) {
  11560. var styleElem = itemData.style;
  11561. var d = itemData.d;
  11562. if (d && (d._mdf || this._isFirstFrame)) {
  11563. styleElem.da = d.dashArray;
  11564. styleElem.do = d.dashoffset[0];
  11565. }
  11566. if (itemData.c._mdf || this._isFirstFrame) {
  11567. styleElem.co = 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')';
  11568. }
  11569. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11570. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11571. }
  11572. if (itemData.w._mdf || this._isFirstFrame) {
  11573. styleElem.wi = itemData.w.v;
  11574. }
  11575. };
  11576. CVShapeElement.prototype.destroy = function () {
  11577. this.shapesData = null;
  11578. this.globalData = null;
  11579. this.canvasContext = null;
  11580. this.stylesList.length = 0;
  11581. this.itemsData.length = 0;
  11582. };
  11583. function CVTextElement(data, globalData, comp) {
  11584. this.textSpans = [];
  11585. this.yOffset = 0;
  11586. this.fillColorAnim = false;
  11587. this.strokeColorAnim = false;
  11588. this.strokeWidthAnim = false;
  11589. this.stroke = false;
  11590. this.fill = false;
  11591. this.justifyOffset = 0;
  11592. this.currentRender = null;
  11593. this.renderType = 'canvas';
  11594. this.values = {
  11595. fill: 'rgba(0,0,0,0)',
  11596. stroke: 'rgba(0,0,0,0)',
  11597. sWidth: 0,
  11598. fValue: '',
  11599. };
  11600. this.initElement(data, globalData, comp);
  11601. }
  11602. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement, ITextElement], CVTextElement);
  11603. CVTextElement.prototype.tHelper = createTag('canvas').getContext('2d');
  11604. CVTextElement.prototype.buildNewText = function () {
  11605. var documentData = this.textProperty.currentData;
  11606. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  11607. var hasFill = false;
  11608. if (documentData.fc) {
  11609. hasFill = true;
  11610. this.values.fill = this.buildColor(documentData.fc);
  11611. } else {
  11612. this.values.fill = 'rgba(0,0,0,0)';
  11613. }
  11614. this.fill = hasFill;
  11615. var hasStroke = false;
  11616. if (documentData.sc) {
  11617. hasStroke = true;
  11618. this.values.stroke = this.buildColor(documentData.sc);
  11619. this.values.sWidth = documentData.sw;
  11620. }
  11621. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  11622. var i;
  11623. var len;
  11624. var letters = documentData.l;
  11625. var matrixHelper = this.mHelper;
  11626. this.stroke = hasStroke;
  11627. this.values.fValue = documentData.finalSize + 'px ' + this.globalData.fontManager.getFontByName(documentData.f).fFamily;
  11628. len = documentData.finalText.length;
  11629. // this.tHelper.font = this.values.fValue;
  11630. var charData;
  11631. var shapeData;
  11632. var k;
  11633. var kLen;
  11634. var shapes;
  11635. var j;
  11636. var jLen;
  11637. var pathNodes;
  11638. var commands;
  11639. var pathArr;
  11640. var singleShape = this.data.singleShape;
  11641. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  11642. var xPos = 0;
  11643. var yPos = 0;
  11644. var firstLine = true;
  11645. var cnt = 0;
  11646. for (i = 0; i < len; i += 1) {
  11647. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  11648. shapeData = (charData && charData.data) || {};
  11649. matrixHelper.reset();
  11650. if (singleShape && letters[i].n) {
  11651. xPos = -trackingOffset;
  11652. yPos += documentData.yOffset;
  11653. yPos += firstLine ? 1 : 0;
  11654. firstLine = false;
  11655. }
  11656. shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
  11657. jLen = shapes.length;
  11658. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  11659. if (singleShape) {
  11660. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  11661. }
  11662. commands = createSizedArray(jLen - 1);
  11663. var commandsCounter = 0;
  11664. for (j = 0; j < jLen; j += 1) {
  11665. if (shapes[j].ty === 'sh') {
  11666. kLen = shapes[j].ks.k.i.length;
  11667. pathNodes = shapes[j].ks.k;
  11668. pathArr = [];
  11669. for (k = 1; k < kLen; k += 1) {
  11670. if (k === 1) {
  11671. pathArr.push(matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
  11672. }
  11673. 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));
  11674. }
  11675. 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));
  11676. commands[commandsCounter] = pathArr;
  11677. commandsCounter += 1;
  11678. }
  11679. }
  11680. if (singleShape) {
  11681. xPos += letters[i].l;
  11682. xPos += trackingOffset;
  11683. }
  11684. if (this.textSpans[cnt]) {
  11685. this.textSpans[cnt].elem = commands;
  11686. } else {
  11687. this.textSpans[cnt] = { elem: commands };
  11688. }
  11689. cnt += 1;
  11690. }
  11691. };
  11692. CVTextElement.prototype.renderInnerContent = function () {
  11693. this.validateText();
  11694. var ctx = this.canvasContext;
  11695. ctx.font = this.values.fValue;
  11696. this.globalData.renderer.ctxLineCap('butt');
  11697. // ctx.lineCap = 'butt';
  11698. this.globalData.renderer.ctxLineJoin('miter');
  11699. // ctx.lineJoin = 'miter';
  11700. this.globalData.renderer.ctxMiterLimit(4);
  11701. // ctx.miterLimit = 4;
  11702. if (!this.data.singleShape) {
  11703. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  11704. }
  11705. var i;
  11706. var len;
  11707. var j;
  11708. var jLen;
  11709. var k;
  11710. var kLen;
  11711. var renderedLetters = this.textAnimator.renderedLetters;
  11712. var letters = this.textProperty.currentData.l;
  11713. len = letters.length;
  11714. var renderedLetter;
  11715. var lastFill = null;
  11716. var lastStroke = null;
  11717. var lastStrokeW = null;
  11718. var commands;
  11719. var pathArr;
  11720. var renderer = this.globalData.renderer;
  11721. for (i = 0; i < len; i += 1) {
  11722. if (!letters[i].n) {
  11723. renderedLetter = renderedLetters[i];
  11724. if (renderedLetter) {
  11725. renderer.save();
  11726. renderer.ctxTransform(renderedLetter.p);
  11727. renderer.ctxOpacity(renderedLetter.o);
  11728. }
  11729. if (this.fill) {
  11730. if (renderedLetter && renderedLetter.fc) {
  11731. if (lastFill !== renderedLetter.fc) {
  11732. renderer.ctxFillStyle(renderedLetter.fc);
  11733. lastFill = renderedLetter.fc;
  11734. // ctx.fillStyle = renderedLetter.fc;
  11735. }
  11736. } else if (lastFill !== this.values.fill) {
  11737. lastFill = this.values.fill;
  11738. renderer.ctxFillStyle(this.values.fill);
  11739. // ctx.fillStyle = this.values.fill;
  11740. }
  11741. commands = this.textSpans[i].elem;
  11742. jLen = commands.length;
  11743. this.globalData.canvasContext.beginPath();
  11744. for (j = 0; j < jLen; j += 1) {
  11745. pathArr = commands[j];
  11746. kLen = pathArr.length;
  11747. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11748. for (k = 2; k < kLen; k += 6) {
  11749. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11750. }
  11751. }
  11752. this.globalData.canvasContext.closePath();
  11753. renderer.ctxFill();
  11754. // this.globalData.canvasContext.fill();
  11755. /// ctx.fillText(this.textSpans[i].val,0,0);
  11756. }
  11757. if (this.stroke) {
  11758. if (renderedLetter && renderedLetter.sw) {
  11759. if (lastStrokeW !== renderedLetter.sw) {
  11760. lastStrokeW = renderedLetter.sw;
  11761. renderer.ctxLineWidth(renderedLetter.sw);
  11762. // ctx.lineWidth = renderedLetter.sw;
  11763. }
  11764. } else if (lastStrokeW !== this.values.sWidth) {
  11765. lastStrokeW = this.values.sWidth;
  11766. renderer.ctxLineWidth(this.values.sWidth);
  11767. // ctx.lineWidth = this.values.sWidth;
  11768. }
  11769. if (renderedLetter && renderedLetter.sc) {
  11770. if (lastStroke !== renderedLetter.sc) {
  11771. lastStroke = renderedLetter.sc;
  11772. renderer.ctxStrokeStyle(renderedLetter.sc);
  11773. // ctx.strokeStyle = renderedLetter.sc;
  11774. }
  11775. } else if (lastStroke !== this.values.stroke) {
  11776. lastStroke = this.values.stroke;
  11777. renderer.ctxStrokeStyle(this.values.stroke);
  11778. // ctx.strokeStyle = this.values.stroke;
  11779. }
  11780. commands = this.textSpans[i].elem;
  11781. jLen = commands.length;
  11782. this.globalData.canvasContext.beginPath();
  11783. for (j = 0; j < jLen; j += 1) {
  11784. pathArr = commands[j];
  11785. kLen = pathArr.length;
  11786. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11787. for (k = 2; k < kLen; k += 6) {
  11788. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11789. }
  11790. }
  11791. this.globalData.canvasContext.closePath();
  11792. renderer.ctxStroke();
  11793. // this.globalData.canvasContext.stroke();
  11794. /// ctx.strokeText(letters[i].val,0,0);
  11795. }
  11796. if (renderedLetter) {
  11797. this.globalData.renderer.restore();
  11798. }
  11799. }
  11800. }
  11801. };
  11802. function CVImageElement(data, globalData, comp) {
  11803. this.assetData = globalData.getAssetData(data.refId);
  11804. this.img = globalData.imageLoader.getAsset(this.assetData);
  11805. this.initElement(data, globalData, comp);
  11806. }
  11807. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVImageElement);
  11808. CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11809. CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11810. CVImageElement.prototype.createContent = function () {
  11811. if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) {
  11812. var canvas = createTag('canvas');
  11813. canvas.width = this.assetData.w;
  11814. canvas.height = this.assetData.h;
  11815. var ctx = canvas.getContext('2d');
  11816. var imgW = this.img.width;
  11817. var imgH = this.img.height;
  11818. var imgRel = imgW / imgH;
  11819. var canvasRel = this.assetData.w / this.assetData.h;
  11820. var widthCrop;
  11821. var heightCrop;
  11822. var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio;
  11823. if ((imgRel > canvasRel && par === 'xMidYMid slice') || (imgRel < canvasRel && par !== 'xMidYMid slice')) {
  11824. heightCrop = imgH;
  11825. widthCrop = heightCrop * canvasRel;
  11826. } else {
  11827. widthCrop = imgW;
  11828. heightCrop = widthCrop / canvasRel;
  11829. }
  11830. ctx.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h);
  11831. this.img = canvas;
  11832. }
  11833. };
  11834. CVImageElement.prototype.renderInnerContent = function () {
  11835. this.canvasContext.drawImage(this.img, 0, 0);
  11836. };
  11837. CVImageElement.prototype.destroy = function () {
  11838. this.img = null;
  11839. };
  11840. function CVSolidElement(data, globalData, comp) {
  11841. this.initElement(data, globalData, comp);
  11842. }
  11843. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVSolidElement);
  11844. CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11845. CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11846. CVSolidElement.prototype.renderInnerContent = function () {
  11847. // var ctx = this.canvasContext;
  11848. this.globalData.renderer.ctxFillStyle(this.data.sc);
  11849. // ctx.fillStyle = this.data.sc;
  11850. this.globalData.renderer.ctxFillRect(0, 0, this.data.sw, this.data.sh);
  11851. // ctx.fillRect(0, 0, this.data.sw, this.data.sh);
  11852. //
  11853. };
  11854. function CanvasRendererBase() {
  11855. }
  11856. extendPrototype([BaseRenderer], CanvasRendererBase);
  11857. CanvasRendererBase.prototype.createShape = function (data) {
  11858. return new CVShapeElement(data, this.globalData, this);
  11859. };
  11860. CanvasRendererBase.prototype.createText = function (data) {
  11861. return new CVTextElement(data, this.globalData, this);
  11862. };
  11863. CanvasRendererBase.prototype.createImage = function (data) {
  11864. return new CVImageElement(data, this.globalData, this);
  11865. };
  11866. CanvasRendererBase.prototype.createSolid = function (data) {
  11867. return new CVSolidElement(data, this.globalData, this);
  11868. };
  11869. CanvasRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  11870. CanvasRendererBase.prototype.ctxTransform = function (props) {
  11871. if (props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0) {
  11872. return;
  11873. }
  11874. this.canvasContext.transform(props[0], props[1], props[4], props[5], props[12], props[13]);
  11875. };
  11876. CanvasRendererBase.prototype.ctxOpacity = function (op) {
  11877. this.canvasContext.globalAlpha *= op < 0 ? 0 : op;
  11878. };
  11879. CanvasRendererBase.prototype.ctxFillStyle = function (value) {
  11880. this.canvasContext.fillStyle = value;
  11881. };
  11882. CanvasRendererBase.prototype.ctxStrokeStyle = function (value) {
  11883. this.canvasContext.strokeStyle = value;
  11884. };
  11885. CanvasRendererBase.prototype.ctxLineWidth = function (value) {
  11886. this.canvasContext.lineWidth = value;
  11887. };
  11888. CanvasRendererBase.prototype.ctxLineCap = function (value) {
  11889. this.canvasContext.lineCap = value;
  11890. };
  11891. CanvasRendererBase.prototype.ctxLineJoin = function (value) {
  11892. this.canvasContext.lineJoin = value;
  11893. };
  11894. CanvasRendererBase.prototype.ctxMiterLimit = function (value) {
  11895. this.canvasContext.miterLimit = value;
  11896. };
  11897. CanvasRendererBase.prototype.ctxFill = function (rule) {
  11898. this.canvasContext.fill(rule);
  11899. };
  11900. CanvasRendererBase.prototype.ctxFillRect = function (x, y, w, h) {
  11901. this.canvasContext.fillRect(x, y, w, h);
  11902. };
  11903. CanvasRendererBase.prototype.ctxStroke = function () {
  11904. this.canvasContext.stroke();
  11905. };
  11906. CanvasRendererBase.prototype.reset = function () {
  11907. if (!this.renderConfig.clearCanvas) {
  11908. this.canvasContext.restore();
  11909. return;
  11910. }
  11911. this.contextData.reset();
  11912. };
  11913. CanvasRendererBase.prototype.save = function () {
  11914. this.canvasContext.save();
  11915. };
  11916. CanvasRendererBase.prototype.restore = function (actionFlag) {
  11917. if (!this.renderConfig.clearCanvas) {
  11918. this.canvasContext.restore();
  11919. return;
  11920. }
  11921. if (actionFlag) {
  11922. this.globalData.blendMode = 'source-over';
  11923. }
  11924. this.contextData.restore(actionFlag);
  11925. };
  11926. CanvasRendererBase.prototype.configAnimation = function (animData) {
  11927. if (this.animationItem.wrapper) {
  11928. this.animationItem.container = createTag('canvas');
  11929. var containerStyle = this.animationItem.container.style;
  11930. containerStyle.width = '100%';
  11931. containerStyle.height = '100%';
  11932. var origin = '0px 0px 0px';
  11933. containerStyle.transformOrigin = origin;
  11934. containerStyle.mozTransformOrigin = origin;
  11935. containerStyle.webkitTransformOrigin = origin;
  11936. containerStyle['-webkit-transform'] = origin;
  11937. containerStyle.contentVisibility = this.renderConfig.contentVisibility;
  11938. this.animationItem.wrapper.appendChild(this.animationItem.container);
  11939. this.canvasContext = this.animationItem.container.getContext('2d');
  11940. if (this.renderConfig.className) {
  11941. this.animationItem.container.setAttribute('class', this.renderConfig.className);
  11942. }
  11943. if (this.renderConfig.id) {
  11944. this.animationItem.container.setAttribute('id', this.renderConfig.id);
  11945. }
  11946. } else {
  11947. this.canvasContext = this.renderConfig.context;
  11948. }
  11949. this.contextData.setContext(this.canvasContext);
  11950. this.data = animData;
  11951. this.layers = animData.layers;
  11952. this.transformCanvas = {
  11953. w: animData.w,
  11954. h: animData.h,
  11955. sx: 0,
  11956. sy: 0,
  11957. tx: 0,
  11958. ty: 0,
  11959. };
  11960. this.setupGlobalData(animData, document.body);
  11961. this.globalData.canvasContext = this.canvasContext;
  11962. this.globalData.renderer = this;
  11963. this.globalData.isDashed = false;
  11964. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  11965. this.globalData.transformCanvas = this.transformCanvas;
  11966. this.elements = createSizedArray(animData.layers.length);
  11967. this.updateContainerSize();
  11968. };
  11969. CanvasRendererBase.prototype.updateContainerSize = function (width, height) {
  11970. this.reset();
  11971. var elementWidth;
  11972. var elementHeight;
  11973. if (width) {
  11974. elementWidth = width;
  11975. elementHeight = height;
  11976. this.canvasContext.canvas.width = elementWidth;
  11977. this.canvasContext.canvas.height = elementHeight;
  11978. } else {
  11979. if (this.animationItem.wrapper && this.animationItem.container) {
  11980. elementWidth = this.animationItem.wrapper.offsetWidth;
  11981. elementHeight = this.animationItem.wrapper.offsetHeight;
  11982. } else {
  11983. elementWidth = this.canvasContext.canvas.width;
  11984. elementHeight = this.canvasContext.canvas.height;
  11985. }
  11986. this.canvasContext.canvas.width = elementWidth * this.renderConfig.dpr;
  11987. this.canvasContext.canvas.height = elementHeight * this.renderConfig.dpr;
  11988. }
  11989. var elementRel;
  11990. var animationRel;
  11991. if (this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1) {
  11992. var par = this.renderConfig.preserveAspectRatio.split(' ');
  11993. var fillType = par[1] || 'meet';
  11994. var pos = par[0] || 'xMidYMid';
  11995. var xPos = pos.substr(0, 4);
  11996. var yPos = pos.substr(4);
  11997. elementRel = elementWidth / elementHeight;
  11998. animationRel = this.transformCanvas.w / this.transformCanvas.h;
  11999. if ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice')) {
  12000. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12001. this.transformCanvas.sy = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12002. } else {
  12003. this.transformCanvas.sx = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12004. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12005. }
  12006. if (xPos === 'xMid' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
  12007. this.transformCanvas.tx = ((elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) / 2) * this.renderConfig.dpr;
  12008. } else if (xPos === 'xMax' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
  12009. this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) * this.renderConfig.dpr;
  12010. } else {
  12011. this.transformCanvas.tx = 0;
  12012. }
  12013. if (yPos === 'YMid' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
  12014. this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) / 2) * this.renderConfig.dpr;
  12015. } else if (yPos === 'YMax' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
  12016. this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w))) * this.renderConfig.dpr;
  12017. } else {
  12018. this.transformCanvas.ty = 0;
  12019. }
  12020. } else if (this.renderConfig.preserveAspectRatio === 'none') {
  12021. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12022. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12023. this.transformCanvas.tx = 0;
  12024. this.transformCanvas.ty = 0;
  12025. } else {
  12026. this.transformCanvas.sx = this.renderConfig.dpr;
  12027. this.transformCanvas.sy = this.renderConfig.dpr;
  12028. this.transformCanvas.tx = 0;
  12029. this.transformCanvas.ty = 0;
  12030. }
  12031. 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];
  12032. /* var i, len = this.elements.length;
  12033. for(i=0;i<len;i+=1){
  12034. if(this.elements[i] && this.elements[i].data.ty === 0){
  12035. this.elements[i].resize(this.globalData.transformCanvas);
  12036. }
  12037. } */
  12038. this.ctxTransform(this.transformCanvas.props);
  12039. this.canvasContext.beginPath();
  12040. this.canvasContext.rect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12041. this.canvasContext.closePath();
  12042. this.canvasContext.clip();
  12043. this.renderFrame(this.renderedFrame, true);
  12044. };
  12045. CanvasRendererBase.prototype.destroy = function () {
  12046. if (this.renderConfig.clearCanvas && this.animationItem.wrapper) {
  12047. this.animationItem.wrapper.innerText = '';
  12048. }
  12049. var i;
  12050. var len = this.layers ? this.layers.length : 0;
  12051. for (i = len - 1; i >= 0; i -= 1) {
  12052. if (this.elements[i] && this.elements[i].destroy) {
  12053. this.elements[i].destroy();
  12054. }
  12055. }
  12056. this.elements.length = 0;
  12057. this.globalData.canvasContext = null;
  12058. this.animationItem.container = null;
  12059. this.destroyed = true;
  12060. };
  12061. CanvasRendererBase.prototype.renderFrame = function (num, forceRender) {
  12062. if ((this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender) || this.destroyed || num === -1) {
  12063. return;
  12064. }
  12065. this.renderedFrame = num;
  12066. this.globalData.frameNum = num - this.animationItem._isFirstFrame;
  12067. this.globalData.frameId += 1;
  12068. this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender;
  12069. this.globalData.projectInterface.currentFrame = num;
  12070. // console.log('--------');
  12071. // console.log('NEW: ',num);
  12072. var i;
  12073. var len = this.layers.length;
  12074. if (!this.completeLayers) {
  12075. this.checkLayers(num);
  12076. }
  12077. for (i = len - 1; i >= 0; i -= 1) {
  12078. if (this.completeLayers || this.elements[i]) {
  12079. this.elements[i].prepareFrame(num - this.layers[i].st);
  12080. }
  12081. }
  12082. if (this.globalData._mdf) {
  12083. if (this.renderConfig.clearCanvas === true) {
  12084. this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12085. } else {
  12086. this.save();
  12087. }
  12088. for (i = len - 1; i >= 0; i -= 1) {
  12089. if (this.completeLayers || this.elements[i]) {
  12090. this.elements[i].renderFrame();
  12091. }
  12092. }
  12093. if (this.renderConfig.clearCanvas !== true) {
  12094. this.restore();
  12095. }
  12096. }
  12097. };
  12098. CanvasRendererBase.prototype.buildItem = function (pos) {
  12099. var elements = this.elements;
  12100. if (elements[pos] || this.layers[pos].ty === 99) {
  12101. return;
  12102. }
  12103. var element = this.createItem(this.layers[pos], this, this.globalData);
  12104. elements[pos] = element;
  12105. element.initExpressions();
  12106. /* if(this.layers[pos].ty === 0){
  12107. element.resize(this.globalData.transformCanvas);
  12108. } */
  12109. };
  12110. CanvasRendererBase.prototype.checkPendingElements = function () {
  12111. while (this.pendingElements.length) {
  12112. var element = this.pendingElements.pop();
  12113. element.checkParenting();
  12114. }
  12115. };
  12116. CanvasRendererBase.prototype.hide = function () {
  12117. this.animationItem.container.style.display = 'none';
  12118. };
  12119. CanvasRendererBase.prototype.show = function () {
  12120. this.animationItem.container.style.display = 'block';
  12121. };
  12122. function CanvasContext() {
  12123. this.opacity = -1;
  12124. this.transform = createTypedArray('float32', 16);
  12125. this.fillStyle = '';
  12126. this.strokeStyle = '';
  12127. this.lineWidth = '';
  12128. this.lineCap = '';
  12129. this.lineJoin = '';
  12130. this.miterLimit = '';
  12131. this.id = Math.random();
  12132. }
  12133. function CVContextData() {
  12134. this.stack = [];
  12135. this.cArrPos = 0;
  12136. this.cTr = new Matrix();
  12137. var i;
  12138. var len = 15;
  12139. for (i = 0; i < len; i += 1) {
  12140. var canvasContext = new CanvasContext();
  12141. this.stack[i] = canvasContext;
  12142. }
  12143. this._length = len;
  12144. this.nativeContext = null;
  12145. this.transformMat = new Matrix();
  12146. this.currentOpacity = 1;
  12147. //
  12148. this.currentFillStyle = '';
  12149. this.appliedFillStyle = '';
  12150. //
  12151. this.currentStrokeStyle = '';
  12152. this.appliedStrokeStyle = '';
  12153. //
  12154. this.currentLineWidth = '';
  12155. this.appliedLineWidth = '';
  12156. //
  12157. this.currentLineCap = '';
  12158. this.appliedLineCap = '';
  12159. //
  12160. this.currentLineJoin = '';
  12161. this.appliedLineJoin = '';
  12162. //
  12163. this.appliedMiterLimit = '';
  12164. this.currentMiterLimit = '';
  12165. }
  12166. CVContextData.prototype.duplicate = function () {
  12167. var newLength = this._length * 2;
  12168. var i = 0;
  12169. for (i = this._length; i < newLength; i += 1) {
  12170. this.stack[i] = new CanvasContext();
  12171. }
  12172. this._length = newLength;
  12173. };
  12174. CVContextData.prototype.reset = function () {
  12175. this.cArrPos = 0;
  12176. this.cTr.reset();
  12177. this.stack[this.cArrPos].opacity = 1;
  12178. };
  12179. CVContextData.prototype.restore = function (forceRestore) {
  12180. this.cArrPos -= 1;
  12181. var currentContext = this.stack[this.cArrPos];
  12182. var transform = currentContext.transform;
  12183. var i;
  12184. var arr = this.cTr.props;
  12185. for (i = 0; i < 16; i += 1) {
  12186. arr[i] = transform[i];
  12187. }
  12188. if (forceRestore) {
  12189. this.nativeContext.restore();
  12190. var prevStack = this.stack[this.cArrPos + 1];
  12191. this.appliedFillStyle = prevStack.fillStyle;
  12192. this.appliedStrokeStyle = prevStack.strokeStyle;
  12193. this.appliedLineWidth = prevStack.lineWidth;
  12194. this.appliedLineCap = prevStack.lineCap;
  12195. this.appliedLineJoin = prevStack.lineJoin;
  12196. this.appliedMiterLimit = prevStack.miterLimit;
  12197. }
  12198. this.nativeContext.setTransform(transform[0], transform[1], transform[4], transform[5], transform[12], transform[13]);
  12199. if (forceRestore || (currentContext.opacity !== -1 && this.currentOpacity !== currentContext.opacity)) {
  12200. this.nativeContext.globalAlpha = currentContext.opacity;
  12201. this.currentOpacity = currentContext.opacity;
  12202. }
  12203. this.currentFillStyle = currentContext.fillStyle;
  12204. this.currentStrokeStyle = currentContext.strokeStyle;
  12205. this.currentLineWidth = currentContext.lineWidth;
  12206. this.currentLineCap = currentContext.lineCap;
  12207. this.currentLineJoin = currentContext.lineJoin;
  12208. this.currentMiterLimit = currentContext.miterLimit;
  12209. };
  12210. CVContextData.prototype.save = function (saveOnNativeFlag) {
  12211. if (saveOnNativeFlag) {
  12212. this.nativeContext.save();
  12213. }
  12214. var props = this.cTr.props;
  12215. if (this._length <= this.cArrPos) {
  12216. this.duplicate();
  12217. }
  12218. var currentStack = this.stack[this.cArrPos];
  12219. var i;
  12220. for (i = 0; i < 16; i += 1) {
  12221. currentStack.transform[i] = props[i];
  12222. }
  12223. this.cArrPos += 1;
  12224. var newStack = this.stack[this.cArrPos];
  12225. newStack.opacity = currentStack.opacity;
  12226. newStack.fillStyle = currentStack.fillStyle;
  12227. newStack.strokeStyle = currentStack.strokeStyle;
  12228. newStack.lineWidth = currentStack.lineWidth;
  12229. newStack.lineCap = currentStack.lineCap;
  12230. newStack.lineJoin = currentStack.lineJoin;
  12231. newStack.miterLimit = currentStack.miterLimit;
  12232. };
  12233. CVContextData.prototype.setOpacity = function (value) {
  12234. this.stack[this.cArrPos].opacity = value;
  12235. };
  12236. CVContextData.prototype.setContext = function (value) {
  12237. this.nativeContext = value;
  12238. };
  12239. CVContextData.prototype.fillStyle = function (value) {
  12240. if (this.stack[this.cArrPos].fillStyle !== value) {
  12241. this.currentFillStyle = value;
  12242. this.stack[this.cArrPos].fillStyle = value;
  12243. }
  12244. };
  12245. CVContextData.prototype.strokeStyle = function (value) {
  12246. if (this.stack[this.cArrPos].strokeStyle !== value) {
  12247. this.currentStrokeStyle = value;
  12248. this.stack[this.cArrPos].strokeStyle = value;
  12249. }
  12250. };
  12251. CVContextData.prototype.lineWidth = function (value) {
  12252. if (this.stack[this.cArrPos].lineWidth !== value) {
  12253. this.currentLineWidth = value;
  12254. this.stack[this.cArrPos].lineWidth = value;
  12255. }
  12256. };
  12257. CVContextData.prototype.lineCap = function (value) {
  12258. if (this.stack[this.cArrPos].lineCap !== value) {
  12259. this.currentLineCap = value;
  12260. this.stack[this.cArrPos].lineCap = value;
  12261. }
  12262. };
  12263. CVContextData.prototype.lineJoin = function (value) {
  12264. if (this.stack[this.cArrPos].lineJoin !== value) {
  12265. this.currentLineJoin = value;
  12266. this.stack[this.cArrPos].lineJoin = value;
  12267. }
  12268. };
  12269. CVContextData.prototype.miterLimit = function (value) {
  12270. if (this.stack[this.cArrPos].miterLimit !== value) {
  12271. this.currentMiterLimit = value;
  12272. this.stack[this.cArrPos].miterLimit = value;
  12273. }
  12274. };
  12275. CVContextData.prototype.transform = function (props) {
  12276. this.transformMat.cloneFromProps(props);
  12277. // Taking the last transform value from the stored stack of transforms
  12278. var currentTransform = this.cTr;
  12279. // Applying the last transform value after the new transform to respect the order of transformations
  12280. this.transformMat.multiply(currentTransform);
  12281. // Storing the new transformed value in the stored transform
  12282. currentTransform.cloneFromProps(this.transformMat.props);
  12283. var trProps = currentTransform.props;
  12284. // Applying the new transform to the canvas
  12285. this.nativeContext.setTransform(trProps[0], trProps[1], trProps[4], trProps[5], trProps[12], trProps[13]);
  12286. };
  12287. CVContextData.prototype.opacity = function (op) {
  12288. var currentOpacity = this.stack[this.cArrPos].opacity;
  12289. currentOpacity *= op < 0 ? 0 : op;
  12290. if (this.stack[this.cArrPos].opacity !== currentOpacity) {
  12291. if (this.currentOpacity !== op) {
  12292. this.nativeContext.globalAlpha = op;
  12293. this.currentOpacity = op;
  12294. }
  12295. this.stack[this.cArrPos].opacity = currentOpacity;
  12296. }
  12297. };
  12298. CVContextData.prototype.fill = function (rule) {
  12299. if (this.appliedFillStyle !== this.currentFillStyle) {
  12300. this.appliedFillStyle = this.currentFillStyle;
  12301. this.nativeContext.fillStyle = this.appliedFillStyle;
  12302. }
  12303. this.nativeContext.fill(rule);
  12304. };
  12305. CVContextData.prototype.fillRect = function (x, y, w, h) {
  12306. if (this.appliedFillStyle !== this.currentFillStyle) {
  12307. this.appliedFillStyle = this.currentFillStyle;
  12308. this.nativeContext.fillStyle = this.appliedFillStyle;
  12309. }
  12310. this.nativeContext.fillRect(x, y, w, h);
  12311. };
  12312. CVContextData.prototype.stroke = function () {
  12313. if (this.appliedStrokeStyle !== this.currentStrokeStyle) {
  12314. this.appliedStrokeStyle = this.currentStrokeStyle;
  12315. this.nativeContext.strokeStyle = this.appliedStrokeStyle;
  12316. }
  12317. if (this.appliedLineWidth !== this.currentLineWidth) {
  12318. this.appliedLineWidth = this.currentLineWidth;
  12319. this.nativeContext.lineWidth = this.appliedLineWidth;
  12320. }
  12321. if (this.appliedLineCap !== this.currentLineCap) {
  12322. this.appliedLineCap = this.currentLineCap;
  12323. this.nativeContext.lineCap = this.appliedLineCap;
  12324. }
  12325. if (this.appliedLineJoin !== this.currentLineJoin) {
  12326. this.appliedLineJoin = this.currentLineJoin;
  12327. this.nativeContext.lineJoin = this.appliedLineJoin;
  12328. }
  12329. if (this.appliedMiterLimit !== this.currentMiterLimit) {
  12330. this.appliedMiterLimit = this.currentMiterLimit;
  12331. this.nativeContext.miterLimit = this.appliedMiterLimit;
  12332. }
  12333. this.nativeContext.stroke();
  12334. };
  12335. function CVCompElement(data, globalData, comp) {
  12336. this.completeLayers = false;
  12337. this.layers = data.layers;
  12338. this.pendingElements = [];
  12339. this.elements = createSizedArray(this.layers.length);
  12340. this.initElement(data, globalData, comp);
  12341. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  12342. }
  12343. extendPrototype([CanvasRendererBase, ICompElement, CVBaseElement], CVCompElement);
  12344. CVCompElement.prototype.renderInnerContent = function () {
  12345. var ctx = this.canvasContext;
  12346. ctx.beginPath();
  12347. ctx.moveTo(0, 0);
  12348. ctx.lineTo(this.data.w, 0);
  12349. ctx.lineTo(this.data.w, this.data.h);
  12350. ctx.lineTo(0, this.data.h);
  12351. ctx.lineTo(0, 0);
  12352. ctx.clip();
  12353. var i;
  12354. var len = this.layers.length;
  12355. for (i = len - 1; i >= 0; i -= 1) {
  12356. if (this.completeLayers || this.elements[i]) {
  12357. this.elements[i].renderFrame();
  12358. }
  12359. }
  12360. };
  12361. CVCompElement.prototype.destroy = function () {
  12362. var i;
  12363. var len = this.layers.length;
  12364. for (i = len - 1; i >= 0; i -= 1) {
  12365. if (this.elements[i]) {
  12366. this.elements[i].destroy();
  12367. }
  12368. }
  12369. this.layers = null;
  12370. this.elements = null;
  12371. };
  12372. CVCompElement.prototype.createComp = function (data) {
  12373. return new CVCompElement(data, this.globalData, this);
  12374. };
  12375. function CanvasRenderer(animationItem, config) {
  12376. this.animationItem = animationItem;
  12377. this.renderConfig = {
  12378. clearCanvas: (config && config.clearCanvas !== undefined) ? config.clearCanvas : true,
  12379. context: (config && config.context) || null,
  12380. progressiveLoad: (config && config.progressiveLoad) || false,
  12381. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  12382. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  12383. contentVisibility: (config && config.contentVisibility) || 'visible',
  12384. className: (config && config.className) || '',
  12385. id: (config && config.id) || '',
  12386. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  12387. };
  12388. this.renderConfig.dpr = (config && config.dpr) || 1;
  12389. if (this.animationItem.wrapper) {
  12390. this.renderConfig.dpr = (config && config.dpr) || window.devicePixelRatio || 1;
  12391. }
  12392. this.renderedFrame = -1;
  12393. this.globalData = {
  12394. frameNum: -1,
  12395. _mdf: false,
  12396. renderConfig: this.renderConfig,
  12397. currentGlobalAlpha: -1,
  12398. };
  12399. this.contextData = new CVContextData();
  12400. this.elements = [];
  12401. this.pendingElements = [];
  12402. this.transformMat = new Matrix();
  12403. this.completeLayers = false;
  12404. this.rendererType = 'canvas';
  12405. if (this.renderConfig.clearCanvas) {
  12406. this.ctxTransform = this.contextData.transform.bind(this.contextData);
  12407. this.ctxOpacity = this.contextData.opacity.bind(this.contextData);
  12408. this.ctxFillStyle = this.contextData.fillStyle.bind(this.contextData);
  12409. this.ctxStrokeStyle = this.contextData.strokeStyle.bind(this.contextData);
  12410. this.ctxLineWidth = this.contextData.lineWidth.bind(this.contextData);
  12411. this.ctxLineCap = this.contextData.lineCap.bind(this.contextData);
  12412. this.ctxLineJoin = this.contextData.lineJoin.bind(this.contextData);
  12413. this.ctxMiterLimit = this.contextData.miterLimit.bind(this.contextData);
  12414. this.ctxFill = this.contextData.fill.bind(this.contextData);
  12415. this.ctxFillRect = this.contextData.fillRect.bind(this.contextData);
  12416. this.ctxStroke = this.contextData.stroke.bind(this.contextData);
  12417. this.save = this.contextData.save.bind(this.contextData);
  12418. }
  12419. }
  12420. extendPrototype([CanvasRendererBase], CanvasRenderer);
  12421. CanvasRenderer.prototype.createComp = function (data) {
  12422. return new CVCompElement(data, this.globalData, this);
  12423. };
  12424. function HBaseElement() {}
  12425. HBaseElement.prototype = {
  12426. checkBlendMode: function () {},
  12427. initRendererElement: function () {
  12428. this.baseElement = createTag(this.data.tg || 'div');
  12429. if (this.data.hasMask) {
  12430. this.svgElement = createNS('svg');
  12431. this.layerElement = createNS('g');
  12432. this.maskedElement = this.layerElement;
  12433. this.svgElement.appendChild(this.layerElement);
  12434. this.baseElement.appendChild(this.svgElement);
  12435. } else {
  12436. this.layerElement = this.baseElement;
  12437. }
  12438. styleDiv(this.baseElement);
  12439. },
  12440. createContainerElements: function () {
  12441. this.renderableEffectsManager = new CVEffects(this);
  12442. this.transformedElement = this.baseElement;
  12443. this.maskedElement = this.layerElement;
  12444. if (this.data.ln) {
  12445. this.layerElement.setAttribute('id', this.data.ln);
  12446. }
  12447. if (this.data.cl) {
  12448. this.layerElement.setAttribute('class', this.data.cl);
  12449. }
  12450. if (this.data.bm !== 0) {
  12451. this.setBlendMode();
  12452. }
  12453. },
  12454. renderElement: function () {
  12455. var transformedElementStyle = this.transformedElement ? this.transformedElement.style : {};
  12456. if (this.finalTransform._matMdf) {
  12457. var matrixValue = this.finalTransform.mat.toCSS();
  12458. transformedElementStyle.transform = matrixValue;
  12459. transformedElementStyle.webkitTransform = matrixValue;
  12460. }
  12461. if (this.finalTransform._opMdf) {
  12462. transformedElementStyle.opacity = this.finalTransform.mProp.o.v;
  12463. }
  12464. },
  12465. renderFrame: function () {
  12466. // If it is exported as hidden (data.hd === true) no need to render
  12467. // If it is not visible no need to render
  12468. if (this.data.hd || this.hidden) {
  12469. return;
  12470. }
  12471. this.renderTransform();
  12472. this.renderRenderable();
  12473. this.renderElement();
  12474. this.renderInnerContent();
  12475. if (this._isFirstFrame) {
  12476. this._isFirstFrame = false;
  12477. }
  12478. },
  12479. destroy: function () {
  12480. this.layerElement = null;
  12481. this.transformedElement = null;
  12482. if (this.matteElement) {
  12483. this.matteElement = null;
  12484. }
  12485. if (this.maskManager) {
  12486. this.maskManager.destroy();
  12487. this.maskManager = null;
  12488. }
  12489. },
  12490. createRenderableComponents: function () {
  12491. this.maskManager = new MaskElement(this.data, this, this.globalData);
  12492. },
  12493. addEffects: function () {
  12494. },
  12495. setMatte: function () {},
  12496. };
  12497. HBaseElement.prototype.getBaseElement = SVGBaseElement.prototype.getBaseElement;
  12498. HBaseElement.prototype.destroyBaseElement = HBaseElement.prototype.destroy;
  12499. HBaseElement.prototype.buildElementParenting = BaseRenderer.prototype.buildElementParenting;
  12500. function HSolidElement(data, globalData, comp) {
  12501. this.initElement(data, globalData, comp);
  12502. }
  12503. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], HSolidElement);
  12504. HSolidElement.prototype.createContent = function () {
  12505. var rect;
  12506. if (this.data.hasMask) {
  12507. rect = createNS('rect');
  12508. rect.setAttribute('width', this.data.sw);
  12509. rect.setAttribute('height', this.data.sh);
  12510. rect.setAttribute('fill', this.data.sc);
  12511. this.svgElement.setAttribute('width', this.data.sw);
  12512. this.svgElement.setAttribute('height', this.data.sh);
  12513. } else {
  12514. rect = createTag('div');
  12515. rect.style.width = this.data.sw + 'px';
  12516. rect.style.height = this.data.sh + 'px';
  12517. rect.style.backgroundColor = this.data.sc;
  12518. }
  12519. this.layerElement.appendChild(rect);
  12520. };
  12521. function HShapeElement(data, globalData, comp) {
  12522. // List of drawable elements
  12523. this.shapes = [];
  12524. // Full shape data
  12525. this.shapesData = data.shapes;
  12526. // List of styles that will be applied to shapes
  12527. this.stylesList = [];
  12528. // List of modifiers that will be applied to shapes
  12529. this.shapeModifiers = [];
  12530. // List of items in shape tree
  12531. this.itemsData = [];
  12532. // List of items in previous shape tree
  12533. this.processedElements = [];
  12534. // List of animated components
  12535. this.animatedContents = [];
  12536. this.shapesContainer = createNS('g');
  12537. this.initElement(data, globalData, comp);
  12538. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  12539. // List of elements that have been created
  12540. this.prevViewData = [];
  12541. this.currentBBox = {
  12542. x: 999999,
  12543. y: -999999,
  12544. h: 0,
  12545. w: 0,
  12546. };
  12547. }
  12548. extendPrototype([BaseElement, TransformElement, HSolidElement, SVGShapeElement, HBaseElement, HierarchyElement, FrameElement, RenderableElement], HShapeElement);
  12549. HShapeElement.prototype._renderShapeFrame = HShapeElement.prototype.renderInnerContent;
  12550. HShapeElement.prototype.createContent = function () {
  12551. var cont;
  12552. this.baseElement.style.fontSize = 0;
  12553. if (this.data.hasMask) {
  12554. this.layerElement.appendChild(this.shapesContainer);
  12555. cont = this.svgElement;
  12556. } else {
  12557. cont = createNS('svg');
  12558. var size = this.comp.data ? this.comp.data : this.globalData.compSize;
  12559. cont.setAttribute('width', size.w);
  12560. cont.setAttribute('height', size.h);
  12561. cont.appendChild(this.shapesContainer);
  12562. this.layerElement.appendChild(cont);
  12563. }
  12564. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.shapesContainer, 0, [], true);
  12565. this.filterUniqueShapes();
  12566. this.shapeCont = cont;
  12567. };
  12568. HShapeElement.prototype.getTransformedPoint = function (transformers, point) {
  12569. var i;
  12570. var len = transformers.length;
  12571. for (i = 0; i < len; i += 1) {
  12572. point = transformers[i].mProps.v.applyToPointArray(point[0], point[1], 0);
  12573. }
  12574. return point;
  12575. };
  12576. HShapeElement.prototype.calculateShapeBoundingBox = function (item, boundingBox) {
  12577. var shape = item.sh.v;
  12578. var transformers = item.transformers;
  12579. var i;
  12580. var len = shape._length;
  12581. var vPoint;
  12582. var oPoint;
  12583. var nextIPoint;
  12584. var nextVPoint;
  12585. if (len <= 1) {
  12586. return;
  12587. }
  12588. for (i = 0; i < len - 1; i += 1) {
  12589. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  12590. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  12591. nextIPoint = this.getTransformedPoint(transformers, shape.i[i + 1]);
  12592. nextVPoint = this.getTransformedPoint(transformers, shape.v[i + 1]);
  12593. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  12594. }
  12595. if (shape.c) {
  12596. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  12597. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  12598. nextIPoint = this.getTransformedPoint(transformers, shape.i[0]);
  12599. nextVPoint = this.getTransformedPoint(transformers, shape.v[0]);
  12600. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  12601. }
  12602. };
  12603. HShapeElement.prototype.checkBounds = function (vPoint, oPoint, nextIPoint, nextVPoint, boundingBox) {
  12604. this.getBoundsOfCurve(vPoint, oPoint, nextIPoint, nextVPoint);
  12605. var bounds = this.shapeBoundingBox;
  12606. boundingBox.x = bmMin(bounds.left, boundingBox.x);
  12607. boundingBox.xMax = bmMax(bounds.right, boundingBox.xMax);
  12608. boundingBox.y = bmMin(bounds.top, boundingBox.y);
  12609. boundingBox.yMax = bmMax(bounds.bottom, boundingBox.yMax);
  12610. };
  12611. HShapeElement.prototype.shapeBoundingBox = {
  12612. left: 0,
  12613. right: 0,
  12614. top: 0,
  12615. bottom: 0,
  12616. };
  12617. HShapeElement.prototype.tempBoundingBox = {
  12618. x: 0,
  12619. xMax: 0,
  12620. y: 0,
  12621. yMax: 0,
  12622. width: 0,
  12623. height: 0,
  12624. };
  12625. HShapeElement.prototype.getBoundsOfCurve = function (p0, p1, p2, p3) {
  12626. var bounds = [[p0[0], p3[0]], [p0[1], p3[1]]];
  12627. for (var a, b, c, t, b2ac, t1, t2, i = 0; i < 2; ++i) { // eslint-disable-line no-plusplus
  12628. b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
  12629. a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
  12630. c = 3 * p1[i] - 3 * p0[i];
  12631. b |= 0; // eslint-disable-line no-bitwise
  12632. a |= 0; // eslint-disable-line no-bitwise
  12633. c |= 0; // eslint-disable-line no-bitwise
  12634. if (a === 0 && b === 0) {
  12635. //
  12636. } else if (a === 0) {
  12637. t = -c / b;
  12638. if (t > 0 && t < 1) {
  12639. bounds[i].push(this.calculateF(t, p0, p1, p2, p3, i));
  12640. }
  12641. } else {
  12642. b2ac = b * b - 4 * c * a;
  12643. if (b2ac >= 0) {
  12644. t1 = (-b + bmSqrt(b2ac)) / (2 * a);
  12645. if (t1 > 0 && t1 < 1) bounds[i].push(this.calculateF(t1, p0, p1, p2, p3, i));
  12646. t2 = (-b - bmSqrt(b2ac)) / (2 * a);
  12647. if (t2 > 0 && t2 < 1) bounds[i].push(this.calculateF(t2, p0, p1, p2, p3, i));
  12648. }
  12649. }
  12650. }
  12651. this.shapeBoundingBox.left = bmMin.apply(null, bounds[0]);
  12652. this.shapeBoundingBox.top = bmMin.apply(null, bounds[1]);
  12653. this.shapeBoundingBox.right = bmMax.apply(null, bounds[0]);
  12654. this.shapeBoundingBox.bottom = bmMax.apply(null, bounds[1]);
  12655. };
  12656. HShapeElement.prototype.calculateF = function (t, p0, p1, p2, p3, i) {
  12657. return bmPow(1 - t, 3) * p0[i]
  12658. + 3 * bmPow(1 - t, 2) * t * p1[i]
  12659. + 3 * (1 - t) * bmPow(t, 2) * p2[i]
  12660. + bmPow(t, 3) * p3[i];
  12661. };
  12662. HShapeElement.prototype.calculateBoundingBox = function (itemsData, boundingBox) {
  12663. var i;
  12664. var len = itemsData.length;
  12665. for (i = 0; i < len; i += 1) {
  12666. if (itemsData[i] && itemsData[i].sh) {
  12667. this.calculateShapeBoundingBox(itemsData[i], boundingBox);
  12668. } else if (itemsData[i] && itemsData[i].it) {
  12669. this.calculateBoundingBox(itemsData[i].it, boundingBox);
  12670. } else if (itemsData[i] && itemsData[i].style && itemsData[i].w) {
  12671. this.expandStrokeBoundingBox(itemsData[i].w, boundingBox);
  12672. }
  12673. }
  12674. };
  12675. HShapeElement.prototype.expandStrokeBoundingBox = function (widthProperty, boundingBox) {
  12676. var width = 0;
  12677. if (widthProperty.keyframes) {
  12678. for (var i = 0; i < widthProperty.keyframes.length; i += 1) {
  12679. var kfw = widthProperty.keyframes[i].s;
  12680. if (kfw > width) {
  12681. width = kfw;
  12682. }
  12683. }
  12684. width *= widthProperty.mult;
  12685. } else {
  12686. width = widthProperty.v * widthProperty.mult;
  12687. }
  12688. boundingBox.x -= width;
  12689. boundingBox.xMax += width;
  12690. boundingBox.y -= width;
  12691. boundingBox.yMax += width;
  12692. };
  12693. HShapeElement.prototype.currentBoxContains = function (box) {
  12694. return this.currentBBox.x <= box.x
  12695. && this.currentBBox.y <= box.y
  12696. && this.currentBBox.width + this.currentBBox.x >= box.x + box.width
  12697. && this.currentBBox.height + this.currentBBox.y >= box.y + box.height;
  12698. };
  12699. HShapeElement.prototype.renderInnerContent = function () {
  12700. this._renderShapeFrame();
  12701. if (!this.hidden && (this._isFirstFrame || this._mdf)) {
  12702. var tempBoundingBox = this.tempBoundingBox;
  12703. var max = 999999;
  12704. tempBoundingBox.x = max;
  12705. tempBoundingBox.xMax = -max;
  12706. tempBoundingBox.y = max;
  12707. tempBoundingBox.yMax = -max;
  12708. this.calculateBoundingBox(this.itemsData, tempBoundingBox);
  12709. tempBoundingBox.width = tempBoundingBox.xMax < tempBoundingBox.x ? 0 : tempBoundingBox.xMax - tempBoundingBox.x;
  12710. tempBoundingBox.height = tempBoundingBox.yMax < tempBoundingBox.y ? 0 : tempBoundingBox.yMax - tempBoundingBox.y;
  12711. // var tempBoundingBox = this.shapeCont.getBBox();
  12712. if (this.currentBoxContains(tempBoundingBox)) {
  12713. return;
  12714. }
  12715. var changed = false;
  12716. if (this.currentBBox.w !== tempBoundingBox.width) {
  12717. this.currentBBox.w = tempBoundingBox.width;
  12718. this.shapeCont.setAttribute('width', tempBoundingBox.width);
  12719. changed = true;
  12720. }
  12721. if (this.currentBBox.h !== tempBoundingBox.height) {
  12722. this.currentBBox.h = tempBoundingBox.height;
  12723. this.shapeCont.setAttribute('height', tempBoundingBox.height);
  12724. changed = true;
  12725. }
  12726. if (changed || this.currentBBox.x !== tempBoundingBox.x || this.currentBBox.y !== tempBoundingBox.y) {
  12727. this.currentBBox.w = tempBoundingBox.width;
  12728. this.currentBBox.h = tempBoundingBox.height;
  12729. this.currentBBox.x = tempBoundingBox.x;
  12730. this.currentBBox.y = tempBoundingBox.y;
  12731. this.shapeCont.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  12732. var shapeStyle = this.shapeCont.style;
  12733. var shapeTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  12734. shapeStyle.transform = shapeTransform;
  12735. shapeStyle.webkitTransform = shapeTransform;
  12736. }
  12737. }
  12738. };
  12739. function HTextElement(data, globalData, comp) {
  12740. this.textSpans = [];
  12741. this.textPaths = [];
  12742. this.currentBBox = {
  12743. x: 999999,
  12744. y: -999999,
  12745. h: 0,
  12746. w: 0,
  12747. };
  12748. this.renderType = 'svg';
  12749. this.isMasked = false;
  12750. this.initElement(data, globalData, comp);
  12751. }
  12752. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], HTextElement);
  12753. HTextElement.prototype.createContent = function () {
  12754. this.isMasked = this.checkMasks();
  12755. if (this.isMasked) {
  12756. this.renderType = 'svg';
  12757. this.compW = this.comp.data.w;
  12758. this.compH = this.comp.data.h;
  12759. this.svgElement.setAttribute('width', this.compW);
  12760. this.svgElement.setAttribute('height', this.compH);
  12761. var g = createNS('g');
  12762. this.maskedElement.appendChild(g);
  12763. this.innerElem = g;
  12764. } else {
  12765. this.renderType = 'html';
  12766. this.innerElem = this.layerElement;
  12767. }
  12768. this.checkParenting();
  12769. };
  12770. HTextElement.prototype.buildNewText = function () {
  12771. var documentData = this.textProperty.currentData;
  12772. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  12773. var innerElemStyle = this.innerElem.style;
  12774. var textColor = documentData.fc ? this.buildColor(documentData.fc) : 'rgba(0,0,0,0)';
  12775. innerElemStyle.fill = textColor;
  12776. innerElemStyle.color = textColor;
  12777. if (documentData.sc) {
  12778. innerElemStyle.stroke = this.buildColor(documentData.sc);
  12779. innerElemStyle.strokeWidth = documentData.sw + 'px';
  12780. }
  12781. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  12782. if (!this.globalData.fontManager.chars) {
  12783. innerElemStyle.fontSize = documentData.finalSize + 'px';
  12784. innerElemStyle.lineHeight = documentData.finalSize + 'px';
  12785. if (fontData.fClass) {
  12786. this.innerElem.className = fontData.fClass;
  12787. } else {
  12788. innerElemStyle.fontFamily = fontData.fFamily;
  12789. var fWeight = documentData.fWeight;
  12790. var fStyle = documentData.fStyle;
  12791. innerElemStyle.fontStyle = fStyle;
  12792. innerElemStyle.fontWeight = fWeight;
  12793. }
  12794. }
  12795. var i;
  12796. var len;
  12797. var letters = documentData.l;
  12798. len = letters.length;
  12799. var tSpan;
  12800. var tParent;
  12801. var tCont;
  12802. var matrixHelper = this.mHelper;
  12803. var shapes;
  12804. var shapeStr = '';
  12805. var cnt = 0;
  12806. for (i = 0; i < len; i += 1) {
  12807. if (this.globalData.fontManager.chars) {
  12808. if (!this.textPaths[cnt]) {
  12809. tSpan = createNS('path');
  12810. tSpan.setAttribute('stroke-linecap', lineCapEnum[1]);
  12811. tSpan.setAttribute('stroke-linejoin', lineJoinEnum[2]);
  12812. tSpan.setAttribute('stroke-miterlimit', '4');
  12813. } else {
  12814. tSpan = this.textPaths[cnt];
  12815. }
  12816. if (!this.isMasked) {
  12817. if (this.textSpans[cnt]) {
  12818. tParent = this.textSpans[cnt];
  12819. tCont = tParent.children[0];
  12820. } else {
  12821. tParent = createTag('div');
  12822. tParent.style.lineHeight = 0;
  12823. tCont = createNS('svg');
  12824. tCont.appendChild(tSpan);
  12825. styleDiv(tParent);
  12826. }
  12827. }
  12828. } else if (!this.isMasked) {
  12829. if (this.textSpans[cnt]) {
  12830. tParent = this.textSpans[cnt];
  12831. tSpan = this.textPaths[cnt];
  12832. } else {
  12833. tParent = createTag('span');
  12834. styleDiv(tParent);
  12835. tSpan = createTag('span');
  12836. styleDiv(tSpan);
  12837. tParent.appendChild(tSpan);
  12838. }
  12839. } else {
  12840. tSpan = this.textPaths[cnt] ? this.textPaths[cnt] : createNS('text');
  12841. }
  12842. // tSpan.setAttribute('visibility', 'hidden');
  12843. if (this.globalData.fontManager.chars) {
  12844. var charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  12845. var shapeData;
  12846. if (charData) {
  12847. shapeData = charData.data;
  12848. } else {
  12849. shapeData = null;
  12850. }
  12851. matrixHelper.reset();
  12852. if (shapeData && shapeData.shapes && shapeData.shapes.length) {
  12853. shapes = shapeData.shapes[0].it;
  12854. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  12855. shapeStr = this.createPathShape(matrixHelper, shapes);
  12856. tSpan.setAttribute('d', shapeStr);
  12857. }
  12858. if (!this.isMasked) {
  12859. this.innerElem.appendChild(tParent);
  12860. if (shapeData && shapeData.shapes) {
  12861. // document.body.appendChild is needed to get exact measure of shape
  12862. document.body.appendChild(tCont);
  12863. var boundingBox = tCont.getBBox();
  12864. tCont.setAttribute('width', boundingBox.width + 2);
  12865. tCont.setAttribute('height', boundingBox.height + 2);
  12866. tCont.setAttribute('viewBox', (boundingBox.x - 1) + ' ' + (boundingBox.y - 1) + ' ' + (boundingBox.width + 2) + ' ' + (boundingBox.height + 2));
  12867. var tContStyle = tCont.style;
  12868. var tContTranslation = 'translate(' + (boundingBox.x - 1) + 'px,' + (boundingBox.y - 1) + 'px)';
  12869. tContStyle.transform = tContTranslation;
  12870. tContStyle.webkitTransform = tContTranslation;
  12871. letters[i].yOffset = boundingBox.y - 1;
  12872. } else {
  12873. tCont.setAttribute('width', 1);
  12874. tCont.setAttribute('height', 1);
  12875. }
  12876. tParent.appendChild(tCont);
  12877. } else {
  12878. this.innerElem.appendChild(tSpan);
  12879. }
  12880. } else {
  12881. tSpan.textContent = letters[i].val;
  12882. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  12883. if (!this.isMasked) {
  12884. this.innerElem.appendChild(tParent);
  12885. //
  12886. var tStyle = tSpan.style;
  12887. var tSpanTranslation = 'translate3d(0,' + -documentData.finalSize / 1.2 + 'px,0)';
  12888. tStyle.transform = tSpanTranslation;
  12889. tStyle.webkitTransform = tSpanTranslation;
  12890. } else {
  12891. this.innerElem.appendChild(tSpan);
  12892. }
  12893. }
  12894. //
  12895. if (!this.isMasked) {
  12896. this.textSpans[cnt] = tParent;
  12897. } else {
  12898. this.textSpans[cnt] = tSpan;
  12899. }
  12900. this.textSpans[cnt].style.display = 'block';
  12901. this.textPaths[cnt] = tSpan;
  12902. cnt += 1;
  12903. }
  12904. while (cnt < this.textSpans.length) {
  12905. this.textSpans[cnt].style.display = 'none';
  12906. cnt += 1;
  12907. }
  12908. };
  12909. HTextElement.prototype.renderInnerContent = function () {
  12910. this.validateText();
  12911. var svgStyle;
  12912. if (this.data.singleShape) {
  12913. if (!this._isFirstFrame && !this.lettersChangedFlag) {
  12914. return;
  12915. } if (this.isMasked && this.finalTransform._matMdf) {
  12916. // Todo Benchmark if using this is better than getBBox
  12917. this.svgElement.setAttribute('viewBox', -this.finalTransform.mProp.p.v[0] + ' ' + -this.finalTransform.mProp.p.v[1] + ' ' + this.compW + ' ' + this.compH);
  12918. svgStyle = this.svgElement.style;
  12919. var translation = 'translate(' + -this.finalTransform.mProp.p.v[0] + 'px,' + -this.finalTransform.mProp.p.v[1] + 'px)';
  12920. svgStyle.transform = translation;
  12921. svgStyle.webkitTransform = translation;
  12922. }
  12923. }
  12924. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  12925. if (!this.lettersChangedFlag && !this.textAnimator.lettersChangedFlag) {
  12926. return;
  12927. }
  12928. var i;
  12929. var len;
  12930. var count = 0;
  12931. var renderedLetters = this.textAnimator.renderedLetters;
  12932. var letters = this.textProperty.currentData.l;
  12933. len = letters.length;
  12934. var renderedLetter;
  12935. var textSpan;
  12936. var textPath;
  12937. for (i = 0; i < len; i += 1) {
  12938. if (letters[i].n) {
  12939. count += 1;
  12940. } else {
  12941. textSpan = this.textSpans[i];
  12942. textPath = this.textPaths[i];
  12943. renderedLetter = renderedLetters[count];
  12944. count += 1;
  12945. if (renderedLetter._mdf.m) {
  12946. if (!this.isMasked) {
  12947. textSpan.style.webkitTransform = renderedLetter.m;
  12948. textSpan.style.transform = renderedLetter.m;
  12949. } else {
  12950. textSpan.setAttribute('transform', renderedLetter.m);
  12951. }
  12952. }
  12953. /// /textSpan.setAttribute('opacity',renderedLetter.o);
  12954. textSpan.style.opacity = renderedLetter.o;
  12955. if (renderedLetter.sw && renderedLetter._mdf.sw) {
  12956. textPath.setAttribute('stroke-width', renderedLetter.sw);
  12957. }
  12958. if (renderedLetter.sc && renderedLetter._mdf.sc) {
  12959. textPath.setAttribute('stroke', renderedLetter.sc);
  12960. }
  12961. if (renderedLetter.fc && renderedLetter._mdf.fc) {
  12962. textPath.setAttribute('fill', renderedLetter.fc);
  12963. textPath.style.color = renderedLetter.fc;
  12964. }
  12965. }
  12966. }
  12967. if (this.innerElem.getBBox && !this.hidden && (this._isFirstFrame || this._mdf)) {
  12968. var boundingBox = this.innerElem.getBBox();
  12969. if (this.currentBBox.w !== boundingBox.width) {
  12970. this.currentBBox.w = boundingBox.width;
  12971. this.svgElement.setAttribute('width', boundingBox.width);
  12972. }
  12973. if (this.currentBBox.h !== boundingBox.height) {
  12974. this.currentBBox.h = boundingBox.height;
  12975. this.svgElement.setAttribute('height', boundingBox.height);
  12976. }
  12977. var margin = 1;
  12978. if (this.currentBBox.w !== (boundingBox.width + margin * 2) || this.currentBBox.h !== (boundingBox.height + margin * 2) || this.currentBBox.x !== (boundingBox.x - margin) || this.currentBBox.y !== (boundingBox.y - margin)) {
  12979. this.currentBBox.w = boundingBox.width + margin * 2;
  12980. this.currentBBox.h = boundingBox.height + margin * 2;
  12981. this.currentBBox.x = boundingBox.x - margin;
  12982. this.currentBBox.y = boundingBox.y - margin;
  12983. this.svgElement.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  12984. svgStyle = this.svgElement.style;
  12985. var svgTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  12986. svgStyle.transform = svgTransform;
  12987. svgStyle.webkitTransform = svgTransform;
  12988. }
  12989. }
  12990. };
  12991. function HCameraElement(data, globalData, comp) {
  12992. this.initFrame();
  12993. this.initBaseData(data, globalData, comp);
  12994. this.initHierarchy();
  12995. var getProp = PropertyFactory.getProp;
  12996. this.pe = getProp(this, data.pe, 0, 0, this);
  12997. if (data.ks.p.s) {
  12998. this.px = getProp(this, data.ks.p.x, 1, 0, this);
  12999. this.py = getProp(this, data.ks.p.y, 1, 0, this);
  13000. this.pz = getProp(this, data.ks.p.z, 1, 0, this);
  13001. } else {
  13002. this.p = getProp(this, data.ks.p, 1, 0, this);
  13003. }
  13004. if (data.ks.a) {
  13005. this.a = getProp(this, data.ks.a, 1, 0, this);
  13006. }
  13007. if (data.ks.or.k.length && data.ks.or.k[0].to) {
  13008. var i;
  13009. var len = data.ks.or.k.length;
  13010. for (i = 0; i < len; i += 1) {
  13011. data.ks.or.k[i].to = null;
  13012. data.ks.or.k[i].ti = null;
  13013. }
  13014. }
  13015. this.or = getProp(this, data.ks.or, 1, degToRads, this);
  13016. this.or.sh = true;
  13017. this.rx = getProp(this, data.ks.rx, 0, degToRads, this);
  13018. this.ry = getProp(this, data.ks.ry, 0, degToRads, this);
  13019. this.rz = getProp(this, data.ks.rz, 0, degToRads, this);
  13020. this.mat = new Matrix();
  13021. this._prevMat = new Matrix();
  13022. this._isFirstFrame = true;
  13023. // TODO: find a better way to make the HCamera element to be compatible with the LayerInterface and TransformInterface.
  13024. this.finalTransform = {
  13025. mProp: this,
  13026. };
  13027. }
  13028. extendPrototype([BaseElement, FrameElement, HierarchyElement], HCameraElement);
  13029. HCameraElement.prototype.setup = function () {
  13030. var i;
  13031. var len = this.comp.threeDElements.length;
  13032. var comp;
  13033. var perspectiveStyle;
  13034. var containerStyle;
  13035. for (i = 0; i < len; i += 1) {
  13036. // [perspectiveElem,container]
  13037. comp = this.comp.threeDElements[i];
  13038. if (comp.type === '3d') {
  13039. perspectiveStyle = comp.perspectiveElem.style;
  13040. containerStyle = comp.container.style;
  13041. var perspective = this.pe.v + 'px';
  13042. var origin = '0px 0px 0px';
  13043. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  13044. perspectiveStyle.perspective = perspective;
  13045. perspectiveStyle.webkitPerspective = perspective;
  13046. containerStyle.transformOrigin = origin;
  13047. containerStyle.mozTransformOrigin = origin;
  13048. containerStyle.webkitTransformOrigin = origin;
  13049. perspectiveStyle.transform = matrix;
  13050. perspectiveStyle.webkitTransform = matrix;
  13051. }
  13052. }
  13053. };
  13054. HCameraElement.prototype.createElements = function () {
  13055. };
  13056. HCameraElement.prototype.hide = function () {
  13057. };
  13058. HCameraElement.prototype.renderFrame = function () {
  13059. var _mdf = this._isFirstFrame;
  13060. var i;
  13061. var len;
  13062. if (this.hierarchy) {
  13063. len = this.hierarchy.length;
  13064. for (i = 0; i < len; i += 1) {
  13065. _mdf = this.hierarchy[i].finalTransform.mProp._mdf || _mdf;
  13066. }
  13067. }
  13068. if (_mdf || this.pe._mdf || (this.p && this.p._mdf) || (this.px && (this.px._mdf || this.py._mdf || this.pz._mdf)) || this.rx._mdf || this.ry._mdf || this.rz._mdf || this.or._mdf || (this.a && this.a._mdf)) {
  13069. this.mat.reset();
  13070. if (this.hierarchy) {
  13071. len = this.hierarchy.length - 1;
  13072. for (i = len; i >= 0; i -= 1) {
  13073. var mTransf = this.hierarchy[i].finalTransform.mProp;
  13074. this.mat.translate(-mTransf.p.v[0], -mTransf.p.v[1], mTransf.p.v[2]);
  13075. this.mat.rotateX(-mTransf.or.v[0]).rotateY(-mTransf.or.v[1]).rotateZ(mTransf.or.v[2]);
  13076. this.mat.rotateX(-mTransf.rx.v).rotateY(-mTransf.ry.v).rotateZ(mTransf.rz.v);
  13077. this.mat.scale(1 / mTransf.s.v[0], 1 / mTransf.s.v[1], 1 / mTransf.s.v[2]);
  13078. this.mat.translate(mTransf.a.v[0], mTransf.a.v[1], mTransf.a.v[2]);
  13079. }
  13080. }
  13081. if (this.p) {
  13082. this.mat.translate(-this.p.v[0], -this.p.v[1], this.p.v[2]);
  13083. } else {
  13084. this.mat.translate(-this.px.v, -this.py.v, this.pz.v);
  13085. }
  13086. if (this.a) {
  13087. var diffVector;
  13088. if (this.p) {
  13089. diffVector = [this.p.v[0] - this.a.v[0], this.p.v[1] - this.a.v[1], this.p.v[2] - this.a.v[2]];
  13090. } else {
  13091. diffVector = [this.px.v - this.a.v[0], this.py.v - this.a.v[1], this.pz.v - this.a.v[2]];
  13092. }
  13093. var mag = Math.sqrt(Math.pow(diffVector[0], 2) + Math.pow(diffVector[1], 2) + Math.pow(diffVector[2], 2));
  13094. // var lookDir = getNormalizedPoint(getDiffVector(this.a.v,this.p.v));
  13095. var lookDir = [diffVector[0] / mag, diffVector[1] / mag, diffVector[2] / mag];
  13096. var lookLengthOnXZ = Math.sqrt(lookDir[2] * lookDir[2] + lookDir[0] * lookDir[0]);
  13097. var mRotationX = (Math.atan2(lookDir[1], lookLengthOnXZ));
  13098. var mRotationY = (Math.atan2(lookDir[0], -lookDir[2]));
  13099. this.mat.rotateY(mRotationY).rotateX(-mRotationX);
  13100. }
  13101. this.mat.rotateX(-this.rx.v).rotateY(-this.ry.v).rotateZ(this.rz.v);
  13102. this.mat.rotateX(-this.or.v[0]).rotateY(-this.or.v[1]).rotateZ(this.or.v[2]);
  13103. this.mat.translate(this.globalData.compSize.w / 2, this.globalData.compSize.h / 2, 0);
  13104. this.mat.translate(0, 0, this.pe.v);
  13105. var hasMatrixChanged = !this._prevMat.equals(this.mat);
  13106. if ((hasMatrixChanged || this.pe._mdf) && this.comp.threeDElements) {
  13107. len = this.comp.threeDElements.length;
  13108. var comp;
  13109. var perspectiveStyle;
  13110. var containerStyle;
  13111. for (i = 0; i < len; i += 1) {
  13112. comp = this.comp.threeDElements[i];
  13113. if (comp.type === '3d') {
  13114. if (hasMatrixChanged) {
  13115. var matValue = this.mat.toCSS();
  13116. containerStyle = comp.container.style;
  13117. containerStyle.transform = matValue;
  13118. containerStyle.webkitTransform = matValue;
  13119. }
  13120. if (this.pe._mdf) {
  13121. perspectiveStyle = comp.perspectiveElem.style;
  13122. perspectiveStyle.perspective = this.pe.v + 'px';
  13123. perspectiveStyle.webkitPerspective = this.pe.v + 'px';
  13124. }
  13125. }
  13126. }
  13127. this.mat.clone(this._prevMat);
  13128. }
  13129. }
  13130. this._isFirstFrame = false;
  13131. };
  13132. HCameraElement.prototype.prepareFrame = function (num) {
  13133. this.prepareProperties(num, true);
  13134. };
  13135. HCameraElement.prototype.destroy = function () {
  13136. };
  13137. HCameraElement.prototype.getBaseElement = function () { return null; };
  13138. function HImageElement(data, globalData, comp) {
  13139. this.assetData = globalData.getAssetData(data.refId);
  13140. this.initElement(data, globalData, comp);
  13141. }
  13142. extendPrototype([BaseElement, TransformElement, HBaseElement, HSolidElement, HierarchyElement, FrameElement, RenderableElement], HImageElement);
  13143. HImageElement.prototype.createContent = function () {
  13144. var assetPath = this.globalData.getAssetsPath(this.assetData);
  13145. var img = new Image();
  13146. if (this.data.hasMask) {
  13147. this.imageElem = createNS('image');
  13148. this.imageElem.setAttribute('width', this.assetData.w + 'px');
  13149. this.imageElem.setAttribute('height', this.assetData.h + 'px');
  13150. this.imageElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  13151. this.layerElement.appendChild(this.imageElem);
  13152. this.baseElement.setAttribute('width', this.assetData.w);
  13153. this.baseElement.setAttribute('height', this.assetData.h);
  13154. } else {
  13155. this.layerElement.appendChild(img);
  13156. }
  13157. img.crossOrigin = 'anonymous';
  13158. img.src = assetPath;
  13159. if (this.data.ln) {
  13160. this.baseElement.setAttribute('id', this.data.ln);
  13161. }
  13162. };
  13163. function HybridRendererBase(animationItem, config) {
  13164. this.animationItem = animationItem;
  13165. this.layers = null;
  13166. this.renderedFrame = -1;
  13167. this.renderConfig = {
  13168. className: (config && config.className) || '',
  13169. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  13170. hideOnTransparent: !(config && config.hideOnTransparent === false),
  13171. filterSize: {
  13172. width: (config && config.filterSize && config.filterSize.width) || '400%',
  13173. height: (config && config.filterSize && config.filterSize.height) || '400%',
  13174. x: (config && config.filterSize && config.filterSize.x) || '-100%',
  13175. y: (config && config.filterSize && config.filterSize.y) || '-100%',
  13176. },
  13177. };
  13178. this.globalData = {
  13179. _mdf: false,
  13180. frameNum: -1,
  13181. renderConfig: this.renderConfig,
  13182. };
  13183. this.pendingElements = [];
  13184. this.elements = [];
  13185. this.threeDElements = [];
  13186. this.destroyed = false;
  13187. this.camera = null;
  13188. this.supports3d = true;
  13189. this.rendererType = 'html';
  13190. }
  13191. extendPrototype([BaseRenderer], HybridRendererBase);
  13192. HybridRendererBase.prototype.buildItem = SVGRenderer.prototype.buildItem;
  13193. HybridRendererBase.prototype.checkPendingElements = function () {
  13194. while (this.pendingElements.length) {
  13195. var element = this.pendingElements.pop();
  13196. element.checkParenting();
  13197. }
  13198. };
  13199. HybridRendererBase.prototype.appendElementInPos = function (element, pos) {
  13200. var newDOMElement = element.getBaseElement();
  13201. if (!newDOMElement) {
  13202. return;
  13203. }
  13204. var layer = this.layers[pos];
  13205. if (!layer.ddd || !this.supports3d) {
  13206. if (this.threeDElements) {
  13207. this.addTo3dContainer(newDOMElement, pos);
  13208. } else {
  13209. var i = 0;
  13210. var nextDOMElement;
  13211. var nextLayer;
  13212. var tmpDOMElement;
  13213. while (i < pos) {
  13214. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement) {
  13215. nextLayer = this.elements[i];
  13216. tmpDOMElement = this.layers[i].ddd ? this.getThreeDContainerByPos(i) : nextLayer.getBaseElement();
  13217. nextDOMElement = tmpDOMElement || nextDOMElement;
  13218. }
  13219. i += 1;
  13220. }
  13221. if (nextDOMElement) {
  13222. if (!layer.ddd || !this.supports3d) {
  13223. this.layerElement.insertBefore(newDOMElement, nextDOMElement);
  13224. }
  13225. } else if (!layer.ddd || !this.supports3d) {
  13226. this.layerElement.appendChild(newDOMElement);
  13227. }
  13228. }
  13229. } else {
  13230. this.addTo3dContainer(newDOMElement, pos);
  13231. }
  13232. };
  13233. HybridRendererBase.prototype.createShape = function (data) {
  13234. if (!this.supports3d) {
  13235. return new SVGShapeElement(data, this.globalData, this);
  13236. }
  13237. return new HShapeElement(data, this.globalData, this);
  13238. };
  13239. HybridRendererBase.prototype.createText = function (data) {
  13240. if (!this.supports3d) {
  13241. return new SVGTextLottieElement(data, this.globalData, this);
  13242. }
  13243. return new HTextElement(data, this.globalData, this);
  13244. };
  13245. HybridRendererBase.prototype.createCamera = function (data) {
  13246. this.camera = new HCameraElement(data, this.globalData, this);
  13247. return this.camera;
  13248. };
  13249. HybridRendererBase.prototype.createImage = function (data) {
  13250. if (!this.supports3d) {
  13251. return new IImageElement(data, this.globalData, this);
  13252. }
  13253. return new HImageElement(data, this.globalData, this);
  13254. };
  13255. HybridRendererBase.prototype.createSolid = function (data) {
  13256. if (!this.supports3d) {
  13257. return new ISolidElement(data, this.globalData, this);
  13258. }
  13259. return new HSolidElement(data, this.globalData, this);
  13260. };
  13261. HybridRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  13262. HybridRendererBase.prototype.getThreeDContainerByPos = function (pos) {
  13263. var i = 0;
  13264. var len = this.threeDElements.length;
  13265. while (i < len) {
  13266. if (this.threeDElements[i].startPos <= pos && this.threeDElements[i].endPos >= pos) {
  13267. return this.threeDElements[i].perspectiveElem;
  13268. }
  13269. i += 1;
  13270. }
  13271. return null;
  13272. };
  13273. HybridRendererBase.prototype.createThreeDContainer = function (pos, type) {
  13274. var perspectiveElem = createTag('div');
  13275. var style;
  13276. var containerStyle;
  13277. styleDiv(perspectiveElem);
  13278. var container = createTag('div');
  13279. styleDiv(container);
  13280. if (type === '3d') {
  13281. style = perspectiveElem.style;
  13282. style.width = this.globalData.compSize.w + 'px';
  13283. style.height = this.globalData.compSize.h + 'px';
  13284. var center = '50% 50%';
  13285. style.webkitTransformOrigin = center;
  13286. style.mozTransformOrigin = center;
  13287. style.transformOrigin = center;
  13288. containerStyle = container.style;
  13289. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  13290. containerStyle.transform = matrix;
  13291. containerStyle.webkitTransform = matrix;
  13292. }
  13293. perspectiveElem.appendChild(container);
  13294. // this.resizerElem.appendChild(perspectiveElem);
  13295. var threeDContainerData = {
  13296. container: container,
  13297. perspectiveElem: perspectiveElem,
  13298. startPos: pos,
  13299. endPos: pos,
  13300. type: type,
  13301. };
  13302. this.threeDElements.push(threeDContainerData);
  13303. return threeDContainerData;
  13304. };
  13305. HybridRendererBase.prototype.build3dContainers = function () {
  13306. var i;
  13307. var len = this.layers.length;
  13308. var lastThreeDContainerData;
  13309. var currentContainer = '';
  13310. for (i = 0; i < len; i += 1) {
  13311. if (this.layers[i].ddd && this.layers[i].ty !== 3) {
  13312. if (currentContainer !== '3d') {
  13313. currentContainer = '3d';
  13314. lastThreeDContainerData = this.createThreeDContainer(i, '3d');
  13315. }
  13316. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  13317. } else {
  13318. if (currentContainer !== '2d') {
  13319. currentContainer = '2d';
  13320. lastThreeDContainerData = this.createThreeDContainer(i, '2d');
  13321. }
  13322. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  13323. }
  13324. }
  13325. len = this.threeDElements.length;
  13326. for (i = len - 1; i >= 0; i -= 1) {
  13327. this.resizerElem.appendChild(this.threeDElements[i].perspectiveElem);
  13328. }
  13329. };
  13330. HybridRendererBase.prototype.addTo3dContainer = function (elem, pos) {
  13331. var i = 0;
  13332. var len = this.threeDElements.length;
  13333. while (i < len) {
  13334. if (pos <= this.threeDElements[i].endPos) {
  13335. var j = this.threeDElements[i].startPos;
  13336. var nextElement;
  13337. while (j < pos) {
  13338. if (this.elements[j] && this.elements[j].getBaseElement) {
  13339. nextElement = this.elements[j].getBaseElement();
  13340. }
  13341. j += 1;
  13342. }
  13343. if (nextElement) {
  13344. this.threeDElements[i].container.insertBefore(elem, nextElement);
  13345. } else {
  13346. this.threeDElements[i].container.appendChild(elem);
  13347. }
  13348. break;
  13349. }
  13350. i += 1;
  13351. }
  13352. };
  13353. HybridRendererBase.prototype.configAnimation = function (animData) {
  13354. var resizerElem = createTag('div');
  13355. var wrapper = this.animationItem.wrapper;
  13356. var style = resizerElem.style;
  13357. style.width = animData.w + 'px';
  13358. style.height = animData.h + 'px';
  13359. this.resizerElem = resizerElem;
  13360. styleDiv(resizerElem);
  13361. style.transformStyle = 'flat';
  13362. style.mozTransformStyle = 'flat';
  13363. style.webkitTransformStyle = 'flat';
  13364. if (this.renderConfig.className) {
  13365. resizerElem.setAttribute('class', this.renderConfig.className);
  13366. }
  13367. wrapper.appendChild(resizerElem);
  13368. style.overflow = 'hidden';
  13369. var svg = createNS('svg');
  13370. svg.setAttribute('width', '1');
  13371. svg.setAttribute('height', '1');
  13372. styleDiv(svg);
  13373. this.resizerElem.appendChild(svg);
  13374. var defs = createNS('defs');
  13375. svg.appendChild(defs);
  13376. this.data = animData;
  13377. // Mask animation
  13378. this.setupGlobalData(animData, svg);
  13379. this.globalData.defs = defs;
  13380. this.layers = animData.layers;
  13381. this.layerElement = this.resizerElem;
  13382. this.build3dContainers();
  13383. this.updateContainerSize();
  13384. };
  13385. HybridRendererBase.prototype.destroy = function () {
  13386. if (this.animationItem.wrapper) {
  13387. this.animationItem.wrapper.innerText = '';
  13388. }
  13389. this.animationItem.container = null;
  13390. this.globalData.defs = null;
  13391. var i;
  13392. var len = this.layers ? this.layers.length : 0;
  13393. for (i = 0; i < len; i += 1) {
  13394. if (this.elements[i] && this.elements[i].destroy) {
  13395. this.elements[i].destroy();
  13396. }
  13397. }
  13398. this.elements.length = 0;
  13399. this.destroyed = true;
  13400. this.animationItem = null;
  13401. };
  13402. HybridRendererBase.prototype.updateContainerSize = function () {
  13403. var elementWidth = this.animationItem.wrapper.offsetWidth;
  13404. var elementHeight = this.animationItem.wrapper.offsetHeight;
  13405. var elementRel = elementWidth / elementHeight;
  13406. var animationRel = this.globalData.compSize.w / this.globalData.compSize.h;
  13407. var sx;
  13408. var sy;
  13409. var tx;
  13410. var ty;
  13411. if (animationRel > elementRel) {
  13412. sx = elementWidth / (this.globalData.compSize.w);
  13413. sy = elementWidth / (this.globalData.compSize.w);
  13414. tx = 0;
  13415. ty = ((elementHeight - this.globalData.compSize.h * (elementWidth / this.globalData.compSize.w)) / 2);
  13416. } else {
  13417. sx = elementHeight / (this.globalData.compSize.h);
  13418. sy = elementHeight / (this.globalData.compSize.h);
  13419. tx = (elementWidth - this.globalData.compSize.w * (elementHeight / this.globalData.compSize.h)) / 2;
  13420. ty = 0;
  13421. }
  13422. var style = this.resizerElem.style;
  13423. style.webkitTransform = 'matrix3d(' + sx + ',0,0,0,0,' + sy + ',0,0,0,0,1,0,' + tx + ',' + ty + ',0,1)';
  13424. style.transform = style.webkitTransform;
  13425. };
  13426. HybridRendererBase.prototype.renderFrame = SVGRenderer.prototype.renderFrame;
  13427. HybridRendererBase.prototype.hide = function () {
  13428. this.resizerElem.style.display = 'none';
  13429. };
  13430. HybridRendererBase.prototype.show = function () {
  13431. this.resizerElem.style.display = 'block';
  13432. };
  13433. HybridRendererBase.prototype.initItems = function () {
  13434. this.buildAllItems();
  13435. if (this.camera) {
  13436. this.camera.setup();
  13437. } else {
  13438. var cWidth = this.globalData.compSize.w;
  13439. var cHeight = this.globalData.compSize.h;
  13440. var i;
  13441. var len = this.threeDElements.length;
  13442. for (i = 0; i < len; i += 1) {
  13443. var style = this.threeDElements[i].perspectiveElem.style;
  13444. style.webkitPerspective = Math.sqrt(Math.pow(cWidth, 2) + Math.pow(cHeight, 2)) + 'px';
  13445. style.perspective = style.webkitPerspective;
  13446. }
  13447. }
  13448. };
  13449. HybridRendererBase.prototype.searchExtraCompositions = function (assets) {
  13450. var i;
  13451. var len = assets.length;
  13452. var floatingContainer = createTag('div');
  13453. for (i = 0; i < len; i += 1) {
  13454. if (assets[i].xt) {
  13455. var comp = this.createComp(assets[i], floatingContainer, this.globalData.comp, null);
  13456. comp.initExpressions();
  13457. this.globalData.projectInterface.registerComposition(comp);
  13458. }
  13459. }
  13460. };
  13461. function HCompElement(data, globalData, comp) {
  13462. this.layers = data.layers;
  13463. this.supports3d = !data.hasMask;
  13464. this.completeLayers = false;
  13465. this.pendingElements = [];
  13466. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  13467. this.initElement(data, globalData, comp);
  13468. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  13469. }
  13470. extendPrototype([HybridRendererBase, ICompElement, HBaseElement], HCompElement);
  13471. HCompElement.prototype._createBaseContainerElements = HCompElement.prototype.createContainerElements;
  13472. HCompElement.prototype.createContainerElements = function () {
  13473. this._createBaseContainerElements();
  13474. // divElement.style.clip = 'rect(0px, '+this.data.w+'px, '+this.data.h+'px, 0px)';
  13475. if (this.data.hasMask) {
  13476. this.svgElement.setAttribute('width', this.data.w);
  13477. this.svgElement.setAttribute('height', this.data.h);
  13478. this.transformedElement = this.baseElement;
  13479. } else {
  13480. this.transformedElement = this.layerElement;
  13481. }
  13482. };
  13483. HCompElement.prototype.addTo3dContainer = function (elem, pos) {
  13484. var j = 0;
  13485. var nextElement;
  13486. while (j < pos) {
  13487. if (this.elements[j] && this.elements[j].getBaseElement) {
  13488. nextElement = this.elements[j].getBaseElement();
  13489. }
  13490. j += 1;
  13491. }
  13492. if (nextElement) {
  13493. this.layerElement.insertBefore(elem, nextElement);
  13494. } else {
  13495. this.layerElement.appendChild(elem);
  13496. }
  13497. };
  13498. HCompElement.prototype.createComp = function (data) {
  13499. if (!this.supports3d) {
  13500. return new SVGCompElement(data, this.globalData, this);
  13501. }
  13502. return new HCompElement(data, this.globalData, this);
  13503. };
  13504. function HybridRenderer(animationItem, config) {
  13505. this.animationItem = animationItem;
  13506. this.layers = null;
  13507. this.renderedFrame = -1;
  13508. this.renderConfig = {
  13509. className: (config && config.className) || '',
  13510. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  13511. hideOnTransparent: !(config && config.hideOnTransparent === false),
  13512. filterSize: {
  13513. width: (config && config.filterSize && config.filterSize.width) || '400%',
  13514. height: (config && config.filterSize && config.filterSize.height) || '400%',
  13515. x: (config && config.filterSize && config.filterSize.x) || '-100%',
  13516. y: (config && config.filterSize && config.filterSize.y) || '-100%',
  13517. },
  13518. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  13519. };
  13520. this.globalData = {
  13521. _mdf: false,
  13522. frameNum: -1,
  13523. renderConfig: this.renderConfig,
  13524. };
  13525. this.pendingElements = [];
  13526. this.elements = [];
  13527. this.threeDElements = [];
  13528. this.destroyed = false;
  13529. this.camera = null;
  13530. this.supports3d = true;
  13531. this.rendererType = 'html';
  13532. }
  13533. extendPrototype([HybridRendererBase], HybridRenderer);
  13534. HybridRenderer.prototype.createComp = function (data) {
  13535. if (!this.supports3d) {
  13536. return new SVGCompElement(data, this.globalData, this);
  13537. }
  13538. return new HCompElement(data, this.globalData, this);
  13539. };
  13540. const CompExpressionInterface = (function () {
  13541. return function (comp) {
  13542. function _thisLayerFunction(name) {
  13543. var i = 0;
  13544. var len = comp.layers.length;
  13545. while (i < len) {
  13546. if (comp.layers[i].nm === name || comp.layers[i].ind === name) {
  13547. return comp.elements[i].layerInterface;
  13548. }
  13549. i += 1;
  13550. }
  13551. return null;
  13552. // return {active:false};
  13553. }
  13554. Object.defineProperty(_thisLayerFunction, '_name', { value: comp.data.nm });
  13555. _thisLayerFunction.layer = _thisLayerFunction;
  13556. _thisLayerFunction.pixelAspect = 1;
  13557. _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h;
  13558. _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w;
  13559. _thisLayerFunction.pixelAspect = 1;
  13560. _thisLayerFunction.frameDuration = 1 / comp.globalData.frameRate;
  13561. _thisLayerFunction.displayStartTime = 0;
  13562. _thisLayerFunction.numLayers = comp.layers.length;
  13563. return _thisLayerFunction;
  13564. };
  13565. }());
  13566. /* eslint-disable */
  13567. /*
  13568. Copyright 2014 David Bau.
  13569. Permission is hereby granted, free of charge, to any person obtaining
  13570. a copy of this software and associated documentation files (the
  13571. "Software"), to deal in the Software without restriction, including
  13572. without limitation the rights to use, copy, modify, merge, publish,
  13573. distribute, sublicense, and/or sell copies of the Software, and to
  13574. permit persons to whom the Software is furnished to do so, subject to
  13575. the following conditions:
  13576. The above copyright notice and this permission notice shall be
  13577. included in all copies or substantial portions of the Software.
  13578. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13579. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13580. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13581. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  13582. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  13583. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  13584. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13585. */
  13586. function seedRandom(pool, math) {
  13587. //
  13588. // The following constants are related to IEEE 754 limits.
  13589. //
  13590. var global = this,
  13591. width = 256, // each RC4 output is 0 <= x < 256
  13592. chunks = 6, // at least six RC4 outputs for each double
  13593. digits = 52, // there are 52 significant digits in a double
  13594. rngname = 'random', // rngname: name for Math.random and Math.seedrandom
  13595. startdenom = math.pow(width, chunks),
  13596. significance = math.pow(2, digits),
  13597. overflow = significance * 2,
  13598. mask = width - 1,
  13599. nodecrypto; // node.js crypto module, initialized at the bottom.
  13600. //
  13601. // seedrandom()
  13602. // This is the seedrandom function described above.
  13603. //
  13604. function seedrandom(seed, options, callback) {
  13605. var key = [];
  13606. options = (options === true) ? { entropy: true } : (options || {});
  13607. // Flatten the seed string or build one from local entropy if needed.
  13608. var shortseed = mixkey(flatten(
  13609. options.entropy ? [seed, tostring(pool)] :
  13610. (seed === null) ? autoseed() : seed, 3), key);
  13611. // Use the seed to initialize an ARC4 generator.
  13612. var arc4 = new ARC4(key);
  13613. // This function returns a random double in [0, 1) that contains
  13614. // randomness in every bit of the mantissa of the IEEE 754 value.
  13615. var prng = function() {
  13616. var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
  13617. d = startdenom, // and denominator d = 2 ^ 48.
  13618. x = 0; // and no 'extra last byte'.
  13619. while (n < significance) { // Fill up all significant digits by
  13620. n = (n + x) * width; // shifting numerator and
  13621. d *= width; // denominator and generating a
  13622. x = arc4.g(1); // new least-significant-byte.
  13623. }
  13624. while (n >= overflow) { // To avoid rounding up, before adding
  13625. n /= 2; // last byte, shift everything
  13626. d /= 2; // right using integer math until
  13627. x >>>= 1; // we have exactly the desired bits.
  13628. }
  13629. return (n + x) / d; // Form the number within [0, 1).
  13630. };
  13631. prng.int32 = function() { return arc4.g(4) | 0; };
  13632. prng.quick = function() { return arc4.g(4) / 0x100000000; };
  13633. prng.double = prng;
  13634. // Mix the randomness into accumulated entropy.
  13635. mixkey(tostring(arc4.S), pool);
  13636. // Calling convention: what to return as a function of prng, seed, is_math.
  13637. return (options.pass || callback ||
  13638. function(prng, seed, is_math_call, state) {
  13639. if (state) {
  13640. // Load the arc4 state from the given state if it has an S array.
  13641. if (state.S) { copy(state, arc4); }
  13642. // Only provide the .state method if requested via options.state.
  13643. prng.state = function() { return copy(arc4, {}); };
  13644. }
  13645. // If called as a method of Math (Math.seedrandom()), mutate
  13646. // Math.random because that is how seedrandom.js has worked since v1.0.
  13647. if (is_math_call) { math[rngname] = prng; return seed; }
  13648. // Otherwise, it is a newer calling convention, so return the
  13649. // prng directly.
  13650. else return prng;
  13651. })(
  13652. prng,
  13653. shortseed,
  13654. 'global' in options ? options.global : (this == math),
  13655. options.state);
  13656. }
  13657. math['seed' + rngname] = seedrandom;
  13658. //
  13659. // ARC4
  13660. //
  13661. // An ARC4 implementation. The constructor takes a key in the form of
  13662. // an array of at most (width) integers that should be 0 <= x < (width).
  13663. //
  13664. // The g(count) method returns a pseudorandom integer that concatenates
  13665. // the next (count) outputs from ARC4. Its return value is a number x
  13666. // that is in the range 0 <= x < (width ^ count).
  13667. //
  13668. function ARC4(key) {
  13669. var t, keylen = key.length,
  13670. me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
  13671. // The empty key [] is treated as [0].
  13672. if (!keylen) { key = [keylen++]; }
  13673. // Set up S using the standard key scheduling algorithm.
  13674. while (i < width) {
  13675. s[i] = i++;
  13676. }
  13677. for (i = 0; i < width; i++) {
  13678. s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
  13679. s[j] = t;
  13680. }
  13681. // The "g" method returns the next (count) outputs as one number.
  13682. me.g = function(count) {
  13683. // Using instance members instead of closure state nearly doubles speed.
  13684. var t, r = 0,
  13685. i = me.i, j = me.j, s = me.S;
  13686. while (count--) {
  13687. t = s[i = mask & (i + 1)];
  13688. r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
  13689. }
  13690. me.i = i; me.j = j;
  13691. return r;
  13692. // For robust unpredictability, the function call below automatically
  13693. // discards an initial batch of values. This is called RC4-drop[256].
  13694. // See http://google.com/search?q=rsa+fluhrer+response&btnI
  13695. };
  13696. }
  13697. //
  13698. // copy()
  13699. // Copies internal state of ARC4 to or from a plain object.
  13700. //
  13701. function copy(f, t) {
  13702. t.i = f.i;
  13703. t.j = f.j;
  13704. t.S = f.S.slice();
  13705. return t;
  13706. }
  13707. //
  13708. // flatten()
  13709. // Converts an object tree to nested arrays of strings.
  13710. //
  13711. function flatten(obj, depth) {
  13712. var result = [], typ = (typeof obj), prop;
  13713. if (depth && typ == 'object') {
  13714. for (prop in obj) {
  13715. try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
  13716. }
  13717. }
  13718. return (result.length ? result : typ == 'string' ? obj : obj + '\0');
  13719. }
  13720. //
  13721. // mixkey()
  13722. // Mixes a string seed into a key that is an array of integers, and
  13723. // returns a shortened string seed that is equivalent to the result key.
  13724. //
  13725. function mixkey(seed, key) {
  13726. var stringseed = seed + '', smear, j = 0;
  13727. while (j < stringseed.length) {
  13728. key[mask & j] =
  13729. mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
  13730. }
  13731. return tostring(key);
  13732. }
  13733. //
  13734. // autoseed()
  13735. // Returns an object for autoseeding, using window.crypto and Node crypto
  13736. // module if available.
  13737. //
  13738. function autoseed() {
  13739. try {
  13740. if (nodecrypto) { return tostring(nodecrypto.randomBytes(width)); }
  13741. var out = new Uint8Array(width);
  13742. (global.crypto || global.msCrypto).getRandomValues(out);
  13743. return tostring(out);
  13744. } catch (e) {
  13745. var browser = global.navigator,
  13746. plugins = browser && browser.plugins;
  13747. return [+new Date(), global, plugins, global.screen, tostring(pool)];
  13748. }
  13749. }
  13750. //
  13751. // tostring()
  13752. // Converts an array of charcodes to a string
  13753. //
  13754. function tostring(a) {
  13755. return String.fromCharCode.apply(0, a);
  13756. }
  13757. //
  13758. // When seedrandom.js is loaded, we immediately mix a few bits
  13759. // from the built-in RNG into the entropy pool. Because we do
  13760. // not want to interfere with deterministic PRNG state later,
  13761. // seedrandom will not call math.random on its own again after
  13762. // initialization.
  13763. //
  13764. mixkey(math.random(), pool);
  13765. //
  13766. // Nodejs and AMD support: export the implementation as a module using
  13767. // either convention.
  13768. //
  13769. // End anonymous scope, and pass initial values.
  13770. };
  13771. function initialize$2(BMMath) {
  13772. seedRandom([], BMMath);
  13773. }
  13774. var propTypes = {
  13775. SHAPE: 'shape',
  13776. };
  13777. /* eslint-disable camelcase */
  13778. const ExpressionManager = (function () {
  13779. 'use strict';
  13780. var ob = {};
  13781. var Math = BMMath;
  13782. var window = null;
  13783. var document = null;
  13784. var XMLHttpRequest = null;
  13785. var fetch = null;
  13786. var frames = null;
  13787. var _lottieGlobal = {};
  13788. initialize$2(BMMath);
  13789. function resetFrame() {
  13790. _lottieGlobal = {};
  13791. }
  13792. function $bm_isInstanceOfArray(arr) {
  13793. return arr.constructor === Array || arr.constructor === Float32Array;
  13794. }
  13795. function isNumerable(tOfV, v) {
  13796. return tOfV === 'number' || v instanceof Number || tOfV === 'boolean' || tOfV === 'string';
  13797. }
  13798. function $bm_neg(a) {
  13799. var tOfA = typeof a;
  13800. if (tOfA === 'number' || a instanceof Number || tOfA === 'boolean') {
  13801. return -a;
  13802. }
  13803. if ($bm_isInstanceOfArray(a)) {
  13804. var i;
  13805. var lenA = a.length;
  13806. var retArr = [];
  13807. for (i = 0; i < lenA; i += 1) {
  13808. retArr[i] = -a[i];
  13809. }
  13810. return retArr;
  13811. }
  13812. if (a.propType) {
  13813. return a.v;
  13814. }
  13815. return -a;
  13816. }
  13817. var easeInBez = BezierFactory.getBezierEasing(0.333, 0, 0.833, 0.833, 'easeIn').get;
  13818. var easeOutBez = BezierFactory.getBezierEasing(0.167, 0.167, 0.667, 1, 'easeOut').get;
  13819. var easeInOutBez = BezierFactory.getBezierEasing(0.33, 0, 0.667, 1, 'easeInOut').get;
  13820. function sum(a, b) {
  13821. var tOfA = typeof a;
  13822. var tOfB = typeof b;
  13823. if ((isNumerable(tOfA, a) && isNumerable(tOfB, b)) || tOfA === 'string' || tOfB === 'string') {
  13824. return a + b;
  13825. }
  13826. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  13827. a = a.slice(0);
  13828. a[0] += b;
  13829. return a;
  13830. }
  13831. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  13832. b = b.slice(0);
  13833. b[0] = a + b[0];
  13834. return b;
  13835. }
  13836. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  13837. var i = 0;
  13838. var lenA = a.length;
  13839. var lenB = b.length;
  13840. var retArr = [];
  13841. while (i < lenA || i < lenB) {
  13842. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  13843. retArr[i] = a[i] + b[i];
  13844. } else {
  13845. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  13846. }
  13847. i += 1;
  13848. }
  13849. return retArr;
  13850. }
  13851. return 0;
  13852. }
  13853. var add = sum;
  13854. function sub(a, b) {
  13855. var tOfA = typeof a;
  13856. var tOfB = typeof b;
  13857. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  13858. if (tOfA === 'string') {
  13859. a = parseInt(a, 10);
  13860. }
  13861. if (tOfB === 'string') {
  13862. b = parseInt(b, 10);
  13863. }
  13864. return a - b;
  13865. }
  13866. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  13867. a = a.slice(0);
  13868. a[0] -= b;
  13869. return a;
  13870. }
  13871. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  13872. b = b.slice(0);
  13873. b[0] = a - b[0];
  13874. return b;
  13875. }
  13876. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  13877. var i = 0;
  13878. var lenA = a.length;
  13879. var lenB = b.length;
  13880. var retArr = [];
  13881. while (i < lenA || i < lenB) {
  13882. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  13883. retArr[i] = a[i] - b[i];
  13884. } else {
  13885. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  13886. }
  13887. i += 1;
  13888. }
  13889. return retArr;
  13890. }
  13891. return 0;
  13892. }
  13893. function mul(a, b) {
  13894. var tOfA = typeof a;
  13895. var tOfB = typeof b;
  13896. var arr;
  13897. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  13898. return a * b;
  13899. }
  13900. var i;
  13901. var len;
  13902. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  13903. len = a.length;
  13904. arr = createTypedArray('float32', len);
  13905. for (i = 0; i < len; i += 1) {
  13906. arr[i] = a[i] * b;
  13907. }
  13908. return arr;
  13909. }
  13910. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  13911. len = b.length;
  13912. arr = createTypedArray('float32', len);
  13913. for (i = 0; i < len; i += 1) {
  13914. arr[i] = a * b[i];
  13915. }
  13916. return arr;
  13917. }
  13918. return 0;
  13919. }
  13920. function div(a, b) {
  13921. var tOfA = typeof a;
  13922. var tOfB = typeof b;
  13923. var arr;
  13924. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  13925. return a / b;
  13926. }
  13927. var i;
  13928. var len;
  13929. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  13930. len = a.length;
  13931. arr = createTypedArray('float32', len);
  13932. for (i = 0; i < len; i += 1) {
  13933. arr[i] = a[i] / b;
  13934. }
  13935. return arr;
  13936. }
  13937. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  13938. len = b.length;
  13939. arr = createTypedArray('float32', len);
  13940. for (i = 0; i < len; i += 1) {
  13941. arr[i] = a / b[i];
  13942. }
  13943. return arr;
  13944. }
  13945. return 0;
  13946. }
  13947. function mod(a, b) {
  13948. if (typeof a === 'string') {
  13949. a = parseInt(a, 10);
  13950. }
  13951. if (typeof b === 'string') {
  13952. b = parseInt(b, 10);
  13953. }
  13954. return a % b;
  13955. }
  13956. var $bm_sum = sum;
  13957. var $bm_sub = sub;
  13958. var $bm_mul = mul;
  13959. var $bm_div = div;
  13960. var $bm_mod = mod;
  13961. function clamp(num, min, max) {
  13962. if (min > max) {
  13963. var mm = max;
  13964. max = min;
  13965. min = mm;
  13966. }
  13967. return Math.min(Math.max(num, min), max);
  13968. }
  13969. function radiansToDegrees(val) {
  13970. return val / degToRads;
  13971. }
  13972. var radians_to_degrees = radiansToDegrees;
  13973. function degreesToRadians(val) {
  13974. return val * degToRads;
  13975. }
  13976. var degrees_to_radians = radiansToDegrees;
  13977. var helperLengthArray = [0, 0, 0, 0, 0, 0];
  13978. function length(arr1, arr2) {
  13979. if (typeof arr1 === 'number' || arr1 instanceof Number) {
  13980. arr2 = arr2 || 0;
  13981. return Math.abs(arr1 - arr2);
  13982. }
  13983. if (!arr2) {
  13984. arr2 = helperLengthArray;
  13985. }
  13986. var i;
  13987. var len = Math.min(arr1.length, arr2.length);
  13988. var addedLength = 0;
  13989. for (i = 0; i < len; i += 1) {
  13990. addedLength += Math.pow(arr2[i] - arr1[i], 2);
  13991. }
  13992. return Math.sqrt(addedLength);
  13993. }
  13994. function normalize(vec) {
  13995. return div(vec, length(vec));
  13996. }
  13997. function rgbToHsl(val) {
  13998. var r = val[0]; var g = val[1]; var b = val[2];
  13999. var max = Math.max(r, g, b);
  14000. var min = Math.min(r, g, b);
  14001. var h;
  14002. var s;
  14003. var l = (max + min) / 2;
  14004. if (max === min) {
  14005. h = 0; // achromatic
  14006. s = 0; // achromatic
  14007. } else {
  14008. var d = max - min;
  14009. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  14010. switch (max) {
  14011. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  14012. case g: h = (b - r) / d + 2; break;
  14013. case b: h = (r - g) / d + 4; break;
  14014. default: break;
  14015. }
  14016. h /= 6;
  14017. }
  14018. return [h, s, l, val[3]];
  14019. }
  14020. function hue2rgb(p, q, t) {
  14021. if (t < 0) t += 1;
  14022. if (t > 1) t -= 1;
  14023. if (t < 1 / 6) return p + (q - p) * 6 * t;
  14024. if (t < 1 / 2) return q;
  14025. if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
  14026. return p;
  14027. }
  14028. function hslToRgb(val) {
  14029. var h = val[0];
  14030. var s = val[1];
  14031. var l = val[2];
  14032. var r;
  14033. var g;
  14034. var b;
  14035. if (s === 0) {
  14036. r = l; // achromatic
  14037. b = l; // achromatic
  14038. g = l; // achromatic
  14039. } else {
  14040. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  14041. var p = 2 * l - q;
  14042. r = hue2rgb(p, q, h + 1 / 3);
  14043. g = hue2rgb(p, q, h);
  14044. b = hue2rgb(p, q, h - 1 / 3);
  14045. }
  14046. return [r, g, b, val[3]];
  14047. }
  14048. function linear(t, tMin, tMax, value1, value2) {
  14049. if (value1 === undefined || value2 === undefined) {
  14050. value1 = tMin;
  14051. value2 = tMax;
  14052. tMin = 0;
  14053. tMax = 1;
  14054. }
  14055. if (tMax < tMin) {
  14056. var _tMin = tMax;
  14057. tMax = tMin;
  14058. tMin = _tMin;
  14059. }
  14060. if (t <= tMin) {
  14061. return value1;
  14062. } if (t >= tMax) {
  14063. return value2;
  14064. }
  14065. var perc = tMax === tMin ? 0 : (t - tMin) / (tMax - tMin);
  14066. if (!value1.length) {
  14067. return value1 + (value2 - value1) * perc;
  14068. }
  14069. var i;
  14070. var len = value1.length;
  14071. var arr = createTypedArray('float32', len);
  14072. for (i = 0; i < len; i += 1) {
  14073. arr[i] = value1[i] + (value2[i] - value1[i]) * perc;
  14074. }
  14075. return arr;
  14076. }
  14077. function random(min, max) {
  14078. if (max === undefined) {
  14079. if (min === undefined) {
  14080. min = 0;
  14081. max = 1;
  14082. } else {
  14083. max = min;
  14084. min = undefined;
  14085. }
  14086. }
  14087. if (max.length) {
  14088. var i;
  14089. var len = max.length;
  14090. if (!min) {
  14091. min = createTypedArray('float32', len);
  14092. }
  14093. var arr = createTypedArray('float32', len);
  14094. var rnd = BMMath.random();
  14095. for (i = 0; i < len; i += 1) {
  14096. arr[i] = min[i] + rnd * (max[i] - min[i]);
  14097. }
  14098. return arr;
  14099. }
  14100. if (min === undefined) {
  14101. min = 0;
  14102. }
  14103. var rndm = BMMath.random();
  14104. return min + rndm * (max - min);
  14105. }
  14106. function createPath(points, inTangents, outTangents, closed) {
  14107. var i;
  14108. var len = points.length;
  14109. var path = shapePool.newElement();
  14110. path.setPathData(!!closed, len);
  14111. var arrPlaceholder = [0, 0];
  14112. var inVertexPoint;
  14113. var outVertexPoint;
  14114. for (i = 0; i < len; i += 1) {
  14115. inVertexPoint = (inTangents && inTangents[i]) ? inTangents[i] : arrPlaceholder;
  14116. outVertexPoint = (outTangents && outTangents[i]) ? outTangents[i] : arrPlaceholder;
  14117. 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);
  14118. }
  14119. return path;
  14120. }
  14121. function initiateExpression(elem, data, property) {
  14122. // Bail out if we don't want expressions
  14123. function noOp(_value) {
  14124. return _value;
  14125. }
  14126. if (!elem.globalData.renderConfig.runExpressions) {
  14127. return noOp;
  14128. }
  14129. var val = data.x;
  14130. var needsVelocity = /velocity(?![\w\d])/.test(val);
  14131. var _needsRandom = val.indexOf('random') !== -1;
  14132. var elemType = elem.data.ty;
  14133. var transform;
  14134. var $bm_transform;
  14135. var content;
  14136. var effect;
  14137. var thisProperty = property;
  14138. thisProperty.valueAtTime = thisProperty.getValueAtTime;
  14139. Object.defineProperty(thisProperty, 'value', {
  14140. get: function () {
  14141. return thisProperty.v;
  14142. },
  14143. });
  14144. elem.comp.frameDuration = 1 / elem.comp.globalData.frameRate;
  14145. elem.comp.displayStartTime = 0;
  14146. var inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  14147. var outPoint = elem.data.op / elem.comp.globalData.frameRate;
  14148. var width = elem.data.sw ? elem.data.sw : 0;
  14149. var height = elem.data.sh ? elem.data.sh : 0;
  14150. var name = elem.data.nm;
  14151. var loopIn;
  14152. var loop_in;
  14153. var loopOut;
  14154. var loop_out;
  14155. var smooth;
  14156. var toWorld;
  14157. var fromWorld;
  14158. var fromComp;
  14159. var toComp;
  14160. var fromCompToSurface;
  14161. var position;
  14162. var rotation;
  14163. var anchorPoint;
  14164. var scale;
  14165. var thisLayer;
  14166. var thisComp;
  14167. var mask;
  14168. var valueAtTime;
  14169. var velocityAtTime;
  14170. var scoped_bm_rt;
  14171. // val = val.replace(/(\\?"|')((http)(s)?(:\/))?\/.*?(\\?"|')/g, "\"\""); // deter potential network calls
  14172. var expression_function = eval('[function _expression_function(){' + val + ';scoped_bm_rt=$bm_rt}]')[0]; // eslint-disable-line no-eval
  14173. var numKeys = property.kf ? data.k.length : 0;
  14174. var active = !this.data || this.data.hd !== true;
  14175. var wiggle = function wiggle(freq, amp) {
  14176. var iWiggle;
  14177. var j;
  14178. var lenWiggle = this.pv.length ? this.pv.length : 1;
  14179. var addedAmps = createTypedArray('float32', lenWiggle);
  14180. freq = 5;
  14181. var iterations = Math.floor(time * freq);
  14182. iWiggle = 0;
  14183. j = 0;
  14184. while (iWiggle < iterations) {
  14185. // var rnd = BMMath.random();
  14186. for (j = 0; j < lenWiggle; j += 1) {
  14187. addedAmps[j] += -amp + amp * 2 * BMMath.random();
  14188. // addedAmps[j] += -amp + amp*2*rnd;
  14189. }
  14190. iWiggle += 1;
  14191. }
  14192. // var rnd2 = BMMath.random();
  14193. var periods = time * freq;
  14194. var perc = periods - Math.floor(periods);
  14195. var arr = createTypedArray('float32', lenWiggle);
  14196. if (lenWiggle > 1) {
  14197. for (j = 0; j < lenWiggle; j += 1) {
  14198. arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc;
  14199. // arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc;
  14200. // arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc);
  14201. }
  14202. return arr;
  14203. }
  14204. return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc;
  14205. }.bind(this);
  14206. if (thisProperty.loopIn) {
  14207. loopIn = thisProperty.loopIn.bind(thisProperty);
  14208. loop_in = loopIn;
  14209. }
  14210. if (thisProperty.loopOut) {
  14211. loopOut = thisProperty.loopOut.bind(thisProperty);
  14212. loop_out = loopOut;
  14213. }
  14214. if (thisProperty.smooth) {
  14215. smooth = thisProperty.smooth.bind(thisProperty);
  14216. }
  14217. function loopInDuration(type, duration) {
  14218. return loopIn(type, duration, true);
  14219. }
  14220. function loopOutDuration(type, duration) {
  14221. return loopOut(type, duration, true);
  14222. }
  14223. if (this.getValueAtTime) {
  14224. valueAtTime = this.getValueAtTime.bind(this);
  14225. }
  14226. if (this.getVelocityAtTime) {
  14227. velocityAtTime = this.getVelocityAtTime.bind(this);
  14228. }
  14229. var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface);
  14230. function lookAt(elem1, elem2) {
  14231. var fVec = [elem2[0] - elem1[0], elem2[1] - elem1[1], elem2[2] - elem1[2]];
  14232. var pitch = Math.atan2(fVec[0], Math.sqrt(fVec[1] * fVec[1] + fVec[2] * fVec[2])) / degToRads;
  14233. var yaw = -Math.atan2(fVec[1], fVec[2]) / degToRads;
  14234. return [yaw, pitch, 0];
  14235. }
  14236. function easeOut(t, tMin, tMax, val1, val2) {
  14237. return applyEase(easeOutBez, t, tMin, tMax, val1, val2);
  14238. }
  14239. function easeIn(t, tMin, tMax, val1, val2) {
  14240. return applyEase(easeInBez, t, tMin, tMax, val1, val2);
  14241. }
  14242. function ease(t, tMin, tMax, val1, val2) {
  14243. return applyEase(easeInOutBez, t, tMin, tMax, val1, val2);
  14244. }
  14245. function applyEase(fn, t, tMin, tMax, val1, val2) {
  14246. if (val1 === undefined) {
  14247. val1 = tMin;
  14248. val2 = tMax;
  14249. } else {
  14250. t = (t - tMin) / (tMax - tMin);
  14251. }
  14252. if (t > 1) {
  14253. t = 1;
  14254. } else if (t < 0) {
  14255. t = 0;
  14256. }
  14257. var mult = fn(t);
  14258. if ($bm_isInstanceOfArray(val1)) {
  14259. var iKey;
  14260. var lenKey = val1.length;
  14261. var arr = createTypedArray('float32', lenKey);
  14262. for (iKey = 0; iKey < lenKey; iKey += 1) {
  14263. arr[iKey] = (val2[iKey] - val1[iKey]) * mult + val1[iKey];
  14264. }
  14265. return arr;
  14266. }
  14267. return (val2 - val1) * mult + val1;
  14268. }
  14269. function nearestKey(time) {
  14270. var iKey;
  14271. var lenKey = data.k.length;
  14272. var index;
  14273. var keyTime;
  14274. if (!data.k.length || typeof (data.k[0]) === 'number') {
  14275. index = 0;
  14276. keyTime = 0;
  14277. } else {
  14278. index = -1;
  14279. time *= elem.comp.globalData.frameRate;
  14280. if (time < data.k[0].t) {
  14281. index = 1;
  14282. keyTime = data.k[0].t;
  14283. } else {
  14284. for (iKey = 0; iKey < lenKey - 1; iKey += 1) {
  14285. if (time === data.k[iKey].t) {
  14286. index = iKey + 1;
  14287. keyTime = data.k[iKey].t;
  14288. break;
  14289. } else if (time > data.k[iKey].t && time < data.k[iKey + 1].t) {
  14290. if (time - data.k[iKey].t > data.k[iKey + 1].t - time) {
  14291. index = iKey + 2;
  14292. keyTime = data.k[iKey + 1].t;
  14293. } else {
  14294. index = iKey + 1;
  14295. keyTime = data.k[iKey].t;
  14296. }
  14297. break;
  14298. }
  14299. }
  14300. if (index === -1) {
  14301. index = iKey + 1;
  14302. keyTime = data.k[iKey].t;
  14303. }
  14304. }
  14305. }
  14306. var obKey = {};
  14307. obKey.index = index;
  14308. obKey.time = keyTime / elem.comp.globalData.frameRate;
  14309. return obKey;
  14310. }
  14311. function key(ind) {
  14312. var obKey;
  14313. var iKey;
  14314. var lenKey;
  14315. if (!data.k.length || typeof (data.k[0]) === 'number') {
  14316. throw new Error('The property has no keyframe at index ' + ind);
  14317. }
  14318. ind -= 1;
  14319. obKey = {
  14320. time: data.k[ind].t / elem.comp.globalData.frameRate,
  14321. value: [],
  14322. };
  14323. var arr = Object.prototype.hasOwnProperty.call(data.k[ind], 's') ? data.k[ind].s : data.k[ind - 1].e;
  14324. lenKey = arr.length;
  14325. for (iKey = 0; iKey < lenKey; iKey += 1) {
  14326. obKey[iKey] = arr[iKey];
  14327. obKey.value[iKey] = arr[iKey];
  14328. }
  14329. return obKey;
  14330. }
  14331. function framesToTime(fr, fps) {
  14332. if (!fps) {
  14333. fps = elem.comp.globalData.frameRate;
  14334. }
  14335. return fr / fps;
  14336. }
  14337. function timeToFrames(t, fps) {
  14338. if (!t && t !== 0) {
  14339. t = time;
  14340. }
  14341. if (!fps) {
  14342. fps = elem.comp.globalData.frameRate;
  14343. }
  14344. return t * fps;
  14345. }
  14346. function seedRandom(seed) {
  14347. BMMath.seedrandom(randSeed + seed);
  14348. }
  14349. function sourceRectAtTime() {
  14350. return elem.sourceRectAtTime();
  14351. }
  14352. function substring(init, end) {
  14353. if (typeof value === 'string') {
  14354. if (end === undefined) {
  14355. return value.substring(init);
  14356. }
  14357. return value.substring(init, end);
  14358. }
  14359. return '';
  14360. }
  14361. function substr(init, end) {
  14362. if (typeof value === 'string') {
  14363. if (end === undefined) {
  14364. return value.substr(init);
  14365. }
  14366. return value.substr(init, end);
  14367. }
  14368. return '';
  14369. }
  14370. function posterizeTime(framesPerSecond) {
  14371. time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond;
  14372. value = valueAtTime(time);
  14373. }
  14374. var time;
  14375. var velocity;
  14376. var value;
  14377. var text;
  14378. var textIndex;
  14379. var textTotal;
  14380. var selectorValue;
  14381. var index = elem.data.ind;
  14382. var hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  14383. var parent;
  14384. var randSeed = Math.floor(Math.random() * 1000000);
  14385. var globalData = elem.globalData;
  14386. function executeExpression(_value) {
  14387. // globalData.pushExpression();
  14388. value = _value;
  14389. if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') {
  14390. return value;
  14391. }
  14392. if (this.propType === 'textSelector') {
  14393. textIndex = this.textIndex;
  14394. textTotal = this.textTotal;
  14395. selectorValue = this.selectorValue;
  14396. }
  14397. if (!thisLayer) {
  14398. text = elem.layerInterface.text;
  14399. thisLayer = elem.layerInterface;
  14400. thisComp = elem.comp.compInterface;
  14401. toWorld = thisLayer.toWorld.bind(thisLayer);
  14402. fromWorld = thisLayer.fromWorld.bind(thisLayer);
  14403. fromComp = thisLayer.fromComp.bind(thisLayer);
  14404. toComp = thisLayer.toComp.bind(thisLayer);
  14405. mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null;
  14406. fromCompToSurface = fromComp;
  14407. }
  14408. if (!transform) {
  14409. transform = elem.layerInterface('ADBE Transform Group');
  14410. $bm_transform = transform;
  14411. if (transform) {
  14412. anchorPoint = transform.anchorPoint;
  14413. /* position = transform.position;
  14414. rotation = transform.rotation;
  14415. scale = transform.scale; */
  14416. }
  14417. }
  14418. if (elemType === 4 && !content) {
  14419. content = thisLayer('ADBE Root Vectors Group');
  14420. }
  14421. if (!effect) {
  14422. effect = thisLayer(4);
  14423. }
  14424. hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  14425. if (hasParent && !parent) {
  14426. parent = elem.hierarchy[0].layerInterface;
  14427. }
  14428. time = this.comp.renderedFrame / this.comp.globalData.frameRate;
  14429. if (_needsRandom) {
  14430. seedRandom(randSeed + time);
  14431. }
  14432. if (needsVelocity) {
  14433. velocity = velocityAtTime(time);
  14434. }
  14435. expression_function();
  14436. this.frameExpressionId = elem.globalData.frameId;
  14437. // TODO: Check if it's possible to return on ShapeInterface the .v value
  14438. // Changed this to a ternary operation because Rollup failed compiling it correctly
  14439. scoped_bm_rt = scoped_bm_rt.propType === propTypes.SHAPE
  14440. ? scoped_bm_rt.v
  14441. : scoped_bm_rt;
  14442. return scoped_bm_rt;
  14443. }
  14444. // Bundlers will see these as dead code and unless we reference them
  14445. 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];
  14446. return executeExpression;
  14447. }
  14448. ob.initiateExpression = initiateExpression;
  14449. 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, _lottieGlobal];
  14450. ob.resetFrame = resetFrame;
  14451. return ob;
  14452. }());
  14453. const Expressions = (function () {
  14454. var ob = {};
  14455. ob.initExpressions = initExpressions;
  14456. ob.resetFrame = ExpressionManager.resetFrame;
  14457. function initExpressions(animation) {
  14458. var stackCount = 0;
  14459. var registers = [];
  14460. function pushExpression() {
  14461. stackCount += 1;
  14462. }
  14463. function popExpression() {
  14464. stackCount -= 1;
  14465. if (stackCount === 0) {
  14466. releaseInstances();
  14467. }
  14468. }
  14469. function registerExpressionProperty(expression) {
  14470. if (registers.indexOf(expression) === -1) {
  14471. registers.push(expression);
  14472. }
  14473. }
  14474. function releaseInstances() {
  14475. var i;
  14476. var len = registers.length;
  14477. for (i = 0; i < len; i += 1) {
  14478. registers[i].release();
  14479. }
  14480. registers.length = 0;
  14481. }
  14482. animation.renderer.compInterface = CompExpressionInterface(animation.renderer);
  14483. animation.renderer.globalData.projectInterface.registerComposition(animation.renderer);
  14484. animation.renderer.globalData.pushExpression = pushExpression;
  14485. animation.renderer.globalData.popExpression = popExpression;
  14486. animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty;
  14487. }
  14488. return ob;
  14489. }());
  14490. const MaskManagerInterface = (function () {
  14491. function MaskInterface(mask, data) {
  14492. this._mask = mask;
  14493. this._data = data;
  14494. }
  14495. Object.defineProperty(MaskInterface.prototype, 'maskPath', {
  14496. get: function () {
  14497. if (this._mask.prop.k) {
  14498. this._mask.prop.getValue();
  14499. }
  14500. return this._mask.prop;
  14501. },
  14502. });
  14503. Object.defineProperty(MaskInterface.prototype, 'maskOpacity', {
  14504. get: function () {
  14505. if (this._mask.op.k) {
  14506. this._mask.op.getValue();
  14507. }
  14508. return this._mask.op.v * 100;
  14509. },
  14510. });
  14511. var MaskManager = function (maskManager) {
  14512. var _masksInterfaces = createSizedArray(maskManager.viewData.length);
  14513. var i;
  14514. var len = maskManager.viewData.length;
  14515. for (i = 0; i < len; i += 1) {
  14516. _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]);
  14517. }
  14518. var maskFunction = function (name) {
  14519. i = 0;
  14520. while (i < len) {
  14521. if (maskManager.masksProperties[i].nm === name) {
  14522. return _masksInterfaces[i];
  14523. }
  14524. i += 1;
  14525. }
  14526. return null;
  14527. };
  14528. return maskFunction;
  14529. };
  14530. return MaskManager;
  14531. }());
  14532. const ExpressionPropertyInterface = (function () {
  14533. var defaultUnidimensionalValue = { pv: 0, v: 0, mult: 1 };
  14534. var defaultMultidimensionalValue = { pv: [0, 0, 0], v: [0, 0, 0], mult: 1 };
  14535. function completeProperty(expressionValue, property, type) {
  14536. Object.defineProperty(expressionValue, 'velocity', {
  14537. get: function () {
  14538. return property.getVelocityAtTime(property.comp.currentFrame);
  14539. },
  14540. });
  14541. expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0;
  14542. expressionValue.key = function (pos) {
  14543. if (!expressionValue.numKeys) {
  14544. return 0;
  14545. }
  14546. var value = '';
  14547. if ('s' in property.keyframes[pos - 1]) {
  14548. value = property.keyframes[pos - 1].s;
  14549. } else if ('e' in property.keyframes[pos - 2]) {
  14550. value = property.keyframes[pos - 2].e;
  14551. } else {
  14552. value = property.keyframes[pos - 2].s;
  14553. }
  14554. var valueProp = type === 'unidimensional' ? new Number(value) : Object.assign({}, value); // eslint-disable-line no-new-wrappers
  14555. valueProp.time = property.keyframes[pos - 1].t / property.elem.comp.globalData.frameRate;
  14556. valueProp.value = type === 'unidimensional' ? value[0] : value;
  14557. return valueProp;
  14558. };
  14559. expressionValue.valueAtTime = property.getValueAtTime;
  14560. expressionValue.speedAtTime = property.getSpeedAtTime;
  14561. expressionValue.velocityAtTime = property.getVelocityAtTime;
  14562. expressionValue.propertyGroup = property.propertyGroup;
  14563. }
  14564. function UnidimensionalPropertyInterface(property) {
  14565. if (!property || !('pv' in property)) {
  14566. property = defaultUnidimensionalValue;
  14567. }
  14568. var mult = 1 / property.mult;
  14569. var val = property.pv * mult;
  14570. var expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  14571. expressionValue.value = val;
  14572. completeProperty(expressionValue, property, 'unidimensional');
  14573. return function () {
  14574. if (property.k) {
  14575. property.getValue();
  14576. }
  14577. val = property.v * mult;
  14578. if (expressionValue.value !== val) {
  14579. expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  14580. expressionValue.value = val;
  14581. completeProperty(expressionValue, property, 'unidimensional');
  14582. }
  14583. return expressionValue;
  14584. };
  14585. }
  14586. function MultidimensionalPropertyInterface(property) {
  14587. if (!property || !('pv' in property)) {
  14588. property = defaultMultidimensionalValue;
  14589. }
  14590. var mult = 1 / property.mult;
  14591. var len = (property.data && property.data.l) || property.pv.length;
  14592. var expressionValue = createTypedArray('float32', len);
  14593. var arrValue = createTypedArray('float32', len);
  14594. expressionValue.value = arrValue;
  14595. completeProperty(expressionValue, property, 'multidimensional');
  14596. return function () {
  14597. if (property.k) {
  14598. property.getValue();
  14599. }
  14600. for (var i = 0; i < len; i += 1) {
  14601. arrValue[i] = property.v[i] * mult;
  14602. expressionValue[i] = arrValue[i];
  14603. }
  14604. return expressionValue;
  14605. };
  14606. }
  14607. // TODO: try to avoid using this getter
  14608. function defaultGetter() {
  14609. return defaultUnidimensionalValue;
  14610. }
  14611. return function (property) {
  14612. if (!property) {
  14613. return defaultGetter;
  14614. } if (property.propType === 'unidimensional') {
  14615. return UnidimensionalPropertyInterface(property);
  14616. }
  14617. return MultidimensionalPropertyInterface(property);
  14618. };
  14619. }());
  14620. const TransformExpressionInterface = (function () {
  14621. return function (transform) {
  14622. function _thisFunction(name) {
  14623. switch (name) {
  14624. case 'scale':
  14625. case 'Scale':
  14626. case 'ADBE Scale':
  14627. case 6:
  14628. return _thisFunction.scale;
  14629. case 'rotation':
  14630. case 'Rotation':
  14631. case 'ADBE Rotation':
  14632. case 'ADBE Rotate Z':
  14633. case 10:
  14634. return _thisFunction.rotation;
  14635. case 'ADBE Rotate X':
  14636. return _thisFunction.xRotation;
  14637. case 'ADBE Rotate Y':
  14638. return _thisFunction.yRotation;
  14639. case 'position':
  14640. case 'Position':
  14641. case 'ADBE Position':
  14642. case 2:
  14643. return _thisFunction.position;
  14644. case 'ADBE Position_0':
  14645. return _thisFunction.xPosition;
  14646. case 'ADBE Position_1':
  14647. return _thisFunction.yPosition;
  14648. case 'ADBE Position_2':
  14649. return _thisFunction.zPosition;
  14650. case 'anchorPoint':
  14651. case 'AnchorPoint':
  14652. case 'Anchor Point':
  14653. case 'ADBE AnchorPoint':
  14654. case 1:
  14655. return _thisFunction.anchorPoint;
  14656. case 'opacity':
  14657. case 'Opacity':
  14658. case 11:
  14659. return _thisFunction.opacity;
  14660. default:
  14661. return null;
  14662. }
  14663. }
  14664. Object.defineProperty(_thisFunction, 'rotation', {
  14665. get: ExpressionPropertyInterface(transform.r || transform.rz),
  14666. });
  14667. Object.defineProperty(_thisFunction, 'zRotation', {
  14668. get: ExpressionPropertyInterface(transform.rz || transform.r),
  14669. });
  14670. Object.defineProperty(_thisFunction, 'xRotation', {
  14671. get: ExpressionPropertyInterface(transform.rx),
  14672. });
  14673. Object.defineProperty(_thisFunction, 'yRotation', {
  14674. get: ExpressionPropertyInterface(transform.ry),
  14675. });
  14676. Object.defineProperty(_thisFunction, 'scale', {
  14677. get: ExpressionPropertyInterface(transform.s),
  14678. });
  14679. var _px;
  14680. var _py;
  14681. var _pz;
  14682. var _transformFactory;
  14683. if (transform.p) {
  14684. _transformFactory = ExpressionPropertyInterface(transform.p);
  14685. } else {
  14686. _px = ExpressionPropertyInterface(transform.px);
  14687. _py = ExpressionPropertyInterface(transform.py);
  14688. if (transform.pz) {
  14689. _pz = ExpressionPropertyInterface(transform.pz);
  14690. }
  14691. }
  14692. Object.defineProperty(_thisFunction, 'position', {
  14693. get: function () {
  14694. if (transform.p) {
  14695. return _transformFactory();
  14696. }
  14697. return [
  14698. _px(),
  14699. _py(),
  14700. _pz ? _pz() : 0];
  14701. },
  14702. });
  14703. Object.defineProperty(_thisFunction, 'xPosition', {
  14704. get: ExpressionPropertyInterface(transform.px),
  14705. });
  14706. Object.defineProperty(_thisFunction, 'yPosition', {
  14707. get: ExpressionPropertyInterface(transform.py),
  14708. });
  14709. Object.defineProperty(_thisFunction, 'zPosition', {
  14710. get: ExpressionPropertyInterface(transform.pz),
  14711. });
  14712. Object.defineProperty(_thisFunction, 'anchorPoint', {
  14713. get: ExpressionPropertyInterface(transform.a),
  14714. });
  14715. Object.defineProperty(_thisFunction, 'opacity', {
  14716. get: ExpressionPropertyInterface(transform.o),
  14717. });
  14718. Object.defineProperty(_thisFunction, 'skew', {
  14719. get: ExpressionPropertyInterface(transform.sk),
  14720. });
  14721. Object.defineProperty(_thisFunction, 'skewAxis', {
  14722. get: ExpressionPropertyInterface(transform.sa),
  14723. });
  14724. Object.defineProperty(_thisFunction, 'orientation', {
  14725. get: ExpressionPropertyInterface(transform.or),
  14726. });
  14727. return _thisFunction;
  14728. };
  14729. }());
  14730. const LayerExpressionInterface = (function () {
  14731. function getMatrix(time) {
  14732. var toWorldMat = new Matrix();
  14733. if (time !== undefined) {
  14734. var propMatrix = this._elem.finalTransform.mProp.getValueAtTime(time);
  14735. propMatrix.clone(toWorldMat);
  14736. } else {
  14737. var transformMat = this._elem.finalTransform.mProp;
  14738. transformMat.applyToMatrix(toWorldMat);
  14739. }
  14740. return toWorldMat;
  14741. }
  14742. function toWorldVec(arr, time) {
  14743. var toWorldMat = this.getMatrix(time);
  14744. toWorldMat.props[12] = 0;
  14745. toWorldMat.props[13] = 0;
  14746. toWorldMat.props[14] = 0;
  14747. return this.applyPoint(toWorldMat, arr);
  14748. }
  14749. function toWorld(arr, time) {
  14750. var toWorldMat = this.getMatrix(time);
  14751. return this.applyPoint(toWorldMat, arr);
  14752. }
  14753. function fromWorldVec(arr, time) {
  14754. var toWorldMat = this.getMatrix(time);
  14755. toWorldMat.props[12] = 0;
  14756. toWorldMat.props[13] = 0;
  14757. toWorldMat.props[14] = 0;
  14758. return this.invertPoint(toWorldMat, arr);
  14759. }
  14760. function fromWorld(arr, time) {
  14761. var toWorldMat = this.getMatrix(time);
  14762. return this.invertPoint(toWorldMat, arr);
  14763. }
  14764. function applyPoint(matrix, arr) {
  14765. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  14766. var i;
  14767. var len = this._elem.hierarchy.length;
  14768. for (i = 0; i < len; i += 1) {
  14769. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  14770. }
  14771. }
  14772. return matrix.applyToPointArray(arr[0], arr[1], arr[2] || 0);
  14773. }
  14774. function invertPoint(matrix, arr) {
  14775. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  14776. var i;
  14777. var len = this._elem.hierarchy.length;
  14778. for (i = 0; i < len; i += 1) {
  14779. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  14780. }
  14781. }
  14782. return matrix.inversePoint(arr);
  14783. }
  14784. function fromComp(arr) {
  14785. var toWorldMat = new Matrix();
  14786. toWorldMat.reset();
  14787. this._elem.finalTransform.mProp.applyToMatrix(toWorldMat);
  14788. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  14789. var i;
  14790. var len = this._elem.hierarchy.length;
  14791. for (i = 0; i < len; i += 1) {
  14792. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  14793. }
  14794. return toWorldMat.inversePoint(arr);
  14795. }
  14796. return toWorldMat.inversePoint(arr);
  14797. }
  14798. function sampleImage() {
  14799. return [1, 1, 1, 1];
  14800. }
  14801. return function (elem) {
  14802. var transformInterface;
  14803. function _registerMaskInterface(maskManager) {
  14804. _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem);
  14805. }
  14806. function _registerEffectsInterface(effects) {
  14807. _thisLayerFunction.effect = effects;
  14808. }
  14809. function _thisLayerFunction(name) {
  14810. switch (name) {
  14811. case 'ADBE Root Vectors Group':
  14812. case 'Contents':
  14813. case 2:
  14814. return _thisLayerFunction.shapeInterface;
  14815. case 1:
  14816. case 6:
  14817. case 'Transform':
  14818. case 'transform':
  14819. case 'ADBE Transform Group':
  14820. return transformInterface;
  14821. case 4:
  14822. case 'ADBE Effect Parade':
  14823. case 'effects':
  14824. case 'Effects':
  14825. return _thisLayerFunction.effect;
  14826. case 'ADBE Text Properties':
  14827. return _thisLayerFunction.textInterface;
  14828. default:
  14829. return null;
  14830. }
  14831. }
  14832. _thisLayerFunction.getMatrix = getMatrix;
  14833. _thisLayerFunction.invertPoint = invertPoint;
  14834. _thisLayerFunction.applyPoint = applyPoint;
  14835. _thisLayerFunction.toWorld = toWorld;
  14836. _thisLayerFunction.toWorldVec = toWorldVec;
  14837. _thisLayerFunction.fromWorld = fromWorld;
  14838. _thisLayerFunction.fromWorldVec = fromWorldVec;
  14839. _thisLayerFunction.toComp = toWorld;
  14840. _thisLayerFunction.fromComp = fromComp;
  14841. _thisLayerFunction.sampleImage = sampleImage;
  14842. _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem);
  14843. _thisLayerFunction._elem = elem;
  14844. transformInterface = TransformExpressionInterface(elem.finalTransform.mProp);
  14845. var anchorPointDescriptor = getDescriptor(transformInterface, 'anchorPoint');
  14846. Object.defineProperties(_thisLayerFunction, {
  14847. hasParent: {
  14848. get: function () {
  14849. return elem.hierarchy.length;
  14850. },
  14851. },
  14852. parent: {
  14853. get: function () {
  14854. return elem.hierarchy[0].layerInterface;
  14855. },
  14856. },
  14857. rotation: getDescriptor(transformInterface, 'rotation'),
  14858. scale: getDescriptor(transformInterface, 'scale'),
  14859. position: getDescriptor(transformInterface, 'position'),
  14860. opacity: getDescriptor(transformInterface, 'opacity'),
  14861. anchorPoint: anchorPointDescriptor,
  14862. anchor_point: anchorPointDescriptor,
  14863. transform: {
  14864. get: function () {
  14865. return transformInterface;
  14866. },
  14867. },
  14868. active: {
  14869. get: function () {
  14870. return elem.isInRange;
  14871. },
  14872. },
  14873. });
  14874. _thisLayerFunction.startTime = elem.data.st;
  14875. _thisLayerFunction.index = elem.data.ind;
  14876. _thisLayerFunction.source = elem.data.refId;
  14877. _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100;
  14878. _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100;
  14879. _thisLayerFunction.inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  14880. _thisLayerFunction.outPoint = elem.data.op / elem.comp.globalData.frameRate;
  14881. _thisLayerFunction._name = elem.data.nm;
  14882. _thisLayerFunction.registerMaskInterface = _registerMaskInterface;
  14883. _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface;
  14884. return _thisLayerFunction;
  14885. };
  14886. }());
  14887. const propertyGroupFactory = (function () {
  14888. return function (interfaceFunction, parentPropertyGroup) {
  14889. return function (val) {
  14890. val = val === undefined ? 1 : val;
  14891. if (val <= 0) {
  14892. return interfaceFunction;
  14893. }
  14894. return parentPropertyGroup(val - 1);
  14895. };
  14896. };
  14897. }());
  14898. const PropertyInterface = (function () {
  14899. return function (propertyName, propertyGroup) {
  14900. var interfaceFunction = {
  14901. _name: propertyName,
  14902. };
  14903. function _propertyGroup(val) {
  14904. val = val === undefined ? 1 : val;
  14905. if (val <= 0) {
  14906. return interfaceFunction;
  14907. }
  14908. return propertyGroup(val - 1);
  14909. }
  14910. return _propertyGroup;
  14911. };
  14912. }());
  14913. const EffectsExpressionInterface = (function () {
  14914. var ob = {
  14915. createEffectsInterface: createEffectsInterface,
  14916. };
  14917. function createEffectsInterface(elem, propertyGroup) {
  14918. if (elem.effectsManager) {
  14919. var effectElements = [];
  14920. var effectsData = elem.data.ef;
  14921. var i;
  14922. var len = elem.effectsManager.effectElements.length;
  14923. for (i = 0; i < len; i += 1) {
  14924. effectElements.push(createGroupInterface(effectsData[i], elem.effectsManager.effectElements[i], propertyGroup, elem));
  14925. }
  14926. var effects = elem.data.ef || [];
  14927. var groupInterface = function (name) {
  14928. i = 0;
  14929. len = effects.length;
  14930. while (i < len) {
  14931. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  14932. return effectElements[i];
  14933. }
  14934. i += 1;
  14935. }
  14936. return null;
  14937. };
  14938. Object.defineProperty(groupInterface, 'numProperties', {
  14939. get: function () {
  14940. return effects.length;
  14941. },
  14942. });
  14943. return groupInterface;
  14944. }
  14945. return null;
  14946. }
  14947. function createGroupInterface(data, elements, propertyGroup, elem) {
  14948. function groupInterface(name) {
  14949. var effects = data.ef;
  14950. var i = 0;
  14951. var len = effects.length;
  14952. while (i < len) {
  14953. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  14954. if (effects[i].ty === 5) {
  14955. return effectElements[i];
  14956. }
  14957. return effectElements[i]();
  14958. }
  14959. i += 1;
  14960. }
  14961. throw new Error();
  14962. }
  14963. var _propertyGroup = propertyGroupFactory(groupInterface, propertyGroup);
  14964. var effectElements = [];
  14965. var i;
  14966. var len = data.ef.length;
  14967. for (i = 0; i < len; i += 1) {
  14968. if (data.ef[i].ty === 5) {
  14969. effectElements.push(createGroupInterface(data.ef[i], elements.effectElements[i], elements.effectElements[i].propertyGroup, elem));
  14970. } else {
  14971. effectElements.push(createValueInterface(elements.effectElements[i], data.ef[i].ty, elem, _propertyGroup));
  14972. }
  14973. }
  14974. if (data.mn === 'ADBE Color Control') {
  14975. Object.defineProperty(groupInterface, 'color', {
  14976. get: function () {
  14977. return effectElements[0]();
  14978. },
  14979. });
  14980. }
  14981. Object.defineProperties(groupInterface, {
  14982. numProperties: {
  14983. get: function () {
  14984. return data.np;
  14985. },
  14986. },
  14987. _name: { value: data.nm },
  14988. propertyGroup: { value: _propertyGroup },
  14989. });
  14990. groupInterface.enabled = data.en !== 0;
  14991. groupInterface.active = groupInterface.enabled;
  14992. return groupInterface;
  14993. }
  14994. function createValueInterface(element, type, elem, propertyGroup) {
  14995. var expressionProperty = ExpressionPropertyInterface(element.p);
  14996. function interfaceFunction() {
  14997. if (type === 10) {
  14998. return elem.comp.compInterface(element.p.v);
  14999. }
  15000. return expressionProperty();
  15001. }
  15002. if (element.p.setGroupProperty) {
  15003. element.p.setGroupProperty(PropertyInterface('', propertyGroup));
  15004. }
  15005. return interfaceFunction;
  15006. }
  15007. return ob;
  15008. }());
  15009. const ShapePathInterface = (
  15010. function () {
  15011. return function pathInterfaceFactory(shape, view, propertyGroup) {
  15012. var prop = view.sh;
  15013. function interfaceFunction(val) {
  15014. if (val === 'Shape' || val === 'shape' || val === 'Path' || val === 'path' || val === 'ADBE Vector Shape' || val === 2) {
  15015. return interfaceFunction.path;
  15016. }
  15017. return null;
  15018. }
  15019. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15020. prop.setGroupProperty(PropertyInterface('Path', _propertyGroup));
  15021. Object.defineProperties(interfaceFunction, {
  15022. path: {
  15023. get: function () {
  15024. if (prop.k) {
  15025. prop.getValue();
  15026. }
  15027. return prop;
  15028. },
  15029. },
  15030. shape: {
  15031. get: function () {
  15032. if (prop.k) {
  15033. prop.getValue();
  15034. }
  15035. return prop;
  15036. },
  15037. },
  15038. _name: { value: shape.nm },
  15039. ix: { value: shape.ix },
  15040. propertyIndex: { value: shape.ix },
  15041. mn: { value: shape.mn },
  15042. propertyGroup: { value: propertyGroup },
  15043. });
  15044. return interfaceFunction;
  15045. };
  15046. }()
  15047. );
  15048. const ShapeExpressionInterface = (function () {
  15049. function iterateElements(shapes, view, propertyGroup) {
  15050. var arr = [];
  15051. var i;
  15052. var len = shapes ? shapes.length : 0;
  15053. for (i = 0; i < len; i += 1) {
  15054. if (shapes[i].ty === 'gr') {
  15055. arr.push(groupInterfaceFactory(shapes[i], view[i], propertyGroup));
  15056. } else if (shapes[i].ty === 'fl') {
  15057. arr.push(fillInterfaceFactory(shapes[i], view[i], propertyGroup));
  15058. } else if (shapes[i].ty === 'st') {
  15059. arr.push(strokeInterfaceFactory(shapes[i], view[i], propertyGroup));
  15060. } else if (shapes[i].ty === 'tm') {
  15061. arr.push(trimInterfaceFactory(shapes[i], view[i], propertyGroup));
  15062. } else if (shapes[i].ty === 'tr') {
  15063. // arr.push(transformInterfaceFactory(shapes[i],view[i],propertyGroup));
  15064. } else if (shapes[i].ty === 'el') {
  15065. arr.push(ellipseInterfaceFactory(shapes[i], view[i], propertyGroup));
  15066. } else if (shapes[i].ty === 'sr') {
  15067. arr.push(starInterfaceFactory(shapes[i], view[i], propertyGroup));
  15068. } else if (shapes[i].ty === 'sh') {
  15069. arr.push(ShapePathInterface(shapes[i], view[i], propertyGroup));
  15070. } else if (shapes[i].ty === 'rc') {
  15071. arr.push(rectInterfaceFactory(shapes[i], view[i], propertyGroup));
  15072. } else if (shapes[i].ty === 'rd') {
  15073. arr.push(roundedInterfaceFactory(shapes[i], view[i], propertyGroup));
  15074. } else if (shapes[i].ty === 'rp') {
  15075. arr.push(repeaterInterfaceFactory(shapes[i], view[i], propertyGroup));
  15076. } else if (shapes[i].ty === 'gf') {
  15077. arr.push(gradientFillInterfaceFactory(shapes[i], view[i], propertyGroup));
  15078. } else {
  15079. arr.push(defaultInterfaceFactory(shapes[i], view[i], propertyGroup));
  15080. }
  15081. }
  15082. return arr;
  15083. }
  15084. function contentsInterfaceFactory(shape, view, propertyGroup) {
  15085. var interfaces;
  15086. var interfaceFunction = function _interfaceFunction(value) {
  15087. var i = 0;
  15088. var len = interfaces.length;
  15089. while (i < len) {
  15090. if (interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value) {
  15091. return interfaces[i];
  15092. }
  15093. i += 1;
  15094. }
  15095. if (typeof value === 'number') {
  15096. return interfaces[value - 1];
  15097. }
  15098. return null;
  15099. };
  15100. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15101. interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup);
  15102. interfaceFunction.numProperties = interfaces.length;
  15103. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  15104. interfaceFunction.transform = transformInterface;
  15105. interfaceFunction.propertyIndex = shape.cix;
  15106. interfaceFunction._name = shape.nm;
  15107. return interfaceFunction;
  15108. }
  15109. function groupInterfaceFactory(shape, view, propertyGroup) {
  15110. var interfaceFunction = function _interfaceFunction(value) {
  15111. switch (value) {
  15112. case 'ADBE Vectors Group':
  15113. case 'Contents':
  15114. case 2:
  15115. return interfaceFunction.content;
  15116. // Not necessary for now. Keeping them here in case a new case appears
  15117. // case 'ADBE Vector Transform Group':
  15118. // case 3:
  15119. default:
  15120. return interfaceFunction.transform;
  15121. }
  15122. };
  15123. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15124. var content = contentsInterfaceFactory(shape, view, interfaceFunction.propertyGroup);
  15125. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  15126. interfaceFunction.content = content;
  15127. interfaceFunction.transform = transformInterface;
  15128. Object.defineProperty(interfaceFunction, '_name', {
  15129. get: function () {
  15130. return shape.nm;
  15131. },
  15132. });
  15133. // interfaceFunction.content = interfaceFunction;
  15134. interfaceFunction.numProperties = shape.np;
  15135. interfaceFunction.propertyIndex = shape.ix;
  15136. interfaceFunction.nm = shape.nm;
  15137. interfaceFunction.mn = shape.mn;
  15138. return interfaceFunction;
  15139. }
  15140. function fillInterfaceFactory(shape, view, propertyGroup) {
  15141. function interfaceFunction(val) {
  15142. if (val === 'Color' || val === 'color') {
  15143. return interfaceFunction.color;
  15144. } if (val === 'Opacity' || val === 'opacity') {
  15145. return interfaceFunction.opacity;
  15146. }
  15147. return null;
  15148. }
  15149. Object.defineProperties(interfaceFunction, {
  15150. color: {
  15151. get: ExpressionPropertyInterface(view.c),
  15152. },
  15153. opacity: {
  15154. get: ExpressionPropertyInterface(view.o),
  15155. },
  15156. _name: { value: shape.nm },
  15157. mn: { value: shape.mn },
  15158. });
  15159. view.c.setGroupProperty(PropertyInterface('Color', propertyGroup));
  15160. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  15161. return interfaceFunction;
  15162. }
  15163. function gradientFillInterfaceFactory(shape, view, propertyGroup) {
  15164. function interfaceFunction(val) {
  15165. if (val === 'Start Point' || val === 'start point') {
  15166. return interfaceFunction.startPoint;
  15167. }
  15168. if (val === 'End Point' || val === 'end point') {
  15169. return interfaceFunction.endPoint;
  15170. }
  15171. if (val === 'Opacity' || val === 'opacity') {
  15172. return interfaceFunction.opacity;
  15173. }
  15174. return null;
  15175. }
  15176. Object.defineProperties(interfaceFunction, {
  15177. startPoint: {
  15178. get: ExpressionPropertyInterface(view.s),
  15179. },
  15180. endPoint: {
  15181. get: ExpressionPropertyInterface(view.e),
  15182. },
  15183. opacity: {
  15184. get: ExpressionPropertyInterface(view.o),
  15185. },
  15186. type: {
  15187. get: function () {
  15188. return 'a';
  15189. },
  15190. },
  15191. _name: { value: shape.nm },
  15192. mn: { value: shape.mn },
  15193. });
  15194. view.s.setGroupProperty(PropertyInterface('Start Point', propertyGroup));
  15195. view.e.setGroupProperty(PropertyInterface('End Point', propertyGroup));
  15196. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  15197. return interfaceFunction;
  15198. }
  15199. function defaultInterfaceFactory() {
  15200. function interfaceFunction() {
  15201. return null;
  15202. }
  15203. return interfaceFunction;
  15204. }
  15205. function strokeInterfaceFactory(shape, view, propertyGroup) {
  15206. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15207. var _dashPropertyGroup = propertyGroupFactory(dashOb, _propertyGroup);
  15208. function addPropertyToDashOb(i) {
  15209. Object.defineProperty(dashOb, shape.d[i].nm, {
  15210. get: ExpressionPropertyInterface(view.d.dataProps[i].p),
  15211. });
  15212. }
  15213. var i;
  15214. var len = shape.d ? shape.d.length : 0;
  15215. var dashOb = {};
  15216. for (i = 0; i < len; i += 1) {
  15217. addPropertyToDashOb(i);
  15218. view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup);
  15219. }
  15220. function interfaceFunction(val) {
  15221. if (val === 'Color' || val === 'color') {
  15222. return interfaceFunction.color;
  15223. } if (val === 'Opacity' || val === 'opacity') {
  15224. return interfaceFunction.opacity;
  15225. } if (val === 'Stroke Width' || val === 'stroke width') {
  15226. return interfaceFunction.strokeWidth;
  15227. }
  15228. return null;
  15229. }
  15230. Object.defineProperties(interfaceFunction, {
  15231. color: {
  15232. get: ExpressionPropertyInterface(view.c),
  15233. },
  15234. opacity: {
  15235. get: ExpressionPropertyInterface(view.o),
  15236. },
  15237. strokeWidth: {
  15238. get: ExpressionPropertyInterface(view.w),
  15239. },
  15240. dash: {
  15241. get: function () {
  15242. return dashOb;
  15243. },
  15244. },
  15245. _name: { value: shape.nm },
  15246. mn: { value: shape.mn },
  15247. });
  15248. view.c.setGroupProperty(PropertyInterface('Color', _propertyGroup));
  15249. view.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  15250. view.w.setGroupProperty(PropertyInterface('Stroke Width', _propertyGroup));
  15251. return interfaceFunction;
  15252. }
  15253. function trimInterfaceFactory(shape, view, propertyGroup) {
  15254. function interfaceFunction(val) {
  15255. if (val === shape.e.ix || val === 'End' || val === 'end') {
  15256. return interfaceFunction.end;
  15257. }
  15258. if (val === shape.s.ix) {
  15259. return interfaceFunction.start;
  15260. }
  15261. if (val === shape.o.ix) {
  15262. return interfaceFunction.offset;
  15263. }
  15264. return null;
  15265. }
  15266. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15267. interfaceFunction.propertyIndex = shape.ix;
  15268. view.s.setGroupProperty(PropertyInterface('Start', _propertyGroup));
  15269. view.e.setGroupProperty(PropertyInterface('End', _propertyGroup));
  15270. view.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  15271. interfaceFunction.propertyIndex = shape.ix;
  15272. interfaceFunction.propertyGroup = propertyGroup;
  15273. Object.defineProperties(interfaceFunction, {
  15274. start: {
  15275. get: ExpressionPropertyInterface(view.s),
  15276. },
  15277. end: {
  15278. get: ExpressionPropertyInterface(view.e),
  15279. },
  15280. offset: {
  15281. get: ExpressionPropertyInterface(view.o),
  15282. },
  15283. _name: { value: shape.nm },
  15284. });
  15285. interfaceFunction.mn = shape.mn;
  15286. return interfaceFunction;
  15287. }
  15288. function transformInterfaceFactory(shape, view, propertyGroup) {
  15289. function interfaceFunction(value) {
  15290. if (shape.a.ix === value || value === 'Anchor Point') {
  15291. return interfaceFunction.anchorPoint;
  15292. }
  15293. if (shape.o.ix === value || value === 'Opacity') {
  15294. return interfaceFunction.opacity;
  15295. }
  15296. if (shape.p.ix === value || value === 'Position') {
  15297. return interfaceFunction.position;
  15298. }
  15299. if (shape.r.ix === value || value === 'Rotation' || value === 'ADBE Vector Rotation') {
  15300. return interfaceFunction.rotation;
  15301. }
  15302. if (shape.s.ix === value || value === 'Scale') {
  15303. return interfaceFunction.scale;
  15304. }
  15305. if ((shape.sk && shape.sk.ix === value) || value === 'Skew') {
  15306. return interfaceFunction.skew;
  15307. }
  15308. if ((shape.sa && shape.sa.ix === value) || value === 'Skew Axis') {
  15309. return interfaceFunction.skewAxis;
  15310. }
  15311. return null;
  15312. }
  15313. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15314. view.transform.mProps.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  15315. view.transform.mProps.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  15316. view.transform.mProps.a.setGroupProperty(PropertyInterface('Anchor Point', _propertyGroup));
  15317. view.transform.mProps.s.setGroupProperty(PropertyInterface('Scale', _propertyGroup));
  15318. view.transform.mProps.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  15319. if (view.transform.mProps.sk) {
  15320. view.transform.mProps.sk.setGroupProperty(PropertyInterface('Skew', _propertyGroup));
  15321. view.transform.mProps.sa.setGroupProperty(PropertyInterface('Skew Angle', _propertyGroup));
  15322. }
  15323. view.transform.op.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  15324. Object.defineProperties(interfaceFunction, {
  15325. opacity: {
  15326. get: ExpressionPropertyInterface(view.transform.mProps.o),
  15327. },
  15328. position: {
  15329. get: ExpressionPropertyInterface(view.transform.mProps.p),
  15330. },
  15331. anchorPoint: {
  15332. get: ExpressionPropertyInterface(view.transform.mProps.a),
  15333. },
  15334. scale: {
  15335. get: ExpressionPropertyInterface(view.transform.mProps.s),
  15336. },
  15337. rotation: {
  15338. get: ExpressionPropertyInterface(view.transform.mProps.r),
  15339. },
  15340. skew: {
  15341. get: ExpressionPropertyInterface(view.transform.mProps.sk),
  15342. },
  15343. skewAxis: {
  15344. get: ExpressionPropertyInterface(view.transform.mProps.sa),
  15345. },
  15346. _name: { value: shape.nm },
  15347. });
  15348. interfaceFunction.ty = 'tr';
  15349. interfaceFunction.mn = shape.mn;
  15350. interfaceFunction.propertyGroup = propertyGroup;
  15351. return interfaceFunction;
  15352. }
  15353. function ellipseInterfaceFactory(shape, view, propertyGroup) {
  15354. function interfaceFunction(value) {
  15355. if (shape.p.ix === value) {
  15356. return interfaceFunction.position;
  15357. }
  15358. if (shape.s.ix === value) {
  15359. return interfaceFunction.size;
  15360. }
  15361. return null;
  15362. }
  15363. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15364. interfaceFunction.propertyIndex = shape.ix;
  15365. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  15366. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  15367. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  15368. Object.defineProperties(interfaceFunction, {
  15369. size: {
  15370. get: ExpressionPropertyInterface(prop.s),
  15371. },
  15372. position: {
  15373. get: ExpressionPropertyInterface(prop.p),
  15374. },
  15375. _name: { value: shape.nm },
  15376. });
  15377. interfaceFunction.mn = shape.mn;
  15378. return interfaceFunction;
  15379. }
  15380. function starInterfaceFactory(shape, view, propertyGroup) {
  15381. function interfaceFunction(value) {
  15382. if (shape.p.ix === value) {
  15383. return interfaceFunction.position;
  15384. }
  15385. if (shape.r.ix === value) {
  15386. return interfaceFunction.rotation;
  15387. }
  15388. if (shape.pt.ix === value) {
  15389. return interfaceFunction.points;
  15390. }
  15391. if (shape.or.ix === value || value === 'ADBE Vector Star Outer Radius') {
  15392. return interfaceFunction.outerRadius;
  15393. }
  15394. if (shape.os.ix === value) {
  15395. return interfaceFunction.outerRoundness;
  15396. }
  15397. if (shape.ir && (shape.ir.ix === value || value === 'ADBE Vector Star Inner Radius')) {
  15398. return interfaceFunction.innerRadius;
  15399. }
  15400. if (shape.is && shape.is.ix === value) {
  15401. return interfaceFunction.innerRoundness;
  15402. }
  15403. return null;
  15404. }
  15405. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15406. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  15407. interfaceFunction.propertyIndex = shape.ix;
  15408. prop.or.setGroupProperty(PropertyInterface('Outer Radius', _propertyGroup));
  15409. prop.os.setGroupProperty(PropertyInterface('Outer Roundness', _propertyGroup));
  15410. prop.pt.setGroupProperty(PropertyInterface('Points', _propertyGroup));
  15411. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  15412. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  15413. if (shape.ir) {
  15414. prop.ir.setGroupProperty(PropertyInterface('Inner Radius', _propertyGroup));
  15415. prop.is.setGroupProperty(PropertyInterface('Inner Roundness', _propertyGroup));
  15416. }
  15417. Object.defineProperties(interfaceFunction, {
  15418. position: {
  15419. get: ExpressionPropertyInterface(prop.p),
  15420. },
  15421. rotation: {
  15422. get: ExpressionPropertyInterface(prop.r),
  15423. },
  15424. points: {
  15425. get: ExpressionPropertyInterface(prop.pt),
  15426. },
  15427. outerRadius: {
  15428. get: ExpressionPropertyInterface(prop.or),
  15429. },
  15430. outerRoundness: {
  15431. get: ExpressionPropertyInterface(prop.os),
  15432. },
  15433. innerRadius: {
  15434. get: ExpressionPropertyInterface(prop.ir),
  15435. },
  15436. innerRoundness: {
  15437. get: ExpressionPropertyInterface(prop.is),
  15438. },
  15439. _name: { value: shape.nm },
  15440. });
  15441. interfaceFunction.mn = shape.mn;
  15442. return interfaceFunction;
  15443. }
  15444. function rectInterfaceFactory(shape, view, propertyGroup) {
  15445. function interfaceFunction(value) {
  15446. if (shape.p.ix === value) {
  15447. return interfaceFunction.position;
  15448. }
  15449. if (shape.r.ix === value) {
  15450. return interfaceFunction.roundness;
  15451. }
  15452. if (shape.s.ix === value || value === 'Size' || value === 'ADBE Vector Rect Size') {
  15453. return interfaceFunction.size;
  15454. }
  15455. return null;
  15456. }
  15457. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15458. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  15459. interfaceFunction.propertyIndex = shape.ix;
  15460. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  15461. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  15462. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  15463. Object.defineProperties(interfaceFunction, {
  15464. position: {
  15465. get: ExpressionPropertyInterface(prop.p),
  15466. },
  15467. roundness: {
  15468. get: ExpressionPropertyInterface(prop.r),
  15469. },
  15470. size: {
  15471. get: ExpressionPropertyInterface(prop.s),
  15472. },
  15473. _name: { value: shape.nm },
  15474. });
  15475. interfaceFunction.mn = shape.mn;
  15476. return interfaceFunction;
  15477. }
  15478. function roundedInterfaceFactory(shape, view, propertyGroup) {
  15479. function interfaceFunction(value) {
  15480. if (shape.r.ix === value || value === 'Round Corners 1') {
  15481. return interfaceFunction.radius;
  15482. }
  15483. return null;
  15484. }
  15485. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15486. var prop = view;
  15487. interfaceFunction.propertyIndex = shape.ix;
  15488. prop.rd.setGroupProperty(PropertyInterface('Radius', _propertyGroup));
  15489. Object.defineProperties(interfaceFunction, {
  15490. radius: {
  15491. get: ExpressionPropertyInterface(prop.rd),
  15492. },
  15493. _name: { value: shape.nm },
  15494. });
  15495. interfaceFunction.mn = shape.mn;
  15496. return interfaceFunction;
  15497. }
  15498. function repeaterInterfaceFactory(shape, view, propertyGroup) {
  15499. function interfaceFunction(value) {
  15500. if (shape.c.ix === value || value === 'Copies') {
  15501. return interfaceFunction.copies;
  15502. } if (shape.o.ix === value || value === 'Offset') {
  15503. return interfaceFunction.offset;
  15504. }
  15505. return null;
  15506. }
  15507. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  15508. var prop = view;
  15509. interfaceFunction.propertyIndex = shape.ix;
  15510. prop.c.setGroupProperty(PropertyInterface('Copies', _propertyGroup));
  15511. prop.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  15512. Object.defineProperties(interfaceFunction, {
  15513. copies: {
  15514. get: ExpressionPropertyInterface(prop.c),
  15515. },
  15516. offset: {
  15517. get: ExpressionPropertyInterface(prop.o),
  15518. },
  15519. _name: { value: shape.nm },
  15520. });
  15521. interfaceFunction.mn = shape.mn;
  15522. return interfaceFunction;
  15523. }
  15524. return function (shapes, view, propertyGroup) {
  15525. var interfaces;
  15526. function _interfaceFunction(value) {
  15527. if (typeof value === 'number') {
  15528. value = value === undefined ? 1 : value;
  15529. if (value === 0) {
  15530. return propertyGroup;
  15531. }
  15532. return interfaces[value - 1];
  15533. }
  15534. var i = 0;
  15535. var len = interfaces.length;
  15536. while (i < len) {
  15537. if (interfaces[i]._name === value) {
  15538. return interfaces[i];
  15539. }
  15540. i += 1;
  15541. }
  15542. return null;
  15543. }
  15544. function parentGroupWrapper() {
  15545. return propertyGroup;
  15546. }
  15547. _interfaceFunction.propertyGroup = propertyGroupFactory(_interfaceFunction, parentGroupWrapper);
  15548. interfaces = iterateElements(shapes, view, _interfaceFunction.propertyGroup);
  15549. _interfaceFunction.numProperties = interfaces.length;
  15550. _interfaceFunction._name = 'Contents';
  15551. return _interfaceFunction;
  15552. };
  15553. }());
  15554. const TextExpressionInterface = (function () {
  15555. return function (elem) {
  15556. var _sourceText;
  15557. function _thisLayerFunction(name) {
  15558. switch (name) {
  15559. case 'ADBE Text Document':
  15560. return _thisLayerFunction.sourceText;
  15561. default:
  15562. return null;
  15563. }
  15564. }
  15565. Object.defineProperty(_thisLayerFunction, 'sourceText', {
  15566. get: function () {
  15567. elem.textProperty.getValue();
  15568. var stringValue = elem.textProperty.currentData.t;
  15569. if (!_sourceText || stringValue !== _sourceText.value) {
  15570. _sourceText = new String(stringValue); // eslint-disable-line no-new-wrappers
  15571. // If stringValue is an empty string, eval returns undefined, so it has to be returned as a String primitive
  15572. _sourceText.value = stringValue || new String(stringValue); // eslint-disable-line no-new-wrappers
  15573. Object.defineProperty(_sourceText, 'style', {
  15574. get: function () {
  15575. return {
  15576. fillColor: elem.textProperty.currentData.fc,
  15577. };
  15578. },
  15579. });
  15580. }
  15581. return _sourceText;
  15582. },
  15583. });
  15584. return _thisLayerFunction;
  15585. };
  15586. }());
  15587. const FootageInterface = (function () {
  15588. var outlineInterfaceFactory = (function (elem) {
  15589. var currentPropertyName = '';
  15590. var currentProperty = elem.getFootageData();
  15591. function init() {
  15592. currentPropertyName = '';
  15593. currentProperty = elem.getFootageData();
  15594. return searchProperty;
  15595. }
  15596. function searchProperty(value) {
  15597. if (currentProperty[value]) {
  15598. currentPropertyName = value;
  15599. currentProperty = currentProperty[value];
  15600. if (typeof currentProperty === 'object') {
  15601. return searchProperty;
  15602. }
  15603. return currentProperty;
  15604. }
  15605. var propertyNameIndex = value.indexOf(currentPropertyName);
  15606. if (propertyNameIndex !== -1) {
  15607. var index = parseInt(value.substr(propertyNameIndex + currentPropertyName.length), 10);
  15608. currentProperty = currentProperty[index];
  15609. if (typeof currentProperty === 'object') {
  15610. return searchProperty;
  15611. }
  15612. return currentProperty;
  15613. }
  15614. return '';
  15615. }
  15616. return init;
  15617. });
  15618. var dataInterfaceFactory = function (elem) {
  15619. function interfaceFunction(value) {
  15620. if (value === 'Outline') {
  15621. return interfaceFunction.outlineInterface();
  15622. }
  15623. return null;
  15624. }
  15625. interfaceFunction._name = 'Outline';
  15626. interfaceFunction.outlineInterface = outlineInterfaceFactory(elem);
  15627. return interfaceFunction;
  15628. };
  15629. return function (elem) {
  15630. function _interfaceFunction(value) {
  15631. if (value === 'Data') {
  15632. return _interfaceFunction.dataInterface;
  15633. }
  15634. return null;
  15635. }
  15636. _interfaceFunction._name = 'Data';
  15637. _interfaceFunction.dataInterface = dataInterfaceFactory(elem);
  15638. return _interfaceFunction;
  15639. };
  15640. }());
  15641. var interfaces = {
  15642. layer: LayerExpressionInterface,
  15643. effects: EffectsExpressionInterface,
  15644. comp: CompExpressionInterface,
  15645. shape: ShapeExpressionInterface,
  15646. text: TextExpressionInterface,
  15647. footage: FootageInterface,
  15648. };
  15649. function getInterface(type) {
  15650. return interfaces[type] || null;
  15651. }
  15652. const expressionHelpers = (function () {
  15653. function searchExpressions(elem, data, prop) {
  15654. if (data.x) {
  15655. prop.k = true;
  15656. prop.x = true;
  15657. prop.initiateExpression = ExpressionManager.initiateExpression;
  15658. prop.effectsSequence.push(prop.initiateExpression(elem, data, prop).bind(prop));
  15659. }
  15660. }
  15661. function getValueAtTime(frameNum) {
  15662. frameNum *= this.elem.globalData.frameRate;
  15663. frameNum -= this.offsetTime;
  15664. if (frameNum !== this._cachingAtTime.lastFrame) {
  15665. this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
  15666. this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
  15667. this._cachingAtTime.lastFrame = frameNum;
  15668. }
  15669. return this._cachingAtTime.value;
  15670. }
  15671. function getSpeedAtTime(frameNum) {
  15672. var delta = -0.01;
  15673. var v1 = this.getValueAtTime(frameNum);
  15674. var v2 = this.getValueAtTime(frameNum + delta);
  15675. var speed = 0;
  15676. if (v1.length) {
  15677. var i;
  15678. for (i = 0; i < v1.length; i += 1) {
  15679. speed += Math.pow(v2[i] - v1[i], 2);
  15680. }
  15681. speed = Math.sqrt(speed) * 100;
  15682. } else {
  15683. speed = 0;
  15684. }
  15685. return speed;
  15686. }
  15687. function getVelocityAtTime(frameNum) {
  15688. if (this.vel !== undefined) {
  15689. return this.vel;
  15690. }
  15691. var delta = -0.001;
  15692. // frameNum += this.elem.data.st;
  15693. var v1 = this.getValueAtTime(frameNum);
  15694. var v2 = this.getValueAtTime(frameNum + delta);
  15695. var velocity;
  15696. if (v1.length) {
  15697. velocity = createTypedArray('float32', v1.length);
  15698. var i;
  15699. for (i = 0; i < v1.length; i += 1) {
  15700. // removing frameRate
  15701. // if needed, don't add it here
  15702. // velocity[i] = this.elem.globalData.frameRate*((v2[i] - v1[i])/delta);
  15703. velocity[i] = (v2[i] - v1[i]) / delta;
  15704. }
  15705. } else {
  15706. velocity = (v2 - v1) / delta;
  15707. }
  15708. return velocity;
  15709. }
  15710. function getStaticValueAtTime() {
  15711. return this.pv;
  15712. }
  15713. function setGroupProperty(propertyGroup) {
  15714. this.propertyGroup = propertyGroup;
  15715. }
  15716. return {
  15717. searchExpressions: searchExpressions,
  15718. getSpeedAtTime: getSpeedAtTime,
  15719. getVelocityAtTime: getVelocityAtTime,
  15720. getValueAtTime: getValueAtTime,
  15721. getStaticValueAtTime: getStaticValueAtTime,
  15722. setGroupProperty: setGroupProperty,
  15723. };
  15724. }());
  15725. function addPropertyDecorator() {
  15726. function loopOut(type, duration, durationFlag) {
  15727. if (!this.k || !this.keyframes) {
  15728. return this.pv;
  15729. }
  15730. type = type ? type.toLowerCase() : '';
  15731. var currentFrame = this.comp.renderedFrame;
  15732. var keyframes = this.keyframes;
  15733. var lastKeyFrame = keyframes[keyframes.length - 1].t;
  15734. if (currentFrame <= lastKeyFrame) {
  15735. return this.pv;
  15736. }
  15737. var cycleDuration;
  15738. var firstKeyFrame;
  15739. if (!durationFlag) {
  15740. if (!duration || duration > keyframes.length - 1) {
  15741. duration = keyframes.length - 1;
  15742. }
  15743. firstKeyFrame = keyframes[keyframes.length - 1 - duration].t;
  15744. cycleDuration = lastKeyFrame - firstKeyFrame;
  15745. } else {
  15746. if (!duration) {
  15747. cycleDuration = Math.max(0, lastKeyFrame - this.elem.data.ip);
  15748. } else {
  15749. cycleDuration = Math.abs(lastKeyFrame - this.elem.comp.globalData.frameRate * duration);
  15750. }
  15751. firstKeyFrame = lastKeyFrame - cycleDuration;
  15752. }
  15753. var i;
  15754. var len;
  15755. var ret;
  15756. if (type === 'pingpong') {
  15757. var iterations = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  15758. if (iterations % 2 !== 0) {
  15759. return this.getValueAtTime(((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  15760. }
  15761. } else if (type === 'offset') {
  15762. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  15763. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  15764. var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  15765. var repeats = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  15766. if (this.pv.length) {
  15767. ret = new Array(initV.length);
  15768. len = ret.length;
  15769. for (i = 0; i < len; i += 1) {
  15770. ret[i] = (endV[i] - initV[i]) * repeats + current[i];
  15771. }
  15772. return ret;
  15773. }
  15774. return (endV - initV) * repeats + current;
  15775. } else if (type === 'continue') {
  15776. var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  15777. var nextLastValue = this.getValueAtTime((lastKeyFrame - 0.001) / this.comp.globalData.frameRate, 0);
  15778. if (this.pv.length) {
  15779. ret = new Array(lastValue.length);
  15780. len = ret.length;
  15781. for (i = 0; i < len; i += 1) {
  15782. ret[i] = lastValue[i] + (lastValue[i] - nextLastValue[i]) * ((currentFrame - lastKeyFrame) / this.comp.globalData.frameRate) / 0.0005; // eslint-disable-line
  15783. }
  15784. return ret;
  15785. }
  15786. return lastValue + (lastValue - nextLastValue) * (((currentFrame - lastKeyFrame)) / 0.001);
  15787. }
  15788. return this.getValueAtTime((((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  15789. }
  15790. function loopIn(type, duration, durationFlag) {
  15791. if (!this.k) {
  15792. return this.pv;
  15793. }
  15794. type = type ? type.toLowerCase() : '';
  15795. var currentFrame = this.comp.renderedFrame;
  15796. var keyframes = this.keyframes;
  15797. var firstKeyFrame = keyframes[0].t;
  15798. if (currentFrame >= firstKeyFrame) {
  15799. return this.pv;
  15800. }
  15801. var cycleDuration;
  15802. var lastKeyFrame;
  15803. if (!durationFlag) {
  15804. if (!duration || duration > keyframes.length - 1) {
  15805. duration = keyframes.length - 1;
  15806. }
  15807. lastKeyFrame = keyframes[duration].t;
  15808. cycleDuration = lastKeyFrame - firstKeyFrame;
  15809. } else {
  15810. if (!duration) {
  15811. cycleDuration = Math.max(0, this.elem.data.op - firstKeyFrame);
  15812. } else {
  15813. cycleDuration = Math.abs(this.elem.comp.globalData.frameRate * duration);
  15814. }
  15815. lastKeyFrame = firstKeyFrame + cycleDuration;
  15816. }
  15817. var i;
  15818. var len;
  15819. var ret;
  15820. if (type === 'pingpong') {
  15821. var iterations = Math.floor((firstKeyFrame - currentFrame) / cycleDuration);
  15822. if (iterations % 2 === 0) {
  15823. return this.getValueAtTime((((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  15824. }
  15825. } else if (type === 'offset') {
  15826. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  15827. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  15828. var current = this.getValueAtTime((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration) + firstKeyFrame) / this.comp.globalData.frameRate, 0);
  15829. var repeats = Math.floor((firstKeyFrame - currentFrame) / cycleDuration) + 1;
  15830. if (this.pv.length) {
  15831. ret = new Array(initV.length);
  15832. len = ret.length;
  15833. for (i = 0; i < len; i += 1) {
  15834. ret[i] = current[i] - (endV[i] - initV[i]) * repeats;
  15835. }
  15836. return ret;
  15837. }
  15838. return current - (endV - initV) * repeats;
  15839. } else if (type === 'continue') {
  15840. var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  15841. var nextFirstValue = this.getValueAtTime((firstKeyFrame + 0.001) / this.comp.globalData.frameRate, 0);
  15842. if (this.pv.length) {
  15843. ret = new Array(firstValue.length);
  15844. len = ret.length;
  15845. for (i = 0; i < len; i += 1) {
  15846. ret[i] = firstValue[i] + ((firstValue[i] - nextFirstValue[i]) * (firstKeyFrame - currentFrame)) / 0.001;
  15847. }
  15848. return ret;
  15849. }
  15850. return firstValue + ((firstValue - nextFirstValue) * (firstKeyFrame - currentFrame)) / 0.001;
  15851. }
  15852. return this.getValueAtTime(((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame))) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  15853. }
  15854. function smooth(width, samples) {
  15855. if (!this.k) {
  15856. return this.pv;
  15857. }
  15858. width = (width || 0.4) * 0.5;
  15859. samples = Math.floor(samples || 5);
  15860. if (samples <= 1) {
  15861. return this.pv;
  15862. }
  15863. var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate;
  15864. var initFrame = currentTime - width;
  15865. var endFrame = currentTime + width;
  15866. var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1;
  15867. var i = 0;
  15868. var j = 0;
  15869. var value;
  15870. if (this.pv.length) {
  15871. value = createTypedArray('float32', this.pv.length);
  15872. } else {
  15873. value = 0;
  15874. }
  15875. var sampleValue;
  15876. while (i < samples) {
  15877. sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency);
  15878. if (this.pv.length) {
  15879. for (j = 0; j < this.pv.length; j += 1) {
  15880. value[j] += sampleValue[j];
  15881. }
  15882. } else {
  15883. value += sampleValue;
  15884. }
  15885. i += 1;
  15886. }
  15887. if (this.pv.length) {
  15888. for (j = 0; j < this.pv.length; j += 1) {
  15889. value[j] /= samples;
  15890. }
  15891. } else {
  15892. value /= samples;
  15893. }
  15894. return value;
  15895. }
  15896. function getTransformValueAtTime(time) {
  15897. if (!this._transformCachingAtTime) {
  15898. this._transformCachingAtTime = {
  15899. v: new Matrix(),
  15900. };
  15901. }
  15902. /// /
  15903. var matrix = this._transformCachingAtTime.v;
  15904. matrix.cloneFromProps(this.pre.props);
  15905. if (this.appliedTransformations < 1) {
  15906. var anchor = this.a.getValueAtTime(time);
  15907. matrix.translate(
  15908. -anchor[0] * this.a.mult,
  15909. -anchor[1] * this.a.mult,
  15910. anchor[2] * this.a.mult
  15911. );
  15912. }
  15913. if (this.appliedTransformations < 2) {
  15914. var scale = this.s.getValueAtTime(time);
  15915. matrix.scale(
  15916. scale[0] * this.s.mult,
  15917. scale[1] * this.s.mult,
  15918. scale[2] * this.s.mult
  15919. );
  15920. }
  15921. if (this.sk && this.appliedTransformations < 3) {
  15922. var skew = this.sk.getValueAtTime(time);
  15923. var skewAxis = this.sa.getValueAtTime(time);
  15924. matrix.skewFromAxis(-skew * this.sk.mult, skewAxis * this.sa.mult);
  15925. }
  15926. if (this.r && this.appliedTransformations < 4) {
  15927. var rotation = this.r.getValueAtTime(time);
  15928. matrix.rotate(-rotation * this.r.mult);
  15929. } else if (!this.r && this.appliedTransformations < 4) {
  15930. var rotationZ = this.rz.getValueAtTime(time);
  15931. var rotationY = this.ry.getValueAtTime(time);
  15932. var rotationX = this.rx.getValueAtTime(time);
  15933. var orientation = this.or.getValueAtTime(time);
  15934. matrix.rotateZ(-rotationZ * this.rz.mult)
  15935. .rotateY(rotationY * this.ry.mult)
  15936. .rotateX(rotationX * this.rx.mult)
  15937. .rotateZ(-orientation[2] * this.or.mult)
  15938. .rotateY(orientation[1] * this.or.mult)
  15939. .rotateX(orientation[0] * this.or.mult);
  15940. }
  15941. if (this.data.p && this.data.p.s) {
  15942. var positionX = this.px.getValueAtTime(time);
  15943. var positionY = this.py.getValueAtTime(time);
  15944. if (this.data.p.z) {
  15945. var positionZ = this.pz.getValueAtTime(time);
  15946. matrix.translate(
  15947. positionX * this.px.mult,
  15948. positionY * this.py.mult,
  15949. -positionZ * this.pz.mult
  15950. );
  15951. } else {
  15952. matrix.translate(positionX * this.px.mult, positionY * this.py.mult, 0);
  15953. }
  15954. } else {
  15955. var position = this.p.getValueAtTime(time);
  15956. matrix.translate(
  15957. position[0] * this.p.mult,
  15958. position[1] * this.p.mult,
  15959. -position[2] * this.p.mult
  15960. );
  15961. }
  15962. return matrix;
  15963. /// /
  15964. }
  15965. function getTransformStaticValueAtTime() {
  15966. return this.v.clone(new Matrix());
  15967. }
  15968. var getTransformProperty = TransformPropertyFactory.getTransformProperty;
  15969. TransformPropertyFactory.getTransformProperty = function (elem, data, container) {
  15970. var prop = getTransformProperty(elem, data, container);
  15971. if (prop.dynamicProperties.length) {
  15972. prop.getValueAtTime = getTransformValueAtTime.bind(prop);
  15973. } else {
  15974. prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop);
  15975. }
  15976. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  15977. return prop;
  15978. };
  15979. var propertyGetProp = PropertyFactory.getProp;
  15980. PropertyFactory.getProp = function (elem, data, type, mult, container) {
  15981. var prop = propertyGetProp(elem, data, type, mult, container);
  15982. // prop.getVelocityAtTime = getVelocityAtTime;
  15983. // prop.loopOut = loopOut;
  15984. // prop.loopIn = loopIn;
  15985. if (prop.kf) {
  15986. prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop);
  15987. } else {
  15988. prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop);
  15989. }
  15990. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  15991. prop.loopOut = loopOut;
  15992. prop.loopIn = loopIn;
  15993. prop.smooth = smooth;
  15994. prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop);
  15995. prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop);
  15996. prop.numKeys = data.a === 1 ? data.k.length : 0;
  15997. prop.propertyIndex = data.ix;
  15998. var value = 0;
  15999. if (type !== 0) {
  16000. value = createTypedArray('float32', data.a === 1 ? data.k[0].s.length : data.k.length);
  16001. }
  16002. prop._cachingAtTime = {
  16003. lastFrame: initialDefaultFrame,
  16004. lastIndex: 0,
  16005. value: value,
  16006. };
  16007. expressionHelpers.searchExpressions(elem, data, prop);
  16008. if (prop.k) {
  16009. container.addDynamicProperty(prop);
  16010. }
  16011. return prop;
  16012. };
  16013. function getShapeValueAtTime(frameNum) {
  16014. // For now this caching object is created only when needed instead of creating it when the shape is initialized.
  16015. if (!this._cachingAtTime) {
  16016. this._cachingAtTime = {
  16017. shapeValue: shapePool.clone(this.pv),
  16018. lastIndex: 0,
  16019. lastTime: initialDefaultFrame,
  16020. };
  16021. }
  16022. frameNum *= this.elem.globalData.frameRate;
  16023. frameNum -= this.offsetTime;
  16024. if (frameNum !== this._cachingAtTime.lastTime) {
  16025. this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0;
  16026. this._cachingAtTime.lastTime = frameNum;
  16027. this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime);
  16028. }
  16029. return this._cachingAtTime.shapeValue;
  16030. }
  16031. var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction();
  16032. var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction();
  16033. function ShapeExpressions() {}
  16034. ShapeExpressions.prototype = {
  16035. vertices: function (prop, time) {
  16036. if (this.k) {
  16037. this.getValue();
  16038. }
  16039. var shapePath = this.v;
  16040. if (time !== undefined) {
  16041. shapePath = this.getValueAtTime(time, 0);
  16042. }
  16043. var i;
  16044. var len = shapePath._length;
  16045. var vertices = shapePath[prop];
  16046. var points = shapePath.v;
  16047. var arr = createSizedArray(len);
  16048. for (i = 0; i < len; i += 1) {
  16049. if (prop === 'i' || prop === 'o') {
  16050. arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]];
  16051. } else {
  16052. arr[i] = [vertices[i][0], vertices[i][1]];
  16053. }
  16054. }
  16055. return arr;
  16056. },
  16057. points: function (time) {
  16058. return this.vertices('v', time);
  16059. },
  16060. inTangents: function (time) {
  16061. return this.vertices('i', time);
  16062. },
  16063. outTangents: function (time) {
  16064. return this.vertices('o', time);
  16065. },
  16066. isClosed: function () {
  16067. return this.v.c;
  16068. },
  16069. pointOnPath: function (perc, time) {
  16070. var shapePath = this.v;
  16071. if (time !== undefined) {
  16072. shapePath = this.getValueAtTime(time, 0);
  16073. }
  16074. if (!this._segmentsLength) {
  16075. this._segmentsLength = bez.getSegmentsLength(shapePath);
  16076. }
  16077. var segmentsLength = this._segmentsLength;
  16078. var lengths = segmentsLength.lengths;
  16079. var lengthPos = segmentsLength.totalLength * perc;
  16080. var i = 0;
  16081. var len = lengths.length;
  16082. var accumulatedLength = 0;
  16083. var pt;
  16084. while (i < len) {
  16085. if (accumulatedLength + lengths[i].addedLength > lengthPos) {
  16086. var initIndex = i;
  16087. var endIndex = (shapePath.c && i === len - 1) ? 0 : i + 1;
  16088. var segmentPerc = (lengthPos - accumulatedLength) / lengths[i].addedLength;
  16089. pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]);
  16090. break;
  16091. } else {
  16092. accumulatedLength += lengths[i].addedLength;
  16093. }
  16094. i += 1;
  16095. }
  16096. if (!pt) {
  16097. pt = shapePath.c ? [shapePath.v[0][0], shapePath.v[0][1]] : [shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1]];
  16098. }
  16099. return pt;
  16100. },
  16101. vectorOnPath: function (perc, time, vectorType) {
  16102. // perc doesn't use triple equality because it can be a Number object as well as a primitive.
  16103. if (perc == 1) { // eslint-disable-line eqeqeq
  16104. perc = this.v.c;
  16105. } else if (perc == 0) { // eslint-disable-line eqeqeq
  16106. perc = 0.999;
  16107. }
  16108. var pt1 = this.pointOnPath(perc, time);
  16109. var pt2 = this.pointOnPath(perc + 0.001, time);
  16110. var xLength = pt2[0] - pt1[0];
  16111. var yLength = pt2[1] - pt1[1];
  16112. var magnitude = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2));
  16113. if (magnitude === 0) {
  16114. return [0, 0];
  16115. }
  16116. var unitVector = vectorType === 'tangent' ? [xLength / magnitude, yLength / magnitude] : [-yLength / magnitude, xLength / magnitude];
  16117. return unitVector;
  16118. },
  16119. tangentOnPath: function (perc, time) {
  16120. return this.vectorOnPath(perc, time, 'tangent');
  16121. },
  16122. normalOnPath: function (perc, time) {
  16123. return this.vectorOnPath(perc, time, 'normal');
  16124. },
  16125. setGroupProperty: expressionHelpers.setGroupProperty,
  16126. getValueAtTime: expressionHelpers.getStaticValueAtTime,
  16127. };
  16128. extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction);
  16129. extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction);
  16130. KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime;
  16131. KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression;
  16132. var propertyGetShapeProp = ShapePropertyFactory.getShapeProp;
  16133. ShapePropertyFactory.getShapeProp = function (elem, data, type, arr, trims) {
  16134. var prop = propertyGetShapeProp(elem, data, type, arr, trims);
  16135. prop.propertyIndex = data.ix;
  16136. prop.lock = false;
  16137. if (type === 3) {
  16138. expressionHelpers.searchExpressions(elem, data.pt, prop);
  16139. } else if (type === 4) {
  16140. expressionHelpers.searchExpressions(elem, data.ks, prop);
  16141. }
  16142. if (prop.k) {
  16143. elem.addDynamicProperty(prop);
  16144. }
  16145. return prop;
  16146. };
  16147. }
  16148. function initialize$1() {
  16149. addPropertyDecorator();
  16150. }
  16151. function addDecorator() {
  16152. function searchExpressions() {
  16153. if (this.data.d.x) {
  16154. this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem, this.data.d, this);
  16155. this.addEffect(this.getExpressionValue.bind(this));
  16156. return true;
  16157. }
  16158. return null;
  16159. }
  16160. TextProperty.prototype.getExpressionValue = function (currentValue, text) {
  16161. var newValue = this.calculateExpression(text);
  16162. if (currentValue.t !== newValue) {
  16163. var newData = {};
  16164. this.copyData(newData, currentValue);
  16165. newData.t = newValue.toString();
  16166. newData.__complete = false;
  16167. return newData;
  16168. }
  16169. return currentValue;
  16170. };
  16171. TextProperty.prototype.searchProperty = function () {
  16172. var isKeyframed = this.searchKeyframes();
  16173. var hasExpressions = this.searchExpressions();
  16174. this.kf = isKeyframed || hasExpressions;
  16175. return this.kf;
  16176. };
  16177. TextProperty.prototype.searchExpressions = searchExpressions;
  16178. }
  16179. function initialize() {
  16180. addDecorator();
  16181. }
  16182. function SVGComposableEffect() {
  16183. }
  16184. SVGComposableEffect.prototype = {
  16185. createMergeNode: (resultId, ins) => {
  16186. var feMerge = createNS('feMerge');
  16187. feMerge.setAttribute('result', resultId);
  16188. var feMergeNode;
  16189. var i;
  16190. for (i = 0; i < ins.length; i += 1) {
  16191. feMergeNode = createNS('feMergeNode');
  16192. feMergeNode.setAttribute('in', ins[i]);
  16193. feMerge.appendChild(feMergeNode);
  16194. feMerge.appendChild(feMergeNode);
  16195. }
  16196. return feMerge;
  16197. },
  16198. };
  16199. var linearFilterValue = '0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0';
  16200. function SVGTintFilter(filter, filterManager, elem, id, source) {
  16201. this.filterManager = filterManager;
  16202. var feColorMatrix = createNS('feColorMatrix');
  16203. feColorMatrix.setAttribute('type', 'matrix');
  16204. feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB');
  16205. feColorMatrix.setAttribute('values', linearFilterValue + ' 1 0');
  16206. this.linearFilter = feColorMatrix;
  16207. feColorMatrix.setAttribute('result', id + '_tint_1');
  16208. filter.appendChild(feColorMatrix);
  16209. feColorMatrix = createNS('feColorMatrix');
  16210. feColorMatrix.setAttribute('type', 'matrix');
  16211. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  16212. feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0');
  16213. feColorMatrix.setAttribute('result', id + '_tint_2');
  16214. filter.appendChild(feColorMatrix);
  16215. this.matrixFilter = feColorMatrix;
  16216. var feMerge = this.createMergeNode(
  16217. id,
  16218. [
  16219. source,
  16220. id + '_tint_1',
  16221. id + '_tint_2',
  16222. ]
  16223. );
  16224. filter.appendChild(feMerge);
  16225. }
  16226. extendPrototype([SVGComposableEffect], SVGTintFilter);
  16227. SVGTintFilter.prototype.renderFrame = function (forceRender) {
  16228. if (forceRender || this.filterManager._mdf) {
  16229. var colorBlack = this.filterManager.effectElements[0].p.v;
  16230. var colorWhite = this.filterManager.effectElements[1].p.v;
  16231. var opacity = this.filterManager.effectElements[2].p.v / 100;
  16232. this.linearFilter.setAttribute('values', linearFilterValue + ' ' + opacity + ' 0');
  16233. this.matrixFilter.setAttribute('values', (colorWhite[0] - colorBlack[0]) + ' 0 0 0 ' + colorBlack[0] + ' ' + (colorWhite[1] - colorBlack[1]) + ' 0 0 0 ' + colorBlack[1] + ' ' + (colorWhite[2] - colorBlack[2]) + ' 0 0 0 ' + colorBlack[2] + ' 0 0 0 1 0');
  16234. }
  16235. };
  16236. function SVGFillFilter(filter, filterManager, elem, id) {
  16237. this.filterManager = filterManager;
  16238. var feColorMatrix = createNS('feColorMatrix');
  16239. feColorMatrix.setAttribute('type', 'matrix');
  16240. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  16241. feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0');
  16242. feColorMatrix.setAttribute('result', id);
  16243. filter.appendChild(feColorMatrix);
  16244. this.matrixFilter = feColorMatrix;
  16245. }
  16246. SVGFillFilter.prototype.renderFrame = function (forceRender) {
  16247. if (forceRender || this.filterManager._mdf) {
  16248. var color = this.filterManager.effectElements[2].p.v;
  16249. var opacity = this.filterManager.effectElements[6].p.v;
  16250. this.matrixFilter.setAttribute('values', '0 0 0 0 ' + color[0] + ' 0 0 0 0 ' + color[1] + ' 0 0 0 0 ' + color[2] + ' 0 0 0 ' + opacity + ' 0');
  16251. }
  16252. };
  16253. function SVGStrokeEffect(fil, filterManager, elem) {
  16254. this.initialized = false;
  16255. this.filterManager = filterManager;
  16256. this.elem = elem;
  16257. this.paths = [];
  16258. }
  16259. SVGStrokeEffect.prototype.initialize = function () {
  16260. var elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes;
  16261. var path;
  16262. var groupPath;
  16263. var i;
  16264. var len;
  16265. if (this.filterManager.effectElements[1].p.v === 1) {
  16266. len = this.elem.maskManager.masksProperties.length;
  16267. i = 0;
  16268. } else {
  16269. i = this.filterManager.effectElements[0].p.v - 1;
  16270. len = i + 1;
  16271. }
  16272. groupPath = createNS('g');
  16273. groupPath.setAttribute('fill', 'none');
  16274. groupPath.setAttribute('stroke-linecap', 'round');
  16275. groupPath.setAttribute('stroke-dashoffset', 1);
  16276. for (i; i < len; i += 1) {
  16277. path = createNS('path');
  16278. groupPath.appendChild(path);
  16279. this.paths.push({ p: path, m: i });
  16280. }
  16281. if (this.filterManager.effectElements[10].p.v === 3) {
  16282. var mask = createNS('mask');
  16283. var id = createElementID();
  16284. mask.setAttribute('id', id);
  16285. mask.setAttribute('mask-type', 'alpha');
  16286. mask.appendChild(groupPath);
  16287. this.elem.globalData.defs.appendChild(mask);
  16288. var g = createNS('g');
  16289. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  16290. while (elemChildren[0]) {
  16291. g.appendChild(elemChildren[0]);
  16292. }
  16293. this.elem.layerElement.appendChild(g);
  16294. this.masker = mask;
  16295. groupPath.setAttribute('stroke', '#fff');
  16296. } else if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) {
  16297. if (this.filterManager.effectElements[10].p.v === 2) {
  16298. elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes;
  16299. while (elemChildren.length) {
  16300. this.elem.layerElement.removeChild(elemChildren[0]);
  16301. }
  16302. }
  16303. this.elem.layerElement.appendChild(groupPath);
  16304. this.elem.layerElement.removeAttribute('mask');
  16305. groupPath.setAttribute('stroke', '#fff');
  16306. }
  16307. this.initialized = true;
  16308. this.pathMasker = groupPath;
  16309. };
  16310. SVGStrokeEffect.prototype.renderFrame = function (forceRender) {
  16311. if (!this.initialized) {
  16312. this.initialize();
  16313. }
  16314. var i;
  16315. var len = this.paths.length;
  16316. var mask;
  16317. var path;
  16318. for (i = 0; i < len; i += 1) {
  16319. if (this.paths[i].m !== -1) {
  16320. mask = this.elem.maskManager.viewData[this.paths[i].m];
  16321. path = this.paths[i].p;
  16322. if (forceRender || this.filterManager._mdf || mask.prop._mdf) {
  16323. path.setAttribute('d', mask.lastPath);
  16324. }
  16325. if (forceRender || this.filterManager.effectElements[9].p._mdf || this.filterManager.effectElements[4].p._mdf || this.filterManager.effectElements[7].p._mdf || this.filterManager.effectElements[8].p._mdf || mask.prop._mdf) {
  16326. var dasharrayValue;
  16327. if (this.filterManager.effectElements[7].p.v !== 0 || this.filterManager.effectElements[8].p.v !== 100) {
  16328. var s = Math.min(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01;
  16329. var e = Math.max(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01;
  16330. var l = path.getTotalLength();
  16331. dasharrayValue = '0 0 0 ' + l * s + ' ';
  16332. var lineLength = l * (e - s);
  16333. var segment = 1 + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01;
  16334. var units = Math.floor(lineLength / segment);
  16335. var j;
  16336. for (j = 0; j < units; j += 1) {
  16337. dasharrayValue += '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01 + ' ';
  16338. }
  16339. dasharrayValue += '0 ' + l * 10 + ' 0 0';
  16340. } else {
  16341. dasharrayValue = '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01;
  16342. }
  16343. path.setAttribute('stroke-dasharray', dasharrayValue);
  16344. }
  16345. }
  16346. }
  16347. if (forceRender || this.filterManager.effectElements[4].p._mdf) {
  16348. this.pathMasker.setAttribute('stroke-width', this.filterManager.effectElements[4].p.v * 2);
  16349. }
  16350. if (forceRender || this.filterManager.effectElements[6].p._mdf) {
  16351. this.pathMasker.setAttribute('opacity', this.filterManager.effectElements[6].p.v);
  16352. }
  16353. if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) {
  16354. if (forceRender || this.filterManager.effectElements[3].p._mdf) {
  16355. var color = this.filterManager.effectElements[3].p.v;
  16356. this.pathMasker.setAttribute('stroke', 'rgb(' + bmFloor(color[0] * 255) + ',' + bmFloor(color[1] * 255) + ',' + bmFloor(color[2] * 255) + ')');
  16357. }
  16358. }
  16359. };
  16360. function SVGTritoneFilter(filter, filterManager, elem, id) {
  16361. this.filterManager = filterManager;
  16362. var feColorMatrix = createNS('feColorMatrix');
  16363. feColorMatrix.setAttribute('type', 'matrix');
  16364. feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB');
  16365. feColorMatrix.setAttribute('values', '0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0');
  16366. filter.appendChild(feColorMatrix);
  16367. var feComponentTransfer = createNS('feComponentTransfer');
  16368. feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB');
  16369. feComponentTransfer.setAttribute('result', id);
  16370. this.matrixFilter = feComponentTransfer;
  16371. var feFuncR = createNS('feFuncR');
  16372. feFuncR.setAttribute('type', 'table');
  16373. feComponentTransfer.appendChild(feFuncR);
  16374. this.feFuncR = feFuncR;
  16375. var feFuncG = createNS('feFuncG');
  16376. feFuncG.setAttribute('type', 'table');
  16377. feComponentTransfer.appendChild(feFuncG);
  16378. this.feFuncG = feFuncG;
  16379. var feFuncB = createNS('feFuncB');
  16380. feFuncB.setAttribute('type', 'table');
  16381. feComponentTransfer.appendChild(feFuncB);
  16382. this.feFuncB = feFuncB;
  16383. filter.appendChild(feComponentTransfer);
  16384. }
  16385. SVGTritoneFilter.prototype.renderFrame = function (forceRender) {
  16386. if (forceRender || this.filterManager._mdf) {
  16387. var color1 = this.filterManager.effectElements[0].p.v;
  16388. var color2 = this.filterManager.effectElements[1].p.v;
  16389. var color3 = this.filterManager.effectElements[2].p.v;
  16390. var tableR = color3[0] + ' ' + color2[0] + ' ' + color1[0];
  16391. var tableG = color3[1] + ' ' + color2[1] + ' ' + color1[1];
  16392. var tableB = color3[2] + ' ' + color2[2] + ' ' + color1[2];
  16393. this.feFuncR.setAttribute('tableValues', tableR);
  16394. this.feFuncG.setAttribute('tableValues', tableG);
  16395. this.feFuncB.setAttribute('tableValues', tableB);
  16396. }
  16397. };
  16398. function SVGProLevelsFilter(filter, filterManager, elem, id) {
  16399. this.filterManager = filterManager;
  16400. var effectElements = this.filterManager.effectElements;
  16401. var feComponentTransfer = createNS('feComponentTransfer');
  16402. // Red
  16403. if (effectElements[10].p.k || effectElements[10].p.v !== 0 || effectElements[11].p.k || effectElements[11].p.v !== 1 || effectElements[12].p.k || effectElements[12].p.v !== 1 || effectElements[13].p.k || effectElements[13].p.v !== 0 || effectElements[14].p.k || effectElements[14].p.v !== 1) {
  16404. this.feFuncR = this.createFeFunc('feFuncR', feComponentTransfer);
  16405. }
  16406. // Green
  16407. if (effectElements[17].p.k || effectElements[17].p.v !== 0 || effectElements[18].p.k || effectElements[18].p.v !== 1 || effectElements[19].p.k || effectElements[19].p.v !== 1 || effectElements[20].p.k || effectElements[20].p.v !== 0 || effectElements[21].p.k || effectElements[21].p.v !== 1) {
  16408. this.feFuncG = this.createFeFunc('feFuncG', feComponentTransfer);
  16409. }
  16410. // Blue
  16411. if (effectElements[24].p.k || effectElements[24].p.v !== 0 || effectElements[25].p.k || effectElements[25].p.v !== 1 || effectElements[26].p.k || effectElements[26].p.v !== 1 || effectElements[27].p.k || effectElements[27].p.v !== 0 || effectElements[28].p.k || effectElements[28].p.v !== 1) {
  16412. this.feFuncB = this.createFeFunc('feFuncB', feComponentTransfer);
  16413. }
  16414. // Alpha
  16415. if (effectElements[31].p.k || effectElements[31].p.v !== 0 || effectElements[32].p.k || effectElements[32].p.v !== 1 || effectElements[33].p.k || effectElements[33].p.v !== 1 || effectElements[34].p.k || effectElements[34].p.v !== 0 || effectElements[35].p.k || effectElements[35].p.v !== 1) {
  16416. this.feFuncA = this.createFeFunc('feFuncA', feComponentTransfer);
  16417. }
  16418. // RGB
  16419. if (this.feFuncR || this.feFuncG || this.feFuncB || this.feFuncA) {
  16420. feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB');
  16421. filter.appendChild(feComponentTransfer);
  16422. }
  16423. if (effectElements[3].p.k || effectElements[3].p.v !== 0 || effectElements[4].p.k || effectElements[4].p.v !== 1 || effectElements[5].p.k || effectElements[5].p.v !== 1 || effectElements[6].p.k || effectElements[6].p.v !== 0 || effectElements[7].p.k || effectElements[7].p.v !== 1) {
  16424. feComponentTransfer = createNS('feComponentTransfer');
  16425. feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB');
  16426. feComponentTransfer.setAttribute('result', id);
  16427. filter.appendChild(feComponentTransfer);
  16428. this.feFuncRComposed = this.createFeFunc('feFuncR', feComponentTransfer);
  16429. this.feFuncGComposed = this.createFeFunc('feFuncG', feComponentTransfer);
  16430. this.feFuncBComposed = this.createFeFunc('feFuncB', feComponentTransfer);
  16431. }
  16432. }
  16433. SVGProLevelsFilter.prototype.createFeFunc = function (type, feComponentTransfer) {
  16434. var feFunc = createNS(type);
  16435. feFunc.setAttribute('type', 'table');
  16436. feComponentTransfer.appendChild(feFunc);
  16437. return feFunc;
  16438. };
  16439. SVGProLevelsFilter.prototype.getTableValue = function (inputBlack, inputWhite, gamma, outputBlack, outputWhite) {
  16440. var cnt = 0;
  16441. var segments = 256;
  16442. var perc;
  16443. var min = Math.min(inputBlack, inputWhite);
  16444. var max = Math.max(inputBlack, inputWhite);
  16445. var table = Array.call(null, { length: segments });
  16446. var colorValue;
  16447. var pos = 0;
  16448. var outputDelta = outputWhite - outputBlack;
  16449. var inputDelta = inputWhite - inputBlack;
  16450. while (cnt <= 256) {
  16451. perc = cnt / 256;
  16452. if (perc <= min) {
  16453. colorValue = inputDelta < 0 ? outputWhite : outputBlack;
  16454. } else if (perc >= max) {
  16455. colorValue = inputDelta < 0 ? outputBlack : outputWhite;
  16456. } else {
  16457. colorValue = (outputBlack + outputDelta * Math.pow((perc - inputBlack) / inputDelta, 1 / gamma));
  16458. }
  16459. table[pos] = colorValue;
  16460. pos += 1;
  16461. cnt += 256 / (segments - 1);
  16462. }
  16463. return table.join(' ');
  16464. };
  16465. SVGProLevelsFilter.prototype.renderFrame = function (forceRender) {
  16466. if (forceRender || this.filterManager._mdf) {
  16467. var val;
  16468. var effectElements = this.filterManager.effectElements;
  16469. if (this.feFuncRComposed && (forceRender || effectElements[3].p._mdf || effectElements[4].p._mdf || effectElements[5].p._mdf || effectElements[6].p._mdf || effectElements[7].p._mdf)) {
  16470. val = this.getTableValue(effectElements[3].p.v, effectElements[4].p.v, effectElements[5].p.v, effectElements[6].p.v, effectElements[7].p.v);
  16471. this.feFuncRComposed.setAttribute('tableValues', val);
  16472. this.feFuncGComposed.setAttribute('tableValues', val);
  16473. this.feFuncBComposed.setAttribute('tableValues', val);
  16474. }
  16475. if (this.feFuncR && (forceRender || effectElements[10].p._mdf || effectElements[11].p._mdf || effectElements[12].p._mdf || effectElements[13].p._mdf || effectElements[14].p._mdf)) {
  16476. val = this.getTableValue(effectElements[10].p.v, effectElements[11].p.v, effectElements[12].p.v, effectElements[13].p.v, effectElements[14].p.v);
  16477. this.feFuncR.setAttribute('tableValues', val);
  16478. }
  16479. if (this.feFuncG && (forceRender || effectElements[17].p._mdf || effectElements[18].p._mdf || effectElements[19].p._mdf || effectElements[20].p._mdf || effectElements[21].p._mdf)) {
  16480. val = this.getTableValue(effectElements[17].p.v, effectElements[18].p.v, effectElements[19].p.v, effectElements[20].p.v, effectElements[21].p.v);
  16481. this.feFuncG.setAttribute('tableValues', val);
  16482. }
  16483. if (this.feFuncB && (forceRender || effectElements[24].p._mdf || effectElements[25].p._mdf || effectElements[26].p._mdf || effectElements[27].p._mdf || effectElements[28].p._mdf)) {
  16484. val = this.getTableValue(effectElements[24].p.v, effectElements[25].p.v, effectElements[26].p.v, effectElements[27].p.v, effectElements[28].p.v);
  16485. this.feFuncB.setAttribute('tableValues', val);
  16486. }
  16487. if (this.feFuncA && (forceRender || effectElements[31].p._mdf || effectElements[32].p._mdf || effectElements[33].p._mdf || effectElements[34].p._mdf || effectElements[35].p._mdf)) {
  16488. val = this.getTableValue(effectElements[31].p.v, effectElements[32].p.v, effectElements[33].p.v, effectElements[34].p.v, effectElements[35].p.v);
  16489. this.feFuncA.setAttribute('tableValues', val);
  16490. }
  16491. }
  16492. };
  16493. function SVGDropShadowEffect(filter, filterManager, elem, id, source) {
  16494. var globalFilterSize = filterManager.container.globalData.renderConfig.filterSize;
  16495. var filterSize = filterManager.data.fs || globalFilterSize;
  16496. filter.setAttribute('x', filterSize.x || globalFilterSize.x);
  16497. filter.setAttribute('y', filterSize.y || globalFilterSize.y);
  16498. filter.setAttribute('width', filterSize.width || globalFilterSize.width);
  16499. filter.setAttribute('height', filterSize.height || globalFilterSize.height);
  16500. this.filterManager = filterManager;
  16501. var feGaussianBlur = createNS('feGaussianBlur');
  16502. feGaussianBlur.setAttribute('in', 'SourceAlpha');
  16503. feGaussianBlur.setAttribute('result', id + '_drop_shadow_1');
  16504. feGaussianBlur.setAttribute('stdDeviation', '0');
  16505. this.feGaussianBlur = feGaussianBlur;
  16506. filter.appendChild(feGaussianBlur);
  16507. var feOffset = createNS('feOffset');
  16508. feOffset.setAttribute('dx', '25');
  16509. feOffset.setAttribute('dy', '0');
  16510. feOffset.setAttribute('in', id + '_drop_shadow_1');
  16511. feOffset.setAttribute('result', id + '_drop_shadow_2');
  16512. this.feOffset = feOffset;
  16513. filter.appendChild(feOffset);
  16514. var feFlood = createNS('feFlood');
  16515. feFlood.setAttribute('flood-color', '#00ff00');
  16516. feFlood.setAttribute('flood-opacity', '1');
  16517. feFlood.setAttribute('result', id + '_drop_shadow_3');
  16518. this.feFlood = feFlood;
  16519. filter.appendChild(feFlood);
  16520. var feComposite = createNS('feComposite');
  16521. feComposite.setAttribute('in', id + '_drop_shadow_3');
  16522. feComposite.setAttribute('in2', id + '_drop_shadow_2');
  16523. feComposite.setAttribute('operator', 'in');
  16524. feComposite.setAttribute('result', id + '_drop_shadow_4');
  16525. filter.appendChild(feComposite);
  16526. var feMerge = this.createMergeNode(
  16527. id,
  16528. [
  16529. id + '_drop_shadow_4',
  16530. source,
  16531. ]
  16532. );
  16533. filter.appendChild(feMerge);
  16534. //
  16535. }
  16536. extendPrototype([SVGComposableEffect], SVGDropShadowEffect);
  16537. SVGDropShadowEffect.prototype.renderFrame = function (forceRender) {
  16538. if (forceRender || this.filterManager._mdf) {
  16539. if (forceRender || this.filterManager.effectElements[4].p._mdf) {
  16540. this.feGaussianBlur.setAttribute('stdDeviation', this.filterManager.effectElements[4].p.v / 4);
  16541. }
  16542. if (forceRender || this.filterManager.effectElements[0].p._mdf) {
  16543. var col = this.filterManager.effectElements[0].p.v;
  16544. this.feFlood.setAttribute('flood-color', rgbToHex(Math.round(col[0] * 255), Math.round(col[1] * 255), Math.round(col[2] * 255)));
  16545. }
  16546. if (forceRender || this.filterManager.effectElements[1].p._mdf) {
  16547. this.feFlood.setAttribute('flood-opacity', this.filterManager.effectElements[1].p.v / 255);
  16548. }
  16549. if (forceRender || this.filterManager.effectElements[2].p._mdf || this.filterManager.effectElements[3].p._mdf) {
  16550. var distance = this.filterManager.effectElements[3].p.v;
  16551. var angle = (this.filterManager.effectElements[2].p.v - 90) * degToRads;
  16552. var x = distance * Math.cos(angle);
  16553. var y = distance * Math.sin(angle);
  16554. this.feOffset.setAttribute('dx', x);
  16555. this.feOffset.setAttribute('dy', y);
  16556. }
  16557. }
  16558. };
  16559. var _svgMatteSymbols = [];
  16560. function SVGMatte3Effect(filterElem, filterManager, elem) {
  16561. this.initialized = false;
  16562. this.filterManager = filterManager;
  16563. this.filterElem = filterElem;
  16564. this.elem = elem;
  16565. elem.matteElement = createNS('g');
  16566. elem.matteElement.appendChild(elem.layerElement);
  16567. elem.matteElement.appendChild(elem.transformedElement);
  16568. elem.baseElement = elem.matteElement;
  16569. }
  16570. SVGMatte3Effect.prototype.findSymbol = function (mask) {
  16571. var i = 0;
  16572. var len = _svgMatteSymbols.length;
  16573. while (i < len) {
  16574. if (_svgMatteSymbols[i] === mask) {
  16575. return _svgMatteSymbols[i];
  16576. }
  16577. i += 1;
  16578. }
  16579. return null;
  16580. };
  16581. SVGMatte3Effect.prototype.replaceInParent = function (mask, symbolId) {
  16582. var parentNode = mask.layerElement.parentNode;
  16583. if (!parentNode) {
  16584. return;
  16585. }
  16586. var children = parentNode.children;
  16587. var i = 0;
  16588. var len = children.length;
  16589. while (i < len) {
  16590. if (children[i] === mask.layerElement) {
  16591. break;
  16592. }
  16593. i += 1;
  16594. }
  16595. var nextChild;
  16596. if (i <= len - 2) {
  16597. nextChild = children[i + 1];
  16598. }
  16599. var useElem = createNS('use');
  16600. useElem.setAttribute('href', '#' + symbolId);
  16601. if (nextChild) {
  16602. parentNode.insertBefore(useElem, nextChild);
  16603. } else {
  16604. parentNode.appendChild(useElem);
  16605. }
  16606. };
  16607. SVGMatte3Effect.prototype.setElementAsMask = function (elem, mask) {
  16608. if (!this.findSymbol(mask)) {
  16609. var symbolId = createElementID();
  16610. var masker = createNS('mask');
  16611. masker.setAttribute('id', mask.layerId);
  16612. masker.setAttribute('mask-type', 'alpha');
  16613. _svgMatteSymbols.push(mask);
  16614. var defs = elem.globalData.defs;
  16615. defs.appendChild(masker);
  16616. var symbol = createNS('symbol');
  16617. symbol.setAttribute('id', symbolId);
  16618. this.replaceInParent(mask, symbolId);
  16619. symbol.appendChild(mask.layerElement);
  16620. defs.appendChild(symbol);
  16621. var useElem = createNS('use');
  16622. useElem.setAttribute('href', '#' + symbolId);
  16623. masker.appendChild(useElem);
  16624. mask.data.hd = false;
  16625. mask.show();
  16626. }
  16627. elem.setMatte(mask.layerId);
  16628. };
  16629. SVGMatte3Effect.prototype.initialize = function () {
  16630. var ind = this.filterManager.effectElements[0].p.v;
  16631. var elements = this.elem.comp.elements;
  16632. var i = 0;
  16633. var len = elements.length;
  16634. while (i < len) {
  16635. if (elements[i] && elements[i].data.ind === ind) {
  16636. this.setElementAsMask(this.elem, elements[i]);
  16637. }
  16638. i += 1;
  16639. }
  16640. this.initialized = true;
  16641. };
  16642. SVGMatte3Effect.prototype.renderFrame = function () {
  16643. if (!this.initialized) {
  16644. this.initialize();
  16645. }
  16646. };
  16647. function SVGGaussianBlurEffect(filter, filterManager, elem, id) {
  16648. // Outset the filter region by 100% on all sides to accommodate blur expansion.
  16649. filter.setAttribute('x', '-100%');
  16650. filter.setAttribute('y', '-100%');
  16651. filter.setAttribute('width', '300%');
  16652. filter.setAttribute('height', '300%');
  16653. this.filterManager = filterManager;
  16654. var feGaussianBlur = createNS('feGaussianBlur');
  16655. feGaussianBlur.setAttribute('result', id);
  16656. filter.appendChild(feGaussianBlur);
  16657. this.feGaussianBlur = feGaussianBlur;
  16658. }
  16659. SVGGaussianBlurEffect.prototype.renderFrame = function (forceRender) {
  16660. if (forceRender || this.filterManager._mdf) {
  16661. // Empirical value, matching AE's blur appearance.
  16662. var kBlurrinessToSigma = 0.3;
  16663. var sigma = this.filterManager.effectElements[0].p.v * kBlurrinessToSigma;
  16664. // Dimensions mapping:
  16665. //
  16666. // 1 -> horizontal & vertical
  16667. // 2 -> horizontal only
  16668. // 3 -> vertical only
  16669. //
  16670. var dimensions = this.filterManager.effectElements[1].p.v;
  16671. var sigmaX = (dimensions == 3) ? 0 : sigma; // eslint-disable-line eqeqeq
  16672. var sigmaY = (dimensions == 2) ? 0 : sigma; // eslint-disable-line eqeqeq
  16673. this.feGaussianBlur.setAttribute('stdDeviation', sigmaX + ' ' + sigmaY);
  16674. // Repeat edges mapping:
  16675. //
  16676. // 0 -> off -> duplicate
  16677. // 1 -> on -> wrap
  16678. var edgeMode = (this.filterManager.effectElements[2].p.v == 1) ? 'wrap' : 'duplicate'; // eslint-disable-line eqeqeq
  16679. this.feGaussianBlur.setAttribute('edgeMode', edgeMode);
  16680. }
  16681. };
  16682. function TransformEffect() {
  16683. }
  16684. TransformEffect.prototype.init = function (effectsManager) {
  16685. this.effectsManager = effectsManager;
  16686. this.type = effectTypes.TRANSFORM_EFFECT;
  16687. this.matrix = new Matrix();
  16688. this.opacity = -1;
  16689. this._mdf = false;
  16690. this._opMdf = false;
  16691. };
  16692. TransformEffect.prototype.renderFrame = function (forceFrame) {
  16693. this._opMdf = false;
  16694. this._mdf = false;
  16695. if (forceFrame || this.effectsManager._mdf) {
  16696. var effectElements = this.effectsManager.effectElements;
  16697. var anchor = effectElements[0].p.v;
  16698. var position = effectElements[1].p.v;
  16699. var isUniformScale = effectElements[2].p.v === 1;
  16700. var scaleHeight = effectElements[3].p.v;
  16701. var scaleWidth = isUniformScale ? scaleHeight : effectElements[4].p.v;
  16702. var skew = effectElements[5].p.v;
  16703. var skewAxis = effectElements[6].p.v;
  16704. var rotation = effectElements[7].p.v;
  16705. this.matrix.reset();
  16706. this.matrix.translate(-anchor[0], -anchor[1], anchor[2]);
  16707. this.matrix.scale(scaleWidth * 0.01, scaleHeight * 0.01, 1);
  16708. this.matrix.rotate(-rotation * degToRads);
  16709. this.matrix.skewFromAxis(-skew * degToRads, (skewAxis + 90) * degToRads);
  16710. this.matrix.translate(position[0], position[1], 0);
  16711. this._mdf = true;
  16712. if (this.opacity !== effectElements[8].p.v) {
  16713. this.opacity = effectElements[8].p.v;
  16714. this._opMdf = true;
  16715. }
  16716. }
  16717. };
  16718. function SVGTransformEffect(_, filterManager) {
  16719. this.init(filterManager);
  16720. }
  16721. extendPrototype([TransformEffect], SVGTransformEffect);
  16722. function CVTransformEffect(effectsManager) {
  16723. this.init(effectsManager);
  16724. }
  16725. extendPrototype([TransformEffect], CVTransformEffect);
  16726. // Registering renderers
  16727. registerRenderer('canvas', CanvasRenderer);
  16728. registerRenderer('html', HybridRenderer);
  16729. registerRenderer('svg', SVGRenderer);
  16730. // Registering shape modifiers
  16731. ShapeModifiers.registerModifier('tm', TrimModifier);
  16732. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  16733. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  16734. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  16735. ShapeModifiers.registerModifier('zz', ZigZagModifier);
  16736. ShapeModifiers.registerModifier('op', OffsetPathModifier);
  16737. // Registering expression plugin
  16738. setExpressionsPlugin(Expressions);
  16739. setExpressionInterfaces(getInterface);
  16740. initialize$1();
  16741. initialize();
  16742. // Registering svg effects
  16743. registerEffect$1(20, SVGTintFilter, true);
  16744. registerEffect$1(21, SVGFillFilter, true);
  16745. registerEffect$1(22, SVGStrokeEffect, false);
  16746. registerEffect$1(23, SVGTritoneFilter, true);
  16747. registerEffect$1(24, SVGProLevelsFilter, true);
  16748. registerEffect$1(25, SVGDropShadowEffect, true);
  16749. registerEffect$1(28, SVGMatte3Effect, false);
  16750. registerEffect$1(29, SVGGaussianBlurEffect, true);
  16751. registerEffect$1(35, SVGTransformEffect, false);
  16752. registerEffect(35, CVTransformEffect);
  16753. exports["default"] = lottie;