lottie_light_html.js 424 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022
  1. (typeof document !== "undefined") && (typeof navigator !== "undefined") && (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.lottie = factory());
  5. })(this, (function () { 'use strict';
  6. var svgNS = 'http://www.w3.org/2000/svg';
  7. var locationHref = '';
  8. var _useWebWorker = false;
  9. var initialDefaultFrame = -999999;
  10. var setWebWorker = function setWebWorker(flag) {
  11. _useWebWorker = !!flag;
  12. };
  13. var getWebWorker = function getWebWorker() {
  14. return _useWebWorker;
  15. };
  16. var setLocationHref = function setLocationHref(value) {
  17. locationHref = value;
  18. };
  19. var getLocationHref = function getLocationHref() {
  20. return locationHref;
  21. };
  22. function createTag(type) {
  23. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  24. return document.createElement(type);
  25. }
  26. function extendPrototype(sources, destination) {
  27. var i;
  28. var len = sources.length;
  29. var sourcePrototype;
  30. for (i = 0; i < len; i += 1) {
  31. sourcePrototype = sources[i].prototype;
  32. for (var attr in sourcePrototype) {
  33. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  34. }
  35. }
  36. }
  37. function getDescriptor(object, prop) {
  38. return Object.getOwnPropertyDescriptor(object, prop);
  39. }
  40. function createProxyFunction(prototype) {
  41. function ProxyFunction() {}
  42. ProxyFunction.prototype = prototype;
  43. return ProxyFunction;
  44. }
  45. // import Howl from '../../3rd_party/howler';
  46. var audioControllerFactory = function () {
  47. function AudioController(audioFactory) {
  48. this.audios = [];
  49. this.audioFactory = audioFactory;
  50. this._volume = 1;
  51. this._isMuted = false;
  52. }
  53. AudioController.prototype = {
  54. addAudio: function addAudio(audio) {
  55. this.audios.push(audio);
  56. },
  57. pause: function pause() {
  58. var i;
  59. var len = this.audios.length;
  60. for (i = 0; i < len; i += 1) {
  61. this.audios[i].pause();
  62. }
  63. },
  64. resume: function resume() {
  65. var i;
  66. var len = this.audios.length;
  67. for (i = 0; i < len; i += 1) {
  68. this.audios[i].resume();
  69. }
  70. },
  71. setRate: function setRate(rateValue) {
  72. var i;
  73. var len = this.audios.length;
  74. for (i = 0; i < len; i += 1) {
  75. this.audios[i].setRate(rateValue);
  76. }
  77. },
  78. createAudio: function createAudio(assetPath) {
  79. if (this.audioFactory) {
  80. return this.audioFactory(assetPath);
  81. }
  82. if (window.Howl) {
  83. return new window.Howl({
  84. src: [assetPath]
  85. });
  86. }
  87. return {
  88. isPlaying: false,
  89. play: function play() {
  90. this.isPlaying = true;
  91. },
  92. seek: function seek() {
  93. this.isPlaying = false;
  94. },
  95. playing: function playing() {},
  96. rate: function rate() {},
  97. setVolume: function setVolume() {}
  98. };
  99. },
  100. setAudioFactory: function setAudioFactory(audioFactory) {
  101. this.audioFactory = audioFactory;
  102. },
  103. setVolume: function setVolume(value) {
  104. this._volume = value;
  105. this._updateVolume();
  106. },
  107. mute: function mute() {
  108. this._isMuted = true;
  109. this._updateVolume();
  110. },
  111. unmute: function unmute() {
  112. this._isMuted = false;
  113. this._updateVolume();
  114. },
  115. getVolume: function getVolume() {
  116. return this._volume;
  117. },
  118. _updateVolume: function _updateVolume() {
  119. var i;
  120. var len = this.audios.length;
  121. for (i = 0; i < len; i += 1) {
  122. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  123. }
  124. }
  125. };
  126. return function () {
  127. return new AudioController();
  128. };
  129. }();
  130. var createTypedArray = function () {
  131. function createRegularArray(type, len) {
  132. var i = 0;
  133. var arr = [];
  134. var value;
  135. switch (type) {
  136. case 'int16':
  137. case 'uint8c':
  138. value = 1;
  139. break;
  140. default:
  141. value = 1.1;
  142. break;
  143. }
  144. for (i = 0; i < len; i += 1) {
  145. arr.push(value);
  146. }
  147. return arr;
  148. }
  149. function createTypedArrayFactory(type, len) {
  150. if (type === 'float32') {
  151. return new Float32Array(len);
  152. }
  153. if (type === 'int16') {
  154. return new Int16Array(len);
  155. }
  156. if (type === 'uint8c') {
  157. return new Uint8ClampedArray(len);
  158. }
  159. return createRegularArray(type, len);
  160. }
  161. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  162. return createTypedArrayFactory;
  163. }
  164. return createRegularArray;
  165. }();
  166. function createSizedArray(len) {
  167. return Array.apply(null, {
  168. length: len
  169. });
  170. }
  171. function _typeof$3(o) { "@babel/helpers - typeof"; return _typeof$3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$3(o); }
  172. var subframeEnabled = true;
  173. var expressionsPlugin = null;
  174. var expressionsInterfaces = null;
  175. var idPrefix$1 = '';
  176. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  177. var _shouldRoundValues = false;
  178. var bmPow = Math.pow;
  179. var bmSqrt = Math.sqrt;
  180. var bmFloor = Math.floor;
  181. var bmMax = Math.max;
  182. var bmMin = Math.min;
  183. var BMMath = {};
  184. (function () {
  185. var propertyNames = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'atan2', 'ceil', 'cbrt', 'expm1', 'clz32', 'cos', 'cosh', 'exp', 'floor', 'fround', 'hypot', 'imul', 'log', 'log1p', 'log2', 'log10', 'max', 'min', 'pow', 'random', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', 'E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2'];
  186. var i;
  187. var len = propertyNames.length;
  188. for (i = 0; i < len; i += 1) {
  189. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  190. }
  191. })();
  192. function ProjectInterface$1() {
  193. return {};
  194. }
  195. BMMath.random = Math.random;
  196. BMMath.abs = function (val) {
  197. var tOfVal = _typeof$3(val);
  198. if (tOfVal === 'object' && val.length) {
  199. var absArr = createSizedArray(val.length);
  200. var i;
  201. var len = val.length;
  202. for (i = 0; i < len; i += 1) {
  203. absArr[i] = Math.abs(val[i]);
  204. }
  205. return absArr;
  206. }
  207. return Math.abs(val);
  208. };
  209. var defaultCurveSegments = 150;
  210. var degToRads = Math.PI / 180;
  211. var roundCorner = 0.5519;
  212. function roundValues(flag) {
  213. _shouldRoundValues = !!flag;
  214. }
  215. function bmRnd(value) {
  216. if (_shouldRoundValues) {
  217. return Math.round(value);
  218. }
  219. return value;
  220. }
  221. function styleDiv(element) {
  222. element.style.position = 'absolute';
  223. element.style.top = 0;
  224. element.style.left = 0;
  225. element.style.display = 'block';
  226. element.style.transformOrigin = '0 0';
  227. element.style.webkitTransformOrigin = '0 0';
  228. element.style.backfaceVisibility = 'visible';
  229. element.style.webkitBackfaceVisibility = 'visible';
  230. element.style.transformStyle = 'preserve-3d';
  231. element.style.webkitTransformStyle = 'preserve-3d';
  232. element.style.mozTransformStyle = 'preserve-3d';
  233. }
  234. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  235. this.type = type;
  236. this.currentTime = currentTime;
  237. this.totalTime = totalTime;
  238. this.direction = frameMultiplier < 0 ? -1 : 1;
  239. }
  240. function BMCompleteEvent(type, frameMultiplier) {
  241. this.type = type;
  242. this.direction = frameMultiplier < 0 ? -1 : 1;
  243. }
  244. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  245. this.type = type;
  246. this.currentLoop = currentLoop;
  247. this.totalLoops = totalLoops;
  248. this.direction = frameMultiplier < 0 ? -1 : 1;
  249. }
  250. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  251. this.type = type;
  252. this.firstFrame = firstFrame;
  253. this.totalFrames = totalFrames;
  254. }
  255. function BMDestroyEvent(type, target) {
  256. this.type = type;
  257. this.target = target;
  258. }
  259. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  260. this.type = 'renderFrameError';
  261. this.nativeError = nativeError;
  262. this.currentTime = currentTime;
  263. }
  264. function BMConfigErrorEvent(nativeError) {
  265. this.type = 'configError';
  266. this.nativeError = nativeError;
  267. }
  268. function BMAnimationConfigErrorEvent(type, nativeError) {
  269. this.type = type;
  270. this.nativeError = nativeError;
  271. }
  272. var createElementID = function () {
  273. var _count = 0;
  274. return function createID() {
  275. _count += 1;
  276. return idPrefix$1 + '__lottie_element_' + _count;
  277. };
  278. }();
  279. function HSVtoRGB(h, s, v) {
  280. var r;
  281. var g;
  282. var b;
  283. var i;
  284. var f;
  285. var p;
  286. var q;
  287. var t;
  288. i = Math.floor(h * 6);
  289. f = h * 6 - i;
  290. p = v * (1 - s);
  291. q = v * (1 - f * s);
  292. t = v * (1 - (1 - f) * s);
  293. switch (i % 6) {
  294. case 0:
  295. r = v;
  296. g = t;
  297. b = p;
  298. break;
  299. case 1:
  300. r = q;
  301. g = v;
  302. b = p;
  303. break;
  304. case 2:
  305. r = p;
  306. g = v;
  307. b = t;
  308. break;
  309. case 3:
  310. r = p;
  311. g = q;
  312. b = v;
  313. break;
  314. case 4:
  315. r = t;
  316. g = p;
  317. b = v;
  318. break;
  319. case 5:
  320. r = v;
  321. g = p;
  322. b = q;
  323. break;
  324. default:
  325. break;
  326. }
  327. return [r, g, b];
  328. }
  329. function RGBtoHSV(r, g, b) {
  330. var max = Math.max(r, g, b);
  331. var min = Math.min(r, g, b);
  332. var d = max - min;
  333. var h;
  334. var s = max === 0 ? 0 : d / max;
  335. var v = max / 255;
  336. switch (max) {
  337. case min:
  338. h = 0;
  339. break;
  340. case r:
  341. h = g - b + d * (g < b ? 6 : 0);
  342. h /= 6 * d;
  343. break;
  344. case g:
  345. h = b - r + d * 2;
  346. h /= 6 * d;
  347. break;
  348. case b:
  349. h = r - g + d * 4;
  350. h /= 6 * d;
  351. break;
  352. default:
  353. break;
  354. }
  355. return [h, s, v];
  356. }
  357. function addSaturationToRGB(color, offset) {
  358. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  359. hsv[1] += offset;
  360. if (hsv[1] > 1) {
  361. hsv[1] = 1;
  362. } else if (hsv[1] <= 0) {
  363. hsv[1] = 0;
  364. }
  365. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  366. }
  367. function addBrightnessToRGB(color, offset) {
  368. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  369. hsv[2] += offset;
  370. if (hsv[2] > 1) {
  371. hsv[2] = 1;
  372. } else if (hsv[2] < 0) {
  373. hsv[2] = 0;
  374. }
  375. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  376. }
  377. function addHueToRGB(color, offset) {
  378. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  379. hsv[0] += offset / 360;
  380. if (hsv[0] > 1) {
  381. hsv[0] -= 1;
  382. } else if (hsv[0] < 0) {
  383. hsv[0] += 1;
  384. }
  385. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  386. }
  387. var rgbToHex = function () {
  388. var colorMap = [];
  389. var i;
  390. var hex;
  391. for (i = 0; i < 256; i += 1) {
  392. hex = i.toString(16);
  393. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  394. }
  395. return function (r, g, b) {
  396. if (r < 0) {
  397. r = 0;
  398. }
  399. if (g < 0) {
  400. g = 0;
  401. }
  402. if (b < 0) {
  403. b = 0;
  404. }
  405. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  406. };
  407. }();
  408. var setSubframeEnabled = function setSubframeEnabled(flag) {
  409. subframeEnabled = !!flag;
  410. };
  411. var getSubframeEnabled = function getSubframeEnabled() {
  412. return subframeEnabled;
  413. };
  414. var setExpressionsPlugin = function setExpressionsPlugin(value) {
  415. expressionsPlugin = value;
  416. };
  417. var getExpressionsPlugin = function getExpressionsPlugin() {
  418. return expressionsPlugin;
  419. };
  420. var setExpressionInterfaces = function setExpressionInterfaces(value) {
  421. expressionsInterfaces = value;
  422. };
  423. var getExpressionInterfaces = function getExpressionInterfaces() {
  424. return expressionsInterfaces;
  425. };
  426. var setDefaultCurveSegments = function setDefaultCurveSegments(value) {
  427. defaultCurveSegments = value;
  428. };
  429. var getDefaultCurveSegments = function getDefaultCurveSegments() {
  430. return defaultCurveSegments;
  431. };
  432. var setIdPrefix = function setIdPrefix(value) {
  433. idPrefix$1 = value;
  434. };
  435. var getIdPrefix = function getIdPrefix() {
  436. return idPrefix$1;
  437. };
  438. function createNS(type) {
  439. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  440. return document.createElementNS(svgNS, type);
  441. }
  442. function _typeof$2(o) { "@babel/helpers - typeof"; return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$2(o); }
  443. var dataManager = function () {
  444. var _counterId = 1;
  445. var processes = [];
  446. var workerFn;
  447. var workerInstance;
  448. var workerProxy = {
  449. onmessage: function onmessage() {},
  450. postMessage: function postMessage(path) {
  451. workerFn({
  452. data: path
  453. });
  454. }
  455. };
  456. var _workerSelf = {
  457. postMessage: function postMessage(data) {
  458. workerProxy.onmessage({
  459. data: data
  460. });
  461. }
  462. };
  463. function createWorker(fn) {
  464. if (window.Worker && window.Blob && getWebWorker()) {
  465. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], {
  466. type: 'text/javascript'
  467. });
  468. // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  469. var url = URL.createObjectURL(blob);
  470. return new Worker(url);
  471. }
  472. workerFn = fn;
  473. return workerProxy;
  474. }
  475. function setupWorker() {
  476. if (!workerInstance) {
  477. workerInstance = createWorker(function workerStart(e) {
  478. function dataFunctionManager() {
  479. function completeLayers(layers, comps) {
  480. var layerData;
  481. var i;
  482. var len = layers.length;
  483. var j;
  484. var jLen;
  485. var k;
  486. var kLen;
  487. for (i = 0; i < len; i += 1) {
  488. layerData = layers[i];
  489. if ('ks' in layerData && !layerData.completed) {
  490. layerData.completed = true;
  491. if (layerData.hasMask) {
  492. var maskProps = layerData.masksProperties;
  493. jLen = maskProps.length;
  494. for (j = 0; j < jLen; j += 1) {
  495. if (maskProps[j].pt.k.i) {
  496. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  497. } else {
  498. kLen = maskProps[j].pt.k.length;
  499. for (k = 0; k < kLen; k += 1) {
  500. if (maskProps[j].pt.k[k].s) {
  501. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  502. }
  503. if (maskProps[j].pt.k[k].e) {
  504. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  505. }
  506. }
  507. }
  508. }
  509. }
  510. if (layerData.ty === 0) {
  511. layerData.layers = findCompLayers(layerData.refId, comps);
  512. completeLayers(layerData.layers, comps);
  513. } else if (layerData.ty === 4) {
  514. completeShapes(layerData.shapes);
  515. } else if (layerData.ty === 5) {
  516. completeText(layerData);
  517. }
  518. }
  519. }
  520. }
  521. function completeChars(chars, assets) {
  522. if (chars) {
  523. var i = 0;
  524. var len = chars.length;
  525. for (i = 0; i < len; i += 1) {
  526. if (chars[i].t === 1) {
  527. // var compData = findComp(chars[i].data.refId, assets);
  528. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
  529. // chars[i].data.ip = 0;
  530. // chars[i].data.op = 99999;
  531. // chars[i].data.st = 0;
  532. // chars[i].data.sr = 1;
  533. // chars[i].w = compData.w;
  534. // chars[i].data.ks = {
  535. // a: { k: [0, 0, 0], a: 0 },
  536. // p: { k: [0, -compData.h, 0], a: 0 },
  537. // r: { k: 0, a: 0 },
  538. // s: { k: [100, 100], a: 0 },
  539. // o: { k: 100, a: 0 },
  540. // };
  541. completeLayers(chars[i].data.layers, assets);
  542. }
  543. }
  544. }
  545. }
  546. function findComp(id, comps) {
  547. var i = 0;
  548. var len = comps.length;
  549. while (i < len) {
  550. if (comps[i].id === id) {
  551. return comps[i];
  552. }
  553. i += 1;
  554. }
  555. return null;
  556. }
  557. function findCompLayers(id, comps) {
  558. var comp = findComp(id, comps);
  559. if (comp) {
  560. if (!comp.layers.__used) {
  561. comp.layers.__used = true;
  562. return comp.layers;
  563. }
  564. return JSON.parse(JSON.stringify(comp.layers));
  565. }
  566. return null;
  567. }
  568. function completeShapes(arr) {
  569. var i;
  570. var len = arr.length;
  571. var j;
  572. var jLen;
  573. for (i = len - 1; i >= 0; i -= 1) {
  574. if (arr[i].ty === 'sh') {
  575. if (arr[i].ks.k.i) {
  576. convertPathsToAbsoluteValues(arr[i].ks.k);
  577. } else {
  578. jLen = arr[i].ks.k.length;
  579. for (j = 0; j < jLen; j += 1) {
  580. if (arr[i].ks.k[j].s) {
  581. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  582. }
  583. if (arr[i].ks.k[j].e) {
  584. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  585. }
  586. }
  587. }
  588. } else if (arr[i].ty === 'gr') {
  589. completeShapes(arr[i].it);
  590. }
  591. }
  592. }
  593. function convertPathsToAbsoluteValues(path) {
  594. var i;
  595. var len = path.i.length;
  596. for (i = 0; i < len; i += 1) {
  597. path.i[i][0] += path.v[i][0];
  598. path.i[i][1] += path.v[i][1];
  599. path.o[i][0] += path.v[i][0];
  600. path.o[i][1] += path.v[i][1];
  601. }
  602. }
  603. function checkVersion(minimum, animVersionString) {
  604. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  605. if (minimum[0] > animVersion[0]) {
  606. return true;
  607. }
  608. if (animVersion[0] > minimum[0]) {
  609. return false;
  610. }
  611. if (minimum[1] > animVersion[1]) {
  612. return true;
  613. }
  614. if (animVersion[1] > minimum[1]) {
  615. return false;
  616. }
  617. if (minimum[2] > animVersion[2]) {
  618. return true;
  619. }
  620. if (animVersion[2] > minimum[2]) {
  621. return false;
  622. }
  623. return null;
  624. }
  625. var checkText = function () {
  626. var minimumVersion = [4, 4, 14];
  627. function updateTextLayer(textLayer) {
  628. var documentData = textLayer.t.d;
  629. textLayer.t.d = {
  630. k: [{
  631. s: documentData,
  632. t: 0
  633. }]
  634. };
  635. }
  636. function iterateLayers(layers) {
  637. var i;
  638. var len = layers.length;
  639. for (i = 0; i < len; i += 1) {
  640. if (layers[i].ty === 5) {
  641. updateTextLayer(layers[i]);
  642. }
  643. }
  644. }
  645. return function (animationData) {
  646. if (checkVersion(minimumVersion, animationData.v)) {
  647. iterateLayers(animationData.layers);
  648. if (animationData.assets) {
  649. var i;
  650. var len = animationData.assets.length;
  651. for (i = 0; i < len; i += 1) {
  652. if (animationData.assets[i].layers) {
  653. iterateLayers(animationData.assets[i].layers);
  654. }
  655. }
  656. }
  657. }
  658. };
  659. }();
  660. var checkChars = function () {
  661. var minimumVersion = [4, 7, 99];
  662. return function (animationData) {
  663. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  664. var i;
  665. var len = animationData.chars.length;
  666. for (i = 0; i < len; i += 1) {
  667. var charData = animationData.chars[i];
  668. if (charData.data && charData.data.shapes) {
  669. completeShapes(charData.data.shapes);
  670. charData.data.ip = 0;
  671. charData.data.op = 99999;
  672. charData.data.st = 0;
  673. charData.data.sr = 1;
  674. charData.data.ks = {
  675. p: {
  676. k: [0, 0],
  677. a: 0
  678. },
  679. s: {
  680. k: [100, 100],
  681. a: 0
  682. },
  683. a: {
  684. k: [0, 0],
  685. a: 0
  686. },
  687. r: {
  688. k: 0,
  689. a: 0
  690. },
  691. o: {
  692. k: 100,
  693. a: 0
  694. }
  695. };
  696. if (!animationData.chars[i].t) {
  697. charData.data.shapes.push({
  698. ty: 'no'
  699. });
  700. charData.data.shapes[0].it.push({
  701. p: {
  702. k: [0, 0],
  703. a: 0
  704. },
  705. s: {
  706. k: [100, 100],
  707. a: 0
  708. },
  709. a: {
  710. k: [0, 0],
  711. a: 0
  712. },
  713. r: {
  714. k: 0,
  715. a: 0
  716. },
  717. o: {
  718. k: 100,
  719. a: 0
  720. },
  721. sk: {
  722. k: 0,
  723. a: 0
  724. },
  725. sa: {
  726. k: 0,
  727. a: 0
  728. },
  729. ty: 'tr'
  730. });
  731. }
  732. }
  733. }
  734. }
  735. };
  736. }();
  737. var checkPathProperties = function () {
  738. var minimumVersion = [5, 7, 15];
  739. function updateTextLayer(textLayer) {
  740. var pathData = textLayer.t.p;
  741. if (typeof pathData.a === 'number') {
  742. pathData.a = {
  743. a: 0,
  744. k: pathData.a
  745. };
  746. }
  747. if (typeof pathData.p === 'number') {
  748. pathData.p = {
  749. a: 0,
  750. k: pathData.p
  751. };
  752. }
  753. if (typeof pathData.r === 'number') {
  754. pathData.r = {
  755. a: 0,
  756. k: pathData.r
  757. };
  758. }
  759. }
  760. function iterateLayers(layers) {
  761. var i;
  762. var len = layers.length;
  763. for (i = 0; i < len; i += 1) {
  764. if (layers[i].ty === 5) {
  765. updateTextLayer(layers[i]);
  766. }
  767. }
  768. }
  769. return function (animationData) {
  770. if (checkVersion(minimumVersion, animationData.v)) {
  771. iterateLayers(animationData.layers);
  772. if (animationData.assets) {
  773. var i;
  774. var len = animationData.assets.length;
  775. for (i = 0; i < len; i += 1) {
  776. if (animationData.assets[i].layers) {
  777. iterateLayers(animationData.assets[i].layers);
  778. }
  779. }
  780. }
  781. }
  782. };
  783. }();
  784. var checkColors = function () {
  785. var minimumVersion = [4, 1, 9];
  786. function iterateShapes(shapes) {
  787. var i;
  788. var len = shapes.length;
  789. var j;
  790. var jLen;
  791. for (i = 0; i < len; i += 1) {
  792. if (shapes[i].ty === 'gr') {
  793. iterateShapes(shapes[i].it);
  794. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  795. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  796. jLen = shapes[i].c.k.length;
  797. for (j = 0; j < jLen; j += 1) {
  798. if (shapes[i].c.k[j].s) {
  799. shapes[i].c.k[j].s[0] /= 255;
  800. shapes[i].c.k[j].s[1] /= 255;
  801. shapes[i].c.k[j].s[2] /= 255;
  802. shapes[i].c.k[j].s[3] /= 255;
  803. }
  804. if (shapes[i].c.k[j].e) {
  805. shapes[i].c.k[j].e[0] /= 255;
  806. shapes[i].c.k[j].e[1] /= 255;
  807. shapes[i].c.k[j].e[2] /= 255;
  808. shapes[i].c.k[j].e[3] /= 255;
  809. }
  810. }
  811. } else {
  812. shapes[i].c.k[0] /= 255;
  813. shapes[i].c.k[1] /= 255;
  814. shapes[i].c.k[2] /= 255;
  815. shapes[i].c.k[3] /= 255;
  816. }
  817. }
  818. }
  819. }
  820. function iterateLayers(layers) {
  821. var i;
  822. var len = layers.length;
  823. for (i = 0; i < len; i += 1) {
  824. if (layers[i].ty === 4) {
  825. iterateShapes(layers[i].shapes);
  826. }
  827. }
  828. }
  829. return function (animationData) {
  830. if (checkVersion(minimumVersion, animationData.v)) {
  831. iterateLayers(animationData.layers);
  832. if (animationData.assets) {
  833. var i;
  834. var len = animationData.assets.length;
  835. for (i = 0; i < len; i += 1) {
  836. if (animationData.assets[i].layers) {
  837. iterateLayers(animationData.assets[i].layers);
  838. }
  839. }
  840. }
  841. }
  842. };
  843. }();
  844. var checkShapes = function () {
  845. var minimumVersion = [4, 4, 18];
  846. function completeClosingShapes(arr) {
  847. var i;
  848. var len = arr.length;
  849. var j;
  850. var jLen;
  851. for (i = len - 1; i >= 0; i -= 1) {
  852. if (arr[i].ty === 'sh') {
  853. if (arr[i].ks.k.i) {
  854. arr[i].ks.k.c = arr[i].closed;
  855. } else {
  856. jLen = arr[i].ks.k.length;
  857. for (j = 0; j < jLen; j += 1) {
  858. if (arr[i].ks.k[j].s) {
  859. arr[i].ks.k[j].s[0].c = arr[i].closed;
  860. }
  861. if (arr[i].ks.k[j].e) {
  862. arr[i].ks.k[j].e[0].c = arr[i].closed;
  863. }
  864. }
  865. }
  866. } else if (arr[i].ty === 'gr') {
  867. completeClosingShapes(arr[i].it);
  868. }
  869. }
  870. }
  871. function iterateLayers(layers) {
  872. var layerData;
  873. var i;
  874. var len = layers.length;
  875. var j;
  876. var jLen;
  877. var k;
  878. var kLen;
  879. for (i = 0; i < len; i += 1) {
  880. layerData = layers[i];
  881. if (layerData.hasMask) {
  882. var maskProps = layerData.masksProperties;
  883. jLen = maskProps.length;
  884. for (j = 0; j < jLen; j += 1) {
  885. if (maskProps[j].pt.k.i) {
  886. maskProps[j].pt.k.c = maskProps[j].cl;
  887. } else {
  888. kLen = maskProps[j].pt.k.length;
  889. for (k = 0; k < kLen; k += 1) {
  890. if (maskProps[j].pt.k[k].s) {
  891. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  892. }
  893. if (maskProps[j].pt.k[k].e) {
  894. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  895. }
  896. }
  897. }
  898. }
  899. }
  900. if (layerData.ty === 4) {
  901. completeClosingShapes(layerData.shapes);
  902. }
  903. }
  904. }
  905. return function (animationData) {
  906. if (checkVersion(minimumVersion, animationData.v)) {
  907. iterateLayers(animationData.layers);
  908. if (animationData.assets) {
  909. var i;
  910. var len = animationData.assets.length;
  911. for (i = 0; i < len; i += 1) {
  912. if (animationData.assets[i].layers) {
  913. iterateLayers(animationData.assets[i].layers);
  914. }
  915. }
  916. }
  917. }
  918. };
  919. }();
  920. function completeData(animationData) {
  921. if (animationData.__complete) {
  922. return;
  923. }
  924. checkColors(animationData);
  925. checkText(animationData);
  926. checkChars(animationData);
  927. checkPathProperties(animationData);
  928. checkShapes(animationData);
  929. completeLayers(animationData.layers, animationData.assets);
  930. completeChars(animationData.chars, animationData.assets);
  931. animationData.__complete = true;
  932. }
  933. function completeText(data) {
  934. if (data.t.a.length === 0 && !('m' in data.t.p)) {
  935. // data.singleShape = true;
  936. }
  937. }
  938. var moduleOb = {};
  939. moduleOb.completeData = completeData;
  940. moduleOb.checkColors = checkColors;
  941. moduleOb.checkChars = checkChars;
  942. moduleOb.checkPathProperties = checkPathProperties;
  943. moduleOb.checkShapes = checkShapes;
  944. moduleOb.completeLayers = completeLayers;
  945. return moduleOb;
  946. }
  947. if (!_workerSelf.dataManager) {
  948. _workerSelf.dataManager = dataFunctionManager();
  949. }
  950. if (!_workerSelf.assetLoader) {
  951. _workerSelf.assetLoader = function () {
  952. function formatResponse(xhr) {
  953. // using typeof doubles the time of execution of this method,
  954. // so if available, it's better to use the header to validate the type
  955. var contentTypeHeader = xhr.getResponseHeader('content-type');
  956. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  957. return xhr.response;
  958. }
  959. if (xhr.response && _typeof$2(xhr.response) === 'object') {
  960. return xhr.response;
  961. }
  962. if (xhr.response && typeof xhr.response === 'string') {
  963. return JSON.parse(xhr.response);
  964. }
  965. if (xhr.responseText) {
  966. return JSON.parse(xhr.responseText);
  967. }
  968. return null;
  969. }
  970. function loadAsset(path, fullPath, callback, errorCallback) {
  971. var response;
  972. var xhr = new XMLHttpRequest();
  973. // set responseType after calling open or IE will break.
  974. try {
  975. // This crashes on Android WebView prior to KitKat
  976. xhr.responseType = 'json';
  977. } catch (err) {} // eslint-disable-line no-empty
  978. xhr.onreadystatechange = function () {
  979. if (xhr.readyState === 4) {
  980. if (xhr.status === 200) {
  981. response = formatResponse(xhr);
  982. callback(response);
  983. } else {
  984. try {
  985. response = formatResponse(xhr);
  986. callback(response);
  987. } catch (err) {
  988. if (errorCallback) {
  989. errorCallback(err);
  990. }
  991. }
  992. }
  993. }
  994. };
  995. try {
  996. // Hack to workaround banner validation
  997. xhr.open(['G', 'E', 'T'].join(''), path, true);
  998. } catch (error) {
  999. // Hack to workaround banner validation
  1000. xhr.open(['G', 'E', 'T'].join(''), fullPath + '/' + path, true);
  1001. }
  1002. xhr.send();
  1003. }
  1004. return {
  1005. load: loadAsset
  1006. };
  1007. }();
  1008. }
  1009. if (e.data.type === 'loadAnimation') {
  1010. _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function (data) {
  1011. _workerSelf.dataManager.completeData(data);
  1012. _workerSelf.postMessage({
  1013. id: e.data.id,
  1014. payload: data,
  1015. status: 'success'
  1016. });
  1017. }, function () {
  1018. _workerSelf.postMessage({
  1019. id: e.data.id,
  1020. status: 'error'
  1021. });
  1022. });
  1023. } else if (e.data.type === 'complete') {
  1024. var animation = e.data.animation;
  1025. _workerSelf.dataManager.completeData(animation);
  1026. _workerSelf.postMessage({
  1027. id: e.data.id,
  1028. payload: animation,
  1029. status: 'success'
  1030. });
  1031. } else if (e.data.type === 'loadData') {
  1032. _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function (data) {
  1033. _workerSelf.postMessage({
  1034. id: e.data.id,
  1035. payload: data,
  1036. status: 'success'
  1037. });
  1038. }, function () {
  1039. _workerSelf.postMessage({
  1040. id: e.data.id,
  1041. status: 'error'
  1042. });
  1043. });
  1044. }
  1045. });
  1046. workerInstance.onmessage = function (event) {
  1047. var data = event.data;
  1048. var id = data.id;
  1049. var process = processes[id];
  1050. processes[id] = null;
  1051. if (data.status === 'success') {
  1052. process.onComplete(data.payload);
  1053. } else if (process.onError) {
  1054. process.onError();
  1055. }
  1056. };
  1057. }
  1058. }
  1059. function createProcess(onComplete, onError) {
  1060. _counterId += 1;
  1061. var id = 'processId_' + _counterId;
  1062. processes[id] = {
  1063. onComplete: onComplete,
  1064. onError: onError
  1065. };
  1066. return id;
  1067. }
  1068. function loadAnimation(path, onComplete, onError) {
  1069. setupWorker();
  1070. var processId = createProcess(onComplete, onError);
  1071. workerInstance.postMessage({
  1072. type: 'loadAnimation',
  1073. path: path,
  1074. fullPath: window.location.origin + window.location.pathname,
  1075. id: processId
  1076. });
  1077. }
  1078. function loadData(path, onComplete, onError) {
  1079. setupWorker();
  1080. var processId = createProcess(onComplete, onError);
  1081. workerInstance.postMessage({
  1082. type: 'loadData',
  1083. path: path,
  1084. fullPath: window.location.origin + window.location.pathname,
  1085. id: processId
  1086. });
  1087. }
  1088. function completeAnimation(anim, onComplete, onError) {
  1089. setupWorker();
  1090. var processId = createProcess(onComplete, onError);
  1091. workerInstance.postMessage({
  1092. type: 'complete',
  1093. animation: anim,
  1094. id: processId
  1095. });
  1096. }
  1097. return {
  1098. loadAnimation: loadAnimation,
  1099. loadData: loadData,
  1100. completeAnimation: completeAnimation
  1101. };
  1102. }();
  1103. var ImagePreloader = function () {
  1104. var proxyImage = function () {
  1105. var canvas = createTag('canvas');
  1106. canvas.width = 1;
  1107. canvas.height = 1;
  1108. var ctx = canvas.getContext('2d');
  1109. ctx.fillStyle = 'rgba(0,0,0,0)';
  1110. ctx.fillRect(0, 0, 1, 1);
  1111. return canvas;
  1112. }();
  1113. function imageLoaded() {
  1114. this.loadedAssets += 1;
  1115. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1116. if (this.imagesLoadedCb) {
  1117. this.imagesLoadedCb(null);
  1118. }
  1119. }
  1120. }
  1121. function footageLoaded() {
  1122. this.loadedFootagesCount += 1;
  1123. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1124. if (this.imagesLoadedCb) {
  1125. this.imagesLoadedCb(null);
  1126. }
  1127. }
  1128. }
  1129. function getAssetsPath(assetData, assetsPath, originalPath) {
  1130. var path = '';
  1131. if (assetData.e) {
  1132. path = assetData.p;
  1133. } else if (assetsPath) {
  1134. var imagePath = assetData.p;
  1135. if (imagePath.indexOf('images/') !== -1) {
  1136. imagePath = imagePath.split('/')[1];
  1137. }
  1138. path = assetsPath + imagePath;
  1139. } else {
  1140. path = originalPath;
  1141. path += assetData.u ? assetData.u : '';
  1142. path += assetData.p;
  1143. }
  1144. return path;
  1145. }
  1146. function testImageLoaded(img) {
  1147. var _count = 0;
  1148. var intervalId = setInterval(function () {
  1149. var box = img.getBBox();
  1150. if (box.width || _count > 500) {
  1151. this._imageLoaded();
  1152. clearInterval(intervalId);
  1153. }
  1154. _count += 1;
  1155. }.bind(this), 50);
  1156. }
  1157. function createImageData(assetData) {
  1158. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1159. var img = createNS('image');
  1160. if (isSafari) {
  1161. this.testImageLoaded(img);
  1162. } else {
  1163. img.addEventListener('load', this._imageLoaded, false);
  1164. }
  1165. img.addEventListener('error', function () {
  1166. ob.img = proxyImage;
  1167. this._imageLoaded();
  1168. }.bind(this), false);
  1169. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1170. if (this._elementHelper.append) {
  1171. this._elementHelper.append(img);
  1172. } else {
  1173. this._elementHelper.appendChild(img);
  1174. }
  1175. var ob = {
  1176. img: img,
  1177. assetData: assetData
  1178. };
  1179. return ob;
  1180. }
  1181. function createImgData(assetData) {
  1182. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1183. var img = createTag('img');
  1184. img.crossOrigin = 'anonymous';
  1185. img.addEventListener('load', this._imageLoaded, false);
  1186. img.addEventListener('error', function () {
  1187. ob.img = proxyImage;
  1188. this._imageLoaded();
  1189. }.bind(this), false);
  1190. img.src = path;
  1191. var ob = {
  1192. img: img,
  1193. assetData: assetData
  1194. };
  1195. return ob;
  1196. }
  1197. function createFootageData(data) {
  1198. var ob = {
  1199. assetData: data
  1200. };
  1201. var path = getAssetsPath(data, this.assetsPath, this.path);
  1202. dataManager.loadData(path, function (footageData) {
  1203. ob.img = footageData;
  1204. this._footageLoaded();
  1205. }.bind(this), function () {
  1206. ob.img = {};
  1207. this._footageLoaded();
  1208. }.bind(this));
  1209. return ob;
  1210. }
  1211. function loadAssets(assets, cb) {
  1212. this.imagesLoadedCb = cb;
  1213. var i;
  1214. var len = assets.length;
  1215. for (i = 0; i < len; i += 1) {
  1216. if (!assets[i].layers) {
  1217. if (!assets[i].t || assets[i].t === 'seq') {
  1218. this.totalImages += 1;
  1219. this.images.push(this._createImageData(assets[i]));
  1220. } else if (assets[i].t === 3) {
  1221. this.totalFootages += 1;
  1222. this.images.push(this.createFootageData(assets[i]));
  1223. }
  1224. }
  1225. }
  1226. }
  1227. function setPath(path) {
  1228. this.path = path || '';
  1229. }
  1230. function setAssetsPath(path) {
  1231. this.assetsPath = path || '';
  1232. }
  1233. function getAsset(assetData) {
  1234. var i = 0;
  1235. var len = this.images.length;
  1236. while (i < len) {
  1237. if (this.images[i].assetData === assetData) {
  1238. return this.images[i].img;
  1239. }
  1240. i += 1;
  1241. }
  1242. return null;
  1243. }
  1244. function destroy() {
  1245. this.imagesLoadedCb = null;
  1246. this.images.length = 0;
  1247. }
  1248. function loadedImages() {
  1249. return this.totalImages === this.loadedAssets;
  1250. }
  1251. function loadedFootages() {
  1252. return this.totalFootages === this.loadedFootagesCount;
  1253. }
  1254. function setCacheType(type, elementHelper) {
  1255. if (type === 'svg') {
  1256. this._elementHelper = elementHelper;
  1257. this._createImageData = this.createImageData.bind(this);
  1258. } else {
  1259. this._createImageData = this.createImgData.bind(this);
  1260. }
  1261. }
  1262. function ImagePreloaderFactory() {
  1263. this._imageLoaded = imageLoaded.bind(this);
  1264. this._footageLoaded = footageLoaded.bind(this);
  1265. this.testImageLoaded = testImageLoaded.bind(this);
  1266. this.createFootageData = createFootageData.bind(this);
  1267. this.assetsPath = '';
  1268. this.path = '';
  1269. this.totalImages = 0;
  1270. this.totalFootages = 0;
  1271. this.loadedAssets = 0;
  1272. this.loadedFootagesCount = 0;
  1273. this.imagesLoadedCb = null;
  1274. this.images = [];
  1275. }
  1276. ImagePreloaderFactory.prototype = {
  1277. loadAssets: loadAssets,
  1278. setAssetsPath: setAssetsPath,
  1279. setPath: setPath,
  1280. loadedImages: loadedImages,
  1281. loadedFootages: loadedFootages,
  1282. destroy: destroy,
  1283. getAsset: getAsset,
  1284. createImgData: createImgData,
  1285. createImageData: createImageData,
  1286. imageLoaded: imageLoaded,
  1287. footageLoaded: footageLoaded,
  1288. setCacheType: setCacheType
  1289. };
  1290. return ImagePreloaderFactory;
  1291. }();
  1292. function BaseEvent() {}
  1293. BaseEvent.prototype = {
  1294. triggerEvent: function triggerEvent(eventName, args) {
  1295. if (this._cbs[eventName]) {
  1296. var callbacks = this._cbs[eventName];
  1297. for (var i = 0; i < callbacks.length; i += 1) {
  1298. callbacks[i](args);
  1299. }
  1300. }
  1301. },
  1302. addEventListener: function addEventListener(eventName, callback) {
  1303. if (!this._cbs[eventName]) {
  1304. this._cbs[eventName] = [];
  1305. }
  1306. this._cbs[eventName].push(callback);
  1307. return function () {
  1308. this.removeEventListener(eventName, callback);
  1309. }.bind(this);
  1310. },
  1311. removeEventListener: function removeEventListener(eventName, callback) {
  1312. if (!callback) {
  1313. this._cbs[eventName] = null;
  1314. } else if (this._cbs[eventName]) {
  1315. var i = 0;
  1316. var len = this._cbs[eventName].length;
  1317. while (i < len) {
  1318. if (this._cbs[eventName][i] === callback) {
  1319. this._cbs[eventName].splice(i, 1);
  1320. i -= 1;
  1321. len -= 1;
  1322. }
  1323. i += 1;
  1324. }
  1325. if (!this._cbs[eventName].length) {
  1326. this._cbs[eventName] = null;
  1327. }
  1328. }
  1329. }
  1330. };
  1331. var markerParser = function () {
  1332. function parsePayloadLines(payload) {
  1333. var lines = payload.split('\r\n');
  1334. var keys = {};
  1335. var line;
  1336. var keysCount = 0;
  1337. for (var i = 0; i < lines.length; i += 1) {
  1338. line = lines[i].split(':');
  1339. if (line.length === 2) {
  1340. keys[line[0]] = line[1].trim();
  1341. keysCount += 1;
  1342. }
  1343. }
  1344. if (keysCount === 0) {
  1345. throw new Error();
  1346. }
  1347. return keys;
  1348. }
  1349. return function (_markers) {
  1350. var markers = [];
  1351. for (var i = 0; i < _markers.length; i += 1) {
  1352. var _marker = _markers[i];
  1353. var markerData = {
  1354. time: _marker.tm,
  1355. duration: _marker.dr
  1356. };
  1357. try {
  1358. markerData.payload = JSON.parse(_markers[i].cm);
  1359. } catch (_) {
  1360. try {
  1361. markerData.payload = parsePayloadLines(_markers[i].cm);
  1362. } catch (__) {
  1363. markerData.payload = {
  1364. name: _markers[i].cm
  1365. };
  1366. }
  1367. }
  1368. markers.push(markerData);
  1369. }
  1370. return markers;
  1371. };
  1372. }();
  1373. var ProjectInterface = function () {
  1374. function registerComposition(comp) {
  1375. this.compositions.push(comp);
  1376. }
  1377. return function () {
  1378. function _thisProjectFunction(name) {
  1379. var i = 0;
  1380. var len = this.compositions.length;
  1381. while (i < len) {
  1382. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1383. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1384. this.compositions[i].prepareFrame(this.currentFrame);
  1385. }
  1386. return this.compositions[i].compInterface;
  1387. }
  1388. i += 1;
  1389. }
  1390. return null;
  1391. }
  1392. _thisProjectFunction.compositions = [];
  1393. _thisProjectFunction.currentFrame = 0;
  1394. _thisProjectFunction.registerComposition = registerComposition;
  1395. return _thisProjectFunction;
  1396. };
  1397. }();
  1398. var renderers = {};
  1399. var registerRenderer = function registerRenderer(key, value) {
  1400. renderers[key] = value;
  1401. };
  1402. function getRenderer(key) {
  1403. return renderers[key];
  1404. }
  1405. function getRegisteredRenderer() {
  1406. // Returns canvas by default for compatibility
  1407. if (renderers.canvas) {
  1408. return 'canvas';
  1409. }
  1410. // Returns any renderer that is registered
  1411. for (var key in renderers) {
  1412. if (renderers[key]) {
  1413. return key;
  1414. }
  1415. }
  1416. return '';
  1417. }
  1418. function _typeof$1(o) { "@babel/helpers - typeof"; return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$1(o); }
  1419. var AnimationItem = function AnimationItem() {
  1420. this._cbs = [];
  1421. this.name = '';
  1422. this.path = '';
  1423. this.isLoaded = false;
  1424. this.currentFrame = 0;
  1425. this.currentRawFrame = 0;
  1426. this.firstFrame = 0;
  1427. this.totalFrames = 0;
  1428. this.frameRate = 0;
  1429. this.frameMult = 0;
  1430. this.playSpeed = 1;
  1431. this.playDirection = 1;
  1432. this.playCount = 0;
  1433. this.animationData = {};
  1434. this.assets = [];
  1435. this.isPaused = true;
  1436. this.autoplay = false;
  1437. this.loop = true;
  1438. this.renderer = null;
  1439. this.animationID = createElementID();
  1440. this.assetsPath = '';
  1441. this.timeCompleted = 0;
  1442. this.segmentPos = 0;
  1443. this.isSubframeEnabled = getSubframeEnabled();
  1444. this.segments = [];
  1445. this._idle = true;
  1446. this._completedLoop = false;
  1447. this.projectInterface = ProjectInterface();
  1448. this.imagePreloader = new ImagePreloader();
  1449. this.audioController = audioControllerFactory();
  1450. this.markers = [];
  1451. this.configAnimation = this.configAnimation.bind(this);
  1452. this.onSetupError = this.onSetupError.bind(this);
  1453. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1454. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1455. this.expressionsPlugin = getExpressionsPlugin();
  1456. };
  1457. extendPrototype([BaseEvent], AnimationItem);
  1458. AnimationItem.prototype.setParams = function (params) {
  1459. if (params.wrapper || params.container) {
  1460. this.wrapper = params.wrapper || params.container;
  1461. }
  1462. var animType = 'svg';
  1463. if (params.animType) {
  1464. animType = params.animType;
  1465. } else if (params.renderer) {
  1466. animType = params.renderer;
  1467. }
  1468. var RendererClass = getRenderer(animType);
  1469. this.renderer = new RendererClass(this, params.rendererSettings);
  1470. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1471. this.renderer.setProjectInterface(this.projectInterface);
  1472. this.animType = animType;
  1473. if (params.loop === '' || params.loop === null || params.loop === undefined || params.loop === true) {
  1474. this.loop = true;
  1475. } else if (params.loop === false) {
  1476. this.loop = false;
  1477. } else {
  1478. this.loop = parseInt(params.loop, 10);
  1479. }
  1480. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1481. this.name = params.name ? params.name : '';
  1482. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1483. this.assetsPath = params.assetsPath;
  1484. this.initialSegment = params.initialSegment;
  1485. if (params.audioFactory) {
  1486. this.audioController.setAudioFactory(params.audioFactory);
  1487. }
  1488. if (params.animationData) {
  1489. this.setupAnimation(params.animationData);
  1490. } else if (params.path) {
  1491. if (params.path.lastIndexOf('\\') !== -1) {
  1492. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1493. } else {
  1494. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1495. }
  1496. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1497. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1498. dataManager.loadAnimation(params.path, this.configAnimation, this.onSetupError);
  1499. }
  1500. };
  1501. AnimationItem.prototype.onSetupError = function () {
  1502. this.trigger('data_failed');
  1503. };
  1504. AnimationItem.prototype.setupAnimation = function (data) {
  1505. dataManager.completeAnimation(data, this.configAnimation);
  1506. };
  1507. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1508. if (animationData) {
  1509. if (_typeof$1(animationData) !== 'object') {
  1510. animationData = JSON.parse(animationData);
  1511. }
  1512. }
  1513. var params = {
  1514. wrapper: wrapper,
  1515. animationData: animationData
  1516. };
  1517. var wrapperAttributes = wrapper.attributes;
  1518. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1519. ? wrapperAttributes.getNamedItem('data-animation-path').value : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1520. ? wrapperAttributes.getNamedItem('data-bm-path').value : wrapperAttributes.getNamedItem('bm-path') ? wrapperAttributes.getNamedItem('bm-path').value : '';
  1521. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1522. ? wrapperAttributes.getNamedItem('data-anim-type').value : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1523. ? wrapperAttributes.getNamedItem('data-bm-type').value : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1524. ? wrapperAttributes.getNamedItem('bm-type').value : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1525. ? wrapperAttributes.getNamedItem('data-bm-renderer').value : wrapperAttributes.getNamedItem('bm-renderer') ? wrapperAttributes.getNamedItem('bm-renderer').value : getRegisteredRenderer() || 'canvas';
  1526. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1527. ? wrapperAttributes.getNamedItem('data-anim-loop').value : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1528. ? wrapperAttributes.getNamedItem('data-bm-loop').value : wrapperAttributes.getNamedItem('bm-loop') ? wrapperAttributes.getNamedItem('bm-loop').value : '';
  1529. if (loop === 'false') {
  1530. params.loop = false;
  1531. } else if (loop === 'true') {
  1532. params.loop = true;
  1533. } else if (loop !== '') {
  1534. params.loop = parseInt(loop, 10);
  1535. }
  1536. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1537. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1538. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value : wrapperAttributes.getNamedItem('bm-autoplay') ? wrapperAttributes.getNamedItem('bm-autoplay').value : true;
  1539. params.autoplay = autoplay !== 'false';
  1540. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1541. ? wrapperAttributes.getNamedItem('data-name').value : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1542. ? wrapperAttributes.getNamedItem('data-bm-name').value : wrapperAttributes.getNamedItem('bm-name') ? wrapperAttributes.getNamedItem('bm-name').value : '';
  1543. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1544. ? wrapperAttributes.getNamedItem('data-anim-prerender').value : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1545. ? wrapperAttributes.getNamedItem('data-bm-prerender').value : wrapperAttributes.getNamedItem('bm-prerender') ? wrapperAttributes.getNamedItem('bm-prerender').value : '';
  1546. if (prerender === 'false') {
  1547. params.prerender = false;
  1548. }
  1549. if (!params.path) {
  1550. this.trigger('destroy');
  1551. } else {
  1552. this.setParams(params);
  1553. }
  1554. };
  1555. AnimationItem.prototype.includeLayers = function (data) {
  1556. if (data.op > this.animationData.op) {
  1557. this.animationData.op = data.op;
  1558. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1559. }
  1560. var layers = this.animationData.layers;
  1561. var i;
  1562. var len = layers.length;
  1563. var newLayers = data.layers;
  1564. var j;
  1565. var jLen = newLayers.length;
  1566. for (j = 0; j < jLen; j += 1) {
  1567. i = 0;
  1568. while (i < len) {
  1569. if (layers[i].id === newLayers[j].id) {
  1570. layers[i] = newLayers[j];
  1571. break;
  1572. }
  1573. i += 1;
  1574. }
  1575. }
  1576. if (data.chars || data.fonts) {
  1577. this.renderer.globalData.fontManager.addChars(data.chars);
  1578. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1579. }
  1580. if (data.assets) {
  1581. len = data.assets.length;
  1582. for (i = 0; i < len; i += 1) {
  1583. this.animationData.assets.push(data.assets[i]);
  1584. }
  1585. }
  1586. this.animationData.__complete = false;
  1587. dataManager.completeAnimation(this.animationData, this.onSegmentComplete);
  1588. };
  1589. AnimationItem.prototype.onSegmentComplete = function (data) {
  1590. this.animationData = data;
  1591. var expressionsPlugin = getExpressionsPlugin();
  1592. if (expressionsPlugin) {
  1593. expressionsPlugin.initExpressions(this);
  1594. }
  1595. this.loadNextSegment();
  1596. };
  1597. AnimationItem.prototype.loadNextSegment = function () {
  1598. var segments = this.animationData.segments;
  1599. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1600. this.trigger('data_ready');
  1601. this.timeCompleted = this.totalFrames;
  1602. return;
  1603. }
  1604. var segment = segments.shift();
  1605. this.timeCompleted = segment.time * this.frameRate;
  1606. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1607. this.segmentPos += 1;
  1608. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1609. this.trigger('data_failed');
  1610. }.bind(this));
  1611. };
  1612. AnimationItem.prototype.loadSegments = function () {
  1613. var segments = this.animationData.segments;
  1614. if (!segments) {
  1615. this.timeCompleted = this.totalFrames;
  1616. }
  1617. this.loadNextSegment();
  1618. };
  1619. AnimationItem.prototype.imagesLoaded = function () {
  1620. this.trigger('loaded_images');
  1621. this.checkLoaded();
  1622. };
  1623. AnimationItem.prototype.preloadImages = function () {
  1624. this.imagePreloader.setAssetsPath(this.assetsPath);
  1625. this.imagePreloader.setPath(this.path);
  1626. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1627. };
  1628. AnimationItem.prototype.configAnimation = function (animData) {
  1629. if (!this.renderer) {
  1630. return;
  1631. }
  1632. try {
  1633. this.animationData = animData;
  1634. if (this.initialSegment) {
  1635. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1636. this.firstFrame = Math.round(this.initialSegment[0]);
  1637. } else {
  1638. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1639. this.firstFrame = Math.round(this.animationData.ip);
  1640. }
  1641. this.renderer.configAnimation(animData);
  1642. if (!animData.assets) {
  1643. animData.assets = [];
  1644. }
  1645. this.assets = this.animationData.assets;
  1646. this.frameRate = this.animationData.fr;
  1647. this.frameMult = this.animationData.fr / 1000;
  1648. this.renderer.searchExtraCompositions(animData.assets);
  1649. this.markers = markerParser(animData.markers || []);
  1650. this.trigger('config_ready');
  1651. this.preloadImages();
  1652. this.loadSegments();
  1653. this.updaFrameModifier();
  1654. this.waitForFontsLoaded();
  1655. if (this.isPaused) {
  1656. this.audioController.pause();
  1657. }
  1658. } catch (error) {
  1659. this.triggerConfigError(error);
  1660. }
  1661. };
  1662. AnimationItem.prototype.waitForFontsLoaded = function () {
  1663. if (!this.renderer) {
  1664. return;
  1665. }
  1666. if (this.renderer.globalData.fontManager.isLoaded) {
  1667. this.checkLoaded();
  1668. } else {
  1669. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1670. }
  1671. };
  1672. AnimationItem.prototype.checkLoaded = function () {
  1673. if (!this.isLoaded && this.renderer.globalData.fontManager.isLoaded && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas') && this.imagePreloader.loadedFootages()) {
  1674. this.isLoaded = true;
  1675. var expressionsPlugin = getExpressionsPlugin();
  1676. if (expressionsPlugin) {
  1677. expressionsPlugin.initExpressions(this);
  1678. }
  1679. this.renderer.initItems();
  1680. setTimeout(function () {
  1681. this.trigger('DOMLoaded');
  1682. }.bind(this), 0);
  1683. this.gotoFrame();
  1684. if (this.autoplay) {
  1685. this.play();
  1686. }
  1687. }
  1688. };
  1689. AnimationItem.prototype.resize = function (width, height) {
  1690. // Adding this validation for backwards compatibility in case an event object was being passed down
  1691. var _width = typeof width === 'number' ? width : undefined;
  1692. var _height = typeof height === 'number' ? height : undefined;
  1693. this.renderer.updateContainerSize(_width, _height);
  1694. };
  1695. AnimationItem.prototype.setSubframe = function (flag) {
  1696. this.isSubframeEnabled = !!flag;
  1697. };
  1698. AnimationItem.prototype.gotoFrame = function () {
  1699. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1700. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1701. this.currentFrame = this.timeCompleted;
  1702. }
  1703. this.trigger('enterFrame');
  1704. this.renderFrame();
  1705. this.trigger('drawnFrame');
  1706. };
  1707. AnimationItem.prototype.renderFrame = function () {
  1708. if (this.isLoaded === false || !this.renderer) {
  1709. return;
  1710. }
  1711. try {
  1712. if (this.expressionsPlugin) {
  1713. this.expressionsPlugin.resetFrame();
  1714. }
  1715. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1716. } catch (error) {
  1717. this.triggerRenderFrameError(error);
  1718. }
  1719. };
  1720. AnimationItem.prototype.play = function (name) {
  1721. if (name && this.name !== name) {
  1722. return;
  1723. }
  1724. if (this.isPaused === true) {
  1725. this.isPaused = false;
  1726. this.trigger('_play');
  1727. this.audioController.resume();
  1728. if (this._idle) {
  1729. this._idle = false;
  1730. this.trigger('_active');
  1731. }
  1732. }
  1733. };
  1734. AnimationItem.prototype.pause = function (name) {
  1735. if (name && this.name !== name) {
  1736. return;
  1737. }
  1738. if (this.isPaused === false) {
  1739. this.isPaused = true;
  1740. this.trigger('_pause');
  1741. this._idle = true;
  1742. this.trigger('_idle');
  1743. this.audioController.pause();
  1744. }
  1745. };
  1746. AnimationItem.prototype.togglePause = function (name) {
  1747. if (name && this.name !== name) {
  1748. return;
  1749. }
  1750. if (this.isPaused === true) {
  1751. this.play();
  1752. } else {
  1753. this.pause();
  1754. }
  1755. };
  1756. AnimationItem.prototype.stop = function (name) {
  1757. if (name && this.name !== name) {
  1758. return;
  1759. }
  1760. this.pause();
  1761. this.playCount = 0;
  1762. this._completedLoop = false;
  1763. this.setCurrentRawFrameValue(0);
  1764. };
  1765. AnimationItem.prototype.getMarkerData = function (markerName) {
  1766. var marker;
  1767. for (var i = 0; i < this.markers.length; i += 1) {
  1768. marker = this.markers[i];
  1769. if (marker.payload && marker.payload.name === markerName) {
  1770. return marker;
  1771. }
  1772. }
  1773. return null;
  1774. };
  1775. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1776. if (name && this.name !== name) {
  1777. return;
  1778. }
  1779. var numValue = Number(value);
  1780. if (isNaN(numValue)) {
  1781. var marker = this.getMarkerData(value);
  1782. if (marker) {
  1783. this.goToAndStop(marker.time, true);
  1784. }
  1785. } else if (isFrame) {
  1786. this.setCurrentRawFrameValue(value);
  1787. } else {
  1788. this.setCurrentRawFrameValue(value * this.frameModifier);
  1789. }
  1790. this.pause();
  1791. };
  1792. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1793. if (name && this.name !== name) {
  1794. return;
  1795. }
  1796. var numValue = Number(value);
  1797. if (isNaN(numValue)) {
  1798. var marker = this.getMarkerData(value);
  1799. if (marker) {
  1800. if (!marker.duration) {
  1801. this.goToAndStop(marker.time, true);
  1802. } else {
  1803. this.playSegments([marker.time, marker.time + marker.duration], true);
  1804. }
  1805. }
  1806. } else {
  1807. this.goToAndStop(numValue, isFrame, name);
  1808. }
  1809. this.play();
  1810. };
  1811. AnimationItem.prototype.advanceTime = function (value) {
  1812. if (this.isPaused === true || this.isLoaded === false) {
  1813. return;
  1814. }
  1815. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1816. var _isComplete = false;
  1817. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1818. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1819. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1820. if (!this.loop || this.playCount === this.loop) {
  1821. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1822. _isComplete = true;
  1823. nextValue = this.totalFrames - 1;
  1824. }
  1825. } else if (nextValue >= this.totalFrames) {
  1826. this.playCount += 1;
  1827. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1828. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1829. this._completedLoop = true;
  1830. this.trigger('loopComplete');
  1831. }
  1832. } else {
  1833. this.setCurrentRawFrameValue(nextValue);
  1834. }
  1835. } else if (nextValue < 0) {
  1836. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1837. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) {
  1838. // eslint-disable-line no-plusplus
  1839. this.setCurrentRawFrameValue(this.totalFrames + nextValue % this.totalFrames);
  1840. if (!this._completedLoop) {
  1841. this._completedLoop = true;
  1842. } else {
  1843. this.trigger('loopComplete');
  1844. }
  1845. } else {
  1846. _isComplete = true;
  1847. nextValue = 0;
  1848. }
  1849. }
  1850. } else {
  1851. this.setCurrentRawFrameValue(nextValue);
  1852. }
  1853. if (_isComplete) {
  1854. this.setCurrentRawFrameValue(nextValue);
  1855. this.pause();
  1856. this.trigger('complete');
  1857. }
  1858. };
  1859. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1860. this.playCount = 0;
  1861. if (arr[1] < arr[0]) {
  1862. if (this.frameModifier > 0) {
  1863. if (this.playSpeed < 0) {
  1864. this.setSpeed(-this.playSpeed);
  1865. } else {
  1866. this.setDirection(-1);
  1867. }
  1868. }
  1869. this.totalFrames = arr[0] - arr[1];
  1870. this.timeCompleted = this.totalFrames;
  1871. this.firstFrame = arr[1];
  1872. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1873. } else if (arr[1] > arr[0]) {
  1874. if (this.frameModifier < 0) {
  1875. if (this.playSpeed < 0) {
  1876. this.setSpeed(-this.playSpeed);
  1877. } else {
  1878. this.setDirection(1);
  1879. }
  1880. }
  1881. this.totalFrames = arr[1] - arr[0];
  1882. this.timeCompleted = this.totalFrames;
  1883. this.firstFrame = arr[0];
  1884. this.setCurrentRawFrameValue(0.001 + offset);
  1885. }
  1886. this.trigger('segmentStart');
  1887. };
  1888. AnimationItem.prototype.setSegment = function (init, end) {
  1889. var pendingFrame = -1;
  1890. if (this.isPaused) {
  1891. if (this.currentRawFrame + this.firstFrame < init) {
  1892. pendingFrame = init;
  1893. } else if (this.currentRawFrame + this.firstFrame > end) {
  1894. pendingFrame = end - init;
  1895. }
  1896. }
  1897. this.firstFrame = init;
  1898. this.totalFrames = end - init;
  1899. this.timeCompleted = this.totalFrames;
  1900. if (pendingFrame !== -1) {
  1901. this.goToAndStop(pendingFrame, true);
  1902. }
  1903. };
  1904. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1905. if (forceFlag) {
  1906. this.segments.length = 0;
  1907. }
  1908. if (_typeof$1(arr[0]) === 'object') {
  1909. var i;
  1910. var len = arr.length;
  1911. for (i = 0; i < len; i += 1) {
  1912. this.segments.push(arr[i]);
  1913. }
  1914. } else {
  1915. this.segments.push(arr);
  1916. }
  1917. if (this.segments.length && forceFlag) {
  1918. this.adjustSegment(this.segments.shift(), 0);
  1919. }
  1920. if (this.isPaused) {
  1921. this.play();
  1922. }
  1923. };
  1924. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1925. this.segments.length = 0;
  1926. this.segments.push([this.animationData.ip, this.animationData.op]);
  1927. if (forceFlag) {
  1928. this.checkSegments(0);
  1929. }
  1930. };
  1931. AnimationItem.prototype.checkSegments = function (offset) {
  1932. if (this.segments.length) {
  1933. this.adjustSegment(this.segments.shift(), offset);
  1934. return true;
  1935. }
  1936. return false;
  1937. };
  1938. AnimationItem.prototype.destroy = function (name) {
  1939. if (name && this.name !== name || !this.renderer) {
  1940. return;
  1941. }
  1942. this.renderer.destroy();
  1943. this.imagePreloader.destroy();
  1944. this.trigger('destroy');
  1945. this._cbs = null;
  1946. this.onEnterFrame = null;
  1947. this.onLoopComplete = null;
  1948. this.onComplete = null;
  1949. this.onSegmentStart = null;
  1950. this.onDestroy = null;
  1951. this.renderer = null;
  1952. this.expressionsPlugin = null;
  1953. this.imagePreloader = null;
  1954. this.projectInterface = null;
  1955. };
  1956. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1957. this.currentRawFrame = value;
  1958. this.gotoFrame();
  1959. };
  1960. AnimationItem.prototype.setSpeed = function (val) {
  1961. this.playSpeed = val;
  1962. this.updaFrameModifier();
  1963. };
  1964. AnimationItem.prototype.setDirection = function (val) {
  1965. this.playDirection = val < 0 ? -1 : 1;
  1966. this.updaFrameModifier();
  1967. };
  1968. AnimationItem.prototype.setLoop = function (isLooping) {
  1969. this.loop = isLooping;
  1970. };
  1971. AnimationItem.prototype.setVolume = function (val, name) {
  1972. if (name && this.name !== name) {
  1973. return;
  1974. }
  1975. this.audioController.setVolume(val);
  1976. };
  1977. AnimationItem.prototype.getVolume = function () {
  1978. return this.audioController.getVolume();
  1979. };
  1980. AnimationItem.prototype.mute = function (name) {
  1981. if (name && this.name !== name) {
  1982. return;
  1983. }
  1984. this.audioController.mute();
  1985. };
  1986. AnimationItem.prototype.unmute = function (name) {
  1987. if (name && this.name !== name) {
  1988. return;
  1989. }
  1990. this.audioController.unmute();
  1991. };
  1992. AnimationItem.prototype.updaFrameModifier = function () {
  1993. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1994. this.audioController.setRate(this.playSpeed * this.playDirection);
  1995. };
  1996. AnimationItem.prototype.getPath = function () {
  1997. return this.path;
  1998. };
  1999. AnimationItem.prototype.getAssetsPath = function (assetData) {
  2000. var path = '';
  2001. if (assetData.e) {
  2002. path = assetData.p;
  2003. } else if (this.assetsPath) {
  2004. var imagePath = assetData.p;
  2005. if (imagePath.indexOf('images/') !== -1) {
  2006. imagePath = imagePath.split('/')[1];
  2007. }
  2008. path = this.assetsPath + imagePath;
  2009. } else {
  2010. path = this.path;
  2011. path += assetData.u ? assetData.u : '';
  2012. path += assetData.p;
  2013. }
  2014. return path;
  2015. };
  2016. AnimationItem.prototype.getAssetData = function (id) {
  2017. var i = 0;
  2018. var len = this.assets.length;
  2019. while (i < len) {
  2020. if (id === this.assets[i].id) {
  2021. return this.assets[i];
  2022. }
  2023. i += 1;
  2024. }
  2025. return null;
  2026. };
  2027. AnimationItem.prototype.hide = function () {
  2028. this.renderer.hide();
  2029. };
  2030. AnimationItem.prototype.show = function () {
  2031. this.renderer.show();
  2032. };
  2033. AnimationItem.prototype.getDuration = function (isFrame) {
  2034. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  2035. };
  2036. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  2037. try {
  2038. var element = this.renderer.getElementByPath(path);
  2039. element.updateDocumentData(documentData, index);
  2040. } catch (error) {
  2041. // TODO: decide how to handle catch case
  2042. }
  2043. };
  2044. AnimationItem.prototype.trigger = function (name) {
  2045. if (this._cbs && this._cbs[name]) {
  2046. switch (name) {
  2047. case 'enterFrame':
  2048. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  2049. break;
  2050. case 'drawnFrame':
  2051. this.drawnFrameEvent.currentTime = this.currentFrame;
  2052. this.drawnFrameEvent.totalTime = this.totalFrames;
  2053. this.drawnFrameEvent.direction = this.frameModifier;
  2054. this.triggerEvent(name, this.drawnFrameEvent);
  2055. break;
  2056. case 'loopComplete':
  2057. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2058. break;
  2059. case 'complete':
  2060. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  2061. break;
  2062. case 'segmentStart':
  2063. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2064. break;
  2065. case 'destroy':
  2066. this.triggerEvent(name, new BMDestroyEvent(name, this));
  2067. break;
  2068. default:
  2069. this.triggerEvent(name);
  2070. }
  2071. }
  2072. if (name === 'enterFrame' && this.onEnterFrame) {
  2073. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  2074. }
  2075. if (name === 'loopComplete' && this.onLoopComplete) {
  2076. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2077. }
  2078. if (name === 'complete' && this.onComplete) {
  2079. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  2080. }
  2081. if (name === 'segmentStart' && this.onSegmentStart) {
  2082. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2083. }
  2084. if (name === 'destroy' && this.onDestroy) {
  2085. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  2086. }
  2087. };
  2088. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  2089. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2090. this.triggerEvent('error', error);
  2091. if (this.onError) {
  2092. this.onError.call(this, error);
  2093. }
  2094. };
  2095. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2096. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2097. this.triggerEvent('error', error);
  2098. if (this.onError) {
  2099. this.onError.call(this, error);
  2100. }
  2101. };
  2102. var animationManager = function () {
  2103. var moduleOb = {};
  2104. var registeredAnimations = [];
  2105. var initTime = 0;
  2106. var len = 0;
  2107. var playingAnimationsNum = 0;
  2108. var _stopped = true;
  2109. var _isFrozen = false;
  2110. function removeElement(ev) {
  2111. var i = 0;
  2112. var animItem = ev.target;
  2113. while (i < len) {
  2114. if (registeredAnimations[i].animation === animItem) {
  2115. registeredAnimations.splice(i, 1);
  2116. i -= 1;
  2117. len -= 1;
  2118. if (!animItem.isPaused) {
  2119. subtractPlayingCount();
  2120. }
  2121. }
  2122. i += 1;
  2123. }
  2124. }
  2125. function registerAnimation(element, animationData) {
  2126. if (!element) {
  2127. return null;
  2128. }
  2129. var i = 0;
  2130. while (i < len) {
  2131. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2132. return registeredAnimations[i].animation;
  2133. }
  2134. i += 1;
  2135. }
  2136. var animItem = new AnimationItem();
  2137. setupAnimation(animItem, element);
  2138. animItem.setData(element, animationData);
  2139. return animItem;
  2140. }
  2141. function getRegisteredAnimations() {
  2142. var i;
  2143. var lenAnims = registeredAnimations.length;
  2144. var animations = [];
  2145. for (i = 0; i < lenAnims; i += 1) {
  2146. animations.push(registeredAnimations[i].animation);
  2147. }
  2148. return animations;
  2149. }
  2150. function addPlayingCount() {
  2151. playingAnimationsNum += 1;
  2152. activate();
  2153. }
  2154. function subtractPlayingCount() {
  2155. playingAnimationsNum -= 1;
  2156. }
  2157. function setupAnimation(animItem, element) {
  2158. animItem.addEventListener('destroy', removeElement);
  2159. animItem.addEventListener('_active', addPlayingCount);
  2160. animItem.addEventListener('_idle', subtractPlayingCount);
  2161. registeredAnimations.push({
  2162. elem: element,
  2163. animation: animItem
  2164. });
  2165. len += 1;
  2166. }
  2167. function loadAnimation(params) {
  2168. var animItem = new AnimationItem();
  2169. setupAnimation(animItem, null);
  2170. animItem.setParams(params);
  2171. return animItem;
  2172. }
  2173. function setSpeed(val, animation) {
  2174. var i;
  2175. for (i = 0; i < len; i += 1) {
  2176. registeredAnimations[i].animation.setSpeed(val, animation);
  2177. }
  2178. }
  2179. function setDirection(val, animation) {
  2180. var i;
  2181. for (i = 0; i < len; i += 1) {
  2182. registeredAnimations[i].animation.setDirection(val, animation);
  2183. }
  2184. }
  2185. function play(animation) {
  2186. var i;
  2187. for (i = 0; i < len; i += 1) {
  2188. registeredAnimations[i].animation.play(animation);
  2189. }
  2190. }
  2191. function resume(nowTime) {
  2192. var elapsedTime = nowTime - initTime;
  2193. var i;
  2194. for (i = 0; i < len; i += 1) {
  2195. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2196. }
  2197. initTime = nowTime;
  2198. if (playingAnimationsNum && !_isFrozen) {
  2199. window.requestAnimationFrame(resume);
  2200. } else {
  2201. _stopped = true;
  2202. }
  2203. }
  2204. function first(nowTime) {
  2205. initTime = nowTime;
  2206. window.requestAnimationFrame(resume);
  2207. }
  2208. function pause(animation) {
  2209. var i;
  2210. for (i = 0; i < len; i += 1) {
  2211. registeredAnimations[i].animation.pause(animation);
  2212. }
  2213. }
  2214. function goToAndStop(value, isFrame, animation) {
  2215. var i;
  2216. for (i = 0; i < len; i += 1) {
  2217. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2218. }
  2219. }
  2220. function stop(animation) {
  2221. var i;
  2222. for (i = 0; i < len; i += 1) {
  2223. registeredAnimations[i].animation.stop(animation);
  2224. }
  2225. }
  2226. function togglePause(animation) {
  2227. var i;
  2228. for (i = 0; i < len; i += 1) {
  2229. registeredAnimations[i].animation.togglePause(animation);
  2230. }
  2231. }
  2232. function destroy(animation) {
  2233. var i;
  2234. for (i = len - 1; i >= 0; i -= 1) {
  2235. registeredAnimations[i].animation.destroy(animation);
  2236. }
  2237. }
  2238. function searchAnimations(animationData, standalone, renderer) {
  2239. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')), [].slice.call(document.getElementsByClassName('bodymovin')));
  2240. var i;
  2241. var lenAnims = animElements.length;
  2242. for (i = 0; i < lenAnims; i += 1) {
  2243. if (renderer) {
  2244. animElements[i].setAttribute('data-bm-type', renderer);
  2245. }
  2246. registerAnimation(animElements[i], animationData);
  2247. }
  2248. if (standalone && lenAnims === 0) {
  2249. if (!renderer) {
  2250. renderer = 'svg';
  2251. }
  2252. var body = document.getElementsByTagName('body')[0];
  2253. body.innerText = '';
  2254. var div = createTag('div');
  2255. div.style.width = '100%';
  2256. div.style.height = '100%';
  2257. div.setAttribute('data-bm-type', renderer);
  2258. body.appendChild(div);
  2259. registerAnimation(div, animationData);
  2260. }
  2261. }
  2262. function resize() {
  2263. var i;
  2264. for (i = 0; i < len; i += 1) {
  2265. registeredAnimations[i].animation.resize();
  2266. }
  2267. }
  2268. function activate() {
  2269. if (!_isFrozen && playingAnimationsNum) {
  2270. if (_stopped) {
  2271. window.requestAnimationFrame(first);
  2272. _stopped = false;
  2273. }
  2274. }
  2275. }
  2276. function freeze() {
  2277. _isFrozen = true;
  2278. }
  2279. function unfreeze() {
  2280. _isFrozen = false;
  2281. activate();
  2282. }
  2283. function setVolume(val, animation) {
  2284. var i;
  2285. for (i = 0; i < len; i += 1) {
  2286. registeredAnimations[i].animation.setVolume(val, animation);
  2287. }
  2288. }
  2289. function mute(animation) {
  2290. var i;
  2291. for (i = 0; i < len; i += 1) {
  2292. registeredAnimations[i].animation.mute(animation);
  2293. }
  2294. }
  2295. function unmute(animation) {
  2296. var i;
  2297. for (i = 0; i < len; i += 1) {
  2298. registeredAnimations[i].animation.unmute(animation);
  2299. }
  2300. }
  2301. moduleOb.registerAnimation = registerAnimation;
  2302. moduleOb.loadAnimation = loadAnimation;
  2303. moduleOb.setSpeed = setSpeed;
  2304. moduleOb.setDirection = setDirection;
  2305. moduleOb.play = play;
  2306. moduleOb.pause = pause;
  2307. moduleOb.stop = stop;
  2308. moduleOb.togglePause = togglePause;
  2309. moduleOb.searchAnimations = searchAnimations;
  2310. moduleOb.resize = resize;
  2311. // moduleOb.start = start;
  2312. moduleOb.goToAndStop = goToAndStop;
  2313. moduleOb.destroy = destroy;
  2314. moduleOb.freeze = freeze;
  2315. moduleOb.unfreeze = unfreeze;
  2316. moduleOb.setVolume = setVolume;
  2317. moduleOb.mute = mute;
  2318. moduleOb.unmute = unmute;
  2319. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2320. return moduleOb;
  2321. }();
  2322. /* eslint-disable */
  2323. var BezierFactory = function () {
  2324. /**
  2325. * BezierEasing - use bezier curve for transition easing function
  2326. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2327. *
  2328. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2329. * Usage:
  2330. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2331. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2332. *
  2333. */
  2334. var ob = {};
  2335. ob.getBezierEasing = getBezierEasing;
  2336. var beziers = {};
  2337. function getBezierEasing(a, b, c, d, nm) {
  2338. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2339. if (beziers[str]) {
  2340. return beziers[str];
  2341. }
  2342. var bezEasing = new BezierEasing([a, b, c, d]);
  2343. beziers[str] = bezEasing;
  2344. return bezEasing;
  2345. }
  2346. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2347. var NEWTON_ITERATIONS = 4;
  2348. var NEWTON_MIN_SLOPE = 0.001;
  2349. var SUBDIVISION_PRECISION = 0.0000001;
  2350. var SUBDIVISION_MAX_ITERATIONS = 10;
  2351. var kSplineTableSize = 11;
  2352. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2353. var float32ArraySupported = typeof Float32Array === 'function';
  2354. function A(aA1, aA2) {
  2355. return 1.0 - 3.0 * aA2 + 3.0 * aA1;
  2356. }
  2357. function B(aA1, aA2) {
  2358. return 3.0 * aA2 - 6.0 * aA1;
  2359. }
  2360. function C(aA1) {
  2361. return 3.0 * aA1;
  2362. }
  2363. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2364. function calcBezier(aT, aA1, aA2) {
  2365. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2366. }
  2367. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2368. function getSlope(aT, aA1, aA2) {
  2369. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2370. }
  2371. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2372. var currentX,
  2373. currentT,
  2374. i = 0;
  2375. do {
  2376. currentT = aA + (aB - aA) / 2.0;
  2377. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2378. if (currentX > 0.0) {
  2379. aB = currentT;
  2380. } else {
  2381. aA = currentT;
  2382. }
  2383. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2384. return currentT;
  2385. }
  2386. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2387. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2388. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2389. if (currentSlope === 0.0) return aGuessT;
  2390. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2391. aGuessT -= currentX / currentSlope;
  2392. }
  2393. return aGuessT;
  2394. }
  2395. /**
  2396. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2397. */
  2398. function BezierEasing(points) {
  2399. this._p = points;
  2400. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2401. this._precomputed = false;
  2402. this.get = this.get.bind(this);
  2403. }
  2404. BezierEasing.prototype = {
  2405. get: function get(x) {
  2406. var mX1 = this._p[0],
  2407. mY1 = this._p[1],
  2408. mX2 = this._p[2],
  2409. mY2 = this._p[3];
  2410. if (!this._precomputed) this._precompute();
  2411. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2412. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2413. if (x === 0) return 0;
  2414. if (x === 1) return 1;
  2415. return calcBezier(this._getTForX(x), mY1, mY2);
  2416. },
  2417. // Private part
  2418. _precompute: function _precompute() {
  2419. var mX1 = this._p[0],
  2420. mY1 = this._p[1],
  2421. mX2 = this._p[2],
  2422. mY2 = this._p[3];
  2423. this._precomputed = true;
  2424. if (mX1 !== mY1 || mX2 !== mY2) {
  2425. this._calcSampleValues();
  2426. }
  2427. },
  2428. _calcSampleValues: function _calcSampleValues() {
  2429. var mX1 = this._p[0],
  2430. mX2 = this._p[2];
  2431. for (var i = 0; i < kSplineTableSize; ++i) {
  2432. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2433. }
  2434. },
  2435. /**
  2436. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2437. */
  2438. _getTForX: function _getTForX(aX) {
  2439. var mX1 = this._p[0],
  2440. mX2 = this._p[2],
  2441. mSampleValues = this._mSampleValues;
  2442. var intervalStart = 0.0;
  2443. var currentSample = 1;
  2444. var lastSample = kSplineTableSize - 1;
  2445. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2446. intervalStart += kSampleStepSize;
  2447. }
  2448. --currentSample;
  2449. // Interpolate to provide an initial guess for t
  2450. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2451. var guessForT = intervalStart + dist * kSampleStepSize;
  2452. var initialSlope = getSlope(guessForT, mX1, mX2);
  2453. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2454. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2455. }
  2456. if (initialSlope === 0.0) {
  2457. return guessForT;
  2458. }
  2459. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2460. }
  2461. };
  2462. return ob;
  2463. }();
  2464. var pooling = function () {
  2465. function _double(arr) {
  2466. return arr.concat(createSizedArray(arr.length));
  2467. }
  2468. return {
  2469. "double": _double
  2470. };
  2471. }();
  2472. var poolFactory = function () {
  2473. return function (initialLength, _create, _release) {
  2474. var _length = 0;
  2475. var _maxLength = initialLength;
  2476. var pool = createSizedArray(_maxLength);
  2477. var ob = {
  2478. newElement: newElement,
  2479. release: release
  2480. };
  2481. function newElement() {
  2482. var element;
  2483. if (_length) {
  2484. _length -= 1;
  2485. element = pool[_length];
  2486. } else {
  2487. element = _create();
  2488. }
  2489. return element;
  2490. }
  2491. function release(element) {
  2492. if (_length === _maxLength) {
  2493. pool = pooling["double"](pool);
  2494. _maxLength *= 2;
  2495. }
  2496. if (_release) {
  2497. _release(element);
  2498. }
  2499. pool[_length] = element;
  2500. _length += 1;
  2501. }
  2502. return ob;
  2503. };
  2504. }();
  2505. var bezierLengthPool = function () {
  2506. function create() {
  2507. return {
  2508. addedLength: 0,
  2509. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2510. lengths: createTypedArray('float32', getDefaultCurveSegments())
  2511. };
  2512. }
  2513. return poolFactory(8, create);
  2514. }();
  2515. var segmentsLengthPool = function () {
  2516. function create() {
  2517. return {
  2518. lengths: [],
  2519. totalLength: 0
  2520. };
  2521. }
  2522. function release(element) {
  2523. var i;
  2524. var len = element.lengths.length;
  2525. for (i = 0; i < len; i += 1) {
  2526. bezierLengthPool.release(element.lengths[i]);
  2527. }
  2528. element.lengths.length = 0;
  2529. }
  2530. return poolFactory(8, create, release);
  2531. }();
  2532. function bezFunction() {
  2533. var math = Math;
  2534. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2535. var det1 = x1 * y2 + y1 * x3 + x2 * y3 - x3 * y2 - y3 * x1 - x2 * y1;
  2536. return det1 > -0.001 && det1 < 0.001;
  2537. }
  2538. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2539. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2540. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2541. }
  2542. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2543. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2544. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2545. var diffDist;
  2546. if (dist1 > dist2) {
  2547. if (dist1 > dist3) {
  2548. diffDist = dist1 - dist2 - dist3;
  2549. } else {
  2550. diffDist = dist3 - dist2 - dist1;
  2551. }
  2552. } else if (dist3 > dist2) {
  2553. diffDist = dist3 - dist2 - dist1;
  2554. } else {
  2555. diffDist = dist2 - dist1 - dist3;
  2556. }
  2557. return diffDist > -0.0001 && diffDist < 0.0001;
  2558. }
  2559. var getBezierLength = function () {
  2560. return function (pt1, pt2, pt3, pt4) {
  2561. var curveSegments = getDefaultCurveSegments();
  2562. var k;
  2563. var i;
  2564. var len;
  2565. var ptCoord;
  2566. var perc;
  2567. var addedLength = 0;
  2568. var ptDistance;
  2569. var point = [];
  2570. var lastPoint = [];
  2571. var lengthData = bezierLengthPool.newElement();
  2572. len = pt3.length;
  2573. for (k = 0; k < curveSegments; k += 1) {
  2574. perc = k / (curveSegments - 1);
  2575. ptDistance = 0;
  2576. for (i = 0; i < len; i += 1) {
  2577. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * pt3[i] + 3 * (1 - perc) * bmPow(perc, 2) * pt4[i] + bmPow(perc, 3) * pt2[i];
  2578. point[i] = ptCoord;
  2579. if (lastPoint[i] !== null) {
  2580. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2581. }
  2582. lastPoint[i] = point[i];
  2583. }
  2584. if (ptDistance) {
  2585. ptDistance = bmSqrt(ptDistance);
  2586. addedLength += ptDistance;
  2587. }
  2588. lengthData.percents[k] = perc;
  2589. lengthData.lengths[k] = addedLength;
  2590. }
  2591. lengthData.addedLength = addedLength;
  2592. return lengthData;
  2593. };
  2594. }();
  2595. function getSegmentsLength(shapeData) {
  2596. var segmentsLength = segmentsLengthPool.newElement();
  2597. var closed = shapeData.c;
  2598. var pathV = shapeData.v;
  2599. var pathO = shapeData.o;
  2600. var pathI = shapeData.i;
  2601. var i;
  2602. var len = shapeData._length;
  2603. var lengths = segmentsLength.lengths;
  2604. var totalLength = 0;
  2605. for (i = 0; i < len - 1; i += 1) {
  2606. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2607. totalLength += lengths[i].addedLength;
  2608. }
  2609. if (closed && len) {
  2610. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2611. totalLength += lengths[i].addedLength;
  2612. }
  2613. segmentsLength.totalLength = totalLength;
  2614. return segmentsLength;
  2615. }
  2616. function BezierData(length) {
  2617. this.segmentLength = 0;
  2618. this.points = new Array(length);
  2619. }
  2620. function PointData(partial, point) {
  2621. this.partialLength = partial;
  2622. this.point = point;
  2623. }
  2624. var buildBezierData = function () {
  2625. var storedData = {};
  2626. return function (pt1, pt2, pt3, pt4) {
  2627. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2628. if (!storedData[bezierName]) {
  2629. var curveSegments = getDefaultCurveSegments();
  2630. var k;
  2631. var i;
  2632. var len;
  2633. var ptCoord;
  2634. var perc;
  2635. var addedLength = 0;
  2636. var ptDistance;
  2637. var point;
  2638. var lastPoint = null;
  2639. if (pt1.length === 2 && (pt1[0] !== pt2[0] || pt1[1] !== pt2[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt1[0] + pt3[0], pt1[1] + pt3[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt2[0] + pt4[0], pt2[1] + pt4[1])) {
  2640. curveSegments = 2;
  2641. }
  2642. var bezierData = new BezierData(curveSegments);
  2643. len = pt3.length;
  2644. for (k = 0; k < curveSegments; k += 1) {
  2645. point = createSizedArray(len);
  2646. perc = k / (curveSegments - 1);
  2647. ptDistance = 0;
  2648. for (i = 0; i < len; i += 1) {
  2649. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * (pt1[i] + pt3[i]) + 3 * (1 - perc) * bmPow(perc, 2) * (pt2[i] + pt4[i]) + bmPow(perc, 3) * pt2[i];
  2650. point[i] = ptCoord;
  2651. if (lastPoint !== null) {
  2652. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2653. }
  2654. }
  2655. ptDistance = bmSqrt(ptDistance);
  2656. addedLength += ptDistance;
  2657. bezierData.points[k] = new PointData(ptDistance, point);
  2658. lastPoint = point;
  2659. }
  2660. bezierData.segmentLength = addedLength;
  2661. storedData[bezierName] = bezierData;
  2662. }
  2663. return storedData[bezierName];
  2664. };
  2665. }();
  2666. function getDistancePerc(perc, bezierData) {
  2667. var percents = bezierData.percents;
  2668. var lengths = bezierData.lengths;
  2669. var len = percents.length;
  2670. var initPos = bmFloor((len - 1) * perc);
  2671. var lengthPos = perc * bezierData.addedLength;
  2672. var lPerc = 0;
  2673. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2674. return percents[initPos];
  2675. }
  2676. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2677. var flag = true;
  2678. while (flag) {
  2679. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2680. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2681. flag = false;
  2682. } else {
  2683. initPos += dir;
  2684. }
  2685. if (initPos < 0 || initPos >= len - 1) {
  2686. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2687. if (initPos === len - 1) {
  2688. return percents[initPos];
  2689. }
  2690. flag = false;
  2691. }
  2692. }
  2693. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2694. }
  2695. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2696. var t1 = getDistancePerc(percent, bezierData);
  2697. var u1 = 1 - t1;
  2698. var ptX = math.round((u1 * u1 * u1 * pt1[0] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[0] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[0] + t1 * t1 * t1 * pt2[0]) * 1000) / 1000;
  2699. var ptY = math.round((u1 * u1 * u1 * pt1[1] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[1] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[1] + t1 * t1 * t1 * pt2[1]) * 1000) / 1000;
  2700. return [ptX, ptY];
  2701. }
  2702. var bezierSegmentPoints = createTypedArray('float32', 8);
  2703. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2704. if (startPerc < 0) {
  2705. startPerc = 0;
  2706. } else if (startPerc > 1) {
  2707. startPerc = 1;
  2708. }
  2709. var t0 = getDistancePerc(startPerc, bezierData);
  2710. endPerc = endPerc > 1 ? 1 : endPerc;
  2711. var t1 = getDistancePerc(endPerc, bezierData);
  2712. var i;
  2713. var len = pt1.length;
  2714. var u0 = 1 - t0;
  2715. var u1 = 1 - t1;
  2716. var u0u0u0 = u0 * u0 * u0;
  2717. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2718. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2719. var t0t0t0 = t0 * t0 * t0;
  2720. //
  2721. var u0u0u1 = u0 * u0 * u1;
  2722. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2723. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2724. var t0t0t1 = t0 * t0 * t1;
  2725. //
  2726. var u0u1u1 = u0 * u1 * u1;
  2727. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2728. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2729. var t0t1t1 = t0 * t1 * t1;
  2730. //
  2731. var u1u1u1 = u1 * u1 * u1;
  2732. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2733. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2734. var t1t1t1 = t1 * t1 * t1;
  2735. for (i = 0; i < len; i += 1) {
  2736. bezierSegmentPoints[i * 4] = math.round((u0u0u0 * pt1[i] + t0u0u0_3 * pt3[i] + t0t0u0_3 * pt4[i] + t0t0t0 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2737. bezierSegmentPoints[i * 4 + 1] = math.round((u0u0u1 * pt1[i] + t0u0u1_3 * pt3[i] + t0t0u1_3 * pt4[i] + t0t0t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2738. bezierSegmentPoints[i * 4 + 2] = math.round((u0u1u1 * pt1[i] + t0u1u1_3 * pt3[i] + t0t1u1_3 * pt4[i] + t0t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2739. bezierSegmentPoints[i * 4 + 3] = math.round((u1u1u1 * pt1[i] + t1u1u1_3 * pt3[i] + t1t1u1_3 * pt4[i] + t1t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2740. }
  2741. return bezierSegmentPoints;
  2742. }
  2743. return {
  2744. getSegmentsLength: getSegmentsLength,
  2745. getNewSegment: getNewSegment,
  2746. getPointInSegment: getPointInSegment,
  2747. buildBezierData: buildBezierData,
  2748. pointOnLine2D: pointOnLine2D,
  2749. pointOnLine3D: pointOnLine3D
  2750. };
  2751. }
  2752. var bez = bezFunction();
  2753. var initFrame = initialDefaultFrame;
  2754. var mathAbs = Math.abs;
  2755. function interpolateValue(frameNum, caching) {
  2756. var offsetTime = this.offsetTime;
  2757. var newValue;
  2758. if (this.propType === 'multidimensional') {
  2759. newValue = createTypedArray('float32', this.pv.length);
  2760. }
  2761. var iterationIndex = caching.lastIndex;
  2762. var i = iterationIndex;
  2763. var len = this.keyframes.length - 1;
  2764. var flag = true;
  2765. var keyData;
  2766. var nextKeyData;
  2767. var keyframeMetadata;
  2768. while (flag) {
  2769. keyData = this.keyframes[i];
  2770. nextKeyData = this.keyframes[i + 1];
  2771. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2772. if (keyData.h) {
  2773. keyData = nextKeyData;
  2774. }
  2775. iterationIndex = 0;
  2776. break;
  2777. }
  2778. if (nextKeyData.t - offsetTime > frameNum) {
  2779. iterationIndex = i;
  2780. break;
  2781. }
  2782. if (i < len - 1) {
  2783. i += 1;
  2784. } else {
  2785. iterationIndex = 0;
  2786. flag = false;
  2787. }
  2788. }
  2789. keyframeMetadata = this.keyframesMetadata[i] || {};
  2790. var k;
  2791. var kLen;
  2792. var perc;
  2793. var jLen;
  2794. var j;
  2795. var fnc;
  2796. var nextKeyTime = nextKeyData.t - offsetTime;
  2797. var keyTime = keyData.t - offsetTime;
  2798. var endValue;
  2799. if (keyData.to) {
  2800. if (!keyframeMetadata.bezierData) {
  2801. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2802. }
  2803. var bezierData = keyframeMetadata.bezierData;
  2804. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2805. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2806. kLen = bezierData.points[ind].point.length;
  2807. for (k = 0; k < kLen; k += 1) {
  2808. newValue[k] = bezierData.points[ind].point[k];
  2809. }
  2810. // caching._lastKeyframeIndex = -1;
  2811. } else {
  2812. if (keyframeMetadata.__fnct) {
  2813. fnc = keyframeMetadata.__fnct;
  2814. } else {
  2815. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2816. keyframeMetadata.__fnct = fnc;
  2817. }
  2818. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2819. var distanceInLine = bezierData.segmentLength * perc;
  2820. var segmentPerc;
  2821. var addedLength = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastAddedLength : 0;
  2822. j = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastPoint : 0;
  2823. flag = true;
  2824. jLen = bezierData.points.length;
  2825. while (flag) {
  2826. addedLength += bezierData.points[j].partialLength;
  2827. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2828. kLen = bezierData.points[j].point.length;
  2829. for (k = 0; k < kLen; k += 1) {
  2830. newValue[k] = bezierData.points[j].point[k];
  2831. }
  2832. break;
  2833. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2834. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2835. kLen = bezierData.points[j].point.length;
  2836. for (k = 0; k < kLen; k += 1) {
  2837. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2838. }
  2839. break;
  2840. }
  2841. if (j < jLen - 1) {
  2842. j += 1;
  2843. } else {
  2844. flag = false;
  2845. }
  2846. }
  2847. caching._lastPoint = j;
  2848. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2849. caching._lastKeyframeIndex = i;
  2850. }
  2851. } else {
  2852. var outX;
  2853. var outY;
  2854. var inX;
  2855. var inY;
  2856. var keyValue;
  2857. len = keyData.s.length;
  2858. endValue = nextKeyData.s || keyData.e;
  2859. if (this.sh && keyData.h !== 1) {
  2860. if (frameNum >= nextKeyTime) {
  2861. newValue[0] = endValue[0];
  2862. newValue[1] = endValue[1];
  2863. newValue[2] = endValue[2];
  2864. } else if (frameNum <= keyTime) {
  2865. newValue[0] = keyData.s[0];
  2866. newValue[1] = keyData.s[1];
  2867. newValue[2] = keyData.s[2];
  2868. } else {
  2869. var quatStart = createQuaternion(keyData.s);
  2870. var quatEnd = createQuaternion(endValue);
  2871. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2872. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2873. }
  2874. } else {
  2875. for (i = 0; i < len; i += 1) {
  2876. if (keyData.h !== 1) {
  2877. if (frameNum >= nextKeyTime) {
  2878. perc = 1;
  2879. } else if (frameNum < keyTime) {
  2880. perc = 0;
  2881. } else {
  2882. if (keyData.o.x.constructor === Array) {
  2883. if (!keyframeMetadata.__fnct) {
  2884. keyframeMetadata.__fnct = [];
  2885. }
  2886. if (!keyframeMetadata.__fnct[i]) {
  2887. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2888. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2889. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2890. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2891. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2892. keyframeMetadata.__fnct[i] = fnc;
  2893. } else {
  2894. fnc = keyframeMetadata.__fnct[i];
  2895. }
  2896. } else if (!keyframeMetadata.__fnct) {
  2897. outX = keyData.o.x;
  2898. outY = keyData.o.y;
  2899. inX = keyData.i.x;
  2900. inY = keyData.i.y;
  2901. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2902. keyData.keyframeMetadata = fnc;
  2903. } else {
  2904. fnc = keyframeMetadata.__fnct;
  2905. }
  2906. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2907. }
  2908. }
  2909. endValue = nextKeyData.s || keyData.e;
  2910. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2911. if (this.propType === 'multidimensional') {
  2912. newValue[i] = keyValue;
  2913. } else {
  2914. newValue = keyValue;
  2915. }
  2916. }
  2917. }
  2918. }
  2919. caching.lastIndex = iterationIndex;
  2920. return newValue;
  2921. }
  2922. // based on @Toji's https://github.com/toji/gl-matrix/
  2923. function slerp(a, b, t) {
  2924. var out = [];
  2925. var ax = a[0];
  2926. var ay = a[1];
  2927. var az = a[2];
  2928. var aw = a[3];
  2929. var bx = b[0];
  2930. var by = b[1];
  2931. var bz = b[2];
  2932. var bw = b[3];
  2933. var omega;
  2934. var cosom;
  2935. var sinom;
  2936. var scale0;
  2937. var scale1;
  2938. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2939. if (cosom < 0.0) {
  2940. cosom = -cosom;
  2941. bx = -bx;
  2942. by = -by;
  2943. bz = -bz;
  2944. bw = -bw;
  2945. }
  2946. if (1.0 - cosom > 0.000001) {
  2947. omega = Math.acos(cosom);
  2948. sinom = Math.sin(omega);
  2949. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2950. scale1 = Math.sin(t * omega) / sinom;
  2951. } else {
  2952. scale0 = 1.0 - t;
  2953. scale1 = t;
  2954. }
  2955. out[0] = scale0 * ax + scale1 * bx;
  2956. out[1] = scale0 * ay + scale1 * by;
  2957. out[2] = scale0 * az + scale1 * bz;
  2958. out[3] = scale0 * aw + scale1 * bw;
  2959. return out;
  2960. }
  2961. function quaternionToEuler(out, quat) {
  2962. var qx = quat[0];
  2963. var qy = quat[1];
  2964. var qz = quat[2];
  2965. var qw = quat[3];
  2966. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2967. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2968. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2969. out[0] = heading / degToRads;
  2970. out[1] = attitude / degToRads;
  2971. out[2] = bank / degToRads;
  2972. }
  2973. function createQuaternion(values) {
  2974. var heading = values[0] * degToRads;
  2975. var attitude = values[1] * degToRads;
  2976. var bank = values[2] * degToRads;
  2977. var c1 = Math.cos(heading / 2);
  2978. var c2 = Math.cos(attitude / 2);
  2979. var c3 = Math.cos(bank / 2);
  2980. var s1 = Math.sin(heading / 2);
  2981. var s2 = Math.sin(attitude / 2);
  2982. var s3 = Math.sin(bank / 2);
  2983. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2984. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2985. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2986. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2987. return [x, y, z, w];
  2988. }
  2989. function getValueAtCurrentTime() {
  2990. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2991. var initTime = this.keyframes[0].t - this.offsetTime;
  2992. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2993. if (!(frameNum === this._caching.lastFrame || this._caching.lastFrame !== initFrame && (this._caching.lastFrame >= endTime && frameNum >= endTime || this._caching.lastFrame < initTime && frameNum < initTime))) {
  2994. if (this._caching.lastFrame >= frameNum) {
  2995. this._caching._lastKeyframeIndex = -1;
  2996. this._caching.lastIndex = 0;
  2997. }
  2998. var renderResult = this.interpolateValue(frameNum, this._caching);
  2999. this.pv = renderResult;
  3000. }
  3001. this._caching.lastFrame = frameNum;
  3002. return this.pv;
  3003. }
  3004. function setVValue(val) {
  3005. var multipliedValue;
  3006. if (this.propType === 'unidimensional') {
  3007. multipliedValue = val * this.mult;
  3008. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  3009. this.v = multipliedValue;
  3010. this._mdf = true;
  3011. }
  3012. } else {
  3013. var i = 0;
  3014. var len = this.v.length;
  3015. while (i < len) {
  3016. multipliedValue = val[i] * this.mult;
  3017. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  3018. this.v[i] = multipliedValue;
  3019. this._mdf = true;
  3020. }
  3021. i += 1;
  3022. }
  3023. }
  3024. }
  3025. function processEffectsSequence() {
  3026. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  3027. return;
  3028. }
  3029. if (this.lock) {
  3030. this.setVValue(this.pv);
  3031. return;
  3032. }
  3033. this.lock = true;
  3034. this._mdf = this._isFirstFrame;
  3035. var i;
  3036. var len = this.effectsSequence.length;
  3037. var finalValue = this.kf ? this.pv : this.data.k;
  3038. for (i = 0; i < len; i += 1) {
  3039. finalValue = this.effectsSequence[i](finalValue);
  3040. }
  3041. this.setVValue(finalValue);
  3042. this._isFirstFrame = false;
  3043. this.lock = false;
  3044. this.frameId = this.elem.globalData.frameId;
  3045. }
  3046. function addEffect(effectFunction) {
  3047. this.effectsSequence.push(effectFunction);
  3048. this.container.addDynamicProperty(this);
  3049. }
  3050. function ValueProperty(elem, data, mult, container) {
  3051. this.propType = 'unidimensional';
  3052. this.mult = mult || 1;
  3053. this.data = data;
  3054. this.v = mult ? data.k * mult : data.k;
  3055. this.pv = data.k;
  3056. this._mdf = false;
  3057. this.elem = elem;
  3058. this.container = container;
  3059. this.comp = elem.comp;
  3060. this.k = false;
  3061. this.kf = false;
  3062. this.vel = 0;
  3063. this.effectsSequence = [];
  3064. this._isFirstFrame = true;
  3065. this.getValue = processEffectsSequence;
  3066. this.setVValue = setVValue;
  3067. this.addEffect = addEffect;
  3068. }
  3069. function MultiDimensionalProperty(elem, data, mult, container) {
  3070. this.propType = 'multidimensional';
  3071. this.mult = mult || 1;
  3072. this.data = data;
  3073. this._mdf = false;
  3074. this.elem = elem;
  3075. this.container = container;
  3076. this.comp = elem.comp;
  3077. this.k = false;
  3078. this.kf = false;
  3079. this.frameId = -1;
  3080. var i;
  3081. var len = data.k.length;
  3082. this.v = createTypedArray('float32', len);
  3083. this.pv = createTypedArray('float32', len);
  3084. this.vel = createTypedArray('float32', len);
  3085. for (i = 0; i < len; i += 1) {
  3086. this.v[i] = data.k[i] * this.mult;
  3087. this.pv[i] = data.k[i];
  3088. }
  3089. this._isFirstFrame = true;
  3090. this.effectsSequence = [];
  3091. this.getValue = processEffectsSequence;
  3092. this.setVValue = setVValue;
  3093. this.addEffect = addEffect;
  3094. }
  3095. function KeyframedValueProperty(elem, data, mult, container) {
  3096. this.propType = 'unidimensional';
  3097. this.keyframes = data.k;
  3098. this.keyframesMetadata = [];
  3099. this.offsetTime = elem.data.st;
  3100. this.frameId = -1;
  3101. this._caching = {
  3102. lastFrame: initFrame,
  3103. lastIndex: 0,
  3104. value: 0,
  3105. _lastKeyframeIndex: -1
  3106. };
  3107. this.k = true;
  3108. this.kf = true;
  3109. this.data = data;
  3110. this.mult = mult || 1;
  3111. this.elem = elem;
  3112. this.container = container;
  3113. this.comp = elem.comp;
  3114. this.v = initFrame;
  3115. this.pv = initFrame;
  3116. this._isFirstFrame = true;
  3117. this.getValue = processEffectsSequence;
  3118. this.setVValue = setVValue;
  3119. this.interpolateValue = interpolateValue;
  3120. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3121. this.addEffect = addEffect;
  3122. }
  3123. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3124. this.propType = 'multidimensional';
  3125. var i;
  3126. var len = data.k.length;
  3127. var s;
  3128. var e;
  3129. var to;
  3130. var ti;
  3131. for (i = 0; i < len - 1; i += 1) {
  3132. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3133. s = data.k[i].s;
  3134. e = data.k[i + 1].s;
  3135. to = data.k[i].to;
  3136. ti = data.k[i].ti;
  3137. if (s.length === 2 && !(s[0] === e[0] && s[1] === e[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], s[0] + to[0], s[1] + to[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], e[0] + ti[0], e[1] + ti[1]) || s.length === 3 && !(s[0] === e[0] && s[1] === e[1] && s[2] === e[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], s[0] + to[0], s[1] + to[1], s[2] + to[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], e[0] + ti[0], e[1] + ti[1], e[2] + ti[2])) {
  3138. data.k[i].to = null;
  3139. data.k[i].ti = null;
  3140. }
  3141. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3142. if (s.length === 2 || s[2] === e[2] && to[2] === 0 && ti[2] === 0) {
  3143. data.k[i].to = null;
  3144. data.k[i].ti = null;
  3145. }
  3146. }
  3147. }
  3148. }
  3149. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3150. this.data = data;
  3151. this.keyframes = data.k;
  3152. this.keyframesMetadata = [];
  3153. this.offsetTime = elem.data.st;
  3154. this.k = true;
  3155. this.kf = true;
  3156. this._isFirstFrame = true;
  3157. this.mult = mult || 1;
  3158. this.elem = elem;
  3159. this.container = container;
  3160. this.comp = elem.comp;
  3161. this.getValue = processEffectsSequence;
  3162. this.setVValue = setVValue;
  3163. this.interpolateValue = interpolateValue;
  3164. this.frameId = -1;
  3165. var arrLen = data.k[0].s.length;
  3166. this.v = createTypedArray('float32', arrLen);
  3167. this.pv = createTypedArray('float32', arrLen);
  3168. for (i = 0; i < arrLen; i += 1) {
  3169. this.v[i] = initFrame;
  3170. this.pv[i] = initFrame;
  3171. }
  3172. this._caching = {
  3173. lastFrame: initFrame,
  3174. lastIndex: 0,
  3175. value: createTypedArray('float32', arrLen)
  3176. };
  3177. this.addEffect = addEffect;
  3178. }
  3179. var PropertyFactory = function () {
  3180. function getProp(elem, data, type, mult, container) {
  3181. if (data.sid) {
  3182. data = elem.globalData.slotManager.getProp(data);
  3183. }
  3184. var p;
  3185. if (!data.k.length) {
  3186. p = new ValueProperty(elem, data, mult, container);
  3187. } else if (typeof data.k[0] === 'number') {
  3188. p = new MultiDimensionalProperty(elem, data, mult, container);
  3189. } else {
  3190. switch (type) {
  3191. case 0:
  3192. p = new KeyframedValueProperty(elem, data, mult, container);
  3193. break;
  3194. case 1:
  3195. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3196. break;
  3197. default:
  3198. break;
  3199. }
  3200. }
  3201. if (p.effectsSequence.length) {
  3202. container.addDynamicProperty(p);
  3203. }
  3204. return p;
  3205. }
  3206. var ob = {
  3207. getProp: getProp
  3208. };
  3209. return ob;
  3210. }();
  3211. function DynamicPropertyContainer() {}
  3212. DynamicPropertyContainer.prototype = {
  3213. addDynamicProperty: function addDynamicProperty(prop) {
  3214. if (this.dynamicProperties.indexOf(prop) === -1) {
  3215. this.dynamicProperties.push(prop);
  3216. this.container.addDynamicProperty(this);
  3217. this._isAnimated = true;
  3218. }
  3219. },
  3220. iterateDynamicProperties: function iterateDynamicProperties() {
  3221. this._mdf = false;
  3222. var i;
  3223. var len = this.dynamicProperties.length;
  3224. for (i = 0; i < len; i += 1) {
  3225. this.dynamicProperties[i].getValue();
  3226. if (this.dynamicProperties[i]._mdf) {
  3227. this._mdf = true;
  3228. }
  3229. }
  3230. },
  3231. initDynamicPropertyContainer: function initDynamicPropertyContainer(container) {
  3232. this.container = container;
  3233. this.dynamicProperties = [];
  3234. this._mdf = false;
  3235. this._isAnimated = false;
  3236. }
  3237. };
  3238. var pointPool = function () {
  3239. function create() {
  3240. return createTypedArray('float32', 2);
  3241. }
  3242. return poolFactory(8, create);
  3243. }();
  3244. function ShapePath() {
  3245. this.c = false;
  3246. this._length = 0;
  3247. this._maxLength = 8;
  3248. this.v = createSizedArray(this._maxLength);
  3249. this.o = createSizedArray(this._maxLength);
  3250. this.i = createSizedArray(this._maxLength);
  3251. }
  3252. ShapePath.prototype.setPathData = function (closed, len) {
  3253. this.c = closed;
  3254. this.setLength(len);
  3255. var i = 0;
  3256. while (i < len) {
  3257. this.v[i] = pointPool.newElement();
  3258. this.o[i] = pointPool.newElement();
  3259. this.i[i] = pointPool.newElement();
  3260. i += 1;
  3261. }
  3262. };
  3263. ShapePath.prototype.setLength = function (len) {
  3264. while (this._maxLength < len) {
  3265. this.doubleArrayLength();
  3266. }
  3267. this._length = len;
  3268. };
  3269. ShapePath.prototype.doubleArrayLength = function () {
  3270. this.v = this.v.concat(createSizedArray(this._maxLength));
  3271. this.i = this.i.concat(createSizedArray(this._maxLength));
  3272. this.o = this.o.concat(createSizedArray(this._maxLength));
  3273. this._maxLength *= 2;
  3274. };
  3275. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3276. var arr;
  3277. this._length = Math.max(this._length, pos + 1);
  3278. if (this._length >= this._maxLength) {
  3279. this.doubleArrayLength();
  3280. }
  3281. switch (type) {
  3282. case 'v':
  3283. arr = this.v;
  3284. break;
  3285. case 'i':
  3286. arr = this.i;
  3287. break;
  3288. case 'o':
  3289. arr = this.o;
  3290. break;
  3291. default:
  3292. arr = [];
  3293. break;
  3294. }
  3295. if (!arr[pos] || arr[pos] && !replace) {
  3296. arr[pos] = pointPool.newElement();
  3297. }
  3298. arr[pos][0] = x;
  3299. arr[pos][1] = y;
  3300. };
  3301. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3302. this.setXYAt(vX, vY, 'v', pos, replace);
  3303. this.setXYAt(oX, oY, 'o', pos, replace);
  3304. this.setXYAt(iX, iY, 'i', pos, replace);
  3305. };
  3306. ShapePath.prototype.reverse = function () {
  3307. var newPath = new ShapePath();
  3308. newPath.setPathData(this.c, this._length);
  3309. var vertices = this.v;
  3310. var outPoints = this.o;
  3311. var inPoints = this.i;
  3312. var init = 0;
  3313. if (this.c) {
  3314. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3315. init = 1;
  3316. }
  3317. var cnt = this._length - 1;
  3318. var len = this._length;
  3319. var i;
  3320. for (i = init; i < len; i += 1) {
  3321. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3322. cnt -= 1;
  3323. }
  3324. return newPath;
  3325. };
  3326. ShapePath.prototype.length = function () {
  3327. return this._length;
  3328. };
  3329. var shapePool = function () {
  3330. function create() {
  3331. return new ShapePath();
  3332. }
  3333. function release(shapePath) {
  3334. var len = shapePath._length;
  3335. var i;
  3336. for (i = 0; i < len; i += 1) {
  3337. pointPool.release(shapePath.v[i]);
  3338. pointPool.release(shapePath.i[i]);
  3339. pointPool.release(shapePath.o[i]);
  3340. shapePath.v[i] = null;
  3341. shapePath.i[i] = null;
  3342. shapePath.o[i] = null;
  3343. }
  3344. shapePath._length = 0;
  3345. shapePath.c = false;
  3346. }
  3347. function clone(shape) {
  3348. var cloned = factory.newElement();
  3349. var i;
  3350. var len = shape._length === undefined ? shape.v.length : shape._length;
  3351. cloned.setLength(len);
  3352. cloned.c = shape.c;
  3353. for (i = 0; i < len; i += 1) {
  3354. cloned.setTripleAt(shape.v[i][0], shape.v[i][1], shape.o[i][0], shape.o[i][1], shape.i[i][0], shape.i[i][1], i);
  3355. }
  3356. return cloned;
  3357. }
  3358. var factory = poolFactory(4, create, release);
  3359. factory.clone = clone;
  3360. return factory;
  3361. }();
  3362. function ShapeCollection() {
  3363. this._length = 0;
  3364. this._maxLength = 4;
  3365. this.shapes = createSizedArray(this._maxLength);
  3366. }
  3367. ShapeCollection.prototype.addShape = function (shapeData) {
  3368. if (this._length === this._maxLength) {
  3369. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3370. this._maxLength *= 2;
  3371. }
  3372. this.shapes[this._length] = shapeData;
  3373. this._length += 1;
  3374. };
  3375. ShapeCollection.prototype.releaseShapes = function () {
  3376. var i;
  3377. for (i = 0; i < this._length; i += 1) {
  3378. shapePool.release(this.shapes[i]);
  3379. }
  3380. this._length = 0;
  3381. };
  3382. var shapeCollectionPool = function () {
  3383. var ob = {
  3384. newShapeCollection: newShapeCollection,
  3385. release: release
  3386. };
  3387. var _length = 0;
  3388. var _maxLength = 4;
  3389. var pool = createSizedArray(_maxLength);
  3390. function newShapeCollection() {
  3391. var shapeCollection;
  3392. if (_length) {
  3393. _length -= 1;
  3394. shapeCollection = pool[_length];
  3395. } else {
  3396. shapeCollection = new ShapeCollection();
  3397. }
  3398. return shapeCollection;
  3399. }
  3400. function release(shapeCollection) {
  3401. var i;
  3402. var len = shapeCollection._length;
  3403. for (i = 0; i < len; i += 1) {
  3404. shapePool.release(shapeCollection.shapes[i]);
  3405. }
  3406. shapeCollection._length = 0;
  3407. if (_length === _maxLength) {
  3408. pool = pooling["double"](pool);
  3409. _maxLength *= 2;
  3410. }
  3411. pool[_length] = shapeCollection;
  3412. _length += 1;
  3413. }
  3414. return ob;
  3415. }();
  3416. var ShapePropertyFactory = function () {
  3417. var initFrame = -999999;
  3418. function interpolateShape(frameNum, previousValue, caching) {
  3419. var iterationIndex = caching.lastIndex;
  3420. var keyPropS;
  3421. var keyPropE;
  3422. var isHold;
  3423. var j;
  3424. var k;
  3425. var jLen;
  3426. var kLen;
  3427. var perc;
  3428. var vertexValue;
  3429. var kf = this.keyframes;
  3430. if (frameNum < kf[0].t - this.offsetTime) {
  3431. keyPropS = kf[0].s[0];
  3432. isHold = true;
  3433. iterationIndex = 0;
  3434. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3435. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3436. /* if(kf[kf.length - 1].s){
  3437. keyPropS = kf[kf.length - 1].s[0];
  3438. }else{
  3439. keyPropS = kf[kf.length - 2].e[0];
  3440. } */
  3441. isHold = true;
  3442. } else {
  3443. var i = iterationIndex;
  3444. var len = kf.length - 1;
  3445. var flag = true;
  3446. var keyData;
  3447. var nextKeyData;
  3448. var keyframeMetadata;
  3449. while (flag) {
  3450. keyData = kf[i];
  3451. nextKeyData = kf[i + 1];
  3452. if (nextKeyData.t - this.offsetTime > frameNum) {
  3453. break;
  3454. }
  3455. if (i < len - 1) {
  3456. i += 1;
  3457. } else {
  3458. flag = false;
  3459. }
  3460. }
  3461. keyframeMetadata = this.keyframesMetadata[i] || {};
  3462. isHold = keyData.h === 1;
  3463. iterationIndex = i;
  3464. if (!isHold) {
  3465. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3466. perc = 1;
  3467. } else if (frameNum < keyData.t - this.offsetTime) {
  3468. perc = 0;
  3469. } else {
  3470. var fnc;
  3471. if (keyframeMetadata.__fnct) {
  3472. fnc = keyframeMetadata.__fnct;
  3473. } else {
  3474. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3475. keyframeMetadata.__fnct = fnc;
  3476. }
  3477. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / (nextKeyData.t - this.offsetTime - (keyData.t - this.offsetTime)));
  3478. }
  3479. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3480. }
  3481. keyPropS = keyData.s[0];
  3482. }
  3483. jLen = previousValue._length;
  3484. kLen = keyPropS.i[0].length;
  3485. caching.lastIndex = iterationIndex;
  3486. for (j = 0; j < jLen; j += 1) {
  3487. for (k = 0; k < kLen; k += 1) {
  3488. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3489. previousValue.i[j][k] = vertexValue;
  3490. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3491. previousValue.o[j][k] = vertexValue;
  3492. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3493. previousValue.v[j][k] = vertexValue;
  3494. }
  3495. }
  3496. }
  3497. function interpolateShapeCurrentTime() {
  3498. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3499. var initTime = this.keyframes[0].t - this.offsetTime;
  3500. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3501. var lastFrame = this._caching.lastFrame;
  3502. if (!(lastFrame !== initFrame && (lastFrame < initTime && frameNum < initTime || lastFrame > endTime && frameNum > endTime))) {
  3503. /// /
  3504. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3505. this.interpolateShape(frameNum, this.pv, this._caching);
  3506. /// /
  3507. }
  3508. this._caching.lastFrame = frameNum;
  3509. return this.pv;
  3510. }
  3511. function resetShape() {
  3512. this.paths = this.localShapeCollection;
  3513. }
  3514. function shapesEqual(shape1, shape2) {
  3515. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3516. return false;
  3517. }
  3518. var i;
  3519. var len = shape1._length;
  3520. for (i = 0; i < len; i += 1) {
  3521. if (shape1.v[i][0] !== shape2.v[i][0] || shape1.v[i][1] !== shape2.v[i][1] || shape1.o[i][0] !== shape2.o[i][0] || shape1.o[i][1] !== shape2.o[i][1] || shape1.i[i][0] !== shape2.i[i][0] || shape1.i[i][1] !== shape2.i[i][1]) {
  3522. return false;
  3523. }
  3524. }
  3525. return true;
  3526. }
  3527. function setVValue(newPath) {
  3528. if (!shapesEqual(this.v, newPath)) {
  3529. this.v = shapePool.clone(newPath);
  3530. this.localShapeCollection.releaseShapes();
  3531. this.localShapeCollection.addShape(this.v);
  3532. this._mdf = true;
  3533. this.paths = this.localShapeCollection;
  3534. }
  3535. }
  3536. function processEffectsSequence() {
  3537. if (this.elem.globalData.frameId === this.frameId) {
  3538. return;
  3539. }
  3540. if (!this.effectsSequence.length) {
  3541. this._mdf = false;
  3542. return;
  3543. }
  3544. if (this.lock) {
  3545. this.setVValue(this.pv);
  3546. return;
  3547. }
  3548. this.lock = true;
  3549. this._mdf = false;
  3550. var finalValue;
  3551. if (this.kf) {
  3552. finalValue = this.pv;
  3553. } else if (this.data.ks) {
  3554. finalValue = this.data.ks.k;
  3555. } else {
  3556. finalValue = this.data.pt.k;
  3557. }
  3558. var i;
  3559. var len = this.effectsSequence.length;
  3560. for (i = 0; i < len; i += 1) {
  3561. finalValue = this.effectsSequence[i](finalValue);
  3562. }
  3563. this.setVValue(finalValue);
  3564. this.lock = false;
  3565. this.frameId = this.elem.globalData.frameId;
  3566. }
  3567. function ShapeProperty(elem, data, type) {
  3568. this.propType = 'shape';
  3569. this.comp = elem.comp;
  3570. this.container = elem;
  3571. this.elem = elem;
  3572. this.data = data;
  3573. this.k = false;
  3574. this.kf = false;
  3575. this._mdf = false;
  3576. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3577. this.v = shapePool.clone(pathData);
  3578. this.pv = shapePool.clone(this.v);
  3579. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3580. this.paths = this.localShapeCollection;
  3581. this.paths.addShape(this.v);
  3582. this.reset = resetShape;
  3583. this.effectsSequence = [];
  3584. }
  3585. function addEffect(effectFunction) {
  3586. this.effectsSequence.push(effectFunction);
  3587. this.container.addDynamicProperty(this);
  3588. }
  3589. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3590. ShapeProperty.prototype.getValue = processEffectsSequence;
  3591. ShapeProperty.prototype.setVValue = setVValue;
  3592. ShapeProperty.prototype.addEffect = addEffect;
  3593. function KeyframedShapeProperty(elem, data, type) {
  3594. this.propType = 'shape';
  3595. this.comp = elem.comp;
  3596. this.elem = elem;
  3597. this.container = elem;
  3598. this.offsetTime = elem.data.st;
  3599. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3600. this.keyframesMetadata = [];
  3601. this.k = true;
  3602. this.kf = true;
  3603. var len = this.keyframes[0].s[0].i.length;
  3604. this.v = shapePool.newElement();
  3605. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3606. this.pv = shapePool.clone(this.v);
  3607. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3608. this.paths = this.localShapeCollection;
  3609. this.paths.addShape(this.v);
  3610. this.lastFrame = initFrame;
  3611. this.reset = resetShape;
  3612. this._caching = {
  3613. lastFrame: initFrame,
  3614. lastIndex: 0
  3615. };
  3616. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3617. }
  3618. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3619. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3620. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3621. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3622. var EllShapeProperty = function () {
  3623. var cPoint = roundCorner;
  3624. function EllShapePropertyFactory(elem, data) {
  3625. this.v = shapePool.newElement();
  3626. this.v.setPathData(true, 4);
  3627. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3628. this.paths = this.localShapeCollection;
  3629. this.localShapeCollection.addShape(this.v);
  3630. this.d = data.d;
  3631. this.elem = elem;
  3632. this.comp = elem.comp;
  3633. this.frameId = -1;
  3634. this.initDynamicPropertyContainer(elem);
  3635. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3636. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3637. if (this.dynamicProperties.length) {
  3638. this.k = true;
  3639. } else {
  3640. this.k = false;
  3641. this.convertEllToPath();
  3642. }
  3643. }
  3644. EllShapePropertyFactory.prototype = {
  3645. reset: resetShape,
  3646. getValue: function getValue() {
  3647. if (this.elem.globalData.frameId === this.frameId) {
  3648. return;
  3649. }
  3650. this.frameId = this.elem.globalData.frameId;
  3651. this.iterateDynamicProperties();
  3652. if (this._mdf) {
  3653. this.convertEllToPath();
  3654. }
  3655. },
  3656. convertEllToPath: function convertEllToPath() {
  3657. var p0 = this.p.v[0];
  3658. var p1 = this.p.v[1];
  3659. var s0 = this.s.v[0] / 2;
  3660. var s1 = this.s.v[1] / 2;
  3661. var _cw = this.d !== 3;
  3662. var _v = this.v;
  3663. _v.v[0][0] = p0;
  3664. _v.v[0][1] = p1 - s1;
  3665. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3666. _v.v[1][1] = p1;
  3667. _v.v[2][0] = p0;
  3668. _v.v[2][1] = p1 + s1;
  3669. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3670. _v.v[3][1] = p1;
  3671. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3672. _v.i[0][1] = p1 - s1;
  3673. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3674. _v.i[1][1] = p1 - s1 * cPoint;
  3675. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3676. _v.i[2][1] = p1 + s1;
  3677. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3678. _v.i[3][1] = p1 + s1 * cPoint;
  3679. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3680. _v.o[0][1] = p1 - s1;
  3681. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3682. _v.o[1][1] = p1 + s1 * cPoint;
  3683. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3684. _v.o[2][1] = p1 + s1;
  3685. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3686. _v.o[3][1] = p1 - s1 * cPoint;
  3687. }
  3688. };
  3689. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3690. return EllShapePropertyFactory;
  3691. }();
  3692. var StarShapeProperty = function () {
  3693. function StarShapePropertyFactory(elem, data) {
  3694. this.v = shapePool.newElement();
  3695. this.v.setPathData(true, 0);
  3696. this.elem = elem;
  3697. this.comp = elem.comp;
  3698. this.data = data;
  3699. this.frameId = -1;
  3700. this.d = data.d;
  3701. this.initDynamicPropertyContainer(elem);
  3702. if (data.sy === 1) {
  3703. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3704. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3705. this.convertToPath = this.convertStarToPath;
  3706. } else {
  3707. this.convertToPath = this.convertPolygonToPath;
  3708. }
  3709. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3710. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3711. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3712. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3713. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3714. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3715. this.localShapeCollection.addShape(this.v);
  3716. this.paths = this.localShapeCollection;
  3717. if (this.dynamicProperties.length) {
  3718. this.k = true;
  3719. } else {
  3720. this.k = false;
  3721. this.convertToPath();
  3722. }
  3723. }
  3724. StarShapePropertyFactory.prototype = {
  3725. reset: resetShape,
  3726. getValue: function getValue() {
  3727. if (this.elem.globalData.frameId === this.frameId) {
  3728. return;
  3729. }
  3730. this.frameId = this.elem.globalData.frameId;
  3731. this.iterateDynamicProperties();
  3732. if (this._mdf) {
  3733. this.convertToPath();
  3734. }
  3735. },
  3736. convertStarToPath: function convertStarToPath() {
  3737. var numPts = Math.floor(this.pt.v) * 2;
  3738. var angle = Math.PI * 2 / numPts;
  3739. /* this.v.v.length = numPts;
  3740. this.v.i.length = numPts;
  3741. this.v.o.length = numPts; */
  3742. var longFlag = true;
  3743. var longRad = this.or.v;
  3744. var shortRad = this.ir.v;
  3745. var longRound = this.os.v;
  3746. var shortRound = this.is.v;
  3747. var longPerimSegment = 2 * Math.PI * longRad / (numPts * 2);
  3748. var shortPerimSegment = 2 * Math.PI * shortRad / (numPts * 2);
  3749. var i;
  3750. var rad;
  3751. var roundness;
  3752. var perimSegment;
  3753. var currentAng = -Math.PI / 2;
  3754. currentAng += this.r.v;
  3755. var dir = this.data.d === 3 ? -1 : 1;
  3756. this.v._length = 0;
  3757. for (i = 0; i < numPts; i += 1) {
  3758. rad = longFlag ? longRad : shortRad;
  3759. roundness = longFlag ? longRound : shortRound;
  3760. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3761. var x = rad * Math.cos(currentAng);
  3762. var y = rad * Math.sin(currentAng);
  3763. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3764. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3765. x += +this.p.v[0];
  3766. y += +this.p.v[1];
  3767. this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
  3768. /* this.v.v[i] = [x,y];
  3769. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3770. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3771. this.v._length = numPts; */
  3772. longFlag = !longFlag;
  3773. currentAng += angle * dir;
  3774. }
  3775. },
  3776. convertPolygonToPath: function convertPolygonToPath() {
  3777. var numPts = Math.floor(this.pt.v);
  3778. var angle = Math.PI * 2 / numPts;
  3779. var rad = this.or.v;
  3780. var roundness = this.os.v;
  3781. var perimSegment = 2 * Math.PI * rad / (numPts * 4);
  3782. var i;
  3783. var currentAng = -Math.PI * 0.5;
  3784. var dir = this.data.d === 3 ? -1 : 1;
  3785. currentAng += this.r.v;
  3786. this.v._length = 0;
  3787. for (i = 0; i < numPts; i += 1) {
  3788. var x = rad * Math.cos(currentAng);
  3789. var y = rad * Math.sin(currentAng);
  3790. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3791. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3792. x += +this.p.v[0];
  3793. y += +this.p.v[1];
  3794. this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
  3795. currentAng += angle * dir;
  3796. }
  3797. this.paths.length = 0;
  3798. this.paths[0] = this.v;
  3799. }
  3800. };
  3801. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3802. return StarShapePropertyFactory;
  3803. }();
  3804. var RectShapeProperty = function () {
  3805. function RectShapePropertyFactory(elem, data) {
  3806. this.v = shapePool.newElement();
  3807. this.v.c = true;
  3808. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3809. this.localShapeCollection.addShape(this.v);
  3810. this.paths = this.localShapeCollection;
  3811. this.elem = elem;
  3812. this.comp = elem.comp;
  3813. this.frameId = -1;
  3814. this.d = data.d;
  3815. this.initDynamicPropertyContainer(elem);
  3816. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3817. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3818. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3819. if (this.dynamicProperties.length) {
  3820. this.k = true;
  3821. } else {
  3822. this.k = false;
  3823. this.convertRectToPath();
  3824. }
  3825. }
  3826. RectShapePropertyFactory.prototype = {
  3827. convertRectToPath: function convertRectToPath() {
  3828. var p0 = this.p.v[0];
  3829. var p1 = this.p.v[1];
  3830. var v0 = this.s.v[0] / 2;
  3831. var v1 = this.s.v[1] / 2;
  3832. var round = bmMin(v0, v1, this.r.v);
  3833. var cPoint = round * (1 - roundCorner);
  3834. this.v._length = 0;
  3835. if (this.d === 2 || this.d === 1) {
  3836. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3837. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3838. if (round !== 0) {
  3839. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3840. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3841. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3842. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3843. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3844. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3845. } else {
  3846. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3847. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3848. }
  3849. } else {
  3850. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3851. if (round !== 0) {
  3852. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3853. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3854. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3855. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3856. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3857. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3858. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3859. } else {
  3860. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3861. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3862. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3863. }
  3864. }
  3865. },
  3866. getValue: function getValue() {
  3867. if (this.elem.globalData.frameId === this.frameId) {
  3868. return;
  3869. }
  3870. this.frameId = this.elem.globalData.frameId;
  3871. this.iterateDynamicProperties();
  3872. if (this._mdf) {
  3873. this.convertRectToPath();
  3874. }
  3875. },
  3876. reset: resetShape
  3877. };
  3878. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3879. return RectShapePropertyFactory;
  3880. }();
  3881. function getShapeProp(elem, data, type) {
  3882. var prop;
  3883. if (type === 3 || type === 4) {
  3884. var dataProp = type === 3 ? data.pt : data.ks;
  3885. var keys = dataProp.k;
  3886. if (keys.length) {
  3887. prop = new KeyframedShapeProperty(elem, data, type);
  3888. } else {
  3889. prop = new ShapeProperty(elem, data, type);
  3890. }
  3891. } else if (type === 5) {
  3892. prop = new RectShapeProperty(elem, data);
  3893. } else if (type === 6) {
  3894. prop = new EllShapeProperty(elem, data);
  3895. } else if (type === 7) {
  3896. prop = new StarShapeProperty(elem, data);
  3897. }
  3898. if (prop.k) {
  3899. elem.addDynamicProperty(prop);
  3900. }
  3901. return prop;
  3902. }
  3903. function getConstructorFunction() {
  3904. return ShapeProperty;
  3905. }
  3906. function getKeyframedConstructorFunction() {
  3907. return KeyframedShapeProperty;
  3908. }
  3909. var ob = {};
  3910. ob.getShapeProp = getShapeProp;
  3911. ob.getConstructorFunction = getConstructorFunction;
  3912. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3913. return ob;
  3914. }();
  3915. /*!
  3916. Transformation Matrix v2.0
  3917. (c) Epistemex 2014-2015
  3918. www.epistemex.com
  3919. By Ken Fyrstenberg
  3920. Contributions by leeoniya.
  3921. License: MIT, header required.
  3922. */
  3923. /**
  3924. * 2D transformation matrix object initialized with identity matrix.
  3925. *
  3926. * The matrix can synchronize a canvas context by supplying the context
  3927. * as an argument, or later apply current absolute transform to an
  3928. * existing context.
  3929. *
  3930. * All values are handled as floating point values.
  3931. *
  3932. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3933. * @prop {number} a - scale x
  3934. * @prop {number} b - shear y
  3935. * @prop {number} c - shear x
  3936. * @prop {number} d - scale y
  3937. * @prop {number} e - translate x
  3938. * @prop {number} f - translate y
  3939. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3940. * @constructor
  3941. */
  3942. var Matrix = function () {
  3943. var _cos = Math.cos;
  3944. var _sin = Math.sin;
  3945. var _tan = Math.tan;
  3946. var _rnd = Math.round;
  3947. function reset() {
  3948. this.props[0] = 1;
  3949. this.props[1] = 0;
  3950. this.props[2] = 0;
  3951. this.props[3] = 0;
  3952. this.props[4] = 0;
  3953. this.props[5] = 1;
  3954. this.props[6] = 0;
  3955. this.props[7] = 0;
  3956. this.props[8] = 0;
  3957. this.props[9] = 0;
  3958. this.props[10] = 1;
  3959. this.props[11] = 0;
  3960. this.props[12] = 0;
  3961. this.props[13] = 0;
  3962. this.props[14] = 0;
  3963. this.props[15] = 1;
  3964. return this;
  3965. }
  3966. function rotate(angle) {
  3967. if (angle === 0) {
  3968. return this;
  3969. }
  3970. var mCos = _cos(angle);
  3971. var mSin = _sin(angle);
  3972. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3973. }
  3974. function rotateX(angle) {
  3975. if (angle === 0) {
  3976. return this;
  3977. }
  3978. var mCos = _cos(angle);
  3979. var mSin = _sin(angle);
  3980. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3981. }
  3982. function rotateY(angle) {
  3983. if (angle === 0) {
  3984. return this;
  3985. }
  3986. var mCos = _cos(angle);
  3987. var mSin = _sin(angle);
  3988. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3989. }
  3990. function rotateZ(angle) {
  3991. if (angle === 0) {
  3992. return this;
  3993. }
  3994. var mCos = _cos(angle);
  3995. var mSin = _sin(angle);
  3996. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3997. }
  3998. function shear(sx, sy) {
  3999. return this._t(1, sy, sx, 1, 0, 0);
  4000. }
  4001. function skew(ax, ay) {
  4002. return this.shear(_tan(ax), _tan(ay));
  4003. }
  4004. function skewFromAxis(ax, angle) {
  4005. var mCos = _cos(angle);
  4006. var mSin = _sin(angle);
  4007. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4008. // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  4009. }
  4010. function scale(sx, sy, sz) {
  4011. if (!sz && sz !== 0) {
  4012. sz = 1;
  4013. }
  4014. if (sx === 1 && sy === 1 && sz === 1) {
  4015. return this;
  4016. }
  4017. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  4018. }
  4019. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  4020. this.props[0] = a;
  4021. this.props[1] = b;
  4022. this.props[2] = c;
  4023. this.props[3] = d;
  4024. this.props[4] = e;
  4025. this.props[5] = f;
  4026. this.props[6] = g;
  4027. this.props[7] = h;
  4028. this.props[8] = i;
  4029. this.props[9] = j;
  4030. this.props[10] = k;
  4031. this.props[11] = l;
  4032. this.props[12] = m;
  4033. this.props[13] = n;
  4034. this.props[14] = o;
  4035. this.props[15] = p;
  4036. return this;
  4037. }
  4038. function translate(tx, ty, tz) {
  4039. tz = tz || 0;
  4040. if (tx !== 0 || ty !== 0 || tz !== 0) {
  4041. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  4042. }
  4043. return this;
  4044. }
  4045. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  4046. var _p = this.props;
  4047. if (a2 === 1 && b2 === 0 && c2 === 0 && d2 === 0 && e2 === 0 && f2 === 1 && g2 === 0 && h2 === 0 && i2 === 0 && j2 === 0 && k2 === 1 && l2 === 0) {
  4048. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  4049. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  4050. _p[12] = _p[12] * a2 + _p[15] * m2;
  4051. _p[13] = _p[13] * f2 + _p[15] * n2;
  4052. _p[14] = _p[14] * k2 + _p[15] * o2;
  4053. _p[15] *= p2;
  4054. // }
  4055. this._identityCalculated = false;
  4056. return this;
  4057. }
  4058. var a1 = _p[0];
  4059. var b1 = _p[1];
  4060. var c1 = _p[2];
  4061. var d1 = _p[3];
  4062. var e1 = _p[4];
  4063. var f1 = _p[5];
  4064. var g1 = _p[6];
  4065. var h1 = _p[7];
  4066. var i1 = _p[8];
  4067. var j1 = _p[9];
  4068. var k1 = _p[10];
  4069. var l1 = _p[11];
  4070. var m1 = _p[12];
  4071. var n1 = _p[13];
  4072. var o1 = _p[14];
  4073. var p1 = _p[15];
  4074. /* matrix order (canvas compatible):
  4075. * ace
  4076. * bdf
  4077. * 001
  4078. */
  4079. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  4080. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  4081. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  4082. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  4083. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  4084. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  4085. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  4086. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  4087. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  4088. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  4089. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  4090. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  4091. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  4092. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  4093. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  4094. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  4095. this._identityCalculated = false;
  4096. return this;
  4097. }
  4098. function multiply(matrix) {
  4099. var matrixProps = matrix.props;
  4100. return this.transform(matrixProps[0], matrixProps[1], matrixProps[2], matrixProps[3], matrixProps[4], matrixProps[5], matrixProps[6], matrixProps[7], matrixProps[8], matrixProps[9], matrixProps[10], matrixProps[11], matrixProps[12], matrixProps[13], matrixProps[14], matrixProps[15]);
  4101. }
  4102. function isIdentity() {
  4103. if (!this._identityCalculated) {
  4104. this._identity = !(this.props[0] !== 1 || this.props[1] !== 0 || this.props[2] !== 0 || this.props[3] !== 0 || this.props[4] !== 0 || this.props[5] !== 1 || this.props[6] !== 0 || this.props[7] !== 0 || this.props[8] !== 0 || this.props[9] !== 0 || this.props[10] !== 1 || this.props[11] !== 0 || this.props[12] !== 0 || this.props[13] !== 0 || this.props[14] !== 0 || this.props[15] !== 1);
  4105. this._identityCalculated = true;
  4106. }
  4107. return this._identity;
  4108. }
  4109. function equals(matr) {
  4110. var i = 0;
  4111. while (i < 16) {
  4112. if (matr.props[i] !== this.props[i]) {
  4113. return false;
  4114. }
  4115. i += 1;
  4116. }
  4117. return true;
  4118. }
  4119. function clone(matr) {
  4120. var i;
  4121. for (i = 0; i < 16; i += 1) {
  4122. matr.props[i] = this.props[i];
  4123. }
  4124. return matr;
  4125. }
  4126. function cloneFromProps(props) {
  4127. var i;
  4128. for (i = 0; i < 16; i += 1) {
  4129. this.props[i] = props[i];
  4130. }
  4131. }
  4132. function applyToPoint(x, y, z) {
  4133. return {
  4134. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4135. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4136. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]
  4137. };
  4138. /* return {
  4139. x: x * me.a + y * me.c + me.e,
  4140. y: x * me.b + y * me.d + me.f
  4141. }; */
  4142. }
  4143. function applyToX(x, y, z) {
  4144. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4145. }
  4146. function applyToY(x, y, z) {
  4147. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4148. }
  4149. function applyToZ(x, y, z) {
  4150. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4151. }
  4152. function getInverseMatrix() {
  4153. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4154. var a = this.props[5] / determinant;
  4155. var b = -this.props[1] / determinant;
  4156. var c = -this.props[4] / determinant;
  4157. var d = this.props[0] / determinant;
  4158. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4159. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4160. var inverseMatrix = new Matrix();
  4161. inverseMatrix.props[0] = a;
  4162. inverseMatrix.props[1] = b;
  4163. inverseMatrix.props[4] = c;
  4164. inverseMatrix.props[5] = d;
  4165. inverseMatrix.props[12] = e;
  4166. inverseMatrix.props[13] = f;
  4167. return inverseMatrix;
  4168. }
  4169. function inversePoint(pt) {
  4170. var inverseMatrix = this.getInverseMatrix();
  4171. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4172. }
  4173. function inversePoints(pts) {
  4174. var i;
  4175. var len = pts.length;
  4176. var retPts = [];
  4177. for (i = 0; i < len; i += 1) {
  4178. retPts[i] = inversePoint(pts[i]);
  4179. }
  4180. return retPts;
  4181. }
  4182. function applyToTriplePoints(pt1, pt2, pt3) {
  4183. var arr = createTypedArray('float32', 6);
  4184. if (this.isIdentity()) {
  4185. arr[0] = pt1[0];
  4186. arr[1] = pt1[1];
  4187. arr[2] = pt2[0];
  4188. arr[3] = pt2[1];
  4189. arr[4] = pt3[0];
  4190. arr[5] = pt3[1];
  4191. } else {
  4192. var p0 = this.props[0];
  4193. var p1 = this.props[1];
  4194. var p4 = this.props[4];
  4195. var p5 = this.props[5];
  4196. var p12 = this.props[12];
  4197. var p13 = this.props[13];
  4198. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4199. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4200. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4201. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4202. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4203. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4204. }
  4205. return arr;
  4206. }
  4207. function applyToPointArray(x, y, z) {
  4208. var arr;
  4209. if (this.isIdentity()) {
  4210. arr = [x, y, z];
  4211. } else {
  4212. arr = [x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12], x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13], x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]];
  4213. }
  4214. return arr;
  4215. }
  4216. function applyToPointStringified(x, y) {
  4217. if (this.isIdentity()) {
  4218. return x + ',' + y;
  4219. }
  4220. var _p = this.props;
  4221. return Math.round((x * _p[0] + y * _p[4] + _p[12]) * 100) / 100 + ',' + Math.round((x * _p[1] + y * _p[5] + _p[13]) * 100) / 100;
  4222. }
  4223. function toCSS() {
  4224. // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed.
  4225. /* if(this.isIdentity()) {
  4226. return '';
  4227. } */
  4228. var i = 0;
  4229. var props = this.props;
  4230. var cssValue = 'matrix3d(';
  4231. var v = 10000;
  4232. while (i < 16) {
  4233. cssValue += _rnd(props[i] * v) / v;
  4234. cssValue += i === 15 ? ')' : ',';
  4235. i += 1;
  4236. }
  4237. return cssValue;
  4238. }
  4239. function roundMatrixProperty(val) {
  4240. var v = 10000;
  4241. if (val < 0.000001 && val > 0 || val > -0.000001 && val < 0) {
  4242. return _rnd(val * v) / v;
  4243. }
  4244. return val;
  4245. }
  4246. function to2dCSS() {
  4247. // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed.
  4248. /* if(this.isIdentity()) {
  4249. return '';
  4250. } */
  4251. var props = this.props;
  4252. var _a = roundMatrixProperty(props[0]);
  4253. var _b = roundMatrixProperty(props[1]);
  4254. var _c = roundMatrixProperty(props[4]);
  4255. var _d = roundMatrixProperty(props[5]);
  4256. var _e = roundMatrixProperty(props[12]);
  4257. var _f = roundMatrixProperty(props[13]);
  4258. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4259. }
  4260. return function () {
  4261. this.reset = reset;
  4262. this.rotate = rotate;
  4263. this.rotateX = rotateX;
  4264. this.rotateY = rotateY;
  4265. this.rotateZ = rotateZ;
  4266. this.skew = skew;
  4267. this.skewFromAxis = skewFromAxis;
  4268. this.shear = shear;
  4269. this.scale = scale;
  4270. this.setTransform = setTransform;
  4271. this.translate = translate;
  4272. this.transform = transform;
  4273. this.multiply = multiply;
  4274. this.applyToPoint = applyToPoint;
  4275. this.applyToX = applyToX;
  4276. this.applyToY = applyToY;
  4277. this.applyToZ = applyToZ;
  4278. this.applyToPointArray = applyToPointArray;
  4279. this.applyToTriplePoints = applyToTriplePoints;
  4280. this.applyToPointStringified = applyToPointStringified;
  4281. this.toCSS = toCSS;
  4282. this.to2dCSS = to2dCSS;
  4283. this.clone = clone;
  4284. this.cloneFromProps = cloneFromProps;
  4285. this.equals = equals;
  4286. this.inversePoints = inversePoints;
  4287. this.inversePoint = inversePoint;
  4288. this.getInverseMatrix = getInverseMatrix;
  4289. this._t = this.transform;
  4290. this.isIdentity = isIdentity;
  4291. this._identity = true;
  4292. this._identityCalculated = false;
  4293. this.props = createTypedArray('float32', 16);
  4294. this.reset();
  4295. };
  4296. }();
  4297. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  4298. var lottie = {};
  4299. var standalone = '__[STANDALONE]__';
  4300. var animationData = '__[ANIMATIONDATA]__';
  4301. var renderer = '';
  4302. function setLocation(href) {
  4303. setLocationHref(href);
  4304. }
  4305. function searchAnimations() {
  4306. if (standalone === true) {
  4307. animationManager.searchAnimations(animationData, standalone, renderer);
  4308. } else {
  4309. animationManager.searchAnimations();
  4310. }
  4311. }
  4312. function setSubframeRendering(flag) {
  4313. setSubframeEnabled(flag);
  4314. }
  4315. function setPrefix(prefix) {
  4316. setIdPrefix(prefix);
  4317. }
  4318. function loadAnimation(params) {
  4319. if (standalone === true) {
  4320. params.animationData = JSON.parse(animationData);
  4321. }
  4322. return animationManager.loadAnimation(params);
  4323. }
  4324. function setQuality(value) {
  4325. if (typeof value === 'string') {
  4326. switch (value) {
  4327. case 'high':
  4328. setDefaultCurveSegments(200);
  4329. break;
  4330. default:
  4331. case 'medium':
  4332. setDefaultCurveSegments(50);
  4333. break;
  4334. case 'low':
  4335. setDefaultCurveSegments(10);
  4336. break;
  4337. }
  4338. } else if (!isNaN(value) && value > 1) {
  4339. setDefaultCurveSegments(value);
  4340. }
  4341. if (getDefaultCurveSegments() >= 50) {
  4342. roundValues(false);
  4343. } else {
  4344. roundValues(true);
  4345. }
  4346. }
  4347. function inBrowser() {
  4348. return typeof navigator !== 'undefined';
  4349. }
  4350. function installPlugin(type, plugin) {
  4351. if (type === 'expressions') {
  4352. setExpressionsPlugin(plugin);
  4353. }
  4354. }
  4355. function getFactory(name) {
  4356. switch (name) {
  4357. case 'propertyFactory':
  4358. return PropertyFactory;
  4359. case 'shapePropertyFactory':
  4360. return ShapePropertyFactory;
  4361. case 'matrix':
  4362. return Matrix;
  4363. default:
  4364. return null;
  4365. }
  4366. }
  4367. lottie.play = animationManager.play;
  4368. lottie.pause = animationManager.pause;
  4369. lottie.setLocationHref = setLocation;
  4370. lottie.togglePause = animationManager.togglePause;
  4371. lottie.setSpeed = animationManager.setSpeed;
  4372. lottie.setDirection = animationManager.setDirection;
  4373. lottie.stop = animationManager.stop;
  4374. lottie.searchAnimations = searchAnimations;
  4375. lottie.registerAnimation = animationManager.registerAnimation;
  4376. lottie.loadAnimation = loadAnimation;
  4377. lottie.setSubframeRendering = setSubframeRendering;
  4378. lottie.resize = animationManager.resize;
  4379. // lottie.start = start;
  4380. lottie.goToAndStop = animationManager.goToAndStop;
  4381. lottie.destroy = animationManager.destroy;
  4382. lottie.setQuality = setQuality;
  4383. lottie.inBrowser = inBrowser;
  4384. lottie.installPlugin = installPlugin;
  4385. lottie.freeze = animationManager.freeze;
  4386. lottie.unfreeze = animationManager.unfreeze;
  4387. lottie.setVolume = animationManager.setVolume;
  4388. lottie.mute = animationManager.mute;
  4389. lottie.unmute = animationManager.unmute;
  4390. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4391. lottie.useWebWorker = setWebWorker;
  4392. lottie.setIDPrefix = setPrefix;
  4393. lottie.__getFactory = getFactory;
  4394. lottie.version = '5.13.0';
  4395. function checkReady() {
  4396. if (document.readyState === 'complete') {
  4397. clearInterval(readyStateCheckInterval);
  4398. searchAnimations();
  4399. }
  4400. }
  4401. function getQueryVariable(variable) {
  4402. var vars = queryString.split('&');
  4403. for (var i = 0; i < vars.length; i += 1) {
  4404. var pair = vars[i].split('=');
  4405. if (decodeURIComponent(pair[0]) == variable) {
  4406. // eslint-disable-line eqeqeq
  4407. return decodeURIComponent(pair[1]);
  4408. }
  4409. }
  4410. return null;
  4411. }
  4412. var queryString = '';
  4413. if (standalone) {
  4414. var scripts = document.getElementsByTagName('script');
  4415. var index = scripts.length - 1;
  4416. var myScript = scripts[index] || {
  4417. src: ''
  4418. };
  4419. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4420. renderer = getQueryVariable('renderer');
  4421. }
  4422. var readyStateCheckInterval = setInterval(checkReady, 100);
  4423. // this adds bodymovin to the window object for backwards compatibility
  4424. try {
  4425. if (!((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined') && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4426. ) {
  4427. window.bodymovin = lottie;
  4428. }
  4429. } catch (err) {
  4430. //
  4431. }
  4432. var ShapeModifiers = function () {
  4433. var ob = {};
  4434. var modifiers = {};
  4435. ob.registerModifier = registerModifier;
  4436. ob.getModifier = getModifier;
  4437. function registerModifier(nm, factory) {
  4438. if (!modifiers[nm]) {
  4439. modifiers[nm] = factory;
  4440. }
  4441. }
  4442. function getModifier(nm, elem, data) {
  4443. return new modifiers[nm](elem, data);
  4444. }
  4445. return ob;
  4446. }();
  4447. function ShapeModifier() {}
  4448. ShapeModifier.prototype.initModifierProperties = function () {};
  4449. ShapeModifier.prototype.addShapeToModifier = function () {};
  4450. ShapeModifier.prototype.addShape = function (data) {
  4451. if (!this.closed) {
  4452. // Adding shape to dynamic properties. It covers the case where a shape has no effects applied, to reset it's _mdf state on every tick.
  4453. data.sh.container.addDynamicProperty(data.sh);
  4454. var shapeData = {
  4455. shape: data.sh,
  4456. data: data,
  4457. localShapeCollection: shapeCollectionPool.newShapeCollection()
  4458. };
  4459. this.shapes.push(shapeData);
  4460. this.addShapeToModifier(shapeData);
  4461. if (this._isAnimated) {
  4462. data.setAsAnimated();
  4463. }
  4464. }
  4465. };
  4466. ShapeModifier.prototype.init = function (elem, data) {
  4467. this.shapes = [];
  4468. this.elem = elem;
  4469. this.initDynamicPropertyContainer(elem);
  4470. this.initModifierProperties(elem, data);
  4471. this.frameId = initialDefaultFrame;
  4472. this.closed = false;
  4473. this.k = false;
  4474. if (this.dynamicProperties.length) {
  4475. this.k = true;
  4476. } else {
  4477. this.getValue(true);
  4478. }
  4479. };
  4480. ShapeModifier.prototype.processKeys = function () {
  4481. if (this.elem.globalData.frameId === this.frameId) {
  4482. return;
  4483. }
  4484. this.frameId = this.elem.globalData.frameId;
  4485. this.iterateDynamicProperties();
  4486. };
  4487. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4488. function TrimModifier() {}
  4489. extendPrototype([ShapeModifier], TrimModifier);
  4490. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4491. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4492. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4493. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4494. this.sValue = 0;
  4495. this.eValue = 0;
  4496. this.getValue = this.processKeys;
  4497. this.m = data.m;
  4498. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4499. };
  4500. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4501. shapeData.pathsData = [];
  4502. };
  4503. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4504. var segments = [];
  4505. if (e <= 1) {
  4506. segments.push({
  4507. s: s,
  4508. e: e
  4509. });
  4510. } else if (s >= 1) {
  4511. segments.push({
  4512. s: s - 1,
  4513. e: e - 1
  4514. });
  4515. } else {
  4516. segments.push({
  4517. s: s,
  4518. e: 1
  4519. });
  4520. segments.push({
  4521. s: 0,
  4522. e: e - 1
  4523. });
  4524. }
  4525. var shapeSegments = [];
  4526. var i;
  4527. var len = segments.length;
  4528. var segmentOb;
  4529. for (i = 0; i < len; i += 1) {
  4530. segmentOb = segments[i];
  4531. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4532. var shapeS;
  4533. var shapeE;
  4534. if (segmentOb.s * totalModifierLength <= addedLength) {
  4535. shapeS = 0;
  4536. } else {
  4537. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4538. }
  4539. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4540. shapeE = 1;
  4541. } else {
  4542. shapeE = (segmentOb.e * totalModifierLength - addedLength) / shapeLength;
  4543. }
  4544. shapeSegments.push([shapeS, shapeE]);
  4545. }
  4546. }
  4547. if (!shapeSegments.length) {
  4548. shapeSegments.push([0, 0]);
  4549. }
  4550. return shapeSegments;
  4551. };
  4552. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4553. var i;
  4554. var len = pathsData.length;
  4555. for (i = 0; i < len; i += 1) {
  4556. segmentsLengthPool.release(pathsData[i]);
  4557. }
  4558. pathsData.length = 0;
  4559. return pathsData;
  4560. };
  4561. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4562. var s;
  4563. var e;
  4564. if (this._mdf || _isFirstFrame) {
  4565. var o = this.o.v % 360 / 360;
  4566. if (o < 0) {
  4567. o += 1;
  4568. }
  4569. if (this.s.v > 1) {
  4570. s = 1 + o;
  4571. } else if (this.s.v < 0) {
  4572. s = 0 + o;
  4573. } else {
  4574. s = this.s.v + o;
  4575. }
  4576. if (this.e.v > 1) {
  4577. e = 1 + o;
  4578. } else if (this.e.v < 0) {
  4579. e = 0 + o;
  4580. } else {
  4581. e = this.e.v + o;
  4582. }
  4583. if (s > e) {
  4584. var _s = s;
  4585. s = e;
  4586. e = _s;
  4587. }
  4588. s = Math.round(s * 10000) * 0.0001;
  4589. e = Math.round(e * 10000) * 0.0001;
  4590. this.sValue = s;
  4591. this.eValue = e;
  4592. } else {
  4593. s = this.sValue;
  4594. e = this.eValue;
  4595. }
  4596. var shapePaths;
  4597. var i;
  4598. var len = this.shapes.length;
  4599. var j;
  4600. var jLen;
  4601. var pathsData;
  4602. var pathData;
  4603. var totalShapeLength;
  4604. var totalModifierLength = 0;
  4605. if (e === s) {
  4606. for (i = 0; i < len; i += 1) {
  4607. this.shapes[i].localShapeCollection.releaseShapes();
  4608. this.shapes[i].shape._mdf = true;
  4609. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4610. if (this._mdf) {
  4611. this.shapes[i].pathsData.length = 0;
  4612. }
  4613. }
  4614. } else if (!(e === 1 && s === 0 || e === 0 && s === 1)) {
  4615. var segments = [];
  4616. var shapeData;
  4617. var localShapeCollection;
  4618. for (i = 0; i < len; i += 1) {
  4619. shapeData = this.shapes[i];
  4620. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4621. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4622. shapeData.shape.paths = shapeData.localShapeCollection;
  4623. } else {
  4624. shapePaths = shapeData.shape.paths;
  4625. jLen = shapePaths._length;
  4626. totalShapeLength = 0;
  4627. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4628. totalShapeLength = shapeData.totalShapeLength;
  4629. } else {
  4630. pathsData = this.releasePathsData(shapeData.pathsData);
  4631. for (j = 0; j < jLen; j += 1) {
  4632. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4633. pathsData.push(pathData);
  4634. totalShapeLength += pathData.totalLength;
  4635. }
  4636. shapeData.totalShapeLength = totalShapeLength;
  4637. shapeData.pathsData = pathsData;
  4638. }
  4639. totalModifierLength += totalShapeLength;
  4640. shapeData.shape._mdf = true;
  4641. }
  4642. }
  4643. var shapeS = s;
  4644. var shapeE = e;
  4645. var addedLength = 0;
  4646. var edges;
  4647. for (i = len - 1; i >= 0; i -= 1) {
  4648. shapeData = this.shapes[i];
  4649. if (shapeData.shape._mdf) {
  4650. localShapeCollection = shapeData.localShapeCollection;
  4651. localShapeCollection.releaseShapes();
  4652. // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4653. if (this.m === 2 && len > 1) {
  4654. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4655. addedLength += shapeData.totalShapeLength;
  4656. } else {
  4657. edges = [[shapeS, shapeE]];
  4658. }
  4659. jLen = edges.length;
  4660. for (j = 0; j < jLen; j += 1) {
  4661. shapeS = edges[j][0];
  4662. shapeE = edges[j][1];
  4663. segments.length = 0;
  4664. if (shapeE <= 1) {
  4665. segments.push({
  4666. s: shapeData.totalShapeLength * shapeS,
  4667. e: shapeData.totalShapeLength * shapeE
  4668. });
  4669. } else if (shapeS >= 1) {
  4670. segments.push({
  4671. s: shapeData.totalShapeLength * (shapeS - 1),
  4672. e: shapeData.totalShapeLength * (shapeE - 1)
  4673. });
  4674. } else {
  4675. segments.push({
  4676. s: shapeData.totalShapeLength * shapeS,
  4677. e: shapeData.totalShapeLength
  4678. });
  4679. segments.push({
  4680. s: 0,
  4681. e: shapeData.totalShapeLength * (shapeE - 1)
  4682. });
  4683. }
  4684. var newShapesData = this.addShapes(shapeData, segments[0]);
  4685. if (segments[0].s !== segments[0].e) {
  4686. if (segments.length > 1) {
  4687. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4688. if (lastShapeInCollection.c) {
  4689. var lastShape = newShapesData.pop();
  4690. this.addPaths(newShapesData, localShapeCollection);
  4691. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4692. } else {
  4693. this.addPaths(newShapesData, localShapeCollection);
  4694. newShapesData = this.addShapes(shapeData, segments[1]);
  4695. }
  4696. }
  4697. this.addPaths(newShapesData, localShapeCollection);
  4698. }
  4699. }
  4700. shapeData.shape.paths = localShapeCollection;
  4701. }
  4702. }
  4703. } else if (this._mdf) {
  4704. for (i = 0; i < len; i += 1) {
  4705. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4706. // Don't remove this even if it's losing cached info.
  4707. this.shapes[i].pathsData.length = 0;
  4708. this.shapes[i].shape._mdf = true;
  4709. }
  4710. }
  4711. };
  4712. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4713. var i;
  4714. var len = newPaths.length;
  4715. for (i = 0; i < len; i += 1) {
  4716. localShapeCollection.addShape(newPaths[i]);
  4717. }
  4718. };
  4719. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4720. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4721. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4722. if (newShape) {
  4723. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4724. }
  4725. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4726. };
  4727. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4728. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4729. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4730. if (newShape) {
  4731. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4732. }
  4733. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4734. };
  4735. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4736. var pathsData = shapeData.pathsData;
  4737. var shapePaths = shapeData.shape.paths.shapes;
  4738. var i;
  4739. var len = shapeData.shape.paths._length;
  4740. var j;
  4741. var jLen;
  4742. var addedLength = 0;
  4743. var currentLengthData;
  4744. var segmentCount;
  4745. var lengths;
  4746. var segment;
  4747. var shapes = [];
  4748. var initPos;
  4749. var newShape = true;
  4750. if (!shapePath) {
  4751. shapePath = shapePool.newElement();
  4752. segmentCount = 0;
  4753. initPos = 0;
  4754. } else {
  4755. segmentCount = shapePath._length;
  4756. initPos = shapePath._length;
  4757. }
  4758. shapes.push(shapePath);
  4759. for (i = 0; i < len; i += 1) {
  4760. lengths = pathsData[i].lengths;
  4761. shapePath.c = shapePaths[i].c;
  4762. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4763. for (j = 1; j < jLen; j += 1) {
  4764. currentLengthData = lengths[j - 1];
  4765. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4766. addedLength += currentLengthData.addedLength;
  4767. shapePath.c = false;
  4768. } else if (addedLength > shapeSegment.e) {
  4769. shapePath.c = false;
  4770. break;
  4771. } else {
  4772. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4773. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4774. newShape = false;
  4775. } else {
  4776. segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[j], shapePaths[i].o[j - 1], shapePaths[i].i[j], (shapeSegment.s - addedLength) / currentLengthData.addedLength, (shapeSegment.e - addedLength) / currentLengthData.addedLength, lengths[j - 1]);
  4777. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4778. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4779. newShape = false;
  4780. shapePath.c = false;
  4781. }
  4782. addedLength += currentLengthData.addedLength;
  4783. segmentCount += 1;
  4784. }
  4785. }
  4786. if (shapePaths[i].c && lengths.length) {
  4787. currentLengthData = lengths[j - 1];
  4788. if (addedLength <= shapeSegment.e) {
  4789. var segmentLength = lengths[j - 1].addedLength;
  4790. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4791. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4792. newShape = false;
  4793. } else {
  4794. segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[0], shapePaths[i].o[j - 1], shapePaths[i].i[0], (shapeSegment.s - addedLength) / segmentLength, (shapeSegment.e - addedLength) / segmentLength, lengths[j - 1]);
  4795. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4796. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4797. newShape = false;
  4798. shapePath.c = false;
  4799. }
  4800. } else {
  4801. shapePath.c = false;
  4802. }
  4803. addedLength += currentLengthData.addedLength;
  4804. segmentCount += 1;
  4805. }
  4806. if (shapePath._length) {
  4807. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4808. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4809. }
  4810. if (addedLength > shapeSegment.e) {
  4811. break;
  4812. }
  4813. if (i < len - 1) {
  4814. shapePath = shapePool.newElement();
  4815. newShape = true;
  4816. shapes.push(shapePath);
  4817. segmentCount = 0;
  4818. }
  4819. }
  4820. return shapes;
  4821. };
  4822. function PuckerAndBloatModifier() {}
  4823. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4824. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4825. this.getValue = this.processKeys;
  4826. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4827. this._isAnimated = !!this.amount.effectsSequence.length;
  4828. };
  4829. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4830. var percent = amount / 100;
  4831. var centerPoint = [0, 0];
  4832. var pathLength = path._length;
  4833. var i = 0;
  4834. for (i = 0; i < pathLength; i += 1) {
  4835. centerPoint[0] += path.v[i][0];
  4836. centerPoint[1] += path.v[i][1];
  4837. }
  4838. centerPoint[0] /= pathLength;
  4839. centerPoint[1] /= pathLength;
  4840. var clonedPath = shapePool.newElement();
  4841. clonedPath.c = path.c;
  4842. var vX;
  4843. var vY;
  4844. var oX;
  4845. var oY;
  4846. var iX;
  4847. var iY;
  4848. for (i = 0; i < pathLength; i += 1) {
  4849. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4850. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4851. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4852. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4853. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4854. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4855. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4856. }
  4857. return clonedPath;
  4858. };
  4859. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4860. var shapePaths;
  4861. var i;
  4862. var len = this.shapes.length;
  4863. var j;
  4864. var jLen;
  4865. var amount = this.amount.v;
  4866. if (amount !== 0) {
  4867. var shapeData;
  4868. var localShapeCollection;
  4869. for (i = 0; i < len; i += 1) {
  4870. shapeData = this.shapes[i];
  4871. localShapeCollection = shapeData.localShapeCollection;
  4872. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4873. localShapeCollection.releaseShapes();
  4874. shapeData.shape._mdf = true;
  4875. shapePaths = shapeData.shape.paths.shapes;
  4876. jLen = shapeData.shape.paths._length;
  4877. for (j = 0; j < jLen; j += 1) {
  4878. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4879. }
  4880. }
  4881. shapeData.shape.paths = shapeData.localShapeCollection;
  4882. }
  4883. }
  4884. if (!this.dynamicProperties.length) {
  4885. this._mdf = false;
  4886. }
  4887. };
  4888. var TransformPropertyFactory = function () {
  4889. var defaultVector = [0, 0];
  4890. function applyToMatrix(mat) {
  4891. var _mdf = this._mdf;
  4892. this.iterateDynamicProperties();
  4893. this._mdf = this._mdf || _mdf;
  4894. if (this.a) {
  4895. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4896. }
  4897. if (this.s) {
  4898. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4899. }
  4900. if (this.sk) {
  4901. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4902. }
  4903. if (this.r) {
  4904. mat.rotate(-this.r.v);
  4905. } else {
  4906. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  4907. }
  4908. if (this.data.p.s) {
  4909. if (this.data.p.z) {
  4910. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4911. } else {
  4912. mat.translate(this.px.v, this.py.v, 0);
  4913. }
  4914. } else {
  4915. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4916. }
  4917. }
  4918. function processKeys(forceRender) {
  4919. if (this.elem.globalData.frameId === this.frameId) {
  4920. return;
  4921. }
  4922. if (this._isDirty) {
  4923. this.precalculateMatrix();
  4924. this._isDirty = false;
  4925. }
  4926. this.iterateDynamicProperties();
  4927. if (this._mdf || forceRender) {
  4928. var frameRate;
  4929. this.v.cloneFromProps(this.pre.props);
  4930. if (this.appliedTransformations < 1) {
  4931. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4932. }
  4933. if (this.appliedTransformations < 2) {
  4934. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4935. }
  4936. if (this.sk && this.appliedTransformations < 3) {
  4937. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4938. }
  4939. if (this.r && this.appliedTransformations < 4) {
  4940. this.v.rotate(-this.r.v);
  4941. } else if (!this.r && this.appliedTransformations < 4) {
  4942. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  4943. }
  4944. if (this.autoOriented) {
  4945. var v1;
  4946. var v2;
  4947. frameRate = this.elem.globalData.frameRate;
  4948. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4949. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4950. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4951. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4952. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4953. v1 = this.p.getValueAtTime(this.p.keyframes[this.p.keyframes.length - 1].t / frameRate, 0);
  4954. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4955. } else {
  4956. v1 = this.p.pv;
  4957. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4958. }
  4959. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4960. v1 = [];
  4961. v2 = [];
  4962. var px = this.px;
  4963. var py = this.py;
  4964. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4965. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4966. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4967. v2[0] = px.getValueAtTime(px.keyframes[0].t / frameRate, 0);
  4968. v2[1] = py.getValueAtTime(py.keyframes[0].t / frameRate, 0);
  4969. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4970. v1[0] = px.getValueAtTime(px.keyframes[px.keyframes.length - 1].t / frameRate, 0);
  4971. v1[1] = py.getValueAtTime(py.keyframes[py.keyframes.length - 1].t / frameRate, 0);
  4972. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4973. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4974. } else {
  4975. v1 = [px.pv, py.pv];
  4976. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4977. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4978. }
  4979. } else {
  4980. v2 = defaultVector;
  4981. v1 = v2;
  4982. }
  4983. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4984. }
  4985. if (this.data.p && this.data.p.s) {
  4986. if (this.data.p.z) {
  4987. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4988. } else {
  4989. this.v.translate(this.px.v, this.py.v, 0);
  4990. }
  4991. } else {
  4992. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4993. }
  4994. }
  4995. this.frameId = this.elem.globalData.frameId;
  4996. }
  4997. function precalculateMatrix() {
  4998. this.appliedTransformations = 0;
  4999. this.pre.reset();
  5000. if (!this.a.effectsSequence.length) {
  5001. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  5002. this.appliedTransformations = 1;
  5003. } else {
  5004. return;
  5005. }
  5006. if (!this.s.effectsSequence.length) {
  5007. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  5008. this.appliedTransformations = 2;
  5009. } else {
  5010. return;
  5011. }
  5012. if (this.sk) {
  5013. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  5014. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  5015. this.appliedTransformations = 3;
  5016. } else {
  5017. return;
  5018. }
  5019. }
  5020. if (this.r) {
  5021. if (!this.r.effectsSequence.length) {
  5022. this.pre.rotate(-this.r.v);
  5023. this.appliedTransformations = 4;
  5024. }
  5025. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  5026. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  5027. this.appliedTransformations = 4;
  5028. }
  5029. }
  5030. function autoOrient() {
  5031. //
  5032. // var prevP = this.getValueAtTime();
  5033. }
  5034. function addDynamicProperty(prop) {
  5035. this._addDynamicProperty(prop);
  5036. this.elem.addDynamicProperty(prop);
  5037. this._isDirty = true;
  5038. }
  5039. function TransformProperty(elem, data, container) {
  5040. this.elem = elem;
  5041. this.frameId = -1;
  5042. this.propType = 'transform';
  5043. this.data = data;
  5044. this.v = new Matrix();
  5045. // Precalculated matrix with non animated properties
  5046. this.pre = new Matrix();
  5047. this.appliedTransformations = 0;
  5048. this.initDynamicPropertyContainer(container || elem);
  5049. if (data.p && data.p.s) {
  5050. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  5051. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  5052. if (data.p.z) {
  5053. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  5054. }
  5055. } else {
  5056. this.p = PropertyFactory.getProp(elem, data.p || {
  5057. k: [0, 0, 0]
  5058. }, 1, 0, this);
  5059. }
  5060. if (data.rx) {
  5061. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  5062. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  5063. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  5064. if (data.or.k[0].ti) {
  5065. var i;
  5066. var len = data.or.k.length;
  5067. for (i = 0; i < len; i += 1) {
  5068. data.or.k[i].to = null;
  5069. data.or.k[i].ti = null;
  5070. }
  5071. }
  5072. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  5073. // sh Indicates it needs to be capped between -180 and 180
  5074. this.or.sh = true;
  5075. } else {
  5076. this.r = PropertyFactory.getProp(elem, data.r || {
  5077. k: 0
  5078. }, 0, degToRads, this);
  5079. }
  5080. if (data.sk) {
  5081. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  5082. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  5083. }
  5084. this.a = PropertyFactory.getProp(elem, data.a || {
  5085. k: [0, 0, 0]
  5086. }, 1, 0, this);
  5087. this.s = PropertyFactory.getProp(elem, data.s || {
  5088. k: [100, 100, 100]
  5089. }, 1, 0.01, this);
  5090. // Opacity is not part of the transform properties, that's why it won't use this.dynamicProperties. That way transforms won't get updated if opacity changes.
  5091. if (data.o) {
  5092. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  5093. } else {
  5094. this.o = {
  5095. _mdf: false,
  5096. v: 1
  5097. };
  5098. }
  5099. this._isDirty = true;
  5100. if (!this.dynamicProperties.length) {
  5101. this.getValue(true);
  5102. }
  5103. }
  5104. TransformProperty.prototype = {
  5105. applyToMatrix: applyToMatrix,
  5106. getValue: processKeys,
  5107. precalculateMatrix: precalculateMatrix,
  5108. autoOrient: autoOrient
  5109. };
  5110. extendPrototype([DynamicPropertyContainer], TransformProperty);
  5111. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  5112. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  5113. function getTransformProperty(elem, data, container) {
  5114. return new TransformProperty(elem, data, container);
  5115. }
  5116. return {
  5117. getTransformProperty: getTransformProperty
  5118. };
  5119. }();
  5120. function RepeaterModifier() {}
  5121. extendPrototype([ShapeModifier], RepeaterModifier);
  5122. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5123. this.getValue = this.processKeys;
  5124. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5125. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5126. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5127. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5128. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5129. this.data = data;
  5130. if (!this.dynamicProperties.length) {
  5131. this.getValue(true);
  5132. }
  5133. this._isAnimated = !!this.dynamicProperties.length;
  5134. this.pMatrix = new Matrix();
  5135. this.rMatrix = new Matrix();
  5136. this.sMatrix = new Matrix();
  5137. this.tMatrix = new Matrix();
  5138. this.matrix = new Matrix();
  5139. };
  5140. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5141. var dir = inv ? -1 : 1;
  5142. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5143. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5144. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5145. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5146. rMatrix.rotate(-transform.r.v * dir * perc);
  5147. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5148. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5149. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5150. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5151. };
  5152. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5153. this.elem = elem;
  5154. this.arr = arr;
  5155. this.pos = pos;
  5156. this.elemsData = elemsData;
  5157. this._currentCopies = 0;
  5158. this._elements = [];
  5159. this._groups = [];
  5160. this.frameId = -1;
  5161. this.initDynamicPropertyContainer(elem);
  5162. this.initModifierProperties(elem, arr[pos]);
  5163. while (pos > 0) {
  5164. pos -= 1;
  5165. // this._elements.unshift(arr.splice(pos,1)[0]);
  5166. this._elements.unshift(arr[pos]);
  5167. }
  5168. if (this.dynamicProperties.length) {
  5169. this.k = true;
  5170. } else {
  5171. this.getValue(true);
  5172. }
  5173. };
  5174. RepeaterModifier.prototype.resetElements = function (elements) {
  5175. var i;
  5176. var len = elements.length;
  5177. for (i = 0; i < len; i += 1) {
  5178. elements[i]._processed = false;
  5179. if (elements[i].ty === 'gr') {
  5180. this.resetElements(elements[i].it);
  5181. }
  5182. }
  5183. };
  5184. RepeaterModifier.prototype.cloneElements = function (elements) {
  5185. var newElements = JSON.parse(JSON.stringify(elements));
  5186. this.resetElements(newElements);
  5187. return newElements;
  5188. };
  5189. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5190. var i;
  5191. var len = elements.length;
  5192. for (i = 0; i < len; i += 1) {
  5193. elements[i]._render = renderFlag;
  5194. if (elements[i].ty === 'gr') {
  5195. this.changeGroupRender(elements[i].it, renderFlag);
  5196. }
  5197. }
  5198. };
  5199. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5200. var items;
  5201. var itemsTransform;
  5202. var i;
  5203. var dir;
  5204. var cont;
  5205. var hasReloaded = false;
  5206. if (this._mdf || _isFirstFrame) {
  5207. var copies = Math.ceil(this.c.v);
  5208. if (this._groups.length < copies) {
  5209. while (this._groups.length < copies) {
  5210. var group = {
  5211. it: this.cloneElements(this._elements),
  5212. ty: 'gr'
  5213. };
  5214. group.it.push({
  5215. a: {
  5216. a: 0,
  5217. ix: 1,
  5218. k: [0, 0]
  5219. },
  5220. nm: 'Transform',
  5221. o: {
  5222. a: 0,
  5223. ix: 7,
  5224. k: 100
  5225. },
  5226. p: {
  5227. a: 0,
  5228. ix: 2,
  5229. k: [0, 0]
  5230. },
  5231. r: {
  5232. a: 1,
  5233. ix: 6,
  5234. k: [{
  5235. s: 0,
  5236. e: 0,
  5237. t: 0
  5238. }, {
  5239. s: 0,
  5240. e: 0,
  5241. t: 1
  5242. }]
  5243. },
  5244. s: {
  5245. a: 0,
  5246. ix: 3,
  5247. k: [100, 100]
  5248. },
  5249. sa: {
  5250. a: 0,
  5251. ix: 5,
  5252. k: 0
  5253. },
  5254. sk: {
  5255. a: 0,
  5256. ix: 4,
  5257. k: 0
  5258. },
  5259. ty: 'tr'
  5260. });
  5261. this.arr.splice(0, 0, group);
  5262. this._groups.splice(0, 0, group);
  5263. this._currentCopies += 1;
  5264. }
  5265. this.elem.reloadShapes();
  5266. hasReloaded = true;
  5267. }
  5268. cont = 0;
  5269. var renderFlag;
  5270. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5271. renderFlag = cont < copies;
  5272. this._groups[i]._render = renderFlag;
  5273. this.changeGroupRender(this._groups[i].it, renderFlag);
  5274. if (!renderFlag) {
  5275. var elems = this.elemsData[i].it;
  5276. var transformData = elems[elems.length - 1];
  5277. if (transformData.transform.op.v !== 0) {
  5278. transformData.transform.op._mdf = true;
  5279. transformData.transform.op.v = 0;
  5280. } else {
  5281. transformData.transform.op._mdf = false;
  5282. }
  5283. }
  5284. cont += 1;
  5285. }
  5286. this._currentCopies = copies;
  5287. /// /
  5288. var offset = this.o.v;
  5289. var offsetModulo = offset % 1;
  5290. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5291. var pProps = this.pMatrix.props;
  5292. var rProps = this.rMatrix.props;
  5293. var sProps = this.sMatrix.props;
  5294. this.pMatrix.reset();
  5295. this.rMatrix.reset();
  5296. this.sMatrix.reset();
  5297. this.tMatrix.reset();
  5298. this.matrix.reset();
  5299. var iteration = 0;
  5300. if (offset > 0) {
  5301. while (iteration < roundOffset) {
  5302. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5303. iteration += 1;
  5304. }
  5305. if (offsetModulo) {
  5306. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5307. iteration += offsetModulo;
  5308. }
  5309. } else if (offset < 0) {
  5310. while (iteration > roundOffset) {
  5311. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5312. iteration -= 1;
  5313. }
  5314. if (offsetModulo) {
  5315. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5316. iteration -= offsetModulo;
  5317. }
  5318. }
  5319. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5320. dir = this.data.m === 1 ? 1 : -1;
  5321. cont = this._currentCopies;
  5322. var j;
  5323. var jLen;
  5324. while (cont) {
  5325. items = this.elemsData[i].it;
  5326. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5327. jLen = itemsTransform.length;
  5328. items[items.length - 1].transform.mProps._mdf = true;
  5329. items[items.length - 1].transform.op._mdf = true;
  5330. items[items.length - 1].transform.op.v = this._currentCopies === 1 ? this.so.v : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5331. if (iteration !== 0) {
  5332. if (i !== 0 && dir === 1 || i !== this._currentCopies - 1 && dir === -1) {
  5333. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5334. }
  5335. this.matrix.transform(rProps[0], rProps[1], rProps[2], rProps[3], rProps[4], rProps[5], rProps[6], rProps[7], rProps[8], rProps[9], rProps[10], rProps[11], rProps[12], rProps[13], rProps[14], rProps[15]);
  5336. this.matrix.transform(sProps[0], sProps[1], sProps[2], sProps[3], sProps[4], sProps[5], sProps[6], sProps[7], sProps[8], sProps[9], sProps[10], sProps[11], sProps[12], sProps[13], sProps[14], sProps[15]);
  5337. this.matrix.transform(pProps[0], pProps[1], pProps[2], pProps[3], pProps[4], pProps[5], pProps[6], pProps[7], pProps[8], pProps[9], pProps[10], pProps[11], pProps[12], pProps[13], pProps[14], pProps[15]);
  5338. for (j = 0; j < jLen; j += 1) {
  5339. itemsTransform[j] = this.matrix.props[j];
  5340. }
  5341. this.matrix.reset();
  5342. } else {
  5343. this.matrix.reset();
  5344. for (j = 0; j < jLen; j += 1) {
  5345. itemsTransform[j] = this.matrix.props[j];
  5346. }
  5347. }
  5348. iteration += 1;
  5349. cont -= 1;
  5350. i += dir;
  5351. }
  5352. } else {
  5353. cont = this._currentCopies;
  5354. i = 0;
  5355. dir = 1;
  5356. while (cont) {
  5357. items = this.elemsData[i].it;
  5358. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5359. items[items.length - 1].transform.mProps._mdf = false;
  5360. items[items.length - 1].transform.op._mdf = false;
  5361. cont -= 1;
  5362. i += dir;
  5363. }
  5364. }
  5365. return hasReloaded;
  5366. };
  5367. RepeaterModifier.prototype.addShape = function () {};
  5368. function RoundCornersModifier() {}
  5369. extendPrototype([ShapeModifier], RoundCornersModifier);
  5370. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5371. this.getValue = this.processKeys;
  5372. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5373. this._isAnimated = !!this.rd.effectsSequence.length;
  5374. };
  5375. RoundCornersModifier.prototype.processPath = function (path, round) {
  5376. var clonedPath = shapePool.newElement();
  5377. clonedPath.c = path.c;
  5378. var i;
  5379. var len = path._length;
  5380. var currentV;
  5381. var currentI;
  5382. var currentO;
  5383. var closerV;
  5384. var distance;
  5385. var newPosPerc;
  5386. var index = 0;
  5387. var vX;
  5388. var vY;
  5389. var oX;
  5390. var oY;
  5391. var iX;
  5392. var iY;
  5393. for (i = 0; i < len; i += 1) {
  5394. currentV = path.v[i];
  5395. currentO = path.o[i];
  5396. currentI = path.i[i];
  5397. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5398. if ((i === 0 || i === len - 1) && !path.c) {
  5399. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5400. /* clonedPath.v[index] = currentV;
  5401. clonedPath.o[index] = currentO;
  5402. clonedPath.i[index] = currentI; */
  5403. index += 1;
  5404. } else {
  5405. if (i === 0) {
  5406. closerV = path.v[len - 1];
  5407. } else {
  5408. closerV = path.v[i - 1];
  5409. }
  5410. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5411. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5412. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5413. vX = iX;
  5414. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5415. vY = iY;
  5416. oX = vX - (vX - currentV[0]) * roundCorner;
  5417. oY = vY - (vY - currentV[1]) * roundCorner;
  5418. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5419. index += 1;
  5420. if (i === len - 1) {
  5421. closerV = path.v[0];
  5422. } else {
  5423. closerV = path.v[i + 1];
  5424. }
  5425. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5426. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5427. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5428. vX = oX;
  5429. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5430. vY = oY;
  5431. iX = vX - (vX - currentV[0]) * roundCorner;
  5432. iY = vY - (vY - currentV[1]) * roundCorner;
  5433. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5434. index += 1;
  5435. }
  5436. } else {
  5437. clonedPath.setTripleAt(path.v[i][0], path.v[i][1], path.o[i][0], path.o[i][1], path.i[i][0], path.i[i][1], index);
  5438. index += 1;
  5439. }
  5440. }
  5441. return clonedPath;
  5442. };
  5443. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5444. var shapePaths;
  5445. var i;
  5446. var len = this.shapes.length;
  5447. var j;
  5448. var jLen;
  5449. var rd = this.rd.v;
  5450. if (rd !== 0) {
  5451. var shapeData;
  5452. var localShapeCollection;
  5453. for (i = 0; i < len; i += 1) {
  5454. shapeData = this.shapes[i];
  5455. localShapeCollection = shapeData.localShapeCollection;
  5456. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5457. localShapeCollection.releaseShapes();
  5458. shapeData.shape._mdf = true;
  5459. shapePaths = shapeData.shape.paths.shapes;
  5460. jLen = shapeData.shape.paths._length;
  5461. for (j = 0; j < jLen; j += 1) {
  5462. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5463. }
  5464. }
  5465. shapeData.shape.paths = shapeData.localShapeCollection;
  5466. }
  5467. }
  5468. if (!this.dynamicProperties.length) {
  5469. this._mdf = false;
  5470. }
  5471. };
  5472. function floatEqual(a, b) {
  5473. return Math.abs(a - b) * 100000 <= Math.min(Math.abs(a), Math.abs(b));
  5474. }
  5475. function floatZero(f) {
  5476. return Math.abs(f) <= 0.00001;
  5477. }
  5478. function lerp(p0, p1, amount) {
  5479. return p0 * (1 - amount) + p1 * amount;
  5480. }
  5481. function lerpPoint(p0, p1, amount) {
  5482. return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
  5483. }
  5484. function quadRoots(a, b, c) {
  5485. // no root
  5486. if (a === 0) return [];
  5487. var s = b * b - 4 * a * c;
  5488. // Complex roots
  5489. if (s < 0) return [];
  5490. var singleRoot = -b / (2 * a);
  5491. // 1 root
  5492. if (s === 0) return [singleRoot];
  5493. var delta = Math.sqrt(s) / (2 * a);
  5494. // 2 roots
  5495. return [singleRoot - delta, singleRoot + delta];
  5496. }
  5497. function polynomialCoefficients(p0, p1, p2, p3) {
  5498. return [-p0 + 3 * p1 - 3 * p2 + p3, 3 * p0 - 6 * p1 + 3 * p2, -3 * p0 + 3 * p1, p0];
  5499. }
  5500. function singlePoint(p) {
  5501. return new PolynomialBezier(p, p, p, p, false);
  5502. }
  5503. function PolynomialBezier(p0, p1, p2, p3, linearize) {
  5504. if (linearize && pointEqual(p0, p1)) {
  5505. p1 = lerpPoint(p0, p3, 1 / 3);
  5506. }
  5507. if (linearize && pointEqual(p2, p3)) {
  5508. p2 = lerpPoint(p0, p3, 2 / 3);
  5509. }
  5510. var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
  5511. var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
  5512. this.a = [coeffx[0], coeffy[0]];
  5513. this.b = [coeffx[1], coeffy[1]];
  5514. this.c = [coeffx[2], coeffy[2]];
  5515. this.d = [coeffx[3], coeffy[3]];
  5516. this.points = [p0, p1, p2, p3];
  5517. }
  5518. PolynomialBezier.prototype.point = function (t) {
  5519. return [((this.a[0] * t + this.b[0]) * t + this.c[0]) * t + this.d[0], ((this.a[1] * t + this.b[1]) * t + this.c[1]) * t + this.d[1]];
  5520. };
  5521. PolynomialBezier.prototype.derivative = function (t) {
  5522. return [(3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0], (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1]];
  5523. };
  5524. PolynomialBezier.prototype.tangentAngle = function (t) {
  5525. var p = this.derivative(t);
  5526. return Math.atan2(p[1], p[0]);
  5527. };
  5528. PolynomialBezier.prototype.normalAngle = function (t) {
  5529. var p = this.derivative(t);
  5530. return Math.atan2(p[0], p[1]);
  5531. };
  5532. PolynomialBezier.prototype.inflectionPoints = function () {
  5533. var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
  5534. if (floatZero(denom)) return [];
  5535. var tcusp = -0.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1]) / denom;
  5536. var square = tcusp * tcusp - 1 / 3 * (this.b[1] * this.c[0] - this.b[0] * this.c[1]) / denom;
  5537. if (square < 0) return [];
  5538. var root = Math.sqrt(square);
  5539. if (floatZero(root)) {
  5540. if (root > 0 && root < 1) return [tcusp];
  5541. return [];
  5542. }
  5543. return [tcusp - root, tcusp + root].filter(function (r) {
  5544. return r > 0 && r < 1;
  5545. });
  5546. };
  5547. PolynomialBezier.prototype.split = function (t) {
  5548. if (t <= 0) return [singlePoint(this.points[0]), this];
  5549. if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
  5550. var p10 = lerpPoint(this.points[0], this.points[1], t);
  5551. var p11 = lerpPoint(this.points[1], this.points[2], t);
  5552. var p12 = lerpPoint(this.points[2], this.points[3], t);
  5553. var p20 = lerpPoint(p10, p11, t);
  5554. var p21 = lerpPoint(p11, p12, t);
  5555. var p3 = lerpPoint(p20, p21, t);
  5556. return [new PolynomialBezier(this.points[0], p10, p20, p3, true), new PolynomialBezier(p3, p21, p12, this.points[3], true)];
  5557. };
  5558. function extrema(bez, comp) {
  5559. var min = bez.points[0][comp];
  5560. var max = bez.points[bez.points.length - 1][comp];
  5561. if (min > max) {
  5562. var e = max;
  5563. max = min;
  5564. min = e;
  5565. }
  5566. // Derivative roots to find min/max
  5567. var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
  5568. for (var i = 0; i < f.length; i += 1) {
  5569. if (f[i] > 0 && f[i] < 1) {
  5570. var val = bez.point(f[i])[comp];
  5571. if (val < min) min = val;else if (val > max) max = val;
  5572. }
  5573. }
  5574. return {
  5575. min: min,
  5576. max: max
  5577. };
  5578. }
  5579. PolynomialBezier.prototype.bounds = function () {
  5580. return {
  5581. x: extrema(this, 0),
  5582. y: extrema(this, 1)
  5583. };
  5584. };
  5585. PolynomialBezier.prototype.boundingBox = function () {
  5586. var bounds = this.bounds();
  5587. return {
  5588. left: bounds.x.min,
  5589. right: bounds.x.max,
  5590. top: bounds.y.min,
  5591. bottom: bounds.y.max,
  5592. width: bounds.x.max - bounds.x.min,
  5593. height: bounds.y.max - bounds.y.min,
  5594. cx: (bounds.x.max + bounds.x.min) / 2,
  5595. cy: (bounds.y.max + bounds.y.min) / 2
  5596. };
  5597. };
  5598. function intersectData(bez, t1, t2) {
  5599. var box = bez.boundingBox();
  5600. return {
  5601. cx: box.cx,
  5602. cy: box.cy,
  5603. width: box.width,
  5604. height: box.height,
  5605. bez: bez,
  5606. t: (t1 + t2) / 2,
  5607. t1: t1,
  5608. t2: t2
  5609. };
  5610. }
  5611. function splitData(data) {
  5612. var split = data.bez.split(0.5);
  5613. return [intersectData(split[0], data.t1, data.t), intersectData(split[1], data.t, data.t2)];
  5614. }
  5615. function boxIntersect(b1, b2) {
  5616. return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
  5617. }
  5618. function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
  5619. if (!boxIntersect(d1, d2)) return;
  5620. if (depth >= maxRecursion || d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance) {
  5621. intersections.push([d1.t, d2.t]);
  5622. return;
  5623. }
  5624. var d1s = splitData(d1);
  5625. var d2s = splitData(d2);
  5626. intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5627. intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5628. intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5629. intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5630. }
  5631. PolynomialBezier.prototype.intersections = function (other, tolerance, maxRecursion) {
  5632. if (tolerance === undefined) tolerance = 2;
  5633. if (maxRecursion === undefined) maxRecursion = 7;
  5634. var intersections = [];
  5635. intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
  5636. return intersections;
  5637. };
  5638. PolynomialBezier.shapeSegment = function (shapePath, index) {
  5639. var nextIndex = (index + 1) % shapePath.length();
  5640. return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
  5641. };
  5642. PolynomialBezier.shapeSegmentInverted = function (shapePath, index) {
  5643. var nextIndex = (index + 1) % shapePath.length();
  5644. return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
  5645. };
  5646. function crossProduct(a, b) {
  5647. return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
  5648. }
  5649. function lineIntersection(start1, end1, start2, end2) {
  5650. var v1 = [start1[0], start1[1], 1];
  5651. var v2 = [end1[0], end1[1], 1];
  5652. var v3 = [start2[0], start2[1], 1];
  5653. var v4 = [end2[0], end2[1], 1];
  5654. var r = crossProduct(crossProduct(v1, v2), crossProduct(v3, v4));
  5655. if (floatZero(r[2])) return null;
  5656. return [r[0] / r[2], r[1] / r[2]];
  5657. }
  5658. function polarOffset(p, angle, length) {
  5659. return [p[0] + Math.cos(angle) * length, p[1] - Math.sin(angle) * length];
  5660. }
  5661. function pointDistance(p1, p2) {
  5662. return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
  5663. }
  5664. function pointEqual(p1, p2) {
  5665. return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
  5666. }
  5667. function ZigZagModifier() {}
  5668. extendPrototype([ShapeModifier], ZigZagModifier);
  5669. ZigZagModifier.prototype.initModifierProperties = function (elem, data) {
  5670. this.getValue = this.processKeys;
  5671. this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
  5672. this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5673. this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
  5674. this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
  5675. };
  5676. function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
  5677. var angO = angle - Math.PI / 2;
  5678. var angI = angle + Math.PI / 2;
  5679. var px = point[0] + Math.cos(angle) * direction * amplitude;
  5680. var py = point[1] - Math.sin(angle) * direction * amplitude;
  5681. outputBezier.setTripleAt(px, py, px + Math.cos(angO) * outAmplitude, py - Math.sin(angO) * outAmplitude, px + Math.cos(angI) * inAmplitude, py - Math.sin(angI) * inAmplitude, outputBezier.length());
  5682. }
  5683. function getPerpendicularVector(pt1, pt2) {
  5684. var vector = [pt2[0] - pt1[0], pt2[1] - pt1[1]];
  5685. var rot = -Math.PI * 0.5;
  5686. var rotatedVector = [Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1], Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1]];
  5687. return rotatedVector;
  5688. }
  5689. function getProjectingAngle(path, cur) {
  5690. var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
  5691. var nextIndex = (cur + 1) % path.length();
  5692. var prevPoint = path.v[prevIndex];
  5693. var nextPoint = path.v[nextIndex];
  5694. var pVector = getPerpendicularVector(prevPoint, nextPoint);
  5695. return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
  5696. }
  5697. function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
  5698. var angle = getProjectingAngle(path, cur);
  5699. var point = path.v[cur % path._length];
  5700. var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
  5701. var nextPoint = path.v[(cur + 1) % path._length];
  5702. var prevDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2)) : 0;
  5703. var nextDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2)) : 0;
  5704. setPoint(outputBezier, path.v[cur % path._length], angle, direction, amplitude, nextDist / ((frequency + 1) * 2), prevDist / ((frequency + 1) * 2), pointType);
  5705. }
  5706. function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
  5707. for (var i = 0; i < frequency; i += 1) {
  5708. var t = (i + 1) / (frequency + 1);
  5709. var dist = pointType === 2 ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2)) : 0;
  5710. var angle = segment.normalAngle(t);
  5711. var point = segment.point(t);
  5712. setPoint(outputBezier, point, angle, direction, amplitude, dist / ((frequency + 1) * 2), dist / ((frequency + 1) * 2), pointType);
  5713. direction = -direction;
  5714. }
  5715. return direction;
  5716. }
  5717. ZigZagModifier.prototype.processPath = function (path, amplitude, frequency, pointType) {
  5718. var count = path._length;
  5719. var clonedPath = shapePool.newElement();
  5720. clonedPath.c = path.c;
  5721. if (!path.c) {
  5722. count -= 1;
  5723. }
  5724. if (count === 0) return clonedPath;
  5725. var direction = -1;
  5726. var segment = PolynomialBezier.shapeSegment(path, 0);
  5727. zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
  5728. for (var i = 0; i < count; i += 1) {
  5729. direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
  5730. if (i === count - 1 && !path.c) {
  5731. segment = null;
  5732. } else {
  5733. segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
  5734. }
  5735. zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
  5736. }
  5737. return clonedPath;
  5738. };
  5739. ZigZagModifier.prototype.processShapes = function (_isFirstFrame) {
  5740. var shapePaths;
  5741. var i;
  5742. var len = this.shapes.length;
  5743. var j;
  5744. var jLen;
  5745. var amplitude = this.amplitude.v;
  5746. var frequency = Math.max(0, Math.round(this.frequency.v));
  5747. var pointType = this.pointsType.v;
  5748. if (amplitude !== 0) {
  5749. var shapeData;
  5750. var localShapeCollection;
  5751. for (i = 0; i < len; i += 1) {
  5752. shapeData = this.shapes[i];
  5753. localShapeCollection = shapeData.localShapeCollection;
  5754. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5755. localShapeCollection.releaseShapes();
  5756. shapeData.shape._mdf = true;
  5757. shapePaths = shapeData.shape.paths.shapes;
  5758. jLen = shapeData.shape.paths._length;
  5759. for (j = 0; j < jLen; j += 1) {
  5760. localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
  5761. }
  5762. }
  5763. shapeData.shape.paths = shapeData.localShapeCollection;
  5764. }
  5765. }
  5766. if (!this.dynamicProperties.length) {
  5767. this._mdf = false;
  5768. }
  5769. };
  5770. function linearOffset(p1, p2, amount) {
  5771. var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
  5772. return [polarOffset(p1, angle, amount), polarOffset(p2, angle, amount)];
  5773. }
  5774. function offsetSegment(segment, amount) {
  5775. var p0;
  5776. var p1a;
  5777. var p1b;
  5778. var p2b;
  5779. var p2a;
  5780. var p3;
  5781. var e;
  5782. e = linearOffset(segment.points[0], segment.points[1], amount);
  5783. p0 = e[0];
  5784. p1a = e[1];
  5785. e = linearOffset(segment.points[1], segment.points[2], amount);
  5786. p1b = e[0];
  5787. p2b = e[1];
  5788. e = linearOffset(segment.points[2], segment.points[3], amount);
  5789. p2a = e[0];
  5790. p3 = e[1];
  5791. var p1 = lineIntersection(p0, p1a, p1b, p2b);
  5792. if (p1 === null) p1 = p1a;
  5793. var p2 = lineIntersection(p2a, p3, p1b, p2b);
  5794. if (p2 === null) p2 = p2a;
  5795. return new PolynomialBezier(p0, p1, p2, p3);
  5796. }
  5797. function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
  5798. var p0 = seg1.points[3];
  5799. var p1 = seg2.points[0];
  5800. // Bevel
  5801. if (lineJoin === 3) return p0;
  5802. // Connected, they don't need a joint
  5803. if (pointEqual(p0, p1)) return p0;
  5804. // Round
  5805. if (lineJoin === 2) {
  5806. var angleOut = -seg1.tangentAngle(1);
  5807. var angleIn = -seg2.tangentAngle(0) + Math.PI;
  5808. var center = lineIntersection(p0, polarOffset(p0, angleOut + Math.PI / 2, 100), p1, polarOffset(p1, angleOut + Math.PI / 2, 100));
  5809. var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
  5810. var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
  5811. outputBezier.setXYAt(tan[0], tan[1], 'o', outputBezier.length() - 1);
  5812. tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
  5813. outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
  5814. return p1;
  5815. }
  5816. // Miter
  5817. var t0 = pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2];
  5818. var t1 = pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1];
  5819. var intersection = lineIntersection(t0, p0, p1, t1);
  5820. if (intersection && pointDistance(intersection, p0) < miterLimit) {
  5821. outputBezier.setTripleAt(intersection[0], intersection[1], intersection[0], intersection[1], intersection[0], intersection[1], outputBezier.length());
  5822. return intersection;
  5823. }
  5824. return p0;
  5825. }
  5826. function getIntersection(a, b) {
  5827. var intersect = a.intersections(b);
  5828. if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
  5829. if (intersect.length) return intersect[0];
  5830. return null;
  5831. }
  5832. function pruneSegmentIntersection(a, b) {
  5833. var outa = a.slice();
  5834. var outb = b.slice();
  5835. var intersect = getIntersection(a[a.length - 1], b[0]);
  5836. if (intersect) {
  5837. outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
  5838. outb[0] = b[0].split(intersect[1])[1];
  5839. }
  5840. if (a.length > 1 && b.length > 1) {
  5841. intersect = getIntersection(a[0], b[b.length - 1]);
  5842. if (intersect) {
  5843. return [[a[0].split(intersect[0])[0]], [b[b.length - 1].split(intersect[1])[1]]];
  5844. }
  5845. }
  5846. return [outa, outb];
  5847. }
  5848. function pruneIntersections(segments) {
  5849. var e;
  5850. for (var i = 1; i < segments.length; i += 1) {
  5851. e = pruneSegmentIntersection(segments[i - 1], segments[i]);
  5852. segments[i - 1] = e[0];
  5853. segments[i] = e[1];
  5854. }
  5855. if (segments.length > 1) {
  5856. e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
  5857. segments[segments.length - 1] = e[0];
  5858. segments[0] = e[1];
  5859. }
  5860. return segments;
  5861. }
  5862. function offsetSegmentSplit(segment, amount) {
  5863. /*
  5864. We split each bezier segment into smaller pieces based
  5865. on inflection points, this ensures the control point
  5866. polygon is convex.
  5867. (A cubic bezier can have none, one, or two inflection points)
  5868. */
  5869. var flex = segment.inflectionPoints();
  5870. var left;
  5871. var right;
  5872. var split;
  5873. var mid;
  5874. if (flex.length === 0) {
  5875. return [offsetSegment(segment, amount)];
  5876. }
  5877. if (flex.length === 1 || floatEqual(flex[1], 1)) {
  5878. split = segment.split(flex[0]);
  5879. left = split[0];
  5880. right = split[1];
  5881. return [offsetSegment(left, amount), offsetSegment(right, amount)];
  5882. }
  5883. split = segment.split(flex[0]);
  5884. left = split[0];
  5885. var t = (flex[1] - flex[0]) / (1 - flex[0]);
  5886. split = split[1].split(t);
  5887. mid = split[0];
  5888. right = split[1];
  5889. return [offsetSegment(left, amount), offsetSegment(mid, amount), offsetSegment(right, amount)];
  5890. }
  5891. function OffsetPathModifier() {}
  5892. extendPrototype([ShapeModifier], OffsetPathModifier);
  5893. OffsetPathModifier.prototype.initModifierProperties = function (elem, data) {
  5894. this.getValue = this.processKeys;
  5895. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  5896. this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
  5897. this.lineJoin = data.lj;
  5898. this._isAnimated = this.amount.effectsSequence.length !== 0;
  5899. };
  5900. OffsetPathModifier.prototype.processPath = function (inputBezier, amount, lineJoin, miterLimit) {
  5901. var outputBezier = shapePool.newElement();
  5902. outputBezier.c = inputBezier.c;
  5903. var count = inputBezier.length();
  5904. if (!inputBezier.c) {
  5905. count -= 1;
  5906. }
  5907. var i;
  5908. var j;
  5909. var segment;
  5910. var multiSegments = [];
  5911. for (i = 0; i < count; i += 1) {
  5912. segment = PolynomialBezier.shapeSegment(inputBezier, i);
  5913. multiSegments.push(offsetSegmentSplit(segment, amount));
  5914. }
  5915. if (!inputBezier.c) {
  5916. for (i = count - 1; i >= 0; i -= 1) {
  5917. segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
  5918. multiSegments.push(offsetSegmentSplit(segment, amount));
  5919. }
  5920. }
  5921. multiSegments = pruneIntersections(multiSegments);
  5922. // Add bezier segments to the output and apply line joints
  5923. var lastPoint = null;
  5924. var lastSeg = null;
  5925. for (i = 0; i < multiSegments.length; i += 1) {
  5926. var multiSegment = multiSegments[i];
  5927. if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
  5928. lastSeg = multiSegment[multiSegment.length - 1];
  5929. for (j = 0; j < multiSegment.length; j += 1) {
  5930. segment = multiSegment[j];
  5931. if (lastPoint && pointEqual(segment.points[0], lastPoint)) {
  5932. outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], 'o', outputBezier.length() - 1);
  5933. } else {
  5934. outputBezier.setTripleAt(segment.points[0][0], segment.points[0][1], segment.points[1][0], segment.points[1][1], segment.points[0][0], segment.points[0][1], outputBezier.length());
  5935. }
  5936. outputBezier.setTripleAt(segment.points[3][0], segment.points[3][1], segment.points[3][0], segment.points[3][1], segment.points[2][0], segment.points[2][1], outputBezier.length());
  5937. lastPoint = segment.points[3];
  5938. }
  5939. }
  5940. if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
  5941. return outputBezier;
  5942. };
  5943. OffsetPathModifier.prototype.processShapes = function (_isFirstFrame) {
  5944. var shapePaths;
  5945. var i;
  5946. var len = this.shapes.length;
  5947. var j;
  5948. var jLen;
  5949. var amount = this.amount.v;
  5950. var miterLimit = this.miterLimit.v;
  5951. var lineJoin = this.lineJoin;
  5952. if (amount !== 0) {
  5953. var shapeData;
  5954. var localShapeCollection;
  5955. for (i = 0; i < len; i += 1) {
  5956. shapeData = this.shapes[i];
  5957. localShapeCollection = shapeData.localShapeCollection;
  5958. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5959. localShapeCollection.releaseShapes();
  5960. shapeData.shape._mdf = true;
  5961. shapePaths = shapeData.shape.paths.shapes;
  5962. jLen = shapeData.shape.paths._length;
  5963. for (j = 0; j < jLen; j += 1) {
  5964. localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
  5965. }
  5966. }
  5967. shapeData.shape.paths = shapeData.localShapeCollection;
  5968. }
  5969. }
  5970. if (!this.dynamicProperties.length) {
  5971. this._mdf = false;
  5972. }
  5973. };
  5974. function getFontProperties(fontData) {
  5975. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5976. var fWeight = 'normal';
  5977. var fStyle = 'normal';
  5978. var len = styles.length;
  5979. var styleName;
  5980. for (var i = 0; i < len; i += 1) {
  5981. styleName = styles[i].toLowerCase();
  5982. switch (styleName) {
  5983. case 'italic':
  5984. fStyle = 'italic';
  5985. break;
  5986. case 'bold':
  5987. fWeight = '700';
  5988. break;
  5989. case 'black':
  5990. fWeight = '900';
  5991. break;
  5992. case 'medium':
  5993. fWeight = '500';
  5994. break;
  5995. case 'regular':
  5996. case 'normal':
  5997. fWeight = '400';
  5998. break;
  5999. case 'light':
  6000. case 'thin':
  6001. fWeight = '200';
  6002. break;
  6003. default:
  6004. break;
  6005. }
  6006. }
  6007. return {
  6008. style: fStyle,
  6009. weight: fontData.fWeight || fWeight
  6010. };
  6011. }
  6012. var FontManager = function () {
  6013. var maxWaitingTime = 5000;
  6014. var emptyChar = {
  6015. w: 0,
  6016. size: 0,
  6017. shapes: [],
  6018. data: {
  6019. shapes: []
  6020. }
  6021. };
  6022. var combinedCharacters = [];
  6023. // Hindi characters
  6024. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366, 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379, 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  6025. var BLACK_FLAG_CODE_POINT = 127988;
  6026. var CANCEL_TAG_CODE_POINT = 917631;
  6027. var A_TAG_CODE_POINT = 917601;
  6028. var Z_TAG_CODE_POINT = 917626;
  6029. var VARIATION_SELECTOR_16_CODE_POINT = 65039;
  6030. var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
  6031. var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
  6032. var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
  6033. var surrogateModifiers = ['d83cdffb', 'd83cdffc', 'd83cdffd', 'd83cdffe', 'd83cdfff'];
  6034. function trimFontOptions(font) {
  6035. var familyArray = font.split(',');
  6036. var i;
  6037. var len = familyArray.length;
  6038. var enabledFamilies = [];
  6039. for (i = 0; i < len; i += 1) {
  6040. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  6041. enabledFamilies.push(familyArray[i]);
  6042. }
  6043. }
  6044. return enabledFamilies.join(',');
  6045. }
  6046. function setUpNode(font, family) {
  6047. var parentNode = createTag('span');
  6048. // Node is invisible to screen readers.
  6049. parentNode.setAttribute('aria-hidden', true);
  6050. parentNode.style.fontFamily = family;
  6051. var node = createTag('span');
  6052. // Characters that vary significantly among different fonts
  6053. node.innerText = 'giItT1WQy@!-/#';
  6054. // Visible - so we can measure it - but not on the screen
  6055. parentNode.style.position = 'absolute';
  6056. parentNode.style.left = '-10000px';
  6057. parentNode.style.top = '-10000px';
  6058. // Large font size makes even subtle changes obvious
  6059. parentNode.style.fontSize = '300px';
  6060. // Reset any font properties
  6061. parentNode.style.fontVariant = 'normal';
  6062. parentNode.style.fontStyle = 'normal';
  6063. parentNode.style.fontWeight = 'normal';
  6064. parentNode.style.letterSpacing = '0';
  6065. parentNode.appendChild(node);
  6066. document.body.appendChild(parentNode);
  6067. // Remember width with no applied web font
  6068. var width = node.offsetWidth;
  6069. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  6070. return {
  6071. node: node,
  6072. w: width,
  6073. parent: parentNode
  6074. };
  6075. }
  6076. function checkLoadedFonts() {
  6077. var i;
  6078. var len = this.fonts.length;
  6079. var node;
  6080. var w;
  6081. var loadedCount = len;
  6082. for (i = 0; i < len; i += 1) {
  6083. if (this.fonts[i].loaded) {
  6084. loadedCount -= 1;
  6085. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  6086. this.fonts[i].loaded = true;
  6087. } else {
  6088. node = this.fonts[i].monoCase.node;
  6089. w = this.fonts[i].monoCase.w;
  6090. if (node.offsetWidth !== w) {
  6091. loadedCount -= 1;
  6092. this.fonts[i].loaded = true;
  6093. } else {
  6094. node = this.fonts[i].sansCase.node;
  6095. w = this.fonts[i].sansCase.w;
  6096. if (node.offsetWidth !== w) {
  6097. loadedCount -= 1;
  6098. this.fonts[i].loaded = true;
  6099. }
  6100. }
  6101. if (this.fonts[i].loaded) {
  6102. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  6103. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  6104. }
  6105. }
  6106. }
  6107. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  6108. setTimeout(this.checkLoadedFontsBinded, 20);
  6109. } else {
  6110. setTimeout(this.setIsLoadedBinded, 10);
  6111. }
  6112. }
  6113. function createHelper(fontData, def) {
  6114. var engine = document.body && def ? 'svg' : 'canvas';
  6115. var helper;
  6116. var fontProps = getFontProperties(fontData);
  6117. if (engine === 'svg') {
  6118. var tHelper = createNS('text');
  6119. tHelper.style.fontSize = '100px';
  6120. // tHelper.style.fontFamily = fontData.fFamily;
  6121. tHelper.setAttribute('font-family', fontData.fFamily);
  6122. tHelper.setAttribute('font-style', fontProps.style);
  6123. tHelper.setAttribute('font-weight', fontProps.weight);
  6124. tHelper.textContent = '1';
  6125. if (fontData.fClass) {
  6126. tHelper.style.fontFamily = 'inherit';
  6127. tHelper.setAttribute('class', fontData.fClass);
  6128. } else {
  6129. tHelper.style.fontFamily = fontData.fFamily;
  6130. }
  6131. def.appendChild(tHelper);
  6132. helper = tHelper;
  6133. } else {
  6134. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  6135. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  6136. helper = tCanvasHelper;
  6137. }
  6138. function measure(text) {
  6139. if (engine === 'svg') {
  6140. helper.textContent = text;
  6141. return helper.getComputedTextLength();
  6142. }
  6143. return helper.measureText(text).width;
  6144. }
  6145. return {
  6146. measureText: measure
  6147. };
  6148. }
  6149. function addFonts(fontData, defs) {
  6150. if (!fontData) {
  6151. this.isLoaded = true;
  6152. return;
  6153. }
  6154. if (this.chars) {
  6155. this.isLoaded = true;
  6156. this.fonts = fontData.list;
  6157. return;
  6158. }
  6159. if (!document.body) {
  6160. this.isLoaded = true;
  6161. fontData.list.forEach(function (data) {
  6162. data.helper = createHelper(data);
  6163. data.cache = {};
  6164. });
  6165. this.fonts = fontData.list;
  6166. return;
  6167. }
  6168. var fontArr = fontData.list;
  6169. var i;
  6170. var len = fontArr.length;
  6171. var _pendingFonts = len;
  6172. for (i = 0; i < len; i += 1) {
  6173. var shouldLoadFont = true;
  6174. var loadedSelector;
  6175. var j;
  6176. fontArr[i].loaded = false;
  6177. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  6178. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  6179. if (!fontArr[i].fPath) {
  6180. fontArr[i].loaded = true;
  6181. _pendingFonts -= 1;
  6182. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  6183. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  6184. if (loadedSelector.length > 0) {
  6185. shouldLoadFont = false;
  6186. }
  6187. if (shouldLoadFont) {
  6188. var s = createTag('style');
  6189. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  6190. s.setAttribute('f-origin', fontArr[i].origin);
  6191. s.setAttribute('f-family', fontArr[i].fFamily);
  6192. s.type = 'text/css';
  6193. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  6194. defs.appendChild(s);
  6195. }
  6196. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  6197. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  6198. for (j = 0; j < loadedSelector.length; j += 1) {
  6199. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  6200. // Font is already loaded
  6201. shouldLoadFont = false;
  6202. }
  6203. }
  6204. if (shouldLoadFont) {
  6205. var l = createTag('link');
  6206. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  6207. l.setAttribute('f-origin', fontArr[i].origin);
  6208. l.type = 'text/css';
  6209. l.rel = 'stylesheet';
  6210. l.href = fontArr[i].fPath;
  6211. document.body.appendChild(l);
  6212. }
  6213. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  6214. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  6215. for (j = 0; j < loadedSelector.length; j += 1) {
  6216. if (fontArr[i].fPath === loadedSelector[j].src) {
  6217. // Font is already loaded
  6218. shouldLoadFont = false;
  6219. }
  6220. }
  6221. if (shouldLoadFont) {
  6222. var sc = createTag('link');
  6223. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  6224. sc.setAttribute('f-origin', fontArr[i].origin);
  6225. sc.setAttribute('rel', 'stylesheet');
  6226. sc.setAttribute('href', fontArr[i].fPath);
  6227. defs.appendChild(sc);
  6228. }
  6229. }
  6230. fontArr[i].helper = createHelper(fontArr[i], defs);
  6231. fontArr[i].cache = {};
  6232. this.fonts.push(fontArr[i]);
  6233. }
  6234. if (_pendingFonts === 0) {
  6235. this.isLoaded = true;
  6236. } else {
  6237. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  6238. // Adding this timeout seems to fix it
  6239. setTimeout(this.checkLoadedFonts.bind(this), 100);
  6240. }
  6241. }
  6242. function addChars(chars) {
  6243. if (!chars) {
  6244. return;
  6245. }
  6246. if (!this.chars) {
  6247. this.chars = [];
  6248. }
  6249. var i;
  6250. var len = chars.length;
  6251. var j;
  6252. var jLen = this.chars.length;
  6253. var found;
  6254. for (i = 0; i < len; i += 1) {
  6255. j = 0;
  6256. found = false;
  6257. while (j < jLen) {
  6258. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  6259. found = true;
  6260. }
  6261. j += 1;
  6262. }
  6263. if (!found) {
  6264. this.chars.push(chars[i]);
  6265. jLen += 1;
  6266. }
  6267. }
  6268. }
  6269. function getCharData(_char, style, font) {
  6270. var i = 0;
  6271. var len = this.chars.length;
  6272. while (i < len) {
  6273. if (this.chars[i].ch === _char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  6274. return this.chars[i];
  6275. }
  6276. i += 1;
  6277. }
  6278. if ((typeof _char === 'string' && _char.charCodeAt(0) !== 13 || !_char) && console && console.warn // eslint-disable-line no-console
  6279. && !this._warned) {
  6280. this._warned = true;
  6281. console.warn('Missing character from exported characters list: ', _char, style, font); // eslint-disable-line no-console
  6282. }
  6283. return emptyChar;
  6284. }
  6285. function measureText(_char2, fontName, size) {
  6286. var fontData = this.getFontByName(fontName);
  6287. // Using the char instead of char.charCodeAt(0)
  6288. // to avoid collisions between equal chars
  6289. var index = _char2;
  6290. if (!fontData.cache[index]) {
  6291. var tHelper = fontData.helper;
  6292. if (_char2 === ' ') {
  6293. var doubleSize = tHelper.measureText('|' + _char2 + '|');
  6294. var singleSize = tHelper.measureText('||');
  6295. fontData.cache[index] = (doubleSize - singleSize) / 100;
  6296. } else {
  6297. fontData.cache[index] = tHelper.measureText(_char2) / 100;
  6298. }
  6299. }
  6300. return fontData.cache[index] * size;
  6301. }
  6302. function getFontByName(name) {
  6303. var i = 0;
  6304. var len = this.fonts.length;
  6305. while (i < len) {
  6306. if (this.fonts[i].fName === name) {
  6307. return this.fonts[i];
  6308. }
  6309. i += 1;
  6310. }
  6311. return this.fonts[0];
  6312. }
  6313. function getCodePoint(string) {
  6314. var codePoint = 0;
  6315. var first = string.charCodeAt(0);
  6316. if (first >= 0xD800 && first <= 0xDBFF) {
  6317. var second = string.charCodeAt(1);
  6318. if (second >= 0xDC00 && second <= 0xDFFF) {
  6319. codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  6320. }
  6321. }
  6322. return codePoint;
  6323. }
  6324. // Skin tone modifiers
  6325. function isModifier(firstCharCode, secondCharCode) {
  6326. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  6327. return surrogateModifiers.indexOf(sum) !== -1;
  6328. }
  6329. function isZeroWidthJoiner(charCode) {
  6330. return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
  6331. }
  6332. // This codepoint may change the appearance of the preceding character.
  6333. // If that is a symbol, dingbat or emoji, U+FE0F forces it to be rendered
  6334. // as a colorful image as compared to a monochrome text variant.
  6335. function isVariationSelector(charCode) {
  6336. return charCode === VARIATION_SELECTOR_16_CODE_POINT;
  6337. }
  6338. // The regional indicator symbols are a set of 26 alphabetic Unicode
  6339. /// characters (A–Z) intended to be used to encode ISO 3166-1 alpha-2
  6340. // two-letter country codes in a way that allows optional special treatment.
  6341. function isRegionalCode(string) {
  6342. var codePoint = getCodePoint(string);
  6343. if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) {
  6344. return true;
  6345. }
  6346. return false;
  6347. }
  6348. // Some Emoji implementations represent combinations of
  6349. // two “regional indicator” letters as a single flag symbol.
  6350. function isFlagEmoji(string) {
  6351. return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
  6352. }
  6353. function isCombinedCharacter(_char3) {
  6354. return combinedCharacters.indexOf(_char3) !== -1;
  6355. }
  6356. // Regional flags start with a BLACK_FLAG_CODE_POINT
  6357. // folowed by 5 chars in the TAG range
  6358. // and end with a CANCEL_TAG_CODE_POINT
  6359. function isRegionalFlag(text, index) {
  6360. var codePoint = getCodePoint(text.substr(index, 2));
  6361. if (codePoint !== BLACK_FLAG_CODE_POINT) {
  6362. return false;
  6363. }
  6364. var count = 0;
  6365. index += 2;
  6366. while (count < 5) {
  6367. codePoint = getCodePoint(text.substr(index, 2));
  6368. if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) {
  6369. return false;
  6370. }
  6371. count += 1;
  6372. index += 2;
  6373. }
  6374. return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
  6375. }
  6376. function setIsLoaded() {
  6377. this.isLoaded = true;
  6378. }
  6379. var Font = function Font() {
  6380. this.fonts = [];
  6381. this.chars = null;
  6382. this.typekitLoaded = 0;
  6383. this.isLoaded = false;
  6384. this._warned = false;
  6385. this.initTime = Date.now();
  6386. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  6387. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  6388. };
  6389. Font.isModifier = isModifier;
  6390. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  6391. Font.isFlagEmoji = isFlagEmoji;
  6392. Font.isRegionalCode = isRegionalCode;
  6393. Font.isCombinedCharacter = isCombinedCharacter;
  6394. Font.isRegionalFlag = isRegionalFlag;
  6395. Font.isVariationSelector = isVariationSelector;
  6396. Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
  6397. var fontPrototype = {
  6398. addChars: addChars,
  6399. addFonts: addFonts,
  6400. getCharData: getCharData,
  6401. getFontByName: getFontByName,
  6402. measureText: measureText,
  6403. checkLoadedFonts: checkLoadedFonts,
  6404. setIsLoaded: setIsLoaded
  6405. };
  6406. Font.prototype = fontPrototype;
  6407. return Font;
  6408. }();
  6409. function SlotManager(animationData) {
  6410. this.animationData = animationData;
  6411. }
  6412. SlotManager.prototype.getProp = function (data) {
  6413. if (this.animationData.slots && this.animationData.slots[data.sid]) {
  6414. return Object.assign(data, this.animationData.slots[data.sid].p);
  6415. }
  6416. return data;
  6417. };
  6418. function slotFactory(animationData) {
  6419. return new SlotManager(animationData);
  6420. }
  6421. function RenderableElement() {}
  6422. RenderableElement.prototype = {
  6423. initRenderable: function initRenderable() {
  6424. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6425. this.isInRange = false;
  6426. // layer's display state
  6427. this.hidden = false;
  6428. // If layer's transparency equals 0, it can be hidden
  6429. this.isTransparent = false;
  6430. // list of animated components
  6431. this.renderableComponents = [];
  6432. },
  6433. addRenderableComponent: function addRenderableComponent(component) {
  6434. if (this.renderableComponents.indexOf(component) === -1) {
  6435. this.renderableComponents.push(component);
  6436. }
  6437. },
  6438. removeRenderableComponent: function removeRenderableComponent(component) {
  6439. if (this.renderableComponents.indexOf(component) !== -1) {
  6440. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6441. }
  6442. },
  6443. prepareRenderableFrame: function prepareRenderableFrame(num) {
  6444. this.checkLayerLimits(num);
  6445. },
  6446. checkTransparency: function checkTransparency() {
  6447. if (this.finalTransform.mProp.o.v <= 0) {
  6448. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  6449. this.isTransparent = true;
  6450. this.hide();
  6451. }
  6452. } else if (this.isTransparent) {
  6453. this.isTransparent = false;
  6454. this.show();
  6455. }
  6456. },
  6457. /**
  6458. * @function
  6459. * Initializes frame related properties.
  6460. *
  6461. * @param {number} num
  6462. * current frame number in Layer's time
  6463. *
  6464. */
  6465. checkLayerLimits: function checkLayerLimits(num) {
  6466. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  6467. if (this.isInRange !== true) {
  6468. this.globalData._mdf = true;
  6469. this._mdf = true;
  6470. this.isInRange = true;
  6471. this.show();
  6472. }
  6473. } else if (this.isInRange !== false) {
  6474. this.globalData._mdf = true;
  6475. this.isInRange = false;
  6476. this.hide();
  6477. }
  6478. },
  6479. renderRenderable: function renderRenderable() {
  6480. var i;
  6481. var len = this.renderableComponents.length;
  6482. for (i = 0; i < len; i += 1) {
  6483. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6484. }
  6485. /* this.maskManager.renderFrame(this.finalTransform.mat);
  6486. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  6487. },
  6488. sourceRectAtTime: function sourceRectAtTime() {
  6489. return {
  6490. top: 0,
  6491. left: 0,
  6492. width: 100,
  6493. height: 100
  6494. };
  6495. },
  6496. getLayerSize: function getLayerSize() {
  6497. if (this.data.ty === 5) {
  6498. return {
  6499. w: this.data.textData.width,
  6500. h: this.data.textData.height
  6501. };
  6502. }
  6503. return {
  6504. w: this.data.width,
  6505. h: this.data.height
  6506. };
  6507. }
  6508. };
  6509. var getBlendMode = function () {
  6510. var blendModeEnums = {
  6511. 0: 'source-over',
  6512. 1: 'multiply',
  6513. 2: 'screen',
  6514. 3: 'overlay',
  6515. 4: 'darken',
  6516. 5: 'lighten',
  6517. 6: 'color-dodge',
  6518. 7: 'color-burn',
  6519. 8: 'hard-light',
  6520. 9: 'soft-light',
  6521. 10: 'difference',
  6522. 11: 'exclusion',
  6523. 12: 'hue',
  6524. 13: 'saturation',
  6525. 14: 'color',
  6526. 15: 'luminosity'
  6527. };
  6528. return function (mode) {
  6529. return blendModeEnums[mode] || '';
  6530. };
  6531. }();
  6532. function SliderEffect(data, elem, container) {
  6533. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6534. }
  6535. function AngleEffect(data, elem, container) {
  6536. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6537. }
  6538. function ColorEffect(data, elem, container) {
  6539. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6540. }
  6541. function PointEffect(data, elem, container) {
  6542. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6543. }
  6544. function LayerIndexEffect(data, elem, container) {
  6545. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6546. }
  6547. function MaskIndexEffect(data, elem, container) {
  6548. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6549. }
  6550. function CheckboxEffect(data, elem, container) {
  6551. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6552. }
  6553. function NoValueEffect() {
  6554. this.p = {};
  6555. }
  6556. function EffectsManager(data, element) {
  6557. var effects = data.ef || [];
  6558. this.effectElements = [];
  6559. var i;
  6560. var len = effects.length;
  6561. var effectItem;
  6562. for (i = 0; i < len; i += 1) {
  6563. effectItem = new GroupEffect(effects[i], element);
  6564. this.effectElements.push(effectItem);
  6565. }
  6566. }
  6567. function GroupEffect(data, element) {
  6568. this.init(data, element);
  6569. }
  6570. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6571. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6572. GroupEffect.prototype.init = function (data, element) {
  6573. this.data = data;
  6574. this.effectElements = [];
  6575. this.initDynamicPropertyContainer(element);
  6576. var i;
  6577. var len = this.data.ef.length;
  6578. var eff;
  6579. var effects = this.data.ef;
  6580. for (i = 0; i < len; i += 1) {
  6581. eff = null;
  6582. switch (effects[i].ty) {
  6583. case 0:
  6584. eff = new SliderEffect(effects[i], element, this);
  6585. break;
  6586. case 1:
  6587. eff = new AngleEffect(effects[i], element, this);
  6588. break;
  6589. case 2:
  6590. eff = new ColorEffect(effects[i], element, this);
  6591. break;
  6592. case 3:
  6593. eff = new PointEffect(effects[i], element, this);
  6594. break;
  6595. case 4:
  6596. case 7:
  6597. eff = new CheckboxEffect(effects[i], element, this);
  6598. break;
  6599. case 10:
  6600. eff = new LayerIndexEffect(effects[i], element, this);
  6601. break;
  6602. case 11:
  6603. eff = new MaskIndexEffect(effects[i], element, this);
  6604. break;
  6605. case 5:
  6606. eff = new EffectsManager(effects[i], element, this);
  6607. break;
  6608. // case 6:
  6609. default:
  6610. eff = new NoValueEffect(effects[i], element, this);
  6611. break;
  6612. }
  6613. if (eff) {
  6614. this.effectElements.push(eff);
  6615. }
  6616. }
  6617. };
  6618. function BaseElement() {}
  6619. BaseElement.prototype = {
  6620. checkMasks: function checkMasks() {
  6621. if (!this.data.hasMask) {
  6622. return false;
  6623. }
  6624. var i = 0;
  6625. var len = this.data.masksProperties.length;
  6626. while (i < len) {
  6627. if (this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false) {
  6628. return true;
  6629. }
  6630. i += 1;
  6631. }
  6632. return false;
  6633. },
  6634. initExpressions: function initExpressions() {
  6635. var expressionsInterfaces = getExpressionInterfaces();
  6636. if (!expressionsInterfaces) {
  6637. return;
  6638. }
  6639. var LayerExpressionInterface = expressionsInterfaces('layer');
  6640. var EffectsExpressionInterface = expressionsInterfaces('effects');
  6641. var ShapeExpressionInterface = expressionsInterfaces('shape');
  6642. var TextExpressionInterface = expressionsInterfaces('text');
  6643. var CompExpressionInterface = expressionsInterfaces('comp');
  6644. this.layerInterface = LayerExpressionInterface(this);
  6645. if (this.data.hasMask && this.maskManager) {
  6646. this.layerInterface.registerMaskInterface(this.maskManager);
  6647. }
  6648. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
  6649. this.layerInterface.registerEffectsInterface(effectsInterface);
  6650. if (this.data.ty === 0 || this.data.xt) {
  6651. this.compInterface = CompExpressionInterface(this);
  6652. } else if (this.data.ty === 4) {
  6653. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
  6654. this.layerInterface.content = this.layerInterface.shapeInterface;
  6655. } else if (this.data.ty === 5) {
  6656. this.layerInterface.textInterface = TextExpressionInterface(this);
  6657. this.layerInterface.text = this.layerInterface.textInterface;
  6658. }
  6659. },
  6660. setBlendMode: function setBlendMode() {
  6661. var blendModeValue = getBlendMode(this.data.bm);
  6662. var elem = this.baseElement || this.layerElement;
  6663. elem.style['mix-blend-mode'] = blendModeValue;
  6664. },
  6665. initBaseData: function initBaseData(data, globalData, comp) {
  6666. this.globalData = globalData;
  6667. this.comp = comp;
  6668. this.data = data;
  6669. this.layerId = createElementID();
  6670. // Stretch factor for old animations missing this property.
  6671. if (!this.data.sr) {
  6672. this.data.sr = 1;
  6673. }
  6674. // effects manager
  6675. this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
  6676. },
  6677. getType: function getType() {
  6678. return this.type;
  6679. },
  6680. sourceRectAtTime: function sourceRectAtTime() {}
  6681. };
  6682. /**
  6683. * @file
  6684. * Handles element's layer frame update.
  6685. * Checks layer in point and out point
  6686. *
  6687. */
  6688. function FrameElement() {}
  6689. FrameElement.prototype = {
  6690. /**
  6691. * @function
  6692. * Initializes frame related properties.
  6693. *
  6694. */
  6695. initFrame: function initFrame() {
  6696. // set to true when inpoint is rendered
  6697. this._isFirstFrame = false;
  6698. // list of animated properties
  6699. this.dynamicProperties = [];
  6700. // If layer has been modified in current tick this will be true
  6701. this._mdf = false;
  6702. },
  6703. /**
  6704. * @function
  6705. * Calculates all dynamic values
  6706. *
  6707. * @param {number} num
  6708. * current frame number in Layer's time
  6709. * @param {boolean} isVisible
  6710. * if layers is currently in range
  6711. *
  6712. */
  6713. prepareProperties: function prepareProperties(num, isVisible) {
  6714. var i;
  6715. var len = this.dynamicProperties.length;
  6716. for (i = 0; i < len; i += 1) {
  6717. if (isVisible || this._isParent && this.dynamicProperties[i].propType === 'transform') {
  6718. this.dynamicProperties[i].getValue();
  6719. if (this.dynamicProperties[i]._mdf) {
  6720. this.globalData._mdf = true;
  6721. this._mdf = true;
  6722. }
  6723. }
  6724. }
  6725. },
  6726. addDynamicProperty: function addDynamicProperty(prop) {
  6727. if (this.dynamicProperties.indexOf(prop) === -1) {
  6728. this.dynamicProperties.push(prop);
  6729. }
  6730. }
  6731. };
  6732. function FootageElement(data, globalData, comp) {
  6733. this.initFrame();
  6734. this.initRenderable();
  6735. this.assetData = globalData.getAssetData(data.refId);
  6736. this.footageData = globalData.imageLoader.getAsset(this.assetData);
  6737. this.initBaseData(data, globalData, comp);
  6738. }
  6739. FootageElement.prototype.prepareFrame = function () {};
  6740. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  6741. FootageElement.prototype.getBaseElement = function () {
  6742. return null;
  6743. };
  6744. FootageElement.prototype.renderFrame = function () {};
  6745. FootageElement.prototype.destroy = function () {};
  6746. FootageElement.prototype.initExpressions = function () {
  6747. var expressionsInterfaces = getExpressionInterfaces();
  6748. if (!expressionsInterfaces) {
  6749. return;
  6750. }
  6751. var FootageInterface = expressionsInterfaces('footage');
  6752. this.layerInterface = FootageInterface(this);
  6753. };
  6754. FootageElement.prototype.getFootageData = function () {
  6755. return this.footageData;
  6756. };
  6757. function AudioElement(data, globalData, comp) {
  6758. this.initFrame();
  6759. this.initRenderable();
  6760. this.assetData = globalData.getAssetData(data.refId);
  6761. this.initBaseData(data, globalData, comp);
  6762. this._isPlaying = false;
  6763. this._canPlay = false;
  6764. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6765. this.audio = this.globalData.audioController.createAudio(assetPath);
  6766. this._currentTime = 0;
  6767. this.globalData.audioController.addAudio(this);
  6768. this._volumeMultiplier = 1;
  6769. this._volume = 1;
  6770. this._previousVolume = null;
  6771. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  6772. _placeholder: true
  6773. };
  6774. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : {
  6775. k: [100]
  6776. }, 1, 0.01, this);
  6777. }
  6778. AudioElement.prototype.prepareFrame = function (num) {
  6779. this.prepareRenderableFrame(num, true);
  6780. this.prepareProperties(num, true);
  6781. if (!this.tm._placeholder) {
  6782. var timeRemapped = this.tm.v;
  6783. this._currentTime = timeRemapped;
  6784. } else {
  6785. this._currentTime = num / this.data.sr;
  6786. }
  6787. this._volume = this.lv.v[0];
  6788. var totalVolume = this._volume * this._volumeMultiplier;
  6789. if (this._previousVolume !== totalVolume) {
  6790. this._previousVolume = totalVolume;
  6791. this.audio.volume(totalVolume);
  6792. }
  6793. };
  6794. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  6795. AudioElement.prototype.renderFrame = function () {
  6796. if (this.isInRange && this._canPlay) {
  6797. if (!this._isPlaying) {
  6798. this.audio.play();
  6799. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6800. this._isPlaying = true;
  6801. } else if (!this.audio.playing() || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1) {
  6802. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6803. }
  6804. }
  6805. };
  6806. AudioElement.prototype.show = function () {
  6807. // this.audio.play()
  6808. };
  6809. AudioElement.prototype.hide = function () {
  6810. this.audio.pause();
  6811. this._isPlaying = false;
  6812. };
  6813. AudioElement.prototype.pause = function () {
  6814. this.audio.pause();
  6815. this._isPlaying = false;
  6816. this._canPlay = false;
  6817. };
  6818. AudioElement.prototype.resume = function () {
  6819. this._canPlay = true;
  6820. };
  6821. AudioElement.prototype.setRate = function (rateValue) {
  6822. this.audio.rate(rateValue);
  6823. };
  6824. AudioElement.prototype.volume = function (volumeValue) {
  6825. this._volumeMultiplier = volumeValue;
  6826. this._previousVolume = volumeValue * this._volume;
  6827. this.audio.volume(this._previousVolume);
  6828. };
  6829. AudioElement.prototype.getBaseElement = function () {
  6830. return null;
  6831. };
  6832. AudioElement.prototype.destroy = function () {};
  6833. AudioElement.prototype.sourceRectAtTime = function () {};
  6834. AudioElement.prototype.initExpressions = function () {};
  6835. function BaseRenderer() {}
  6836. BaseRenderer.prototype.checkLayers = function (num) {
  6837. var i;
  6838. var len = this.layers.length;
  6839. var data;
  6840. this.completeLayers = true;
  6841. for (i = len - 1; i >= 0; i -= 1) {
  6842. if (!this.elements[i]) {
  6843. data = this.layers[i];
  6844. if (data.ip - data.st <= num - this.layers[i].st && data.op - data.st > num - this.layers[i].st) {
  6845. this.buildItem(i);
  6846. }
  6847. }
  6848. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  6849. }
  6850. this.checkPendingElements();
  6851. };
  6852. BaseRenderer.prototype.createItem = function (layer) {
  6853. switch (layer.ty) {
  6854. case 2:
  6855. return this.createImage(layer);
  6856. case 0:
  6857. return this.createComp(layer);
  6858. case 1:
  6859. return this.createSolid(layer);
  6860. case 3:
  6861. return this.createNull(layer);
  6862. case 4:
  6863. return this.createShape(layer);
  6864. case 5:
  6865. return this.createText(layer);
  6866. case 6:
  6867. return this.createAudio(layer);
  6868. case 13:
  6869. return this.createCamera(layer);
  6870. case 15:
  6871. return this.createFootage(layer);
  6872. default:
  6873. return this.createNull(layer);
  6874. }
  6875. };
  6876. BaseRenderer.prototype.createCamera = function () {
  6877. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  6878. };
  6879. BaseRenderer.prototype.createAudio = function (data) {
  6880. return new AudioElement(data, this.globalData, this);
  6881. };
  6882. BaseRenderer.prototype.createFootage = function (data) {
  6883. return new FootageElement(data, this.globalData, this);
  6884. };
  6885. BaseRenderer.prototype.buildAllItems = function () {
  6886. var i;
  6887. var len = this.layers.length;
  6888. for (i = 0; i < len; i += 1) {
  6889. this.buildItem(i);
  6890. }
  6891. this.checkPendingElements();
  6892. };
  6893. BaseRenderer.prototype.includeLayers = function (newLayers) {
  6894. this.completeLayers = false;
  6895. var i;
  6896. var len = newLayers.length;
  6897. var j;
  6898. var jLen = this.layers.length;
  6899. for (i = 0; i < len; i += 1) {
  6900. j = 0;
  6901. while (j < jLen) {
  6902. if (this.layers[j].id === newLayers[i].id) {
  6903. this.layers[j] = newLayers[i];
  6904. break;
  6905. }
  6906. j += 1;
  6907. }
  6908. }
  6909. };
  6910. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  6911. this.globalData.projectInterface = pInterface;
  6912. };
  6913. BaseRenderer.prototype.initItems = function () {
  6914. if (!this.globalData.progressiveLoad) {
  6915. this.buildAllItems();
  6916. }
  6917. };
  6918. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  6919. var elements = this.elements;
  6920. var layers = this.layers;
  6921. var i = 0;
  6922. var len = layers.length;
  6923. while (i < len) {
  6924. if (layers[i].ind == parentName) {
  6925. // eslint-disable-line eqeqeq
  6926. if (!elements[i] || elements[i] === true) {
  6927. this.buildItem(i);
  6928. this.addPendingElement(element);
  6929. } else {
  6930. hierarchy.push(elements[i]);
  6931. elements[i].setAsParent();
  6932. if (layers[i].parent !== undefined) {
  6933. this.buildElementParenting(element, layers[i].parent, hierarchy);
  6934. } else {
  6935. element.setHierarchy(hierarchy);
  6936. }
  6937. }
  6938. }
  6939. i += 1;
  6940. }
  6941. };
  6942. BaseRenderer.prototype.addPendingElement = function (element) {
  6943. this.pendingElements.push(element);
  6944. };
  6945. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  6946. var i;
  6947. var len = assets.length;
  6948. for (i = 0; i < len; i += 1) {
  6949. if (assets[i].xt) {
  6950. var comp = this.createComp(assets[i]);
  6951. comp.initExpressions();
  6952. this.globalData.projectInterface.registerComposition(comp);
  6953. }
  6954. }
  6955. };
  6956. BaseRenderer.prototype.getElementById = function (ind) {
  6957. var i;
  6958. var len = this.elements.length;
  6959. for (i = 0; i < len; i += 1) {
  6960. if (this.elements[i].data.ind === ind) {
  6961. return this.elements[i];
  6962. }
  6963. }
  6964. return null;
  6965. };
  6966. BaseRenderer.prototype.getElementByPath = function (path) {
  6967. var pathValue = path.shift();
  6968. var element;
  6969. if (typeof pathValue === 'number') {
  6970. element = this.elements[pathValue];
  6971. } else {
  6972. var i;
  6973. var len = this.elements.length;
  6974. for (i = 0; i < len; i += 1) {
  6975. if (this.elements[i].data.nm === pathValue) {
  6976. element = this.elements[i];
  6977. break;
  6978. }
  6979. }
  6980. }
  6981. if (path.length === 0) {
  6982. return element;
  6983. }
  6984. return element.getElementByPath(path);
  6985. };
  6986. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  6987. this.globalData.fontManager = new FontManager();
  6988. this.globalData.slotManager = slotFactory(animData);
  6989. this.globalData.fontManager.addChars(animData.chars);
  6990. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  6991. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  6992. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  6993. this.globalData.imageLoader = this.animationItem.imagePreloader;
  6994. this.globalData.audioController = this.animationItem.audioController;
  6995. this.globalData.frameId = 0;
  6996. this.globalData.frameRate = animData.fr;
  6997. this.globalData.nm = animData.nm;
  6998. this.globalData.compSize = {
  6999. w: animData.w,
  7000. h: animData.h
  7001. };
  7002. };
  7003. var effectTypes = {
  7004. TRANSFORM_EFFECT: 'transformEFfect'
  7005. };
  7006. function TransformElement() {}
  7007. TransformElement.prototype = {
  7008. initTransform: function initTransform() {
  7009. var mat = new Matrix();
  7010. this.finalTransform = {
  7011. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : {
  7012. o: 0
  7013. },
  7014. _matMdf: false,
  7015. _localMatMdf: false,
  7016. _opMdf: false,
  7017. mat: mat,
  7018. localMat: mat,
  7019. localOpacity: 1
  7020. };
  7021. if (this.data.ao) {
  7022. this.finalTransform.mProp.autoOriented = true;
  7023. }
  7024. // TODO: check TYPE 11: Guided elements
  7025. if (this.data.ty !== 11) {
  7026. // this.createElements();
  7027. }
  7028. },
  7029. renderTransform: function renderTransform() {
  7030. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  7031. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  7032. if (this.hierarchy) {
  7033. var mat;
  7034. var finalMat = this.finalTransform.mat;
  7035. var i = 0;
  7036. var len = this.hierarchy.length;
  7037. // Checking if any of the transformation matrices in the hierarchy chain has changed.
  7038. if (!this.finalTransform._matMdf) {
  7039. while (i < len) {
  7040. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  7041. this.finalTransform._matMdf = true;
  7042. break;
  7043. }
  7044. i += 1;
  7045. }
  7046. }
  7047. if (this.finalTransform._matMdf) {
  7048. mat = this.finalTransform.mProp.v.props;
  7049. finalMat.cloneFromProps(mat);
  7050. for (i = 0; i < len; i += 1) {
  7051. finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
  7052. }
  7053. }
  7054. }
  7055. if (!this.localTransforms || this.finalTransform._matMdf) {
  7056. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7057. }
  7058. if (this.finalTransform._opMdf) {
  7059. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7060. }
  7061. },
  7062. renderLocalTransform: function renderLocalTransform() {
  7063. if (this.localTransforms) {
  7064. var i = 0;
  7065. var len = this.localTransforms.length;
  7066. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7067. if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) {
  7068. while (i < len) {
  7069. if (this.localTransforms[i]._mdf) {
  7070. this.finalTransform._localMatMdf = true;
  7071. }
  7072. if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
  7073. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7074. this.finalTransform._opMdf = true;
  7075. }
  7076. i += 1;
  7077. }
  7078. }
  7079. if (this.finalTransform._localMatMdf) {
  7080. var localMat = this.finalTransform.localMat;
  7081. this.localTransforms[0].matrix.clone(localMat);
  7082. for (i = 1; i < len; i += 1) {
  7083. var lmat = this.localTransforms[i].matrix;
  7084. localMat.multiply(lmat);
  7085. }
  7086. localMat.multiply(this.finalTransform.mat);
  7087. }
  7088. if (this.finalTransform._opMdf) {
  7089. var localOp = this.finalTransform.localOpacity;
  7090. for (i = 0; i < len; i += 1) {
  7091. localOp *= this.localTransforms[i].opacity * 0.01;
  7092. }
  7093. this.finalTransform.localOpacity = localOp;
  7094. }
  7095. }
  7096. },
  7097. searchEffectTransforms: function searchEffectTransforms() {
  7098. if (this.renderableEffectsManager) {
  7099. var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  7100. if (transformEffects.length) {
  7101. this.localTransforms = [];
  7102. this.finalTransform.localMat = new Matrix();
  7103. var i = 0;
  7104. var len = transformEffects.length;
  7105. for (i = 0; i < len; i += 1) {
  7106. this.localTransforms.push(transformEffects[i]);
  7107. }
  7108. }
  7109. }
  7110. },
  7111. globalToLocal: function globalToLocal(pt) {
  7112. var transforms = [];
  7113. transforms.push(this.finalTransform);
  7114. var flag = true;
  7115. var comp = this.comp;
  7116. while (flag) {
  7117. if (comp.finalTransform) {
  7118. if (comp.data.hasMask) {
  7119. transforms.splice(0, 0, comp.finalTransform);
  7120. }
  7121. comp = comp.comp;
  7122. } else {
  7123. flag = false;
  7124. }
  7125. }
  7126. var i;
  7127. var len = transforms.length;
  7128. var ptNew;
  7129. for (i = 0; i < len; i += 1) {
  7130. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  7131. // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7132. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7133. }
  7134. return pt;
  7135. },
  7136. mHelper: new Matrix()
  7137. };
  7138. function MaskElement(data, element, globalData) {
  7139. this.data = data;
  7140. this.element = element;
  7141. this.globalData = globalData;
  7142. this.storedData = [];
  7143. this.masksProperties = this.data.masksProperties || [];
  7144. this.maskElement = null;
  7145. var defs = this.globalData.defs;
  7146. var i;
  7147. var len = this.masksProperties ? this.masksProperties.length : 0;
  7148. this.viewData = createSizedArray(len);
  7149. this.solidPath = '';
  7150. var path;
  7151. var properties = this.masksProperties;
  7152. var count = 0;
  7153. var currentMasks = [];
  7154. var j;
  7155. var jLen;
  7156. var layerId = createElementID();
  7157. var rect;
  7158. var expansor;
  7159. var feMorph;
  7160. var x;
  7161. var maskType = 'clipPath';
  7162. var maskRef = 'clip-path';
  7163. for (i = 0; i < len; i += 1) {
  7164. if (properties[i].mode !== 'a' && properties[i].mode !== 'n' || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7165. maskType = 'mask';
  7166. maskRef = 'mask';
  7167. }
  7168. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7169. rect = createNS('rect');
  7170. rect.setAttribute('fill', '#ffffff');
  7171. rect.setAttribute('width', this.element.comp.data.w || 0);
  7172. rect.setAttribute('height', this.element.comp.data.h || 0);
  7173. currentMasks.push(rect);
  7174. } else {
  7175. rect = null;
  7176. }
  7177. path = createNS('path');
  7178. if (properties[i].mode === 'n') {
  7179. // TODO move this to a factory or to a constructor
  7180. this.viewData[i] = {
  7181. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7182. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7183. elem: path,
  7184. lastPath: ''
  7185. };
  7186. defs.appendChild(path);
  7187. } else {
  7188. count += 1;
  7189. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7190. path.setAttribute('clip-rule', 'nonzero');
  7191. var filterID;
  7192. if (properties[i].x.k !== 0) {
  7193. maskType = 'mask';
  7194. maskRef = 'mask';
  7195. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7196. filterID = createElementID();
  7197. expansor = createNS('filter');
  7198. expansor.setAttribute('id', filterID);
  7199. feMorph = createNS('feMorphology');
  7200. feMorph.setAttribute('operator', 'erode');
  7201. feMorph.setAttribute('in', 'SourceGraphic');
  7202. feMorph.setAttribute('radius', '0');
  7203. expansor.appendChild(feMorph);
  7204. defs.appendChild(expansor);
  7205. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7206. } else {
  7207. feMorph = null;
  7208. x = null;
  7209. }
  7210. // TODO move this to a factory or to a constructor
  7211. this.storedData[i] = {
  7212. elem: path,
  7213. x: x,
  7214. expan: feMorph,
  7215. lastPath: '',
  7216. lastOperator: '',
  7217. filterId: filterID,
  7218. lastRadius: 0
  7219. };
  7220. if (properties[i].mode === 'i') {
  7221. jLen = currentMasks.length;
  7222. var g = createNS('g');
  7223. for (j = 0; j < jLen; j += 1) {
  7224. g.appendChild(currentMasks[j]);
  7225. }
  7226. var mask = createNS('mask');
  7227. mask.setAttribute('mask-type', 'alpha');
  7228. mask.setAttribute('id', layerId + '_' + count);
  7229. mask.appendChild(path);
  7230. defs.appendChild(mask);
  7231. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7232. currentMasks.length = 0;
  7233. currentMasks.push(g);
  7234. } else {
  7235. currentMasks.push(path);
  7236. }
  7237. if (properties[i].inv && !this.solidPath) {
  7238. this.solidPath = this.createLayerSolidPath();
  7239. }
  7240. // TODO move this to a factory or to a constructor
  7241. this.viewData[i] = {
  7242. elem: path,
  7243. lastPath: '',
  7244. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7245. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7246. invRect: rect
  7247. };
  7248. if (!this.viewData[i].prop.k) {
  7249. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7250. }
  7251. }
  7252. }
  7253. this.maskElement = createNS(maskType);
  7254. len = currentMasks.length;
  7255. for (i = 0; i < len; i += 1) {
  7256. this.maskElement.appendChild(currentMasks[i]);
  7257. }
  7258. if (count > 0) {
  7259. this.maskElement.setAttribute('id', layerId);
  7260. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7261. defs.appendChild(this.maskElement);
  7262. }
  7263. if (this.viewData.length) {
  7264. this.element.addRenderableComponent(this);
  7265. }
  7266. }
  7267. MaskElement.prototype.getMaskProperty = function (pos) {
  7268. return this.viewData[pos].prop;
  7269. };
  7270. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7271. var finalMat = this.element.finalTransform.mat;
  7272. var i;
  7273. var len = this.masksProperties.length;
  7274. for (i = 0; i < len; i += 1) {
  7275. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7276. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7277. }
  7278. if (this.viewData[i].op._mdf || isFirstFrame) {
  7279. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7280. }
  7281. if (this.masksProperties[i].mode !== 'n') {
  7282. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7283. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7284. }
  7285. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7286. var feMorph = this.storedData[i].expan;
  7287. if (this.storedData[i].x.v < 0) {
  7288. if (this.storedData[i].lastOperator !== 'erode') {
  7289. this.storedData[i].lastOperator = 'erode';
  7290. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7291. }
  7292. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7293. } else {
  7294. if (this.storedData[i].lastOperator !== 'dilate') {
  7295. this.storedData[i].lastOperator = 'dilate';
  7296. this.storedData[i].elem.setAttribute('filter', null);
  7297. }
  7298. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7299. }
  7300. }
  7301. }
  7302. }
  7303. };
  7304. MaskElement.prototype.getMaskelement = function () {
  7305. return this.maskElement;
  7306. };
  7307. MaskElement.prototype.createLayerSolidPath = function () {
  7308. var path = 'M0,0 ';
  7309. path += ' h' + this.globalData.compSize.w;
  7310. path += ' v' + this.globalData.compSize.h;
  7311. path += ' h-' + this.globalData.compSize.w;
  7312. path += ' v-' + this.globalData.compSize.h + ' ';
  7313. return path;
  7314. };
  7315. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7316. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7317. var i;
  7318. var len;
  7319. len = pathNodes._length;
  7320. for (i = 1; i < len; i += 1) {
  7321. // pathString += " C"+pathNodes.o[i-1][0]+','+pathNodes.o[i-1][1] + " "+pathNodes.i[i][0]+','+pathNodes.i[i][1] + " "+pathNodes.v[i][0]+','+pathNodes.v[i][1];
  7322. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[i][0] + ',' + pathNodes.i[i][1] + ' ' + pathNodes.v[i][0] + ',' + pathNodes.v[i][1];
  7323. }
  7324. // pathString += " C"+pathNodes.o[i-1][0]+','+pathNodes.o[i-1][1] + " "+pathNodes.i[0][0]+','+pathNodes.i[0][1] + " "+pathNodes.v[0][0]+','+pathNodes.v[0][1];
  7325. if (pathNodes.c && len > 1) {
  7326. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[0][0] + ',' + pathNodes.i[0][1] + ' ' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7327. }
  7328. // pathNodes.__renderedString = pathString;
  7329. if (viewData.lastPath !== pathString) {
  7330. var pathShapeValue = '';
  7331. if (viewData.elem) {
  7332. if (pathNodes.c) {
  7333. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7334. }
  7335. viewData.elem.setAttribute('d', pathShapeValue);
  7336. }
  7337. viewData.lastPath = pathString;
  7338. }
  7339. };
  7340. MaskElement.prototype.destroy = function () {
  7341. this.element = null;
  7342. this.globalData = null;
  7343. this.maskElement = null;
  7344. this.data = null;
  7345. this.masksProperties = null;
  7346. };
  7347. var filtersFactory = function () {
  7348. var ob = {};
  7349. ob.createFilter = createFilter;
  7350. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7351. function createFilter(filId, skipCoordinates) {
  7352. var fil = createNS('filter');
  7353. fil.setAttribute('id', filId);
  7354. if (skipCoordinates !== true) {
  7355. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7356. fil.setAttribute('x', '0%');
  7357. fil.setAttribute('y', '0%');
  7358. fil.setAttribute('width', '100%');
  7359. fil.setAttribute('height', '100%');
  7360. }
  7361. return fil;
  7362. }
  7363. function createAlphaToLuminanceFilter() {
  7364. var feColorMatrix = createNS('feColorMatrix');
  7365. feColorMatrix.setAttribute('type', 'matrix');
  7366. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7367. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7368. return feColorMatrix;
  7369. }
  7370. return ob;
  7371. }();
  7372. var featureSupport = function () {
  7373. var ob = {
  7374. maskType: true,
  7375. svgLumaHidden: true,
  7376. offscreenCanvas: typeof OffscreenCanvas !== 'undefined'
  7377. };
  7378. if (/MSIE 10/i.test(navigator.userAgent) || /MSIE 9/i.test(navigator.userAgent) || /rv:11.0/i.test(navigator.userAgent) || /Edge\/\d./i.test(navigator.userAgent)) {
  7379. ob.maskType = false;
  7380. }
  7381. if (/firefox/i.test(navigator.userAgent)) {
  7382. ob.svgLumaHidden = false;
  7383. }
  7384. return ob;
  7385. }();
  7386. var registeredEffects$1 = {};
  7387. var idPrefix = 'filter_result_';
  7388. function SVGEffects(elem) {
  7389. var i;
  7390. var source = 'SourceGraphic';
  7391. var len = elem.data.ef ? elem.data.ef.length : 0;
  7392. var filId = createElementID();
  7393. var fil = filtersFactory.createFilter(filId, true);
  7394. var count = 0;
  7395. this.filters = [];
  7396. var filterManager;
  7397. for (i = 0; i < len; i += 1) {
  7398. filterManager = null;
  7399. var type = elem.data.ef[i].ty;
  7400. if (registeredEffects$1[type]) {
  7401. var Effect = registeredEffects$1[type].effect;
  7402. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7403. source = idPrefix + count;
  7404. if (registeredEffects$1[type].countsAsEffect) {
  7405. count += 1;
  7406. }
  7407. }
  7408. if (filterManager) {
  7409. this.filters.push(filterManager);
  7410. }
  7411. }
  7412. if (count) {
  7413. elem.globalData.defs.appendChild(fil);
  7414. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7415. }
  7416. if (this.filters.length) {
  7417. elem.addRenderableComponent(this);
  7418. }
  7419. }
  7420. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7421. var i;
  7422. var len = this.filters.length;
  7423. for (i = 0; i < len; i += 1) {
  7424. this.filters[i].renderFrame(_isFirstFrame);
  7425. }
  7426. };
  7427. SVGEffects.prototype.getEffects = function (type) {
  7428. var i;
  7429. var len = this.filters.length;
  7430. var effects = [];
  7431. for (i = 0; i < len; i += 1) {
  7432. if (this.filters[i].type === type) {
  7433. effects.push(this.filters[i]);
  7434. }
  7435. }
  7436. return effects;
  7437. };
  7438. function registerEffect$1(id, effect, countsAsEffect) {
  7439. registeredEffects$1[id] = {
  7440. effect: effect,
  7441. countsAsEffect: countsAsEffect
  7442. };
  7443. }
  7444. function SVGBaseElement() {}
  7445. SVGBaseElement.prototype = {
  7446. initRendererElement: function initRendererElement() {
  7447. this.layerElement = createNS('g');
  7448. },
  7449. createContainerElements: function createContainerElements() {
  7450. this.matteElement = createNS('g');
  7451. this.transformedElement = this.layerElement;
  7452. this.maskedElement = this.layerElement;
  7453. this._sizeChanged = false;
  7454. var layerElementParent = null;
  7455. // If this layer acts as a mask for the following layer
  7456. if (this.data.td) {
  7457. this.matteMasks = {};
  7458. var gg = createNS('g');
  7459. gg.setAttribute('id', this.layerId);
  7460. gg.appendChild(this.layerElement);
  7461. layerElementParent = gg;
  7462. this.globalData.defs.appendChild(gg);
  7463. } else if (this.data.tt) {
  7464. this.matteElement.appendChild(this.layerElement);
  7465. layerElementParent = this.matteElement;
  7466. this.baseElement = this.matteElement;
  7467. } else {
  7468. this.baseElement = this.layerElement;
  7469. }
  7470. if (this.data.ln) {
  7471. this.layerElement.setAttribute('id', this.data.ln);
  7472. }
  7473. if (this.data.cl) {
  7474. this.layerElement.setAttribute('class', this.data.cl);
  7475. }
  7476. // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7477. if (this.data.ty === 0 && !this.data.hd) {
  7478. var cp = createNS('clipPath');
  7479. var pt = createNS('path');
  7480. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7481. var clipId = createElementID();
  7482. cp.setAttribute('id', clipId);
  7483. cp.appendChild(pt);
  7484. this.globalData.defs.appendChild(cp);
  7485. if (this.checkMasks()) {
  7486. var cpGroup = createNS('g');
  7487. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7488. cpGroup.appendChild(this.layerElement);
  7489. this.transformedElement = cpGroup;
  7490. if (layerElementParent) {
  7491. layerElementParent.appendChild(this.transformedElement);
  7492. } else {
  7493. this.baseElement = this.transformedElement;
  7494. }
  7495. } else {
  7496. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7497. }
  7498. }
  7499. if (this.data.bm !== 0) {
  7500. this.setBlendMode();
  7501. }
  7502. },
  7503. renderElement: function renderElement() {
  7504. if (this.finalTransform._localMatMdf) {
  7505. this.transformedElement.setAttribute('transform', this.finalTransform.localMat.to2dCSS());
  7506. }
  7507. if (this.finalTransform._opMdf) {
  7508. this.transformedElement.setAttribute('opacity', this.finalTransform.localOpacity);
  7509. }
  7510. },
  7511. destroyBaseElement: function destroyBaseElement() {
  7512. this.layerElement = null;
  7513. this.matteElement = null;
  7514. this.maskManager.destroy();
  7515. },
  7516. getBaseElement: function getBaseElement() {
  7517. if (this.data.hd) {
  7518. return null;
  7519. }
  7520. return this.baseElement;
  7521. },
  7522. createRenderableComponents: function createRenderableComponents() {
  7523. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7524. this.renderableEffectsManager = new SVGEffects(this);
  7525. this.searchEffectTransforms();
  7526. },
  7527. getMatte: function getMatte(matteType) {
  7528. // This should not be a common case. But for backward compatibility, we'll create the matte object.
  7529. // It solves animations that have two consecutive layers marked as matte masks.
  7530. // Which is an undefined behavior in AE.
  7531. if (!this.matteMasks) {
  7532. this.matteMasks = {};
  7533. }
  7534. if (!this.matteMasks[matteType]) {
  7535. var id = this.layerId + '_' + matteType;
  7536. var filId;
  7537. var fil;
  7538. var useElement;
  7539. var gg;
  7540. if (matteType === 1 || matteType === 3) {
  7541. var masker = createNS('mask');
  7542. masker.setAttribute('id', id);
  7543. masker.setAttribute('mask-type', matteType === 3 ? 'luminance' : 'alpha');
  7544. useElement = createNS('use');
  7545. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7546. masker.appendChild(useElement);
  7547. this.globalData.defs.appendChild(masker);
  7548. if (!featureSupport.maskType && matteType === 1) {
  7549. masker.setAttribute('mask-type', 'luminance');
  7550. filId = createElementID();
  7551. fil = filtersFactory.createFilter(filId);
  7552. this.globalData.defs.appendChild(fil);
  7553. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7554. gg = createNS('g');
  7555. gg.appendChild(useElement);
  7556. masker.appendChild(gg);
  7557. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7558. }
  7559. } else if (matteType === 2) {
  7560. var maskGroup = createNS('mask');
  7561. maskGroup.setAttribute('id', id);
  7562. maskGroup.setAttribute('mask-type', 'alpha');
  7563. var maskGrouper = createNS('g');
  7564. maskGroup.appendChild(maskGrouper);
  7565. filId = createElementID();
  7566. fil = filtersFactory.createFilter(filId);
  7567. /// /
  7568. var feCTr = createNS('feComponentTransfer');
  7569. feCTr.setAttribute('in', 'SourceGraphic');
  7570. fil.appendChild(feCTr);
  7571. var feFunc = createNS('feFuncA');
  7572. feFunc.setAttribute('type', 'table');
  7573. feFunc.setAttribute('tableValues', '1.0 0.0');
  7574. feCTr.appendChild(feFunc);
  7575. /// /
  7576. this.globalData.defs.appendChild(fil);
  7577. var alphaRect = createNS('rect');
  7578. alphaRect.setAttribute('width', this.comp.data.w);
  7579. alphaRect.setAttribute('height', this.comp.data.h);
  7580. alphaRect.setAttribute('x', '0');
  7581. alphaRect.setAttribute('y', '0');
  7582. alphaRect.setAttribute('fill', '#ffffff');
  7583. alphaRect.setAttribute('opacity', '0');
  7584. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7585. maskGrouper.appendChild(alphaRect);
  7586. useElement = createNS('use');
  7587. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7588. maskGrouper.appendChild(useElement);
  7589. if (!featureSupport.maskType) {
  7590. maskGroup.setAttribute('mask-type', 'luminance');
  7591. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7592. gg = createNS('g');
  7593. maskGrouper.appendChild(alphaRect);
  7594. gg.appendChild(this.layerElement);
  7595. maskGrouper.appendChild(gg);
  7596. }
  7597. this.globalData.defs.appendChild(maskGroup);
  7598. }
  7599. this.matteMasks[matteType] = id;
  7600. }
  7601. return this.matteMasks[matteType];
  7602. },
  7603. setMatte: function setMatte(id) {
  7604. if (!this.matteElement) {
  7605. return;
  7606. }
  7607. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7608. }
  7609. };
  7610. /**
  7611. * @file
  7612. * Handles AE's layer parenting property.
  7613. *
  7614. */
  7615. function HierarchyElement() {}
  7616. HierarchyElement.prototype = {
  7617. /**
  7618. * @function
  7619. * Initializes hierarchy properties
  7620. *
  7621. */
  7622. initHierarchy: function initHierarchy() {
  7623. // element's parent list
  7624. this.hierarchy = [];
  7625. // if element is parent of another layer _isParent will be true
  7626. this._isParent = false;
  7627. this.checkParenting();
  7628. },
  7629. /**
  7630. * @function
  7631. * Sets layer's hierarchy.
  7632. * @param {array} hierarch
  7633. * layer's parent list
  7634. *
  7635. */
  7636. setHierarchy: function setHierarchy(hierarchy) {
  7637. this.hierarchy = hierarchy;
  7638. },
  7639. /**
  7640. * @function
  7641. * Sets layer as parent.
  7642. *
  7643. */
  7644. setAsParent: function setAsParent() {
  7645. this._isParent = true;
  7646. },
  7647. /**
  7648. * @function
  7649. * Searches layer's parenting chain
  7650. *
  7651. */
  7652. checkParenting: function checkParenting() {
  7653. if (this.data.parent !== undefined) {
  7654. this.comp.buildElementParenting(this, this.data.parent, []);
  7655. }
  7656. }
  7657. };
  7658. function RenderableDOMElement() {}
  7659. (function () {
  7660. var _prototype = {
  7661. initElement: function initElement(data, globalData, comp) {
  7662. this.initFrame();
  7663. this.initBaseData(data, globalData, comp);
  7664. this.initTransform(data, globalData, comp);
  7665. this.initHierarchy();
  7666. this.initRenderable();
  7667. this.initRendererElement();
  7668. this.createContainerElements();
  7669. this.createRenderableComponents();
  7670. this.createContent();
  7671. this.hide();
  7672. },
  7673. hide: function hide() {
  7674. // console.log('HIDE', this);
  7675. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7676. var elem = this.baseElement || this.layerElement;
  7677. elem.style.display = 'none';
  7678. this.hidden = true;
  7679. }
  7680. },
  7681. show: function show() {
  7682. // console.log('SHOW', this);
  7683. if (this.isInRange && !this.isTransparent) {
  7684. if (!this.data.hd) {
  7685. var elem = this.baseElement || this.layerElement;
  7686. elem.style.display = 'block';
  7687. }
  7688. this.hidden = false;
  7689. this._isFirstFrame = true;
  7690. }
  7691. },
  7692. renderFrame: function renderFrame() {
  7693. // If it is exported as hidden (data.hd === true) no need to render
  7694. // If it is not visible no need to render
  7695. if (this.data.hd || this.hidden) {
  7696. return;
  7697. }
  7698. this.renderTransform();
  7699. this.renderRenderable();
  7700. this.renderLocalTransform();
  7701. this.renderElement();
  7702. this.renderInnerContent();
  7703. if (this._isFirstFrame) {
  7704. this._isFirstFrame = false;
  7705. }
  7706. },
  7707. renderInnerContent: function renderInnerContent() {},
  7708. prepareFrame: function prepareFrame(num) {
  7709. this._mdf = false;
  7710. this.prepareRenderableFrame(num);
  7711. this.prepareProperties(num, this.isInRange);
  7712. this.checkTransparency();
  7713. },
  7714. destroy: function destroy() {
  7715. this.innerElem = null;
  7716. this.destroyBaseElement();
  7717. }
  7718. };
  7719. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  7720. })();
  7721. function IImageElement(data, globalData, comp) {
  7722. this.assetData = globalData.getAssetData(data.refId);
  7723. if (this.assetData && this.assetData.sid) {
  7724. this.assetData = globalData.slotManager.getProp(this.assetData);
  7725. }
  7726. this.initElement(data, globalData, comp);
  7727. this.sourceRect = {
  7728. top: 0,
  7729. left: 0,
  7730. width: this.assetData.w,
  7731. height: this.assetData.h
  7732. };
  7733. }
  7734. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  7735. IImageElement.prototype.createContent = function () {
  7736. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7737. this.innerElem = createNS('image');
  7738. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  7739. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  7740. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7741. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  7742. this.layerElement.appendChild(this.innerElem);
  7743. };
  7744. IImageElement.prototype.sourceRectAtTime = function () {
  7745. return this.sourceRect;
  7746. };
  7747. function ProcessedElement(element, position) {
  7748. this.elem = element;
  7749. this.pos = position;
  7750. }
  7751. function IShapeElement() {}
  7752. IShapeElement.prototype = {
  7753. addShapeToModifiers: function addShapeToModifiers(data) {
  7754. var i;
  7755. var len = this.shapeModifiers.length;
  7756. for (i = 0; i < len; i += 1) {
  7757. this.shapeModifiers[i].addShape(data);
  7758. }
  7759. },
  7760. isShapeInAnimatedModifiers: function isShapeInAnimatedModifiers(data) {
  7761. var i = 0;
  7762. var len = this.shapeModifiers.length;
  7763. while (i < len) {
  7764. if (this.shapeModifiers[i].isAnimatedWithShape(data)) {
  7765. return true;
  7766. }
  7767. }
  7768. return false;
  7769. },
  7770. renderModifiers: function renderModifiers() {
  7771. if (!this.shapeModifiers.length) {
  7772. return;
  7773. }
  7774. var i;
  7775. var len = this.shapes.length;
  7776. for (i = 0; i < len; i += 1) {
  7777. this.shapes[i].sh.reset();
  7778. }
  7779. len = this.shapeModifiers.length;
  7780. var shouldBreakProcess;
  7781. for (i = len - 1; i >= 0; i -= 1) {
  7782. shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame);
  7783. // workaround to fix cases where a repeater resets the shape so the following processes get called twice
  7784. // TODO: find a better solution for this
  7785. if (shouldBreakProcess) {
  7786. break;
  7787. }
  7788. }
  7789. },
  7790. searchProcessedElement: function searchProcessedElement(elem) {
  7791. var elements = this.processedElements;
  7792. var i = 0;
  7793. var len = elements.length;
  7794. while (i < len) {
  7795. if (elements[i].elem === elem) {
  7796. return elements[i].pos;
  7797. }
  7798. i += 1;
  7799. }
  7800. return 0;
  7801. },
  7802. addProcessedElement: function addProcessedElement(elem, pos) {
  7803. var elements = this.processedElements;
  7804. var i = elements.length;
  7805. while (i) {
  7806. i -= 1;
  7807. if (elements[i].elem === elem) {
  7808. elements[i].pos = pos;
  7809. return;
  7810. }
  7811. }
  7812. elements.push(new ProcessedElement(elem, pos));
  7813. },
  7814. prepareFrame: function prepareFrame(num) {
  7815. this.prepareRenderableFrame(num);
  7816. this.prepareProperties(num, this.isInRange);
  7817. }
  7818. };
  7819. var lineCapEnum = {
  7820. 1: 'butt',
  7821. 2: 'round',
  7822. 3: 'square'
  7823. };
  7824. var lineJoinEnum = {
  7825. 1: 'miter',
  7826. 2: 'round',
  7827. 3: 'bevel'
  7828. };
  7829. function SVGShapeData(transformers, level, shape) {
  7830. this.caches = [];
  7831. this.styles = [];
  7832. this.transformers = transformers;
  7833. this.lStr = '';
  7834. this.sh = shape;
  7835. this.lvl = level;
  7836. // TODO find if there are some cases where _isAnimated can be false.
  7837. // For now, since shapes add up with other shapes. They have to be calculated every time.
  7838. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  7839. this._isAnimated = !!shape.k;
  7840. // TODO: commenting this for now since all shapes are animated
  7841. var i = 0;
  7842. var len = transformers.length;
  7843. while (i < len) {
  7844. if (transformers[i].mProps.dynamicProperties.length) {
  7845. this._isAnimated = true;
  7846. break;
  7847. }
  7848. i += 1;
  7849. }
  7850. }
  7851. SVGShapeData.prototype.setAsAnimated = function () {
  7852. this._isAnimated = true;
  7853. };
  7854. function SVGStyleData(data, level) {
  7855. this.data = data;
  7856. this.type = data.ty;
  7857. this.d = '';
  7858. this.lvl = level;
  7859. this._mdf = false;
  7860. this.closed = data.hd === true;
  7861. this.pElem = createNS('path');
  7862. this.msElem = null;
  7863. }
  7864. SVGStyleData.prototype.reset = function () {
  7865. this.d = '';
  7866. this._mdf = false;
  7867. };
  7868. function DashProperty(elem, data, renderer, container) {
  7869. this.elem = elem;
  7870. this.frameId = -1;
  7871. this.dataProps = createSizedArray(data.length);
  7872. this.renderer = renderer;
  7873. this.k = false;
  7874. this.dashStr = '';
  7875. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  7876. this.dashoffset = createTypedArray('float32', 1);
  7877. this.initDynamicPropertyContainer(container);
  7878. var i;
  7879. var len = data.length || 0;
  7880. var prop;
  7881. for (i = 0; i < len; i += 1) {
  7882. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  7883. this.k = prop.k || this.k;
  7884. this.dataProps[i] = {
  7885. n: data[i].n,
  7886. p: prop
  7887. };
  7888. }
  7889. if (!this.k) {
  7890. this.getValue(true);
  7891. }
  7892. this._isAnimated = this.k;
  7893. }
  7894. DashProperty.prototype.getValue = function (forceRender) {
  7895. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  7896. return;
  7897. }
  7898. this.frameId = this.elem.globalData.frameId;
  7899. this.iterateDynamicProperties();
  7900. this._mdf = this._mdf || forceRender;
  7901. if (this._mdf) {
  7902. var i = 0;
  7903. var len = this.dataProps.length;
  7904. if (this.renderer === 'svg') {
  7905. this.dashStr = '';
  7906. }
  7907. for (i = 0; i < len; i += 1) {
  7908. if (this.dataProps[i].n !== 'o') {
  7909. if (this.renderer === 'svg') {
  7910. this.dashStr += ' ' + this.dataProps[i].p.v;
  7911. } else {
  7912. this.dashArray[i] = this.dataProps[i].p.v;
  7913. }
  7914. } else {
  7915. this.dashoffset[0] = this.dataProps[i].p.v;
  7916. }
  7917. }
  7918. }
  7919. };
  7920. extendPrototype([DynamicPropertyContainer], DashProperty);
  7921. function SVGStrokeStyleData(elem, data, styleOb) {
  7922. this.initDynamicPropertyContainer(elem);
  7923. this.getValue = this.iterateDynamicProperties;
  7924. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7925. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  7926. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  7927. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7928. this.style = styleOb;
  7929. this._isAnimated = !!this._isAnimated;
  7930. }
  7931. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  7932. function SVGFillStyleData(elem, data, styleOb) {
  7933. this.initDynamicPropertyContainer(elem);
  7934. this.getValue = this.iterateDynamicProperties;
  7935. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7936. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7937. this.style = styleOb;
  7938. }
  7939. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  7940. function SVGNoStyleData(elem, data, styleOb) {
  7941. this.initDynamicPropertyContainer(elem);
  7942. this.getValue = this.iterateDynamicProperties;
  7943. this.style = styleOb;
  7944. }
  7945. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  7946. function GradientProperty(elem, data, container) {
  7947. this.data = data;
  7948. this.c = createTypedArray('uint8c', data.p * 4);
  7949. var cLength = data.k.k[0].s ? data.k.k[0].s.length - data.p * 4 : data.k.k.length - data.p * 4;
  7950. this.o = createTypedArray('float32', cLength);
  7951. this._cmdf = false;
  7952. this._omdf = false;
  7953. this._collapsable = this.checkCollapsable();
  7954. this._hasOpacity = cLength;
  7955. this.initDynamicPropertyContainer(container);
  7956. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  7957. this.k = this.prop.k;
  7958. this.getValue(true);
  7959. }
  7960. GradientProperty.prototype.comparePoints = function (values, points) {
  7961. var i = 0;
  7962. var len = this.o.length / 2;
  7963. var diff;
  7964. while (i < len) {
  7965. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  7966. if (diff > 0.01) {
  7967. return false;
  7968. }
  7969. i += 1;
  7970. }
  7971. return true;
  7972. };
  7973. GradientProperty.prototype.checkCollapsable = function () {
  7974. if (this.o.length / 2 !== this.c.length / 4) {
  7975. return false;
  7976. }
  7977. if (this.data.k.k[0].s) {
  7978. var i = 0;
  7979. var len = this.data.k.k.length;
  7980. while (i < len) {
  7981. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  7982. return false;
  7983. }
  7984. i += 1;
  7985. }
  7986. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  7987. return false;
  7988. }
  7989. return true;
  7990. };
  7991. GradientProperty.prototype.getValue = function (forceRender) {
  7992. this.prop.getValue();
  7993. this._mdf = false;
  7994. this._cmdf = false;
  7995. this._omdf = false;
  7996. if (this.prop._mdf || forceRender) {
  7997. var i;
  7998. var len = this.data.p * 4;
  7999. var mult;
  8000. var val;
  8001. for (i = 0; i < len; i += 1) {
  8002. mult = i % 4 === 0 ? 100 : 255;
  8003. val = Math.round(this.prop.v[i] * mult);
  8004. if (this.c[i] !== val) {
  8005. this.c[i] = val;
  8006. this._cmdf = !forceRender;
  8007. }
  8008. }
  8009. if (this.o.length) {
  8010. len = this.prop.v.length;
  8011. for (i = this.data.p * 4; i < len; i += 1) {
  8012. mult = i % 2 === 0 ? 100 : 1;
  8013. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  8014. if (this.o[i - this.data.p * 4] !== val) {
  8015. this.o[i - this.data.p * 4] = val;
  8016. this._omdf = !forceRender;
  8017. }
  8018. }
  8019. }
  8020. this._mdf = !forceRender;
  8021. }
  8022. };
  8023. extendPrototype([DynamicPropertyContainer], GradientProperty);
  8024. function SVGGradientFillStyleData(elem, data, styleOb) {
  8025. this.initDynamicPropertyContainer(elem);
  8026. this.getValue = this.iterateDynamicProperties;
  8027. this.initGradientData(elem, data, styleOb);
  8028. }
  8029. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  8030. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8031. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  8032. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  8033. this.h = PropertyFactory.getProp(elem, data.h || {
  8034. k: 0
  8035. }, 0, 0.01, this);
  8036. this.a = PropertyFactory.getProp(elem, data.a || {
  8037. k: 0
  8038. }, 0, degToRads, this);
  8039. this.g = new GradientProperty(elem, data.g, this);
  8040. this.style = styleOb;
  8041. this.stops = [];
  8042. this.setGradientData(styleOb.pElem, data);
  8043. this.setGradientOpacity(data, styleOb);
  8044. this._isAnimated = !!this._isAnimated;
  8045. };
  8046. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  8047. var gradientId = createElementID();
  8048. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8049. gfill.setAttribute('id', gradientId);
  8050. gfill.setAttribute('spreadMethod', 'pad');
  8051. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8052. var stops = [];
  8053. var stop;
  8054. var j;
  8055. var jLen;
  8056. jLen = data.g.p * 4;
  8057. for (j = 0; j < jLen; j += 4) {
  8058. stop = createNS('stop');
  8059. gfill.appendChild(stop);
  8060. stops.push(stop);
  8061. }
  8062. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  8063. this.gf = gfill;
  8064. this.cst = stops;
  8065. };
  8066. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  8067. if (this.g._hasOpacity && !this.g._collapsable) {
  8068. var stop;
  8069. var j;
  8070. var jLen;
  8071. var mask = createNS('mask');
  8072. var maskElement = createNS('path');
  8073. mask.appendChild(maskElement);
  8074. var opacityId = createElementID();
  8075. var maskId = createElementID();
  8076. mask.setAttribute('id', maskId);
  8077. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8078. opFill.setAttribute('id', opacityId);
  8079. opFill.setAttribute('spreadMethod', 'pad');
  8080. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8081. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8082. var stops = this.stops;
  8083. for (j = data.g.p * 4; j < jLen; j += 2) {
  8084. stop = createNS('stop');
  8085. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8086. opFill.appendChild(stop);
  8087. stops.push(stop);
  8088. }
  8089. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8090. if (data.ty === 'gs') {
  8091. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8092. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8093. if (data.lj === 1) {
  8094. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8095. }
  8096. }
  8097. this.of = opFill;
  8098. this.ms = mask;
  8099. this.ost = stops;
  8100. this.maskId = maskId;
  8101. styleOb.msElem = maskElement;
  8102. }
  8103. };
  8104. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8105. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8106. this.initDynamicPropertyContainer(elem);
  8107. this.getValue = this.iterateDynamicProperties;
  8108. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8109. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8110. this.initGradientData(elem, data, styleOb);
  8111. this._isAnimated = !!this._isAnimated;
  8112. }
  8113. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8114. function ShapeGroupData() {
  8115. this.it = [];
  8116. this.prevViewData = [];
  8117. this.gr = createNS('g');
  8118. }
  8119. function SVGTransformData(mProps, op, container) {
  8120. this.transform = {
  8121. mProps: mProps,
  8122. op: op,
  8123. container: container
  8124. };
  8125. this.elements = [];
  8126. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8127. }
  8128. var buildShapeString = function buildShapeString(pathNodes, length, closed, mat) {
  8129. if (length === 0) {
  8130. return '';
  8131. }
  8132. var _o = pathNodes.o;
  8133. var _i = pathNodes.i;
  8134. var _v = pathNodes.v;
  8135. var i;
  8136. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8137. for (i = 1; i < length; i += 1) {
  8138. shapeString += ' C' + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + ' ' + mat.applyToPointStringified(_i[i][0], _i[i][1]) + ' ' + mat.applyToPointStringified(_v[i][0], _v[i][1]);
  8139. }
  8140. if (closed && length) {
  8141. shapeString += ' C' + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + ' ' + mat.applyToPointStringified(_i[0][0], _i[0][1]) + ' ' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8142. shapeString += 'z';
  8143. }
  8144. return shapeString;
  8145. };
  8146. var SVGElementsRenderer = function () {
  8147. var _identityMatrix = new Matrix();
  8148. var _matrixHelper = new Matrix();
  8149. var ob = {
  8150. createRenderFunction: createRenderFunction
  8151. };
  8152. function createRenderFunction(data) {
  8153. switch (data.ty) {
  8154. case 'fl':
  8155. return renderFill;
  8156. case 'gf':
  8157. return renderGradient;
  8158. case 'gs':
  8159. return renderGradientStroke;
  8160. case 'st':
  8161. return renderStroke;
  8162. case 'sh':
  8163. case 'el':
  8164. case 'rc':
  8165. case 'sr':
  8166. return renderPath;
  8167. case 'tr':
  8168. return renderContentTransform;
  8169. case 'no':
  8170. return renderNoop;
  8171. default:
  8172. return null;
  8173. }
  8174. }
  8175. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8176. if (isFirstFrame || itemData.transform.op._mdf) {
  8177. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8178. }
  8179. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8180. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8181. }
  8182. }
  8183. function renderNoop() {}
  8184. function renderPath(styleData, itemData, isFirstFrame) {
  8185. var j;
  8186. var jLen;
  8187. var pathStringTransformed;
  8188. var redraw;
  8189. var pathNodes;
  8190. var l;
  8191. var lLen = itemData.styles.length;
  8192. var lvl = itemData.lvl;
  8193. var paths;
  8194. var mat;
  8195. var iterations;
  8196. var k;
  8197. for (l = 0; l < lLen; l += 1) {
  8198. redraw = itemData.sh._mdf || isFirstFrame;
  8199. if (itemData.styles[l].lvl < lvl) {
  8200. mat = _matrixHelper.reset();
  8201. iterations = lvl - itemData.styles[l].lvl;
  8202. k = itemData.transformers.length - 1;
  8203. while (!redraw && iterations > 0) {
  8204. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8205. iterations -= 1;
  8206. k -= 1;
  8207. }
  8208. if (redraw) {
  8209. iterations = lvl - itemData.styles[l].lvl;
  8210. k = itemData.transformers.length - 1;
  8211. while (iterations > 0) {
  8212. mat.multiply(itemData.transformers[k].mProps.v);
  8213. iterations -= 1;
  8214. k -= 1;
  8215. }
  8216. }
  8217. } else {
  8218. mat = _identityMatrix;
  8219. }
  8220. paths = itemData.sh.paths;
  8221. jLen = paths._length;
  8222. if (redraw) {
  8223. pathStringTransformed = '';
  8224. for (j = 0; j < jLen; j += 1) {
  8225. pathNodes = paths.shapes[j];
  8226. if (pathNodes && pathNodes._length) {
  8227. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8228. }
  8229. }
  8230. itemData.caches[l] = pathStringTransformed;
  8231. } else {
  8232. pathStringTransformed = itemData.caches[l];
  8233. }
  8234. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8235. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8236. }
  8237. }
  8238. function renderFill(styleData, itemData, isFirstFrame) {
  8239. var styleElem = itemData.style;
  8240. if (itemData.c._mdf || isFirstFrame) {
  8241. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8242. }
  8243. if (itemData.o._mdf || isFirstFrame) {
  8244. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8245. }
  8246. }
  8247. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8248. renderGradient(styleData, itemData, isFirstFrame);
  8249. renderStroke(styleData, itemData, isFirstFrame);
  8250. }
  8251. function renderGradient(styleData, itemData, isFirstFrame) {
  8252. var gfill = itemData.gf;
  8253. var hasOpacity = itemData.g._hasOpacity;
  8254. var pt1 = itemData.s.v;
  8255. var pt2 = itemData.e.v;
  8256. if (itemData.o._mdf || isFirstFrame) {
  8257. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8258. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8259. }
  8260. if (itemData.s._mdf || isFirstFrame) {
  8261. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8262. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8263. gfill.setAttribute(attr1, pt1[0]);
  8264. gfill.setAttribute(attr2, pt1[1]);
  8265. if (hasOpacity && !itemData.g._collapsable) {
  8266. itemData.of.setAttribute(attr1, pt1[0]);
  8267. itemData.of.setAttribute(attr2, pt1[1]);
  8268. }
  8269. }
  8270. var stops;
  8271. var i;
  8272. var len;
  8273. var stop;
  8274. if (itemData.g._cmdf || isFirstFrame) {
  8275. stops = itemData.cst;
  8276. var cValues = itemData.g.c;
  8277. len = stops.length;
  8278. for (i = 0; i < len; i += 1) {
  8279. stop = stops[i];
  8280. stop.setAttribute('offset', cValues[i * 4] + '%');
  8281. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8282. }
  8283. }
  8284. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8285. var oValues = itemData.g.o;
  8286. if (itemData.g._collapsable) {
  8287. stops = itemData.cst;
  8288. } else {
  8289. stops = itemData.ost;
  8290. }
  8291. len = stops.length;
  8292. for (i = 0; i < len; i += 1) {
  8293. stop = stops[i];
  8294. if (!itemData.g._collapsable) {
  8295. stop.setAttribute('offset', oValues[i * 2] + '%');
  8296. }
  8297. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8298. }
  8299. }
  8300. if (styleData.t === 1) {
  8301. if (itemData.e._mdf || isFirstFrame) {
  8302. gfill.setAttribute('x2', pt2[0]);
  8303. gfill.setAttribute('y2', pt2[1]);
  8304. if (hasOpacity && !itemData.g._collapsable) {
  8305. itemData.of.setAttribute('x2', pt2[0]);
  8306. itemData.of.setAttribute('y2', pt2[1]);
  8307. }
  8308. }
  8309. } else {
  8310. var rad;
  8311. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8312. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8313. gfill.setAttribute('r', rad);
  8314. if (hasOpacity && !itemData.g._collapsable) {
  8315. itemData.of.setAttribute('r', rad);
  8316. }
  8317. }
  8318. if (itemData.s._mdf || itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8319. if (!rad) {
  8320. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8321. }
  8322. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8323. var percent = itemData.h.v;
  8324. if (percent >= 1) {
  8325. percent = 0.99;
  8326. } else if (percent <= -1) {
  8327. percent = -0.99;
  8328. }
  8329. var dist = rad * percent;
  8330. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8331. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8332. gfill.setAttribute('fx', x);
  8333. gfill.setAttribute('fy', y);
  8334. if (hasOpacity && !itemData.g._collapsable) {
  8335. itemData.of.setAttribute('fx', x);
  8336. itemData.of.setAttribute('fy', y);
  8337. }
  8338. }
  8339. // gfill.setAttribute('fy','200');
  8340. }
  8341. }
  8342. function renderStroke(styleData, itemData, isFirstFrame) {
  8343. var styleElem = itemData.style;
  8344. var d = itemData.d;
  8345. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8346. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8347. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8348. }
  8349. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8350. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8351. }
  8352. if (itemData.o._mdf || isFirstFrame) {
  8353. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8354. }
  8355. if (itemData.w._mdf || isFirstFrame) {
  8356. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8357. if (styleElem.msElem) {
  8358. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8359. }
  8360. }
  8361. }
  8362. return ob;
  8363. }();
  8364. function SVGShapeElement(data, globalData, comp) {
  8365. // List of drawable elements
  8366. this.shapes = [];
  8367. // Full shape data
  8368. this.shapesData = data.shapes;
  8369. // List of styles that will be applied to shapes
  8370. this.stylesList = [];
  8371. // List of modifiers that will be applied to shapes
  8372. this.shapeModifiers = [];
  8373. // List of items in shape tree
  8374. this.itemsData = [];
  8375. // List of items in previous shape tree
  8376. this.processedElements = [];
  8377. // List of animated components
  8378. this.animatedContents = [];
  8379. this.initElement(data, globalData, comp);
  8380. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8381. // List of elements that have been created
  8382. this.prevViewData = [];
  8383. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8384. }
  8385. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8386. SVGShapeElement.prototype.initSecondaryElement = function () {};
  8387. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8388. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8389. SVGShapeElement.prototype.createContent = function () {
  8390. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8391. this.filterUniqueShapes();
  8392. };
  8393. /*
  8394. This method searches for multiple shapes that affect a single element and one of them is animated
  8395. */
  8396. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8397. var i;
  8398. var len = this.shapes.length;
  8399. var shape;
  8400. var j;
  8401. var jLen = this.stylesList.length;
  8402. var style;
  8403. var tempShapes = [];
  8404. var areAnimated = false;
  8405. for (j = 0; j < jLen; j += 1) {
  8406. style = this.stylesList[j];
  8407. areAnimated = false;
  8408. tempShapes.length = 0;
  8409. for (i = 0; i < len; i += 1) {
  8410. shape = this.shapes[i];
  8411. if (shape.styles.indexOf(style) !== -1) {
  8412. tempShapes.push(shape);
  8413. areAnimated = shape._isAnimated || areAnimated;
  8414. }
  8415. }
  8416. if (tempShapes.length > 1 && areAnimated) {
  8417. this.setShapesAsAnimated(tempShapes);
  8418. }
  8419. }
  8420. };
  8421. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8422. var i;
  8423. var len = shapes.length;
  8424. for (i = 0; i < len; i += 1) {
  8425. shapes[i].setAsAnimated();
  8426. }
  8427. };
  8428. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8429. // TODO: prevent drawing of hidden styles
  8430. var elementData;
  8431. var styleOb = new SVGStyleData(data, level);
  8432. var pathElement = styleOb.pElem;
  8433. if (data.ty === 'st') {
  8434. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8435. } else if (data.ty === 'fl') {
  8436. elementData = new SVGFillStyleData(this, data, styleOb);
  8437. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8438. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8439. elementData = new GradientConstructor(this, data, styleOb);
  8440. this.globalData.defs.appendChild(elementData.gf);
  8441. if (elementData.maskId) {
  8442. this.globalData.defs.appendChild(elementData.ms);
  8443. this.globalData.defs.appendChild(elementData.of);
  8444. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8445. }
  8446. } else if (data.ty === 'no') {
  8447. elementData = new SVGNoStyleData(this, data, styleOb);
  8448. }
  8449. if (data.ty === 'st' || data.ty === 'gs') {
  8450. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8451. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8452. pathElement.setAttribute('fill-opacity', '0');
  8453. if (data.lj === 1) {
  8454. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8455. }
  8456. }
  8457. if (data.r === 2) {
  8458. pathElement.setAttribute('fill-rule', 'evenodd');
  8459. }
  8460. if (data.ln) {
  8461. pathElement.setAttribute('id', data.ln);
  8462. }
  8463. if (data.cl) {
  8464. pathElement.setAttribute('class', data.cl);
  8465. }
  8466. if (data.bm) {
  8467. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8468. }
  8469. this.stylesList.push(styleOb);
  8470. this.addToAnimatedContents(data, elementData);
  8471. return elementData;
  8472. };
  8473. SVGShapeElement.prototype.createGroupElement = function (data) {
  8474. var elementData = new ShapeGroupData();
  8475. if (data.ln) {
  8476. elementData.gr.setAttribute('id', data.ln);
  8477. }
  8478. if (data.cl) {
  8479. elementData.gr.setAttribute('class', data.cl);
  8480. }
  8481. if (data.bm) {
  8482. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8483. }
  8484. return elementData;
  8485. };
  8486. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8487. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8488. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8489. this.addToAnimatedContents(data, elementData);
  8490. return elementData;
  8491. };
  8492. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8493. var ty = 4;
  8494. if (data.ty === 'rc') {
  8495. ty = 5;
  8496. } else if (data.ty === 'el') {
  8497. ty = 6;
  8498. } else if (data.ty === 'sr') {
  8499. ty = 7;
  8500. }
  8501. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8502. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8503. this.shapes.push(elementData);
  8504. this.addShapeToModifiers(elementData);
  8505. this.addToAnimatedContents(data, elementData);
  8506. return elementData;
  8507. };
  8508. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8509. var i = 0;
  8510. var len = this.animatedContents.length;
  8511. while (i < len) {
  8512. if (this.animatedContents[i].element === element) {
  8513. return;
  8514. }
  8515. i += 1;
  8516. }
  8517. this.animatedContents.push({
  8518. fn: SVGElementsRenderer.createRenderFunction(data),
  8519. element: element,
  8520. data: data
  8521. });
  8522. };
  8523. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8524. var arr = elementData.styles;
  8525. var j;
  8526. var jLen = this.stylesList.length;
  8527. for (j = 0; j < jLen; j += 1) {
  8528. if (arr.indexOf(this.stylesList[j]) === -1 && !this.stylesList[j].closed) {
  8529. arr.push(this.stylesList[j]);
  8530. }
  8531. }
  8532. };
  8533. SVGShapeElement.prototype.reloadShapes = function () {
  8534. this._isFirstFrame = true;
  8535. var i;
  8536. var len = this.itemsData.length;
  8537. for (i = 0; i < len; i += 1) {
  8538. this.prevViewData[i] = this.itemsData[i];
  8539. }
  8540. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8541. this.filterUniqueShapes();
  8542. len = this.dynamicProperties.length;
  8543. for (i = 0; i < len; i += 1) {
  8544. this.dynamicProperties[i].getValue();
  8545. }
  8546. this.renderModifiers();
  8547. };
  8548. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8549. var ownTransformers = [].concat(transformers);
  8550. var i;
  8551. var len = arr.length - 1;
  8552. var j;
  8553. var jLen;
  8554. var ownStyles = [];
  8555. var ownModifiers = [];
  8556. var currentTransform;
  8557. var modifier;
  8558. var processedPos;
  8559. for (i = len; i >= 0; i -= 1) {
  8560. processedPos = this.searchProcessedElement(arr[i]);
  8561. if (!processedPos) {
  8562. arr[i]._render = render;
  8563. } else {
  8564. itemsData[i] = prevViewData[processedPos - 1];
  8565. }
  8566. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8567. if (!processedPos) {
  8568. itemsData[i] = this.createStyleElement(arr[i], level);
  8569. } else {
  8570. itemsData[i].style.closed = arr[i].hd;
  8571. }
  8572. if (arr[i]._render) {
  8573. if (itemsData[i].style.pElem.parentNode !== container) {
  8574. container.appendChild(itemsData[i].style.pElem);
  8575. }
  8576. }
  8577. ownStyles.push(itemsData[i].style);
  8578. } else if (arr[i].ty === 'gr') {
  8579. if (!processedPos) {
  8580. itemsData[i] = this.createGroupElement(arr[i]);
  8581. } else {
  8582. jLen = itemsData[i].it.length;
  8583. for (j = 0; j < jLen; j += 1) {
  8584. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8585. }
  8586. }
  8587. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8588. if (arr[i]._render) {
  8589. if (itemsData[i].gr.parentNode !== container) {
  8590. container.appendChild(itemsData[i].gr);
  8591. }
  8592. }
  8593. } else if (arr[i].ty === 'tr') {
  8594. if (!processedPos) {
  8595. itemsData[i] = this.createTransformElement(arr[i], container);
  8596. }
  8597. currentTransform = itemsData[i].transform;
  8598. ownTransformers.push(currentTransform);
  8599. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8600. if (!processedPos) {
  8601. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8602. }
  8603. this.setElementStyles(itemsData[i]);
  8604. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'ms' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  8605. if (!processedPos) {
  8606. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8607. modifier.init(this, arr[i]);
  8608. itemsData[i] = modifier;
  8609. this.shapeModifiers.push(modifier);
  8610. } else {
  8611. modifier = itemsData[i];
  8612. modifier.closed = false;
  8613. }
  8614. ownModifiers.push(modifier);
  8615. } else if (arr[i].ty === 'rp') {
  8616. if (!processedPos) {
  8617. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8618. itemsData[i] = modifier;
  8619. modifier.init(this, arr, i, itemsData);
  8620. this.shapeModifiers.push(modifier);
  8621. render = false;
  8622. } else {
  8623. modifier = itemsData[i];
  8624. modifier.closed = true;
  8625. }
  8626. ownModifiers.push(modifier);
  8627. }
  8628. this.addProcessedElement(arr[i], i + 1);
  8629. }
  8630. len = ownStyles.length;
  8631. for (i = 0; i < len; i += 1) {
  8632. ownStyles[i].closed = true;
  8633. }
  8634. len = ownModifiers.length;
  8635. for (i = 0; i < len; i += 1) {
  8636. ownModifiers[i].closed = true;
  8637. }
  8638. };
  8639. SVGShapeElement.prototype.renderInnerContent = function () {
  8640. this.renderModifiers();
  8641. var i;
  8642. var len = this.stylesList.length;
  8643. for (i = 0; i < len; i += 1) {
  8644. this.stylesList[i].reset();
  8645. }
  8646. this.renderShape();
  8647. for (i = 0; i < len; i += 1) {
  8648. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8649. if (this.stylesList[i].msElem) {
  8650. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  8651. // Adding M0 0 fixes same mask bug on all browsers
  8652. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8653. }
  8654. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8655. }
  8656. }
  8657. };
  8658. SVGShapeElement.prototype.renderShape = function () {
  8659. var i;
  8660. var len = this.animatedContents.length;
  8661. var animatedContent;
  8662. for (i = 0; i < len; i += 1) {
  8663. animatedContent = this.animatedContents[i];
  8664. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8665. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8666. }
  8667. }
  8668. };
  8669. SVGShapeElement.prototype.destroy = function () {
  8670. this.destroyBaseElement();
  8671. this.shapesData = null;
  8672. this.itemsData = null;
  8673. };
  8674. function LetterProps(o, sw, sc, fc, m, p) {
  8675. this.o = o;
  8676. this.sw = sw;
  8677. this.sc = sc;
  8678. this.fc = fc;
  8679. this.m = m;
  8680. this.p = p;
  8681. this._mdf = {
  8682. o: true,
  8683. sw: !!sw,
  8684. sc: !!sc,
  8685. fc: !!fc,
  8686. m: true,
  8687. p: true
  8688. };
  8689. }
  8690. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  8691. this._mdf.o = false;
  8692. this._mdf.sw = false;
  8693. this._mdf.sc = false;
  8694. this._mdf.fc = false;
  8695. this._mdf.m = false;
  8696. this._mdf.p = false;
  8697. var updated = false;
  8698. if (this.o !== o) {
  8699. this.o = o;
  8700. this._mdf.o = true;
  8701. updated = true;
  8702. }
  8703. if (this.sw !== sw) {
  8704. this.sw = sw;
  8705. this._mdf.sw = true;
  8706. updated = true;
  8707. }
  8708. if (this.sc !== sc) {
  8709. this.sc = sc;
  8710. this._mdf.sc = true;
  8711. updated = true;
  8712. }
  8713. if (this.fc !== fc) {
  8714. this.fc = fc;
  8715. this._mdf.fc = true;
  8716. updated = true;
  8717. }
  8718. if (this.m !== m) {
  8719. this.m = m;
  8720. this._mdf.m = true;
  8721. updated = true;
  8722. }
  8723. if (p.length && (this.p[0] !== p[0] || this.p[1] !== p[1] || this.p[4] !== p[4] || this.p[5] !== p[5] || this.p[12] !== p[12] || this.p[13] !== p[13])) {
  8724. this.p = p;
  8725. this._mdf.p = true;
  8726. updated = true;
  8727. }
  8728. return updated;
  8729. };
  8730. function TextProperty(elem, data) {
  8731. this._frameId = initialDefaultFrame;
  8732. this.pv = '';
  8733. this.v = '';
  8734. this.kf = false;
  8735. this._isFirstFrame = true;
  8736. this._mdf = false;
  8737. if (data.d && data.d.sid) {
  8738. data.d = elem.globalData.slotManager.getProp(data.d);
  8739. }
  8740. this.data = data;
  8741. this.elem = elem;
  8742. this.comp = this.elem.comp;
  8743. this.keysIndex = 0;
  8744. this.canResize = false;
  8745. this.minimumFontSize = 1;
  8746. this.effectsSequence = [];
  8747. this.currentData = {
  8748. ascent: 0,
  8749. boxWidth: this.defaultBoxWidth,
  8750. f: '',
  8751. fStyle: '',
  8752. fWeight: '',
  8753. fc: '',
  8754. j: '',
  8755. justifyOffset: '',
  8756. l: [],
  8757. lh: 0,
  8758. lineWidths: [],
  8759. ls: '',
  8760. of: '',
  8761. s: '',
  8762. sc: '',
  8763. sw: 0,
  8764. t: 0,
  8765. tr: 0,
  8766. sz: 0,
  8767. ps: null,
  8768. fillColorAnim: false,
  8769. strokeColorAnim: false,
  8770. strokeWidthAnim: false,
  8771. yOffset: 0,
  8772. finalSize: 0,
  8773. finalText: [],
  8774. finalLineHeight: 0,
  8775. __complete: false
  8776. };
  8777. this.copyData(this.currentData, this.data.d.k[0].s);
  8778. if (!this.searchProperty()) {
  8779. this.completeTextData(this.currentData);
  8780. }
  8781. }
  8782. TextProperty.prototype.defaultBoxWidth = [0, 0];
  8783. TextProperty.prototype.copyData = function (obj, data) {
  8784. for (var s in data) {
  8785. if (Object.prototype.hasOwnProperty.call(data, s)) {
  8786. obj[s] = data[s];
  8787. }
  8788. }
  8789. return obj;
  8790. };
  8791. TextProperty.prototype.setCurrentData = function (data) {
  8792. if (!data.__complete) {
  8793. this.completeTextData(data);
  8794. }
  8795. this.currentData = data;
  8796. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  8797. this._mdf = true;
  8798. };
  8799. TextProperty.prototype.searchProperty = function () {
  8800. return this.searchKeyframes();
  8801. };
  8802. TextProperty.prototype.searchKeyframes = function () {
  8803. this.kf = this.data.d.k.length > 1;
  8804. if (this.kf) {
  8805. this.addEffect(this.getKeyframeValue.bind(this));
  8806. }
  8807. return this.kf;
  8808. };
  8809. TextProperty.prototype.addEffect = function (effectFunction) {
  8810. this.effectsSequence.push(effectFunction);
  8811. this.elem.addDynamicProperty(this);
  8812. };
  8813. TextProperty.prototype.getValue = function (_finalValue) {
  8814. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  8815. return;
  8816. }
  8817. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  8818. var currentValue = this.currentData;
  8819. var currentIndex = this.keysIndex;
  8820. if (this.lock) {
  8821. this.setCurrentData(this.currentData);
  8822. return;
  8823. }
  8824. this.lock = true;
  8825. this._mdf = false;
  8826. var i;
  8827. var len = this.effectsSequence.length;
  8828. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  8829. for (i = 0; i < len; i += 1) {
  8830. // Checking if index changed to prevent creating a new object every time the expression updates.
  8831. if (currentIndex !== this.keysIndex) {
  8832. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  8833. } else {
  8834. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  8835. }
  8836. }
  8837. if (currentValue !== finalValue) {
  8838. this.setCurrentData(finalValue);
  8839. }
  8840. this.v = this.currentData;
  8841. this.pv = this.v;
  8842. this.lock = false;
  8843. this.frameId = this.elem.globalData.frameId;
  8844. };
  8845. TextProperty.prototype.getKeyframeValue = function () {
  8846. var textKeys = this.data.d.k;
  8847. var frameNum = this.elem.comp.renderedFrame;
  8848. var i = 0;
  8849. var len = textKeys.length;
  8850. while (i <= len - 1) {
  8851. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  8852. break;
  8853. }
  8854. i += 1;
  8855. }
  8856. if (this.keysIndex !== i) {
  8857. this.keysIndex = i;
  8858. }
  8859. return this.data.d.k[this.keysIndex].s;
  8860. };
  8861. TextProperty.prototype.buildFinalText = function (text) {
  8862. var charactersArray = [];
  8863. var i = 0;
  8864. var len = text.length;
  8865. var charCode;
  8866. var secondCharCode;
  8867. var shouldCombine = false;
  8868. var shouldCombineNext = false;
  8869. var currentChars = '';
  8870. while (i < len) {
  8871. shouldCombine = shouldCombineNext;
  8872. shouldCombineNext = false;
  8873. charCode = text.charCodeAt(i);
  8874. currentChars = text.charAt(i);
  8875. if (FontManager.isCombinedCharacter(charCode)) {
  8876. shouldCombine = true;
  8877. // It's a potential surrogate pair (this is the High surrogate)
  8878. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  8879. if (FontManager.isRegionalFlag(text, i)) {
  8880. currentChars = text.substr(i, 14);
  8881. } else {
  8882. secondCharCode = text.charCodeAt(i + 1);
  8883. // It's a surrogate pair (this is the Low surrogate)
  8884. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  8885. if (FontManager.isModifier(charCode, secondCharCode)) {
  8886. currentChars = text.substr(i, 2);
  8887. shouldCombine = true;
  8888. } else if (FontManager.isFlagEmoji(text.substr(i, 4))) {
  8889. currentChars = text.substr(i, 4);
  8890. } else {
  8891. currentChars = text.substr(i, 2);
  8892. }
  8893. }
  8894. }
  8895. } else if (charCode > 0xDBFF) {
  8896. secondCharCode = text.charCodeAt(i + 1);
  8897. if (FontManager.isVariationSelector(charCode)) {
  8898. shouldCombine = true;
  8899. }
  8900. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  8901. shouldCombine = true;
  8902. shouldCombineNext = true;
  8903. }
  8904. if (shouldCombine) {
  8905. charactersArray[charactersArray.length - 1] += currentChars;
  8906. shouldCombine = false;
  8907. } else {
  8908. charactersArray.push(currentChars);
  8909. }
  8910. i += currentChars.length;
  8911. }
  8912. return charactersArray;
  8913. };
  8914. TextProperty.prototype.completeTextData = function (documentData) {
  8915. documentData.__complete = true;
  8916. var fontManager = this.elem.globalData.fontManager;
  8917. var data = this.data;
  8918. var letters = [];
  8919. var i;
  8920. var len;
  8921. var newLineFlag;
  8922. var index = 0;
  8923. var val;
  8924. var anchorGrouping = data.m.g;
  8925. var currentSize = 0;
  8926. var currentPos = 0;
  8927. var currentLine = 0;
  8928. var lineWidths = [];
  8929. var lineWidth = 0;
  8930. var maxLineWidth = 0;
  8931. var j;
  8932. var jLen;
  8933. var fontData = fontManager.getFontByName(documentData.f);
  8934. var charData;
  8935. var cLength = 0;
  8936. var fontProps = getFontProperties(fontData);
  8937. documentData.fWeight = fontProps.weight;
  8938. documentData.fStyle = fontProps.style;
  8939. documentData.finalSize = documentData.s;
  8940. documentData.finalText = this.buildFinalText(documentData.t);
  8941. len = documentData.finalText.length;
  8942. documentData.finalLineHeight = documentData.lh;
  8943. var trackingOffset = documentData.tr / 1000 * documentData.finalSize;
  8944. var charCode;
  8945. if (documentData.sz) {
  8946. var flag = true;
  8947. var boxWidth = documentData.sz[0];
  8948. var boxHeight = documentData.sz[1];
  8949. var currentHeight;
  8950. var finalText;
  8951. while (flag) {
  8952. finalText = this.buildFinalText(documentData.t);
  8953. currentHeight = 0;
  8954. lineWidth = 0;
  8955. len = finalText.length;
  8956. trackingOffset = documentData.tr / 1000 * documentData.finalSize;
  8957. var lastSpaceIndex = -1;
  8958. for (i = 0; i < len; i += 1) {
  8959. charCode = finalText[i].charCodeAt(0);
  8960. newLineFlag = false;
  8961. if (finalText[i] === ' ') {
  8962. lastSpaceIndex = i;
  8963. } else if (charCode === 13 || charCode === 3) {
  8964. lineWidth = 0;
  8965. newLineFlag = true;
  8966. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8967. }
  8968. if (fontManager.chars) {
  8969. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  8970. cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
  8971. } else {
  8972. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  8973. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  8974. }
  8975. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  8976. if (lastSpaceIndex === -1) {
  8977. len += 1;
  8978. } else {
  8979. i = lastSpaceIndex;
  8980. }
  8981. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8982. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r');
  8983. // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  8984. lastSpaceIndex = -1;
  8985. lineWidth = 0;
  8986. } else {
  8987. lineWidth += cLength;
  8988. lineWidth += trackingOffset;
  8989. }
  8990. }
  8991. currentHeight += fontData.ascent * documentData.finalSize / 100;
  8992. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  8993. documentData.finalSize -= 1;
  8994. documentData.finalLineHeight = documentData.finalSize * documentData.lh / documentData.s;
  8995. } else {
  8996. documentData.finalText = finalText;
  8997. len = documentData.finalText.length;
  8998. flag = false;
  8999. }
  9000. }
  9001. }
  9002. lineWidth = -trackingOffset;
  9003. cLength = 0;
  9004. var uncollapsedSpaces = 0;
  9005. var currentChar;
  9006. for (i = 0; i < len; i += 1) {
  9007. newLineFlag = false;
  9008. currentChar = documentData.finalText[i];
  9009. charCode = currentChar.charCodeAt(0);
  9010. if (charCode === 13 || charCode === 3) {
  9011. uncollapsedSpaces = 0;
  9012. lineWidths.push(lineWidth);
  9013. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9014. lineWidth = -2 * trackingOffset;
  9015. val = '';
  9016. newLineFlag = true;
  9017. currentLine += 1;
  9018. } else {
  9019. val = currentChar;
  9020. }
  9021. if (fontManager.chars) {
  9022. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  9023. cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
  9024. } else {
  9025. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9026. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  9027. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9028. }
  9029. //
  9030. if (currentChar === ' ') {
  9031. uncollapsedSpaces += cLength + trackingOffset;
  9032. } else {
  9033. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  9034. uncollapsedSpaces = 0;
  9035. }
  9036. letters.push({
  9037. l: cLength,
  9038. an: cLength,
  9039. add: currentSize,
  9040. n: newLineFlag,
  9041. anIndexes: [],
  9042. val: val,
  9043. line: currentLine,
  9044. animatorJustifyOffset: 0
  9045. });
  9046. if (anchorGrouping == 2) {
  9047. // eslint-disable-line eqeqeq
  9048. currentSize += cLength;
  9049. if (val === '' || val === ' ' || i === len - 1) {
  9050. if (val === '' || val === ' ') {
  9051. currentSize -= cLength;
  9052. }
  9053. while (currentPos <= i) {
  9054. letters[currentPos].an = currentSize;
  9055. letters[currentPos].ind = index;
  9056. letters[currentPos].extra = cLength;
  9057. currentPos += 1;
  9058. }
  9059. index += 1;
  9060. currentSize = 0;
  9061. }
  9062. } else if (anchorGrouping == 3) {
  9063. // eslint-disable-line eqeqeq
  9064. currentSize += cLength;
  9065. if (val === '' || i === len - 1) {
  9066. if (val === '') {
  9067. currentSize -= cLength;
  9068. }
  9069. while (currentPos <= i) {
  9070. letters[currentPos].an = currentSize;
  9071. letters[currentPos].ind = index;
  9072. letters[currentPos].extra = cLength;
  9073. currentPos += 1;
  9074. }
  9075. currentSize = 0;
  9076. index += 1;
  9077. }
  9078. } else {
  9079. letters[index].ind = index;
  9080. letters[index].extra = 0;
  9081. index += 1;
  9082. }
  9083. }
  9084. documentData.l = letters;
  9085. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9086. lineWidths.push(lineWidth);
  9087. if (documentData.sz) {
  9088. documentData.boxWidth = documentData.sz[0];
  9089. documentData.justifyOffset = 0;
  9090. } else {
  9091. documentData.boxWidth = maxLineWidth;
  9092. switch (documentData.j) {
  9093. case 1:
  9094. documentData.justifyOffset = -documentData.boxWidth;
  9095. break;
  9096. case 2:
  9097. documentData.justifyOffset = -documentData.boxWidth / 2;
  9098. break;
  9099. default:
  9100. documentData.justifyOffset = 0;
  9101. }
  9102. }
  9103. documentData.lineWidths = lineWidths;
  9104. var animators = data.a;
  9105. var animatorData;
  9106. var letterData;
  9107. jLen = animators.length;
  9108. var based;
  9109. var ind;
  9110. var indexes = [];
  9111. for (j = 0; j < jLen; j += 1) {
  9112. animatorData = animators[j];
  9113. if (animatorData.a.sc) {
  9114. documentData.strokeColorAnim = true;
  9115. }
  9116. if (animatorData.a.sw) {
  9117. documentData.strokeWidthAnim = true;
  9118. }
  9119. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9120. documentData.fillColorAnim = true;
  9121. }
  9122. ind = 0;
  9123. based = animatorData.s.b;
  9124. for (i = 0; i < len; i += 1) {
  9125. letterData = letters[i];
  9126. letterData.anIndexes[j] = ind;
  9127. if (based == 1 && letterData.val !== '' || based == 2 && letterData.val !== '' && letterData.val !== ' ' || based == 3 && (letterData.n || letterData.val == ' ' || i == len - 1) || based == 4 && (letterData.n || i == len - 1)) {
  9128. // eslint-disable-line eqeqeq
  9129. if (animatorData.s.rn === 1) {
  9130. indexes.push(ind);
  9131. }
  9132. ind += 1;
  9133. }
  9134. }
  9135. data.a[j].s.totalChars = ind;
  9136. var currentInd = -1;
  9137. var newInd;
  9138. if (animatorData.s.rn === 1) {
  9139. for (i = 0; i < len; i += 1) {
  9140. letterData = letters[i];
  9141. if (currentInd != letterData.anIndexes[j]) {
  9142. // eslint-disable-line eqeqeq
  9143. currentInd = letterData.anIndexes[j];
  9144. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9145. }
  9146. letterData.anIndexes[j] = newInd;
  9147. }
  9148. }
  9149. }
  9150. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9151. documentData.ls = documentData.ls || 0;
  9152. documentData.ascent = fontData.ascent * documentData.finalSize / 100;
  9153. };
  9154. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9155. index = index === undefined ? this.keysIndex : index;
  9156. var dData = this.copyData({}, this.data.d.k[index].s);
  9157. dData = this.copyData(dData, newData);
  9158. this.data.d.k[index].s = dData;
  9159. this.recalculate(index);
  9160. this.setCurrentData(dData);
  9161. this.elem.addDynamicProperty(this);
  9162. };
  9163. TextProperty.prototype.recalculate = function (index) {
  9164. var dData = this.data.d.k[index].s;
  9165. dData.__complete = false;
  9166. this.keysIndex = 0;
  9167. this._isFirstFrame = true;
  9168. this.getValue(dData);
  9169. };
  9170. TextProperty.prototype.canResizeFont = function (_canResize) {
  9171. this.canResize = _canResize;
  9172. this.recalculate(this.keysIndex);
  9173. this.elem.addDynamicProperty(this);
  9174. };
  9175. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9176. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9177. this.recalculate(this.keysIndex);
  9178. this.elem.addDynamicProperty(this);
  9179. };
  9180. var TextSelectorProp = function () {
  9181. var max = Math.max;
  9182. var min = Math.min;
  9183. var floor = Math.floor;
  9184. function TextSelectorPropFactory(elem, data) {
  9185. this._currentTextLength = -1;
  9186. this.k = false;
  9187. this.data = data;
  9188. this.elem = elem;
  9189. this.comp = elem.comp;
  9190. this.finalS = 0;
  9191. this.finalE = 0;
  9192. this.initDynamicPropertyContainer(elem);
  9193. this.s = PropertyFactory.getProp(elem, data.s || {
  9194. k: 0
  9195. }, 0, 0, this);
  9196. if ('e' in data) {
  9197. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9198. } else {
  9199. this.e = {
  9200. v: 100
  9201. };
  9202. }
  9203. this.o = PropertyFactory.getProp(elem, data.o || {
  9204. k: 0
  9205. }, 0, 0, this);
  9206. this.xe = PropertyFactory.getProp(elem, data.xe || {
  9207. k: 0
  9208. }, 0, 0, this);
  9209. this.ne = PropertyFactory.getProp(elem, data.ne || {
  9210. k: 0
  9211. }, 0, 0, this);
  9212. this.sm = PropertyFactory.getProp(elem, data.sm || {
  9213. k: 100
  9214. }, 0, 0, this);
  9215. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9216. if (!this.dynamicProperties.length) {
  9217. this.getValue();
  9218. }
  9219. }
  9220. TextSelectorPropFactory.prototype = {
  9221. getMult: function getMult(ind) {
  9222. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9223. this.getValue();
  9224. }
  9225. var x1 = 0;
  9226. var y1 = 0;
  9227. var x2 = 1;
  9228. var y2 = 1;
  9229. if (this.ne.v > 0) {
  9230. x1 = this.ne.v / 100.0;
  9231. } else {
  9232. y1 = -this.ne.v / 100.0;
  9233. }
  9234. if (this.xe.v > 0) {
  9235. x2 = 1.0 - this.xe.v / 100.0;
  9236. } else {
  9237. y2 = 1.0 + this.xe.v / 100.0;
  9238. }
  9239. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9240. var mult = 0;
  9241. var s = this.finalS;
  9242. var e = this.finalE;
  9243. var type = this.data.sh;
  9244. if (type === 2) {
  9245. if (e === s) {
  9246. mult = ind >= e ? 1 : 0;
  9247. } else {
  9248. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9249. }
  9250. mult = easer(mult);
  9251. } else if (type === 3) {
  9252. if (e === s) {
  9253. mult = ind >= e ? 0 : 1;
  9254. } else {
  9255. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9256. }
  9257. mult = easer(mult);
  9258. } else if (type === 4) {
  9259. if (e === s) {
  9260. mult = 0;
  9261. } else {
  9262. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9263. if (mult < 0.5) {
  9264. mult *= 2;
  9265. } else {
  9266. mult = 1 - 2 * (mult - 0.5);
  9267. }
  9268. }
  9269. mult = easer(mult);
  9270. } else if (type === 5) {
  9271. if (e === s) {
  9272. mult = 0;
  9273. } else {
  9274. var tot = e - s;
  9275. /* ind += 0.5;
  9276. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9277. ind = min(max(0, ind + 0.5 - s), e - s);
  9278. var x = -tot / 2 + ind;
  9279. var a = tot / 2;
  9280. mult = Math.sqrt(1 - x * x / (a * a));
  9281. }
  9282. mult = easer(mult);
  9283. } else if (type === 6) {
  9284. if (e === s) {
  9285. mult = 0;
  9286. } else {
  9287. ind = min(max(0, ind + 0.5 - s), e - s);
  9288. mult = (1 + Math.cos(Math.PI + Math.PI * 2 * ind / (e - s))) / 2; // eslint-disable-line
  9289. }
  9290. mult = easer(mult);
  9291. } else {
  9292. if (ind >= floor(s)) {
  9293. if (ind - s < 0) {
  9294. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9295. } else {
  9296. mult = max(0, min(e - ind, 1));
  9297. }
  9298. }
  9299. mult = easer(mult);
  9300. }
  9301. // Smoothness implementation.
  9302. // The smoothness represents a reduced range of the original [0; 1] range.
  9303. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9304. // Steps are:
  9305. // - find the lower value of the new range (threshold)
  9306. // - if multiplier is smaller than that value, floor it to 0
  9307. // - if it is larger,
  9308. // - subtract the threshold
  9309. // - divide it by the smoothness (this will return the range to [0; 1])
  9310. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9311. if (this.sm.v !== 100) {
  9312. var smoothness = this.sm.v * 0.01;
  9313. if (smoothness === 0) {
  9314. smoothness = 0.00000001;
  9315. }
  9316. var threshold = 0.5 - smoothness * 0.5;
  9317. if (mult < threshold) {
  9318. mult = 0;
  9319. } else {
  9320. mult = (mult - threshold) / smoothness;
  9321. if (mult > 1) {
  9322. mult = 1;
  9323. }
  9324. }
  9325. }
  9326. return mult * this.a.v;
  9327. },
  9328. getValue: function getValue(newCharsFlag) {
  9329. this.iterateDynamicProperties();
  9330. this._mdf = newCharsFlag || this._mdf;
  9331. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9332. if (newCharsFlag && this.data.r === 2) {
  9333. this.e.v = this._currentTextLength;
  9334. }
  9335. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9336. var o = this.o.v / divisor;
  9337. var s = this.s.v / divisor + o;
  9338. var e = this.e.v / divisor + o;
  9339. if (s > e) {
  9340. var _s = s;
  9341. s = e;
  9342. e = _s;
  9343. }
  9344. this.finalS = s;
  9345. this.finalE = e;
  9346. }
  9347. };
  9348. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9349. function getTextSelectorProp(elem, data, arr) {
  9350. return new TextSelectorPropFactory(elem, data, arr);
  9351. }
  9352. return {
  9353. getTextSelectorProp: getTextSelectorProp
  9354. };
  9355. }();
  9356. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9357. var defaultData = {
  9358. propType: false
  9359. };
  9360. var getProp = PropertyFactory.getProp;
  9361. var textAnimatorAnimatables = animatorProps.a;
  9362. this.a = {
  9363. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9364. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9365. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9366. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9367. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9368. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9369. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9370. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9371. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9372. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9373. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9374. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9375. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9376. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9377. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9378. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData
  9379. };
  9380. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9381. this.s.t = animatorProps.s.t;
  9382. }
  9383. function TextAnimatorProperty(textData, renderType, elem) {
  9384. this._isFirstFrame = true;
  9385. this._hasMaskedPath = false;
  9386. this._frameId = -1;
  9387. this._textData = textData;
  9388. this._renderType = renderType;
  9389. this._elem = elem;
  9390. this._animatorsData = createSizedArray(this._textData.a.length);
  9391. this._pathData = {};
  9392. this._moreOptions = {
  9393. alignment: {}
  9394. };
  9395. this.renderedLetters = [];
  9396. this.lettersChangedFlag = false;
  9397. this.initDynamicPropertyContainer(elem);
  9398. }
  9399. TextAnimatorProperty.prototype.searchProperties = function () {
  9400. var i;
  9401. var len = this._textData.a.length;
  9402. var animatorProps;
  9403. var getProp = PropertyFactory.getProp;
  9404. for (i = 0; i < len; i += 1) {
  9405. animatorProps = this._textData.a[i];
  9406. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9407. }
  9408. if (this._textData.p && 'm' in this._textData.p) {
  9409. this._pathData = {
  9410. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9411. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9412. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9413. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9414. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9415. m: this._elem.maskManager.getMaskProperty(this._textData.p.m)
  9416. };
  9417. this._hasMaskedPath = true;
  9418. } else {
  9419. this._hasMaskedPath = false;
  9420. }
  9421. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9422. };
  9423. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9424. this.lettersChangedFlag = lettersChangedFlag;
  9425. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9426. return;
  9427. }
  9428. this._isFirstFrame = false;
  9429. var alignment = this._moreOptions.alignment.v;
  9430. var animators = this._animatorsData;
  9431. var textData = this._textData;
  9432. var matrixHelper = this.mHelper;
  9433. var renderType = this._renderType;
  9434. var renderedLettersCount = this.renderedLetters.length;
  9435. var xPos;
  9436. var yPos;
  9437. var i;
  9438. var len;
  9439. var letters = documentData.l;
  9440. var pathInfo;
  9441. var currentLength;
  9442. var currentPoint;
  9443. var segmentLength;
  9444. var flag;
  9445. var pointInd;
  9446. var segmentInd;
  9447. var prevPoint;
  9448. var points;
  9449. var segments;
  9450. var partialLength;
  9451. var totalLength;
  9452. var perc;
  9453. var tanAngle;
  9454. var mask;
  9455. if (this._hasMaskedPath) {
  9456. mask = this._pathData.m;
  9457. if (!this._pathData.n || this._pathData._mdf) {
  9458. var paths = mask.v;
  9459. if (this._pathData.r.v) {
  9460. paths = paths.reverse();
  9461. }
  9462. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9463. pathInfo = {
  9464. tLength: 0,
  9465. segments: []
  9466. };
  9467. len = paths._length - 1;
  9468. var bezierData;
  9469. totalLength = 0;
  9470. for (i = 0; i < len; i += 1) {
  9471. bezierData = bez.buildBezierData(paths.v[i], paths.v[i + 1], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9472. pathInfo.tLength += bezierData.segmentLength;
  9473. pathInfo.segments.push(bezierData);
  9474. totalLength += bezierData.segmentLength;
  9475. }
  9476. i = len;
  9477. if (mask.v.c) {
  9478. bezierData = bez.buildBezierData(paths.v[i], paths.v[0], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9479. pathInfo.tLength += bezierData.segmentLength;
  9480. pathInfo.segments.push(bezierData);
  9481. totalLength += bezierData.segmentLength;
  9482. }
  9483. this._pathData.pi = pathInfo;
  9484. }
  9485. pathInfo = this._pathData.pi;
  9486. currentLength = this._pathData.f.v;
  9487. segmentInd = 0;
  9488. pointInd = 1;
  9489. segmentLength = 0;
  9490. flag = true;
  9491. segments = pathInfo.segments;
  9492. if (currentLength < 0 && mask.v.c) {
  9493. if (pathInfo.tLength < Math.abs(currentLength)) {
  9494. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9495. }
  9496. segmentInd = segments.length - 1;
  9497. points = segments[segmentInd].points;
  9498. pointInd = points.length - 1;
  9499. while (currentLength < 0) {
  9500. currentLength += points[pointInd].partialLength;
  9501. pointInd -= 1;
  9502. if (pointInd < 0) {
  9503. segmentInd -= 1;
  9504. points = segments[segmentInd].points;
  9505. pointInd = points.length - 1;
  9506. }
  9507. }
  9508. }
  9509. points = segments[segmentInd].points;
  9510. prevPoint = points[pointInd - 1];
  9511. currentPoint = points[pointInd];
  9512. partialLength = currentPoint.partialLength;
  9513. }
  9514. len = letters.length;
  9515. xPos = 0;
  9516. yPos = 0;
  9517. var yOff = documentData.finalSize * 1.2 * 0.714;
  9518. var firstLine = true;
  9519. var animatorProps;
  9520. var animatorSelector;
  9521. var j;
  9522. var jLen;
  9523. var letterValue;
  9524. jLen = animators.length;
  9525. var mult;
  9526. var ind = -1;
  9527. var offf;
  9528. var xPathPos;
  9529. var yPathPos;
  9530. var initPathPos = currentLength;
  9531. var initSegmentInd = segmentInd;
  9532. var initPointInd = pointInd;
  9533. var currentLine = -1;
  9534. var elemOpacity;
  9535. var sc;
  9536. var sw;
  9537. var fc;
  9538. var k;
  9539. var letterSw;
  9540. var letterSc;
  9541. var letterFc;
  9542. var letterM = '';
  9543. var letterP = this.defaultPropsArray;
  9544. var letterO;
  9545. //
  9546. if (documentData.j === 2 || documentData.j === 1) {
  9547. var animatorJustifyOffset = 0;
  9548. var animatorFirstCharOffset = 0;
  9549. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9550. var lastIndex = 0;
  9551. var isNewLine = true;
  9552. for (i = 0; i < len; i += 1) {
  9553. if (letters[i].n) {
  9554. if (animatorJustifyOffset) {
  9555. animatorJustifyOffset += animatorFirstCharOffset;
  9556. }
  9557. while (lastIndex < i) {
  9558. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9559. lastIndex += 1;
  9560. }
  9561. animatorJustifyOffset = 0;
  9562. isNewLine = true;
  9563. } else {
  9564. for (j = 0; j < jLen; j += 1) {
  9565. animatorProps = animators[j].a;
  9566. if (animatorProps.t.propType) {
  9567. if (isNewLine && documentData.j === 2) {
  9568. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9569. }
  9570. animatorSelector = animators[j].s;
  9571. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9572. if (mult.length) {
  9573. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9574. } else {
  9575. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9576. }
  9577. }
  9578. }
  9579. isNewLine = false;
  9580. }
  9581. }
  9582. if (animatorJustifyOffset) {
  9583. animatorJustifyOffset += animatorFirstCharOffset;
  9584. }
  9585. while (lastIndex < i) {
  9586. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9587. lastIndex += 1;
  9588. }
  9589. }
  9590. //
  9591. for (i = 0; i < len; i += 1) {
  9592. matrixHelper.reset();
  9593. elemOpacity = 1;
  9594. if (letters[i].n) {
  9595. xPos = 0;
  9596. yPos += documentData.yOffset;
  9597. yPos += firstLine ? 1 : 0;
  9598. currentLength = initPathPos;
  9599. firstLine = false;
  9600. if (this._hasMaskedPath) {
  9601. segmentInd = initSegmentInd;
  9602. pointInd = initPointInd;
  9603. points = segments[segmentInd].points;
  9604. prevPoint = points[pointInd - 1];
  9605. currentPoint = points[pointInd];
  9606. partialLength = currentPoint.partialLength;
  9607. segmentLength = 0;
  9608. }
  9609. letterM = '';
  9610. letterFc = '';
  9611. letterSw = '';
  9612. letterO = '';
  9613. letterP = this.defaultPropsArray;
  9614. } else {
  9615. if (this._hasMaskedPath) {
  9616. if (currentLine !== letters[i].line) {
  9617. switch (documentData.j) {
  9618. case 1:
  9619. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9620. break;
  9621. case 2:
  9622. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9623. break;
  9624. default:
  9625. break;
  9626. }
  9627. currentLine = letters[i].line;
  9628. }
  9629. if (ind !== letters[i].ind) {
  9630. if (letters[ind]) {
  9631. currentLength += letters[ind].extra;
  9632. }
  9633. currentLength += letters[i].an / 2;
  9634. ind = letters[i].ind;
  9635. }
  9636. currentLength += alignment[0] * letters[i].an * 0.005;
  9637. var animatorOffset = 0;
  9638. for (j = 0; j < jLen; j += 1) {
  9639. animatorProps = animators[j].a;
  9640. if (animatorProps.p.propType) {
  9641. animatorSelector = animators[j].s;
  9642. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9643. if (mult.length) {
  9644. animatorOffset += animatorProps.p.v[0] * mult[0];
  9645. } else {
  9646. animatorOffset += animatorProps.p.v[0] * mult;
  9647. }
  9648. }
  9649. if (animatorProps.a.propType) {
  9650. animatorSelector = animators[j].s;
  9651. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9652. if (mult.length) {
  9653. animatorOffset += animatorProps.a.v[0] * mult[0];
  9654. } else {
  9655. animatorOffset += animatorProps.a.v[0] * mult;
  9656. }
  9657. }
  9658. }
  9659. flag = true;
  9660. // Force alignment only works with a single line for now
  9661. if (this._pathData.a.v) {
  9662. currentLength = letters[0].an * 0.5 + (totalLength - this._pathData.f.v - letters[0].an * 0.5 - letters[letters.length - 1].an * 0.5) * ind / (len - 1);
  9663. currentLength += this._pathData.f.v;
  9664. }
  9665. while (flag) {
  9666. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9667. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9668. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9669. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9670. matrixHelper.translate(-alignment[0] * letters[i].an * 0.005, -(alignment[1] * yOff) * 0.01);
  9671. flag = false;
  9672. } else if (points) {
  9673. segmentLength += currentPoint.partialLength;
  9674. pointInd += 1;
  9675. if (pointInd >= points.length) {
  9676. pointInd = 0;
  9677. segmentInd += 1;
  9678. if (!segments[segmentInd]) {
  9679. if (mask.v.c) {
  9680. pointInd = 0;
  9681. segmentInd = 0;
  9682. points = segments[segmentInd].points;
  9683. } else {
  9684. segmentLength -= currentPoint.partialLength;
  9685. points = null;
  9686. }
  9687. } else {
  9688. points = segments[segmentInd].points;
  9689. }
  9690. }
  9691. if (points) {
  9692. prevPoint = currentPoint;
  9693. currentPoint = points[pointInd];
  9694. partialLength = currentPoint.partialLength;
  9695. }
  9696. }
  9697. }
  9698. offf = letters[i].an / 2 - letters[i].add;
  9699. matrixHelper.translate(-offf, 0, 0);
  9700. } else {
  9701. offf = letters[i].an / 2 - letters[i].add;
  9702. matrixHelper.translate(-offf, 0, 0);
  9703. // Grouping alignment
  9704. matrixHelper.translate(-alignment[0] * letters[i].an * 0.005, -alignment[1] * yOff * 0.01, 0);
  9705. }
  9706. for (j = 0; j < jLen; j += 1) {
  9707. animatorProps = animators[j].a;
  9708. if (animatorProps.t.propType) {
  9709. animatorSelector = animators[j].s;
  9710. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9711. // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9712. if (xPos !== 0 || documentData.j !== 0) {
  9713. if (this._hasMaskedPath) {
  9714. if (mult.length) {
  9715. currentLength += animatorProps.t.v * mult[0];
  9716. } else {
  9717. currentLength += animatorProps.t.v * mult;
  9718. }
  9719. } else if (mult.length) {
  9720. xPos += animatorProps.t.v * mult[0];
  9721. } else {
  9722. xPos += animatorProps.t.v * mult;
  9723. }
  9724. }
  9725. }
  9726. }
  9727. if (documentData.strokeWidthAnim) {
  9728. sw = documentData.sw || 0;
  9729. }
  9730. if (documentData.strokeColorAnim) {
  9731. if (documentData.sc) {
  9732. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  9733. } else {
  9734. sc = [0, 0, 0];
  9735. }
  9736. }
  9737. if (documentData.fillColorAnim && documentData.fc) {
  9738. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  9739. }
  9740. for (j = 0; j < jLen; j += 1) {
  9741. animatorProps = animators[j].a;
  9742. if (animatorProps.a.propType) {
  9743. animatorSelector = animators[j].s;
  9744. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9745. if (mult.length) {
  9746. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  9747. } else {
  9748. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  9749. }
  9750. }
  9751. }
  9752. for (j = 0; j < jLen; j += 1) {
  9753. animatorProps = animators[j].a;
  9754. if (animatorProps.s.propType) {
  9755. animatorSelector = animators[j].s;
  9756. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9757. if (mult.length) {
  9758. matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult[0], 1 + (animatorProps.s.v[1] - 1) * mult[1], 1);
  9759. } else {
  9760. matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult, 1 + (animatorProps.s.v[1] - 1) * mult, 1);
  9761. }
  9762. }
  9763. }
  9764. for (j = 0; j < jLen; j += 1) {
  9765. animatorProps = animators[j].a;
  9766. animatorSelector = animators[j].s;
  9767. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9768. if (animatorProps.sk.propType) {
  9769. if (mult.length) {
  9770. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  9771. } else {
  9772. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  9773. }
  9774. }
  9775. if (animatorProps.r.propType) {
  9776. if (mult.length) {
  9777. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  9778. } else {
  9779. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  9780. }
  9781. }
  9782. if (animatorProps.ry.propType) {
  9783. if (mult.length) {
  9784. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  9785. } else {
  9786. matrixHelper.rotateY(animatorProps.ry.v * mult);
  9787. }
  9788. }
  9789. if (animatorProps.rx.propType) {
  9790. if (mult.length) {
  9791. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  9792. } else {
  9793. matrixHelper.rotateX(animatorProps.rx.v * mult);
  9794. }
  9795. }
  9796. if (animatorProps.o.propType) {
  9797. if (mult.length) {
  9798. elemOpacity += (animatorProps.o.v * mult[0] - elemOpacity) * mult[0];
  9799. } else {
  9800. elemOpacity += (animatorProps.o.v * mult - elemOpacity) * mult;
  9801. }
  9802. }
  9803. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  9804. if (mult.length) {
  9805. sw += animatorProps.sw.v * mult[0];
  9806. } else {
  9807. sw += animatorProps.sw.v * mult;
  9808. }
  9809. }
  9810. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  9811. for (k = 0; k < 3; k += 1) {
  9812. if (mult.length) {
  9813. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  9814. } else {
  9815. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  9816. }
  9817. }
  9818. }
  9819. if (documentData.fillColorAnim && documentData.fc) {
  9820. if (animatorProps.fc.propType) {
  9821. for (k = 0; k < 3; k += 1) {
  9822. if (mult.length) {
  9823. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  9824. } else {
  9825. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  9826. }
  9827. }
  9828. }
  9829. if (animatorProps.fh.propType) {
  9830. if (mult.length) {
  9831. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  9832. } else {
  9833. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  9834. }
  9835. }
  9836. if (animatorProps.fs.propType) {
  9837. if (mult.length) {
  9838. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  9839. } else {
  9840. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  9841. }
  9842. }
  9843. if (animatorProps.fb.propType) {
  9844. if (mult.length) {
  9845. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  9846. } else {
  9847. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  9848. }
  9849. }
  9850. }
  9851. }
  9852. for (j = 0; j < jLen; j += 1) {
  9853. animatorProps = animators[j].a;
  9854. if (animatorProps.p.propType) {
  9855. animatorSelector = animators[j].s;
  9856. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9857. if (this._hasMaskedPath) {
  9858. if (mult.length) {
  9859. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  9860. } else {
  9861. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9862. }
  9863. } else if (mult.length) {
  9864. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  9865. } else {
  9866. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9867. }
  9868. }
  9869. }
  9870. if (documentData.strokeWidthAnim) {
  9871. letterSw = sw < 0 ? 0 : sw;
  9872. }
  9873. if (documentData.strokeColorAnim) {
  9874. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  9875. }
  9876. if (documentData.fillColorAnim && documentData.fc) {
  9877. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  9878. }
  9879. if (this._hasMaskedPath) {
  9880. matrixHelper.translate(0, -documentData.ls);
  9881. matrixHelper.translate(0, alignment[1] * yOff * 0.01 + yPos, 0);
  9882. if (this._pathData.p.v) {
  9883. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  9884. var rot = Math.atan(tanAngle) * 180 / Math.PI;
  9885. if (currentPoint.point[0] < prevPoint.point[0]) {
  9886. rot += 180;
  9887. }
  9888. matrixHelper.rotate(-rot * Math.PI / 180);
  9889. }
  9890. matrixHelper.translate(xPathPos, yPathPos, 0);
  9891. currentLength -= alignment[0] * letters[i].an * 0.005;
  9892. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  9893. currentLength += letters[i].an / 2;
  9894. currentLength += documentData.tr * 0.001 * documentData.finalSize;
  9895. }
  9896. } else {
  9897. matrixHelper.translate(xPos, yPos, 0);
  9898. if (documentData.ps) {
  9899. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  9900. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9901. }
  9902. switch (documentData.j) {
  9903. case 1:
  9904. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  9905. break;
  9906. case 2:
  9907. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  9908. break;
  9909. default:
  9910. break;
  9911. }
  9912. matrixHelper.translate(0, -documentData.ls);
  9913. matrixHelper.translate(offf, 0, 0);
  9914. matrixHelper.translate(alignment[0] * letters[i].an * 0.005, alignment[1] * yOff * 0.01, 0);
  9915. xPos += letters[i].l + documentData.tr * 0.001 * documentData.finalSize;
  9916. }
  9917. if (renderType === 'html') {
  9918. letterM = matrixHelper.toCSS();
  9919. } else if (renderType === 'svg') {
  9920. letterM = matrixHelper.to2dCSS();
  9921. } else {
  9922. letterP = [matrixHelper.props[0], matrixHelper.props[1], matrixHelper.props[2], matrixHelper.props[3], matrixHelper.props[4], matrixHelper.props[5], matrixHelper.props[6], matrixHelper.props[7], matrixHelper.props[8], matrixHelper.props[9], matrixHelper.props[10], matrixHelper.props[11], matrixHelper.props[12], matrixHelper.props[13], matrixHelper.props[14], matrixHelper.props[15]];
  9923. }
  9924. letterO = elemOpacity;
  9925. }
  9926. if (renderedLettersCount <= i) {
  9927. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  9928. this.renderedLetters.push(letterValue);
  9929. renderedLettersCount += 1;
  9930. this.lettersChangedFlag = true;
  9931. } else {
  9932. letterValue = this.renderedLetters[i];
  9933. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  9934. }
  9935. }
  9936. };
  9937. TextAnimatorProperty.prototype.getValue = function () {
  9938. if (this._elem.globalData.frameId === this._frameId) {
  9939. return;
  9940. }
  9941. this._frameId = this._elem.globalData.frameId;
  9942. this.iterateDynamicProperties();
  9943. };
  9944. TextAnimatorProperty.prototype.mHelper = new Matrix();
  9945. TextAnimatorProperty.prototype.defaultPropsArray = [];
  9946. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  9947. function ITextElement() {}
  9948. ITextElement.prototype.initElement = function (data, globalData, comp) {
  9949. this.lettersChangedFlag = true;
  9950. this.initFrame();
  9951. this.initBaseData(data, globalData, comp);
  9952. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  9953. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  9954. this.initTransform(data, globalData, comp);
  9955. this.initHierarchy();
  9956. this.initRenderable();
  9957. this.initRendererElement();
  9958. this.createContainerElements();
  9959. this.createRenderableComponents();
  9960. this.createContent();
  9961. this.hide();
  9962. this.textAnimator.searchProperties(this.dynamicProperties);
  9963. };
  9964. ITextElement.prototype.prepareFrame = function (num) {
  9965. this._mdf = false;
  9966. this.prepareRenderableFrame(num);
  9967. this.prepareProperties(num, this.isInRange);
  9968. };
  9969. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  9970. var j;
  9971. var jLen = shapes.length;
  9972. var pathNodes;
  9973. var shapeStr = '';
  9974. for (j = 0; j < jLen; j += 1) {
  9975. if (shapes[j].ty === 'sh') {
  9976. pathNodes = shapes[j].ks.k;
  9977. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  9978. }
  9979. }
  9980. return shapeStr;
  9981. };
  9982. ITextElement.prototype.updateDocumentData = function (newData, index) {
  9983. this.textProperty.updateDocumentData(newData, index);
  9984. };
  9985. ITextElement.prototype.canResizeFont = function (_canResize) {
  9986. this.textProperty.canResizeFont(_canResize);
  9987. };
  9988. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  9989. this.textProperty.setMinimumFontSize(_fontSize);
  9990. };
  9991. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  9992. if (documentData.ps) {
  9993. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9994. }
  9995. matrixHelper.translate(0, -documentData.ls, 0);
  9996. switch (documentData.j) {
  9997. case 1:
  9998. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  9999. break;
  10000. case 2:
  10001. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  10002. break;
  10003. default:
  10004. break;
  10005. }
  10006. matrixHelper.translate(xPos, yPos, 0);
  10007. };
  10008. ITextElement.prototype.buildColor = function (colorData) {
  10009. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  10010. };
  10011. ITextElement.prototype.emptyProp = new LetterProps();
  10012. ITextElement.prototype.destroy = function () {};
  10013. ITextElement.prototype.validateText = function () {
  10014. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  10015. this.buildNewText();
  10016. this.textProperty._isFirstFrame = false;
  10017. this.textProperty._mdf = false;
  10018. }
  10019. };
  10020. var emptyShapeData = {
  10021. shapes: []
  10022. };
  10023. function SVGTextLottieElement(data, globalData, comp) {
  10024. this.textSpans = [];
  10025. this.renderType = 'svg';
  10026. this.initElement(data, globalData, comp);
  10027. }
  10028. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  10029. SVGTextLottieElement.prototype.createContent = function () {
  10030. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  10031. this.textContainer = createNS('text');
  10032. }
  10033. };
  10034. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  10035. var i = 0;
  10036. var len = textArray.length;
  10037. var textContents = [];
  10038. var currentTextContent = '';
  10039. while (i < len) {
  10040. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  10041. textContents.push(currentTextContent);
  10042. currentTextContent = '';
  10043. } else {
  10044. currentTextContent += textArray[i];
  10045. }
  10046. i += 1;
  10047. }
  10048. textContents.push(currentTextContent);
  10049. return textContents;
  10050. };
  10051. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  10052. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  10053. // but since text internal content gets only rendered once and then it's never rerendered,
  10054. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  10055. // Avoiding cloning is preferred since cloning each character shape data is expensive
  10056. if (data.shapes && data.shapes.length) {
  10057. var shape = data.shapes[0];
  10058. if (shape.it) {
  10059. var shapeItem = shape.it[shape.it.length - 1];
  10060. if (shapeItem.s) {
  10061. shapeItem.s.k[0] = scale;
  10062. shapeItem.s.k[1] = scale;
  10063. }
  10064. }
  10065. }
  10066. return data;
  10067. };
  10068. SVGTextLottieElement.prototype.buildNewText = function () {
  10069. this.addDynamicProperty(this);
  10070. var i;
  10071. var len;
  10072. var documentData = this.textProperty.currentData;
  10073. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  10074. if (documentData.fc) {
  10075. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  10076. } else {
  10077. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  10078. }
  10079. if (documentData.sc) {
  10080. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  10081. this.layerElement.setAttribute('stroke-width', documentData.sw);
  10082. }
  10083. this.layerElement.setAttribute('font-size', documentData.finalSize);
  10084. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10085. if (fontData.fClass) {
  10086. this.layerElement.setAttribute('class', fontData.fClass);
  10087. } else {
  10088. this.layerElement.setAttribute('font-family', fontData.fFamily);
  10089. var fWeight = documentData.fWeight;
  10090. var fStyle = documentData.fStyle;
  10091. this.layerElement.setAttribute('font-style', fStyle);
  10092. this.layerElement.setAttribute('font-weight', fWeight);
  10093. }
  10094. this.layerElement.setAttribute('aria-label', documentData.t);
  10095. var letters = documentData.l || [];
  10096. var usesGlyphs = !!this.globalData.fontManager.chars;
  10097. len = letters.length;
  10098. var tSpan;
  10099. var matrixHelper = this.mHelper;
  10100. var shapeStr = '';
  10101. var singleShape = this.data.singleShape;
  10102. var xPos = 0;
  10103. var yPos = 0;
  10104. var firstLine = true;
  10105. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10106. if (singleShape && !usesGlyphs && !documentData.sz) {
  10107. var tElement = this.textContainer;
  10108. var justify = 'start';
  10109. switch (documentData.j) {
  10110. case 1:
  10111. justify = 'end';
  10112. break;
  10113. case 2:
  10114. justify = 'middle';
  10115. break;
  10116. default:
  10117. justify = 'start';
  10118. break;
  10119. }
  10120. tElement.setAttribute('text-anchor', justify);
  10121. tElement.setAttribute('letter-spacing', trackingOffset);
  10122. var textContent = this.buildTextContents(documentData.finalText);
  10123. len = textContent.length;
  10124. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10125. for (i = 0; i < len; i += 1) {
  10126. tSpan = this.textSpans[i].span || createNS('tspan');
  10127. tSpan.textContent = textContent[i];
  10128. tSpan.setAttribute('x', 0);
  10129. tSpan.setAttribute('y', yPos);
  10130. tSpan.style.display = 'inherit';
  10131. tElement.appendChild(tSpan);
  10132. if (!this.textSpans[i]) {
  10133. this.textSpans[i] = {
  10134. span: null,
  10135. glyph: null
  10136. };
  10137. }
  10138. this.textSpans[i].span = tSpan;
  10139. yPos += documentData.finalLineHeight;
  10140. }
  10141. this.layerElement.appendChild(tElement);
  10142. } else {
  10143. var cachedSpansLength = this.textSpans.length;
  10144. var charData;
  10145. for (i = 0; i < len; i += 1) {
  10146. if (!this.textSpans[i]) {
  10147. this.textSpans[i] = {
  10148. span: null,
  10149. childSpan: null,
  10150. glyph: null
  10151. };
  10152. }
  10153. if (!usesGlyphs || !singleShape || i === 0) {
  10154. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10155. if (cachedSpansLength <= i) {
  10156. tSpan.setAttribute('stroke-linecap', 'butt');
  10157. tSpan.setAttribute('stroke-linejoin', 'round');
  10158. tSpan.setAttribute('stroke-miterlimit', '4');
  10159. this.textSpans[i].span = tSpan;
  10160. if (usesGlyphs) {
  10161. var childSpan = createNS('g');
  10162. tSpan.appendChild(childSpan);
  10163. this.textSpans[i].childSpan = childSpan;
  10164. }
  10165. this.textSpans[i].span = tSpan;
  10166. this.layerElement.appendChild(tSpan);
  10167. }
  10168. tSpan.style.display = 'inherit';
  10169. }
  10170. matrixHelper.reset();
  10171. if (singleShape) {
  10172. if (letters[i].n) {
  10173. xPos = -trackingOffset;
  10174. yPos += documentData.yOffset;
  10175. yPos += firstLine ? 1 : 0;
  10176. firstLine = false;
  10177. }
  10178. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10179. xPos += letters[i].l || 0;
  10180. // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10181. xPos += trackingOffset;
  10182. }
  10183. if (usesGlyphs) {
  10184. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  10185. var glyphElement;
  10186. // t === 1 means the character has been replaced with an animated shaped
  10187. if (charData.t === 1) {
  10188. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10189. } else {
  10190. var data = emptyShapeData;
  10191. if (charData.data && charData.data.shapes) {
  10192. data = this.buildShapeData(charData.data, documentData.finalSize);
  10193. }
  10194. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10195. }
  10196. if (this.textSpans[i].glyph) {
  10197. var glyph = this.textSpans[i].glyph;
  10198. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10199. glyph.destroy();
  10200. }
  10201. this.textSpans[i].glyph = glyphElement;
  10202. glyphElement._debug = true;
  10203. glyphElement.prepareFrame(0);
  10204. glyphElement.renderFrame();
  10205. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
  10206. // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10207. // this might have issues with strokes and might need a different solution
  10208. if (charData.t === 1) {
  10209. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10210. }
  10211. } else {
  10212. if (singleShape) {
  10213. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10214. }
  10215. tSpan.textContent = letters[i].val;
  10216. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10217. }
  10218. //
  10219. }
  10220. if (singleShape && tSpan) {
  10221. tSpan.setAttribute('d', shapeStr);
  10222. }
  10223. }
  10224. while (i < this.textSpans.length) {
  10225. this.textSpans[i].span.style.display = 'none';
  10226. i += 1;
  10227. }
  10228. this._sizeChanged = true;
  10229. };
  10230. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10231. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10232. this.renderInnerContent();
  10233. if (this._sizeChanged) {
  10234. this._sizeChanged = false;
  10235. var textBox = this.layerElement.getBBox();
  10236. this.bbox = {
  10237. top: textBox.y,
  10238. left: textBox.x,
  10239. width: textBox.width,
  10240. height: textBox.height
  10241. };
  10242. }
  10243. return this.bbox;
  10244. };
  10245. SVGTextLottieElement.prototype.getValue = function () {
  10246. var i;
  10247. var len = this.textSpans.length;
  10248. var glyphElement;
  10249. this.renderedFrame = this.comp.renderedFrame;
  10250. for (i = 0; i < len; i += 1) {
  10251. glyphElement = this.textSpans[i].glyph;
  10252. if (glyphElement) {
  10253. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10254. if (glyphElement._mdf) {
  10255. this._mdf = true;
  10256. }
  10257. }
  10258. }
  10259. };
  10260. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10261. this.validateText();
  10262. if (!this.data.singleShape || this._mdf) {
  10263. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10264. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10265. this._sizeChanged = true;
  10266. var i;
  10267. var len;
  10268. var renderedLetters = this.textAnimator.renderedLetters;
  10269. var letters = this.textProperty.currentData.l;
  10270. len = letters.length;
  10271. var renderedLetter;
  10272. var textSpan;
  10273. var glyphElement;
  10274. for (i = 0; i < len; i += 1) {
  10275. if (!letters[i].n) {
  10276. renderedLetter = renderedLetters[i];
  10277. textSpan = this.textSpans[i].span;
  10278. glyphElement = this.textSpans[i].glyph;
  10279. if (glyphElement) {
  10280. glyphElement.renderFrame();
  10281. }
  10282. if (renderedLetter._mdf.m) {
  10283. textSpan.setAttribute('transform', renderedLetter.m);
  10284. }
  10285. if (renderedLetter._mdf.o) {
  10286. textSpan.setAttribute('opacity', renderedLetter.o);
  10287. }
  10288. if (renderedLetter._mdf.sw) {
  10289. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10290. }
  10291. if (renderedLetter._mdf.sc) {
  10292. textSpan.setAttribute('stroke', renderedLetter.sc);
  10293. }
  10294. if (renderedLetter._mdf.fc) {
  10295. textSpan.setAttribute('fill', renderedLetter.fc);
  10296. }
  10297. }
  10298. }
  10299. }
  10300. }
  10301. };
  10302. function ISolidElement(data, globalData, comp) {
  10303. this.initElement(data, globalData, comp);
  10304. }
  10305. extendPrototype([IImageElement], ISolidElement);
  10306. ISolidElement.prototype.createContent = function () {
  10307. var rect = createNS('rect');
  10308. /// /rect.style.width = this.data.sw;
  10309. /// /rect.style.height = this.data.sh;
  10310. /// /rect.style.fill = this.data.sc;
  10311. rect.setAttribute('width', this.data.sw);
  10312. rect.setAttribute('height', this.data.sh);
  10313. rect.setAttribute('fill', this.data.sc);
  10314. this.layerElement.appendChild(rect);
  10315. };
  10316. function NullElement(data, globalData, comp) {
  10317. this.initFrame();
  10318. this.initBaseData(data, globalData, comp);
  10319. this.initFrame();
  10320. this.initTransform(data, globalData, comp);
  10321. this.initHierarchy();
  10322. }
  10323. NullElement.prototype.prepareFrame = function (num) {
  10324. this.prepareProperties(num, true);
  10325. };
  10326. NullElement.prototype.renderFrame = function () {};
  10327. NullElement.prototype.getBaseElement = function () {
  10328. return null;
  10329. };
  10330. NullElement.prototype.destroy = function () {};
  10331. NullElement.prototype.sourceRectAtTime = function () {};
  10332. NullElement.prototype.hide = function () {};
  10333. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10334. function SVGRendererBase() {}
  10335. extendPrototype([BaseRenderer], SVGRendererBase);
  10336. SVGRendererBase.prototype.createNull = function (data) {
  10337. return new NullElement(data, this.globalData, this);
  10338. };
  10339. SVGRendererBase.prototype.createShape = function (data) {
  10340. return new SVGShapeElement(data, this.globalData, this);
  10341. };
  10342. SVGRendererBase.prototype.createText = function (data) {
  10343. return new SVGTextLottieElement(data, this.globalData, this);
  10344. };
  10345. SVGRendererBase.prototype.createImage = function (data) {
  10346. return new IImageElement(data, this.globalData, this);
  10347. };
  10348. SVGRendererBase.prototype.createSolid = function (data) {
  10349. return new ISolidElement(data, this.globalData, this);
  10350. };
  10351. SVGRendererBase.prototype.configAnimation = function (animData) {
  10352. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10353. this.svgElement.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  10354. if (this.renderConfig.viewBoxSize) {
  10355. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10356. } else {
  10357. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10358. }
  10359. if (!this.renderConfig.viewBoxOnly) {
  10360. this.svgElement.setAttribute('width', animData.w);
  10361. this.svgElement.setAttribute('height', animData.h);
  10362. this.svgElement.style.width = '100%';
  10363. this.svgElement.style.height = '100%';
  10364. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10365. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10366. }
  10367. if (this.renderConfig.width) {
  10368. this.svgElement.setAttribute('width', this.renderConfig.width);
  10369. }
  10370. if (this.renderConfig.height) {
  10371. this.svgElement.setAttribute('height', this.renderConfig.height);
  10372. }
  10373. if (this.renderConfig.className) {
  10374. this.svgElement.setAttribute('class', this.renderConfig.className);
  10375. }
  10376. if (this.renderConfig.id) {
  10377. this.svgElement.setAttribute('id', this.renderConfig.id);
  10378. }
  10379. if (this.renderConfig.focusable !== undefined) {
  10380. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10381. }
  10382. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio);
  10383. // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10384. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10385. this.animationItem.wrapper.appendChild(this.svgElement);
  10386. // Mask animation
  10387. var defs = this.globalData.defs;
  10388. this.setupGlobalData(animData, defs);
  10389. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10390. this.data = animData;
  10391. var maskElement = createNS('clipPath');
  10392. var rect = createNS('rect');
  10393. rect.setAttribute('width', animData.w);
  10394. rect.setAttribute('height', animData.h);
  10395. rect.setAttribute('x', 0);
  10396. rect.setAttribute('y', 0);
  10397. var maskId = createElementID();
  10398. maskElement.setAttribute('id', maskId);
  10399. maskElement.appendChild(rect);
  10400. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10401. defs.appendChild(maskElement);
  10402. this.layers = animData.layers;
  10403. this.elements = createSizedArray(animData.layers.length);
  10404. };
  10405. SVGRendererBase.prototype.destroy = function () {
  10406. if (this.animationItem.wrapper) {
  10407. this.animationItem.wrapper.innerText = '';
  10408. }
  10409. this.layerElement = null;
  10410. this.globalData.defs = null;
  10411. var i;
  10412. var len = this.layers ? this.layers.length : 0;
  10413. for (i = 0; i < len; i += 1) {
  10414. if (this.elements[i] && this.elements[i].destroy) {
  10415. this.elements[i].destroy();
  10416. }
  10417. }
  10418. this.elements.length = 0;
  10419. this.destroyed = true;
  10420. this.animationItem = null;
  10421. };
  10422. SVGRendererBase.prototype.updateContainerSize = function () {};
  10423. SVGRendererBase.prototype.findIndexByInd = function (ind) {
  10424. var i = 0;
  10425. var len = this.layers.length;
  10426. for (i = 0; i < len; i += 1) {
  10427. if (this.layers[i].ind === ind) {
  10428. return i;
  10429. }
  10430. }
  10431. return -1;
  10432. };
  10433. SVGRendererBase.prototype.buildItem = function (pos) {
  10434. var elements = this.elements;
  10435. if (elements[pos] || this.layers[pos].ty === 99) {
  10436. return;
  10437. }
  10438. elements[pos] = true;
  10439. var element = this.createItem(this.layers[pos]);
  10440. elements[pos] = element;
  10441. if (getExpressionsPlugin()) {
  10442. if (this.layers[pos].ty === 0) {
  10443. this.globalData.projectInterface.registerComposition(element);
  10444. }
  10445. element.initExpressions();
  10446. }
  10447. this.appendElementInPos(element, pos);
  10448. if (this.layers[pos].tt) {
  10449. var elementIndex = 'tp' in this.layers[pos] ? this.findIndexByInd(this.layers[pos].tp) : pos - 1;
  10450. if (elementIndex === -1) {
  10451. return;
  10452. }
  10453. if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
  10454. this.buildItem(elementIndex);
  10455. this.addPendingElement(element);
  10456. } else {
  10457. var matteElement = elements[elementIndex];
  10458. var matteMask = matteElement.getMatte(this.layers[pos].tt);
  10459. element.setMatte(matteMask);
  10460. }
  10461. }
  10462. };
  10463. SVGRendererBase.prototype.checkPendingElements = function () {
  10464. while (this.pendingElements.length) {
  10465. var element = this.pendingElements.pop();
  10466. element.checkParenting();
  10467. if (element.data.tt) {
  10468. var i = 0;
  10469. var len = this.elements.length;
  10470. while (i < len) {
  10471. if (this.elements[i] === element) {
  10472. var elementIndex = 'tp' in element.data ? this.findIndexByInd(element.data.tp) : i - 1;
  10473. var matteElement = this.elements[elementIndex];
  10474. var matteMask = matteElement.getMatte(this.layers[i].tt);
  10475. element.setMatte(matteMask);
  10476. break;
  10477. }
  10478. i += 1;
  10479. }
  10480. }
  10481. }
  10482. };
  10483. SVGRendererBase.prototype.renderFrame = function (num) {
  10484. if (this.renderedFrame === num || this.destroyed) {
  10485. return;
  10486. }
  10487. if (num === null) {
  10488. num = this.renderedFrame;
  10489. } else {
  10490. this.renderedFrame = num;
  10491. }
  10492. // console.log('-------');
  10493. // console.log('FRAME ',num);
  10494. this.globalData.frameNum = num;
  10495. this.globalData.frameId += 1;
  10496. this.globalData.projectInterface.currentFrame = num;
  10497. this.globalData._mdf = false;
  10498. var i;
  10499. var len = this.layers.length;
  10500. if (!this.completeLayers) {
  10501. this.checkLayers(num);
  10502. }
  10503. for (i = len - 1; i >= 0; i -= 1) {
  10504. if (this.completeLayers || this.elements[i]) {
  10505. this.elements[i].prepareFrame(num - this.layers[i].st);
  10506. }
  10507. }
  10508. if (this.globalData._mdf) {
  10509. for (i = 0; i < len; i += 1) {
  10510. if (this.completeLayers || this.elements[i]) {
  10511. this.elements[i].renderFrame();
  10512. }
  10513. }
  10514. }
  10515. };
  10516. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10517. var newElement = element.getBaseElement();
  10518. if (!newElement) {
  10519. return;
  10520. }
  10521. var i = 0;
  10522. var nextElement;
  10523. while (i < pos) {
  10524. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10525. nextElement = this.elements[i].getBaseElement();
  10526. }
  10527. i += 1;
  10528. }
  10529. if (nextElement) {
  10530. this.layerElement.insertBefore(newElement, nextElement);
  10531. } else {
  10532. this.layerElement.appendChild(newElement);
  10533. }
  10534. };
  10535. SVGRendererBase.prototype.hide = function () {
  10536. this.layerElement.style.display = 'none';
  10537. };
  10538. SVGRendererBase.prototype.show = function () {
  10539. this.layerElement.style.display = 'block';
  10540. };
  10541. function ICompElement() {}
  10542. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10543. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10544. this.initFrame();
  10545. this.initBaseData(data, globalData, comp);
  10546. this.initTransform(data, globalData, comp);
  10547. this.initRenderable();
  10548. this.initHierarchy();
  10549. this.initRendererElement();
  10550. this.createContainerElements();
  10551. this.createRenderableComponents();
  10552. if (this.data.xt || !globalData.progressiveLoad) {
  10553. this.buildAllItems();
  10554. }
  10555. this.hide();
  10556. };
  10557. /* ICompElement.prototype.hide = function(){
  10558. if(!this.hidden){
  10559. this.hideElement();
  10560. var i,len = this.elements.length;
  10561. for( i = 0; i < len; i+=1 ){
  10562. if(this.elements[i]){
  10563. this.elements[i].hide();
  10564. }
  10565. }
  10566. }
  10567. }; */
  10568. ICompElement.prototype.prepareFrame = function (num) {
  10569. this._mdf = false;
  10570. this.prepareRenderableFrame(num);
  10571. this.prepareProperties(num, this.isInRange);
  10572. if (!this.isInRange && !this.data.xt) {
  10573. return;
  10574. }
  10575. if (!this.tm._placeholder) {
  10576. var timeRemapped = this.tm.v;
  10577. if (timeRemapped === this.data.op) {
  10578. timeRemapped = this.data.op - 1;
  10579. }
  10580. this.renderedFrame = timeRemapped;
  10581. } else {
  10582. this.renderedFrame = num / this.data.sr;
  10583. }
  10584. var i;
  10585. var len = this.elements.length;
  10586. if (!this.completeLayers) {
  10587. this.checkLayers(this.renderedFrame);
  10588. }
  10589. // This iteration needs to be backwards because of how expressions connect between each other
  10590. for (i = len - 1; i >= 0; i -= 1) {
  10591. if (this.completeLayers || this.elements[i]) {
  10592. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10593. if (this.elements[i]._mdf) {
  10594. this._mdf = true;
  10595. }
  10596. }
  10597. }
  10598. };
  10599. ICompElement.prototype.renderInnerContent = function () {
  10600. var i;
  10601. var len = this.layers.length;
  10602. for (i = 0; i < len; i += 1) {
  10603. if (this.completeLayers || this.elements[i]) {
  10604. this.elements[i].renderFrame();
  10605. }
  10606. }
  10607. };
  10608. ICompElement.prototype.setElements = function (elems) {
  10609. this.elements = elems;
  10610. };
  10611. ICompElement.prototype.getElements = function () {
  10612. return this.elements;
  10613. };
  10614. ICompElement.prototype.destroyElements = function () {
  10615. var i;
  10616. var len = this.layers.length;
  10617. for (i = 0; i < len; i += 1) {
  10618. if (this.elements[i]) {
  10619. this.elements[i].destroy();
  10620. }
  10621. }
  10622. };
  10623. ICompElement.prototype.destroy = function () {
  10624. this.destroyElements();
  10625. this.destroyBaseElement();
  10626. };
  10627. function SVGCompElement(data, globalData, comp) {
  10628. this.layers = data.layers;
  10629. this.supports3d = true;
  10630. this.completeLayers = false;
  10631. this.pendingElements = [];
  10632. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10633. this.initElement(data, globalData, comp);
  10634. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  10635. _placeholder: true
  10636. };
  10637. }
  10638. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10639. SVGCompElement.prototype.createComp = function (data) {
  10640. return new SVGCompElement(data, this.globalData, this);
  10641. };
  10642. function SVGRenderer(animationItem, config) {
  10643. this.animationItem = animationItem;
  10644. this.layers = null;
  10645. this.renderedFrame = -1;
  10646. this.svgElement = createNS('svg');
  10647. var ariaLabel = '';
  10648. if (config && config.title) {
  10649. var titleElement = createNS('title');
  10650. var titleId = createElementID();
  10651. titleElement.setAttribute('id', titleId);
  10652. titleElement.textContent = config.title;
  10653. this.svgElement.appendChild(titleElement);
  10654. ariaLabel += titleId;
  10655. }
  10656. if (config && config.description) {
  10657. var descElement = createNS('desc');
  10658. var descId = createElementID();
  10659. descElement.setAttribute('id', descId);
  10660. descElement.textContent = config.description;
  10661. this.svgElement.appendChild(descElement);
  10662. ariaLabel += ' ' + descId;
  10663. }
  10664. if (ariaLabel) {
  10665. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10666. }
  10667. var defs = createNS('defs');
  10668. this.svgElement.appendChild(defs);
  10669. var maskElement = createNS('g');
  10670. this.svgElement.appendChild(maskElement);
  10671. this.layerElement = maskElement;
  10672. this.renderConfig = {
  10673. preserveAspectRatio: config && config.preserveAspectRatio || 'xMidYMid meet',
  10674. imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || 'xMidYMid slice',
  10675. contentVisibility: config && config.contentVisibility || 'visible',
  10676. progressiveLoad: config && config.progressiveLoad || false,
  10677. hideOnTransparent: !(config && config.hideOnTransparent === false),
  10678. viewBoxOnly: config && config.viewBoxOnly || false,
  10679. viewBoxSize: config && config.viewBoxSize || false,
  10680. className: config && config.className || '',
  10681. id: config && config.id || '',
  10682. focusable: config && config.focusable,
  10683. filterSize: {
  10684. width: config && config.filterSize && config.filterSize.width || '100%',
  10685. height: config && config.filterSize && config.filterSize.height || '100%',
  10686. x: config && config.filterSize && config.filterSize.x || '0%',
  10687. y: config && config.filterSize && config.filterSize.y || '0%'
  10688. },
  10689. width: config && config.width,
  10690. height: config && config.height,
  10691. runExpressions: !config || config.runExpressions === undefined || config.runExpressions
  10692. };
  10693. this.globalData = {
  10694. _mdf: false,
  10695. frameNum: -1,
  10696. defs: defs,
  10697. renderConfig: this.renderConfig
  10698. };
  10699. this.elements = [];
  10700. this.pendingElements = [];
  10701. this.destroyed = false;
  10702. this.rendererType = 'svg';
  10703. }
  10704. extendPrototype([SVGRendererBase], SVGRenderer);
  10705. SVGRenderer.prototype.createComp = function (data) {
  10706. return new SVGCompElement(data, this.globalData, this);
  10707. };
  10708. var registeredEffects = {};
  10709. function CVEffects(elem) {
  10710. var i;
  10711. var len = elem.data.ef ? elem.data.ef.length : 0;
  10712. this.filters = [];
  10713. var filterManager;
  10714. for (i = 0; i < len; i += 1) {
  10715. filterManager = null;
  10716. var type = elem.data.ef[i].ty;
  10717. if (registeredEffects[type]) {
  10718. var Effect = registeredEffects[type].effect;
  10719. filterManager = new Effect(elem.effectsManager.effectElements[i], elem);
  10720. }
  10721. if (filterManager) {
  10722. this.filters.push(filterManager);
  10723. }
  10724. }
  10725. if (this.filters.length) {
  10726. elem.addRenderableComponent(this);
  10727. }
  10728. }
  10729. CVEffects.prototype.renderFrame = function (_isFirstFrame) {
  10730. var i;
  10731. var len = this.filters.length;
  10732. for (i = 0; i < len; i += 1) {
  10733. this.filters[i].renderFrame(_isFirstFrame);
  10734. }
  10735. };
  10736. CVEffects.prototype.getEffects = function (type) {
  10737. var i;
  10738. var len = this.filters.length;
  10739. var effects = [];
  10740. for (i = 0; i < len; i += 1) {
  10741. if (this.filters[i].type === type) {
  10742. effects.push(this.filters[i]);
  10743. }
  10744. }
  10745. return effects;
  10746. };
  10747. function registerEffect(id, effect) {
  10748. registeredEffects[id] = {
  10749. effect: effect
  10750. };
  10751. }
  10752. function HBaseElement() {}
  10753. HBaseElement.prototype = {
  10754. checkBlendMode: function checkBlendMode() {},
  10755. initRendererElement: function initRendererElement() {
  10756. this.baseElement = createTag(this.data.tg || 'div');
  10757. if (this.data.hasMask) {
  10758. this.svgElement = createNS('svg');
  10759. this.layerElement = createNS('g');
  10760. this.maskedElement = this.layerElement;
  10761. this.svgElement.appendChild(this.layerElement);
  10762. this.baseElement.appendChild(this.svgElement);
  10763. } else {
  10764. this.layerElement = this.baseElement;
  10765. }
  10766. styleDiv(this.baseElement);
  10767. },
  10768. createContainerElements: function createContainerElements() {
  10769. this.renderableEffectsManager = new CVEffects(this);
  10770. this.transformedElement = this.baseElement;
  10771. this.maskedElement = this.layerElement;
  10772. if (this.data.ln) {
  10773. this.layerElement.setAttribute('id', this.data.ln);
  10774. }
  10775. if (this.data.cl) {
  10776. this.layerElement.setAttribute('class', this.data.cl);
  10777. }
  10778. if (this.data.bm !== 0) {
  10779. this.setBlendMode();
  10780. }
  10781. },
  10782. renderElement: function renderElement() {
  10783. var transformedElementStyle = this.transformedElement ? this.transformedElement.style : {};
  10784. if (this.finalTransform._matMdf) {
  10785. var matrixValue = this.finalTransform.mat.toCSS();
  10786. transformedElementStyle.transform = matrixValue;
  10787. transformedElementStyle.webkitTransform = matrixValue;
  10788. }
  10789. if (this.finalTransform._opMdf) {
  10790. transformedElementStyle.opacity = this.finalTransform.mProp.o.v;
  10791. }
  10792. },
  10793. renderFrame: function renderFrame() {
  10794. // If it is exported as hidden (data.hd === true) no need to render
  10795. // If it is not visible no need to render
  10796. if (this.data.hd || this.hidden) {
  10797. return;
  10798. }
  10799. this.renderTransform();
  10800. this.renderRenderable();
  10801. this.renderElement();
  10802. this.renderInnerContent();
  10803. if (this._isFirstFrame) {
  10804. this._isFirstFrame = false;
  10805. }
  10806. },
  10807. destroy: function destroy() {
  10808. this.layerElement = null;
  10809. this.transformedElement = null;
  10810. if (this.matteElement) {
  10811. this.matteElement = null;
  10812. }
  10813. if (this.maskManager) {
  10814. this.maskManager.destroy();
  10815. this.maskManager = null;
  10816. }
  10817. },
  10818. createRenderableComponents: function createRenderableComponents() {
  10819. this.maskManager = new MaskElement(this.data, this, this.globalData);
  10820. },
  10821. addEffects: function addEffects() {},
  10822. setMatte: function setMatte() {}
  10823. };
  10824. HBaseElement.prototype.getBaseElement = SVGBaseElement.prototype.getBaseElement;
  10825. HBaseElement.prototype.destroyBaseElement = HBaseElement.prototype.destroy;
  10826. HBaseElement.prototype.buildElementParenting = BaseRenderer.prototype.buildElementParenting;
  10827. function HSolidElement(data, globalData, comp) {
  10828. this.initElement(data, globalData, comp);
  10829. }
  10830. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], HSolidElement);
  10831. HSolidElement.prototype.createContent = function () {
  10832. var rect;
  10833. if (this.data.hasMask) {
  10834. rect = createNS('rect');
  10835. rect.setAttribute('width', this.data.sw);
  10836. rect.setAttribute('height', this.data.sh);
  10837. rect.setAttribute('fill', this.data.sc);
  10838. this.svgElement.setAttribute('width', this.data.sw);
  10839. this.svgElement.setAttribute('height', this.data.sh);
  10840. } else {
  10841. rect = createTag('div');
  10842. rect.style.width = this.data.sw + 'px';
  10843. rect.style.height = this.data.sh + 'px';
  10844. rect.style.backgroundColor = this.data.sc;
  10845. }
  10846. this.layerElement.appendChild(rect);
  10847. };
  10848. function HShapeElement(data, globalData, comp) {
  10849. // List of drawable elements
  10850. this.shapes = [];
  10851. // Full shape data
  10852. this.shapesData = data.shapes;
  10853. // List of styles that will be applied to shapes
  10854. this.stylesList = [];
  10855. // List of modifiers that will be applied to shapes
  10856. this.shapeModifiers = [];
  10857. // List of items in shape tree
  10858. this.itemsData = [];
  10859. // List of items in previous shape tree
  10860. this.processedElements = [];
  10861. // List of animated components
  10862. this.animatedContents = [];
  10863. this.shapesContainer = createNS('g');
  10864. this.initElement(data, globalData, comp);
  10865. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  10866. // List of elements that have been created
  10867. this.prevViewData = [];
  10868. this.currentBBox = {
  10869. x: 999999,
  10870. y: -999999,
  10871. h: 0,
  10872. w: 0
  10873. };
  10874. }
  10875. extendPrototype([BaseElement, TransformElement, HSolidElement, SVGShapeElement, HBaseElement, HierarchyElement, FrameElement, RenderableElement], HShapeElement);
  10876. HShapeElement.prototype._renderShapeFrame = HShapeElement.prototype.renderInnerContent;
  10877. HShapeElement.prototype.createContent = function () {
  10878. var cont;
  10879. this.baseElement.style.fontSize = 0;
  10880. if (this.data.hasMask) {
  10881. this.layerElement.appendChild(this.shapesContainer);
  10882. cont = this.svgElement;
  10883. } else {
  10884. cont = createNS('svg');
  10885. var size = this.comp.data ? this.comp.data : this.globalData.compSize;
  10886. cont.setAttribute('width', size.w);
  10887. cont.setAttribute('height', size.h);
  10888. cont.appendChild(this.shapesContainer);
  10889. this.layerElement.appendChild(cont);
  10890. }
  10891. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.shapesContainer, 0, [], true);
  10892. this.filterUniqueShapes();
  10893. this.shapeCont = cont;
  10894. };
  10895. HShapeElement.prototype.getTransformedPoint = function (transformers, point) {
  10896. var i;
  10897. var len = transformers.length;
  10898. for (i = 0; i < len; i += 1) {
  10899. point = transformers[i].mProps.v.applyToPointArray(point[0], point[1], 0);
  10900. }
  10901. return point;
  10902. };
  10903. HShapeElement.prototype.calculateShapeBoundingBox = function (item, boundingBox) {
  10904. var shape = item.sh.v;
  10905. var transformers = item.transformers;
  10906. var i;
  10907. var len = shape._length;
  10908. var vPoint;
  10909. var oPoint;
  10910. var nextIPoint;
  10911. var nextVPoint;
  10912. if (len <= 1) {
  10913. return;
  10914. }
  10915. for (i = 0; i < len - 1; i += 1) {
  10916. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  10917. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  10918. nextIPoint = this.getTransformedPoint(transformers, shape.i[i + 1]);
  10919. nextVPoint = this.getTransformedPoint(transformers, shape.v[i + 1]);
  10920. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  10921. }
  10922. if (shape.c) {
  10923. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  10924. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  10925. nextIPoint = this.getTransformedPoint(transformers, shape.i[0]);
  10926. nextVPoint = this.getTransformedPoint(transformers, shape.v[0]);
  10927. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  10928. }
  10929. };
  10930. HShapeElement.prototype.checkBounds = function (vPoint, oPoint, nextIPoint, nextVPoint, boundingBox) {
  10931. this.getBoundsOfCurve(vPoint, oPoint, nextIPoint, nextVPoint);
  10932. var bounds = this.shapeBoundingBox;
  10933. boundingBox.x = bmMin(bounds.left, boundingBox.x);
  10934. boundingBox.xMax = bmMax(bounds.right, boundingBox.xMax);
  10935. boundingBox.y = bmMin(bounds.top, boundingBox.y);
  10936. boundingBox.yMax = bmMax(bounds.bottom, boundingBox.yMax);
  10937. };
  10938. HShapeElement.prototype.shapeBoundingBox = {
  10939. left: 0,
  10940. right: 0,
  10941. top: 0,
  10942. bottom: 0
  10943. };
  10944. HShapeElement.prototype.tempBoundingBox = {
  10945. x: 0,
  10946. xMax: 0,
  10947. y: 0,
  10948. yMax: 0,
  10949. width: 0,
  10950. height: 0
  10951. };
  10952. HShapeElement.prototype.getBoundsOfCurve = function (p0, p1, p2, p3) {
  10953. var bounds = [[p0[0], p3[0]], [p0[1], p3[1]]];
  10954. for (var a, b, c, t, b2ac, t1, t2, i = 0; i < 2; ++i) {
  10955. // eslint-disable-line no-plusplus
  10956. b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
  10957. a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
  10958. c = 3 * p1[i] - 3 * p0[i];
  10959. b |= 0; // eslint-disable-line no-bitwise
  10960. a |= 0; // eslint-disable-line no-bitwise
  10961. c |= 0; // eslint-disable-line no-bitwise
  10962. if (a === 0 && b === 0) {
  10963. //
  10964. } else if (a === 0) {
  10965. t = -c / b;
  10966. if (t > 0 && t < 1) {
  10967. bounds[i].push(this.calculateF(t, p0, p1, p2, p3, i));
  10968. }
  10969. } else {
  10970. b2ac = b * b - 4 * c * a;
  10971. if (b2ac >= 0) {
  10972. t1 = (-b + bmSqrt(b2ac)) / (2 * a);
  10973. if (t1 > 0 && t1 < 1) bounds[i].push(this.calculateF(t1, p0, p1, p2, p3, i));
  10974. t2 = (-b - bmSqrt(b2ac)) / (2 * a);
  10975. if (t2 > 0 && t2 < 1) bounds[i].push(this.calculateF(t2, p0, p1, p2, p3, i));
  10976. }
  10977. }
  10978. }
  10979. this.shapeBoundingBox.left = bmMin.apply(null, bounds[0]);
  10980. this.shapeBoundingBox.top = bmMin.apply(null, bounds[1]);
  10981. this.shapeBoundingBox.right = bmMax.apply(null, bounds[0]);
  10982. this.shapeBoundingBox.bottom = bmMax.apply(null, bounds[1]);
  10983. };
  10984. HShapeElement.prototype.calculateF = function (t, p0, p1, p2, p3, i) {
  10985. return bmPow(1 - t, 3) * p0[i] + 3 * bmPow(1 - t, 2) * t * p1[i] + 3 * (1 - t) * bmPow(t, 2) * p2[i] + bmPow(t, 3) * p3[i];
  10986. };
  10987. HShapeElement.prototype.calculateBoundingBox = function (itemsData, boundingBox) {
  10988. var i;
  10989. var len = itemsData.length;
  10990. for (i = 0; i < len; i += 1) {
  10991. if (itemsData[i] && itemsData[i].sh) {
  10992. this.calculateShapeBoundingBox(itemsData[i], boundingBox);
  10993. } else if (itemsData[i] && itemsData[i].it) {
  10994. this.calculateBoundingBox(itemsData[i].it, boundingBox);
  10995. } else if (itemsData[i] && itemsData[i].style && itemsData[i].w) {
  10996. this.expandStrokeBoundingBox(itemsData[i].w, boundingBox);
  10997. }
  10998. }
  10999. };
  11000. HShapeElement.prototype.expandStrokeBoundingBox = function (widthProperty, boundingBox) {
  11001. var width = 0;
  11002. if (widthProperty.keyframes) {
  11003. for (var i = 0; i < widthProperty.keyframes.length; i += 1) {
  11004. var kfw = widthProperty.keyframes[i].s;
  11005. if (kfw > width) {
  11006. width = kfw;
  11007. }
  11008. }
  11009. width *= widthProperty.mult;
  11010. } else {
  11011. width = widthProperty.v * widthProperty.mult;
  11012. }
  11013. boundingBox.x -= width;
  11014. boundingBox.xMax += width;
  11015. boundingBox.y -= width;
  11016. boundingBox.yMax += width;
  11017. };
  11018. HShapeElement.prototype.currentBoxContains = function (box) {
  11019. return this.currentBBox.x <= box.x && this.currentBBox.y <= box.y && this.currentBBox.width + this.currentBBox.x >= box.x + box.width && this.currentBBox.height + this.currentBBox.y >= box.y + box.height;
  11020. };
  11021. HShapeElement.prototype.renderInnerContent = function () {
  11022. this._renderShapeFrame();
  11023. if (!this.hidden && (this._isFirstFrame || this._mdf)) {
  11024. var tempBoundingBox = this.tempBoundingBox;
  11025. var max = 999999;
  11026. tempBoundingBox.x = max;
  11027. tempBoundingBox.xMax = -max;
  11028. tempBoundingBox.y = max;
  11029. tempBoundingBox.yMax = -max;
  11030. this.calculateBoundingBox(this.itemsData, tempBoundingBox);
  11031. tempBoundingBox.width = tempBoundingBox.xMax < tempBoundingBox.x ? 0 : tempBoundingBox.xMax - tempBoundingBox.x;
  11032. tempBoundingBox.height = tempBoundingBox.yMax < tempBoundingBox.y ? 0 : tempBoundingBox.yMax - tempBoundingBox.y;
  11033. // var tempBoundingBox = this.shapeCont.getBBox();
  11034. if (this.currentBoxContains(tempBoundingBox)) {
  11035. return;
  11036. }
  11037. var changed = false;
  11038. if (this.currentBBox.w !== tempBoundingBox.width) {
  11039. this.currentBBox.w = tempBoundingBox.width;
  11040. this.shapeCont.setAttribute('width', tempBoundingBox.width);
  11041. changed = true;
  11042. }
  11043. if (this.currentBBox.h !== tempBoundingBox.height) {
  11044. this.currentBBox.h = tempBoundingBox.height;
  11045. this.shapeCont.setAttribute('height', tempBoundingBox.height);
  11046. changed = true;
  11047. }
  11048. if (changed || this.currentBBox.x !== tempBoundingBox.x || this.currentBBox.y !== tempBoundingBox.y) {
  11049. this.currentBBox.w = tempBoundingBox.width;
  11050. this.currentBBox.h = tempBoundingBox.height;
  11051. this.currentBBox.x = tempBoundingBox.x;
  11052. this.currentBBox.y = tempBoundingBox.y;
  11053. this.shapeCont.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  11054. var shapeStyle = this.shapeCont.style;
  11055. var shapeTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  11056. shapeStyle.transform = shapeTransform;
  11057. shapeStyle.webkitTransform = shapeTransform;
  11058. }
  11059. }
  11060. };
  11061. function HTextElement(data, globalData, comp) {
  11062. this.textSpans = [];
  11063. this.textPaths = [];
  11064. this.currentBBox = {
  11065. x: 999999,
  11066. y: -999999,
  11067. h: 0,
  11068. w: 0
  11069. };
  11070. this.renderType = 'svg';
  11071. this.isMasked = false;
  11072. this.initElement(data, globalData, comp);
  11073. }
  11074. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], HTextElement);
  11075. HTextElement.prototype.createContent = function () {
  11076. this.isMasked = this.checkMasks();
  11077. if (this.isMasked) {
  11078. this.renderType = 'svg';
  11079. this.compW = this.comp.data.w;
  11080. this.compH = this.comp.data.h;
  11081. this.svgElement.setAttribute('width', this.compW);
  11082. this.svgElement.setAttribute('height', this.compH);
  11083. var g = createNS('g');
  11084. this.maskedElement.appendChild(g);
  11085. this.innerElem = g;
  11086. } else {
  11087. this.renderType = 'html';
  11088. this.innerElem = this.layerElement;
  11089. }
  11090. this.checkParenting();
  11091. };
  11092. HTextElement.prototype.buildNewText = function () {
  11093. var documentData = this.textProperty.currentData;
  11094. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  11095. var innerElemStyle = this.innerElem.style;
  11096. var textColor = documentData.fc ? this.buildColor(documentData.fc) : 'rgba(0,0,0,0)';
  11097. innerElemStyle.fill = textColor;
  11098. innerElemStyle.color = textColor;
  11099. if (documentData.sc) {
  11100. innerElemStyle.stroke = this.buildColor(documentData.sc);
  11101. innerElemStyle.strokeWidth = documentData.sw + 'px';
  11102. }
  11103. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  11104. if (!this.globalData.fontManager.chars) {
  11105. innerElemStyle.fontSize = documentData.finalSize + 'px';
  11106. innerElemStyle.lineHeight = documentData.finalSize + 'px';
  11107. if (fontData.fClass) {
  11108. this.innerElem.className = fontData.fClass;
  11109. } else {
  11110. innerElemStyle.fontFamily = fontData.fFamily;
  11111. var fWeight = documentData.fWeight;
  11112. var fStyle = documentData.fStyle;
  11113. innerElemStyle.fontStyle = fStyle;
  11114. innerElemStyle.fontWeight = fWeight;
  11115. }
  11116. }
  11117. var i;
  11118. var len;
  11119. var letters = documentData.l;
  11120. len = letters.length;
  11121. var tSpan;
  11122. var tParent;
  11123. var tCont;
  11124. var matrixHelper = this.mHelper;
  11125. var shapes;
  11126. var shapeStr = '';
  11127. var cnt = 0;
  11128. for (i = 0; i < len; i += 1) {
  11129. if (this.globalData.fontManager.chars) {
  11130. if (!this.textPaths[cnt]) {
  11131. tSpan = createNS('path');
  11132. tSpan.setAttribute('stroke-linecap', lineCapEnum[1]);
  11133. tSpan.setAttribute('stroke-linejoin', lineJoinEnum[2]);
  11134. tSpan.setAttribute('stroke-miterlimit', '4');
  11135. } else {
  11136. tSpan = this.textPaths[cnt];
  11137. }
  11138. if (!this.isMasked) {
  11139. if (this.textSpans[cnt]) {
  11140. tParent = this.textSpans[cnt];
  11141. tCont = tParent.children[0];
  11142. } else {
  11143. tParent = createTag('div');
  11144. tParent.style.lineHeight = 0;
  11145. tCont = createNS('svg');
  11146. tCont.appendChild(tSpan);
  11147. styleDiv(tParent);
  11148. }
  11149. }
  11150. } else if (!this.isMasked) {
  11151. if (this.textSpans[cnt]) {
  11152. tParent = this.textSpans[cnt];
  11153. tSpan = this.textPaths[cnt];
  11154. } else {
  11155. tParent = createTag('span');
  11156. styleDiv(tParent);
  11157. tSpan = createTag('span');
  11158. styleDiv(tSpan);
  11159. tParent.appendChild(tSpan);
  11160. }
  11161. } else {
  11162. tSpan = this.textPaths[cnt] ? this.textPaths[cnt] : createNS('text');
  11163. }
  11164. // tSpan.setAttribute('visibility', 'hidden');
  11165. if (this.globalData.fontManager.chars) {
  11166. var charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  11167. var shapeData;
  11168. if (charData) {
  11169. shapeData = charData.data;
  11170. } else {
  11171. shapeData = null;
  11172. }
  11173. matrixHelper.reset();
  11174. if (shapeData && shapeData.shapes && shapeData.shapes.length) {
  11175. shapes = shapeData.shapes[0].it;
  11176. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  11177. shapeStr = this.createPathShape(matrixHelper, shapes);
  11178. tSpan.setAttribute('d', shapeStr);
  11179. }
  11180. if (!this.isMasked) {
  11181. this.innerElem.appendChild(tParent);
  11182. if (shapeData && shapeData.shapes) {
  11183. // document.body.appendChild is needed to get exact measure of shape
  11184. document.body.appendChild(tCont);
  11185. var boundingBox = tCont.getBBox();
  11186. tCont.setAttribute('width', boundingBox.width + 2);
  11187. tCont.setAttribute('height', boundingBox.height + 2);
  11188. tCont.setAttribute('viewBox', boundingBox.x - 1 + ' ' + (boundingBox.y - 1) + ' ' + (boundingBox.width + 2) + ' ' + (boundingBox.height + 2));
  11189. var tContStyle = tCont.style;
  11190. var tContTranslation = 'translate(' + (boundingBox.x - 1) + 'px,' + (boundingBox.y - 1) + 'px)';
  11191. tContStyle.transform = tContTranslation;
  11192. tContStyle.webkitTransform = tContTranslation;
  11193. letters[i].yOffset = boundingBox.y - 1;
  11194. } else {
  11195. tCont.setAttribute('width', 1);
  11196. tCont.setAttribute('height', 1);
  11197. }
  11198. tParent.appendChild(tCont);
  11199. } else {
  11200. this.innerElem.appendChild(tSpan);
  11201. }
  11202. } else {
  11203. tSpan.textContent = letters[i].val;
  11204. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  11205. if (!this.isMasked) {
  11206. this.innerElem.appendChild(tParent);
  11207. //
  11208. var tStyle = tSpan.style;
  11209. var tSpanTranslation = 'translate3d(0,' + -documentData.finalSize / 1.2 + 'px,0)';
  11210. tStyle.transform = tSpanTranslation;
  11211. tStyle.webkitTransform = tSpanTranslation;
  11212. } else {
  11213. this.innerElem.appendChild(tSpan);
  11214. }
  11215. }
  11216. //
  11217. if (!this.isMasked) {
  11218. this.textSpans[cnt] = tParent;
  11219. } else {
  11220. this.textSpans[cnt] = tSpan;
  11221. }
  11222. this.textSpans[cnt].style.display = 'block';
  11223. this.textPaths[cnt] = tSpan;
  11224. cnt += 1;
  11225. }
  11226. while (cnt < this.textSpans.length) {
  11227. this.textSpans[cnt].style.display = 'none';
  11228. cnt += 1;
  11229. }
  11230. };
  11231. HTextElement.prototype.renderInnerContent = function () {
  11232. this.validateText();
  11233. var svgStyle;
  11234. if (this.data.singleShape) {
  11235. if (!this._isFirstFrame && !this.lettersChangedFlag) {
  11236. return;
  11237. }
  11238. if (this.isMasked && this.finalTransform._matMdf) {
  11239. // Todo Benchmark if using this is better than getBBox
  11240. this.svgElement.setAttribute('viewBox', -this.finalTransform.mProp.p.v[0] + ' ' + -this.finalTransform.mProp.p.v[1] + ' ' + this.compW + ' ' + this.compH);
  11241. svgStyle = this.svgElement.style;
  11242. var translation = 'translate(' + -this.finalTransform.mProp.p.v[0] + 'px,' + -this.finalTransform.mProp.p.v[1] + 'px)';
  11243. svgStyle.transform = translation;
  11244. svgStyle.webkitTransform = translation;
  11245. }
  11246. }
  11247. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  11248. if (!this.lettersChangedFlag && !this.textAnimator.lettersChangedFlag) {
  11249. return;
  11250. }
  11251. var i;
  11252. var len;
  11253. var count = 0;
  11254. var renderedLetters = this.textAnimator.renderedLetters;
  11255. var letters = this.textProperty.currentData.l;
  11256. len = letters.length;
  11257. var renderedLetter;
  11258. var textSpan;
  11259. var textPath;
  11260. for (i = 0; i < len; i += 1) {
  11261. if (letters[i].n) {
  11262. count += 1;
  11263. } else {
  11264. textSpan = this.textSpans[i];
  11265. textPath = this.textPaths[i];
  11266. renderedLetter = renderedLetters[count];
  11267. count += 1;
  11268. if (renderedLetter._mdf.m) {
  11269. if (!this.isMasked) {
  11270. textSpan.style.webkitTransform = renderedLetter.m;
  11271. textSpan.style.transform = renderedLetter.m;
  11272. } else {
  11273. textSpan.setAttribute('transform', renderedLetter.m);
  11274. }
  11275. }
  11276. /// /textSpan.setAttribute('opacity',renderedLetter.o);
  11277. textSpan.style.opacity = renderedLetter.o;
  11278. if (renderedLetter.sw && renderedLetter._mdf.sw) {
  11279. textPath.setAttribute('stroke-width', renderedLetter.sw);
  11280. }
  11281. if (renderedLetter.sc && renderedLetter._mdf.sc) {
  11282. textPath.setAttribute('stroke', renderedLetter.sc);
  11283. }
  11284. if (renderedLetter.fc && renderedLetter._mdf.fc) {
  11285. textPath.setAttribute('fill', renderedLetter.fc);
  11286. textPath.style.color = renderedLetter.fc;
  11287. }
  11288. }
  11289. }
  11290. if (this.innerElem.getBBox && !this.hidden && (this._isFirstFrame || this._mdf)) {
  11291. var boundingBox = this.innerElem.getBBox();
  11292. if (this.currentBBox.w !== boundingBox.width) {
  11293. this.currentBBox.w = boundingBox.width;
  11294. this.svgElement.setAttribute('width', boundingBox.width);
  11295. }
  11296. if (this.currentBBox.h !== boundingBox.height) {
  11297. this.currentBBox.h = boundingBox.height;
  11298. this.svgElement.setAttribute('height', boundingBox.height);
  11299. }
  11300. var margin = 1;
  11301. 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) {
  11302. this.currentBBox.w = boundingBox.width + margin * 2;
  11303. this.currentBBox.h = boundingBox.height + margin * 2;
  11304. this.currentBBox.x = boundingBox.x - margin;
  11305. this.currentBBox.y = boundingBox.y - margin;
  11306. this.svgElement.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  11307. svgStyle = this.svgElement.style;
  11308. var svgTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  11309. svgStyle.transform = svgTransform;
  11310. svgStyle.webkitTransform = svgTransform;
  11311. }
  11312. }
  11313. };
  11314. function HCameraElement(data, globalData, comp) {
  11315. this.initFrame();
  11316. this.initBaseData(data, globalData, comp);
  11317. this.initHierarchy();
  11318. var getProp = PropertyFactory.getProp;
  11319. this.pe = getProp(this, data.pe, 0, 0, this);
  11320. if (data.ks.p.s) {
  11321. this.px = getProp(this, data.ks.p.x, 1, 0, this);
  11322. this.py = getProp(this, data.ks.p.y, 1, 0, this);
  11323. this.pz = getProp(this, data.ks.p.z, 1, 0, this);
  11324. } else {
  11325. this.p = getProp(this, data.ks.p, 1, 0, this);
  11326. }
  11327. if (data.ks.a) {
  11328. this.a = getProp(this, data.ks.a, 1, 0, this);
  11329. }
  11330. if (data.ks.or.k.length && data.ks.or.k[0].to) {
  11331. var i;
  11332. var len = data.ks.or.k.length;
  11333. for (i = 0; i < len; i += 1) {
  11334. data.ks.or.k[i].to = null;
  11335. data.ks.or.k[i].ti = null;
  11336. }
  11337. }
  11338. this.or = getProp(this, data.ks.or, 1, degToRads, this);
  11339. this.or.sh = true;
  11340. this.rx = getProp(this, data.ks.rx, 0, degToRads, this);
  11341. this.ry = getProp(this, data.ks.ry, 0, degToRads, this);
  11342. this.rz = getProp(this, data.ks.rz, 0, degToRads, this);
  11343. this.mat = new Matrix();
  11344. this._prevMat = new Matrix();
  11345. this._isFirstFrame = true;
  11346. // TODO: find a better way to make the HCamera element to be compatible with the LayerInterface and TransformInterface.
  11347. this.finalTransform = {
  11348. mProp: this
  11349. };
  11350. }
  11351. extendPrototype([BaseElement, FrameElement, HierarchyElement], HCameraElement);
  11352. HCameraElement.prototype.setup = function () {
  11353. var i;
  11354. var len = this.comp.threeDElements.length;
  11355. var comp;
  11356. var perspectiveStyle;
  11357. var containerStyle;
  11358. for (i = 0; i < len; i += 1) {
  11359. // [perspectiveElem,container]
  11360. comp = this.comp.threeDElements[i];
  11361. if (comp.type === '3d') {
  11362. perspectiveStyle = comp.perspectiveElem.style;
  11363. containerStyle = comp.container.style;
  11364. var perspective = this.pe.v + 'px';
  11365. var origin = '0px 0px 0px';
  11366. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  11367. perspectiveStyle.perspective = perspective;
  11368. perspectiveStyle.webkitPerspective = perspective;
  11369. containerStyle.transformOrigin = origin;
  11370. containerStyle.mozTransformOrigin = origin;
  11371. containerStyle.webkitTransformOrigin = origin;
  11372. perspectiveStyle.transform = matrix;
  11373. perspectiveStyle.webkitTransform = matrix;
  11374. }
  11375. }
  11376. };
  11377. HCameraElement.prototype.createElements = function () {};
  11378. HCameraElement.prototype.hide = function () {};
  11379. HCameraElement.prototype.renderFrame = function () {
  11380. var _mdf = this._isFirstFrame;
  11381. var i;
  11382. var len;
  11383. if (this.hierarchy) {
  11384. len = this.hierarchy.length;
  11385. for (i = 0; i < len; i += 1) {
  11386. _mdf = this.hierarchy[i].finalTransform.mProp._mdf || _mdf;
  11387. }
  11388. }
  11389. 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) {
  11390. this.mat.reset();
  11391. if (this.hierarchy) {
  11392. len = this.hierarchy.length - 1;
  11393. for (i = len; i >= 0; i -= 1) {
  11394. var mTransf = this.hierarchy[i].finalTransform.mProp;
  11395. this.mat.translate(-mTransf.p.v[0], -mTransf.p.v[1], mTransf.p.v[2]);
  11396. this.mat.rotateX(-mTransf.or.v[0]).rotateY(-mTransf.or.v[1]).rotateZ(mTransf.or.v[2]);
  11397. this.mat.rotateX(-mTransf.rx.v).rotateY(-mTransf.ry.v).rotateZ(mTransf.rz.v);
  11398. this.mat.scale(1 / mTransf.s.v[0], 1 / mTransf.s.v[1], 1 / mTransf.s.v[2]);
  11399. this.mat.translate(mTransf.a.v[0], mTransf.a.v[1], mTransf.a.v[2]);
  11400. }
  11401. }
  11402. if (this.p) {
  11403. this.mat.translate(-this.p.v[0], -this.p.v[1], this.p.v[2]);
  11404. } else {
  11405. this.mat.translate(-this.px.v, -this.py.v, this.pz.v);
  11406. }
  11407. if (this.a) {
  11408. var diffVector;
  11409. if (this.p) {
  11410. 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]];
  11411. } else {
  11412. diffVector = [this.px.v - this.a.v[0], this.py.v - this.a.v[1], this.pz.v - this.a.v[2]];
  11413. }
  11414. var mag = Math.sqrt(Math.pow(diffVector[0], 2) + Math.pow(diffVector[1], 2) + Math.pow(diffVector[2], 2));
  11415. // var lookDir = getNormalizedPoint(getDiffVector(this.a.v,this.p.v));
  11416. var lookDir = [diffVector[0] / mag, diffVector[1] / mag, diffVector[2] / mag];
  11417. var lookLengthOnXZ = Math.sqrt(lookDir[2] * lookDir[2] + lookDir[0] * lookDir[0]);
  11418. var mRotationX = Math.atan2(lookDir[1], lookLengthOnXZ);
  11419. var mRotationY = Math.atan2(lookDir[0], -lookDir[2]);
  11420. this.mat.rotateY(mRotationY).rotateX(-mRotationX);
  11421. }
  11422. this.mat.rotateX(-this.rx.v).rotateY(-this.ry.v).rotateZ(this.rz.v);
  11423. this.mat.rotateX(-this.or.v[0]).rotateY(-this.or.v[1]).rotateZ(this.or.v[2]);
  11424. this.mat.translate(this.globalData.compSize.w / 2, this.globalData.compSize.h / 2, 0);
  11425. this.mat.translate(0, 0, this.pe.v);
  11426. var hasMatrixChanged = !this._prevMat.equals(this.mat);
  11427. if ((hasMatrixChanged || this.pe._mdf) && this.comp.threeDElements) {
  11428. len = this.comp.threeDElements.length;
  11429. var comp;
  11430. var perspectiveStyle;
  11431. var containerStyle;
  11432. for (i = 0; i < len; i += 1) {
  11433. comp = this.comp.threeDElements[i];
  11434. if (comp.type === '3d') {
  11435. if (hasMatrixChanged) {
  11436. var matValue = this.mat.toCSS();
  11437. containerStyle = comp.container.style;
  11438. containerStyle.transform = matValue;
  11439. containerStyle.webkitTransform = matValue;
  11440. }
  11441. if (this.pe._mdf) {
  11442. perspectiveStyle = comp.perspectiveElem.style;
  11443. perspectiveStyle.perspective = this.pe.v + 'px';
  11444. perspectiveStyle.webkitPerspective = this.pe.v + 'px';
  11445. }
  11446. }
  11447. }
  11448. this.mat.clone(this._prevMat);
  11449. }
  11450. }
  11451. this._isFirstFrame = false;
  11452. };
  11453. HCameraElement.prototype.prepareFrame = function (num) {
  11454. this.prepareProperties(num, true);
  11455. };
  11456. HCameraElement.prototype.destroy = function () {};
  11457. HCameraElement.prototype.getBaseElement = function () {
  11458. return null;
  11459. };
  11460. function HImageElement(data, globalData, comp) {
  11461. this.assetData = globalData.getAssetData(data.refId);
  11462. this.initElement(data, globalData, comp);
  11463. }
  11464. extendPrototype([BaseElement, TransformElement, HBaseElement, HSolidElement, HierarchyElement, FrameElement, RenderableElement], HImageElement);
  11465. HImageElement.prototype.createContent = function () {
  11466. var assetPath = this.globalData.getAssetsPath(this.assetData);
  11467. var img = new Image();
  11468. if (this.data.hasMask) {
  11469. this.imageElem = createNS('image');
  11470. this.imageElem.setAttribute('width', this.assetData.w + 'px');
  11471. this.imageElem.setAttribute('height', this.assetData.h + 'px');
  11472. this.imageElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  11473. this.layerElement.appendChild(this.imageElem);
  11474. this.baseElement.setAttribute('width', this.assetData.w);
  11475. this.baseElement.setAttribute('height', this.assetData.h);
  11476. } else {
  11477. this.layerElement.appendChild(img);
  11478. }
  11479. img.crossOrigin = 'anonymous';
  11480. img.src = assetPath;
  11481. if (this.data.ln) {
  11482. this.baseElement.setAttribute('id', this.data.ln);
  11483. }
  11484. };
  11485. function HybridRendererBase(animationItem, config) {
  11486. this.animationItem = animationItem;
  11487. this.layers = null;
  11488. this.renderedFrame = -1;
  11489. this.renderConfig = {
  11490. className: config && config.className || '',
  11491. imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || 'xMidYMid slice',
  11492. hideOnTransparent: !(config && config.hideOnTransparent === false),
  11493. filterSize: {
  11494. width: config && config.filterSize && config.filterSize.width || '400%',
  11495. height: config && config.filterSize && config.filterSize.height || '400%',
  11496. x: config && config.filterSize && config.filterSize.x || '-100%',
  11497. y: config && config.filterSize && config.filterSize.y || '-100%'
  11498. }
  11499. };
  11500. this.globalData = {
  11501. _mdf: false,
  11502. frameNum: -1,
  11503. renderConfig: this.renderConfig
  11504. };
  11505. this.pendingElements = [];
  11506. this.elements = [];
  11507. this.threeDElements = [];
  11508. this.destroyed = false;
  11509. this.camera = null;
  11510. this.supports3d = true;
  11511. this.rendererType = 'html';
  11512. }
  11513. extendPrototype([BaseRenderer], HybridRendererBase);
  11514. HybridRendererBase.prototype.buildItem = SVGRenderer.prototype.buildItem;
  11515. HybridRendererBase.prototype.checkPendingElements = function () {
  11516. while (this.pendingElements.length) {
  11517. var element = this.pendingElements.pop();
  11518. element.checkParenting();
  11519. }
  11520. };
  11521. HybridRendererBase.prototype.appendElementInPos = function (element, pos) {
  11522. var newDOMElement = element.getBaseElement();
  11523. if (!newDOMElement) {
  11524. return;
  11525. }
  11526. var layer = this.layers[pos];
  11527. if (!layer.ddd || !this.supports3d) {
  11528. if (this.threeDElements) {
  11529. this.addTo3dContainer(newDOMElement, pos);
  11530. } else {
  11531. var i = 0;
  11532. var nextDOMElement;
  11533. var nextLayer;
  11534. var tmpDOMElement;
  11535. while (i < pos) {
  11536. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement) {
  11537. nextLayer = this.elements[i];
  11538. tmpDOMElement = this.layers[i].ddd ? this.getThreeDContainerByPos(i) : nextLayer.getBaseElement();
  11539. nextDOMElement = tmpDOMElement || nextDOMElement;
  11540. }
  11541. i += 1;
  11542. }
  11543. if (nextDOMElement) {
  11544. if (!layer.ddd || !this.supports3d) {
  11545. this.layerElement.insertBefore(newDOMElement, nextDOMElement);
  11546. }
  11547. } else if (!layer.ddd || !this.supports3d) {
  11548. this.layerElement.appendChild(newDOMElement);
  11549. }
  11550. }
  11551. } else {
  11552. this.addTo3dContainer(newDOMElement, pos);
  11553. }
  11554. };
  11555. HybridRendererBase.prototype.createShape = function (data) {
  11556. if (!this.supports3d) {
  11557. return new SVGShapeElement(data, this.globalData, this);
  11558. }
  11559. return new HShapeElement(data, this.globalData, this);
  11560. };
  11561. HybridRendererBase.prototype.createText = function (data) {
  11562. if (!this.supports3d) {
  11563. return new SVGTextLottieElement(data, this.globalData, this);
  11564. }
  11565. return new HTextElement(data, this.globalData, this);
  11566. };
  11567. HybridRendererBase.prototype.createCamera = function (data) {
  11568. this.camera = new HCameraElement(data, this.globalData, this);
  11569. return this.camera;
  11570. };
  11571. HybridRendererBase.prototype.createImage = function (data) {
  11572. if (!this.supports3d) {
  11573. return new IImageElement(data, this.globalData, this);
  11574. }
  11575. return new HImageElement(data, this.globalData, this);
  11576. };
  11577. HybridRendererBase.prototype.createSolid = function (data) {
  11578. if (!this.supports3d) {
  11579. return new ISolidElement(data, this.globalData, this);
  11580. }
  11581. return new HSolidElement(data, this.globalData, this);
  11582. };
  11583. HybridRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  11584. HybridRendererBase.prototype.getThreeDContainerByPos = function (pos) {
  11585. var i = 0;
  11586. var len = this.threeDElements.length;
  11587. while (i < len) {
  11588. if (this.threeDElements[i].startPos <= pos && this.threeDElements[i].endPos >= pos) {
  11589. return this.threeDElements[i].perspectiveElem;
  11590. }
  11591. i += 1;
  11592. }
  11593. return null;
  11594. };
  11595. HybridRendererBase.prototype.createThreeDContainer = function (pos, type) {
  11596. var perspectiveElem = createTag('div');
  11597. var style;
  11598. var containerStyle;
  11599. styleDiv(perspectiveElem);
  11600. var container = createTag('div');
  11601. styleDiv(container);
  11602. if (type === '3d') {
  11603. style = perspectiveElem.style;
  11604. style.width = this.globalData.compSize.w + 'px';
  11605. style.height = this.globalData.compSize.h + 'px';
  11606. var center = '50% 50%';
  11607. style.webkitTransformOrigin = center;
  11608. style.mozTransformOrigin = center;
  11609. style.transformOrigin = center;
  11610. containerStyle = container.style;
  11611. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  11612. containerStyle.transform = matrix;
  11613. containerStyle.webkitTransform = matrix;
  11614. }
  11615. perspectiveElem.appendChild(container);
  11616. // this.resizerElem.appendChild(perspectiveElem);
  11617. var threeDContainerData = {
  11618. container: container,
  11619. perspectiveElem: perspectiveElem,
  11620. startPos: pos,
  11621. endPos: pos,
  11622. type: type
  11623. };
  11624. this.threeDElements.push(threeDContainerData);
  11625. return threeDContainerData;
  11626. };
  11627. HybridRendererBase.prototype.build3dContainers = function () {
  11628. var i;
  11629. var len = this.layers.length;
  11630. var lastThreeDContainerData;
  11631. var currentContainer = '';
  11632. for (i = 0; i < len; i += 1) {
  11633. if (this.layers[i].ddd && this.layers[i].ty !== 3) {
  11634. if (currentContainer !== '3d') {
  11635. currentContainer = '3d';
  11636. lastThreeDContainerData = this.createThreeDContainer(i, '3d');
  11637. }
  11638. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  11639. } else {
  11640. if (currentContainer !== '2d') {
  11641. currentContainer = '2d';
  11642. lastThreeDContainerData = this.createThreeDContainer(i, '2d');
  11643. }
  11644. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  11645. }
  11646. }
  11647. len = this.threeDElements.length;
  11648. for (i = len - 1; i >= 0; i -= 1) {
  11649. this.resizerElem.appendChild(this.threeDElements[i].perspectiveElem);
  11650. }
  11651. };
  11652. HybridRendererBase.prototype.addTo3dContainer = function (elem, pos) {
  11653. var i = 0;
  11654. var len = this.threeDElements.length;
  11655. while (i < len) {
  11656. if (pos <= this.threeDElements[i].endPos) {
  11657. var j = this.threeDElements[i].startPos;
  11658. var nextElement;
  11659. while (j < pos) {
  11660. if (this.elements[j] && this.elements[j].getBaseElement) {
  11661. nextElement = this.elements[j].getBaseElement();
  11662. }
  11663. j += 1;
  11664. }
  11665. if (nextElement) {
  11666. this.threeDElements[i].container.insertBefore(elem, nextElement);
  11667. } else {
  11668. this.threeDElements[i].container.appendChild(elem);
  11669. }
  11670. break;
  11671. }
  11672. i += 1;
  11673. }
  11674. };
  11675. HybridRendererBase.prototype.configAnimation = function (animData) {
  11676. var resizerElem = createTag('div');
  11677. var wrapper = this.animationItem.wrapper;
  11678. var style = resizerElem.style;
  11679. style.width = animData.w + 'px';
  11680. style.height = animData.h + 'px';
  11681. this.resizerElem = resizerElem;
  11682. styleDiv(resizerElem);
  11683. style.transformStyle = 'flat';
  11684. style.mozTransformStyle = 'flat';
  11685. style.webkitTransformStyle = 'flat';
  11686. if (this.renderConfig.className) {
  11687. resizerElem.setAttribute('class', this.renderConfig.className);
  11688. }
  11689. wrapper.appendChild(resizerElem);
  11690. style.overflow = 'hidden';
  11691. var svg = createNS('svg');
  11692. svg.setAttribute('width', '1');
  11693. svg.setAttribute('height', '1');
  11694. styleDiv(svg);
  11695. this.resizerElem.appendChild(svg);
  11696. var defs = createNS('defs');
  11697. svg.appendChild(defs);
  11698. this.data = animData;
  11699. // Mask animation
  11700. this.setupGlobalData(animData, svg);
  11701. this.globalData.defs = defs;
  11702. this.layers = animData.layers;
  11703. this.layerElement = this.resizerElem;
  11704. this.build3dContainers();
  11705. this.updateContainerSize();
  11706. };
  11707. HybridRendererBase.prototype.destroy = function () {
  11708. if (this.animationItem.wrapper) {
  11709. this.animationItem.wrapper.innerText = '';
  11710. }
  11711. this.animationItem.container = null;
  11712. this.globalData.defs = null;
  11713. var i;
  11714. var len = this.layers ? this.layers.length : 0;
  11715. for (i = 0; i < len; i += 1) {
  11716. if (this.elements[i] && this.elements[i].destroy) {
  11717. this.elements[i].destroy();
  11718. }
  11719. }
  11720. this.elements.length = 0;
  11721. this.destroyed = true;
  11722. this.animationItem = null;
  11723. };
  11724. HybridRendererBase.prototype.updateContainerSize = function () {
  11725. var elementWidth = this.animationItem.wrapper.offsetWidth;
  11726. var elementHeight = this.animationItem.wrapper.offsetHeight;
  11727. var elementRel = elementWidth / elementHeight;
  11728. var animationRel = this.globalData.compSize.w / this.globalData.compSize.h;
  11729. var sx;
  11730. var sy;
  11731. var tx;
  11732. var ty;
  11733. if (animationRel > elementRel) {
  11734. sx = elementWidth / this.globalData.compSize.w;
  11735. sy = elementWidth / this.globalData.compSize.w;
  11736. tx = 0;
  11737. ty = (elementHeight - this.globalData.compSize.h * (elementWidth / this.globalData.compSize.w)) / 2;
  11738. } else {
  11739. sx = elementHeight / this.globalData.compSize.h;
  11740. sy = elementHeight / this.globalData.compSize.h;
  11741. tx = (elementWidth - this.globalData.compSize.w * (elementHeight / this.globalData.compSize.h)) / 2;
  11742. ty = 0;
  11743. }
  11744. var style = this.resizerElem.style;
  11745. style.webkitTransform = 'matrix3d(' + sx + ',0,0,0,0,' + sy + ',0,0,0,0,1,0,' + tx + ',' + ty + ',0,1)';
  11746. style.transform = style.webkitTransform;
  11747. };
  11748. HybridRendererBase.prototype.renderFrame = SVGRenderer.prototype.renderFrame;
  11749. HybridRendererBase.prototype.hide = function () {
  11750. this.resizerElem.style.display = 'none';
  11751. };
  11752. HybridRendererBase.prototype.show = function () {
  11753. this.resizerElem.style.display = 'block';
  11754. };
  11755. HybridRendererBase.prototype.initItems = function () {
  11756. this.buildAllItems();
  11757. if (this.camera) {
  11758. this.camera.setup();
  11759. } else {
  11760. var cWidth = this.globalData.compSize.w;
  11761. var cHeight = this.globalData.compSize.h;
  11762. var i;
  11763. var len = this.threeDElements.length;
  11764. for (i = 0; i < len; i += 1) {
  11765. var style = this.threeDElements[i].perspectiveElem.style;
  11766. style.webkitPerspective = Math.sqrt(Math.pow(cWidth, 2) + Math.pow(cHeight, 2)) + 'px';
  11767. style.perspective = style.webkitPerspective;
  11768. }
  11769. }
  11770. };
  11771. HybridRendererBase.prototype.searchExtraCompositions = function (assets) {
  11772. var i;
  11773. var len = assets.length;
  11774. var floatingContainer = createTag('div');
  11775. for (i = 0; i < len; i += 1) {
  11776. if (assets[i].xt) {
  11777. var comp = this.createComp(assets[i], floatingContainer, this.globalData.comp, null);
  11778. comp.initExpressions();
  11779. this.globalData.projectInterface.registerComposition(comp);
  11780. }
  11781. }
  11782. };
  11783. function HCompElement(data, globalData, comp) {
  11784. this.layers = data.layers;
  11785. this.supports3d = !data.hasMask;
  11786. this.completeLayers = false;
  11787. this.pendingElements = [];
  11788. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  11789. this.initElement(data, globalData, comp);
  11790. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  11791. _placeholder: true
  11792. };
  11793. }
  11794. extendPrototype([HybridRendererBase, ICompElement, HBaseElement], HCompElement);
  11795. HCompElement.prototype._createBaseContainerElements = HCompElement.prototype.createContainerElements;
  11796. HCompElement.prototype.createContainerElements = function () {
  11797. this._createBaseContainerElements();
  11798. // divElement.style.clip = 'rect(0px, '+this.data.w+'px, '+this.data.h+'px, 0px)';
  11799. if (this.data.hasMask) {
  11800. this.svgElement.setAttribute('width', this.data.w);
  11801. this.svgElement.setAttribute('height', this.data.h);
  11802. this.transformedElement = this.baseElement;
  11803. } else {
  11804. this.transformedElement = this.layerElement;
  11805. }
  11806. };
  11807. HCompElement.prototype.addTo3dContainer = function (elem, pos) {
  11808. var j = 0;
  11809. var nextElement;
  11810. while (j < pos) {
  11811. if (this.elements[j] && this.elements[j].getBaseElement) {
  11812. nextElement = this.elements[j].getBaseElement();
  11813. }
  11814. j += 1;
  11815. }
  11816. if (nextElement) {
  11817. this.layerElement.insertBefore(elem, nextElement);
  11818. } else {
  11819. this.layerElement.appendChild(elem);
  11820. }
  11821. };
  11822. HCompElement.prototype.createComp = function (data) {
  11823. if (!this.supports3d) {
  11824. return new SVGCompElement(data, this.globalData, this);
  11825. }
  11826. return new HCompElement(data, this.globalData, this);
  11827. };
  11828. function HybridRenderer(animationItem, config) {
  11829. this.animationItem = animationItem;
  11830. this.layers = null;
  11831. this.renderedFrame = -1;
  11832. this.renderConfig = {
  11833. className: config && config.className || '',
  11834. imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || 'xMidYMid slice',
  11835. hideOnTransparent: !(config && config.hideOnTransparent === false),
  11836. filterSize: {
  11837. width: config && config.filterSize && config.filterSize.width || '400%',
  11838. height: config && config.filterSize && config.filterSize.height || '400%',
  11839. x: config && config.filterSize && config.filterSize.x || '-100%',
  11840. y: config && config.filterSize && config.filterSize.y || '-100%'
  11841. },
  11842. runExpressions: !config || config.runExpressions === undefined || config.runExpressions
  11843. };
  11844. this.globalData = {
  11845. _mdf: false,
  11846. frameNum: -1,
  11847. renderConfig: this.renderConfig
  11848. };
  11849. this.pendingElements = [];
  11850. this.elements = [];
  11851. this.threeDElements = [];
  11852. this.destroyed = false;
  11853. this.camera = null;
  11854. this.supports3d = true;
  11855. this.rendererType = 'html';
  11856. }
  11857. extendPrototype([HybridRendererBase], HybridRenderer);
  11858. HybridRenderer.prototype.createComp = function (data) {
  11859. if (!this.supports3d) {
  11860. return new SVGCompElement(data, this.globalData, this);
  11861. }
  11862. return new HCompElement(data, this.globalData, this);
  11863. };
  11864. // Registering renderers
  11865. registerRenderer('html', HybridRenderer);
  11866. // Registering shape modifiers
  11867. ShapeModifiers.registerModifier('tm', TrimModifier);
  11868. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  11869. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  11870. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  11871. ShapeModifiers.registerModifier('zz', ZigZagModifier);
  11872. ShapeModifiers.registerModifier('op', OffsetPathModifier);
  11873. return lottie;
  11874. }));