lottie_light_html.min.js 398 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832
  1. const svgNS = 'http://www.w3.org/2000/svg';
  2. let locationHref = '';
  3. let _useWebWorker = false;
  4. const initialDefaultFrame = -999999;
  5. const setWebWorker = (flag) => { _useWebWorker = !!flag; };
  6. const getWebWorker = () => _useWebWorker;
  7. const setLocationHref = (value) => { locationHref = value; };
  8. const getLocationHref = () => locationHref;
  9. function createTag(type) {
  10. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  11. return document.createElement(type);
  12. }
  13. function extendPrototype(sources, destination) {
  14. var i;
  15. var len = sources.length;
  16. var sourcePrototype;
  17. for (i = 0; i < len; i += 1) {
  18. sourcePrototype = sources[i].prototype;
  19. for (var attr in sourcePrototype) {
  20. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  21. }
  22. }
  23. }
  24. function getDescriptor(object, prop) {
  25. return Object.getOwnPropertyDescriptor(object, prop);
  26. }
  27. function createProxyFunction(prototype) {
  28. function ProxyFunction() {}
  29. ProxyFunction.prototype = prototype;
  30. return ProxyFunction;
  31. }
  32. // import Howl from '../../3rd_party/howler';
  33. const audioControllerFactory = (function () {
  34. function AudioController(audioFactory) {
  35. this.audios = [];
  36. this.audioFactory = audioFactory;
  37. this._volume = 1;
  38. this._isMuted = false;
  39. }
  40. AudioController.prototype = {
  41. addAudio: function (audio) {
  42. this.audios.push(audio);
  43. },
  44. pause: function () {
  45. var i;
  46. var len = this.audios.length;
  47. for (i = 0; i < len; i += 1) {
  48. this.audios[i].pause();
  49. }
  50. },
  51. resume: function () {
  52. var i;
  53. var len = this.audios.length;
  54. for (i = 0; i < len; i += 1) {
  55. this.audios[i].resume();
  56. }
  57. },
  58. setRate: function (rateValue) {
  59. var i;
  60. var len = this.audios.length;
  61. for (i = 0; i < len; i += 1) {
  62. this.audios[i].setRate(rateValue);
  63. }
  64. },
  65. createAudio: function (assetPath) {
  66. if (this.audioFactory) {
  67. return this.audioFactory(assetPath);
  68. } if (window.Howl) {
  69. return new window.Howl({
  70. src: [assetPath],
  71. });
  72. }
  73. return {
  74. isPlaying: false,
  75. play: function () { this.isPlaying = true; },
  76. seek: function () { this.isPlaying = false; },
  77. playing: function () {},
  78. rate: function () {},
  79. setVolume: function () {},
  80. };
  81. },
  82. setAudioFactory: function (audioFactory) {
  83. this.audioFactory = audioFactory;
  84. },
  85. setVolume: function (value) {
  86. this._volume = value;
  87. this._updateVolume();
  88. },
  89. mute: function () {
  90. this._isMuted = true;
  91. this._updateVolume();
  92. },
  93. unmute: function () {
  94. this._isMuted = false;
  95. this._updateVolume();
  96. },
  97. getVolume: function () {
  98. return this._volume;
  99. },
  100. _updateVolume: function () {
  101. var i;
  102. var len = this.audios.length;
  103. for (i = 0; i < len; i += 1) {
  104. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  105. }
  106. },
  107. };
  108. return function () {
  109. return new AudioController();
  110. };
  111. }());
  112. const createTypedArray = (function () {
  113. function createRegularArray(type, len) {
  114. var i = 0;
  115. var arr = [];
  116. var value;
  117. switch (type) {
  118. case 'int16':
  119. case 'uint8c':
  120. value = 1;
  121. break;
  122. default:
  123. value = 1.1;
  124. break;
  125. }
  126. for (i = 0; i < len; i += 1) {
  127. arr.push(value);
  128. }
  129. return arr;
  130. }
  131. function createTypedArrayFactory(type, len) {
  132. if (type === 'float32') {
  133. return new Float32Array(len);
  134. } if (type === 'int16') {
  135. return new Int16Array(len);
  136. } if (type === 'uint8c') {
  137. return new Uint8ClampedArray(len);
  138. }
  139. return createRegularArray(type, len);
  140. }
  141. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  142. return createTypedArrayFactory;
  143. }
  144. return createRegularArray;
  145. }());
  146. function createSizedArray(len) {
  147. return Array.apply(null, { length: len });
  148. }
  149. let subframeEnabled = true;
  150. let expressionsPlugin = null;
  151. let expressionsInterfaces = null;
  152. let idPrefix$1 = '';
  153. const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  154. let _shouldRoundValues = false;
  155. const bmPow = Math.pow;
  156. const bmSqrt = Math.sqrt;
  157. const bmFloor = Math.floor;
  158. const bmMax = Math.max;
  159. const bmMin = Math.min;
  160. const BMMath = {};
  161. (function () {
  162. 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'];
  163. var i;
  164. var len = propertyNames.length;
  165. for (i = 0; i < len; i += 1) {
  166. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  167. }
  168. }());
  169. function ProjectInterface$1() { return {}; }
  170. BMMath.random = Math.random;
  171. BMMath.abs = function (val) {
  172. var tOfVal = typeof val;
  173. if (tOfVal === 'object' && val.length) {
  174. var absArr = createSizedArray(val.length);
  175. var i;
  176. var len = val.length;
  177. for (i = 0; i < len; i += 1) {
  178. absArr[i] = Math.abs(val[i]);
  179. }
  180. return absArr;
  181. }
  182. return Math.abs(val);
  183. };
  184. let defaultCurveSegments = 150;
  185. const degToRads = Math.PI / 180;
  186. const roundCorner = 0.5519;
  187. function roundValues(flag) {
  188. _shouldRoundValues = !!flag;
  189. }
  190. function bmRnd(value) {
  191. if (_shouldRoundValues) {
  192. return Math.round(value);
  193. }
  194. return value;
  195. }
  196. function styleDiv(element) {
  197. element.style.position = 'absolute';
  198. element.style.top = 0;
  199. element.style.left = 0;
  200. element.style.display = 'block';
  201. element.style.transformOrigin = '0 0';
  202. element.style.webkitTransformOrigin = '0 0';
  203. element.style.backfaceVisibility = 'visible';
  204. element.style.webkitBackfaceVisibility = 'visible';
  205. element.style.transformStyle = 'preserve-3d';
  206. element.style.webkitTransformStyle = 'preserve-3d';
  207. element.style.mozTransformStyle = 'preserve-3d';
  208. }
  209. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  210. this.type = type;
  211. this.currentTime = currentTime;
  212. this.totalTime = totalTime;
  213. this.direction = frameMultiplier < 0 ? -1 : 1;
  214. }
  215. function BMCompleteEvent(type, frameMultiplier) {
  216. this.type = type;
  217. this.direction = frameMultiplier < 0 ? -1 : 1;
  218. }
  219. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  220. this.type = type;
  221. this.currentLoop = currentLoop;
  222. this.totalLoops = totalLoops;
  223. this.direction = frameMultiplier < 0 ? -1 : 1;
  224. }
  225. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  226. this.type = type;
  227. this.firstFrame = firstFrame;
  228. this.totalFrames = totalFrames;
  229. }
  230. function BMDestroyEvent(type, target) {
  231. this.type = type;
  232. this.target = target;
  233. }
  234. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  235. this.type = 'renderFrameError';
  236. this.nativeError = nativeError;
  237. this.currentTime = currentTime;
  238. }
  239. function BMConfigErrorEvent(nativeError) {
  240. this.type = 'configError';
  241. this.nativeError = nativeError;
  242. }
  243. function BMAnimationConfigErrorEvent(type, nativeError) {
  244. this.type = type;
  245. this.nativeError = nativeError;
  246. }
  247. const createElementID = (function () {
  248. var _count = 0;
  249. return function createID() {
  250. _count += 1;
  251. return idPrefix$1 + '__lottie_element_' + _count;
  252. };
  253. }());
  254. function HSVtoRGB(h, s, v) {
  255. var r;
  256. var g;
  257. var b;
  258. var i;
  259. var f;
  260. var p;
  261. var q;
  262. var t;
  263. i = Math.floor(h * 6);
  264. f = h * 6 - i;
  265. p = v * (1 - s);
  266. q = v * (1 - f * s);
  267. t = v * (1 - (1 - f) * s);
  268. switch (i % 6) {
  269. case 0: r = v; g = t; b = p; break;
  270. case 1: r = q; g = v; b = p; break;
  271. case 2: r = p; g = v; b = t; break;
  272. case 3: r = p; g = q; b = v; break;
  273. case 4: r = t; g = p; b = v; break;
  274. case 5: r = v; g = p; b = q; break;
  275. default: break;
  276. }
  277. return [r,
  278. g,
  279. b];
  280. }
  281. function RGBtoHSV(r, g, b) {
  282. var max = Math.max(r, g, b);
  283. var min = Math.min(r, g, b);
  284. var d = max - min;
  285. var h;
  286. var s = (max === 0 ? 0 : d / max);
  287. var v = max / 255;
  288. switch (max) {
  289. case min: h = 0; break;
  290. case r: h = (g - b) + d * (g < b ? 6 : 0); h /= 6 * d; break;
  291. case g: h = (b - r) + d * 2; h /= 6 * d; break;
  292. case b: h = (r - g) + d * 4; h /= 6 * d; break;
  293. default: break;
  294. }
  295. return [
  296. h,
  297. s,
  298. v,
  299. ];
  300. }
  301. function addSaturationToRGB(color, offset) {
  302. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  303. hsv[1] += offset;
  304. if (hsv[1] > 1) {
  305. hsv[1] = 1;
  306. } else if (hsv[1] <= 0) {
  307. hsv[1] = 0;
  308. }
  309. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  310. }
  311. function addBrightnessToRGB(color, offset) {
  312. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  313. hsv[2] += offset;
  314. if (hsv[2] > 1) {
  315. hsv[2] = 1;
  316. } else if (hsv[2] < 0) {
  317. hsv[2] = 0;
  318. }
  319. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  320. }
  321. function addHueToRGB(color, offset) {
  322. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  323. hsv[0] += offset / 360;
  324. if (hsv[0] > 1) {
  325. hsv[0] -= 1;
  326. } else if (hsv[0] < 0) {
  327. hsv[0] += 1;
  328. }
  329. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  330. }
  331. const rgbToHex = (function () {
  332. var colorMap = [];
  333. var i;
  334. var hex;
  335. for (i = 0; i < 256; i += 1) {
  336. hex = i.toString(16);
  337. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  338. }
  339. return function (r, g, b) {
  340. if (r < 0) {
  341. r = 0;
  342. }
  343. if (g < 0) {
  344. g = 0;
  345. }
  346. if (b < 0) {
  347. b = 0;
  348. }
  349. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  350. };
  351. }());
  352. const setSubframeEnabled = (flag) => { subframeEnabled = !!flag; };
  353. const getSubframeEnabled = () => subframeEnabled;
  354. const setExpressionsPlugin = (value) => { expressionsPlugin = value; };
  355. const getExpressionsPlugin = () => expressionsPlugin;
  356. const setExpressionInterfaces = (value) => { expressionsInterfaces = value; };
  357. const getExpressionInterfaces = () => expressionsInterfaces;
  358. const setDefaultCurveSegments = (value) => { defaultCurveSegments = value; };
  359. const getDefaultCurveSegments = () => defaultCurveSegments;
  360. const setIdPrefix = (value) => { idPrefix$1 = value; };
  361. const getIdPrefix = () => idPrefix$1;
  362. function createNS(type) {
  363. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  364. return document.createElementNS(svgNS, type);
  365. }
  366. const dataManager = (function () {
  367. var _counterId = 1;
  368. var processes = [];
  369. var workerFn;
  370. var workerInstance;
  371. var workerProxy = {
  372. onmessage: function () {
  373. },
  374. postMessage: function (path) {
  375. workerFn({
  376. data: path,
  377. });
  378. },
  379. };
  380. var _workerSelf = {
  381. postMessage: function (data) {
  382. workerProxy.onmessage({
  383. data: data,
  384. });
  385. },
  386. };
  387. function createWorker(fn) {
  388. if (window.Worker && window.Blob && getWebWorker()) {
  389. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  390. // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  391. var url = URL.createObjectURL(blob);
  392. return new Worker(url);
  393. }
  394. workerFn = fn;
  395. return workerProxy;
  396. }
  397. function setupWorker() {
  398. if (!workerInstance) {
  399. workerInstance = createWorker(function workerStart(e) {
  400. function dataFunctionManager() {
  401. function completeLayers(layers, comps) {
  402. var layerData;
  403. var i;
  404. var len = layers.length;
  405. var j;
  406. var jLen;
  407. var k;
  408. var kLen;
  409. for (i = 0; i < len; i += 1) {
  410. layerData = layers[i];
  411. if (('ks' in layerData) && !layerData.completed) {
  412. layerData.completed = true;
  413. if (layerData.hasMask) {
  414. var maskProps = layerData.masksProperties;
  415. jLen = maskProps.length;
  416. for (j = 0; j < jLen; j += 1) {
  417. if (maskProps[j].pt.k.i) {
  418. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  419. } else {
  420. kLen = maskProps[j].pt.k.length;
  421. for (k = 0; k < kLen; k += 1) {
  422. if (maskProps[j].pt.k[k].s) {
  423. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  424. }
  425. if (maskProps[j].pt.k[k].e) {
  426. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  427. }
  428. }
  429. }
  430. }
  431. }
  432. if (layerData.ty === 0) {
  433. layerData.layers = findCompLayers(layerData.refId, comps);
  434. completeLayers(layerData.layers, comps);
  435. } else if (layerData.ty === 4) {
  436. completeShapes(layerData.shapes);
  437. } else if (layerData.ty === 5) {
  438. completeText(layerData);
  439. }
  440. }
  441. }
  442. }
  443. function completeChars(chars, assets) {
  444. if (chars) {
  445. var i = 0;
  446. var len = chars.length;
  447. for (i = 0; i < len; i += 1) {
  448. if (chars[i].t === 1) {
  449. // var compData = findComp(chars[i].data.refId, assets);
  450. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
  451. // chars[i].data.ip = 0;
  452. // chars[i].data.op = 99999;
  453. // chars[i].data.st = 0;
  454. // chars[i].data.sr = 1;
  455. // chars[i].w = compData.w;
  456. // chars[i].data.ks = {
  457. // a: { k: [0, 0, 0], a: 0 },
  458. // p: { k: [0, -compData.h, 0], a: 0 },
  459. // r: { k: 0, a: 0 },
  460. // s: { k: [100, 100], a: 0 },
  461. // o: { k: 100, a: 0 },
  462. // };
  463. completeLayers(chars[i].data.layers, assets);
  464. }
  465. }
  466. }
  467. }
  468. function findComp(id, comps) {
  469. var i = 0;
  470. var len = comps.length;
  471. while (i < len) {
  472. if (comps[i].id === id) {
  473. return comps[i];
  474. }
  475. i += 1;
  476. }
  477. return null;
  478. }
  479. function findCompLayers(id, comps) {
  480. var comp = findComp(id, comps);
  481. if (comp) {
  482. if (!comp.layers.__used) {
  483. comp.layers.__used = true;
  484. return comp.layers;
  485. }
  486. return JSON.parse(JSON.stringify(comp.layers));
  487. }
  488. return null;
  489. }
  490. function completeShapes(arr) {
  491. var i;
  492. var len = arr.length;
  493. var j;
  494. var jLen;
  495. for (i = len - 1; i >= 0; i -= 1) {
  496. if (arr[i].ty === 'sh') {
  497. if (arr[i].ks.k.i) {
  498. convertPathsToAbsoluteValues(arr[i].ks.k);
  499. } else {
  500. jLen = arr[i].ks.k.length;
  501. for (j = 0; j < jLen; j += 1) {
  502. if (arr[i].ks.k[j].s) {
  503. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  504. }
  505. if (arr[i].ks.k[j].e) {
  506. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  507. }
  508. }
  509. }
  510. } else if (arr[i].ty === 'gr') {
  511. completeShapes(arr[i].it);
  512. }
  513. }
  514. }
  515. function convertPathsToAbsoluteValues(path) {
  516. var i;
  517. var len = path.i.length;
  518. for (i = 0; i < len; i += 1) {
  519. path.i[i][0] += path.v[i][0];
  520. path.i[i][1] += path.v[i][1];
  521. path.o[i][0] += path.v[i][0];
  522. path.o[i][1] += path.v[i][1];
  523. }
  524. }
  525. function checkVersion(minimum, animVersionString) {
  526. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  527. if (minimum[0] > animVersion[0]) {
  528. return true;
  529. } if (animVersion[0] > minimum[0]) {
  530. return false;
  531. }
  532. if (minimum[1] > animVersion[1]) {
  533. return true;
  534. } if (animVersion[1] > minimum[1]) {
  535. return false;
  536. }
  537. if (minimum[2] > animVersion[2]) {
  538. return true;
  539. } if (animVersion[2] > minimum[2]) {
  540. return false;
  541. }
  542. return null;
  543. }
  544. var checkText = (function () {
  545. var minimumVersion = [4, 4, 14];
  546. function updateTextLayer(textLayer) {
  547. var documentData = textLayer.t.d;
  548. textLayer.t.d = {
  549. k: [
  550. {
  551. s: documentData,
  552. t: 0,
  553. },
  554. ],
  555. };
  556. }
  557. function iterateLayers(layers) {
  558. var i;
  559. var len = layers.length;
  560. for (i = 0; i < len; i += 1) {
  561. if (layers[i].ty === 5) {
  562. updateTextLayer(layers[i]);
  563. }
  564. }
  565. }
  566. return function (animationData) {
  567. if (checkVersion(minimumVersion, animationData.v)) {
  568. iterateLayers(animationData.layers);
  569. if (animationData.assets) {
  570. var i;
  571. var len = animationData.assets.length;
  572. for (i = 0; i < len; i += 1) {
  573. if (animationData.assets[i].layers) {
  574. iterateLayers(animationData.assets[i].layers);
  575. }
  576. }
  577. }
  578. }
  579. };
  580. }());
  581. var checkChars = (function () {
  582. var minimumVersion = [4, 7, 99];
  583. return function (animationData) {
  584. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  585. var i;
  586. var len = animationData.chars.length;
  587. for (i = 0; i < len; i += 1) {
  588. var charData = animationData.chars[i];
  589. if (charData.data && charData.data.shapes) {
  590. completeShapes(charData.data.shapes);
  591. charData.data.ip = 0;
  592. charData.data.op = 99999;
  593. charData.data.st = 0;
  594. charData.data.sr = 1;
  595. charData.data.ks = {
  596. p: { k: [0, 0], a: 0 },
  597. s: { k: [100, 100], a: 0 },
  598. a: { k: [0, 0], a: 0 },
  599. r: { k: 0, a: 0 },
  600. o: { k: 100, a: 0 },
  601. };
  602. if (!animationData.chars[i].t) {
  603. charData.data.shapes.push(
  604. {
  605. ty: 'no',
  606. }
  607. );
  608. charData.data.shapes[0].it.push(
  609. {
  610. p: { k: [0, 0], a: 0 },
  611. s: { k: [100, 100], a: 0 },
  612. a: { k: [0, 0], a: 0 },
  613. r: { k: 0, a: 0 },
  614. o: { k: 100, a: 0 },
  615. sk: { k: 0, a: 0 },
  616. sa: { k: 0, a: 0 },
  617. ty: 'tr',
  618. }
  619. );
  620. }
  621. }
  622. }
  623. }
  624. };
  625. }());
  626. var checkPathProperties = (function () {
  627. var minimumVersion = [5, 7, 15];
  628. function updateTextLayer(textLayer) {
  629. var pathData = textLayer.t.p;
  630. if (typeof pathData.a === 'number') {
  631. pathData.a = {
  632. a: 0,
  633. k: pathData.a,
  634. };
  635. }
  636. if (typeof pathData.p === 'number') {
  637. pathData.p = {
  638. a: 0,
  639. k: pathData.p,
  640. };
  641. }
  642. if (typeof pathData.r === 'number') {
  643. pathData.r = {
  644. a: 0,
  645. k: pathData.r,
  646. };
  647. }
  648. }
  649. function iterateLayers(layers) {
  650. var i;
  651. var len = layers.length;
  652. for (i = 0; i < len; i += 1) {
  653. if (layers[i].ty === 5) {
  654. updateTextLayer(layers[i]);
  655. }
  656. }
  657. }
  658. return function (animationData) {
  659. if (checkVersion(minimumVersion, animationData.v)) {
  660. iterateLayers(animationData.layers);
  661. if (animationData.assets) {
  662. var i;
  663. var len = animationData.assets.length;
  664. for (i = 0; i < len; i += 1) {
  665. if (animationData.assets[i].layers) {
  666. iterateLayers(animationData.assets[i].layers);
  667. }
  668. }
  669. }
  670. }
  671. };
  672. }());
  673. var checkColors = (function () {
  674. var minimumVersion = [4, 1, 9];
  675. function iterateShapes(shapes) {
  676. var i;
  677. var len = shapes.length;
  678. var j;
  679. var jLen;
  680. for (i = 0; i < len; i += 1) {
  681. if (shapes[i].ty === 'gr') {
  682. iterateShapes(shapes[i].it);
  683. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  684. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  685. jLen = shapes[i].c.k.length;
  686. for (j = 0; j < jLen; j += 1) {
  687. if (shapes[i].c.k[j].s) {
  688. shapes[i].c.k[j].s[0] /= 255;
  689. shapes[i].c.k[j].s[1] /= 255;
  690. shapes[i].c.k[j].s[2] /= 255;
  691. shapes[i].c.k[j].s[3] /= 255;
  692. }
  693. if (shapes[i].c.k[j].e) {
  694. shapes[i].c.k[j].e[0] /= 255;
  695. shapes[i].c.k[j].e[1] /= 255;
  696. shapes[i].c.k[j].e[2] /= 255;
  697. shapes[i].c.k[j].e[3] /= 255;
  698. }
  699. }
  700. } else {
  701. shapes[i].c.k[0] /= 255;
  702. shapes[i].c.k[1] /= 255;
  703. shapes[i].c.k[2] /= 255;
  704. shapes[i].c.k[3] /= 255;
  705. }
  706. }
  707. }
  708. }
  709. function iterateLayers(layers) {
  710. var i;
  711. var len = layers.length;
  712. for (i = 0; i < len; i += 1) {
  713. if (layers[i].ty === 4) {
  714. iterateShapes(layers[i].shapes);
  715. }
  716. }
  717. }
  718. return function (animationData) {
  719. if (checkVersion(minimumVersion, animationData.v)) {
  720. iterateLayers(animationData.layers);
  721. if (animationData.assets) {
  722. var i;
  723. var len = animationData.assets.length;
  724. for (i = 0; i < len; i += 1) {
  725. if (animationData.assets[i].layers) {
  726. iterateLayers(animationData.assets[i].layers);
  727. }
  728. }
  729. }
  730. }
  731. };
  732. }());
  733. var checkShapes = (function () {
  734. var minimumVersion = [4, 4, 18];
  735. function completeClosingShapes(arr) {
  736. var i;
  737. var len = arr.length;
  738. var j;
  739. var jLen;
  740. for (i = len - 1; i >= 0; i -= 1) {
  741. if (arr[i].ty === 'sh') {
  742. if (arr[i].ks.k.i) {
  743. arr[i].ks.k.c = arr[i].closed;
  744. } else {
  745. jLen = arr[i].ks.k.length;
  746. for (j = 0; j < jLen; j += 1) {
  747. if (arr[i].ks.k[j].s) {
  748. arr[i].ks.k[j].s[0].c = arr[i].closed;
  749. }
  750. if (arr[i].ks.k[j].e) {
  751. arr[i].ks.k[j].e[0].c = arr[i].closed;
  752. }
  753. }
  754. }
  755. } else if (arr[i].ty === 'gr') {
  756. completeClosingShapes(arr[i].it);
  757. }
  758. }
  759. }
  760. function iterateLayers(layers) {
  761. var layerData;
  762. var i;
  763. var len = layers.length;
  764. var j;
  765. var jLen;
  766. var k;
  767. var kLen;
  768. for (i = 0; i < len; i += 1) {
  769. layerData = layers[i];
  770. if (layerData.hasMask) {
  771. var maskProps = layerData.masksProperties;
  772. jLen = maskProps.length;
  773. for (j = 0; j < jLen; j += 1) {
  774. if (maskProps[j].pt.k.i) {
  775. maskProps[j].pt.k.c = maskProps[j].cl;
  776. } else {
  777. kLen = maskProps[j].pt.k.length;
  778. for (k = 0; k < kLen; k += 1) {
  779. if (maskProps[j].pt.k[k].s) {
  780. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  781. }
  782. if (maskProps[j].pt.k[k].e) {
  783. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  784. }
  785. }
  786. }
  787. }
  788. }
  789. if (layerData.ty === 4) {
  790. completeClosingShapes(layerData.shapes);
  791. }
  792. }
  793. }
  794. return function (animationData) {
  795. if (checkVersion(minimumVersion, animationData.v)) {
  796. iterateLayers(animationData.layers);
  797. if (animationData.assets) {
  798. var i;
  799. var len = animationData.assets.length;
  800. for (i = 0; i < len; i += 1) {
  801. if (animationData.assets[i].layers) {
  802. iterateLayers(animationData.assets[i].layers);
  803. }
  804. }
  805. }
  806. }
  807. };
  808. }());
  809. function completeData(animationData) {
  810. if (animationData.__complete) {
  811. return;
  812. }
  813. checkColors(animationData);
  814. checkText(animationData);
  815. checkChars(animationData);
  816. checkPathProperties(animationData);
  817. checkShapes(animationData);
  818. completeLayers(animationData.layers, animationData.assets);
  819. completeChars(animationData.chars, animationData.assets);
  820. animationData.__complete = true;
  821. }
  822. function completeText(data) {
  823. if (data.t.a.length === 0 && !('m' in data.t.p)) {
  824. // data.singleShape = true;
  825. }
  826. }
  827. var moduleOb = {};
  828. moduleOb.completeData = completeData;
  829. moduleOb.checkColors = checkColors;
  830. moduleOb.checkChars = checkChars;
  831. moduleOb.checkPathProperties = checkPathProperties;
  832. moduleOb.checkShapes = checkShapes;
  833. moduleOb.completeLayers = completeLayers;
  834. return moduleOb;
  835. }
  836. if (!_workerSelf.dataManager) {
  837. _workerSelf.dataManager = dataFunctionManager();
  838. }
  839. if (!_workerSelf.assetLoader) {
  840. _workerSelf.assetLoader = (function () {
  841. function formatResponse(xhr) {
  842. // using typeof doubles the time of execution of this method,
  843. // so if available, it's better to use the header to validate the type
  844. var contentTypeHeader = xhr.getResponseHeader('content-type');
  845. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  846. return xhr.response;
  847. }
  848. if (xhr.response && typeof xhr.response === 'object') {
  849. return xhr.response;
  850. } if (xhr.response && typeof xhr.response === 'string') {
  851. return JSON.parse(xhr.response);
  852. } if (xhr.responseText) {
  853. return JSON.parse(xhr.responseText);
  854. }
  855. return null;
  856. }
  857. function loadAsset(path, fullPath, callback, errorCallback) {
  858. var response;
  859. var xhr = new XMLHttpRequest();
  860. // set responseType after calling open or IE will break.
  861. try {
  862. // This crashes on Android WebView prior to KitKat
  863. xhr.responseType = 'json';
  864. } catch (err) {} // eslint-disable-line no-empty
  865. xhr.onreadystatechange = function () {
  866. if (xhr.readyState === 4) {
  867. if (xhr.status === 200) {
  868. response = formatResponse(xhr);
  869. callback(response);
  870. } else {
  871. try {
  872. response = formatResponse(xhr);
  873. callback(response);
  874. } catch (err) {
  875. if (errorCallback) {
  876. errorCallback(err);
  877. }
  878. }
  879. }
  880. }
  881. };
  882. try {
  883. // Hack to workaround banner validation
  884. xhr.open(['G', 'E', 'T'].join(''), path, true);
  885. } catch (error) {
  886. // Hack to workaround banner validation
  887. xhr.open(['G', 'E', 'T'].join(''), fullPath + '/' + path, true);
  888. }
  889. xhr.send();
  890. }
  891. return {
  892. load: loadAsset,
  893. };
  894. }());
  895. }
  896. if (e.data.type === 'loadAnimation') {
  897. _workerSelf.assetLoader.load(
  898. e.data.path,
  899. e.data.fullPath,
  900. function (data) {
  901. _workerSelf.dataManager.completeData(data);
  902. _workerSelf.postMessage({
  903. id: e.data.id,
  904. payload: data,
  905. status: 'success',
  906. });
  907. },
  908. function () {
  909. _workerSelf.postMessage({
  910. id: e.data.id,
  911. status: 'error',
  912. });
  913. }
  914. );
  915. } else if (e.data.type === 'complete') {
  916. var animation = e.data.animation;
  917. _workerSelf.dataManager.completeData(animation);
  918. _workerSelf.postMessage({
  919. id: e.data.id,
  920. payload: animation,
  921. status: 'success',
  922. });
  923. } else if (e.data.type === 'loadData') {
  924. _workerSelf.assetLoader.load(
  925. e.data.path,
  926. e.data.fullPath,
  927. function (data) {
  928. _workerSelf.postMessage({
  929. id: e.data.id,
  930. payload: data,
  931. status: 'success',
  932. });
  933. },
  934. function () {
  935. _workerSelf.postMessage({
  936. id: e.data.id,
  937. status: 'error',
  938. });
  939. }
  940. );
  941. }
  942. });
  943. workerInstance.onmessage = function (event) {
  944. var data = event.data;
  945. var id = data.id;
  946. var process = processes[id];
  947. processes[id] = null;
  948. if (data.status === 'success') {
  949. process.onComplete(data.payload);
  950. } else if (process.onError) {
  951. process.onError();
  952. }
  953. };
  954. }
  955. }
  956. function createProcess(onComplete, onError) {
  957. _counterId += 1;
  958. var id = 'processId_' + _counterId;
  959. processes[id] = {
  960. onComplete: onComplete,
  961. onError: onError,
  962. };
  963. return id;
  964. }
  965. function loadAnimation(path, onComplete, onError) {
  966. setupWorker();
  967. var processId = createProcess(onComplete, onError);
  968. workerInstance.postMessage({
  969. type: 'loadAnimation',
  970. path: path,
  971. fullPath: window.location.origin + window.location.pathname,
  972. id: processId,
  973. });
  974. }
  975. function loadData(path, onComplete, onError) {
  976. setupWorker();
  977. var processId = createProcess(onComplete, onError);
  978. workerInstance.postMessage({
  979. type: 'loadData',
  980. path: path,
  981. fullPath: window.location.origin + window.location.pathname,
  982. id: processId,
  983. });
  984. }
  985. function completeAnimation(anim, onComplete, onError) {
  986. setupWorker();
  987. var processId = createProcess(onComplete, onError);
  988. workerInstance.postMessage({
  989. type: 'complete',
  990. animation: anim,
  991. id: processId,
  992. });
  993. }
  994. return {
  995. loadAnimation: loadAnimation,
  996. loadData: loadData,
  997. completeAnimation: completeAnimation,
  998. };
  999. }());
  1000. const ImagePreloader = (function () {
  1001. var proxyImage = (function () {
  1002. var canvas = createTag('canvas');
  1003. canvas.width = 1;
  1004. canvas.height = 1;
  1005. var ctx = canvas.getContext('2d');
  1006. ctx.fillStyle = 'rgba(0,0,0,0)';
  1007. ctx.fillRect(0, 0, 1, 1);
  1008. return canvas;
  1009. }());
  1010. function imageLoaded() {
  1011. this.loadedAssets += 1;
  1012. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1013. if (this.imagesLoadedCb) {
  1014. this.imagesLoadedCb(null);
  1015. }
  1016. }
  1017. }
  1018. function footageLoaded() {
  1019. this.loadedFootagesCount += 1;
  1020. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1021. if (this.imagesLoadedCb) {
  1022. this.imagesLoadedCb(null);
  1023. }
  1024. }
  1025. }
  1026. function getAssetsPath(assetData, assetsPath, originalPath) {
  1027. var path = '';
  1028. if (assetData.e) {
  1029. path = assetData.p;
  1030. } else if (assetsPath) {
  1031. var imagePath = assetData.p;
  1032. if (imagePath.indexOf('images/') !== -1) {
  1033. imagePath = imagePath.split('/')[1];
  1034. }
  1035. path = assetsPath + imagePath;
  1036. } else {
  1037. path = originalPath;
  1038. path += assetData.u ? assetData.u : '';
  1039. path += assetData.p;
  1040. }
  1041. return path;
  1042. }
  1043. function testImageLoaded(img) {
  1044. var _count = 0;
  1045. var intervalId = setInterval(function () {
  1046. var box = img.getBBox();
  1047. if (box.width || _count > 500) {
  1048. this._imageLoaded();
  1049. clearInterval(intervalId);
  1050. }
  1051. _count += 1;
  1052. }.bind(this), 50);
  1053. }
  1054. function createImageData(assetData) {
  1055. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1056. var img = createNS('image');
  1057. if (isSafari) {
  1058. this.testImageLoaded(img);
  1059. } else {
  1060. img.addEventListener('load', this._imageLoaded, false);
  1061. }
  1062. img.addEventListener('error', function () {
  1063. ob.img = proxyImage;
  1064. this._imageLoaded();
  1065. }.bind(this), false);
  1066. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1067. if (this._elementHelper.append) {
  1068. this._elementHelper.append(img);
  1069. } else {
  1070. this._elementHelper.appendChild(img);
  1071. }
  1072. var ob = {
  1073. img: img,
  1074. assetData: assetData,
  1075. };
  1076. return ob;
  1077. }
  1078. function createImgData(assetData) {
  1079. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1080. var img = createTag('img');
  1081. img.crossOrigin = 'anonymous';
  1082. img.addEventListener('load', this._imageLoaded, false);
  1083. img.addEventListener('error', function () {
  1084. ob.img = proxyImage;
  1085. this._imageLoaded();
  1086. }.bind(this), false);
  1087. img.src = path;
  1088. var ob = {
  1089. img: img,
  1090. assetData: assetData,
  1091. };
  1092. return ob;
  1093. }
  1094. function createFootageData(data) {
  1095. var ob = {
  1096. assetData: data,
  1097. };
  1098. var path = getAssetsPath(data, this.assetsPath, this.path);
  1099. dataManager.loadData(path, function (footageData) {
  1100. ob.img = footageData;
  1101. this._footageLoaded();
  1102. }.bind(this), function () {
  1103. ob.img = {};
  1104. this._footageLoaded();
  1105. }.bind(this));
  1106. return ob;
  1107. }
  1108. function loadAssets(assets, cb) {
  1109. this.imagesLoadedCb = cb;
  1110. var i;
  1111. var len = assets.length;
  1112. for (i = 0; i < len; i += 1) {
  1113. if (!assets[i].layers) {
  1114. if (!assets[i].t || assets[i].t === 'seq') {
  1115. this.totalImages += 1;
  1116. this.images.push(this._createImageData(assets[i]));
  1117. } else if (assets[i].t === 3) {
  1118. this.totalFootages += 1;
  1119. this.images.push(this.createFootageData(assets[i]));
  1120. }
  1121. }
  1122. }
  1123. }
  1124. function setPath(path) {
  1125. this.path = path || '';
  1126. }
  1127. function setAssetsPath(path) {
  1128. this.assetsPath = path || '';
  1129. }
  1130. function getAsset(assetData) {
  1131. var i = 0;
  1132. var len = this.images.length;
  1133. while (i < len) {
  1134. if (this.images[i].assetData === assetData) {
  1135. return this.images[i].img;
  1136. }
  1137. i += 1;
  1138. }
  1139. return null;
  1140. }
  1141. function destroy() {
  1142. this.imagesLoadedCb = null;
  1143. this.images.length = 0;
  1144. }
  1145. function loadedImages() {
  1146. return this.totalImages === this.loadedAssets;
  1147. }
  1148. function loadedFootages() {
  1149. return this.totalFootages === this.loadedFootagesCount;
  1150. }
  1151. function setCacheType(type, elementHelper) {
  1152. if (type === 'svg') {
  1153. this._elementHelper = elementHelper;
  1154. this._createImageData = this.createImageData.bind(this);
  1155. } else {
  1156. this._createImageData = this.createImgData.bind(this);
  1157. }
  1158. }
  1159. function ImagePreloaderFactory() {
  1160. this._imageLoaded = imageLoaded.bind(this);
  1161. this._footageLoaded = footageLoaded.bind(this);
  1162. this.testImageLoaded = testImageLoaded.bind(this);
  1163. this.createFootageData = createFootageData.bind(this);
  1164. this.assetsPath = '';
  1165. this.path = '';
  1166. this.totalImages = 0;
  1167. this.totalFootages = 0;
  1168. this.loadedAssets = 0;
  1169. this.loadedFootagesCount = 0;
  1170. this.imagesLoadedCb = null;
  1171. this.images = [];
  1172. }
  1173. ImagePreloaderFactory.prototype = {
  1174. loadAssets: loadAssets,
  1175. setAssetsPath: setAssetsPath,
  1176. setPath: setPath,
  1177. loadedImages: loadedImages,
  1178. loadedFootages: loadedFootages,
  1179. destroy: destroy,
  1180. getAsset: getAsset,
  1181. createImgData: createImgData,
  1182. createImageData: createImageData,
  1183. imageLoaded: imageLoaded,
  1184. footageLoaded: footageLoaded,
  1185. setCacheType: setCacheType,
  1186. };
  1187. return ImagePreloaderFactory;
  1188. }());
  1189. function BaseEvent() {}
  1190. BaseEvent.prototype = {
  1191. triggerEvent: function (eventName, args) {
  1192. if (this._cbs[eventName]) {
  1193. var callbacks = this._cbs[eventName];
  1194. for (var i = 0; i < callbacks.length; i += 1) {
  1195. callbacks[i](args);
  1196. }
  1197. }
  1198. },
  1199. addEventListener: function (eventName, callback) {
  1200. if (!this._cbs[eventName]) {
  1201. this._cbs[eventName] = [];
  1202. }
  1203. this._cbs[eventName].push(callback);
  1204. return function () {
  1205. this.removeEventListener(eventName, callback);
  1206. }.bind(this);
  1207. },
  1208. removeEventListener: function (eventName, callback) {
  1209. if (!callback) {
  1210. this._cbs[eventName] = null;
  1211. } else if (this._cbs[eventName]) {
  1212. var i = 0;
  1213. var len = this._cbs[eventName].length;
  1214. while (i < len) {
  1215. if (this._cbs[eventName][i] === callback) {
  1216. this._cbs[eventName].splice(i, 1);
  1217. i -= 1;
  1218. len -= 1;
  1219. }
  1220. i += 1;
  1221. }
  1222. if (!this._cbs[eventName].length) {
  1223. this._cbs[eventName] = null;
  1224. }
  1225. }
  1226. },
  1227. };
  1228. const markerParser = (
  1229. function () {
  1230. function parsePayloadLines(payload) {
  1231. var lines = payload.split('\r\n');
  1232. var keys = {};
  1233. var line;
  1234. var keysCount = 0;
  1235. for (var i = 0; i < lines.length; i += 1) {
  1236. line = lines[i].split(':');
  1237. if (line.length === 2) {
  1238. keys[line[0]] = line[1].trim();
  1239. keysCount += 1;
  1240. }
  1241. }
  1242. if (keysCount === 0) {
  1243. throw new Error();
  1244. }
  1245. return keys;
  1246. }
  1247. return function (_markers) {
  1248. var markers = [];
  1249. for (var i = 0; i < _markers.length; i += 1) {
  1250. var _marker = _markers[i];
  1251. var markerData = {
  1252. time: _marker.tm,
  1253. duration: _marker.dr,
  1254. };
  1255. try {
  1256. markerData.payload = JSON.parse(_markers[i].cm);
  1257. } catch (_) {
  1258. try {
  1259. markerData.payload = parsePayloadLines(_markers[i].cm);
  1260. } catch (__) {
  1261. markerData.payload = {
  1262. name: _markers[i].cm,
  1263. };
  1264. }
  1265. }
  1266. markers.push(markerData);
  1267. }
  1268. return markers;
  1269. };
  1270. }());
  1271. const ProjectInterface = (function () {
  1272. function registerComposition(comp) {
  1273. this.compositions.push(comp);
  1274. }
  1275. return function () {
  1276. function _thisProjectFunction(name) {
  1277. var i = 0;
  1278. var len = this.compositions.length;
  1279. while (i < len) {
  1280. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1281. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1282. this.compositions[i].prepareFrame(this.currentFrame);
  1283. }
  1284. return this.compositions[i].compInterface;
  1285. }
  1286. i += 1;
  1287. }
  1288. return null;
  1289. }
  1290. _thisProjectFunction.compositions = [];
  1291. _thisProjectFunction.currentFrame = 0;
  1292. _thisProjectFunction.registerComposition = registerComposition;
  1293. return _thisProjectFunction;
  1294. };
  1295. }());
  1296. const renderers = {};
  1297. const registerRenderer = (key, value) => {
  1298. renderers[key] = value;
  1299. };
  1300. function getRenderer(key) {
  1301. return renderers[key];
  1302. }
  1303. function getRegisteredRenderer() {
  1304. // Returns canvas by default for compatibility
  1305. if (renderers.canvas) {
  1306. return 'canvas';
  1307. }
  1308. // Returns any renderer that is registered
  1309. for (const key in renderers) {
  1310. if (renderers[key]) {
  1311. return key;
  1312. }
  1313. }
  1314. return '';
  1315. }
  1316. const AnimationItem = function () {
  1317. this._cbs = [];
  1318. this.name = '';
  1319. this.path = '';
  1320. this.isLoaded = false;
  1321. this.currentFrame = 0;
  1322. this.currentRawFrame = 0;
  1323. this.firstFrame = 0;
  1324. this.totalFrames = 0;
  1325. this.frameRate = 0;
  1326. this.frameMult = 0;
  1327. this.playSpeed = 1;
  1328. this.playDirection = 1;
  1329. this.playCount = 0;
  1330. this.animationData = {};
  1331. this.assets = [];
  1332. this.isPaused = true;
  1333. this.autoplay = false;
  1334. this.loop = true;
  1335. this.renderer = null;
  1336. this.animationID = createElementID();
  1337. this.assetsPath = '';
  1338. this.timeCompleted = 0;
  1339. this.segmentPos = 0;
  1340. this.isSubframeEnabled = getSubframeEnabled();
  1341. this.segments = [];
  1342. this._idle = true;
  1343. this._completedLoop = false;
  1344. this.projectInterface = ProjectInterface();
  1345. this.imagePreloader = new ImagePreloader();
  1346. this.audioController = audioControllerFactory();
  1347. this.markers = [];
  1348. this.configAnimation = this.configAnimation.bind(this);
  1349. this.onSetupError = this.onSetupError.bind(this);
  1350. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1351. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1352. this.expressionsPlugin = getExpressionsPlugin();
  1353. };
  1354. extendPrototype([BaseEvent], AnimationItem);
  1355. AnimationItem.prototype.setParams = function (params) {
  1356. if (params.wrapper || params.container) {
  1357. this.wrapper = params.wrapper || params.container;
  1358. }
  1359. var animType = 'svg';
  1360. if (params.animType) {
  1361. animType = params.animType;
  1362. } else if (params.renderer) {
  1363. animType = params.renderer;
  1364. }
  1365. const RendererClass = getRenderer(animType);
  1366. this.renderer = new RendererClass(this, params.rendererSettings);
  1367. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1368. this.renderer.setProjectInterface(this.projectInterface);
  1369. this.animType = animType;
  1370. if (params.loop === ''
  1371. || params.loop === null
  1372. || params.loop === undefined
  1373. || params.loop === true) {
  1374. this.loop = true;
  1375. } else if (params.loop === false) {
  1376. this.loop = false;
  1377. } else {
  1378. this.loop = parseInt(params.loop, 10);
  1379. }
  1380. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1381. this.name = params.name ? params.name : '';
  1382. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1383. this.assetsPath = params.assetsPath;
  1384. this.initialSegment = params.initialSegment;
  1385. if (params.audioFactory) {
  1386. this.audioController.setAudioFactory(params.audioFactory);
  1387. }
  1388. if (params.animationData) {
  1389. this.setupAnimation(params.animationData);
  1390. } else if (params.path) {
  1391. if (params.path.lastIndexOf('\\') !== -1) {
  1392. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1393. } else {
  1394. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1395. }
  1396. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1397. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1398. dataManager.loadAnimation(
  1399. params.path,
  1400. this.configAnimation,
  1401. this.onSetupError
  1402. );
  1403. }
  1404. };
  1405. AnimationItem.prototype.onSetupError = function () {
  1406. this.trigger('data_failed');
  1407. };
  1408. AnimationItem.prototype.setupAnimation = function (data) {
  1409. dataManager.completeAnimation(
  1410. data,
  1411. this.configAnimation
  1412. );
  1413. };
  1414. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1415. if (animationData) {
  1416. if (typeof animationData !== 'object') {
  1417. animationData = JSON.parse(animationData);
  1418. }
  1419. }
  1420. var params = {
  1421. wrapper: wrapper,
  1422. animationData: animationData,
  1423. };
  1424. var wrapperAttributes = wrapper.attributes;
  1425. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1426. ? wrapperAttributes.getNamedItem('data-animation-path').value
  1427. : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1428. ? wrapperAttributes.getNamedItem('data-bm-path').value
  1429. : wrapperAttributes.getNamedItem('bm-path')
  1430. ? wrapperAttributes.getNamedItem('bm-path').value
  1431. : '';
  1432. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1433. ? wrapperAttributes.getNamedItem('data-anim-type').value
  1434. : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1435. ? wrapperAttributes.getNamedItem('data-bm-type').value
  1436. : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1437. ? wrapperAttributes.getNamedItem('bm-type').value
  1438. : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1439. ? wrapperAttributes.getNamedItem('data-bm-renderer').value
  1440. : wrapperAttributes.getNamedItem('bm-renderer')
  1441. ? wrapperAttributes.getNamedItem('bm-renderer').value
  1442. : getRegisteredRenderer() || 'canvas';
  1443. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1444. ? wrapperAttributes.getNamedItem('data-anim-loop').value
  1445. : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1446. ? wrapperAttributes.getNamedItem('data-bm-loop').value
  1447. : wrapperAttributes.getNamedItem('bm-loop')
  1448. ? wrapperAttributes.getNamedItem('bm-loop').value
  1449. : '';
  1450. if (loop === 'false') {
  1451. params.loop = false;
  1452. } else if (loop === 'true') {
  1453. params.loop = true;
  1454. } else if (loop !== '') {
  1455. params.loop = parseInt(loop, 10);
  1456. }
  1457. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1458. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value
  1459. : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1460. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value
  1461. : wrapperAttributes.getNamedItem('bm-autoplay')
  1462. ? wrapperAttributes.getNamedItem('bm-autoplay').value
  1463. : true;
  1464. params.autoplay = autoplay !== 'false';
  1465. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1466. ? wrapperAttributes.getNamedItem('data-name').value
  1467. : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1468. ? wrapperAttributes.getNamedItem('data-bm-name').value
  1469. : wrapperAttributes.getNamedItem('bm-name')
  1470. ? wrapperAttributes.getNamedItem('bm-name').value
  1471. : '';
  1472. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1473. ? wrapperAttributes.getNamedItem('data-anim-prerender').value
  1474. : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1475. ? wrapperAttributes.getNamedItem('data-bm-prerender').value
  1476. : wrapperAttributes.getNamedItem('bm-prerender')
  1477. ? wrapperAttributes.getNamedItem('bm-prerender').value
  1478. : '';
  1479. if (prerender === 'false') {
  1480. params.prerender = false;
  1481. }
  1482. if (!params.path) {
  1483. this.trigger('destroy');
  1484. } else {
  1485. this.setParams(params);
  1486. }
  1487. };
  1488. AnimationItem.prototype.includeLayers = function (data) {
  1489. if (data.op > this.animationData.op) {
  1490. this.animationData.op = data.op;
  1491. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1492. }
  1493. var layers = this.animationData.layers;
  1494. var i;
  1495. var len = layers.length;
  1496. var newLayers = data.layers;
  1497. var j;
  1498. var jLen = newLayers.length;
  1499. for (j = 0; j < jLen; j += 1) {
  1500. i = 0;
  1501. while (i < len) {
  1502. if (layers[i].id === newLayers[j].id) {
  1503. layers[i] = newLayers[j];
  1504. break;
  1505. }
  1506. i += 1;
  1507. }
  1508. }
  1509. if (data.chars || data.fonts) {
  1510. this.renderer.globalData.fontManager.addChars(data.chars);
  1511. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1512. }
  1513. if (data.assets) {
  1514. len = data.assets.length;
  1515. for (i = 0; i < len; i += 1) {
  1516. this.animationData.assets.push(data.assets[i]);
  1517. }
  1518. }
  1519. this.animationData.__complete = false;
  1520. dataManager.completeAnimation(
  1521. this.animationData,
  1522. this.onSegmentComplete
  1523. );
  1524. };
  1525. AnimationItem.prototype.onSegmentComplete = function (data) {
  1526. this.animationData = data;
  1527. var expressionsPlugin = getExpressionsPlugin();
  1528. if (expressionsPlugin) {
  1529. expressionsPlugin.initExpressions(this);
  1530. }
  1531. this.loadNextSegment();
  1532. };
  1533. AnimationItem.prototype.loadNextSegment = function () {
  1534. var segments = this.animationData.segments;
  1535. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1536. this.trigger('data_ready');
  1537. this.timeCompleted = this.totalFrames;
  1538. return;
  1539. }
  1540. var segment = segments.shift();
  1541. this.timeCompleted = segment.time * this.frameRate;
  1542. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1543. this.segmentPos += 1;
  1544. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1545. this.trigger('data_failed');
  1546. }.bind(this));
  1547. };
  1548. AnimationItem.prototype.loadSegments = function () {
  1549. var segments = this.animationData.segments;
  1550. if (!segments) {
  1551. this.timeCompleted = this.totalFrames;
  1552. }
  1553. this.loadNextSegment();
  1554. };
  1555. AnimationItem.prototype.imagesLoaded = function () {
  1556. this.trigger('loaded_images');
  1557. this.checkLoaded();
  1558. };
  1559. AnimationItem.prototype.preloadImages = function () {
  1560. this.imagePreloader.setAssetsPath(this.assetsPath);
  1561. this.imagePreloader.setPath(this.path);
  1562. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1563. };
  1564. AnimationItem.prototype.configAnimation = function (animData) {
  1565. if (!this.renderer) {
  1566. return;
  1567. }
  1568. try {
  1569. this.animationData = animData;
  1570. if (this.initialSegment) {
  1571. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1572. this.firstFrame = Math.round(this.initialSegment[0]);
  1573. } else {
  1574. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1575. this.firstFrame = Math.round(this.animationData.ip);
  1576. }
  1577. this.renderer.configAnimation(animData);
  1578. if (!animData.assets) {
  1579. animData.assets = [];
  1580. }
  1581. this.assets = this.animationData.assets;
  1582. this.frameRate = this.animationData.fr;
  1583. this.frameMult = this.animationData.fr / 1000;
  1584. this.renderer.searchExtraCompositions(animData.assets);
  1585. this.markers = markerParser(animData.markers || []);
  1586. this.trigger('config_ready');
  1587. this.preloadImages();
  1588. this.loadSegments();
  1589. this.updaFrameModifier();
  1590. this.waitForFontsLoaded();
  1591. if (this.isPaused) {
  1592. this.audioController.pause();
  1593. }
  1594. } catch (error) {
  1595. this.triggerConfigError(error);
  1596. }
  1597. };
  1598. AnimationItem.prototype.waitForFontsLoaded = function () {
  1599. if (!this.renderer) {
  1600. return;
  1601. }
  1602. if (this.renderer.globalData.fontManager.isLoaded) {
  1603. this.checkLoaded();
  1604. } else {
  1605. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1606. }
  1607. };
  1608. AnimationItem.prototype.checkLoaded = function () {
  1609. if (!this.isLoaded
  1610. && this.renderer.globalData.fontManager.isLoaded
  1611. && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas')
  1612. && (this.imagePreloader.loadedFootages())
  1613. ) {
  1614. this.isLoaded = true;
  1615. var expressionsPlugin = getExpressionsPlugin();
  1616. if (expressionsPlugin) {
  1617. expressionsPlugin.initExpressions(this);
  1618. }
  1619. this.renderer.initItems();
  1620. setTimeout(function () {
  1621. this.trigger('DOMLoaded');
  1622. }.bind(this), 0);
  1623. this.gotoFrame();
  1624. if (this.autoplay) {
  1625. this.play();
  1626. }
  1627. }
  1628. };
  1629. AnimationItem.prototype.resize = function (width, height) {
  1630. // Adding this validation for backwards compatibility in case an event object was being passed down
  1631. var _width = typeof width === 'number' ? width : undefined;
  1632. var _height = typeof height === 'number' ? height : undefined;
  1633. this.renderer.updateContainerSize(_width, _height);
  1634. };
  1635. AnimationItem.prototype.setSubframe = function (flag) {
  1636. this.isSubframeEnabled = !!flag;
  1637. };
  1638. AnimationItem.prototype.gotoFrame = function () {
  1639. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1640. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1641. this.currentFrame = this.timeCompleted;
  1642. }
  1643. this.trigger('enterFrame');
  1644. this.renderFrame();
  1645. this.trigger('drawnFrame');
  1646. };
  1647. AnimationItem.prototype.renderFrame = function () {
  1648. if (this.isLoaded === false || !this.renderer) {
  1649. return;
  1650. }
  1651. try {
  1652. if (this.expressionsPlugin) {
  1653. this.expressionsPlugin.resetFrame();
  1654. }
  1655. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1656. } catch (error) {
  1657. this.triggerRenderFrameError(error);
  1658. }
  1659. };
  1660. AnimationItem.prototype.play = function (name) {
  1661. if (name && this.name !== name) {
  1662. return;
  1663. }
  1664. if (this.isPaused === true) {
  1665. this.isPaused = false;
  1666. this.trigger('_play');
  1667. this.audioController.resume();
  1668. if (this._idle) {
  1669. this._idle = false;
  1670. this.trigger('_active');
  1671. }
  1672. }
  1673. };
  1674. AnimationItem.prototype.pause = function (name) {
  1675. if (name && this.name !== name) {
  1676. return;
  1677. }
  1678. if (this.isPaused === false) {
  1679. this.isPaused = true;
  1680. this.trigger('_pause');
  1681. this._idle = true;
  1682. this.trigger('_idle');
  1683. this.audioController.pause();
  1684. }
  1685. };
  1686. AnimationItem.prototype.togglePause = function (name) {
  1687. if (name && this.name !== name) {
  1688. return;
  1689. }
  1690. if (this.isPaused === true) {
  1691. this.play();
  1692. } else {
  1693. this.pause();
  1694. }
  1695. };
  1696. AnimationItem.prototype.stop = function (name) {
  1697. if (name && this.name !== name) {
  1698. return;
  1699. }
  1700. this.pause();
  1701. this.playCount = 0;
  1702. this._completedLoop = false;
  1703. this.setCurrentRawFrameValue(0);
  1704. };
  1705. AnimationItem.prototype.getMarkerData = function (markerName) {
  1706. var marker;
  1707. for (var i = 0; i < this.markers.length; i += 1) {
  1708. marker = this.markers[i];
  1709. if (marker.payload && marker.payload.name === markerName) {
  1710. return marker;
  1711. }
  1712. }
  1713. return null;
  1714. };
  1715. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1716. if (name && this.name !== name) {
  1717. return;
  1718. }
  1719. var numValue = Number(value);
  1720. if (isNaN(numValue)) {
  1721. var marker = this.getMarkerData(value);
  1722. if (marker) {
  1723. this.goToAndStop(marker.time, true);
  1724. }
  1725. } else if (isFrame) {
  1726. this.setCurrentRawFrameValue(value);
  1727. } else {
  1728. this.setCurrentRawFrameValue(value * this.frameModifier);
  1729. }
  1730. this.pause();
  1731. };
  1732. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1733. if (name && this.name !== name) {
  1734. return;
  1735. }
  1736. var numValue = Number(value);
  1737. if (isNaN(numValue)) {
  1738. var marker = this.getMarkerData(value);
  1739. if (marker) {
  1740. if (!marker.duration) {
  1741. this.goToAndStop(marker.time, true);
  1742. } else {
  1743. this.playSegments([marker.time, marker.time + marker.duration], true);
  1744. }
  1745. }
  1746. } else {
  1747. this.goToAndStop(numValue, isFrame, name);
  1748. }
  1749. this.play();
  1750. };
  1751. AnimationItem.prototype.advanceTime = function (value) {
  1752. if (this.isPaused === true || this.isLoaded === false) {
  1753. return;
  1754. }
  1755. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1756. var _isComplete = false;
  1757. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1758. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1759. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1760. if (!this.loop || this.playCount === this.loop) {
  1761. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1762. _isComplete = true;
  1763. nextValue = this.totalFrames - 1;
  1764. }
  1765. } else if (nextValue >= this.totalFrames) {
  1766. this.playCount += 1;
  1767. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1768. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1769. this._completedLoop = true;
  1770. this.trigger('loopComplete');
  1771. }
  1772. } else {
  1773. this.setCurrentRawFrameValue(nextValue);
  1774. }
  1775. } else if (nextValue < 0) {
  1776. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1777. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) { // eslint-disable-line no-plusplus
  1778. this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames));
  1779. if (!this._completedLoop) {
  1780. this._completedLoop = true;
  1781. } else {
  1782. this.trigger('loopComplete');
  1783. }
  1784. } else {
  1785. _isComplete = true;
  1786. nextValue = 0;
  1787. }
  1788. }
  1789. } else {
  1790. this.setCurrentRawFrameValue(nextValue);
  1791. }
  1792. if (_isComplete) {
  1793. this.setCurrentRawFrameValue(nextValue);
  1794. this.pause();
  1795. this.trigger('complete');
  1796. }
  1797. };
  1798. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1799. this.playCount = 0;
  1800. if (arr[1] < arr[0]) {
  1801. if (this.frameModifier > 0) {
  1802. if (this.playSpeed < 0) {
  1803. this.setSpeed(-this.playSpeed);
  1804. } else {
  1805. this.setDirection(-1);
  1806. }
  1807. }
  1808. this.totalFrames = arr[0] - arr[1];
  1809. this.timeCompleted = this.totalFrames;
  1810. this.firstFrame = arr[1];
  1811. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1812. } else if (arr[1] > arr[0]) {
  1813. if (this.frameModifier < 0) {
  1814. if (this.playSpeed < 0) {
  1815. this.setSpeed(-this.playSpeed);
  1816. } else {
  1817. this.setDirection(1);
  1818. }
  1819. }
  1820. this.totalFrames = arr[1] - arr[0];
  1821. this.timeCompleted = this.totalFrames;
  1822. this.firstFrame = arr[0];
  1823. this.setCurrentRawFrameValue(0.001 + offset);
  1824. }
  1825. this.trigger('segmentStart');
  1826. };
  1827. AnimationItem.prototype.setSegment = function (init, end) {
  1828. var pendingFrame = -1;
  1829. if (this.isPaused) {
  1830. if (this.currentRawFrame + this.firstFrame < init) {
  1831. pendingFrame = init;
  1832. } else if (this.currentRawFrame + this.firstFrame > end) {
  1833. pendingFrame = end - init;
  1834. }
  1835. }
  1836. this.firstFrame = init;
  1837. this.totalFrames = end - init;
  1838. this.timeCompleted = this.totalFrames;
  1839. if (pendingFrame !== -1) {
  1840. this.goToAndStop(pendingFrame, true);
  1841. }
  1842. };
  1843. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1844. if (forceFlag) {
  1845. this.segments.length = 0;
  1846. }
  1847. if (typeof arr[0] === 'object') {
  1848. var i;
  1849. var len = arr.length;
  1850. for (i = 0; i < len; i += 1) {
  1851. this.segments.push(arr[i]);
  1852. }
  1853. } else {
  1854. this.segments.push(arr);
  1855. }
  1856. if (this.segments.length && forceFlag) {
  1857. this.adjustSegment(this.segments.shift(), 0);
  1858. }
  1859. if (this.isPaused) {
  1860. this.play();
  1861. }
  1862. };
  1863. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1864. this.segments.length = 0;
  1865. this.segments.push([this.animationData.ip, this.animationData.op]);
  1866. if (forceFlag) {
  1867. this.checkSegments(0);
  1868. }
  1869. };
  1870. AnimationItem.prototype.checkSegments = function (offset) {
  1871. if (this.segments.length) {
  1872. this.adjustSegment(this.segments.shift(), offset);
  1873. return true;
  1874. }
  1875. return false;
  1876. };
  1877. AnimationItem.prototype.destroy = function (name) {
  1878. if ((name && this.name !== name) || !this.renderer) {
  1879. return;
  1880. }
  1881. this.renderer.destroy();
  1882. this.imagePreloader.destroy();
  1883. this.trigger('destroy');
  1884. this._cbs = null;
  1885. this.onEnterFrame = null;
  1886. this.onLoopComplete = null;
  1887. this.onComplete = null;
  1888. this.onSegmentStart = null;
  1889. this.onDestroy = null;
  1890. this.renderer = null;
  1891. this.expressionsPlugin = null;
  1892. this.imagePreloader = null;
  1893. this.projectInterface = null;
  1894. };
  1895. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1896. this.currentRawFrame = value;
  1897. this.gotoFrame();
  1898. };
  1899. AnimationItem.prototype.setSpeed = function (val) {
  1900. this.playSpeed = val;
  1901. this.updaFrameModifier();
  1902. };
  1903. AnimationItem.prototype.setDirection = function (val) {
  1904. this.playDirection = val < 0 ? -1 : 1;
  1905. this.updaFrameModifier();
  1906. };
  1907. AnimationItem.prototype.setLoop = function (isLooping) {
  1908. this.loop = isLooping;
  1909. };
  1910. AnimationItem.prototype.setVolume = function (val, name) {
  1911. if (name && this.name !== name) {
  1912. return;
  1913. }
  1914. this.audioController.setVolume(val);
  1915. };
  1916. AnimationItem.prototype.getVolume = function () {
  1917. return this.audioController.getVolume();
  1918. };
  1919. AnimationItem.prototype.mute = function (name) {
  1920. if (name && this.name !== name) {
  1921. return;
  1922. }
  1923. this.audioController.mute();
  1924. };
  1925. AnimationItem.prototype.unmute = function (name) {
  1926. if (name && this.name !== name) {
  1927. return;
  1928. }
  1929. this.audioController.unmute();
  1930. };
  1931. AnimationItem.prototype.updaFrameModifier = function () {
  1932. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1933. this.audioController.setRate(this.playSpeed * this.playDirection);
  1934. };
  1935. AnimationItem.prototype.getPath = function () {
  1936. return this.path;
  1937. };
  1938. AnimationItem.prototype.getAssetsPath = function (assetData) {
  1939. var path = '';
  1940. if (assetData.e) {
  1941. path = assetData.p;
  1942. } else if (this.assetsPath) {
  1943. var imagePath = assetData.p;
  1944. if (imagePath.indexOf('images/') !== -1) {
  1945. imagePath = imagePath.split('/')[1];
  1946. }
  1947. path = this.assetsPath + imagePath;
  1948. } else {
  1949. path = this.path;
  1950. path += assetData.u ? assetData.u : '';
  1951. path += assetData.p;
  1952. }
  1953. return path;
  1954. };
  1955. AnimationItem.prototype.getAssetData = function (id) {
  1956. var i = 0;
  1957. var len = this.assets.length;
  1958. while (i < len) {
  1959. if (id === this.assets[i].id) {
  1960. return this.assets[i];
  1961. }
  1962. i += 1;
  1963. }
  1964. return null;
  1965. };
  1966. AnimationItem.prototype.hide = function () {
  1967. this.renderer.hide();
  1968. };
  1969. AnimationItem.prototype.show = function () {
  1970. this.renderer.show();
  1971. };
  1972. AnimationItem.prototype.getDuration = function (isFrame) {
  1973. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  1974. };
  1975. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  1976. try {
  1977. var element = this.renderer.getElementByPath(path);
  1978. element.updateDocumentData(documentData, index);
  1979. } catch (error) {
  1980. // TODO: decide how to handle catch case
  1981. }
  1982. };
  1983. AnimationItem.prototype.trigger = function (name) {
  1984. if (this._cbs && this._cbs[name]) {
  1985. switch (name) {
  1986. case 'enterFrame':
  1987. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  1988. break;
  1989. case 'drawnFrame':
  1990. this.drawnFrameEvent.currentTime = this.currentFrame;
  1991. this.drawnFrameEvent.totalTime = this.totalFrames;
  1992. this.drawnFrameEvent.direction = this.frameModifier;
  1993. this.triggerEvent(name, this.drawnFrameEvent);
  1994. break;
  1995. case 'loopComplete':
  1996. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  1997. break;
  1998. case 'complete':
  1999. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  2000. break;
  2001. case 'segmentStart':
  2002. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2003. break;
  2004. case 'destroy':
  2005. this.triggerEvent(name, new BMDestroyEvent(name, this));
  2006. break;
  2007. default:
  2008. this.triggerEvent(name);
  2009. }
  2010. }
  2011. if (name === 'enterFrame' && this.onEnterFrame) {
  2012. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  2013. }
  2014. if (name === 'loopComplete' && this.onLoopComplete) {
  2015. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2016. }
  2017. if (name === 'complete' && this.onComplete) {
  2018. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  2019. }
  2020. if (name === 'segmentStart' && this.onSegmentStart) {
  2021. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2022. }
  2023. if (name === 'destroy' && this.onDestroy) {
  2024. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  2025. }
  2026. };
  2027. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  2028. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2029. this.triggerEvent('error', error);
  2030. if (this.onError) {
  2031. this.onError.call(this, error);
  2032. }
  2033. };
  2034. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2035. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2036. this.triggerEvent('error', error);
  2037. if (this.onError) {
  2038. this.onError.call(this, error);
  2039. }
  2040. };
  2041. const animationManager = (function () {
  2042. var moduleOb = {};
  2043. var registeredAnimations = [];
  2044. var initTime = 0;
  2045. var len = 0;
  2046. var playingAnimationsNum = 0;
  2047. var _stopped = true;
  2048. var _isFrozen = false;
  2049. function removeElement(ev) {
  2050. var i = 0;
  2051. var animItem = ev.target;
  2052. while (i < len) {
  2053. if (registeredAnimations[i].animation === animItem) {
  2054. registeredAnimations.splice(i, 1);
  2055. i -= 1;
  2056. len -= 1;
  2057. if (!animItem.isPaused) {
  2058. subtractPlayingCount();
  2059. }
  2060. }
  2061. i += 1;
  2062. }
  2063. }
  2064. function registerAnimation(element, animationData) {
  2065. if (!element) {
  2066. return null;
  2067. }
  2068. var i = 0;
  2069. while (i < len) {
  2070. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2071. return registeredAnimations[i].animation;
  2072. }
  2073. i += 1;
  2074. }
  2075. var animItem = new AnimationItem();
  2076. setupAnimation(animItem, element);
  2077. animItem.setData(element, animationData);
  2078. return animItem;
  2079. }
  2080. function getRegisteredAnimations() {
  2081. var i;
  2082. var lenAnims = registeredAnimations.length;
  2083. var animations = [];
  2084. for (i = 0; i < lenAnims; i += 1) {
  2085. animations.push(registeredAnimations[i].animation);
  2086. }
  2087. return animations;
  2088. }
  2089. function addPlayingCount() {
  2090. playingAnimationsNum += 1;
  2091. activate();
  2092. }
  2093. function subtractPlayingCount() {
  2094. playingAnimationsNum -= 1;
  2095. }
  2096. function setupAnimation(animItem, element) {
  2097. animItem.addEventListener('destroy', removeElement);
  2098. animItem.addEventListener('_active', addPlayingCount);
  2099. animItem.addEventListener('_idle', subtractPlayingCount);
  2100. registeredAnimations.push({ elem: element, animation: animItem });
  2101. len += 1;
  2102. }
  2103. function loadAnimation(params) {
  2104. var animItem = new AnimationItem();
  2105. setupAnimation(animItem, null);
  2106. animItem.setParams(params);
  2107. return animItem;
  2108. }
  2109. function setSpeed(val, animation) {
  2110. var i;
  2111. for (i = 0; i < len; i += 1) {
  2112. registeredAnimations[i].animation.setSpeed(val, animation);
  2113. }
  2114. }
  2115. function setDirection(val, animation) {
  2116. var i;
  2117. for (i = 0; i < len; i += 1) {
  2118. registeredAnimations[i].animation.setDirection(val, animation);
  2119. }
  2120. }
  2121. function play(animation) {
  2122. var i;
  2123. for (i = 0; i < len; i += 1) {
  2124. registeredAnimations[i].animation.play(animation);
  2125. }
  2126. }
  2127. function resume(nowTime) {
  2128. var elapsedTime = nowTime - initTime;
  2129. var i;
  2130. for (i = 0; i < len; i += 1) {
  2131. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2132. }
  2133. initTime = nowTime;
  2134. if (playingAnimationsNum && !_isFrozen) {
  2135. window.requestAnimationFrame(resume);
  2136. } else {
  2137. _stopped = true;
  2138. }
  2139. }
  2140. function first(nowTime) {
  2141. initTime = nowTime;
  2142. window.requestAnimationFrame(resume);
  2143. }
  2144. function pause(animation) {
  2145. var i;
  2146. for (i = 0; i < len; i += 1) {
  2147. registeredAnimations[i].animation.pause(animation);
  2148. }
  2149. }
  2150. function goToAndStop(value, isFrame, animation) {
  2151. var i;
  2152. for (i = 0; i < len; i += 1) {
  2153. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2154. }
  2155. }
  2156. function stop(animation) {
  2157. var i;
  2158. for (i = 0; i < len; i += 1) {
  2159. registeredAnimations[i].animation.stop(animation);
  2160. }
  2161. }
  2162. function togglePause(animation) {
  2163. var i;
  2164. for (i = 0; i < len; i += 1) {
  2165. registeredAnimations[i].animation.togglePause(animation);
  2166. }
  2167. }
  2168. function destroy(animation) {
  2169. var i;
  2170. for (i = (len - 1); i >= 0; i -= 1) {
  2171. registeredAnimations[i].animation.destroy(animation);
  2172. }
  2173. }
  2174. function searchAnimations(animationData, standalone, renderer) {
  2175. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')),
  2176. [].slice.call(document.getElementsByClassName('bodymovin')));
  2177. var i;
  2178. var lenAnims = animElements.length;
  2179. for (i = 0; i < lenAnims; i += 1) {
  2180. if (renderer) {
  2181. animElements[i].setAttribute('data-bm-type', renderer);
  2182. }
  2183. registerAnimation(animElements[i], animationData);
  2184. }
  2185. if (standalone && lenAnims === 0) {
  2186. if (!renderer) {
  2187. renderer = 'svg';
  2188. }
  2189. var body = document.getElementsByTagName('body')[0];
  2190. body.innerText = '';
  2191. var div = createTag('div');
  2192. div.style.width = '100%';
  2193. div.style.height = '100%';
  2194. div.setAttribute('data-bm-type', renderer);
  2195. body.appendChild(div);
  2196. registerAnimation(div, animationData);
  2197. }
  2198. }
  2199. function resize() {
  2200. var i;
  2201. for (i = 0; i < len; i += 1) {
  2202. registeredAnimations[i].animation.resize();
  2203. }
  2204. }
  2205. function activate() {
  2206. if (!_isFrozen && playingAnimationsNum) {
  2207. if (_stopped) {
  2208. window.requestAnimationFrame(first);
  2209. _stopped = false;
  2210. }
  2211. }
  2212. }
  2213. function freeze() {
  2214. _isFrozen = true;
  2215. }
  2216. function unfreeze() {
  2217. _isFrozen = false;
  2218. activate();
  2219. }
  2220. function setVolume(val, animation) {
  2221. var i;
  2222. for (i = 0; i < len; i += 1) {
  2223. registeredAnimations[i].animation.setVolume(val, animation);
  2224. }
  2225. }
  2226. function mute(animation) {
  2227. var i;
  2228. for (i = 0; i < len; i += 1) {
  2229. registeredAnimations[i].animation.mute(animation);
  2230. }
  2231. }
  2232. function unmute(animation) {
  2233. var i;
  2234. for (i = 0; i < len; i += 1) {
  2235. registeredAnimations[i].animation.unmute(animation);
  2236. }
  2237. }
  2238. moduleOb.registerAnimation = registerAnimation;
  2239. moduleOb.loadAnimation = loadAnimation;
  2240. moduleOb.setSpeed = setSpeed;
  2241. moduleOb.setDirection = setDirection;
  2242. moduleOb.play = play;
  2243. moduleOb.pause = pause;
  2244. moduleOb.stop = stop;
  2245. moduleOb.togglePause = togglePause;
  2246. moduleOb.searchAnimations = searchAnimations;
  2247. moduleOb.resize = resize;
  2248. // moduleOb.start = start;
  2249. moduleOb.goToAndStop = goToAndStop;
  2250. moduleOb.destroy = destroy;
  2251. moduleOb.freeze = freeze;
  2252. moduleOb.unfreeze = unfreeze;
  2253. moduleOb.setVolume = setVolume;
  2254. moduleOb.mute = mute;
  2255. moduleOb.unmute = unmute;
  2256. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2257. return moduleOb;
  2258. }());
  2259. /* eslint-disable */
  2260. const BezierFactory = (function () {
  2261. /**
  2262. * BezierEasing - use bezier curve for transition easing function
  2263. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2264. *
  2265. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2266. * Usage:
  2267. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2268. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2269. *
  2270. */
  2271. var ob = {};
  2272. ob.getBezierEasing = getBezierEasing;
  2273. var beziers = {};
  2274. function getBezierEasing(a, b, c, d, nm) {
  2275. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2276. if (beziers[str]) {
  2277. return beziers[str];
  2278. }
  2279. var bezEasing = new BezierEasing([a, b, c, d]);
  2280. beziers[str] = bezEasing;
  2281. return bezEasing;
  2282. }
  2283. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2284. var NEWTON_ITERATIONS = 4;
  2285. var NEWTON_MIN_SLOPE = 0.001;
  2286. var SUBDIVISION_PRECISION = 0.0000001;
  2287. var SUBDIVISION_MAX_ITERATIONS = 10;
  2288. var kSplineTableSize = 11;
  2289. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2290. var float32ArraySupported = typeof Float32Array === 'function';
  2291. function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
  2292. function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
  2293. function C(aA1) { return 3.0 * aA1; }
  2294. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2295. function calcBezier(aT, aA1, aA2) {
  2296. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2297. }
  2298. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2299. function getSlope(aT, aA1, aA2) {
  2300. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2301. }
  2302. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2303. var currentX,
  2304. currentT,
  2305. i = 0;
  2306. do {
  2307. currentT = aA + (aB - aA) / 2.0;
  2308. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2309. if (currentX > 0.0) {
  2310. aB = currentT;
  2311. } else {
  2312. aA = currentT;
  2313. }
  2314. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2315. return currentT;
  2316. }
  2317. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2318. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2319. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2320. if (currentSlope === 0.0) return aGuessT;
  2321. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2322. aGuessT -= currentX / currentSlope;
  2323. }
  2324. return aGuessT;
  2325. }
  2326. /**
  2327. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2328. */
  2329. function BezierEasing(points) {
  2330. this._p = points;
  2331. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2332. this._precomputed = false;
  2333. this.get = this.get.bind(this);
  2334. }
  2335. BezierEasing.prototype = {
  2336. get: function (x) {
  2337. var mX1 = this._p[0],
  2338. mY1 = this._p[1],
  2339. mX2 = this._p[2],
  2340. mY2 = this._p[3];
  2341. if (!this._precomputed) this._precompute();
  2342. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2343. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2344. if (x === 0) return 0;
  2345. if (x === 1) return 1;
  2346. return calcBezier(this._getTForX(x), mY1, mY2);
  2347. },
  2348. // Private part
  2349. _precompute: function () {
  2350. var mX1 = this._p[0],
  2351. mY1 = this._p[1],
  2352. mX2 = this._p[2],
  2353. mY2 = this._p[3];
  2354. this._precomputed = true;
  2355. if (mX1 !== mY1 || mX2 !== mY2) { this._calcSampleValues(); }
  2356. },
  2357. _calcSampleValues: function () {
  2358. var mX1 = this._p[0],
  2359. mX2 = this._p[2];
  2360. for (var i = 0; i < kSplineTableSize; ++i) {
  2361. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2362. }
  2363. },
  2364. /**
  2365. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2366. */
  2367. _getTForX: function (aX) {
  2368. var mX1 = this._p[0],
  2369. mX2 = this._p[2],
  2370. mSampleValues = this._mSampleValues;
  2371. var intervalStart = 0.0;
  2372. var currentSample = 1;
  2373. var lastSample = kSplineTableSize - 1;
  2374. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2375. intervalStart += kSampleStepSize;
  2376. }
  2377. --currentSample;
  2378. // Interpolate to provide an initial guess for t
  2379. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2380. var guessForT = intervalStart + dist * kSampleStepSize;
  2381. var initialSlope = getSlope(guessForT, mX1, mX2);
  2382. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2383. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2384. } if (initialSlope === 0.0) {
  2385. return guessForT;
  2386. }
  2387. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2388. },
  2389. };
  2390. return ob;
  2391. }());
  2392. const pooling = (function () {
  2393. function double(arr) {
  2394. return arr.concat(createSizedArray(arr.length));
  2395. }
  2396. return {
  2397. double: double,
  2398. };
  2399. }());
  2400. const poolFactory = (function () {
  2401. return function (initialLength, _create, _release) {
  2402. var _length = 0;
  2403. var _maxLength = initialLength;
  2404. var pool = createSizedArray(_maxLength);
  2405. var ob = {
  2406. newElement: newElement,
  2407. release: release,
  2408. };
  2409. function newElement() {
  2410. var element;
  2411. if (_length) {
  2412. _length -= 1;
  2413. element = pool[_length];
  2414. } else {
  2415. element = _create();
  2416. }
  2417. return element;
  2418. }
  2419. function release(element) {
  2420. if (_length === _maxLength) {
  2421. pool = pooling.double(pool);
  2422. _maxLength *= 2;
  2423. }
  2424. if (_release) {
  2425. _release(element);
  2426. }
  2427. pool[_length] = element;
  2428. _length += 1;
  2429. }
  2430. return ob;
  2431. };
  2432. }());
  2433. const bezierLengthPool = (function () {
  2434. function create() {
  2435. return {
  2436. addedLength: 0,
  2437. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2438. lengths: createTypedArray('float32', getDefaultCurveSegments()),
  2439. };
  2440. }
  2441. return poolFactory(8, create);
  2442. }());
  2443. const segmentsLengthPool = (function () {
  2444. function create() {
  2445. return {
  2446. lengths: [],
  2447. totalLength: 0,
  2448. };
  2449. }
  2450. function release(element) {
  2451. var i;
  2452. var len = element.lengths.length;
  2453. for (i = 0; i < len; i += 1) {
  2454. bezierLengthPool.release(element.lengths[i]);
  2455. }
  2456. element.lengths.length = 0;
  2457. }
  2458. return poolFactory(8, create, release);
  2459. }());
  2460. function bezFunction() {
  2461. var math = Math;
  2462. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2463. var det1 = (x1 * y2) + (y1 * x3) + (x2 * y3) - (x3 * y2) - (y3 * x1) - (x2 * y1);
  2464. return det1 > -0.001 && det1 < 0.001;
  2465. }
  2466. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2467. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2468. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2469. }
  2470. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2471. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2472. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2473. var diffDist;
  2474. if (dist1 > dist2) {
  2475. if (dist1 > dist3) {
  2476. diffDist = dist1 - dist2 - dist3;
  2477. } else {
  2478. diffDist = dist3 - dist2 - dist1;
  2479. }
  2480. } else if (dist3 > dist2) {
  2481. diffDist = dist3 - dist2 - dist1;
  2482. } else {
  2483. diffDist = dist2 - dist1 - dist3;
  2484. }
  2485. return diffDist > -0.0001 && diffDist < 0.0001;
  2486. }
  2487. var getBezierLength = (function () {
  2488. return function (pt1, pt2, pt3, pt4) {
  2489. var curveSegments = getDefaultCurveSegments();
  2490. var k;
  2491. var i;
  2492. var len;
  2493. var ptCoord;
  2494. var perc;
  2495. var addedLength = 0;
  2496. var ptDistance;
  2497. var point = [];
  2498. var lastPoint = [];
  2499. var lengthData = bezierLengthPool.newElement();
  2500. len = pt3.length;
  2501. for (k = 0; k < curveSegments; k += 1) {
  2502. perc = k / (curveSegments - 1);
  2503. ptDistance = 0;
  2504. for (i = 0; i < len; i += 1) {
  2505. 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];
  2506. point[i] = ptCoord;
  2507. if (lastPoint[i] !== null) {
  2508. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2509. }
  2510. lastPoint[i] = point[i];
  2511. }
  2512. if (ptDistance) {
  2513. ptDistance = bmSqrt(ptDistance);
  2514. addedLength += ptDistance;
  2515. }
  2516. lengthData.percents[k] = perc;
  2517. lengthData.lengths[k] = addedLength;
  2518. }
  2519. lengthData.addedLength = addedLength;
  2520. return lengthData;
  2521. };
  2522. }());
  2523. function getSegmentsLength(shapeData) {
  2524. var segmentsLength = segmentsLengthPool.newElement();
  2525. var closed = shapeData.c;
  2526. var pathV = shapeData.v;
  2527. var pathO = shapeData.o;
  2528. var pathI = shapeData.i;
  2529. var i;
  2530. var len = shapeData._length;
  2531. var lengths = segmentsLength.lengths;
  2532. var totalLength = 0;
  2533. for (i = 0; i < len - 1; i += 1) {
  2534. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2535. totalLength += lengths[i].addedLength;
  2536. }
  2537. if (closed && len) {
  2538. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2539. totalLength += lengths[i].addedLength;
  2540. }
  2541. segmentsLength.totalLength = totalLength;
  2542. return segmentsLength;
  2543. }
  2544. function BezierData(length) {
  2545. this.segmentLength = 0;
  2546. this.points = new Array(length);
  2547. }
  2548. function PointData(partial, point) {
  2549. this.partialLength = partial;
  2550. this.point = point;
  2551. }
  2552. var buildBezierData = (function () {
  2553. var storedData = {};
  2554. return function (pt1, pt2, pt3, pt4) {
  2555. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2556. if (!storedData[bezierName]) {
  2557. var curveSegments = getDefaultCurveSegments();
  2558. var k;
  2559. var i;
  2560. var len;
  2561. var ptCoord;
  2562. var perc;
  2563. var addedLength = 0;
  2564. var ptDistance;
  2565. var point;
  2566. var lastPoint = null;
  2567. 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])) {
  2568. curveSegments = 2;
  2569. }
  2570. var bezierData = new BezierData(curveSegments);
  2571. len = pt3.length;
  2572. for (k = 0; k < curveSegments; k += 1) {
  2573. point = createSizedArray(len);
  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 * (pt1[i] + pt3[i]) + 3 * (1 - perc) * bmPow(perc, 2) * (pt2[i] + pt4[i]) + bmPow(perc, 3) * pt2[i];
  2578. point[i] = ptCoord;
  2579. if (lastPoint !== null) {
  2580. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2581. }
  2582. }
  2583. ptDistance = bmSqrt(ptDistance);
  2584. addedLength += ptDistance;
  2585. bezierData.points[k] = new PointData(ptDistance, point);
  2586. lastPoint = point;
  2587. }
  2588. bezierData.segmentLength = addedLength;
  2589. storedData[bezierName] = bezierData;
  2590. }
  2591. return storedData[bezierName];
  2592. };
  2593. }());
  2594. function getDistancePerc(perc, bezierData) {
  2595. var percents = bezierData.percents;
  2596. var lengths = bezierData.lengths;
  2597. var len = percents.length;
  2598. var initPos = bmFloor((len - 1) * perc);
  2599. var lengthPos = perc * bezierData.addedLength;
  2600. var lPerc = 0;
  2601. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2602. return percents[initPos];
  2603. }
  2604. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2605. var flag = true;
  2606. while (flag) {
  2607. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2608. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2609. flag = false;
  2610. } else {
  2611. initPos += dir;
  2612. }
  2613. if (initPos < 0 || initPos >= len - 1) {
  2614. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2615. if (initPos === len - 1) {
  2616. return percents[initPos];
  2617. }
  2618. flag = false;
  2619. }
  2620. }
  2621. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2622. }
  2623. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2624. var t1 = getDistancePerc(percent, bezierData);
  2625. var u1 = 1 - t1;
  2626. 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;
  2627. 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;
  2628. return [ptX, ptY];
  2629. }
  2630. var bezierSegmentPoints = createTypedArray('float32', 8);
  2631. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2632. if (startPerc < 0) {
  2633. startPerc = 0;
  2634. } else if (startPerc > 1) {
  2635. startPerc = 1;
  2636. }
  2637. var t0 = getDistancePerc(startPerc, bezierData);
  2638. endPerc = endPerc > 1 ? 1 : endPerc;
  2639. var t1 = getDistancePerc(endPerc, bezierData);
  2640. var i;
  2641. var len = pt1.length;
  2642. var u0 = 1 - t0;
  2643. var u1 = 1 - t1;
  2644. var u0u0u0 = u0 * u0 * u0;
  2645. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2646. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2647. var t0t0t0 = t0 * t0 * t0;
  2648. //
  2649. var u0u0u1 = u0 * u0 * u1;
  2650. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2651. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2652. var t0t0t1 = t0 * t0 * t1;
  2653. //
  2654. var u0u1u1 = u0 * u1 * u1;
  2655. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2656. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2657. var t0t1t1 = t0 * t1 * t1;
  2658. //
  2659. var u1u1u1 = u1 * u1 * u1;
  2660. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2661. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2662. var t1t1t1 = t1 * t1 * t1;
  2663. for (i = 0; i < len; i += 1) {
  2664. 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
  2665. 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
  2666. 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
  2667. 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
  2668. }
  2669. return bezierSegmentPoints;
  2670. }
  2671. return {
  2672. getSegmentsLength: getSegmentsLength,
  2673. getNewSegment: getNewSegment,
  2674. getPointInSegment: getPointInSegment,
  2675. buildBezierData: buildBezierData,
  2676. pointOnLine2D: pointOnLine2D,
  2677. pointOnLine3D: pointOnLine3D,
  2678. };
  2679. }
  2680. const bez = bezFunction();
  2681. var initFrame = initialDefaultFrame;
  2682. var mathAbs = Math.abs;
  2683. function interpolateValue(frameNum, caching) {
  2684. var offsetTime = this.offsetTime;
  2685. var newValue;
  2686. if (this.propType === 'multidimensional') {
  2687. newValue = createTypedArray('float32', this.pv.length);
  2688. }
  2689. var iterationIndex = caching.lastIndex;
  2690. var i = iterationIndex;
  2691. var len = this.keyframes.length - 1;
  2692. var flag = true;
  2693. var keyData;
  2694. var nextKeyData;
  2695. var keyframeMetadata;
  2696. while (flag) {
  2697. keyData = this.keyframes[i];
  2698. nextKeyData = this.keyframes[i + 1];
  2699. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2700. if (keyData.h) {
  2701. keyData = nextKeyData;
  2702. }
  2703. iterationIndex = 0;
  2704. break;
  2705. }
  2706. if ((nextKeyData.t - offsetTime) > frameNum) {
  2707. iterationIndex = i;
  2708. break;
  2709. }
  2710. if (i < len - 1) {
  2711. i += 1;
  2712. } else {
  2713. iterationIndex = 0;
  2714. flag = false;
  2715. }
  2716. }
  2717. keyframeMetadata = this.keyframesMetadata[i] || {};
  2718. var k;
  2719. var kLen;
  2720. var perc;
  2721. var jLen;
  2722. var j;
  2723. var fnc;
  2724. var nextKeyTime = nextKeyData.t - offsetTime;
  2725. var keyTime = keyData.t - offsetTime;
  2726. var endValue;
  2727. if (keyData.to) {
  2728. if (!keyframeMetadata.bezierData) {
  2729. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2730. }
  2731. var bezierData = keyframeMetadata.bezierData;
  2732. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2733. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2734. kLen = bezierData.points[ind].point.length;
  2735. for (k = 0; k < kLen; k += 1) {
  2736. newValue[k] = bezierData.points[ind].point[k];
  2737. }
  2738. // caching._lastKeyframeIndex = -1;
  2739. } else {
  2740. if (keyframeMetadata.__fnct) {
  2741. fnc = keyframeMetadata.__fnct;
  2742. } else {
  2743. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2744. keyframeMetadata.__fnct = fnc;
  2745. }
  2746. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2747. var distanceInLine = bezierData.segmentLength * perc;
  2748. var segmentPerc;
  2749. var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0;
  2750. j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0;
  2751. flag = true;
  2752. jLen = bezierData.points.length;
  2753. while (flag) {
  2754. addedLength += bezierData.points[j].partialLength;
  2755. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2756. kLen = bezierData.points[j].point.length;
  2757. for (k = 0; k < kLen; k += 1) {
  2758. newValue[k] = bezierData.points[j].point[k];
  2759. }
  2760. break;
  2761. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2762. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2763. kLen = bezierData.points[j].point.length;
  2764. for (k = 0; k < kLen; k += 1) {
  2765. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2766. }
  2767. break;
  2768. }
  2769. if (j < jLen - 1) {
  2770. j += 1;
  2771. } else {
  2772. flag = false;
  2773. }
  2774. }
  2775. caching._lastPoint = j;
  2776. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2777. caching._lastKeyframeIndex = i;
  2778. }
  2779. } else {
  2780. var outX;
  2781. var outY;
  2782. var inX;
  2783. var inY;
  2784. var keyValue;
  2785. len = keyData.s.length;
  2786. endValue = nextKeyData.s || keyData.e;
  2787. if (this.sh && keyData.h !== 1) {
  2788. if (frameNum >= nextKeyTime) {
  2789. newValue[0] = endValue[0];
  2790. newValue[1] = endValue[1];
  2791. newValue[2] = endValue[2];
  2792. } else if (frameNum <= keyTime) {
  2793. newValue[0] = keyData.s[0];
  2794. newValue[1] = keyData.s[1];
  2795. newValue[2] = keyData.s[2];
  2796. } else {
  2797. var quatStart = createQuaternion(keyData.s);
  2798. var quatEnd = createQuaternion(endValue);
  2799. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2800. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2801. }
  2802. } else {
  2803. for (i = 0; i < len; i += 1) {
  2804. if (keyData.h !== 1) {
  2805. if (frameNum >= nextKeyTime) {
  2806. perc = 1;
  2807. } else if (frameNum < keyTime) {
  2808. perc = 0;
  2809. } else {
  2810. if (keyData.o.x.constructor === Array) {
  2811. if (!keyframeMetadata.__fnct) {
  2812. keyframeMetadata.__fnct = [];
  2813. }
  2814. if (!keyframeMetadata.__fnct[i]) {
  2815. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2816. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2817. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2818. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2819. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2820. keyframeMetadata.__fnct[i] = fnc;
  2821. } else {
  2822. fnc = keyframeMetadata.__fnct[i];
  2823. }
  2824. } else if (!keyframeMetadata.__fnct) {
  2825. outX = keyData.o.x;
  2826. outY = keyData.o.y;
  2827. inX = keyData.i.x;
  2828. inY = keyData.i.y;
  2829. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2830. keyData.keyframeMetadata = fnc;
  2831. } else {
  2832. fnc = keyframeMetadata.__fnct;
  2833. }
  2834. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2835. }
  2836. }
  2837. endValue = nextKeyData.s || keyData.e;
  2838. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2839. if (this.propType === 'multidimensional') {
  2840. newValue[i] = keyValue;
  2841. } else {
  2842. newValue = keyValue;
  2843. }
  2844. }
  2845. }
  2846. }
  2847. caching.lastIndex = iterationIndex;
  2848. return newValue;
  2849. }
  2850. // based on @Toji's https://github.com/toji/gl-matrix/
  2851. function slerp(a, b, t) {
  2852. var out = [];
  2853. var ax = a[0];
  2854. var ay = a[1];
  2855. var az = a[2];
  2856. var aw = a[3];
  2857. var bx = b[0];
  2858. var by = b[1];
  2859. var bz = b[2];
  2860. var bw = b[3];
  2861. var omega;
  2862. var cosom;
  2863. var sinom;
  2864. var scale0;
  2865. var scale1;
  2866. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2867. if (cosom < 0.0) {
  2868. cosom = -cosom;
  2869. bx = -bx;
  2870. by = -by;
  2871. bz = -bz;
  2872. bw = -bw;
  2873. }
  2874. if ((1.0 - cosom) > 0.000001) {
  2875. omega = Math.acos(cosom);
  2876. sinom = Math.sin(omega);
  2877. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2878. scale1 = Math.sin(t * omega) / sinom;
  2879. } else {
  2880. scale0 = 1.0 - t;
  2881. scale1 = t;
  2882. }
  2883. out[0] = scale0 * ax + scale1 * bx;
  2884. out[1] = scale0 * ay + scale1 * by;
  2885. out[2] = scale0 * az + scale1 * bz;
  2886. out[3] = scale0 * aw + scale1 * bw;
  2887. return out;
  2888. }
  2889. function quaternionToEuler(out, quat) {
  2890. var qx = quat[0];
  2891. var qy = quat[1];
  2892. var qz = quat[2];
  2893. var qw = quat[3];
  2894. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2895. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2896. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2897. out[0] = heading / degToRads;
  2898. out[1] = attitude / degToRads;
  2899. out[2] = bank / degToRads;
  2900. }
  2901. function createQuaternion(values) {
  2902. var heading = values[0] * degToRads;
  2903. var attitude = values[1] * degToRads;
  2904. var bank = values[2] * degToRads;
  2905. var c1 = Math.cos(heading / 2);
  2906. var c2 = Math.cos(attitude / 2);
  2907. var c3 = Math.cos(bank / 2);
  2908. var s1 = Math.sin(heading / 2);
  2909. var s2 = Math.sin(attitude / 2);
  2910. var s3 = Math.sin(bank / 2);
  2911. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2912. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2913. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2914. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2915. return [x, y, z, w];
  2916. }
  2917. function getValueAtCurrentTime() {
  2918. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2919. var initTime = this.keyframes[0].t - this.offsetTime;
  2920. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2921. if (!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))) {
  2922. if (this._caching.lastFrame >= frameNum) {
  2923. this._caching._lastKeyframeIndex = -1;
  2924. this._caching.lastIndex = 0;
  2925. }
  2926. var renderResult = this.interpolateValue(frameNum, this._caching);
  2927. this.pv = renderResult;
  2928. }
  2929. this._caching.lastFrame = frameNum;
  2930. return this.pv;
  2931. }
  2932. function setVValue(val) {
  2933. var multipliedValue;
  2934. if (this.propType === 'unidimensional') {
  2935. multipliedValue = val * this.mult;
  2936. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  2937. this.v = multipliedValue;
  2938. this._mdf = true;
  2939. }
  2940. } else {
  2941. var i = 0;
  2942. var len = this.v.length;
  2943. while (i < len) {
  2944. multipliedValue = val[i] * this.mult;
  2945. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  2946. this.v[i] = multipliedValue;
  2947. this._mdf = true;
  2948. }
  2949. i += 1;
  2950. }
  2951. }
  2952. }
  2953. function processEffectsSequence() {
  2954. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  2955. return;
  2956. }
  2957. if (this.lock) {
  2958. this.setVValue(this.pv);
  2959. return;
  2960. }
  2961. this.lock = true;
  2962. this._mdf = this._isFirstFrame;
  2963. var i;
  2964. var len = this.effectsSequence.length;
  2965. var finalValue = this.kf ? this.pv : this.data.k;
  2966. for (i = 0; i < len; i += 1) {
  2967. finalValue = this.effectsSequence[i](finalValue);
  2968. }
  2969. this.setVValue(finalValue);
  2970. this._isFirstFrame = false;
  2971. this.lock = false;
  2972. this.frameId = this.elem.globalData.frameId;
  2973. }
  2974. function addEffect(effectFunction) {
  2975. this.effectsSequence.push(effectFunction);
  2976. this.container.addDynamicProperty(this);
  2977. }
  2978. function ValueProperty(elem, data, mult, container) {
  2979. this.propType = 'unidimensional';
  2980. this.mult = mult || 1;
  2981. this.data = data;
  2982. this.v = mult ? data.k * mult : data.k;
  2983. this.pv = data.k;
  2984. this._mdf = false;
  2985. this.elem = elem;
  2986. this.container = container;
  2987. this.comp = elem.comp;
  2988. this.k = false;
  2989. this.kf = false;
  2990. this.vel = 0;
  2991. this.effectsSequence = [];
  2992. this._isFirstFrame = true;
  2993. this.getValue = processEffectsSequence;
  2994. this.setVValue = setVValue;
  2995. this.addEffect = addEffect;
  2996. }
  2997. function MultiDimensionalProperty(elem, data, mult, container) {
  2998. this.propType = 'multidimensional';
  2999. this.mult = mult || 1;
  3000. this.data = data;
  3001. this._mdf = false;
  3002. this.elem = elem;
  3003. this.container = container;
  3004. this.comp = elem.comp;
  3005. this.k = false;
  3006. this.kf = false;
  3007. this.frameId = -1;
  3008. var i;
  3009. var len = data.k.length;
  3010. this.v = createTypedArray('float32', len);
  3011. this.pv = createTypedArray('float32', len);
  3012. this.vel = createTypedArray('float32', len);
  3013. for (i = 0; i < len; i += 1) {
  3014. this.v[i] = data.k[i] * this.mult;
  3015. this.pv[i] = data.k[i];
  3016. }
  3017. this._isFirstFrame = true;
  3018. this.effectsSequence = [];
  3019. this.getValue = processEffectsSequence;
  3020. this.setVValue = setVValue;
  3021. this.addEffect = addEffect;
  3022. }
  3023. function KeyframedValueProperty(elem, data, mult, container) {
  3024. this.propType = 'unidimensional';
  3025. this.keyframes = data.k;
  3026. this.keyframesMetadata = [];
  3027. this.offsetTime = elem.data.st;
  3028. this.frameId = -1;
  3029. this._caching = {
  3030. lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1,
  3031. };
  3032. this.k = true;
  3033. this.kf = true;
  3034. this.data = data;
  3035. this.mult = mult || 1;
  3036. this.elem = elem;
  3037. this.container = container;
  3038. this.comp = elem.comp;
  3039. this.v = initFrame;
  3040. this.pv = initFrame;
  3041. this._isFirstFrame = true;
  3042. this.getValue = processEffectsSequence;
  3043. this.setVValue = setVValue;
  3044. this.interpolateValue = interpolateValue;
  3045. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3046. this.addEffect = addEffect;
  3047. }
  3048. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3049. this.propType = 'multidimensional';
  3050. var i;
  3051. var len = data.k.length;
  3052. var s;
  3053. var e;
  3054. var to;
  3055. var ti;
  3056. for (i = 0; i < len - 1; i += 1) {
  3057. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3058. s = data.k[i].s;
  3059. e = data.k[i + 1].s;
  3060. to = data.k[i].to;
  3061. ti = data.k[i].ti;
  3062. 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]))) {
  3063. data.k[i].to = null;
  3064. data.k[i].ti = null;
  3065. }
  3066. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3067. if (s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) {
  3068. data.k[i].to = null;
  3069. data.k[i].ti = null;
  3070. }
  3071. }
  3072. }
  3073. }
  3074. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3075. this.data = data;
  3076. this.keyframes = data.k;
  3077. this.keyframesMetadata = [];
  3078. this.offsetTime = elem.data.st;
  3079. this.k = true;
  3080. this.kf = true;
  3081. this._isFirstFrame = true;
  3082. this.mult = mult || 1;
  3083. this.elem = elem;
  3084. this.container = container;
  3085. this.comp = elem.comp;
  3086. this.getValue = processEffectsSequence;
  3087. this.setVValue = setVValue;
  3088. this.interpolateValue = interpolateValue;
  3089. this.frameId = -1;
  3090. var arrLen = data.k[0].s.length;
  3091. this.v = createTypedArray('float32', arrLen);
  3092. this.pv = createTypedArray('float32', arrLen);
  3093. for (i = 0; i < arrLen; i += 1) {
  3094. this.v[i] = initFrame;
  3095. this.pv[i] = initFrame;
  3096. }
  3097. this._caching = { lastFrame: initFrame, lastIndex: 0, value: createTypedArray('float32', arrLen) };
  3098. this.addEffect = addEffect;
  3099. }
  3100. const PropertyFactory = (function () {
  3101. function getProp(elem, data, type, mult, container) {
  3102. if (data.sid) {
  3103. data = elem.globalData.slotManager.getProp(data);
  3104. }
  3105. var p;
  3106. if (!data.k.length) {
  3107. p = new ValueProperty(elem, data, mult, container);
  3108. } else if (typeof (data.k[0]) === 'number') {
  3109. p = new MultiDimensionalProperty(elem, data, mult, container);
  3110. } else {
  3111. switch (type) {
  3112. case 0:
  3113. p = new KeyframedValueProperty(elem, data, mult, container);
  3114. break;
  3115. case 1:
  3116. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3117. break;
  3118. default:
  3119. break;
  3120. }
  3121. }
  3122. if (p.effectsSequence.length) {
  3123. container.addDynamicProperty(p);
  3124. }
  3125. return p;
  3126. }
  3127. var ob = {
  3128. getProp: getProp,
  3129. };
  3130. return ob;
  3131. }());
  3132. function DynamicPropertyContainer() {}
  3133. DynamicPropertyContainer.prototype = {
  3134. addDynamicProperty: function (prop) {
  3135. if (this.dynamicProperties.indexOf(prop) === -1) {
  3136. this.dynamicProperties.push(prop);
  3137. this.container.addDynamicProperty(this);
  3138. this._isAnimated = true;
  3139. }
  3140. },
  3141. iterateDynamicProperties: function () {
  3142. this._mdf = false;
  3143. var i;
  3144. var len = this.dynamicProperties.length;
  3145. for (i = 0; i < len; i += 1) {
  3146. this.dynamicProperties[i].getValue();
  3147. if (this.dynamicProperties[i]._mdf) {
  3148. this._mdf = true;
  3149. }
  3150. }
  3151. },
  3152. initDynamicPropertyContainer: function (container) {
  3153. this.container = container;
  3154. this.dynamicProperties = [];
  3155. this._mdf = false;
  3156. this._isAnimated = false;
  3157. },
  3158. };
  3159. const pointPool = (function () {
  3160. function create() {
  3161. return createTypedArray('float32', 2);
  3162. }
  3163. return poolFactory(8, create);
  3164. }());
  3165. function ShapePath() {
  3166. this.c = false;
  3167. this._length = 0;
  3168. this._maxLength = 8;
  3169. this.v = createSizedArray(this._maxLength);
  3170. this.o = createSizedArray(this._maxLength);
  3171. this.i = createSizedArray(this._maxLength);
  3172. }
  3173. ShapePath.prototype.setPathData = function (closed, len) {
  3174. this.c = closed;
  3175. this.setLength(len);
  3176. var i = 0;
  3177. while (i < len) {
  3178. this.v[i] = pointPool.newElement();
  3179. this.o[i] = pointPool.newElement();
  3180. this.i[i] = pointPool.newElement();
  3181. i += 1;
  3182. }
  3183. };
  3184. ShapePath.prototype.setLength = function (len) {
  3185. while (this._maxLength < len) {
  3186. this.doubleArrayLength();
  3187. }
  3188. this._length = len;
  3189. };
  3190. ShapePath.prototype.doubleArrayLength = function () {
  3191. this.v = this.v.concat(createSizedArray(this._maxLength));
  3192. this.i = this.i.concat(createSizedArray(this._maxLength));
  3193. this.o = this.o.concat(createSizedArray(this._maxLength));
  3194. this._maxLength *= 2;
  3195. };
  3196. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3197. var arr;
  3198. this._length = Math.max(this._length, pos + 1);
  3199. if (this._length >= this._maxLength) {
  3200. this.doubleArrayLength();
  3201. }
  3202. switch (type) {
  3203. case 'v':
  3204. arr = this.v;
  3205. break;
  3206. case 'i':
  3207. arr = this.i;
  3208. break;
  3209. case 'o':
  3210. arr = this.o;
  3211. break;
  3212. default:
  3213. arr = [];
  3214. break;
  3215. }
  3216. if (!arr[pos] || (arr[pos] && !replace)) {
  3217. arr[pos] = pointPool.newElement();
  3218. }
  3219. arr[pos][0] = x;
  3220. arr[pos][1] = y;
  3221. };
  3222. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3223. this.setXYAt(vX, vY, 'v', pos, replace);
  3224. this.setXYAt(oX, oY, 'o', pos, replace);
  3225. this.setXYAt(iX, iY, 'i', pos, replace);
  3226. };
  3227. ShapePath.prototype.reverse = function () {
  3228. var newPath = new ShapePath();
  3229. newPath.setPathData(this.c, this._length);
  3230. var vertices = this.v;
  3231. var outPoints = this.o;
  3232. var inPoints = this.i;
  3233. var init = 0;
  3234. if (this.c) {
  3235. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3236. init = 1;
  3237. }
  3238. var cnt = this._length - 1;
  3239. var len = this._length;
  3240. var i;
  3241. for (i = init; i < len; i += 1) {
  3242. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3243. cnt -= 1;
  3244. }
  3245. return newPath;
  3246. };
  3247. ShapePath.prototype.length = function () {
  3248. return this._length;
  3249. };
  3250. const shapePool = (function () {
  3251. function create() {
  3252. return new ShapePath();
  3253. }
  3254. function release(shapePath) {
  3255. var len = shapePath._length;
  3256. var i;
  3257. for (i = 0; i < len; i += 1) {
  3258. pointPool.release(shapePath.v[i]);
  3259. pointPool.release(shapePath.i[i]);
  3260. pointPool.release(shapePath.o[i]);
  3261. shapePath.v[i] = null;
  3262. shapePath.i[i] = null;
  3263. shapePath.o[i] = null;
  3264. }
  3265. shapePath._length = 0;
  3266. shapePath.c = false;
  3267. }
  3268. function clone(shape) {
  3269. var cloned = factory.newElement();
  3270. var i;
  3271. var len = shape._length === undefined ? shape.v.length : shape._length;
  3272. cloned.setLength(len);
  3273. cloned.c = shape.c;
  3274. for (i = 0; i < len; i += 1) {
  3275. 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);
  3276. }
  3277. return cloned;
  3278. }
  3279. var factory = poolFactory(4, create, release);
  3280. factory.clone = clone;
  3281. return factory;
  3282. }());
  3283. function ShapeCollection() {
  3284. this._length = 0;
  3285. this._maxLength = 4;
  3286. this.shapes = createSizedArray(this._maxLength);
  3287. }
  3288. ShapeCollection.prototype.addShape = function (shapeData) {
  3289. if (this._length === this._maxLength) {
  3290. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3291. this._maxLength *= 2;
  3292. }
  3293. this.shapes[this._length] = shapeData;
  3294. this._length += 1;
  3295. };
  3296. ShapeCollection.prototype.releaseShapes = function () {
  3297. var i;
  3298. for (i = 0; i < this._length; i += 1) {
  3299. shapePool.release(this.shapes[i]);
  3300. }
  3301. this._length = 0;
  3302. };
  3303. const shapeCollectionPool = (function () {
  3304. var ob = {
  3305. newShapeCollection: newShapeCollection,
  3306. release: release,
  3307. };
  3308. var _length = 0;
  3309. var _maxLength = 4;
  3310. var pool = createSizedArray(_maxLength);
  3311. function newShapeCollection() {
  3312. var shapeCollection;
  3313. if (_length) {
  3314. _length -= 1;
  3315. shapeCollection = pool[_length];
  3316. } else {
  3317. shapeCollection = new ShapeCollection();
  3318. }
  3319. return shapeCollection;
  3320. }
  3321. function release(shapeCollection) {
  3322. var i;
  3323. var len = shapeCollection._length;
  3324. for (i = 0; i < len; i += 1) {
  3325. shapePool.release(shapeCollection.shapes[i]);
  3326. }
  3327. shapeCollection._length = 0;
  3328. if (_length === _maxLength) {
  3329. pool = pooling.double(pool);
  3330. _maxLength *= 2;
  3331. }
  3332. pool[_length] = shapeCollection;
  3333. _length += 1;
  3334. }
  3335. return ob;
  3336. }());
  3337. const ShapePropertyFactory = (function () {
  3338. var initFrame = -999999;
  3339. function interpolateShape(frameNum, previousValue, caching) {
  3340. var iterationIndex = caching.lastIndex;
  3341. var keyPropS;
  3342. var keyPropE;
  3343. var isHold;
  3344. var j;
  3345. var k;
  3346. var jLen;
  3347. var kLen;
  3348. var perc;
  3349. var vertexValue;
  3350. var kf = this.keyframes;
  3351. if (frameNum < kf[0].t - this.offsetTime) {
  3352. keyPropS = kf[0].s[0];
  3353. isHold = true;
  3354. iterationIndex = 0;
  3355. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3356. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3357. /* if(kf[kf.length - 1].s){
  3358. keyPropS = kf[kf.length - 1].s[0];
  3359. }else{
  3360. keyPropS = kf[kf.length - 2].e[0];
  3361. } */
  3362. isHold = true;
  3363. } else {
  3364. var i = iterationIndex;
  3365. var len = kf.length - 1;
  3366. var flag = true;
  3367. var keyData;
  3368. var nextKeyData;
  3369. var keyframeMetadata;
  3370. while (flag) {
  3371. keyData = kf[i];
  3372. nextKeyData = kf[i + 1];
  3373. if ((nextKeyData.t - this.offsetTime) > frameNum) {
  3374. break;
  3375. }
  3376. if (i < len - 1) {
  3377. i += 1;
  3378. } else {
  3379. flag = false;
  3380. }
  3381. }
  3382. keyframeMetadata = this.keyframesMetadata[i] || {};
  3383. isHold = keyData.h === 1;
  3384. iterationIndex = i;
  3385. if (!isHold) {
  3386. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3387. perc = 1;
  3388. } else if (frameNum < keyData.t - this.offsetTime) {
  3389. perc = 0;
  3390. } else {
  3391. var fnc;
  3392. if (keyframeMetadata.__fnct) {
  3393. fnc = keyframeMetadata.__fnct;
  3394. } else {
  3395. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3396. keyframeMetadata.__fnct = fnc;
  3397. }
  3398. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / ((nextKeyData.t - this.offsetTime) - (keyData.t - this.offsetTime)));
  3399. }
  3400. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3401. }
  3402. keyPropS = keyData.s[0];
  3403. }
  3404. jLen = previousValue._length;
  3405. kLen = keyPropS.i[0].length;
  3406. caching.lastIndex = iterationIndex;
  3407. for (j = 0; j < jLen; j += 1) {
  3408. for (k = 0; k < kLen; k += 1) {
  3409. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3410. previousValue.i[j][k] = vertexValue;
  3411. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3412. previousValue.o[j][k] = vertexValue;
  3413. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3414. previousValue.v[j][k] = vertexValue;
  3415. }
  3416. }
  3417. }
  3418. function interpolateShapeCurrentTime() {
  3419. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3420. var initTime = this.keyframes[0].t - this.offsetTime;
  3421. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3422. var lastFrame = this._caching.lastFrame;
  3423. if (!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))) {
  3424. /// /
  3425. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3426. this.interpolateShape(frameNum, this.pv, this._caching);
  3427. /// /
  3428. }
  3429. this._caching.lastFrame = frameNum;
  3430. return this.pv;
  3431. }
  3432. function resetShape() {
  3433. this.paths = this.localShapeCollection;
  3434. }
  3435. function shapesEqual(shape1, shape2) {
  3436. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3437. return false;
  3438. }
  3439. var i;
  3440. var len = shape1._length;
  3441. for (i = 0; i < len; i += 1) {
  3442. if (shape1.v[i][0] !== shape2.v[i][0]
  3443. || shape1.v[i][1] !== shape2.v[i][1]
  3444. || shape1.o[i][0] !== shape2.o[i][0]
  3445. || shape1.o[i][1] !== shape2.o[i][1]
  3446. || shape1.i[i][0] !== shape2.i[i][0]
  3447. || shape1.i[i][1] !== shape2.i[i][1]) {
  3448. return false;
  3449. }
  3450. }
  3451. return true;
  3452. }
  3453. function setVValue(newPath) {
  3454. if (!shapesEqual(this.v, newPath)) {
  3455. this.v = shapePool.clone(newPath);
  3456. this.localShapeCollection.releaseShapes();
  3457. this.localShapeCollection.addShape(this.v);
  3458. this._mdf = true;
  3459. this.paths = this.localShapeCollection;
  3460. }
  3461. }
  3462. function processEffectsSequence() {
  3463. if (this.elem.globalData.frameId === this.frameId) {
  3464. return;
  3465. } if (!this.effectsSequence.length) {
  3466. this._mdf = false;
  3467. return;
  3468. }
  3469. if (this.lock) {
  3470. this.setVValue(this.pv);
  3471. return;
  3472. }
  3473. this.lock = true;
  3474. this._mdf = false;
  3475. var finalValue;
  3476. if (this.kf) {
  3477. finalValue = this.pv;
  3478. } else if (this.data.ks) {
  3479. finalValue = this.data.ks.k;
  3480. } else {
  3481. finalValue = this.data.pt.k;
  3482. }
  3483. var i;
  3484. var len = this.effectsSequence.length;
  3485. for (i = 0; i < len; i += 1) {
  3486. finalValue = this.effectsSequence[i](finalValue);
  3487. }
  3488. this.setVValue(finalValue);
  3489. this.lock = false;
  3490. this.frameId = this.elem.globalData.frameId;
  3491. }
  3492. function ShapeProperty(elem, data, type) {
  3493. this.propType = 'shape';
  3494. this.comp = elem.comp;
  3495. this.container = elem;
  3496. this.elem = elem;
  3497. this.data = data;
  3498. this.k = false;
  3499. this.kf = false;
  3500. this._mdf = false;
  3501. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3502. this.v = shapePool.clone(pathData);
  3503. this.pv = shapePool.clone(this.v);
  3504. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3505. this.paths = this.localShapeCollection;
  3506. this.paths.addShape(this.v);
  3507. this.reset = resetShape;
  3508. this.effectsSequence = [];
  3509. }
  3510. function addEffect(effectFunction) {
  3511. this.effectsSequence.push(effectFunction);
  3512. this.container.addDynamicProperty(this);
  3513. }
  3514. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3515. ShapeProperty.prototype.getValue = processEffectsSequence;
  3516. ShapeProperty.prototype.setVValue = setVValue;
  3517. ShapeProperty.prototype.addEffect = addEffect;
  3518. function KeyframedShapeProperty(elem, data, type) {
  3519. this.propType = 'shape';
  3520. this.comp = elem.comp;
  3521. this.elem = elem;
  3522. this.container = elem;
  3523. this.offsetTime = elem.data.st;
  3524. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3525. this.keyframesMetadata = [];
  3526. this.k = true;
  3527. this.kf = true;
  3528. var len = this.keyframes[0].s[0].i.length;
  3529. this.v = shapePool.newElement();
  3530. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3531. this.pv = shapePool.clone(this.v);
  3532. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3533. this.paths = this.localShapeCollection;
  3534. this.paths.addShape(this.v);
  3535. this.lastFrame = initFrame;
  3536. this.reset = resetShape;
  3537. this._caching = { lastFrame: initFrame, lastIndex: 0 };
  3538. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3539. }
  3540. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3541. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3542. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3543. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3544. var EllShapeProperty = (function () {
  3545. var cPoint = roundCorner;
  3546. function EllShapePropertyFactory(elem, data) {
  3547. this.v = shapePool.newElement();
  3548. this.v.setPathData(true, 4);
  3549. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3550. this.paths = this.localShapeCollection;
  3551. this.localShapeCollection.addShape(this.v);
  3552. this.d = data.d;
  3553. this.elem = elem;
  3554. this.comp = elem.comp;
  3555. this.frameId = -1;
  3556. this.initDynamicPropertyContainer(elem);
  3557. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3558. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3559. if (this.dynamicProperties.length) {
  3560. this.k = true;
  3561. } else {
  3562. this.k = false;
  3563. this.convertEllToPath();
  3564. }
  3565. }
  3566. EllShapePropertyFactory.prototype = {
  3567. reset: resetShape,
  3568. getValue: function () {
  3569. if (this.elem.globalData.frameId === this.frameId) {
  3570. return;
  3571. }
  3572. this.frameId = this.elem.globalData.frameId;
  3573. this.iterateDynamicProperties();
  3574. if (this._mdf) {
  3575. this.convertEllToPath();
  3576. }
  3577. },
  3578. convertEllToPath: function () {
  3579. var p0 = this.p.v[0];
  3580. var p1 = this.p.v[1];
  3581. var s0 = this.s.v[0] / 2;
  3582. var s1 = this.s.v[1] / 2;
  3583. var _cw = this.d !== 3;
  3584. var _v = this.v;
  3585. _v.v[0][0] = p0;
  3586. _v.v[0][1] = p1 - s1;
  3587. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3588. _v.v[1][1] = p1;
  3589. _v.v[2][0] = p0;
  3590. _v.v[2][1] = p1 + s1;
  3591. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3592. _v.v[3][1] = p1;
  3593. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3594. _v.i[0][1] = p1 - s1;
  3595. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3596. _v.i[1][1] = p1 - s1 * cPoint;
  3597. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3598. _v.i[2][1] = p1 + s1;
  3599. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3600. _v.i[3][1] = p1 + s1 * cPoint;
  3601. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3602. _v.o[0][1] = p1 - s1;
  3603. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3604. _v.o[1][1] = p1 + s1 * cPoint;
  3605. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3606. _v.o[2][1] = p1 + s1;
  3607. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3608. _v.o[3][1] = p1 - s1 * cPoint;
  3609. },
  3610. };
  3611. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3612. return EllShapePropertyFactory;
  3613. }());
  3614. var StarShapeProperty = (function () {
  3615. function StarShapePropertyFactory(elem, data) {
  3616. this.v = shapePool.newElement();
  3617. this.v.setPathData(true, 0);
  3618. this.elem = elem;
  3619. this.comp = elem.comp;
  3620. this.data = data;
  3621. this.frameId = -1;
  3622. this.d = data.d;
  3623. this.initDynamicPropertyContainer(elem);
  3624. if (data.sy === 1) {
  3625. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3626. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3627. this.convertToPath = this.convertStarToPath;
  3628. } else {
  3629. this.convertToPath = this.convertPolygonToPath;
  3630. }
  3631. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3632. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3633. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3634. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3635. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3636. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3637. this.localShapeCollection.addShape(this.v);
  3638. this.paths = this.localShapeCollection;
  3639. if (this.dynamicProperties.length) {
  3640. this.k = true;
  3641. } else {
  3642. this.k = false;
  3643. this.convertToPath();
  3644. }
  3645. }
  3646. StarShapePropertyFactory.prototype = {
  3647. reset: resetShape,
  3648. getValue: function () {
  3649. if (this.elem.globalData.frameId === this.frameId) {
  3650. return;
  3651. }
  3652. this.frameId = this.elem.globalData.frameId;
  3653. this.iterateDynamicProperties();
  3654. if (this._mdf) {
  3655. this.convertToPath();
  3656. }
  3657. },
  3658. convertStarToPath: function () {
  3659. var numPts = Math.floor(this.pt.v) * 2;
  3660. var angle = (Math.PI * 2) / numPts;
  3661. /* this.v.v.length = numPts;
  3662. this.v.i.length = numPts;
  3663. this.v.o.length = numPts; */
  3664. var longFlag = true;
  3665. var longRad = this.or.v;
  3666. var shortRad = this.ir.v;
  3667. var longRound = this.os.v;
  3668. var shortRound = this.is.v;
  3669. var longPerimSegment = (2 * Math.PI * longRad) / (numPts * 2);
  3670. var shortPerimSegment = (2 * Math.PI * shortRad) / (numPts * 2);
  3671. var i;
  3672. var rad;
  3673. var roundness;
  3674. var perimSegment;
  3675. var currentAng = -Math.PI / 2;
  3676. currentAng += this.r.v;
  3677. var dir = this.data.d === 3 ? -1 : 1;
  3678. this.v._length = 0;
  3679. for (i = 0; i < numPts; i += 1) {
  3680. rad = longFlag ? longRad : shortRad;
  3681. roundness = longFlag ? longRound : shortRound;
  3682. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3683. var x = rad * Math.cos(currentAng);
  3684. var y = rad * Math.sin(currentAng);
  3685. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3686. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3687. x += +this.p.v[0];
  3688. y += +this.p.v[1];
  3689. 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);
  3690. /* this.v.v[i] = [x,y];
  3691. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3692. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3693. this.v._length = numPts; */
  3694. longFlag = !longFlag;
  3695. currentAng += angle * dir;
  3696. }
  3697. },
  3698. convertPolygonToPath: function () {
  3699. var numPts = Math.floor(this.pt.v);
  3700. var angle = (Math.PI * 2) / numPts;
  3701. var rad = this.or.v;
  3702. var roundness = this.os.v;
  3703. var perimSegment = (2 * Math.PI * rad) / (numPts * 4);
  3704. var i;
  3705. var currentAng = -Math.PI * 0.5;
  3706. var dir = this.data.d === 3 ? -1 : 1;
  3707. currentAng += this.r.v;
  3708. this.v._length = 0;
  3709. for (i = 0; i < numPts; i += 1) {
  3710. var x = rad * Math.cos(currentAng);
  3711. var y = rad * Math.sin(currentAng);
  3712. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3713. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3714. x += +this.p.v[0];
  3715. y += +this.p.v[1];
  3716. 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);
  3717. currentAng += angle * dir;
  3718. }
  3719. this.paths.length = 0;
  3720. this.paths[0] = this.v;
  3721. },
  3722. };
  3723. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3724. return StarShapePropertyFactory;
  3725. }());
  3726. var RectShapeProperty = (function () {
  3727. function RectShapePropertyFactory(elem, data) {
  3728. this.v = shapePool.newElement();
  3729. this.v.c = true;
  3730. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3731. this.localShapeCollection.addShape(this.v);
  3732. this.paths = this.localShapeCollection;
  3733. this.elem = elem;
  3734. this.comp = elem.comp;
  3735. this.frameId = -1;
  3736. this.d = data.d;
  3737. this.initDynamicPropertyContainer(elem);
  3738. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3739. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3740. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3741. if (this.dynamicProperties.length) {
  3742. this.k = true;
  3743. } else {
  3744. this.k = false;
  3745. this.convertRectToPath();
  3746. }
  3747. }
  3748. RectShapePropertyFactory.prototype = {
  3749. convertRectToPath: function () {
  3750. var p0 = this.p.v[0];
  3751. var p1 = this.p.v[1];
  3752. var v0 = this.s.v[0] / 2;
  3753. var v1 = this.s.v[1] / 2;
  3754. var round = bmMin(v0, v1, this.r.v);
  3755. var cPoint = round * (1 - roundCorner);
  3756. this.v._length = 0;
  3757. if (this.d === 2 || this.d === 1) {
  3758. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3759. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3760. if (round !== 0) {
  3761. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3762. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3763. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3764. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3765. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3766. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3767. } else {
  3768. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3769. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3770. }
  3771. } else {
  3772. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3773. if (round !== 0) {
  3774. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3775. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3776. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3777. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3778. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3779. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3780. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3781. } else {
  3782. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3783. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3784. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3785. }
  3786. }
  3787. },
  3788. getValue: function () {
  3789. if (this.elem.globalData.frameId === this.frameId) {
  3790. return;
  3791. }
  3792. this.frameId = this.elem.globalData.frameId;
  3793. this.iterateDynamicProperties();
  3794. if (this._mdf) {
  3795. this.convertRectToPath();
  3796. }
  3797. },
  3798. reset: resetShape,
  3799. };
  3800. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3801. return RectShapePropertyFactory;
  3802. }());
  3803. function getShapeProp(elem, data, type) {
  3804. var prop;
  3805. if (type === 3 || type === 4) {
  3806. var dataProp = type === 3 ? data.pt : data.ks;
  3807. var keys = dataProp.k;
  3808. if (keys.length) {
  3809. prop = new KeyframedShapeProperty(elem, data, type);
  3810. } else {
  3811. prop = new ShapeProperty(elem, data, type);
  3812. }
  3813. } else if (type === 5) {
  3814. prop = new RectShapeProperty(elem, data);
  3815. } else if (type === 6) {
  3816. prop = new EllShapeProperty(elem, data);
  3817. } else if (type === 7) {
  3818. prop = new StarShapeProperty(elem, data);
  3819. }
  3820. if (prop.k) {
  3821. elem.addDynamicProperty(prop);
  3822. }
  3823. return prop;
  3824. }
  3825. function getConstructorFunction() {
  3826. return ShapeProperty;
  3827. }
  3828. function getKeyframedConstructorFunction() {
  3829. return KeyframedShapeProperty;
  3830. }
  3831. var ob = {};
  3832. ob.getShapeProp = getShapeProp;
  3833. ob.getConstructorFunction = getConstructorFunction;
  3834. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3835. return ob;
  3836. }());
  3837. /*!
  3838. Transformation Matrix v2.0
  3839. (c) Epistemex 2014-2015
  3840. www.epistemex.com
  3841. By Ken Fyrstenberg
  3842. Contributions by leeoniya.
  3843. License: MIT, header required.
  3844. */
  3845. /**
  3846. * 2D transformation matrix object initialized with identity matrix.
  3847. *
  3848. * The matrix can synchronize a canvas context by supplying the context
  3849. * as an argument, or later apply current absolute transform to an
  3850. * existing context.
  3851. *
  3852. * All values are handled as floating point values.
  3853. *
  3854. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3855. * @prop {number} a - scale x
  3856. * @prop {number} b - shear y
  3857. * @prop {number} c - shear x
  3858. * @prop {number} d - scale y
  3859. * @prop {number} e - translate x
  3860. * @prop {number} f - translate y
  3861. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3862. * @constructor
  3863. */
  3864. const Matrix = (function () {
  3865. var _cos = Math.cos;
  3866. var _sin = Math.sin;
  3867. var _tan = Math.tan;
  3868. var _rnd = Math.round;
  3869. function reset() {
  3870. this.props[0] = 1;
  3871. this.props[1] = 0;
  3872. this.props[2] = 0;
  3873. this.props[3] = 0;
  3874. this.props[4] = 0;
  3875. this.props[5] = 1;
  3876. this.props[6] = 0;
  3877. this.props[7] = 0;
  3878. this.props[8] = 0;
  3879. this.props[9] = 0;
  3880. this.props[10] = 1;
  3881. this.props[11] = 0;
  3882. this.props[12] = 0;
  3883. this.props[13] = 0;
  3884. this.props[14] = 0;
  3885. this.props[15] = 1;
  3886. return this;
  3887. }
  3888. function rotate(angle) {
  3889. if (angle === 0) {
  3890. return this;
  3891. }
  3892. var mCos = _cos(angle);
  3893. var mSin = _sin(angle);
  3894. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3895. }
  3896. function rotateX(angle) {
  3897. if (angle === 0) {
  3898. return this;
  3899. }
  3900. var mCos = _cos(angle);
  3901. var mSin = _sin(angle);
  3902. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3903. }
  3904. function rotateY(angle) {
  3905. if (angle === 0) {
  3906. return this;
  3907. }
  3908. var mCos = _cos(angle);
  3909. var mSin = _sin(angle);
  3910. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3911. }
  3912. function rotateZ(angle) {
  3913. if (angle === 0) {
  3914. return this;
  3915. }
  3916. var mCos = _cos(angle);
  3917. var mSin = _sin(angle);
  3918. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3919. }
  3920. function shear(sx, sy) {
  3921. return this._t(1, sy, sx, 1, 0, 0);
  3922. }
  3923. function skew(ax, ay) {
  3924. return this.shear(_tan(ax), _tan(ay));
  3925. }
  3926. function skewFromAxis(ax, angle) {
  3927. var mCos = _cos(angle);
  3928. var mSin = _sin(angle);
  3929. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3930. ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3931. ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3932. // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  3933. }
  3934. function scale(sx, sy, sz) {
  3935. if (!sz && sz !== 0) {
  3936. sz = 1;
  3937. }
  3938. if (sx === 1 && sy === 1 && sz === 1) {
  3939. return this;
  3940. }
  3941. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  3942. }
  3943. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  3944. this.props[0] = a;
  3945. this.props[1] = b;
  3946. this.props[2] = c;
  3947. this.props[3] = d;
  3948. this.props[4] = e;
  3949. this.props[5] = f;
  3950. this.props[6] = g;
  3951. this.props[7] = h;
  3952. this.props[8] = i;
  3953. this.props[9] = j;
  3954. this.props[10] = k;
  3955. this.props[11] = l;
  3956. this.props[12] = m;
  3957. this.props[13] = n;
  3958. this.props[14] = o;
  3959. this.props[15] = p;
  3960. return this;
  3961. }
  3962. function translate(tx, ty, tz) {
  3963. tz = tz || 0;
  3964. if (tx !== 0 || ty !== 0 || tz !== 0) {
  3965. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  3966. }
  3967. return this;
  3968. }
  3969. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  3970. var _p = this.props;
  3971. 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) {
  3972. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  3973. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  3974. _p[12] = _p[12] * a2 + _p[15] * m2;
  3975. _p[13] = _p[13] * f2 + _p[15] * n2;
  3976. _p[14] = _p[14] * k2 + _p[15] * o2;
  3977. _p[15] *= p2;
  3978. // }
  3979. this._identityCalculated = false;
  3980. return this;
  3981. }
  3982. var a1 = _p[0];
  3983. var b1 = _p[1];
  3984. var c1 = _p[2];
  3985. var d1 = _p[3];
  3986. var e1 = _p[4];
  3987. var f1 = _p[5];
  3988. var g1 = _p[6];
  3989. var h1 = _p[7];
  3990. var i1 = _p[8];
  3991. var j1 = _p[9];
  3992. var k1 = _p[10];
  3993. var l1 = _p[11];
  3994. var m1 = _p[12];
  3995. var n1 = _p[13];
  3996. var o1 = _p[14];
  3997. var p1 = _p[15];
  3998. /* matrix order (canvas compatible):
  3999. * ace
  4000. * bdf
  4001. * 001
  4002. */
  4003. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  4004. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  4005. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  4006. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  4007. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  4008. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  4009. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  4010. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  4011. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  4012. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  4013. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  4014. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  4015. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  4016. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  4017. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  4018. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  4019. this._identityCalculated = false;
  4020. return this;
  4021. }
  4022. function multiply(matrix) {
  4023. var matrixProps = matrix.props;
  4024. return this.transform(
  4025. matrixProps[0],
  4026. matrixProps[1],
  4027. matrixProps[2],
  4028. matrixProps[3],
  4029. matrixProps[4],
  4030. matrixProps[5],
  4031. matrixProps[6],
  4032. matrixProps[7],
  4033. matrixProps[8],
  4034. matrixProps[9],
  4035. matrixProps[10],
  4036. matrixProps[11],
  4037. matrixProps[12],
  4038. matrixProps[13],
  4039. matrixProps[14],
  4040. matrixProps[15]
  4041. );
  4042. }
  4043. function isIdentity() {
  4044. if (!this._identityCalculated) {
  4045. 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);
  4046. this._identityCalculated = true;
  4047. }
  4048. return this._identity;
  4049. }
  4050. function equals(matr) {
  4051. var i = 0;
  4052. while (i < 16) {
  4053. if (matr.props[i] !== this.props[i]) {
  4054. return false;
  4055. }
  4056. i += 1;
  4057. }
  4058. return true;
  4059. }
  4060. function clone(matr) {
  4061. var i;
  4062. for (i = 0; i < 16; i += 1) {
  4063. matr.props[i] = this.props[i];
  4064. }
  4065. return matr;
  4066. }
  4067. function cloneFromProps(props) {
  4068. var i;
  4069. for (i = 0; i < 16; i += 1) {
  4070. this.props[i] = props[i];
  4071. }
  4072. }
  4073. function applyToPoint(x, y, z) {
  4074. return {
  4075. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4076. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4077. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4078. };
  4079. /* return {
  4080. x: x * me.a + y * me.c + me.e,
  4081. y: x * me.b + y * me.d + me.f
  4082. }; */
  4083. }
  4084. function applyToX(x, y, z) {
  4085. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4086. }
  4087. function applyToY(x, y, z) {
  4088. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4089. }
  4090. function applyToZ(x, y, z) {
  4091. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4092. }
  4093. function getInverseMatrix() {
  4094. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4095. var a = this.props[5] / determinant;
  4096. var b = -this.props[1] / determinant;
  4097. var c = -this.props[4] / determinant;
  4098. var d = this.props[0] / determinant;
  4099. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4100. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4101. var inverseMatrix = new Matrix();
  4102. inverseMatrix.props[0] = a;
  4103. inverseMatrix.props[1] = b;
  4104. inverseMatrix.props[4] = c;
  4105. inverseMatrix.props[5] = d;
  4106. inverseMatrix.props[12] = e;
  4107. inverseMatrix.props[13] = f;
  4108. return inverseMatrix;
  4109. }
  4110. function inversePoint(pt) {
  4111. var inverseMatrix = this.getInverseMatrix();
  4112. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4113. }
  4114. function inversePoints(pts) {
  4115. var i;
  4116. var len = pts.length;
  4117. var retPts = [];
  4118. for (i = 0; i < len; i += 1) {
  4119. retPts[i] = inversePoint(pts[i]);
  4120. }
  4121. return retPts;
  4122. }
  4123. function applyToTriplePoints(pt1, pt2, pt3) {
  4124. var arr = createTypedArray('float32', 6);
  4125. if (this.isIdentity()) {
  4126. arr[0] = pt1[0];
  4127. arr[1] = pt1[1];
  4128. arr[2] = pt2[0];
  4129. arr[3] = pt2[1];
  4130. arr[4] = pt3[0];
  4131. arr[5] = pt3[1];
  4132. } else {
  4133. var p0 = this.props[0];
  4134. var p1 = this.props[1];
  4135. var p4 = this.props[4];
  4136. var p5 = this.props[5];
  4137. var p12 = this.props[12];
  4138. var p13 = this.props[13];
  4139. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4140. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4141. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4142. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4143. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4144. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4145. }
  4146. return arr;
  4147. }
  4148. function applyToPointArray(x, y, z) {
  4149. var arr;
  4150. if (this.isIdentity()) {
  4151. arr = [x, y, z];
  4152. } else {
  4153. arr = [
  4154. x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4155. x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4156. x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4157. ];
  4158. }
  4159. return arr;
  4160. }
  4161. function applyToPointStringified(x, y) {
  4162. if (this.isIdentity()) {
  4163. return x + ',' + y;
  4164. }
  4165. var _p = this.props;
  4166. 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;
  4167. }
  4168. function toCSS() {
  4169. // 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.
  4170. /* if(this.isIdentity()) {
  4171. return '';
  4172. } */
  4173. var i = 0;
  4174. var props = this.props;
  4175. var cssValue = 'matrix3d(';
  4176. var v = 10000;
  4177. while (i < 16) {
  4178. cssValue += _rnd(props[i] * v) / v;
  4179. cssValue += i === 15 ? ')' : ',';
  4180. i += 1;
  4181. }
  4182. return cssValue;
  4183. }
  4184. function roundMatrixProperty(val) {
  4185. var v = 10000;
  4186. if ((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
  4187. return _rnd(val * v) / v;
  4188. }
  4189. return val;
  4190. }
  4191. function to2dCSS() {
  4192. // 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.
  4193. /* if(this.isIdentity()) {
  4194. return '';
  4195. } */
  4196. var props = this.props;
  4197. var _a = roundMatrixProperty(props[0]);
  4198. var _b = roundMatrixProperty(props[1]);
  4199. var _c = roundMatrixProperty(props[4]);
  4200. var _d = roundMatrixProperty(props[5]);
  4201. var _e = roundMatrixProperty(props[12]);
  4202. var _f = roundMatrixProperty(props[13]);
  4203. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4204. }
  4205. return function () {
  4206. this.reset = reset;
  4207. this.rotate = rotate;
  4208. this.rotateX = rotateX;
  4209. this.rotateY = rotateY;
  4210. this.rotateZ = rotateZ;
  4211. this.skew = skew;
  4212. this.skewFromAxis = skewFromAxis;
  4213. this.shear = shear;
  4214. this.scale = scale;
  4215. this.setTransform = setTransform;
  4216. this.translate = translate;
  4217. this.transform = transform;
  4218. this.multiply = multiply;
  4219. this.applyToPoint = applyToPoint;
  4220. this.applyToX = applyToX;
  4221. this.applyToY = applyToY;
  4222. this.applyToZ = applyToZ;
  4223. this.applyToPointArray = applyToPointArray;
  4224. this.applyToTriplePoints = applyToTriplePoints;
  4225. this.applyToPointStringified = applyToPointStringified;
  4226. this.toCSS = toCSS;
  4227. this.to2dCSS = to2dCSS;
  4228. this.clone = clone;
  4229. this.cloneFromProps = cloneFromProps;
  4230. this.equals = equals;
  4231. this.inversePoints = inversePoints;
  4232. this.inversePoint = inversePoint;
  4233. this.getInverseMatrix = getInverseMatrix;
  4234. this._t = this.transform;
  4235. this.isIdentity = isIdentity;
  4236. this._identity = true;
  4237. this._identityCalculated = false;
  4238. this.props = createTypedArray('float32', 16);
  4239. this.reset();
  4240. };
  4241. }());
  4242. const lottie = {};
  4243. var standalone = '__[STANDALONE]__';
  4244. var animationData = '__[ANIMATIONDATA]__';
  4245. var renderer = '';
  4246. function setLocation(href) {
  4247. setLocationHref(href);
  4248. }
  4249. function searchAnimations() {
  4250. if (standalone === true) {
  4251. animationManager.searchAnimations(animationData, standalone, renderer);
  4252. } else {
  4253. animationManager.searchAnimations();
  4254. }
  4255. }
  4256. function setSubframeRendering(flag) {
  4257. setSubframeEnabled(flag);
  4258. }
  4259. function setPrefix(prefix) {
  4260. setIdPrefix(prefix);
  4261. }
  4262. function loadAnimation(params) {
  4263. if (standalone === true) {
  4264. params.animationData = JSON.parse(animationData);
  4265. }
  4266. return animationManager.loadAnimation(params);
  4267. }
  4268. function setQuality(value) {
  4269. if (typeof value === 'string') {
  4270. switch (value) {
  4271. case 'high':
  4272. setDefaultCurveSegments(200);
  4273. break;
  4274. default:
  4275. case 'medium':
  4276. setDefaultCurveSegments(50);
  4277. break;
  4278. case 'low':
  4279. setDefaultCurveSegments(10);
  4280. break;
  4281. }
  4282. } else if (!isNaN(value) && value > 1) {
  4283. setDefaultCurveSegments(value);
  4284. }
  4285. if (getDefaultCurveSegments() >= 50) {
  4286. roundValues(false);
  4287. } else {
  4288. roundValues(true);
  4289. }
  4290. }
  4291. function inBrowser() {
  4292. return typeof navigator !== 'undefined';
  4293. }
  4294. function installPlugin(type, plugin) {
  4295. if (type === 'expressions') {
  4296. setExpressionsPlugin(plugin);
  4297. }
  4298. }
  4299. function getFactory(name) {
  4300. switch (name) {
  4301. case 'propertyFactory':
  4302. return PropertyFactory;
  4303. case 'shapePropertyFactory':
  4304. return ShapePropertyFactory;
  4305. case 'matrix':
  4306. return Matrix;
  4307. default:
  4308. return null;
  4309. }
  4310. }
  4311. lottie.play = animationManager.play;
  4312. lottie.pause = animationManager.pause;
  4313. lottie.setLocationHref = setLocation;
  4314. lottie.togglePause = animationManager.togglePause;
  4315. lottie.setSpeed = animationManager.setSpeed;
  4316. lottie.setDirection = animationManager.setDirection;
  4317. lottie.stop = animationManager.stop;
  4318. lottie.searchAnimations = searchAnimations;
  4319. lottie.registerAnimation = animationManager.registerAnimation;
  4320. lottie.loadAnimation = loadAnimation;
  4321. lottie.setSubframeRendering = setSubframeRendering;
  4322. lottie.resize = animationManager.resize;
  4323. // lottie.start = start;
  4324. lottie.goToAndStop = animationManager.goToAndStop;
  4325. lottie.destroy = animationManager.destroy;
  4326. lottie.setQuality = setQuality;
  4327. lottie.inBrowser = inBrowser;
  4328. lottie.installPlugin = installPlugin;
  4329. lottie.freeze = animationManager.freeze;
  4330. lottie.unfreeze = animationManager.unfreeze;
  4331. lottie.setVolume = animationManager.setVolume;
  4332. lottie.mute = animationManager.mute;
  4333. lottie.unmute = animationManager.unmute;
  4334. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4335. lottie.useWebWorker = setWebWorker;
  4336. lottie.setIDPrefix = setPrefix;
  4337. lottie.__getFactory = getFactory;
  4338. lottie.version = '[[BM_VERSION]]';
  4339. function checkReady() {
  4340. if (document.readyState === 'complete') {
  4341. clearInterval(readyStateCheckInterval);
  4342. searchAnimations();
  4343. }
  4344. }
  4345. function getQueryVariable(variable) {
  4346. var vars = queryString.split('&');
  4347. for (var i = 0; i < vars.length; i += 1) {
  4348. var pair = vars[i].split('=');
  4349. if (decodeURIComponent(pair[0]) == variable) { // eslint-disable-line eqeqeq
  4350. return decodeURIComponent(pair[1]);
  4351. }
  4352. }
  4353. return null;
  4354. }
  4355. var queryString = '';
  4356. if (standalone) {
  4357. var scripts = document.getElementsByTagName('script');
  4358. var index = scripts.length - 1;
  4359. var myScript = scripts[index] || {
  4360. src: '',
  4361. };
  4362. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4363. renderer = getQueryVariable('renderer');
  4364. }
  4365. var readyStateCheckInterval = setInterval(checkReady, 100);
  4366. // this adds bodymovin to the window object for backwards compatibility
  4367. try {
  4368. if (!(typeof exports === 'object' && typeof module !== 'undefined')
  4369. && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4370. ) {
  4371. window.bodymovin = lottie;
  4372. }
  4373. } catch (err) {
  4374. //
  4375. }
  4376. const ShapeModifiers = (function () {
  4377. var ob = {};
  4378. var modifiers = {};
  4379. ob.registerModifier = registerModifier;
  4380. ob.getModifier = getModifier;
  4381. function registerModifier(nm, factory) {
  4382. if (!modifiers[nm]) {
  4383. modifiers[nm] = factory;
  4384. }
  4385. }
  4386. function getModifier(nm, elem, data) {
  4387. return new modifiers[nm](elem, data);
  4388. }
  4389. return ob;
  4390. }());
  4391. function ShapeModifier() {}
  4392. ShapeModifier.prototype.initModifierProperties = function () {};
  4393. ShapeModifier.prototype.addShapeToModifier = function () {};
  4394. ShapeModifier.prototype.addShape = function (data) {
  4395. if (!this.closed) {
  4396. // 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.
  4397. data.sh.container.addDynamicProperty(data.sh);
  4398. var shapeData = { shape: data.sh, data: data, localShapeCollection: shapeCollectionPool.newShapeCollection() };
  4399. this.shapes.push(shapeData);
  4400. this.addShapeToModifier(shapeData);
  4401. if (this._isAnimated) {
  4402. data.setAsAnimated();
  4403. }
  4404. }
  4405. };
  4406. ShapeModifier.prototype.init = function (elem, data) {
  4407. this.shapes = [];
  4408. this.elem = elem;
  4409. this.initDynamicPropertyContainer(elem);
  4410. this.initModifierProperties(elem, data);
  4411. this.frameId = initialDefaultFrame;
  4412. this.closed = false;
  4413. this.k = false;
  4414. if (this.dynamicProperties.length) {
  4415. this.k = true;
  4416. } else {
  4417. this.getValue(true);
  4418. }
  4419. };
  4420. ShapeModifier.prototype.processKeys = function () {
  4421. if (this.elem.globalData.frameId === this.frameId) {
  4422. return;
  4423. }
  4424. this.frameId = this.elem.globalData.frameId;
  4425. this.iterateDynamicProperties();
  4426. };
  4427. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4428. function TrimModifier() {
  4429. }
  4430. extendPrototype([ShapeModifier], TrimModifier);
  4431. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4432. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4433. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4434. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4435. this.sValue = 0;
  4436. this.eValue = 0;
  4437. this.getValue = this.processKeys;
  4438. this.m = data.m;
  4439. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4440. };
  4441. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4442. shapeData.pathsData = [];
  4443. };
  4444. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4445. var segments = [];
  4446. if (e <= 1) {
  4447. segments.push({
  4448. s: s,
  4449. e: e,
  4450. });
  4451. } else if (s >= 1) {
  4452. segments.push({
  4453. s: s - 1,
  4454. e: e - 1,
  4455. });
  4456. } else {
  4457. segments.push({
  4458. s: s,
  4459. e: 1,
  4460. });
  4461. segments.push({
  4462. s: 0,
  4463. e: e - 1,
  4464. });
  4465. }
  4466. var shapeSegments = [];
  4467. var i;
  4468. var len = segments.length;
  4469. var segmentOb;
  4470. for (i = 0; i < len; i += 1) {
  4471. segmentOb = segments[i];
  4472. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4473. var shapeS;
  4474. var shapeE;
  4475. if (segmentOb.s * totalModifierLength <= addedLength) {
  4476. shapeS = 0;
  4477. } else {
  4478. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4479. }
  4480. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4481. shapeE = 1;
  4482. } else {
  4483. shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength);
  4484. }
  4485. shapeSegments.push([shapeS, shapeE]);
  4486. }
  4487. }
  4488. if (!shapeSegments.length) {
  4489. shapeSegments.push([0, 0]);
  4490. }
  4491. return shapeSegments;
  4492. };
  4493. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4494. var i;
  4495. var len = pathsData.length;
  4496. for (i = 0; i < len; i += 1) {
  4497. segmentsLengthPool.release(pathsData[i]);
  4498. }
  4499. pathsData.length = 0;
  4500. return pathsData;
  4501. };
  4502. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4503. var s;
  4504. var e;
  4505. if (this._mdf || _isFirstFrame) {
  4506. var o = (this.o.v % 360) / 360;
  4507. if (o < 0) {
  4508. o += 1;
  4509. }
  4510. if (this.s.v > 1) {
  4511. s = 1 + o;
  4512. } else if (this.s.v < 0) {
  4513. s = 0 + o;
  4514. } else {
  4515. s = this.s.v + o;
  4516. }
  4517. if (this.e.v > 1) {
  4518. e = 1 + o;
  4519. } else if (this.e.v < 0) {
  4520. e = 0 + o;
  4521. } else {
  4522. e = this.e.v + o;
  4523. }
  4524. if (s > e) {
  4525. var _s = s;
  4526. s = e;
  4527. e = _s;
  4528. }
  4529. s = Math.round(s * 10000) * 0.0001;
  4530. e = Math.round(e * 10000) * 0.0001;
  4531. this.sValue = s;
  4532. this.eValue = e;
  4533. } else {
  4534. s = this.sValue;
  4535. e = this.eValue;
  4536. }
  4537. var shapePaths;
  4538. var i;
  4539. var len = this.shapes.length;
  4540. var j;
  4541. var jLen;
  4542. var pathsData;
  4543. var pathData;
  4544. var totalShapeLength;
  4545. var totalModifierLength = 0;
  4546. if (e === s) {
  4547. for (i = 0; i < len; i += 1) {
  4548. this.shapes[i].localShapeCollection.releaseShapes();
  4549. this.shapes[i].shape._mdf = true;
  4550. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4551. if (this._mdf) {
  4552. this.shapes[i].pathsData.length = 0;
  4553. }
  4554. }
  4555. } else if (!((e === 1 && s === 0) || (e === 0 && s === 1))) {
  4556. var segments = [];
  4557. var shapeData;
  4558. var localShapeCollection;
  4559. for (i = 0; i < len; i += 1) {
  4560. shapeData = this.shapes[i];
  4561. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4562. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4563. shapeData.shape.paths = shapeData.localShapeCollection;
  4564. } else {
  4565. shapePaths = shapeData.shape.paths;
  4566. jLen = shapePaths._length;
  4567. totalShapeLength = 0;
  4568. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4569. totalShapeLength = shapeData.totalShapeLength;
  4570. } else {
  4571. pathsData = this.releasePathsData(shapeData.pathsData);
  4572. for (j = 0; j < jLen; j += 1) {
  4573. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4574. pathsData.push(pathData);
  4575. totalShapeLength += pathData.totalLength;
  4576. }
  4577. shapeData.totalShapeLength = totalShapeLength;
  4578. shapeData.pathsData = pathsData;
  4579. }
  4580. totalModifierLength += totalShapeLength;
  4581. shapeData.shape._mdf = true;
  4582. }
  4583. }
  4584. var shapeS = s;
  4585. var shapeE = e;
  4586. var addedLength = 0;
  4587. var edges;
  4588. for (i = len - 1; i >= 0; i -= 1) {
  4589. shapeData = this.shapes[i];
  4590. if (shapeData.shape._mdf) {
  4591. localShapeCollection = shapeData.localShapeCollection;
  4592. localShapeCollection.releaseShapes();
  4593. // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4594. if (this.m === 2 && len > 1) {
  4595. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4596. addedLength += shapeData.totalShapeLength;
  4597. } else {
  4598. edges = [[shapeS, shapeE]];
  4599. }
  4600. jLen = edges.length;
  4601. for (j = 0; j < jLen; j += 1) {
  4602. shapeS = edges[j][0];
  4603. shapeE = edges[j][1];
  4604. segments.length = 0;
  4605. if (shapeE <= 1) {
  4606. segments.push({
  4607. s: shapeData.totalShapeLength * shapeS,
  4608. e: shapeData.totalShapeLength * shapeE,
  4609. });
  4610. } else if (shapeS >= 1) {
  4611. segments.push({
  4612. s: shapeData.totalShapeLength * (shapeS - 1),
  4613. e: shapeData.totalShapeLength * (shapeE - 1),
  4614. });
  4615. } else {
  4616. segments.push({
  4617. s: shapeData.totalShapeLength * shapeS,
  4618. e: shapeData.totalShapeLength,
  4619. });
  4620. segments.push({
  4621. s: 0,
  4622. e: shapeData.totalShapeLength * (shapeE - 1),
  4623. });
  4624. }
  4625. var newShapesData = this.addShapes(shapeData, segments[0]);
  4626. if (segments[0].s !== segments[0].e) {
  4627. if (segments.length > 1) {
  4628. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4629. if (lastShapeInCollection.c) {
  4630. var lastShape = newShapesData.pop();
  4631. this.addPaths(newShapesData, localShapeCollection);
  4632. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4633. } else {
  4634. this.addPaths(newShapesData, localShapeCollection);
  4635. newShapesData = this.addShapes(shapeData, segments[1]);
  4636. }
  4637. }
  4638. this.addPaths(newShapesData, localShapeCollection);
  4639. }
  4640. }
  4641. shapeData.shape.paths = localShapeCollection;
  4642. }
  4643. }
  4644. } else if (this._mdf) {
  4645. for (i = 0; i < len; i += 1) {
  4646. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4647. // Don't remove this even if it's losing cached info.
  4648. this.shapes[i].pathsData.length = 0;
  4649. this.shapes[i].shape._mdf = true;
  4650. }
  4651. }
  4652. };
  4653. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4654. var i;
  4655. var len = newPaths.length;
  4656. for (i = 0; i < len; i += 1) {
  4657. localShapeCollection.addShape(newPaths[i]);
  4658. }
  4659. };
  4660. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4661. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4662. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4663. if (newShape) {
  4664. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4665. }
  4666. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4667. };
  4668. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4669. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4670. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4671. if (newShape) {
  4672. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4673. }
  4674. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4675. };
  4676. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4677. var pathsData = shapeData.pathsData;
  4678. var shapePaths = shapeData.shape.paths.shapes;
  4679. var i;
  4680. var len = shapeData.shape.paths._length;
  4681. var j;
  4682. var jLen;
  4683. var addedLength = 0;
  4684. var currentLengthData;
  4685. var segmentCount;
  4686. var lengths;
  4687. var segment;
  4688. var shapes = [];
  4689. var initPos;
  4690. var newShape = true;
  4691. if (!shapePath) {
  4692. shapePath = shapePool.newElement();
  4693. segmentCount = 0;
  4694. initPos = 0;
  4695. } else {
  4696. segmentCount = shapePath._length;
  4697. initPos = shapePath._length;
  4698. }
  4699. shapes.push(shapePath);
  4700. for (i = 0; i < len; i += 1) {
  4701. lengths = pathsData[i].lengths;
  4702. shapePath.c = shapePaths[i].c;
  4703. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4704. for (j = 1; j < jLen; j += 1) {
  4705. currentLengthData = lengths[j - 1];
  4706. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4707. addedLength += currentLengthData.addedLength;
  4708. shapePath.c = false;
  4709. } else if (addedLength > shapeSegment.e) {
  4710. shapePath.c = false;
  4711. break;
  4712. } else {
  4713. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4714. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4715. newShape = false;
  4716. } else {
  4717. 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]);
  4718. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4719. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4720. newShape = false;
  4721. shapePath.c = false;
  4722. }
  4723. addedLength += currentLengthData.addedLength;
  4724. segmentCount += 1;
  4725. }
  4726. }
  4727. if (shapePaths[i].c && lengths.length) {
  4728. currentLengthData = lengths[j - 1];
  4729. if (addedLength <= shapeSegment.e) {
  4730. var segmentLength = lengths[j - 1].addedLength;
  4731. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4732. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4733. newShape = false;
  4734. } else {
  4735. 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]);
  4736. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4737. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4738. newShape = false;
  4739. shapePath.c = false;
  4740. }
  4741. } else {
  4742. shapePath.c = false;
  4743. }
  4744. addedLength += currentLengthData.addedLength;
  4745. segmentCount += 1;
  4746. }
  4747. if (shapePath._length) {
  4748. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4749. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4750. }
  4751. if (addedLength > shapeSegment.e) {
  4752. break;
  4753. }
  4754. if (i < len - 1) {
  4755. shapePath = shapePool.newElement();
  4756. newShape = true;
  4757. shapes.push(shapePath);
  4758. segmentCount = 0;
  4759. }
  4760. }
  4761. return shapes;
  4762. };
  4763. function PuckerAndBloatModifier() {}
  4764. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4765. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4766. this.getValue = this.processKeys;
  4767. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4768. this._isAnimated = !!this.amount.effectsSequence.length;
  4769. };
  4770. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4771. var percent = amount / 100;
  4772. var centerPoint = [0, 0];
  4773. var pathLength = path._length;
  4774. var i = 0;
  4775. for (i = 0; i < pathLength; i += 1) {
  4776. centerPoint[0] += path.v[i][0];
  4777. centerPoint[1] += path.v[i][1];
  4778. }
  4779. centerPoint[0] /= pathLength;
  4780. centerPoint[1] /= pathLength;
  4781. var clonedPath = shapePool.newElement();
  4782. clonedPath.c = path.c;
  4783. var vX;
  4784. var vY;
  4785. var oX;
  4786. var oY;
  4787. var iX;
  4788. var iY;
  4789. for (i = 0; i < pathLength; i += 1) {
  4790. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4791. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4792. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4793. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4794. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4795. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4796. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4797. }
  4798. return clonedPath;
  4799. };
  4800. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4801. var shapePaths;
  4802. var i;
  4803. var len = this.shapes.length;
  4804. var j;
  4805. var jLen;
  4806. var amount = this.amount.v;
  4807. if (amount !== 0) {
  4808. var shapeData;
  4809. var localShapeCollection;
  4810. for (i = 0; i < len; i += 1) {
  4811. shapeData = this.shapes[i];
  4812. localShapeCollection = shapeData.localShapeCollection;
  4813. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4814. localShapeCollection.releaseShapes();
  4815. shapeData.shape._mdf = true;
  4816. shapePaths = shapeData.shape.paths.shapes;
  4817. jLen = shapeData.shape.paths._length;
  4818. for (j = 0; j < jLen; j += 1) {
  4819. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4820. }
  4821. }
  4822. shapeData.shape.paths = shapeData.localShapeCollection;
  4823. }
  4824. }
  4825. if (!this.dynamicProperties.length) {
  4826. this._mdf = false;
  4827. }
  4828. };
  4829. const TransformPropertyFactory = (function () {
  4830. var defaultVector = [0, 0];
  4831. function applyToMatrix(mat) {
  4832. var _mdf = this._mdf;
  4833. this.iterateDynamicProperties();
  4834. this._mdf = this._mdf || _mdf;
  4835. if (this.a) {
  4836. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4837. }
  4838. if (this.s) {
  4839. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4840. }
  4841. if (this.sk) {
  4842. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4843. }
  4844. if (this.r) {
  4845. mat.rotate(-this.r.v);
  4846. } else {
  4847. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4848. .rotateY(this.or.v[1])
  4849. .rotateX(this.or.v[0]);
  4850. }
  4851. if (this.data.p.s) {
  4852. if (this.data.p.z) {
  4853. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4854. } else {
  4855. mat.translate(this.px.v, this.py.v, 0);
  4856. }
  4857. } else {
  4858. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4859. }
  4860. }
  4861. function processKeys(forceRender) {
  4862. if (this.elem.globalData.frameId === this.frameId) {
  4863. return;
  4864. }
  4865. if (this._isDirty) {
  4866. this.precalculateMatrix();
  4867. this._isDirty = false;
  4868. }
  4869. this.iterateDynamicProperties();
  4870. if (this._mdf || forceRender) {
  4871. var frameRate;
  4872. this.v.cloneFromProps(this.pre.props);
  4873. if (this.appliedTransformations < 1) {
  4874. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4875. }
  4876. if (this.appliedTransformations < 2) {
  4877. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4878. }
  4879. if (this.sk && this.appliedTransformations < 3) {
  4880. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4881. }
  4882. if (this.r && this.appliedTransformations < 4) {
  4883. this.v.rotate(-this.r.v);
  4884. } else if (!this.r && this.appliedTransformations < 4) {
  4885. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4886. .rotateY(this.or.v[1])
  4887. .rotateX(this.or.v[0]);
  4888. }
  4889. if (this.autoOriented) {
  4890. var v1;
  4891. var v2;
  4892. frameRate = this.elem.globalData.frameRate;
  4893. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4894. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4895. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4896. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4897. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4898. v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0);
  4899. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4900. } else {
  4901. v1 = this.p.pv;
  4902. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4903. }
  4904. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4905. v1 = [];
  4906. v2 = [];
  4907. var px = this.px;
  4908. var py = this.py;
  4909. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4910. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4911. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4912. v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate, 0);
  4913. v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate, 0);
  4914. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4915. v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate), 0);
  4916. v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate), 0);
  4917. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4918. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4919. } else {
  4920. v1 = [px.pv, py.pv];
  4921. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4922. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4923. }
  4924. } else {
  4925. v2 = defaultVector;
  4926. v1 = v2;
  4927. }
  4928. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4929. }
  4930. if (this.data.p && this.data.p.s) {
  4931. if (this.data.p.z) {
  4932. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4933. } else {
  4934. this.v.translate(this.px.v, this.py.v, 0);
  4935. }
  4936. } else {
  4937. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4938. }
  4939. }
  4940. this.frameId = this.elem.globalData.frameId;
  4941. }
  4942. function precalculateMatrix() {
  4943. this.appliedTransformations = 0;
  4944. this.pre.reset();
  4945. if (!this.a.effectsSequence.length) {
  4946. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4947. this.appliedTransformations = 1;
  4948. } else {
  4949. return;
  4950. }
  4951. if (!this.s.effectsSequence.length) {
  4952. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4953. this.appliedTransformations = 2;
  4954. } else {
  4955. return;
  4956. }
  4957. if (this.sk) {
  4958. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  4959. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  4960. this.appliedTransformations = 3;
  4961. } else {
  4962. return;
  4963. }
  4964. }
  4965. if (this.r) {
  4966. if (!this.r.effectsSequence.length) {
  4967. this.pre.rotate(-this.r.v);
  4968. this.appliedTransformations = 4;
  4969. }
  4970. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  4971. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4972. .rotateY(this.or.v[1])
  4973. .rotateX(this.or.v[0]);
  4974. this.appliedTransformations = 4;
  4975. }
  4976. }
  4977. function autoOrient() {
  4978. //
  4979. // var prevP = this.getValueAtTime();
  4980. }
  4981. function addDynamicProperty(prop) {
  4982. this._addDynamicProperty(prop);
  4983. this.elem.addDynamicProperty(prop);
  4984. this._isDirty = true;
  4985. }
  4986. function TransformProperty(elem, data, container) {
  4987. this.elem = elem;
  4988. this.frameId = -1;
  4989. this.propType = 'transform';
  4990. this.data = data;
  4991. this.v = new Matrix();
  4992. // Precalculated matrix with non animated properties
  4993. this.pre = new Matrix();
  4994. this.appliedTransformations = 0;
  4995. this.initDynamicPropertyContainer(container || elem);
  4996. if (data.p && data.p.s) {
  4997. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  4998. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  4999. if (data.p.z) {
  5000. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  5001. }
  5002. } else {
  5003. this.p = PropertyFactory.getProp(elem, data.p || { k: [0, 0, 0] }, 1, 0, this);
  5004. }
  5005. if (data.rx) {
  5006. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  5007. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  5008. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  5009. if (data.or.k[0].ti) {
  5010. var i;
  5011. var len = data.or.k.length;
  5012. for (i = 0; i < len; i += 1) {
  5013. data.or.k[i].to = null;
  5014. data.or.k[i].ti = null;
  5015. }
  5016. }
  5017. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  5018. // sh Indicates it needs to be capped between -180 and 180
  5019. this.or.sh = true;
  5020. } else {
  5021. this.r = PropertyFactory.getProp(elem, data.r || { k: 0 }, 0, degToRads, this);
  5022. }
  5023. if (data.sk) {
  5024. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  5025. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  5026. }
  5027. this.a = PropertyFactory.getProp(elem, data.a || { k: [0, 0, 0] }, 1, 0, this);
  5028. this.s = PropertyFactory.getProp(elem, data.s || { k: [100, 100, 100] }, 1, 0.01, this);
  5029. // 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.
  5030. if (data.o) {
  5031. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  5032. } else {
  5033. this.o = { _mdf: false, v: 1 };
  5034. }
  5035. this._isDirty = true;
  5036. if (!this.dynamicProperties.length) {
  5037. this.getValue(true);
  5038. }
  5039. }
  5040. TransformProperty.prototype = {
  5041. applyToMatrix: applyToMatrix,
  5042. getValue: processKeys,
  5043. precalculateMatrix: precalculateMatrix,
  5044. autoOrient: autoOrient,
  5045. };
  5046. extendPrototype([DynamicPropertyContainer], TransformProperty);
  5047. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  5048. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  5049. function getTransformProperty(elem, data, container) {
  5050. return new TransformProperty(elem, data, container);
  5051. }
  5052. return {
  5053. getTransformProperty: getTransformProperty,
  5054. };
  5055. }());
  5056. function RepeaterModifier() {}
  5057. extendPrototype([ShapeModifier], RepeaterModifier);
  5058. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5059. this.getValue = this.processKeys;
  5060. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5061. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5062. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5063. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5064. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5065. this.data = data;
  5066. if (!this.dynamicProperties.length) {
  5067. this.getValue(true);
  5068. }
  5069. this._isAnimated = !!this.dynamicProperties.length;
  5070. this.pMatrix = new Matrix();
  5071. this.rMatrix = new Matrix();
  5072. this.sMatrix = new Matrix();
  5073. this.tMatrix = new Matrix();
  5074. this.matrix = new Matrix();
  5075. };
  5076. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5077. var dir = inv ? -1 : 1;
  5078. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5079. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5080. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5081. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5082. rMatrix.rotate(-transform.r.v * dir * perc);
  5083. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5084. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5085. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5086. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5087. };
  5088. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5089. this.elem = elem;
  5090. this.arr = arr;
  5091. this.pos = pos;
  5092. this.elemsData = elemsData;
  5093. this._currentCopies = 0;
  5094. this._elements = [];
  5095. this._groups = [];
  5096. this.frameId = -1;
  5097. this.initDynamicPropertyContainer(elem);
  5098. this.initModifierProperties(elem, arr[pos]);
  5099. while (pos > 0) {
  5100. pos -= 1;
  5101. // this._elements.unshift(arr.splice(pos,1)[0]);
  5102. this._elements.unshift(arr[pos]);
  5103. }
  5104. if (this.dynamicProperties.length) {
  5105. this.k = true;
  5106. } else {
  5107. this.getValue(true);
  5108. }
  5109. };
  5110. RepeaterModifier.prototype.resetElements = function (elements) {
  5111. var i;
  5112. var len = elements.length;
  5113. for (i = 0; i < len; i += 1) {
  5114. elements[i]._processed = false;
  5115. if (elements[i].ty === 'gr') {
  5116. this.resetElements(elements[i].it);
  5117. }
  5118. }
  5119. };
  5120. RepeaterModifier.prototype.cloneElements = function (elements) {
  5121. var newElements = JSON.parse(JSON.stringify(elements));
  5122. this.resetElements(newElements);
  5123. return newElements;
  5124. };
  5125. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5126. var i;
  5127. var len = elements.length;
  5128. for (i = 0; i < len; i += 1) {
  5129. elements[i]._render = renderFlag;
  5130. if (elements[i].ty === 'gr') {
  5131. this.changeGroupRender(elements[i].it, renderFlag);
  5132. }
  5133. }
  5134. };
  5135. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5136. var items;
  5137. var itemsTransform;
  5138. var i;
  5139. var dir;
  5140. var cont;
  5141. var hasReloaded = false;
  5142. if (this._mdf || _isFirstFrame) {
  5143. var copies = Math.ceil(this.c.v);
  5144. if (this._groups.length < copies) {
  5145. while (this._groups.length < copies) {
  5146. var group = {
  5147. it: this.cloneElements(this._elements),
  5148. ty: 'gr',
  5149. };
  5150. group.it.push({
  5151. a: { a: 0, ix: 1, k: [0, 0] }, nm: 'Transform', o: { a: 0, ix: 7, k: 100 }, p: { a: 0, ix: 2, k: [0, 0] }, r: { a: 1, ix: 6, k: [{ s: 0, e: 0, t: 0 }, { s: 0, e: 0, t: 1 }] }, s: { a: 0, ix: 3, k: [100, 100] }, sa: { a: 0, ix: 5, k: 0 }, sk: { a: 0, ix: 4, k: 0 }, ty: 'tr',
  5152. });
  5153. this.arr.splice(0, 0, group);
  5154. this._groups.splice(0, 0, group);
  5155. this._currentCopies += 1;
  5156. }
  5157. this.elem.reloadShapes();
  5158. hasReloaded = true;
  5159. }
  5160. cont = 0;
  5161. var renderFlag;
  5162. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5163. renderFlag = cont < copies;
  5164. this._groups[i]._render = renderFlag;
  5165. this.changeGroupRender(this._groups[i].it, renderFlag);
  5166. if (!renderFlag) {
  5167. var elems = this.elemsData[i].it;
  5168. var transformData = elems[elems.length - 1];
  5169. if (transformData.transform.op.v !== 0) {
  5170. transformData.transform.op._mdf = true;
  5171. transformData.transform.op.v = 0;
  5172. } else {
  5173. transformData.transform.op._mdf = false;
  5174. }
  5175. }
  5176. cont += 1;
  5177. }
  5178. this._currentCopies = copies;
  5179. /// /
  5180. var offset = this.o.v;
  5181. var offsetModulo = offset % 1;
  5182. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5183. var pProps = this.pMatrix.props;
  5184. var rProps = this.rMatrix.props;
  5185. var sProps = this.sMatrix.props;
  5186. this.pMatrix.reset();
  5187. this.rMatrix.reset();
  5188. this.sMatrix.reset();
  5189. this.tMatrix.reset();
  5190. this.matrix.reset();
  5191. var iteration = 0;
  5192. if (offset > 0) {
  5193. while (iteration < roundOffset) {
  5194. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5195. iteration += 1;
  5196. }
  5197. if (offsetModulo) {
  5198. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5199. iteration += offsetModulo;
  5200. }
  5201. } else if (offset < 0) {
  5202. while (iteration > roundOffset) {
  5203. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5204. iteration -= 1;
  5205. }
  5206. if (offsetModulo) {
  5207. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5208. iteration -= offsetModulo;
  5209. }
  5210. }
  5211. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5212. dir = this.data.m === 1 ? 1 : -1;
  5213. cont = this._currentCopies;
  5214. var j;
  5215. var jLen;
  5216. while (cont) {
  5217. items = this.elemsData[i].it;
  5218. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5219. jLen = itemsTransform.length;
  5220. items[items.length - 1].transform.mProps._mdf = true;
  5221. items[items.length - 1].transform.op._mdf = true;
  5222. items[items.length - 1].transform.op.v = this._currentCopies === 1
  5223. ? this.so.v
  5224. : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5225. if (iteration !== 0) {
  5226. if ((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)) {
  5227. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5228. }
  5229. 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]);
  5230. 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]);
  5231. 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]);
  5232. for (j = 0; j < jLen; j += 1) {
  5233. itemsTransform[j] = this.matrix.props[j];
  5234. }
  5235. this.matrix.reset();
  5236. } else {
  5237. this.matrix.reset();
  5238. for (j = 0; j < jLen; j += 1) {
  5239. itemsTransform[j] = this.matrix.props[j];
  5240. }
  5241. }
  5242. iteration += 1;
  5243. cont -= 1;
  5244. i += dir;
  5245. }
  5246. } else {
  5247. cont = this._currentCopies;
  5248. i = 0;
  5249. dir = 1;
  5250. while (cont) {
  5251. items = this.elemsData[i].it;
  5252. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5253. items[items.length - 1].transform.mProps._mdf = false;
  5254. items[items.length - 1].transform.op._mdf = false;
  5255. cont -= 1;
  5256. i += dir;
  5257. }
  5258. }
  5259. return hasReloaded;
  5260. };
  5261. RepeaterModifier.prototype.addShape = function () {};
  5262. function RoundCornersModifier() {}
  5263. extendPrototype([ShapeModifier], RoundCornersModifier);
  5264. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5265. this.getValue = this.processKeys;
  5266. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5267. this._isAnimated = !!this.rd.effectsSequence.length;
  5268. };
  5269. RoundCornersModifier.prototype.processPath = function (path, round) {
  5270. var clonedPath = shapePool.newElement();
  5271. clonedPath.c = path.c;
  5272. var i;
  5273. var len = path._length;
  5274. var currentV;
  5275. var currentI;
  5276. var currentO;
  5277. var closerV;
  5278. var distance;
  5279. var newPosPerc;
  5280. var index = 0;
  5281. var vX;
  5282. var vY;
  5283. var oX;
  5284. var oY;
  5285. var iX;
  5286. var iY;
  5287. for (i = 0; i < len; i += 1) {
  5288. currentV = path.v[i];
  5289. currentO = path.o[i];
  5290. currentI = path.i[i];
  5291. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5292. if ((i === 0 || i === len - 1) && !path.c) {
  5293. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5294. /* clonedPath.v[index] = currentV;
  5295. clonedPath.o[index] = currentO;
  5296. clonedPath.i[index] = currentI; */
  5297. index += 1;
  5298. } else {
  5299. if (i === 0) {
  5300. closerV = path.v[len - 1];
  5301. } else {
  5302. closerV = path.v[i - 1];
  5303. }
  5304. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5305. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5306. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5307. vX = iX;
  5308. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5309. vY = iY;
  5310. oX = vX - (vX - currentV[0]) * roundCorner;
  5311. oY = vY - (vY - currentV[1]) * roundCorner;
  5312. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5313. index += 1;
  5314. if (i === len - 1) {
  5315. closerV = path.v[0];
  5316. } else {
  5317. closerV = path.v[i + 1];
  5318. }
  5319. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5320. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5321. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5322. vX = oX;
  5323. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5324. vY = oY;
  5325. iX = vX - (vX - currentV[0]) * roundCorner;
  5326. iY = vY - (vY - currentV[1]) * roundCorner;
  5327. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5328. index += 1;
  5329. }
  5330. } else {
  5331. 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);
  5332. index += 1;
  5333. }
  5334. }
  5335. return clonedPath;
  5336. };
  5337. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5338. var shapePaths;
  5339. var i;
  5340. var len = this.shapes.length;
  5341. var j;
  5342. var jLen;
  5343. var rd = this.rd.v;
  5344. if (rd !== 0) {
  5345. var shapeData;
  5346. var localShapeCollection;
  5347. for (i = 0; i < len; i += 1) {
  5348. shapeData = this.shapes[i];
  5349. localShapeCollection = shapeData.localShapeCollection;
  5350. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5351. localShapeCollection.releaseShapes();
  5352. shapeData.shape._mdf = true;
  5353. shapePaths = shapeData.shape.paths.shapes;
  5354. jLen = shapeData.shape.paths._length;
  5355. for (j = 0; j < jLen; j += 1) {
  5356. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5357. }
  5358. }
  5359. shapeData.shape.paths = shapeData.localShapeCollection;
  5360. }
  5361. }
  5362. if (!this.dynamicProperties.length) {
  5363. this._mdf = false;
  5364. }
  5365. };
  5366. function floatEqual(a, b) {
  5367. return Math.abs(a - b) * 100000 <= Math.min(Math.abs(a), Math.abs(b));
  5368. }
  5369. function floatZero(f) {
  5370. return Math.abs(f) <= 0.00001;
  5371. }
  5372. function lerp(p0, p1, amount) {
  5373. return p0 * (1 - amount) + p1 * amount;
  5374. }
  5375. function lerpPoint(p0, p1, amount) {
  5376. return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
  5377. }
  5378. function quadRoots(a, b, c) {
  5379. // no root
  5380. if (a === 0) return [];
  5381. var s = b * b - 4 * a * c;
  5382. // Complex roots
  5383. if (s < 0) return [];
  5384. var singleRoot = -b / (2 * a);
  5385. // 1 root
  5386. if (s === 0) return [singleRoot];
  5387. var delta = Math.sqrt(s) / (2 * a);
  5388. // 2 roots
  5389. return [singleRoot - delta, singleRoot + delta];
  5390. }
  5391. function polynomialCoefficients(p0, p1, p2, p3) {
  5392. return [
  5393. -p0 + 3 * p1 - 3 * p2 + p3,
  5394. 3 * p0 - 6 * p1 + 3 * p2,
  5395. -3 * p0 + 3 * p1,
  5396. p0,
  5397. ];
  5398. }
  5399. function singlePoint(p) {
  5400. return new PolynomialBezier(p, p, p, p, false);
  5401. }
  5402. function PolynomialBezier(p0, p1, p2, p3, linearize) {
  5403. if (linearize && pointEqual(p0, p1)) {
  5404. p1 = lerpPoint(p0, p3, 1 / 3);
  5405. }
  5406. if (linearize && pointEqual(p2, p3)) {
  5407. p2 = lerpPoint(p0, p3, 2 / 3);
  5408. }
  5409. var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
  5410. var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
  5411. this.a = [coeffx[0], coeffy[0]];
  5412. this.b = [coeffx[1], coeffy[1]];
  5413. this.c = [coeffx[2], coeffy[2]];
  5414. this.d = [coeffx[3], coeffy[3]];
  5415. this.points = [p0, p1, p2, p3];
  5416. }
  5417. PolynomialBezier.prototype.point = function (t) {
  5418. return [
  5419. (((this.a[0] * t) + this.b[0]) * t + this.c[0]) * t + this.d[0],
  5420. (((this.a[1] * t) + this.b[1]) * t + this.c[1]) * t + this.d[1],
  5421. ];
  5422. };
  5423. PolynomialBezier.prototype.derivative = function (t) {
  5424. return [
  5425. (3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0],
  5426. (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1],
  5427. ];
  5428. };
  5429. PolynomialBezier.prototype.tangentAngle = function (t) {
  5430. var p = this.derivative(t);
  5431. return Math.atan2(p[1], p[0]);
  5432. };
  5433. PolynomialBezier.prototype.normalAngle = function (t) {
  5434. var p = this.derivative(t);
  5435. return Math.atan2(p[0], p[1]);
  5436. };
  5437. PolynomialBezier.prototype.inflectionPoints = function () {
  5438. var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
  5439. if (floatZero(denom)) return [];
  5440. var tcusp = (-0.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1])) / denom;
  5441. var square = tcusp * tcusp - ((1 / 3) * (this.b[1] * this.c[0] - this.b[0] * this.c[1])) / denom;
  5442. if (square < 0) return [];
  5443. var root = Math.sqrt(square);
  5444. if (floatZero(root)) {
  5445. if (root > 0 && root < 1) return [tcusp];
  5446. return [];
  5447. }
  5448. return [tcusp - root, tcusp + root].filter(function (r) { return r > 0 && r < 1; });
  5449. };
  5450. PolynomialBezier.prototype.split = function (t) {
  5451. if (t <= 0) return [singlePoint(this.points[0]), this];
  5452. if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
  5453. var p10 = lerpPoint(this.points[0], this.points[1], t);
  5454. var p11 = lerpPoint(this.points[1], this.points[2], t);
  5455. var p12 = lerpPoint(this.points[2], this.points[3], t);
  5456. var p20 = lerpPoint(p10, p11, t);
  5457. var p21 = lerpPoint(p11, p12, t);
  5458. var p3 = lerpPoint(p20, p21, t);
  5459. return [
  5460. new PolynomialBezier(this.points[0], p10, p20, p3, true),
  5461. new PolynomialBezier(p3, p21, p12, this.points[3], true),
  5462. ];
  5463. };
  5464. function extrema(bez, comp) {
  5465. var min = bez.points[0][comp];
  5466. var max = bez.points[bez.points.length - 1][comp];
  5467. if (min > max) {
  5468. var e = max;
  5469. max = min;
  5470. min = e;
  5471. }
  5472. // Derivative roots to find min/max
  5473. var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
  5474. for (var i = 0; i < f.length; i += 1) {
  5475. if (f[i] > 0 && f[i] < 1) {
  5476. var val = bez.point(f[i])[comp];
  5477. if (val < min) min = val;
  5478. else if (val > max) max = val;
  5479. }
  5480. }
  5481. return {
  5482. min: min,
  5483. max: max,
  5484. };
  5485. }
  5486. PolynomialBezier.prototype.bounds = function () {
  5487. return {
  5488. x: extrema(this, 0),
  5489. y: extrema(this, 1),
  5490. };
  5491. };
  5492. PolynomialBezier.prototype.boundingBox = function () {
  5493. var bounds = this.bounds();
  5494. return {
  5495. left: bounds.x.min,
  5496. right: bounds.x.max,
  5497. top: bounds.y.min,
  5498. bottom: bounds.y.max,
  5499. width: bounds.x.max - bounds.x.min,
  5500. height: bounds.y.max - bounds.y.min,
  5501. cx: (bounds.x.max + bounds.x.min) / 2,
  5502. cy: (bounds.y.max + bounds.y.min) / 2,
  5503. };
  5504. };
  5505. function intersectData(bez, t1, t2) {
  5506. var box = bez.boundingBox();
  5507. return {
  5508. cx: box.cx,
  5509. cy: box.cy,
  5510. width: box.width,
  5511. height: box.height,
  5512. bez: bez,
  5513. t: (t1 + t2) / 2,
  5514. t1: t1,
  5515. t2: t2,
  5516. };
  5517. }
  5518. function splitData(data) {
  5519. var split = data.bez.split(0.5);
  5520. return [
  5521. intersectData(split[0], data.t1, data.t),
  5522. intersectData(split[1], data.t, data.t2),
  5523. ];
  5524. }
  5525. function boxIntersect(b1, b2) {
  5526. return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width
  5527. && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
  5528. }
  5529. function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
  5530. if (!boxIntersect(d1, d2)) return;
  5531. if (depth >= maxRecursion || (d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance)) {
  5532. intersections.push([d1.t, d2.t]);
  5533. return;
  5534. }
  5535. var d1s = splitData(d1);
  5536. var d2s = splitData(d2);
  5537. intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5538. intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5539. intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5540. intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5541. }
  5542. PolynomialBezier.prototype.intersections = function (other, tolerance, maxRecursion) {
  5543. if (tolerance === undefined) tolerance = 2;
  5544. if (maxRecursion === undefined) maxRecursion = 7;
  5545. var intersections = [];
  5546. intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
  5547. return intersections;
  5548. };
  5549. PolynomialBezier.shapeSegment = function (shapePath, index) {
  5550. var nextIndex = (index + 1) % shapePath.length();
  5551. return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
  5552. };
  5553. PolynomialBezier.shapeSegmentInverted = function (shapePath, index) {
  5554. var nextIndex = (index + 1) % shapePath.length();
  5555. return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
  5556. };
  5557. function crossProduct(a, b) {
  5558. return [
  5559. a[1] * b[2] - a[2] * b[1],
  5560. a[2] * b[0] - a[0] * b[2],
  5561. a[0] * b[1] - a[1] * b[0],
  5562. ];
  5563. }
  5564. function lineIntersection(start1, end1, start2, end2) {
  5565. var v1 = [start1[0], start1[1], 1];
  5566. var v2 = [end1[0], end1[1], 1];
  5567. var v3 = [start2[0], start2[1], 1];
  5568. var v4 = [end2[0], end2[1], 1];
  5569. var r = crossProduct(
  5570. crossProduct(v1, v2),
  5571. crossProduct(v3, v4)
  5572. );
  5573. if (floatZero(r[2])) return null;
  5574. return [r[0] / r[2], r[1] / r[2]];
  5575. }
  5576. function polarOffset(p, angle, length) {
  5577. return [
  5578. p[0] + Math.cos(angle) * length,
  5579. p[1] - Math.sin(angle) * length,
  5580. ];
  5581. }
  5582. function pointDistance(p1, p2) {
  5583. return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
  5584. }
  5585. function pointEqual(p1, p2) {
  5586. return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
  5587. }
  5588. function ZigZagModifier() {}
  5589. extendPrototype([ShapeModifier], ZigZagModifier);
  5590. ZigZagModifier.prototype.initModifierProperties = function (elem, data) {
  5591. this.getValue = this.processKeys;
  5592. this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
  5593. this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5594. this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
  5595. this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
  5596. };
  5597. function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
  5598. var angO = angle - Math.PI / 2;
  5599. var angI = angle + Math.PI / 2;
  5600. var px = point[0] + Math.cos(angle) * direction * amplitude;
  5601. var py = point[1] - Math.sin(angle) * direction * amplitude;
  5602. outputBezier.setTripleAt(
  5603. px,
  5604. py,
  5605. px + Math.cos(angO) * outAmplitude,
  5606. py - Math.sin(angO) * outAmplitude,
  5607. px + Math.cos(angI) * inAmplitude,
  5608. py - Math.sin(angI) * inAmplitude,
  5609. outputBezier.length()
  5610. );
  5611. }
  5612. function getPerpendicularVector(pt1, pt2) {
  5613. var vector = [
  5614. pt2[0] - pt1[0],
  5615. pt2[1] - pt1[1],
  5616. ];
  5617. var rot = -Math.PI * 0.5;
  5618. var rotatedVector = [
  5619. Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1],
  5620. Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1],
  5621. ];
  5622. return rotatedVector;
  5623. }
  5624. function getProjectingAngle(path, cur) {
  5625. var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
  5626. var nextIndex = (cur + 1) % path.length();
  5627. var prevPoint = path.v[prevIndex];
  5628. var nextPoint = path.v[nextIndex];
  5629. var pVector = getPerpendicularVector(prevPoint, nextPoint);
  5630. return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
  5631. }
  5632. function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
  5633. var angle = getProjectingAngle(path, cur);
  5634. var point = path.v[cur % path._length];
  5635. var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
  5636. var nextPoint = path.v[(cur + 1) % path._length];
  5637. var prevDist = pointType === 2
  5638. ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2))
  5639. : 0;
  5640. var nextDist = pointType === 2
  5641. ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2))
  5642. : 0;
  5643. setPoint(
  5644. outputBezier,
  5645. path.v[cur % path._length],
  5646. angle,
  5647. direction,
  5648. amplitude,
  5649. nextDist / ((frequency + 1) * 2),
  5650. prevDist / ((frequency + 1) * 2),
  5651. pointType
  5652. );
  5653. }
  5654. function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
  5655. for (var i = 0; i < frequency; i += 1) {
  5656. var t = (i + 1) / (frequency + 1);
  5657. var dist = pointType === 2
  5658. ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2))
  5659. : 0;
  5660. var angle = segment.normalAngle(t);
  5661. var point = segment.point(t);
  5662. setPoint(
  5663. outputBezier,
  5664. point,
  5665. angle,
  5666. direction,
  5667. amplitude,
  5668. dist / ((frequency + 1) * 2),
  5669. dist / ((frequency + 1) * 2),
  5670. pointType
  5671. );
  5672. direction = -direction;
  5673. }
  5674. return direction;
  5675. }
  5676. ZigZagModifier.prototype.processPath = function (path, amplitude, frequency, pointType) {
  5677. var count = path._length;
  5678. var clonedPath = shapePool.newElement();
  5679. clonedPath.c = path.c;
  5680. if (!path.c) {
  5681. count -= 1;
  5682. }
  5683. if (count === 0) return clonedPath;
  5684. var direction = -1;
  5685. var segment = PolynomialBezier.shapeSegment(path, 0);
  5686. zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
  5687. for (var i = 0; i < count; i += 1) {
  5688. direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
  5689. if (i === count - 1 && !path.c) {
  5690. segment = null;
  5691. } else {
  5692. segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
  5693. }
  5694. zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
  5695. }
  5696. return clonedPath;
  5697. };
  5698. ZigZagModifier.prototype.processShapes = function (_isFirstFrame) {
  5699. var shapePaths;
  5700. var i;
  5701. var len = this.shapes.length;
  5702. var j;
  5703. var jLen;
  5704. var amplitude = this.amplitude.v;
  5705. var frequency = Math.max(0, Math.round(this.frequency.v));
  5706. var pointType = this.pointsType.v;
  5707. if (amplitude !== 0) {
  5708. var shapeData;
  5709. var localShapeCollection;
  5710. for (i = 0; i < len; i += 1) {
  5711. shapeData = this.shapes[i];
  5712. localShapeCollection = shapeData.localShapeCollection;
  5713. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5714. localShapeCollection.releaseShapes();
  5715. shapeData.shape._mdf = true;
  5716. shapePaths = shapeData.shape.paths.shapes;
  5717. jLen = shapeData.shape.paths._length;
  5718. for (j = 0; j < jLen; j += 1) {
  5719. localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
  5720. }
  5721. }
  5722. shapeData.shape.paths = shapeData.localShapeCollection;
  5723. }
  5724. }
  5725. if (!this.dynamicProperties.length) {
  5726. this._mdf = false;
  5727. }
  5728. };
  5729. function linearOffset(p1, p2, amount) {
  5730. var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
  5731. return [
  5732. polarOffset(p1, angle, amount),
  5733. polarOffset(p2, angle, amount),
  5734. ];
  5735. }
  5736. function offsetSegment(segment, amount) {
  5737. var p0; var p1a; var p1b; var p2b; var p2a; var
  5738. p3;
  5739. var e;
  5740. e = linearOffset(segment.points[0], segment.points[1], amount);
  5741. p0 = e[0];
  5742. p1a = e[1];
  5743. e = linearOffset(segment.points[1], segment.points[2], amount);
  5744. p1b = e[0];
  5745. p2b = e[1];
  5746. e = linearOffset(segment.points[2], segment.points[3], amount);
  5747. p2a = e[0];
  5748. p3 = e[1];
  5749. var p1 = lineIntersection(p0, p1a, p1b, p2b);
  5750. if (p1 === null) p1 = p1a;
  5751. var p2 = lineIntersection(p2a, p3, p1b, p2b);
  5752. if (p2 === null) p2 = p2a;
  5753. return new PolynomialBezier(p0, p1, p2, p3);
  5754. }
  5755. function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
  5756. var p0 = seg1.points[3];
  5757. var p1 = seg2.points[0];
  5758. // Bevel
  5759. if (lineJoin === 3) return p0;
  5760. // Connected, they don't need a joint
  5761. if (pointEqual(p0, p1)) return p0;
  5762. // Round
  5763. if (lineJoin === 2) {
  5764. var angleOut = -seg1.tangentAngle(1);
  5765. var angleIn = -seg2.tangentAngle(0) + Math.PI;
  5766. var center = lineIntersection(
  5767. p0,
  5768. polarOffset(p0, angleOut + Math.PI / 2, 100),
  5769. p1,
  5770. polarOffset(p1, angleOut + Math.PI / 2, 100)
  5771. );
  5772. var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
  5773. var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
  5774. outputBezier.setXYAt(tan[0], tan[1], 'o', outputBezier.length() - 1);
  5775. tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
  5776. outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
  5777. return p1;
  5778. }
  5779. // Miter
  5780. var t0 = pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2];
  5781. var t1 = pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1];
  5782. var intersection = lineIntersection(t0, p0, p1, t1);
  5783. if (intersection && pointDistance(intersection, p0) < miterLimit) {
  5784. outputBezier.setTripleAt(
  5785. intersection[0],
  5786. intersection[1],
  5787. intersection[0],
  5788. intersection[1],
  5789. intersection[0],
  5790. intersection[1],
  5791. outputBezier.length()
  5792. );
  5793. return intersection;
  5794. }
  5795. return p0;
  5796. }
  5797. function getIntersection(a, b) {
  5798. const intersect = a.intersections(b);
  5799. if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
  5800. if (intersect.length) return intersect[0];
  5801. return null;
  5802. }
  5803. function pruneSegmentIntersection(a, b) {
  5804. var outa = a.slice();
  5805. var outb = b.slice();
  5806. var intersect = getIntersection(a[a.length - 1], b[0]);
  5807. if (intersect) {
  5808. outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
  5809. outb[0] = b[0].split(intersect[1])[1];
  5810. }
  5811. if (a.length > 1 && b.length > 1) {
  5812. intersect = getIntersection(a[0], b[b.length - 1]);
  5813. if (intersect) {
  5814. return [
  5815. [a[0].split(intersect[0])[0]],
  5816. [b[b.length - 1].split(intersect[1])[1]],
  5817. ];
  5818. }
  5819. }
  5820. return [outa, outb];
  5821. }
  5822. function pruneIntersections(segments) {
  5823. var e;
  5824. for (var i = 1; i < segments.length; i += 1) {
  5825. e = pruneSegmentIntersection(segments[i - 1], segments[i]);
  5826. segments[i - 1] = e[0];
  5827. segments[i] = e[1];
  5828. }
  5829. if (segments.length > 1) {
  5830. e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
  5831. segments[segments.length - 1] = e[0];
  5832. segments[0] = e[1];
  5833. }
  5834. return segments;
  5835. }
  5836. function offsetSegmentSplit(segment, amount) {
  5837. /*
  5838. We split each bezier segment into smaller pieces based
  5839. on inflection points, this ensures the control point
  5840. polygon is convex.
  5841. (A cubic bezier can have none, one, or two inflection points)
  5842. */
  5843. var flex = segment.inflectionPoints();
  5844. var left;
  5845. var right;
  5846. var split;
  5847. var mid;
  5848. if (flex.length === 0) {
  5849. return [offsetSegment(segment, amount)];
  5850. }
  5851. if (flex.length === 1 || floatEqual(flex[1], 1)) {
  5852. split = segment.split(flex[0]);
  5853. left = split[0];
  5854. right = split[1];
  5855. return [
  5856. offsetSegment(left, amount),
  5857. offsetSegment(right, amount),
  5858. ];
  5859. }
  5860. split = segment.split(flex[0]);
  5861. left = split[0];
  5862. var t = (flex[1] - flex[0]) / (1 - flex[0]);
  5863. split = split[1].split(t);
  5864. mid = split[0];
  5865. right = split[1];
  5866. return [
  5867. offsetSegment(left, amount),
  5868. offsetSegment(mid, amount),
  5869. offsetSegment(right, amount),
  5870. ];
  5871. }
  5872. function OffsetPathModifier() {}
  5873. extendPrototype([ShapeModifier], OffsetPathModifier);
  5874. OffsetPathModifier.prototype.initModifierProperties = function (elem, data) {
  5875. this.getValue = this.processKeys;
  5876. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  5877. this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
  5878. this.lineJoin = data.lj;
  5879. this._isAnimated = this.amount.effectsSequence.length !== 0;
  5880. };
  5881. OffsetPathModifier.prototype.processPath = function (inputBezier, amount, lineJoin, miterLimit) {
  5882. var outputBezier = shapePool.newElement();
  5883. outputBezier.c = inputBezier.c;
  5884. var count = inputBezier.length();
  5885. if (!inputBezier.c) {
  5886. count -= 1;
  5887. }
  5888. var i; var j; var segment;
  5889. var multiSegments = [];
  5890. for (i = 0; i < count; i += 1) {
  5891. segment = PolynomialBezier.shapeSegment(inputBezier, i);
  5892. multiSegments.push(offsetSegmentSplit(segment, amount));
  5893. }
  5894. if (!inputBezier.c) {
  5895. for (i = count - 1; i >= 0; i -= 1) {
  5896. segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
  5897. multiSegments.push(offsetSegmentSplit(segment, amount));
  5898. }
  5899. }
  5900. multiSegments = pruneIntersections(multiSegments);
  5901. // Add bezier segments to the output and apply line joints
  5902. var lastPoint = null;
  5903. var lastSeg = null;
  5904. for (i = 0; i < multiSegments.length; i += 1) {
  5905. var multiSegment = multiSegments[i];
  5906. if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
  5907. lastSeg = multiSegment[multiSegment.length - 1];
  5908. for (j = 0; j < multiSegment.length; j += 1) {
  5909. segment = multiSegment[j];
  5910. if (lastPoint && pointEqual(segment.points[0], lastPoint)) {
  5911. outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], 'o', outputBezier.length() - 1);
  5912. } else {
  5913. outputBezier.setTripleAt(
  5914. segment.points[0][0],
  5915. segment.points[0][1],
  5916. segment.points[1][0],
  5917. segment.points[1][1],
  5918. segment.points[0][0],
  5919. segment.points[0][1],
  5920. outputBezier.length()
  5921. );
  5922. }
  5923. outputBezier.setTripleAt(
  5924. segment.points[3][0],
  5925. segment.points[3][1],
  5926. segment.points[3][0],
  5927. segment.points[3][1],
  5928. segment.points[2][0],
  5929. segment.points[2][1],
  5930. outputBezier.length()
  5931. );
  5932. lastPoint = segment.points[3];
  5933. }
  5934. }
  5935. if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
  5936. return outputBezier;
  5937. };
  5938. OffsetPathModifier.prototype.processShapes = function (_isFirstFrame) {
  5939. var shapePaths;
  5940. var i;
  5941. var len = this.shapes.length;
  5942. var j;
  5943. var jLen;
  5944. var amount = this.amount.v;
  5945. var miterLimit = this.miterLimit.v;
  5946. var lineJoin = this.lineJoin;
  5947. if (amount !== 0) {
  5948. var shapeData;
  5949. var localShapeCollection;
  5950. for (i = 0; i < len; i += 1) {
  5951. shapeData = this.shapes[i];
  5952. localShapeCollection = shapeData.localShapeCollection;
  5953. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5954. localShapeCollection.releaseShapes();
  5955. shapeData.shape._mdf = true;
  5956. shapePaths = shapeData.shape.paths.shapes;
  5957. jLen = shapeData.shape.paths._length;
  5958. for (j = 0; j < jLen; j += 1) {
  5959. localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
  5960. }
  5961. }
  5962. shapeData.shape.paths = shapeData.localShapeCollection;
  5963. }
  5964. }
  5965. if (!this.dynamicProperties.length) {
  5966. this._mdf = false;
  5967. }
  5968. };
  5969. function getFontProperties(fontData) {
  5970. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5971. var fWeight = 'normal'; var
  5972. fStyle = 'normal';
  5973. var len = styles.length;
  5974. var styleName;
  5975. for (var i = 0; i < len; i += 1) {
  5976. styleName = styles[i].toLowerCase();
  5977. switch (styleName) {
  5978. case 'italic':
  5979. fStyle = 'italic';
  5980. break;
  5981. case 'bold':
  5982. fWeight = '700';
  5983. break;
  5984. case 'black':
  5985. fWeight = '900';
  5986. break;
  5987. case 'medium':
  5988. fWeight = '500';
  5989. break;
  5990. case 'regular':
  5991. case 'normal':
  5992. fWeight = '400';
  5993. break;
  5994. case 'light':
  5995. case 'thin':
  5996. fWeight = '200';
  5997. break;
  5998. default:
  5999. break;
  6000. }
  6001. }
  6002. return {
  6003. style: fStyle,
  6004. weight: fontData.fWeight || fWeight,
  6005. };
  6006. }
  6007. const FontManager = (function () {
  6008. var maxWaitingTime = 5000;
  6009. var emptyChar = {
  6010. w: 0,
  6011. size: 0,
  6012. shapes: [],
  6013. data: {
  6014. shapes: [],
  6015. },
  6016. };
  6017. var combinedCharacters = [];
  6018. // Hindi characters
  6019. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366,
  6020. 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379,
  6021. 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  6022. var BLACK_FLAG_CODE_POINT = 127988;
  6023. var CANCEL_TAG_CODE_POINT = 917631;
  6024. var A_TAG_CODE_POINT = 917601;
  6025. var Z_TAG_CODE_POINT = 917626;
  6026. var VARIATION_SELECTOR_16_CODE_POINT = 65039;
  6027. var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
  6028. var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
  6029. var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
  6030. var surrogateModifiers = [
  6031. 'd83cdffb',
  6032. 'd83cdffc',
  6033. 'd83cdffd',
  6034. 'd83cdffe',
  6035. 'd83cdfff',
  6036. ];
  6037. function trimFontOptions(font) {
  6038. var familyArray = font.split(',');
  6039. var i;
  6040. var len = familyArray.length;
  6041. var enabledFamilies = [];
  6042. for (i = 0; i < len; i += 1) {
  6043. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  6044. enabledFamilies.push(familyArray[i]);
  6045. }
  6046. }
  6047. return enabledFamilies.join(',');
  6048. }
  6049. function setUpNode(font, family) {
  6050. var parentNode = createTag('span');
  6051. // Node is invisible to screen readers.
  6052. parentNode.setAttribute('aria-hidden', true);
  6053. parentNode.style.fontFamily = family;
  6054. var node = createTag('span');
  6055. // Characters that vary significantly among different fonts
  6056. node.innerText = 'giItT1WQy@!-/#';
  6057. // Visible - so we can measure it - but not on the screen
  6058. parentNode.style.position = 'absolute';
  6059. parentNode.style.left = '-10000px';
  6060. parentNode.style.top = '-10000px';
  6061. // Large font size makes even subtle changes obvious
  6062. parentNode.style.fontSize = '300px';
  6063. // Reset any font properties
  6064. parentNode.style.fontVariant = 'normal';
  6065. parentNode.style.fontStyle = 'normal';
  6066. parentNode.style.fontWeight = 'normal';
  6067. parentNode.style.letterSpacing = '0';
  6068. parentNode.appendChild(node);
  6069. document.body.appendChild(parentNode);
  6070. // Remember width with no applied web font
  6071. var width = node.offsetWidth;
  6072. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  6073. return { node: node, w: width, parent: parentNode };
  6074. }
  6075. function checkLoadedFonts() {
  6076. var i;
  6077. var len = this.fonts.length;
  6078. var node;
  6079. var w;
  6080. var loadedCount = len;
  6081. for (i = 0; i < len; i += 1) {
  6082. if (this.fonts[i].loaded) {
  6083. loadedCount -= 1;
  6084. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  6085. this.fonts[i].loaded = true;
  6086. } else {
  6087. node = this.fonts[i].monoCase.node;
  6088. w = this.fonts[i].monoCase.w;
  6089. if (node.offsetWidth !== w) {
  6090. loadedCount -= 1;
  6091. this.fonts[i].loaded = true;
  6092. } else {
  6093. node = this.fonts[i].sansCase.node;
  6094. w = this.fonts[i].sansCase.w;
  6095. if (node.offsetWidth !== w) {
  6096. loadedCount -= 1;
  6097. this.fonts[i].loaded = true;
  6098. }
  6099. }
  6100. if (this.fonts[i].loaded) {
  6101. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  6102. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  6103. }
  6104. }
  6105. }
  6106. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  6107. setTimeout(this.checkLoadedFontsBinded, 20);
  6108. } else {
  6109. setTimeout(this.setIsLoadedBinded, 10);
  6110. }
  6111. }
  6112. function createHelper(fontData, def) {
  6113. var engine = (document.body && def) ? 'svg' : 'canvas';
  6114. var helper;
  6115. var fontProps = getFontProperties(fontData);
  6116. if (engine === 'svg') {
  6117. var tHelper = createNS('text');
  6118. tHelper.style.fontSize = '100px';
  6119. // tHelper.style.fontFamily = fontData.fFamily;
  6120. tHelper.setAttribute('font-family', fontData.fFamily);
  6121. tHelper.setAttribute('font-style', fontProps.style);
  6122. tHelper.setAttribute('font-weight', fontProps.weight);
  6123. tHelper.textContent = '1';
  6124. if (fontData.fClass) {
  6125. tHelper.style.fontFamily = 'inherit';
  6126. tHelper.setAttribute('class', fontData.fClass);
  6127. } else {
  6128. tHelper.style.fontFamily = fontData.fFamily;
  6129. }
  6130. def.appendChild(tHelper);
  6131. helper = tHelper;
  6132. } else {
  6133. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  6134. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  6135. helper = tCanvasHelper;
  6136. }
  6137. function measure(text) {
  6138. if (engine === 'svg') {
  6139. helper.textContent = text;
  6140. return helper.getComputedTextLength();
  6141. }
  6142. return helper.measureText(text).width;
  6143. }
  6144. return {
  6145. measureText: measure,
  6146. };
  6147. }
  6148. function addFonts(fontData, defs) {
  6149. if (!fontData) {
  6150. this.isLoaded = true;
  6151. return;
  6152. }
  6153. if (this.chars) {
  6154. this.isLoaded = true;
  6155. this.fonts = fontData.list;
  6156. return;
  6157. }
  6158. if (!document.body) {
  6159. this.isLoaded = true;
  6160. fontData.list.forEach((data) => {
  6161. data.helper = createHelper(data);
  6162. data.cache = {};
  6163. });
  6164. this.fonts = fontData.list;
  6165. return;
  6166. }
  6167. var fontArr = fontData.list;
  6168. var i;
  6169. var len = fontArr.length;
  6170. var _pendingFonts = len;
  6171. for (i = 0; i < len; i += 1) {
  6172. var shouldLoadFont = true;
  6173. var loadedSelector;
  6174. var j;
  6175. fontArr[i].loaded = false;
  6176. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  6177. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  6178. if (!fontArr[i].fPath) {
  6179. fontArr[i].loaded = true;
  6180. _pendingFonts -= 1;
  6181. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  6182. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  6183. if (loadedSelector.length > 0) {
  6184. shouldLoadFont = false;
  6185. }
  6186. if (shouldLoadFont) {
  6187. var s = createTag('style');
  6188. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  6189. s.setAttribute('f-origin', fontArr[i].origin);
  6190. s.setAttribute('f-family', fontArr[i].fFamily);
  6191. s.type = 'text/css';
  6192. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  6193. defs.appendChild(s);
  6194. }
  6195. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  6196. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  6197. for (j = 0; j < loadedSelector.length; j += 1) {
  6198. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  6199. // Font is already loaded
  6200. shouldLoadFont = false;
  6201. }
  6202. }
  6203. if (shouldLoadFont) {
  6204. var l = createTag('link');
  6205. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  6206. l.setAttribute('f-origin', fontArr[i].origin);
  6207. l.type = 'text/css';
  6208. l.rel = 'stylesheet';
  6209. l.href = fontArr[i].fPath;
  6210. document.body.appendChild(l);
  6211. }
  6212. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  6213. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  6214. for (j = 0; j < loadedSelector.length; j += 1) {
  6215. if (fontArr[i].fPath === loadedSelector[j].src) {
  6216. // Font is already loaded
  6217. shouldLoadFont = false;
  6218. }
  6219. }
  6220. if (shouldLoadFont) {
  6221. var sc = createTag('link');
  6222. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  6223. sc.setAttribute('f-origin', fontArr[i].origin);
  6224. sc.setAttribute('rel', 'stylesheet');
  6225. sc.setAttribute('href', fontArr[i].fPath);
  6226. defs.appendChild(sc);
  6227. }
  6228. }
  6229. fontArr[i].helper = createHelper(fontArr[i], defs);
  6230. fontArr[i].cache = {};
  6231. this.fonts.push(fontArr[i]);
  6232. }
  6233. if (_pendingFonts === 0) {
  6234. this.isLoaded = true;
  6235. } else {
  6236. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  6237. // Adding this timeout seems to fix it
  6238. setTimeout(this.checkLoadedFonts.bind(this), 100);
  6239. }
  6240. }
  6241. function addChars(chars) {
  6242. if (!chars) {
  6243. return;
  6244. }
  6245. if (!this.chars) {
  6246. this.chars = [];
  6247. }
  6248. var i;
  6249. var len = chars.length;
  6250. var j;
  6251. var jLen = this.chars.length;
  6252. var found;
  6253. for (i = 0; i < len; i += 1) {
  6254. j = 0;
  6255. found = false;
  6256. while (j < jLen) {
  6257. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  6258. found = true;
  6259. }
  6260. j += 1;
  6261. }
  6262. if (!found) {
  6263. this.chars.push(chars[i]);
  6264. jLen += 1;
  6265. }
  6266. }
  6267. }
  6268. function getCharData(char, style, font) {
  6269. var i = 0;
  6270. var len = this.chars.length;
  6271. while (i < len) {
  6272. if (this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  6273. return this.chars[i];
  6274. }
  6275. i += 1;
  6276. }
  6277. if (((typeof char === 'string' && char.charCodeAt(0) !== 13) || !char)
  6278. && console
  6279. && console.warn // eslint-disable-line no-console
  6280. && !this._warned
  6281. ) {
  6282. this._warned = true;
  6283. console.warn('Missing character from exported characters list: ', char, style, font); // eslint-disable-line no-console
  6284. }
  6285. return emptyChar;
  6286. }
  6287. function measureText(char, fontName, size) {
  6288. var fontData = this.getFontByName(fontName);
  6289. // Using the char instead of char.charCodeAt(0)
  6290. // to avoid collisions between equal chars
  6291. var index = char;
  6292. if (!fontData.cache[index]) {
  6293. var tHelper = fontData.helper;
  6294. if (char === ' ') {
  6295. var doubleSize = tHelper.measureText('|' + char + '|');
  6296. var singleSize = tHelper.measureText('||');
  6297. fontData.cache[index] = (doubleSize - singleSize) / 100;
  6298. } else {
  6299. fontData.cache[index] = tHelper.measureText(char) / 100;
  6300. }
  6301. }
  6302. return fontData.cache[index] * size;
  6303. }
  6304. function getFontByName(name) {
  6305. var i = 0;
  6306. var len = this.fonts.length;
  6307. while (i < len) {
  6308. if (this.fonts[i].fName === name) {
  6309. return this.fonts[i];
  6310. }
  6311. i += 1;
  6312. }
  6313. return this.fonts[0];
  6314. }
  6315. function getCodePoint(string) {
  6316. var codePoint = 0;
  6317. var first = string.charCodeAt(0);
  6318. if (first >= 0xD800 && first <= 0xDBFF) {
  6319. var second = string.charCodeAt(1);
  6320. if (second >= 0xDC00 && second <= 0xDFFF) {
  6321. codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  6322. }
  6323. }
  6324. return codePoint;
  6325. }
  6326. // Skin tone modifiers
  6327. function isModifier(firstCharCode, secondCharCode) {
  6328. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  6329. return surrogateModifiers.indexOf(sum) !== -1;
  6330. }
  6331. function isZeroWidthJoiner(charCode) {
  6332. return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
  6333. }
  6334. // This codepoint may change the appearance of the preceding character.
  6335. // If that is a symbol, dingbat or emoji, U+FE0F forces it to be rendered
  6336. // as a colorful image as compared to a monochrome text variant.
  6337. function isVariationSelector(charCode) {
  6338. return charCode === VARIATION_SELECTOR_16_CODE_POINT;
  6339. }
  6340. // The regional indicator symbols are a set of 26 alphabetic Unicode
  6341. /// characters (A–Z) intended to be used to encode ISO 3166-1 alpha-2
  6342. // two-letter country codes in a way that allows optional special treatment.
  6343. function isRegionalCode(string) {
  6344. var codePoint = getCodePoint(string);
  6345. if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) {
  6346. return true;
  6347. }
  6348. return false;
  6349. }
  6350. // Some Emoji implementations represent combinations of
  6351. // two “regional indicator” letters as a single flag symbol.
  6352. function isFlagEmoji(string) {
  6353. return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
  6354. }
  6355. function isCombinedCharacter(char) {
  6356. return combinedCharacters.indexOf(char) !== -1;
  6357. }
  6358. // Regional flags start with a BLACK_FLAG_CODE_POINT
  6359. // folowed by 5 chars in the TAG range
  6360. // and end with a CANCEL_TAG_CODE_POINT
  6361. function isRegionalFlag(text, index) {
  6362. var codePoint = getCodePoint(text.substr(index, 2));
  6363. if (codePoint !== BLACK_FLAG_CODE_POINT) {
  6364. return false;
  6365. }
  6366. var count = 0;
  6367. index += 2;
  6368. while (count < 5) {
  6369. codePoint = getCodePoint(text.substr(index, 2));
  6370. if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) {
  6371. return false;
  6372. }
  6373. count += 1;
  6374. index += 2;
  6375. }
  6376. return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
  6377. }
  6378. function setIsLoaded() {
  6379. this.isLoaded = true;
  6380. }
  6381. var Font = function () {
  6382. this.fonts = [];
  6383. this.chars = null;
  6384. this.typekitLoaded = 0;
  6385. this.isLoaded = false;
  6386. this._warned = false;
  6387. this.initTime = Date.now();
  6388. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  6389. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  6390. };
  6391. Font.isModifier = isModifier;
  6392. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  6393. Font.isFlagEmoji = isFlagEmoji;
  6394. Font.isRegionalCode = isRegionalCode;
  6395. Font.isCombinedCharacter = isCombinedCharacter;
  6396. Font.isRegionalFlag = isRegionalFlag;
  6397. Font.isVariationSelector = isVariationSelector;
  6398. Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
  6399. var fontPrototype = {
  6400. addChars: addChars,
  6401. addFonts: addFonts,
  6402. getCharData: getCharData,
  6403. getFontByName: getFontByName,
  6404. measureText: measureText,
  6405. checkLoadedFonts: checkLoadedFonts,
  6406. setIsLoaded: setIsLoaded,
  6407. };
  6408. Font.prototype = fontPrototype;
  6409. return Font;
  6410. }());
  6411. function SlotManager(animationData) {
  6412. this.animationData = animationData;
  6413. }
  6414. SlotManager.prototype.getProp = function (data) {
  6415. if (this.animationData.slots
  6416. && this.animationData.slots[data.sid]
  6417. ) {
  6418. return Object.assign(data, this.animationData.slots[data.sid].p);
  6419. }
  6420. return data;
  6421. };
  6422. function slotFactory(animationData) {
  6423. return new SlotManager(animationData);
  6424. }
  6425. function RenderableElement() {
  6426. }
  6427. RenderableElement.prototype = {
  6428. initRenderable: function () {
  6429. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6430. this.isInRange = false;
  6431. // layer's display state
  6432. this.hidden = false;
  6433. // If layer's transparency equals 0, it can be hidden
  6434. this.isTransparent = false;
  6435. // list of animated components
  6436. this.renderableComponents = [];
  6437. },
  6438. addRenderableComponent: function (component) {
  6439. if (this.renderableComponents.indexOf(component) === -1) {
  6440. this.renderableComponents.push(component);
  6441. }
  6442. },
  6443. removeRenderableComponent: function (component) {
  6444. if (this.renderableComponents.indexOf(component) !== -1) {
  6445. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6446. }
  6447. },
  6448. prepareRenderableFrame: function (num) {
  6449. this.checkLayerLimits(num);
  6450. },
  6451. checkTransparency: function () {
  6452. if (this.finalTransform.mProp.o.v <= 0) {
  6453. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  6454. this.isTransparent = true;
  6455. this.hide();
  6456. }
  6457. } else if (this.isTransparent) {
  6458. this.isTransparent = false;
  6459. this.show();
  6460. }
  6461. },
  6462. /**
  6463. * @function
  6464. * Initializes frame related properties.
  6465. *
  6466. * @param {number} num
  6467. * current frame number in Layer's time
  6468. *
  6469. */
  6470. checkLayerLimits: function (num) {
  6471. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  6472. if (this.isInRange !== true) {
  6473. this.globalData._mdf = true;
  6474. this._mdf = true;
  6475. this.isInRange = true;
  6476. this.show();
  6477. }
  6478. } else if (this.isInRange !== false) {
  6479. this.globalData._mdf = true;
  6480. this.isInRange = false;
  6481. this.hide();
  6482. }
  6483. },
  6484. renderRenderable: function () {
  6485. var i;
  6486. var len = this.renderableComponents.length;
  6487. for (i = 0; i < len; i += 1) {
  6488. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6489. }
  6490. /* this.maskManager.renderFrame(this.finalTransform.mat);
  6491. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  6492. },
  6493. sourceRectAtTime: function () {
  6494. return {
  6495. top: 0,
  6496. left: 0,
  6497. width: 100,
  6498. height: 100,
  6499. };
  6500. },
  6501. getLayerSize: function () {
  6502. if (this.data.ty === 5) {
  6503. return { w: this.data.textData.width, h: this.data.textData.height };
  6504. }
  6505. return { w: this.data.width, h: this.data.height };
  6506. },
  6507. };
  6508. const getBlendMode = (function () {
  6509. var blendModeEnums = {
  6510. 0: 'source-over',
  6511. 1: 'multiply',
  6512. 2: 'screen',
  6513. 3: 'overlay',
  6514. 4: 'darken',
  6515. 5: 'lighten',
  6516. 6: 'color-dodge',
  6517. 7: 'color-burn',
  6518. 8: 'hard-light',
  6519. 9: 'soft-light',
  6520. 10: 'difference',
  6521. 11: 'exclusion',
  6522. 12: 'hue',
  6523. 13: 'saturation',
  6524. 14: 'color',
  6525. 15: 'luminosity',
  6526. };
  6527. return function (mode) {
  6528. return blendModeEnums[mode] || '';
  6529. };
  6530. }());
  6531. function SliderEffect(data, elem, container) {
  6532. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6533. }
  6534. function AngleEffect(data, elem, container) {
  6535. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6536. }
  6537. function ColorEffect(data, elem, container) {
  6538. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6539. }
  6540. function PointEffect(data, elem, container) {
  6541. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6542. }
  6543. function LayerIndexEffect(data, elem, container) {
  6544. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6545. }
  6546. function MaskIndexEffect(data, elem, container) {
  6547. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6548. }
  6549. function CheckboxEffect(data, elem, container) {
  6550. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6551. }
  6552. function NoValueEffect() {
  6553. this.p = {};
  6554. }
  6555. function EffectsManager(data, element) {
  6556. var effects = data.ef || [];
  6557. this.effectElements = [];
  6558. var i;
  6559. var len = effects.length;
  6560. var effectItem;
  6561. for (i = 0; i < len; i += 1) {
  6562. effectItem = new GroupEffect(effects[i], element);
  6563. this.effectElements.push(effectItem);
  6564. }
  6565. }
  6566. function GroupEffect(data, element) {
  6567. this.init(data, element);
  6568. }
  6569. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6570. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6571. GroupEffect.prototype.init = function (data, element) {
  6572. this.data = data;
  6573. this.effectElements = [];
  6574. this.initDynamicPropertyContainer(element);
  6575. var i;
  6576. var len = this.data.ef.length;
  6577. var eff;
  6578. var effects = this.data.ef;
  6579. for (i = 0; i < len; i += 1) {
  6580. eff = null;
  6581. switch (effects[i].ty) {
  6582. case 0:
  6583. eff = new SliderEffect(effects[i], element, this);
  6584. break;
  6585. case 1:
  6586. eff = new AngleEffect(effects[i], element, this);
  6587. break;
  6588. case 2:
  6589. eff = new ColorEffect(effects[i], element, this);
  6590. break;
  6591. case 3:
  6592. eff = new PointEffect(effects[i], element, this);
  6593. break;
  6594. case 4:
  6595. case 7:
  6596. eff = new CheckboxEffect(effects[i], element, this);
  6597. break;
  6598. case 10:
  6599. eff = new LayerIndexEffect(effects[i], element, this);
  6600. break;
  6601. case 11:
  6602. eff = new MaskIndexEffect(effects[i], element, this);
  6603. break;
  6604. case 5:
  6605. eff = new EffectsManager(effects[i], element, this);
  6606. break;
  6607. // case 6:
  6608. default:
  6609. eff = new NoValueEffect(effects[i], element, this);
  6610. break;
  6611. }
  6612. if (eff) {
  6613. this.effectElements.push(eff);
  6614. }
  6615. }
  6616. };
  6617. function BaseElement() {
  6618. }
  6619. BaseElement.prototype = {
  6620. checkMasks: function () {
  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 () {
  6635. const expressionsInterfaces = getExpressionInterfaces();
  6636. if (!expressionsInterfaces) {
  6637. return;
  6638. }
  6639. const LayerExpressionInterface = expressionsInterfaces('layer');
  6640. const EffectsExpressionInterface = expressionsInterfaces('effects');
  6641. const ShapeExpressionInterface = expressionsInterfaces('shape');
  6642. const TextExpressionInterface = expressionsInterfaces('text');
  6643. const 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 () {
  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 (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 () {
  6678. return this.type;
  6679. },
  6680. sourceRectAtTime: function () {},
  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 () {
  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 (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 (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. };
  6741. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  6742. FootageElement.prototype.getBaseElement = function () {
  6743. return null;
  6744. };
  6745. FootageElement.prototype.renderFrame = function () {
  6746. };
  6747. FootageElement.prototype.destroy = function () {
  6748. };
  6749. FootageElement.prototype.initExpressions = function () {
  6750. const expressionsInterfaces = getExpressionInterfaces();
  6751. if (!expressionsInterfaces) {
  6752. return;
  6753. }
  6754. const FootageInterface = expressionsInterfaces('footage');
  6755. this.layerInterface = FootageInterface(this);
  6756. };
  6757. FootageElement.prototype.getFootageData = function () {
  6758. return this.footageData;
  6759. };
  6760. function AudioElement(data, globalData, comp) {
  6761. this.initFrame();
  6762. this.initRenderable();
  6763. this.assetData = globalData.getAssetData(data.refId);
  6764. this.initBaseData(data, globalData, comp);
  6765. this._isPlaying = false;
  6766. this._canPlay = false;
  6767. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6768. this.audio = this.globalData.audioController.createAudio(assetPath);
  6769. this._currentTime = 0;
  6770. this.globalData.audioController.addAudio(this);
  6771. this._volumeMultiplier = 1;
  6772. this._volume = 1;
  6773. this._previousVolume = null;
  6774. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  6775. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : { k: [100] }, 1, 0.01, this);
  6776. }
  6777. AudioElement.prototype.prepareFrame = function (num) {
  6778. this.prepareRenderableFrame(num, true);
  6779. this.prepareProperties(num, true);
  6780. if (!this.tm._placeholder) {
  6781. var timeRemapped = this.tm.v;
  6782. this._currentTime = timeRemapped;
  6783. } else {
  6784. this._currentTime = num / this.data.sr;
  6785. }
  6786. this._volume = this.lv.v[0];
  6787. var totalVolume = this._volume * this._volumeMultiplier;
  6788. if (this._previousVolume !== totalVolume) {
  6789. this._previousVolume = totalVolume;
  6790. this.audio.volume(totalVolume);
  6791. }
  6792. };
  6793. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  6794. AudioElement.prototype.renderFrame = function () {
  6795. if (this.isInRange && this._canPlay) {
  6796. if (!this._isPlaying) {
  6797. this.audio.play();
  6798. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6799. this._isPlaying = true;
  6800. } else if (!this.audio.playing()
  6801. || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1
  6802. ) {
  6803. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6804. }
  6805. }
  6806. };
  6807. AudioElement.prototype.show = function () {
  6808. // this.audio.play()
  6809. };
  6810. AudioElement.prototype.hide = function () {
  6811. this.audio.pause();
  6812. this._isPlaying = false;
  6813. };
  6814. AudioElement.prototype.pause = function () {
  6815. this.audio.pause();
  6816. this._isPlaying = false;
  6817. this._canPlay = false;
  6818. };
  6819. AudioElement.prototype.resume = function () {
  6820. this._canPlay = true;
  6821. };
  6822. AudioElement.prototype.setRate = function (rateValue) {
  6823. this.audio.rate(rateValue);
  6824. };
  6825. AudioElement.prototype.volume = function (volumeValue) {
  6826. this._volumeMultiplier = volumeValue;
  6827. this._previousVolume = volumeValue * this._volume;
  6828. this.audio.volume(this._previousVolume);
  6829. };
  6830. AudioElement.prototype.getBaseElement = function () {
  6831. return null;
  6832. };
  6833. AudioElement.prototype.destroy = function () {
  6834. };
  6835. AudioElement.prototype.sourceRectAtTime = function () {
  6836. };
  6837. AudioElement.prototype.initExpressions = function () {
  6838. };
  6839. function BaseRenderer() {}
  6840. BaseRenderer.prototype.checkLayers = function (num) {
  6841. var i;
  6842. var len = this.layers.length;
  6843. var data;
  6844. this.completeLayers = true;
  6845. for (i = len - 1; i >= 0; i -= 1) {
  6846. if (!this.elements[i]) {
  6847. data = this.layers[i];
  6848. if (data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st)) {
  6849. this.buildItem(i);
  6850. }
  6851. }
  6852. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  6853. }
  6854. this.checkPendingElements();
  6855. };
  6856. BaseRenderer.prototype.createItem = function (layer) {
  6857. switch (layer.ty) {
  6858. case 2:
  6859. return this.createImage(layer);
  6860. case 0:
  6861. return this.createComp(layer);
  6862. case 1:
  6863. return this.createSolid(layer);
  6864. case 3:
  6865. return this.createNull(layer);
  6866. case 4:
  6867. return this.createShape(layer);
  6868. case 5:
  6869. return this.createText(layer);
  6870. case 6:
  6871. return this.createAudio(layer);
  6872. case 13:
  6873. return this.createCamera(layer);
  6874. case 15:
  6875. return this.createFootage(layer);
  6876. default:
  6877. return this.createNull(layer);
  6878. }
  6879. };
  6880. BaseRenderer.prototype.createCamera = function () {
  6881. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  6882. };
  6883. BaseRenderer.prototype.createAudio = function (data) {
  6884. return new AudioElement(data, this.globalData, this);
  6885. };
  6886. BaseRenderer.prototype.createFootage = function (data) {
  6887. return new FootageElement(data, this.globalData, this);
  6888. };
  6889. BaseRenderer.prototype.buildAllItems = function () {
  6890. var i;
  6891. var len = this.layers.length;
  6892. for (i = 0; i < len; i += 1) {
  6893. this.buildItem(i);
  6894. }
  6895. this.checkPendingElements();
  6896. };
  6897. BaseRenderer.prototype.includeLayers = function (newLayers) {
  6898. this.completeLayers = false;
  6899. var i;
  6900. var len = newLayers.length;
  6901. var j;
  6902. var jLen = this.layers.length;
  6903. for (i = 0; i < len; i += 1) {
  6904. j = 0;
  6905. while (j < jLen) {
  6906. if (this.layers[j].id === newLayers[i].id) {
  6907. this.layers[j] = newLayers[i];
  6908. break;
  6909. }
  6910. j += 1;
  6911. }
  6912. }
  6913. };
  6914. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  6915. this.globalData.projectInterface = pInterface;
  6916. };
  6917. BaseRenderer.prototype.initItems = function () {
  6918. if (!this.globalData.progressiveLoad) {
  6919. this.buildAllItems();
  6920. }
  6921. };
  6922. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  6923. var elements = this.elements;
  6924. var layers = this.layers;
  6925. var i = 0;
  6926. var len = layers.length;
  6927. while (i < len) {
  6928. if (layers[i].ind == parentName) { // eslint-disable-line eqeqeq
  6929. if (!elements[i] || elements[i] === true) {
  6930. this.buildItem(i);
  6931. this.addPendingElement(element);
  6932. } else {
  6933. hierarchy.push(elements[i]);
  6934. elements[i].setAsParent();
  6935. if (layers[i].parent !== undefined) {
  6936. this.buildElementParenting(element, layers[i].parent, hierarchy);
  6937. } else {
  6938. element.setHierarchy(hierarchy);
  6939. }
  6940. }
  6941. }
  6942. i += 1;
  6943. }
  6944. };
  6945. BaseRenderer.prototype.addPendingElement = function (element) {
  6946. this.pendingElements.push(element);
  6947. };
  6948. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  6949. var i;
  6950. var len = assets.length;
  6951. for (i = 0; i < len; i += 1) {
  6952. if (assets[i].xt) {
  6953. var comp = this.createComp(assets[i]);
  6954. comp.initExpressions();
  6955. this.globalData.projectInterface.registerComposition(comp);
  6956. }
  6957. }
  6958. };
  6959. BaseRenderer.prototype.getElementById = function (ind) {
  6960. var i;
  6961. var len = this.elements.length;
  6962. for (i = 0; i < len; i += 1) {
  6963. if (this.elements[i].data.ind === ind) {
  6964. return this.elements[i];
  6965. }
  6966. }
  6967. return null;
  6968. };
  6969. BaseRenderer.prototype.getElementByPath = function (path) {
  6970. var pathValue = path.shift();
  6971. var element;
  6972. if (typeof pathValue === 'number') {
  6973. element = this.elements[pathValue];
  6974. } else {
  6975. var i;
  6976. var len = this.elements.length;
  6977. for (i = 0; i < len; i += 1) {
  6978. if (this.elements[i].data.nm === pathValue) {
  6979. element = this.elements[i];
  6980. break;
  6981. }
  6982. }
  6983. }
  6984. if (path.length === 0) {
  6985. return element;
  6986. }
  6987. return element.getElementByPath(path);
  6988. };
  6989. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  6990. this.globalData.fontManager = new FontManager();
  6991. this.globalData.slotManager = slotFactory(animData);
  6992. this.globalData.fontManager.addChars(animData.chars);
  6993. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  6994. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  6995. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  6996. this.globalData.imageLoader = this.animationItem.imagePreloader;
  6997. this.globalData.audioController = this.animationItem.audioController;
  6998. this.globalData.frameId = 0;
  6999. this.globalData.frameRate = animData.fr;
  7000. this.globalData.nm = animData.nm;
  7001. this.globalData.compSize = {
  7002. w: animData.w,
  7003. h: animData.h,
  7004. };
  7005. };
  7006. var effectTypes = {
  7007. TRANSFORM_EFFECT: 'transformEFfect',
  7008. };
  7009. function TransformElement() {}
  7010. TransformElement.prototype = {
  7011. initTransform: function () {
  7012. var mat = new Matrix();
  7013. this.finalTransform = {
  7014. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : { o: 0 },
  7015. _matMdf: false,
  7016. _localMatMdf: false,
  7017. _opMdf: false,
  7018. mat: mat,
  7019. localMat: mat,
  7020. localOpacity: 1,
  7021. };
  7022. if (this.data.ao) {
  7023. this.finalTransform.mProp.autoOriented = true;
  7024. }
  7025. // TODO: check TYPE 11: Guided elements
  7026. if (this.data.ty !== 11) {
  7027. // this.createElements();
  7028. }
  7029. },
  7030. renderTransform: function () {
  7031. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  7032. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  7033. if (this.hierarchy) {
  7034. var mat;
  7035. var finalMat = this.finalTransform.mat;
  7036. var i = 0;
  7037. var len = this.hierarchy.length;
  7038. // Checking if any of the transformation matrices in the hierarchy chain has changed.
  7039. if (!this.finalTransform._matMdf) {
  7040. while (i < len) {
  7041. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  7042. this.finalTransform._matMdf = true;
  7043. break;
  7044. }
  7045. i += 1;
  7046. }
  7047. }
  7048. if (this.finalTransform._matMdf) {
  7049. mat = this.finalTransform.mProp.v.props;
  7050. finalMat.cloneFromProps(mat);
  7051. for (i = 0; i < len; i += 1) {
  7052. finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
  7053. }
  7054. }
  7055. }
  7056. if (!this.localTransforms || this.finalTransform._matMdf) {
  7057. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7058. }
  7059. if (this.finalTransform._opMdf) {
  7060. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7061. }
  7062. },
  7063. renderLocalTransform: function () {
  7064. if (this.localTransforms) {
  7065. var i = 0;
  7066. var len = this.localTransforms.length;
  7067. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7068. if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) {
  7069. while (i < len) {
  7070. if (this.localTransforms[i]._mdf) {
  7071. this.finalTransform._localMatMdf = true;
  7072. }
  7073. if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
  7074. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7075. this.finalTransform._opMdf = true;
  7076. }
  7077. i += 1;
  7078. }
  7079. }
  7080. if (this.finalTransform._localMatMdf) {
  7081. var localMat = this.finalTransform.localMat;
  7082. this.localTransforms[0].matrix.clone(localMat);
  7083. for (i = 1; i < len; i += 1) {
  7084. var lmat = this.localTransforms[i].matrix;
  7085. localMat.multiply(lmat);
  7086. }
  7087. localMat.multiply(this.finalTransform.mat);
  7088. }
  7089. if (this.finalTransform._opMdf) {
  7090. var localOp = this.finalTransform.localOpacity;
  7091. for (i = 0; i < len; i += 1) {
  7092. localOp *= this.localTransforms[i].opacity * 0.01;
  7093. }
  7094. this.finalTransform.localOpacity = localOp;
  7095. }
  7096. }
  7097. },
  7098. searchEffectTransforms: function () {
  7099. if (this.renderableEffectsManager) {
  7100. var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  7101. if (transformEffects.length) {
  7102. this.localTransforms = [];
  7103. this.finalTransform.localMat = new Matrix();
  7104. var i = 0;
  7105. var len = transformEffects.length;
  7106. for (i = 0; i < len; i += 1) {
  7107. this.localTransforms.push(transformEffects[i]);
  7108. }
  7109. }
  7110. }
  7111. },
  7112. globalToLocal: function (pt) {
  7113. var transforms = [];
  7114. transforms.push(this.finalTransform);
  7115. var flag = true;
  7116. var comp = this.comp;
  7117. while (flag) {
  7118. if (comp.finalTransform) {
  7119. if (comp.data.hasMask) {
  7120. transforms.splice(0, 0, comp.finalTransform);
  7121. }
  7122. comp = comp.comp;
  7123. } else {
  7124. flag = false;
  7125. }
  7126. }
  7127. var i;
  7128. var len = transforms.length;
  7129. var ptNew;
  7130. for (i = 0; i < len; i += 1) {
  7131. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  7132. // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7133. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7134. }
  7135. return pt;
  7136. },
  7137. mHelper: new Matrix(),
  7138. };
  7139. function MaskElement(data, element, globalData) {
  7140. this.data = data;
  7141. this.element = element;
  7142. this.globalData = globalData;
  7143. this.storedData = [];
  7144. this.masksProperties = this.data.masksProperties || [];
  7145. this.maskElement = null;
  7146. var defs = this.globalData.defs;
  7147. var i;
  7148. var len = this.masksProperties ? this.masksProperties.length : 0;
  7149. this.viewData = createSizedArray(len);
  7150. this.solidPath = '';
  7151. var path;
  7152. var properties = this.masksProperties;
  7153. var count = 0;
  7154. var currentMasks = [];
  7155. var j;
  7156. var jLen;
  7157. var layerId = createElementID();
  7158. var rect;
  7159. var expansor;
  7160. var feMorph;
  7161. var x;
  7162. var maskType = 'clipPath';
  7163. var maskRef = 'clip-path';
  7164. for (i = 0; i < len; i += 1) {
  7165. if ((properties[i].mode !== 'a' && properties[i].mode !== 'n') || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7166. maskType = 'mask';
  7167. maskRef = 'mask';
  7168. }
  7169. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7170. rect = createNS('rect');
  7171. rect.setAttribute('fill', '#ffffff');
  7172. rect.setAttribute('width', this.element.comp.data.w || 0);
  7173. rect.setAttribute('height', this.element.comp.data.h || 0);
  7174. currentMasks.push(rect);
  7175. } else {
  7176. rect = null;
  7177. }
  7178. path = createNS('path');
  7179. if (properties[i].mode === 'n') {
  7180. // TODO move this to a factory or to a constructor
  7181. this.viewData[i] = {
  7182. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7183. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7184. elem: path,
  7185. lastPath: '',
  7186. };
  7187. defs.appendChild(path);
  7188. } else {
  7189. count += 1;
  7190. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7191. path.setAttribute('clip-rule', 'nonzero');
  7192. var filterID;
  7193. if (properties[i].x.k !== 0) {
  7194. maskType = 'mask';
  7195. maskRef = 'mask';
  7196. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7197. filterID = createElementID();
  7198. expansor = createNS('filter');
  7199. expansor.setAttribute('id', filterID);
  7200. feMorph = createNS('feMorphology');
  7201. feMorph.setAttribute('operator', 'erode');
  7202. feMorph.setAttribute('in', 'SourceGraphic');
  7203. feMorph.setAttribute('radius', '0');
  7204. expansor.appendChild(feMorph);
  7205. defs.appendChild(expansor);
  7206. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7207. } else {
  7208. feMorph = null;
  7209. x = null;
  7210. }
  7211. // TODO move this to a factory or to a constructor
  7212. this.storedData[i] = {
  7213. elem: path,
  7214. x: x,
  7215. expan: feMorph,
  7216. lastPath: '',
  7217. lastOperator: '',
  7218. filterId: filterID,
  7219. lastRadius: 0,
  7220. };
  7221. if (properties[i].mode === 'i') {
  7222. jLen = currentMasks.length;
  7223. var g = createNS('g');
  7224. for (j = 0; j < jLen; j += 1) {
  7225. g.appendChild(currentMasks[j]);
  7226. }
  7227. var mask = createNS('mask');
  7228. mask.setAttribute('mask-type', 'alpha');
  7229. mask.setAttribute('id', layerId + '_' + count);
  7230. mask.appendChild(path);
  7231. defs.appendChild(mask);
  7232. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7233. currentMasks.length = 0;
  7234. currentMasks.push(g);
  7235. } else {
  7236. currentMasks.push(path);
  7237. }
  7238. if (properties[i].inv && !this.solidPath) {
  7239. this.solidPath = this.createLayerSolidPath();
  7240. }
  7241. // TODO move this to a factory or to a constructor
  7242. this.viewData[i] = {
  7243. elem: path,
  7244. lastPath: '',
  7245. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7246. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7247. invRect: rect,
  7248. };
  7249. if (!this.viewData[i].prop.k) {
  7250. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7251. }
  7252. }
  7253. }
  7254. this.maskElement = createNS(maskType);
  7255. len = currentMasks.length;
  7256. for (i = 0; i < len; i += 1) {
  7257. this.maskElement.appendChild(currentMasks[i]);
  7258. }
  7259. if (count > 0) {
  7260. this.maskElement.setAttribute('id', layerId);
  7261. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7262. defs.appendChild(this.maskElement);
  7263. }
  7264. if (this.viewData.length) {
  7265. this.element.addRenderableComponent(this);
  7266. }
  7267. }
  7268. MaskElement.prototype.getMaskProperty = function (pos) {
  7269. return this.viewData[pos].prop;
  7270. };
  7271. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7272. var finalMat = this.element.finalTransform.mat;
  7273. var i;
  7274. var len = this.masksProperties.length;
  7275. for (i = 0; i < len; i += 1) {
  7276. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7277. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7278. }
  7279. if (this.viewData[i].op._mdf || isFirstFrame) {
  7280. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7281. }
  7282. if (this.masksProperties[i].mode !== 'n') {
  7283. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7284. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7285. }
  7286. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7287. var feMorph = this.storedData[i].expan;
  7288. if (this.storedData[i].x.v < 0) {
  7289. if (this.storedData[i].lastOperator !== 'erode') {
  7290. this.storedData[i].lastOperator = 'erode';
  7291. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7292. }
  7293. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7294. } else {
  7295. if (this.storedData[i].lastOperator !== 'dilate') {
  7296. this.storedData[i].lastOperator = 'dilate';
  7297. this.storedData[i].elem.setAttribute('filter', null);
  7298. }
  7299. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7300. }
  7301. }
  7302. }
  7303. }
  7304. };
  7305. MaskElement.prototype.getMaskelement = function () {
  7306. return this.maskElement;
  7307. };
  7308. MaskElement.prototype.createLayerSolidPath = function () {
  7309. var path = 'M0,0 ';
  7310. path += ' h' + this.globalData.compSize.w;
  7311. path += ' v' + this.globalData.compSize.h;
  7312. path += ' h-' + this.globalData.compSize.w;
  7313. path += ' v-' + this.globalData.compSize.h + ' ';
  7314. return path;
  7315. };
  7316. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7317. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7318. var i;
  7319. var len;
  7320. len = pathNodes._length;
  7321. for (i = 1; i < len; 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. 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];
  7324. }
  7325. // 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];
  7326. if (pathNodes.c && len > 1) {
  7327. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[0][0] + ',' + pathNodes.i[0][1] + ' ' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7328. }
  7329. // pathNodes.__renderedString = pathString;
  7330. if (viewData.lastPath !== pathString) {
  7331. var pathShapeValue = '';
  7332. if (viewData.elem) {
  7333. if (pathNodes.c) {
  7334. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7335. }
  7336. viewData.elem.setAttribute('d', pathShapeValue);
  7337. }
  7338. viewData.lastPath = pathString;
  7339. }
  7340. };
  7341. MaskElement.prototype.destroy = function () {
  7342. this.element = null;
  7343. this.globalData = null;
  7344. this.maskElement = null;
  7345. this.data = null;
  7346. this.masksProperties = null;
  7347. };
  7348. const filtersFactory = (function () {
  7349. var ob = {};
  7350. ob.createFilter = createFilter;
  7351. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7352. function createFilter(filId, skipCoordinates) {
  7353. var fil = createNS('filter');
  7354. fil.setAttribute('id', filId);
  7355. if (skipCoordinates !== true) {
  7356. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7357. fil.setAttribute('x', '0%');
  7358. fil.setAttribute('y', '0%');
  7359. fil.setAttribute('width', '100%');
  7360. fil.setAttribute('height', '100%');
  7361. }
  7362. return fil;
  7363. }
  7364. function createAlphaToLuminanceFilter() {
  7365. var feColorMatrix = createNS('feColorMatrix');
  7366. feColorMatrix.setAttribute('type', 'matrix');
  7367. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7368. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7369. return feColorMatrix;
  7370. }
  7371. return ob;
  7372. }());
  7373. const featureSupport = (function () {
  7374. var ob = {
  7375. maskType: true,
  7376. svgLumaHidden: true,
  7377. offscreenCanvas: typeof OffscreenCanvas !== 'undefined',
  7378. };
  7379. 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)) {
  7380. ob.maskType = false;
  7381. }
  7382. if (/firefox/i.test(navigator.userAgent)) {
  7383. ob.svgLumaHidden = false;
  7384. }
  7385. return ob;
  7386. }());
  7387. var registeredEffects$1 = {};
  7388. var idPrefix = 'filter_result_';
  7389. function SVGEffects(elem) {
  7390. var i;
  7391. var source = 'SourceGraphic';
  7392. var len = elem.data.ef ? elem.data.ef.length : 0;
  7393. var filId = createElementID();
  7394. var fil = filtersFactory.createFilter(filId, true);
  7395. var count = 0;
  7396. this.filters = [];
  7397. var filterManager;
  7398. for (i = 0; i < len; i += 1) {
  7399. filterManager = null;
  7400. var type = elem.data.ef[i].ty;
  7401. if (registeredEffects$1[type]) {
  7402. var Effect = registeredEffects$1[type].effect;
  7403. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7404. source = idPrefix + count;
  7405. if (registeredEffects$1[type].countsAsEffect) {
  7406. count += 1;
  7407. }
  7408. }
  7409. if (filterManager) {
  7410. this.filters.push(filterManager);
  7411. }
  7412. }
  7413. if (count) {
  7414. elem.globalData.defs.appendChild(fil);
  7415. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7416. }
  7417. if (this.filters.length) {
  7418. elem.addRenderableComponent(this);
  7419. }
  7420. }
  7421. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7422. var i;
  7423. var len = this.filters.length;
  7424. for (i = 0; i < len; i += 1) {
  7425. this.filters[i].renderFrame(_isFirstFrame);
  7426. }
  7427. };
  7428. SVGEffects.prototype.getEffects = function (type) {
  7429. var i;
  7430. var len = this.filters.length;
  7431. var effects = [];
  7432. for (i = 0; i < len; i += 1) {
  7433. if (this.filters[i].type === type) {
  7434. effects.push(this.filters[i]);
  7435. }
  7436. }
  7437. return effects;
  7438. };
  7439. function registerEffect$1(id, effect, countsAsEffect) {
  7440. registeredEffects$1[id] = {
  7441. effect,
  7442. countsAsEffect,
  7443. };
  7444. }
  7445. function SVGBaseElement() {
  7446. }
  7447. SVGBaseElement.prototype = {
  7448. initRendererElement: function () {
  7449. this.layerElement = createNS('g');
  7450. },
  7451. createContainerElements: function () {
  7452. this.matteElement = createNS('g');
  7453. this.transformedElement = this.layerElement;
  7454. this.maskedElement = this.layerElement;
  7455. this._sizeChanged = false;
  7456. var layerElementParent = null;
  7457. // If this layer acts as a mask for the following layer
  7458. if (this.data.td) {
  7459. this.matteMasks = {};
  7460. var gg = createNS('g');
  7461. gg.setAttribute('id', this.layerId);
  7462. gg.appendChild(this.layerElement);
  7463. layerElementParent = gg;
  7464. this.globalData.defs.appendChild(gg);
  7465. } else if (this.data.tt) {
  7466. this.matteElement.appendChild(this.layerElement);
  7467. layerElementParent = this.matteElement;
  7468. this.baseElement = this.matteElement;
  7469. } else {
  7470. this.baseElement = this.layerElement;
  7471. }
  7472. if (this.data.ln) {
  7473. this.layerElement.setAttribute('id', this.data.ln);
  7474. }
  7475. if (this.data.cl) {
  7476. this.layerElement.setAttribute('class', this.data.cl);
  7477. }
  7478. // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7479. if (this.data.ty === 0 && !this.data.hd) {
  7480. var cp = createNS('clipPath');
  7481. var pt = createNS('path');
  7482. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7483. var clipId = createElementID();
  7484. cp.setAttribute('id', clipId);
  7485. cp.appendChild(pt);
  7486. this.globalData.defs.appendChild(cp);
  7487. if (this.checkMasks()) {
  7488. var cpGroup = createNS('g');
  7489. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7490. cpGroup.appendChild(this.layerElement);
  7491. this.transformedElement = cpGroup;
  7492. if (layerElementParent) {
  7493. layerElementParent.appendChild(this.transformedElement);
  7494. } else {
  7495. this.baseElement = this.transformedElement;
  7496. }
  7497. } else {
  7498. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7499. }
  7500. }
  7501. if (this.data.bm !== 0) {
  7502. this.setBlendMode();
  7503. }
  7504. },
  7505. renderElement: function () {
  7506. if (this.finalTransform._localMatMdf) {
  7507. this.transformedElement.setAttribute('transform', this.finalTransform.localMat.to2dCSS());
  7508. }
  7509. if (this.finalTransform._opMdf) {
  7510. this.transformedElement.setAttribute('opacity', this.finalTransform.localOpacity);
  7511. }
  7512. },
  7513. destroyBaseElement: function () {
  7514. this.layerElement = null;
  7515. this.matteElement = null;
  7516. this.maskManager.destroy();
  7517. },
  7518. getBaseElement: function () {
  7519. if (this.data.hd) {
  7520. return null;
  7521. }
  7522. return this.baseElement;
  7523. },
  7524. createRenderableComponents: function () {
  7525. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7526. this.renderableEffectsManager = new SVGEffects(this);
  7527. this.searchEffectTransforms();
  7528. },
  7529. getMatte: function (matteType) {
  7530. // This should not be a common case. But for backward compatibility, we'll create the matte object.
  7531. // It solves animations that have two consecutive layers marked as matte masks.
  7532. // Which is an undefined behavior in AE.
  7533. if (!this.matteMasks) {
  7534. this.matteMasks = {};
  7535. }
  7536. if (!this.matteMasks[matteType]) {
  7537. var id = this.layerId + '_' + matteType;
  7538. var filId;
  7539. var fil;
  7540. var useElement;
  7541. var gg;
  7542. if (matteType === 1 || matteType === 3) {
  7543. var masker = createNS('mask');
  7544. masker.setAttribute('id', id);
  7545. masker.setAttribute('mask-type', matteType === 3 ? 'luminance' : 'alpha');
  7546. useElement = createNS('use');
  7547. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7548. masker.appendChild(useElement);
  7549. this.globalData.defs.appendChild(masker);
  7550. if (!featureSupport.maskType && matteType === 1) {
  7551. masker.setAttribute('mask-type', 'luminance');
  7552. filId = createElementID();
  7553. fil = filtersFactory.createFilter(filId);
  7554. this.globalData.defs.appendChild(fil);
  7555. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7556. gg = createNS('g');
  7557. gg.appendChild(useElement);
  7558. masker.appendChild(gg);
  7559. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7560. }
  7561. } else if (matteType === 2) {
  7562. var maskGroup = createNS('mask');
  7563. maskGroup.setAttribute('id', id);
  7564. maskGroup.setAttribute('mask-type', 'alpha');
  7565. var maskGrouper = createNS('g');
  7566. maskGroup.appendChild(maskGrouper);
  7567. filId = createElementID();
  7568. fil = filtersFactory.createFilter(filId);
  7569. /// /
  7570. var feCTr = createNS('feComponentTransfer');
  7571. feCTr.setAttribute('in', 'SourceGraphic');
  7572. fil.appendChild(feCTr);
  7573. var feFunc = createNS('feFuncA');
  7574. feFunc.setAttribute('type', 'table');
  7575. feFunc.setAttribute('tableValues', '1.0 0.0');
  7576. feCTr.appendChild(feFunc);
  7577. /// /
  7578. this.globalData.defs.appendChild(fil);
  7579. var alphaRect = createNS('rect');
  7580. alphaRect.setAttribute('width', this.comp.data.w);
  7581. alphaRect.setAttribute('height', this.comp.data.h);
  7582. alphaRect.setAttribute('x', '0');
  7583. alphaRect.setAttribute('y', '0');
  7584. alphaRect.setAttribute('fill', '#ffffff');
  7585. alphaRect.setAttribute('opacity', '0');
  7586. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7587. maskGrouper.appendChild(alphaRect);
  7588. useElement = createNS('use');
  7589. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7590. maskGrouper.appendChild(useElement);
  7591. if (!featureSupport.maskType) {
  7592. maskGroup.setAttribute('mask-type', 'luminance');
  7593. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7594. gg = createNS('g');
  7595. maskGrouper.appendChild(alphaRect);
  7596. gg.appendChild(this.layerElement);
  7597. maskGrouper.appendChild(gg);
  7598. }
  7599. this.globalData.defs.appendChild(maskGroup);
  7600. }
  7601. this.matteMasks[matteType] = id;
  7602. }
  7603. return this.matteMasks[matteType];
  7604. },
  7605. setMatte: function (id) {
  7606. if (!this.matteElement) {
  7607. return;
  7608. }
  7609. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7610. },
  7611. };
  7612. /**
  7613. * @file
  7614. * Handles AE's layer parenting property.
  7615. *
  7616. */
  7617. function HierarchyElement() {}
  7618. HierarchyElement.prototype = {
  7619. /**
  7620. * @function
  7621. * Initializes hierarchy properties
  7622. *
  7623. */
  7624. initHierarchy: function () {
  7625. // element's parent list
  7626. this.hierarchy = [];
  7627. // if element is parent of another layer _isParent will be true
  7628. this._isParent = false;
  7629. this.checkParenting();
  7630. },
  7631. /**
  7632. * @function
  7633. * Sets layer's hierarchy.
  7634. * @param {array} hierarch
  7635. * layer's parent list
  7636. *
  7637. */
  7638. setHierarchy: function (hierarchy) {
  7639. this.hierarchy = hierarchy;
  7640. },
  7641. /**
  7642. * @function
  7643. * Sets layer as parent.
  7644. *
  7645. */
  7646. setAsParent: function () {
  7647. this._isParent = true;
  7648. },
  7649. /**
  7650. * @function
  7651. * Searches layer's parenting chain
  7652. *
  7653. */
  7654. checkParenting: function () {
  7655. if (this.data.parent !== undefined) {
  7656. this.comp.buildElementParenting(this, this.data.parent, []);
  7657. }
  7658. },
  7659. };
  7660. function RenderableDOMElement() {}
  7661. (function () {
  7662. var _prototype = {
  7663. initElement: function (data, globalData, comp) {
  7664. this.initFrame();
  7665. this.initBaseData(data, globalData, comp);
  7666. this.initTransform(data, globalData, comp);
  7667. this.initHierarchy();
  7668. this.initRenderable();
  7669. this.initRendererElement();
  7670. this.createContainerElements();
  7671. this.createRenderableComponents();
  7672. this.createContent();
  7673. this.hide();
  7674. },
  7675. hide: function () {
  7676. // console.log('HIDE', this);
  7677. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7678. var elem = this.baseElement || this.layerElement;
  7679. elem.style.display = 'none';
  7680. this.hidden = true;
  7681. }
  7682. },
  7683. show: function () {
  7684. // console.log('SHOW', this);
  7685. if (this.isInRange && !this.isTransparent) {
  7686. if (!this.data.hd) {
  7687. var elem = this.baseElement || this.layerElement;
  7688. elem.style.display = 'block';
  7689. }
  7690. this.hidden = false;
  7691. this._isFirstFrame = true;
  7692. }
  7693. },
  7694. renderFrame: function () {
  7695. // If it is exported as hidden (data.hd === true) no need to render
  7696. // If it is not visible no need to render
  7697. if (this.data.hd || this.hidden) {
  7698. return;
  7699. }
  7700. this.renderTransform();
  7701. this.renderRenderable();
  7702. this.renderLocalTransform();
  7703. this.renderElement();
  7704. this.renderInnerContent();
  7705. if (this._isFirstFrame) {
  7706. this._isFirstFrame = false;
  7707. }
  7708. },
  7709. renderInnerContent: function () {},
  7710. prepareFrame: function (num) {
  7711. this._mdf = false;
  7712. this.prepareRenderableFrame(num);
  7713. this.prepareProperties(num, this.isInRange);
  7714. this.checkTransparency();
  7715. },
  7716. destroy: function () {
  7717. this.innerElem = null;
  7718. this.destroyBaseElement();
  7719. },
  7720. };
  7721. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  7722. }());
  7723. function IImageElement(data, globalData, comp) {
  7724. this.assetData = globalData.getAssetData(data.refId);
  7725. if (this.assetData && this.assetData.sid) {
  7726. this.assetData = globalData.slotManager.getProp(this.assetData);
  7727. }
  7728. this.initElement(data, globalData, comp);
  7729. this.sourceRect = {
  7730. top: 0, left: 0, width: this.assetData.w, height: this.assetData.h,
  7731. };
  7732. }
  7733. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  7734. IImageElement.prototype.createContent = function () {
  7735. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7736. this.innerElem = createNS('image');
  7737. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  7738. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  7739. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7740. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  7741. this.layerElement.appendChild(this.innerElem);
  7742. };
  7743. IImageElement.prototype.sourceRectAtTime = function () {
  7744. return this.sourceRect;
  7745. };
  7746. function ProcessedElement(element, position) {
  7747. this.elem = element;
  7748. this.pos = position;
  7749. }
  7750. function IShapeElement() {
  7751. }
  7752. IShapeElement.prototype = {
  7753. addShapeToModifiers: function (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 (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 () {
  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 (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 (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 (num) {
  7815. this.prepareRenderableFrame(num);
  7816. this.prepareProperties(num, this.isInRange);
  7817. },
  7818. };
  7819. const lineCapEnum = {
  7820. 1: 'butt',
  7821. 2: 'round',
  7822. 3: 'square',
  7823. };
  7824. const 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] = { n: data[i].n, p: prop };
  7885. }
  7886. if (!this.k) {
  7887. this.getValue(true);
  7888. }
  7889. this._isAnimated = this.k;
  7890. }
  7891. DashProperty.prototype.getValue = function (forceRender) {
  7892. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  7893. return;
  7894. }
  7895. this.frameId = this.elem.globalData.frameId;
  7896. this.iterateDynamicProperties();
  7897. this._mdf = this._mdf || forceRender;
  7898. if (this._mdf) {
  7899. var i = 0;
  7900. var len = this.dataProps.length;
  7901. if (this.renderer === 'svg') {
  7902. this.dashStr = '';
  7903. }
  7904. for (i = 0; i < len; i += 1) {
  7905. if (this.dataProps[i].n !== 'o') {
  7906. if (this.renderer === 'svg') {
  7907. this.dashStr += ' ' + this.dataProps[i].p.v;
  7908. } else {
  7909. this.dashArray[i] = this.dataProps[i].p.v;
  7910. }
  7911. } else {
  7912. this.dashoffset[0] = this.dataProps[i].p.v;
  7913. }
  7914. }
  7915. }
  7916. };
  7917. extendPrototype([DynamicPropertyContainer], DashProperty);
  7918. function SVGStrokeStyleData(elem, data, styleOb) {
  7919. this.initDynamicPropertyContainer(elem);
  7920. this.getValue = this.iterateDynamicProperties;
  7921. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7922. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  7923. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  7924. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7925. this.style = styleOb;
  7926. this._isAnimated = !!this._isAnimated;
  7927. }
  7928. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  7929. function SVGFillStyleData(elem, data, styleOb) {
  7930. this.initDynamicPropertyContainer(elem);
  7931. this.getValue = this.iterateDynamicProperties;
  7932. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7933. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7934. this.style = styleOb;
  7935. }
  7936. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  7937. function SVGNoStyleData(elem, data, styleOb) {
  7938. this.initDynamicPropertyContainer(elem);
  7939. this.getValue = this.iterateDynamicProperties;
  7940. this.style = styleOb;
  7941. }
  7942. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  7943. function GradientProperty(elem, data, container) {
  7944. this.data = data;
  7945. this.c = createTypedArray('uint8c', data.p * 4);
  7946. var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p * 4) : data.k.k.length - data.p * 4;
  7947. this.o = createTypedArray('float32', cLength);
  7948. this._cmdf = false;
  7949. this._omdf = false;
  7950. this._collapsable = this.checkCollapsable();
  7951. this._hasOpacity = cLength;
  7952. this.initDynamicPropertyContainer(container);
  7953. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  7954. this.k = this.prop.k;
  7955. this.getValue(true);
  7956. }
  7957. GradientProperty.prototype.comparePoints = function (values, points) {
  7958. var i = 0;
  7959. var len = this.o.length / 2;
  7960. var diff;
  7961. while (i < len) {
  7962. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  7963. if (diff > 0.01) {
  7964. return false;
  7965. }
  7966. i += 1;
  7967. }
  7968. return true;
  7969. };
  7970. GradientProperty.prototype.checkCollapsable = function () {
  7971. if (this.o.length / 2 !== this.c.length / 4) {
  7972. return false;
  7973. }
  7974. if (this.data.k.k[0].s) {
  7975. var i = 0;
  7976. var len = this.data.k.k.length;
  7977. while (i < len) {
  7978. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  7979. return false;
  7980. }
  7981. i += 1;
  7982. }
  7983. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  7984. return false;
  7985. }
  7986. return true;
  7987. };
  7988. GradientProperty.prototype.getValue = function (forceRender) {
  7989. this.prop.getValue();
  7990. this._mdf = false;
  7991. this._cmdf = false;
  7992. this._omdf = false;
  7993. if (this.prop._mdf || forceRender) {
  7994. var i;
  7995. var len = this.data.p * 4;
  7996. var mult;
  7997. var val;
  7998. for (i = 0; i < len; i += 1) {
  7999. mult = i % 4 === 0 ? 100 : 255;
  8000. val = Math.round(this.prop.v[i] * mult);
  8001. if (this.c[i] !== val) {
  8002. this.c[i] = val;
  8003. this._cmdf = !forceRender;
  8004. }
  8005. }
  8006. if (this.o.length) {
  8007. len = this.prop.v.length;
  8008. for (i = this.data.p * 4; i < len; i += 1) {
  8009. mult = i % 2 === 0 ? 100 : 1;
  8010. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  8011. if (this.o[i - this.data.p * 4] !== val) {
  8012. this.o[i - this.data.p * 4] = val;
  8013. this._omdf = !forceRender;
  8014. }
  8015. }
  8016. }
  8017. this._mdf = !forceRender;
  8018. }
  8019. };
  8020. extendPrototype([DynamicPropertyContainer], GradientProperty);
  8021. function SVGGradientFillStyleData(elem, data, styleOb) {
  8022. this.initDynamicPropertyContainer(elem);
  8023. this.getValue = this.iterateDynamicProperties;
  8024. this.initGradientData(elem, data, styleOb);
  8025. }
  8026. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  8027. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8028. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  8029. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  8030. this.h = PropertyFactory.getProp(elem, data.h || { k: 0 }, 0, 0.01, this);
  8031. this.a = PropertyFactory.getProp(elem, data.a || { k: 0 }, 0, degToRads, this);
  8032. this.g = new GradientProperty(elem, data.g, this);
  8033. this.style = styleOb;
  8034. this.stops = [];
  8035. this.setGradientData(styleOb.pElem, data);
  8036. this.setGradientOpacity(data, styleOb);
  8037. this._isAnimated = !!this._isAnimated;
  8038. };
  8039. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  8040. var gradientId = createElementID();
  8041. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8042. gfill.setAttribute('id', gradientId);
  8043. gfill.setAttribute('spreadMethod', 'pad');
  8044. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8045. var stops = [];
  8046. var stop;
  8047. var j;
  8048. var jLen;
  8049. jLen = data.g.p * 4;
  8050. for (j = 0; j < jLen; j += 4) {
  8051. stop = createNS('stop');
  8052. gfill.appendChild(stop);
  8053. stops.push(stop);
  8054. }
  8055. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  8056. this.gf = gfill;
  8057. this.cst = stops;
  8058. };
  8059. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  8060. if (this.g._hasOpacity && !this.g._collapsable) {
  8061. var stop;
  8062. var j;
  8063. var jLen;
  8064. var mask = createNS('mask');
  8065. var maskElement = createNS('path');
  8066. mask.appendChild(maskElement);
  8067. var opacityId = createElementID();
  8068. var maskId = createElementID();
  8069. mask.setAttribute('id', maskId);
  8070. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8071. opFill.setAttribute('id', opacityId);
  8072. opFill.setAttribute('spreadMethod', 'pad');
  8073. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8074. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8075. var stops = this.stops;
  8076. for (j = data.g.p * 4; j < jLen; j += 2) {
  8077. stop = createNS('stop');
  8078. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8079. opFill.appendChild(stop);
  8080. stops.push(stop);
  8081. }
  8082. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8083. if (data.ty === 'gs') {
  8084. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8085. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8086. if (data.lj === 1) {
  8087. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8088. }
  8089. }
  8090. this.of = opFill;
  8091. this.ms = mask;
  8092. this.ost = stops;
  8093. this.maskId = maskId;
  8094. styleOb.msElem = maskElement;
  8095. }
  8096. };
  8097. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8098. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8099. this.initDynamicPropertyContainer(elem);
  8100. this.getValue = this.iterateDynamicProperties;
  8101. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8102. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8103. this.initGradientData(elem, data, styleOb);
  8104. this._isAnimated = !!this._isAnimated;
  8105. }
  8106. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8107. function ShapeGroupData() {
  8108. this.it = [];
  8109. this.prevViewData = [];
  8110. this.gr = createNS('g');
  8111. }
  8112. function SVGTransformData(mProps, op, container) {
  8113. this.transform = {
  8114. mProps: mProps,
  8115. op: op,
  8116. container: container,
  8117. };
  8118. this.elements = [];
  8119. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8120. }
  8121. const buildShapeString = function (pathNodes, length, closed, mat) {
  8122. if (length === 0) {
  8123. return '';
  8124. }
  8125. var _o = pathNodes.o;
  8126. var _i = pathNodes.i;
  8127. var _v = pathNodes.v;
  8128. var i;
  8129. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8130. for (i = 1; i < length; i += 1) {
  8131. 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]);
  8132. }
  8133. if (closed && length) {
  8134. 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]);
  8135. shapeString += 'z';
  8136. }
  8137. return shapeString;
  8138. };
  8139. const SVGElementsRenderer = (function () {
  8140. var _identityMatrix = new Matrix();
  8141. var _matrixHelper = new Matrix();
  8142. var ob = {
  8143. createRenderFunction: createRenderFunction,
  8144. };
  8145. function createRenderFunction(data) {
  8146. switch (data.ty) {
  8147. case 'fl':
  8148. return renderFill;
  8149. case 'gf':
  8150. return renderGradient;
  8151. case 'gs':
  8152. return renderGradientStroke;
  8153. case 'st':
  8154. return renderStroke;
  8155. case 'sh':
  8156. case 'el':
  8157. case 'rc':
  8158. case 'sr':
  8159. return renderPath;
  8160. case 'tr':
  8161. return renderContentTransform;
  8162. case 'no':
  8163. return renderNoop;
  8164. default:
  8165. return null;
  8166. }
  8167. }
  8168. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8169. if (isFirstFrame || itemData.transform.op._mdf) {
  8170. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8171. }
  8172. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8173. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8174. }
  8175. }
  8176. function renderNoop() {
  8177. }
  8178. function renderPath(styleData, itemData, isFirstFrame) {
  8179. var j;
  8180. var jLen;
  8181. var pathStringTransformed;
  8182. var redraw;
  8183. var pathNodes;
  8184. var l;
  8185. var lLen = itemData.styles.length;
  8186. var lvl = itemData.lvl;
  8187. var paths;
  8188. var mat;
  8189. var iterations;
  8190. var k;
  8191. for (l = 0; l < lLen; l += 1) {
  8192. redraw = itemData.sh._mdf || isFirstFrame;
  8193. if (itemData.styles[l].lvl < lvl) {
  8194. mat = _matrixHelper.reset();
  8195. iterations = lvl - itemData.styles[l].lvl;
  8196. k = itemData.transformers.length - 1;
  8197. while (!redraw && iterations > 0) {
  8198. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8199. iterations -= 1;
  8200. k -= 1;
  8201. }
  8202. if (redraw) {
  8203. iterations = lvl - itemData.styles[l].lvl;
  8204. k = itemData.transformers.length - 1;
  8205. while (iterations > 0) {
  8206. mat.multiply(itemData.transformers[k].mProps.v);
  8207. iterations -= 1;
  8208. k -= 1;
  8209. }
  8210. }
  8211. } else {
  8212. mat = _identityMatrix;
  8213. }
  8214. paths = itemData.sh.paths;
  8215. jLen = paths._length;
  8216. if (redraw) {
  8217. pathStringTransformed = '';
  8218. for (j = 0; j < jLen; j += 1) {
  8219. pathNodes = paths.shapes[j];
  8220. if (pathNodes && pathNodes._length) {
  8221. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8222. }
  8223. }
  8224. itemData.caches[l] = pathStringTransformed;
  8225. } else {
  8226. pathStringTransformed = itemData.caches[l];
  8227. }
  8228. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8229. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8230. }
  8231. }
  8232. function renderFill(styleData, itemData, isFirstFrame) {
  8233. var styleElem = itemData.style;
  8234. if (itemData.c._mdf || isFirstFrame) {
  8235. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8236. }
  8237. if (itemData.o._mdf || isFirstFrame) {
  8238. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8239. }
  8240. }
  8241. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8242. renderGradient(styleData, itemData, isFirstFrame);
  8243. renderStroke(styleData, itemData, isFirstFrame);
  8244. }
  8245. function renderGradient(styleData, itemData, isFirstFrame) {
  8246. var gfill = itemData.gf;
  8247. var hasOpacity = itemData.g._hasOpacity;
  8248. var pt1 = itemData.s.v;
  8249. var pt2 = itemData.e.v;
  8250. if (itemData.o._mdf || isFirstFrame) {
  8251. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8252. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8253. }
  8254. if (itemData.s._mdf || isFirstFrame) {
  8255. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8256. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8257. gfill.setAttribute(attr1, pt1[0]);
  8258. gfill.setAttribute(attr2, pt1[1]);
  8259. if (hasOpacity && !itemData.g._collapsable) {
  8260. itemData.of.setAttribute(attr1, pt1[0]);
  8261. itemData.of.setAttribute(attr2, pt1[1]);
  8262. }
  8263. }
  8264. var stops;
  8265. var i;
  8266. var len;
  8267. var stop;
  8268. if (itemData.g._cmdf || isFirstFrame) {
  8269. stops = itemData.cst;
  8270. var cValues = itemData.g.c;
  8271. len = stops.length;
  8272. for (i = 0; i < len; i += 1) {
  8273. stop = stops[i];
  8274. stop.setAttribute('offset', cValues[i * 4] + '%');
  8275. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8276. }
  8277. }
  8278. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8279. var oValues = itemData.g.o;
  8280. if (itemData.g._collapsable) {
  8281. stops = itemData.cst;
  8282. } else {
  8283. stops = itemData.ost;
  8284. }
  8285. len = stops.length;
  8286. for (i = 0; i < len; i += 1) {
  8287. stop = stops[i];
  8288. if (!itemData.g._collapsable) {
  8289. stop.setAttribute('offset', oValues[i * 2] + '%');
  8290. }
  8291. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8292. }
  8293. }
  8294. if (styleData.t === 1) {
  8295. if (itemData.e._mdf || isFirstFrame) {
  8296. gfill.setAttribute('x2', pt2[0]);
  8297. gfill.setAttribute('y2', pt2[1]);
  8298. if (hasOpacity && !itemData.g._collapsable) {
  8299. itemData.of.setAttribute('x2', pt2[0]);
  8300. itemData.of.setAttribute('y2', pt2[1]);
  8301. }
  8302. }
  8303. } else {
  8304. var rad;
  8305. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8306. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8307. gfill.setAttribute('r', rad);
  8308. if (hasOpacity && !itemData.g._collapsable) {
  8309. itemData.of.setAttribute('r', rad);
  8310. }
  8311. }
  8312. if (itemData.s._mdf || itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8313. if (!rad) {
  8314. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8315. }
  8316. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8317. var percent = itemData.h.v;
  8318. if (percent >= 1) {
  8319. percent = 0.99;
  8320. } else if (percent <= -1) {
  8321. percent = -0.99;
  8322. }
  8323. var dist = rad * percent;
  8324. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8325. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8326. gfill.setAttribute('fx', x);
  8327. gfill.setAttribute('fy', y);
  8328. if (hasOpacity && !itemData.g._collapsable) {
  8329. itemData.of.setAttribute('fx', x);
  8330. itemData.of.setAttribute('fy', y);
  8331. }
  8332. }
  8333. // gfill.setAttribute('fy','200');
  8334. }
  8335. }
  8336. function renderStroke(styleData, itemData, isFirstFrame) {
  8337. var styleElem = itemData.style;
  8338. var d = itemData.d;
  8339. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8340. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8341. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8342. }
  8343. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8344. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8345. }
  8346. if (itemData.o._mdf || isFirstFrame) {
  8347. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8348. }
  8349. if (itemData.w._mdf || isFirstFrame) {
  8350. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8351. if (styleElem.msElem) {
  8352. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8353. }
  8354. }
  8355. }
  8356. return ob;
  8357. }());
  8358. function SVGShapeElement(data, globalData, comp) {
  8359. // List of drawable elements
  8360. this.shapes = [];
  8361. // Full shape data
  8362. this.shapesData = data.shapes;
  8363. // List of styles that will be applied to shapes
  8364. this.stylesList = [];
  8365. // List of modifiers that will be applied to shapes
  8366. this.shapeModifiers = [];
  8367. // List of items in shape tree
  8368. this.itemsData = [];
  8369. // List of items in previous shape tree
  8370. this.processedElements = [];
  8371. // List of animated components
  8372. this.animatedContents = [];
  8373. this.initElement(data, globalData, comp);
  8374. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8375. // List of elements that have been created
  8376. this.prevViewData = [];
  8377. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8378. }
  8379. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8380. SVGShapeElement.prototype.initSecondaryElement = function () {
  8381. };
  8382. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8383. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8384. SVGShapeElement.prototype.createContent = function () {
  8385. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8386. this.filterUniqueShapes();
  8387. };
  8388. /*
  8389. This method searches for multiple shapes that affect a single element and one of them is animated
  8390. */
  8391. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8392. var i;
  8393. var len = this.shapes.length;
  8394. var shape;
  8395. var j;
  8396. var jLen = this.stylesList.length;
  8397. var style;
  8398. var tempShapes = [];
  8399. var areAnimated = false;
  8400. for (j = 0; j < jLen; j += 1) {
  8401. style = this.stylesList[j];
  8402. areAnimated = false;
  8403. tempShapes.length = 0;
  8404. for (i = 0; i < len; i += 1) {
  8405. shape = this.shapes[i];
  8406. if (shape.styles.indexOf(style) !== -1) {
  8407. tempShapes.push(shape);
  8408. areAnimated = shape._isAnimated || areAnimated;
  8409. }
  8410. }
  8411. if (tempShapes.length > 1 && areAnimated) {
  8412. this.setShapesAsAnimated(tempShapes);
  8413. }
  8414. }
  8415. };
  8416. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8417. var i;
  8418. var len = shapes.length;
  8419. for (i = 0; i < len; i += 1) {
  8420. shapes[i].setAsAnimated();
  8421. }
  8422. };
  8423. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8424. // TODO: prevent drawing of hidden styles
  8425. var elementData;
  8426. var styleOb = new SVGStyleData(data, level);
  8427. var pathElement = styleOb.pElem;
  8428. if (data.ty === 'st') {
  8429. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8430. } else if (data.ty === 'fl') {
  8431. elementData = new SVGFillStyleData(this, data, styleOb);
  8432. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8433. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8434. elementData = new GradientConstructor(this, data, styleOb);
  8435. this.globalData.defs.appendChild(elementData.gf);
  8436. if (elementData.maskId) {
  8437. this.globalData.defs.appendChild(elementData.ms);
  8438. this.globalData.defs.appendChild(elementData.of);
  8439. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8440. }
  8441. } else if (data.ty === 'no') {
  8442. elementData = new SVGNoStyleData(this, data, styleOb);
  8443. }
  8444. if (data.ty === 'st' || data.ty === 'gs') {
  8445. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8446. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8447. pathElement.setAttribute('fill-opacity', '0');
  8448. if (data.lj === 1) {
  8449. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8450. }
  8451. }
  8452. if (data.r === 2) {
  8453. pathElement.setAttribute('fill-rule', 'evenodd');
  8454. }
  8455. if (data.ln) {
  8456. pathElement.setAttribute('id', data.ln);
  8457. }
  8458. if (data.cl) {
  8459. pathElement.setAttribute('class', data.cl);
  8460. }
  8461. if (data.bm) {
  8462. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8463. }
  8464. this.stylesList.push(styleOb);
  8465. this.addToAnimatedContents(data, elementData);
  8466. return elementData;
  8467. };
  8468. SVGShapeElement.prototype.createGroupElement = function (data) {
  8469. var elementData = new ShapeGroupData();
  8470. if (data.ln) {
  8471. elementData.gr.setAttribute('id', data.ln);
  8472. }
  8473. if (data.cl) {
  8474. elementData.gr.setAttribute('class', data.cl);
  8475. }
  8476. if (data.bm) {
  8477. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8478. }
  8479. return elementData;
  8480. };
  8481. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8482. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8483. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8484. this.addToAnimatedContents(data, elementData);
  8485. return elementData;
  8486. };
  8487. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8488. var ty = 4;
  8489. if (data.ty === 'rc') {
  8490. ty = 5;
  8491. } else if (data.ty === 'el') {
  8492. ty = 6;
  8493. } else if (data.ty === 'sr') {
  8494. ty = 7;
  8495. }
  8496. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8497. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8498. this.shapes.push(elementData);
  8499. this.addShapeToModifiers(elementData);
  8500. this.addToAnimatedContents(data, elementData);
  8501. return elementData;
  8502. };
  8503. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8504. var i = 0;
  8505. var len = this.animatedContents.length;
  8506. while (i < len) {
  8507. if (this.animatedContents[i].element === element) {
  8508. return;
  8509. }
  8510. i += 1;
  8511. }
  8512. this.animatedContents.push({
  8513. fn: SVGElementsRenderer.createRenderFunction(data),
  8514. element: element,
  8515. data: data,
  8516. });
  8517. };
  8518. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8519. var arr = elementData.styles;
  8520. var j;
  8521. var jLen = this.stylesList.length;
  8522. for (j = 0; j < jLen; j += 1) {
  8523. if (arr.indexOf(this.stylesList[j]) === -1 && !this.stylesList[j].closed) {
  8524. arr.push(this.stylesList[j]);
  8525. }
  8526. }
  8527. };
  8528. SVGShapeElement.prototype.reloadShapes = function () {
  8529. this._isFirstFrame = true;
  8530. var i;
  8531. var len = this.itemsData.length;
  8532. for (i = 0; i < len; i += 1) {
  8533. this.prevViewData[i] = this.itemsData[i];
  8534. }
  8535. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8536. this.filterUniqueShapes();
  8537. len = this.dynamicProperties.length;
  8538. for (i = 0; i < len; i += 1) {
  8539. this.dynamicProperties[i].getValue();
  8540. }
  8541. this.renderModifiers();
  8542. };
  8543. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8544. var ownTransformers = [].concat(transformers);
  8545. var i;
  8546. var len = arr.length - 1;
  8547. var j;
  8548. var jLen;
  8549. var ownStyles = [];
  8550. var ownModifiers = [];
  8551. var currentTransform;
  8552. var modifier;
  8553. var processedPos;
  8554. for (i = len; i >= 0; i -= 1) {
  8555. processedPos = this.searchProcessedElement(arr[i]);
  8556. if (!processedPos) {
  8557. arr[i]._render = render;
  8558. } else {
  8559. itemsData[i] = prevViewData[processedPos - 1];
  8560. }
  8561. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8562. if (!processedPos) {
  8563. itemsData[i] = this.createStyleElement(arr[i], level);
  8564. } else {
  8565. itemsData[i].style.closed = arr[i].hd;
  8566. }
  8567. if (arr[i]._render) {
  8568. if (itemsData[i].style.pElem.parentNode !== container) {
  8569. container.appendChild(itemsData[i].style.pElem);
  8570. }
  8571. }
  8572. ownStyles.push(itemsData[i].style);
  8573. } else if (arr[i].ty === 'gr') {
  8574. if (!processedPos) {
  8575. itemsData[i] = this.createGroupElement(arr[i]);
  8576. } else {
  8577. jLen = itemsData[i].it.length;
  8578. for (j = 0; j < jLen; j += 1) {
  8579. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8580. }
  8581. }
  8582. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8583. if (arr[i]._render) {
  8584. if (itemsData[i].gr.parentNode !== container) {
  8585. container.appendChild(itemsData[i].gr);
  8586. }
  8587. }
  8588. } else if (arr[i].ty === 'tr') {
  8589. if (!processedPos) {
  8590. itemsData[i] = this.createTransformElement(arr[i], container);
  8591. }
  8592. currentTransform = itemsData[i].transform;
  8593. ownTransformers.push(currentTransform);
  8594. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8595. if (!processedPos) {
  8596. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8597. }
  8598. this.setElementStyles(itemsData[i]);
  8599. } 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') {
  8600. if (!processedPos) {
  8601. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8602. modifier.init(this, arr[i]);
  8603. itemsData[i] = modifier;
  8604. this.shapeModifiers.push(modifier);
  8605. } else {
  8606. modifier = itemsData[i];
  8607. modifier.closed = false;
  8608. }
  8609. ownModifiers.push(modifier);
  8610. } else if (arr[i].ty === 'rp') {
  8611. if (!processedPos) {
  8612. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8613. itemsData[i] = modifier;
  8614. modifier.init(this, arr, i, itemsData);
  8615. this.shapeModifiers.push(modifier);
  8616. render = false;
  8617. } else {
  8618. modifier = itemsData[i];
  8619. modifier.closed = true;
  8620. }
  8621. ownModifiers.push(modifier);
  8622. }
  8623. this.addProcessedElement(arr[i], i + 1);
  8624. }
  8625. len = ownStyles.length;
  8626. for (i = 0; i < len; i += 1) {
  8627. ownStyles[i].closed = true;
  8628. }
  8629. len = ownModifiers.length;
  8630. for (i = 0; i < len; i += 1) {
  8631. ownModifiers[i].closed = true;
  8632. }
  8633. };
  8634. SVGShapeElement.prototype.renderInnerContent = function () {
  8635. this.renderModifiers();
  8636. var i;
  8637. var len = this.stylesList.length;
  8638. for (i = 0; i < len; i += 1) {
  8639. this.stylesList[i].reset();
  8640. }
  8641. this.renderShape();
  8642. for (i = 0; i < len; i += 1) {
  8643. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8644. if (this.stylesList[i].msElem) {
  8645. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  8646. // Adding M0 0 fixes same mask bug on all browsers
  8647. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8648. }
  8649. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8650. }
  8651. }
  8652. };
  8653. SVGShapeElement.prototype.renderShape = function () {
  8654. var i;
  8655. var len = this.animatedContents.length;
  8656. var animatedContent;
  8657. for (i = 0; i < len; i += 1) {
  8658. animatedContent = this.animatedContents[i];
  8659. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8660. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8661. }
  8662. }
  8663. };
  8664. SVGShapeElement.prototype.destroy = function () {
  8665. this.destroyBaseElement();
  8666. this.shapesData = null;
  8667. this.itemsData = null;
  8668. };
  8669. function LetterProps(o, sw, sc, fc, m, p) {
  8670. this.o = o;
  8671. this.sw = sw;
  8672. this.sc = sc;
  8673. this.fc = fc;
  8674. this.m = m;
  8675. this.p = p;
  8676. this._mdf = {
  8677. o: true,
  8678. sw: !!sw,
  8679. sc: !!sc,
  8680. fc: !!fc,
  8681. m: true,
  8682. p: true,
  8683. };
  8684. }
  8685. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  8686. this._mdf.o = false;
  8687. this._mdf.sw = false;
  8688. this._mdf.sc = false;
  8689. this._mdf.fc = false;
  8690. this._mdf.m = false;
  8691. this._mdf.p = false;
  8692. var updated = false;
  8693. if (this.o !== o) {
  8694. this.o = o;
  8695. this._mdf.o = true;
  8696. updated = true;
  8697. }
  8698. if (this.sw !== sw) {
  8699. this.sw = sw;
  8700. this._mdf.sw = true;
  8701. updated = true;
  8702. }
  8703. if (this.sc !== sc) {
  8704. this.sc = sc;
  8705. this._mdf.sc = true;
  8706. updated = true;
  8707. }
  8708. if (this.fc !== fc) {
  8709. this.fc = fc;
  8710. this._mdf.fc = true;
  8711. updated = true;
  8712. }
  8713. if (this.m !== m) {
  8714. this.m = m;
  8715. this._mdf.m = true;
  8716. updated = true;
  8717. }
  8718. 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])) {
  8719. this.p = p;
  8720. this._mdf.p = true;
  8721. updated = true;
  8722. }
  8723. return updated;
  8724. };
  8725. function TextProperty(elem, data) {
  8726. this._frameId = initialDefaultFrame;
  8727. this.pv = '';
  8728. this.v = '';
  8729. this.kf = false;
  8730. this._isFirstFrame = true;
  8731. this._mdf = false;
  8732. if (data.d && data.d.sid) {
  8733. data.d = elem.globalData.slotManager.getProp(data.d);
  8734. }
  8735. this.data = data;
  8736. this.elem = elem;
  8737. this.comp = this.elem.comp;
  8738. this.keysIndex = 0;
  8739. this.canResize = false;
  8740. this.minimumFontSize = 1;
  8741. this.effectsSequence = [];
  8742. this.currentData = {
  8743. ascent: 0,
  8744. boxWidth: this.defaultBoxWidth,
  8745. f: '',
  8746. fStyle: '',
  8747. fWeight: '',
  8748. fc: '',
  8749. j: '',
  8750. justifyOffset: '',
  8751. l: [],
  8752. lh: 0,
  8753. lineWidths: [],
  8754. ls: '',
  8755. of: '',
  8756. s: '',
  8757. sc: '',
  8758. sw: 0,
  8759. t: 0,
  8760. tr: 0,
  8761. sz: 0,
  8762. ps: null,
  8763. fillColorAnim: false,
  8764. strokeColorAnim: false,
  8765. strokeWidthAnim: false,
  8766. yOffset: 0,
  8767. finalSize: 0,
  8768. finalText: [],
  8769. finalLineHeight: 0,
  8770. __complete: false,
  8771. };
  8772. this.copyData(this.currentData, this.data.d.k[0].s);
  8773. if (!this.searchProperty()) {
  8774. this.completeTextData(this.currentData);
  8775. }
  8776. }
  8777. TextProperty.prototype.defaultBoxWidth = [0, 0];
  8778. TextProperty.prototype.copyData = function (obj, data) {
  8779. for (var s in data) {
  8780. if (Object.prototype.hasOwnProperty.call(data, s)) {
  8781. obj[s] = data[s];
  8782. }
  8783. }
  8784. return obj;
  8785. };
  8786. TextProperty.prototype.setCurrentData = function (data) {
  8787. if (!data.__complete) {
  8788. this.completeTextData(data);
  8789. }
  8790. this.currentData = data;
  8791. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  8792. this._mdf = true;
  8793. };
  8794. TextProperty.prototype.searchProperty = function () {
  8795. return this.searchKeyframes();
  8796. };
  8797. TextProperty.prototype.searchKeyframes = function () {
  8798. this.kf = this.data.d.k.length > 1;
  8799. if (this.kf) {
  8800. this.addEffect(this.getKeyframeValue.bind(this));
  8801. }
  8802. return this.kf;
  8803. };
  8804. TextProperty.prototype.addEffect = function (effectFunction) {
  8805. this.effectsSequence.push(effectFunction);
  8806. this.elem.addDynamicProperty(this);
  8807. };
  8808. TextProperty.prototype.getValue = function (_finalValue) {
  8809. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  8810. return;
  8811. }
  8812. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  8813. var currentValue = this.currentData;
  8814. var currentIndex = this.keysIndex;
  8815. if (this.lock) {
  8816. this.setCurrentData(this.currentData);
  8817. return;
  8818. }
  8819. this.lock = true;
  8820. this._mdf = false;
  8821. var i; var
  8822. len = this.effectsSequence.length;
  8823. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  8824. for (i = 0; i < len; i += 1) {
  8825. // Checking if index changed to prevent creating a new object every time the expression updates.
  8826. if (currentIndex !== this.keysIndex) {
  8827. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  8828. } else {
  8829. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  8830. }
  8831. }
  8832. if (currentValue !== finalValue) {
  8833. this.setCurrentData(finalValue);
  8834. }
  8835. this.v = this.currentData;
  8836. this.pv = this.v;
  8837. this.lock = false;
  8838. this.frameId = this.elem.globalData.frameId;
  8839. };
  8840. TextProperty.prototype.getKeyframeValue = function () {
  8841. var textKeys = this.data.d.k;
  8842. var frameNum = this.elem.comp.renderedFrame;
  8843. var i = 0; var
  8844. len = textKeys.length;
  8845. while (i <= len - 1) {
  8846. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  8847. break;
  8848. }
  8849. i += 1;
  8850. }
  8851. if (this.keysIndex !== i) {
  8852. this.keysIndex = i;
  8853. }
  8854. return this.data.d.k[this.keysIndex].s;
  8855. };
  8856. TextProperty.prototype.buildFinalText = function (text) {
  8857. var charactersArray = [];
  8858. var i = 0;
  8859. var len = text.length;
  8860. var charCode;
  8861. var secondCharCode;
  8862. var shouldCombine = false;
  8863. var shouldCombineNext = false;
  8864. var currentChars = '';
  8865. while (i < len) {
  8866. shouldCombine = shouldCombineNext;
  8867. shouldCombineNext = false;
  8868. charCode = text.charCodeAt(i);
  8869. currentChars = text.charAt(i);
  8870. if (FontManager.isCombinedCharacter(charCode)) {
  8871. shouldCombine = true;
  8872. // It's a potential surrogate pair (this is the High surrogate)
  8873. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  8874. if (FontManager.isRegionalFlag(text, i)) {
  8875. currentChars = text.substr(i, 14);
  8876. } else {
  8877. secondCharCode = text.charCodeAt(i + 1);
  8878. // It's a surrogate pair (this is the Low surrogate)
  8879. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  8880. if (FontManager.isModifier(charCode, secondCharCode)) {
  8881. currentChars = text.substr(i, 2);
  8882. shouldCombine = true;
  8883. } else if (FontManager.isFlagEmoji(text.substr(i, 4))) {
  8884. currentChars = text.substr(i, 4);
  8885. } else {
  8886. currentChars = text.substr(i, 2);
  8887. }
  8888. }
  8889. }
  8890. } else if (charCode > 0xDBFF) {
  8891. secondCharCode = text.charCodeAt(i + 1);
  8892. if (FontManager.isVariationSelector(charCode)) {
  8893. shouldCombine = true;
  8894. }
  8895. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  8896. shouldCombine = true;
  8897. shouldCombineNext = true;
  8898. }
  8899. if (shouldCombine) {
  8900. charactersArray[charactersArray.length - 1] += currentChars;
  8901. shouldCombine = false;
  8902. } else {
  8903. charactersArray.push(currentChars);
  8904. }
  8905. i += currentChars.length;
  8906. }
  8907. return charactersArray;
  8908. };
  8909. TextProperty.prototype.completeTextData = function (documentData) {
  8910. documentData.__complete = true;
  8911. var fontManager = this.elem.globalData.fontManager;
  8912. var data = this.data;
  8913. var letters = [];
  8914. var i; var
  8915. len;
  8916. var newLineFlag; var index = 0; var
  8917. val;
  8918. var anchorGrouping = data.m.g;
  8919. var currentSize = 0; var currentPos = 0; var currentLine = 0; var
  8920. lineWidths = [];
  8921. var lineWidth = 0;
  8922. var maxLineWidth = 0;
  8923. var j; var
  8924. jLen;
  8925. var fontData = fontManager.getFontByName(documentData.f);
  8926. var charData; var
  8927. cLength = 0;
  8928. var fontProps = getFontProperties(fontData);
  8929. documentData.fWeight = fontProps.weight;
  8930. documentData.fStyle = fontProps.style;
  8931. documentData.finalSize = documentData.s;
  8932. documentData.finalText = this.buildFinalText(documentData.t);
  8933. len = documentData.finalText.length;
  8934. documentData.finalLineHeight = documentData.lh;
  8935. var trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8936. var charCode;
  8937. if (documentData.sz) {
  8938. var flag = true;
  8939. var boxWidth = documentData.sz[0];
  8940. var boxHeight = documentData.sz[1];
  8941. var currentHeight; var
  8942. finalText;
  8943. while (flag) {
  8944. finalText = this.buildFinalText(documentData.t);
  8945. currentHeight = 0;
  8946. lineWidth = 0;
  8947. len = finalText.length;
  8948. trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8949. var lastSpaceIndex = -1;
  8950. for (i = 0; i < len; i += 1) {
  8951. charCode = finalText[i].charCodeAt(0);
  8952. newLineFlag = false;
  8953. if (finalText[i] === ' ') {
  8954. lastSpaceIndex = i;
  8955. } else if (charCode === 13 || charCode === 3) {
  8956. lineWidth = 0;
  8957. newLineFlag = true;
  8958. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8959. }
  8960. if (fontManager.chars) {
  8961. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  8962. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  8963. } else {
  8964. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  8965. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  8966. }
  8967. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  8968. if (lastSpaceIndex === -1) {
  8969. len += 1;
  8970. } else {
  8971. i = lastSpaceIndex;
  8972. }
  8973. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8974. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r');
  8975. // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  8976. lastSpaceIndex = -1;
  8977. lineWidth = 0;
  8978. } else {
  8979. lineWidth += cLength;
  8980. lineWidth += trackingOffset;
  8981. }
  8982. }
  8983. currentHeight += (fontData.ascent * documentData.finalSize) / 100;
  8984. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  8985. documentData.finalSize -= 1;
  8986. documentData.finalLineHeight = (documentData.finalSize * documentData.lh) / documentData.s;
  8987. } else {
  8988. documentData.finalText = finalText;
  8989. len = documentData.finalText.length;
  8990. flag = false;
  8991. }
  8992. }
  8993. }
  8994. lineWidth = -trackingOffset;
  8995. cLength = 0;
  8996. var uncollapsedSpaces = 0;
  8997. var currentChar;
  8998. for (i = 0; i < len; i += 1) {
  8999. newLineFlag = false;
  9000. currentChar = documentData.finalText[i];
  9001. charCode = currentChar.charCodeAt(0);
  9002. if (charCode === 13 || charCode === 3) {
  9003. uncollapsedSpaces = 0;
  9004. lineWidths.push(lineWidth);
  9005. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9006. lineWidth = -2 * trackingOffset;
  9007. val = '';
  9008. newLineFlag = true;
  9009. currentLine += 1;
  9010. } else {
  9011. val = currentChar;
  9012. }
  9013. if (fontManager.chars) {
  9014. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  9015. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  9016. } else {
  9017. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9018. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  9019. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9020. }
  9021. //
  9022. if (currentChar === ' ') {
  9023. uncollapsedSpaces += cLength + trackingOffset;
  9024. } else {
  9025. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  9026. uncollapsedSpaces = 0;
  9027. }
  9028. letters.push({
  9029. l: cLength, an: cLength, add: currentSize, n: newLineFlag, anIndexes: [], val: val, line: currentLine, animatorJustifyOffset: 0,
  9030. });
  9031. if (anchorGrouping == 2) { // eslint-disable-line eqeqeq
  9032. currentSize += cLength;
  9033. if (val === '' || val === ' ' || i === len - 1) {
  9034. if (val === '' || val === ' ') {
  9035. currentSize -= cLength;
  9036. }
  9037. while (currentPos <= i) {
  9038. letters[currentPos].an = currentSize;
  9039. letters[currentPos].ind = index;
  9040. letters[currentPos].extra = cLength;
  9041. currentPos += 1;
  9042. }
  9043. index += 1;
  9044. currentSize = 0;
  9045. }
  9046. } else if (anchorGrouping == 3) { // eslint-disable-line eqeqeq
  9047. currentSize += cLength;
  9048. if (val === '' || i === len - 1) {
  9049. if (val === '') {
  9050. currentSize -= cLength;
  9051. }
  9052. while (currentPos <= i) {
  9053. letters[currentPos].an = currentSize;
  9054. letters[currentPos].ind = index;
  9055. letters[currentPos].extra = cLength;
  9056. currentPos += 1;
  9057. }
  9058. currentSize = 0;
  9059. index += 1;
  9060. }
  9061. } else {
  9062. letters[index].ind = index;
  9063. letters[index].extra = 0;
  9064. index += 1;
  9065. }
  9066. }
  9067. documentData.l = letters;
  9068. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9069. lineWidths.push(lineWidth);
  9070. if (documentData.sz) {
  9071. documentData.boxWidth = documentData.sz[0];
  9072. documentData.justifyOffset = 0;
  9073. } else {
  9074. documentData.boxWidth = maxLineWidth;
  9075. switch (documentData.j) {
  9076. case 1:
  9077. documentData.justifyOffset = -documentData.boxWidth;
  9078. break;
  9079. case 2:
  9080. documentData.justifyOffset = -documentData.boxWidth / 2;
  9081. break;
  9082. default:
  9083. documentData.justifyOffset = 0;
  9084. }
  9085. }
  9086. documentData.lineWidths = lineWidths;
  9087. var animators = data.a; var animatorData; var
  9088. letterData;
  9089. jLen = animators.length;
  9090. var based; var ind; var
  9091. indexes = [];
  9092. for (j = 0; j < jLen; j += 1) {
  9093. animatorData = animators[j];
  9094. if (animatorData.a.sc) {
  9095. documentData.strokeColorAnim = true;
  9096. }
  9097. if (animatorData.a.sw) {
  9098. documentData.strokeWidthAnim = true;
  9099. }
  9100. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9101. documentData.fillColorAnim = true;
  9102. }
  9103. ind = 0;
  9104. based = animatorData.s.b;
  9105. for (i = 0; i < len; i += 1) {
  9106. letterData = letters[i];
  9107. letterData.anIndexes[j] = ind;
  9108. if ((based == 1 && letterData.val !== '') || (based == 2 && letterData.val !== '' && letterData.val !== ' ') || (based == 3 && (letterData.n || letterData.val == ' ' || i == len - 1)) || (based == 4 && (letterData.n || i == len - 1))) { // eslint-disable-line eqeqeq
  9109. if (animatorData.s.rn === 1) {
  9110. indexes.push(ind);
  9111. }
  9112. ind += 1;
  9113. }
  9114. }
  9115. data.a[j].s.totalChars = ind;
  9116. var currentInd = -1; var
  9117. newInd;
  9118. if (animatorData.s.rn === 1) {
  9119. for (i = 0; i < len; i += 1) {
  9120. letterData = letters[i];
  9121. if (currentInd != letterData.anIndexes[j]) { // eslint-disable-line eqeqeq
  9122. currentInd = letterData.anIndexes[j];
  9123. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9124. }
  9125. letterData.anIndexes[j] = newInd;
  9126. }
  9127. }
  9128. }
  9129. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9130. documentData.ls = documentData.ls || 0;
  9131. documentData.ascent = (fontData.ascent * documentData.finalSize) / 100;
  9132. };
  9133. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9134. index = index === undefined ? this.keysIndex : index;
  9135. var dData = this.copyData({}, this.data.d.k[index].s);
  9136. dData = this.copyData(dData, newData);
  9137. this.data.d.k[index].s = dData;
  9138. this.recalculate(index);
  9139. this.setCurrentData(dData);
  9140. this.elem.addDynamicProperty(this);
  9141. };
  9142. TextProperty.prototype.recalculate = function (index) {
  9143. var dData = this.data.d.k[index].s;
  9144. dData.__complete = false;
  9145. this.keysIndex = 0;
  9146. this._isFirstFrame = true;
  9147. this.getValue(dData);
  9148. };
  9149. TextProperty.prototype.canResizeFont = function (_canResize) {
  9150. this.canResize = _canResize;
  9151. this.recalculate(this.keysIndex);
  9152. this.elem.addDynamicProperty(this);
  9153. };
  9154. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9155. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9156. this.recalculate(this.keysIndex);
  9157. this.elem.addDynamicProperty(this);
  9158. };
  9159. const TextSelectorProp = (function () {
  9160. var max = Math.max;
  9161. var min = Math.min;
  9162. var floor = Math.floor;
  9163. function TextSelectorPropFactory(elem, data) {
  9164. this._currentTextLength = -1;
  9165. this.k = false;
  9166. this.data = data;
  9167. this.elem = elem;
  9168. this.comp = elem.comp;
  9169. this.finalS = 0;
  9170. this.finalE = 0;
  9171. this.initDynamicPropertyContainer(elem);
  9172. this.s = PropertyFactory.getProp(elem, data.s || { k: 0 }, 0, 0, this);
  9173. if ('e' in data) {
  9174. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9175. } else {
  9176. this.e = { v: 100 };
  9177. }
  9178. this.o = PropertyFactory.getProp(elem, data.o || { k: 0 }, 0, 0, this);
  9179. this.xe = PropertyFactory.getProp(elem, data.xe || { k: 0 }, 0, 0, this);
  9180. this.ne = PropertyFactory.getProp(elem, data.ne || { k: 0 }, 0, 0, this);
  9181. this.sm = PropertyFactory.getProp(elem, data.sm || { k: 100 }, 0, 0, this);
  9182. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9183. if (!this.dynamicProperties.length) {
  9184. this.getValue();
  9185. }
  9186. }
  9187. TextSelectorPropFactory.prototype = {
  9188. getMult: function (ind) {
  9189. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9190. this.getValue();
  9191. }
  9192. var x1 = 0;
  9193. var y1 = 0;
  9194. var x2 = 1;
  9195. var y2 = 1;
  9196. if (this.ne.v > 0) {
  9197. x1 = this.ne.v / 100.0;
  9198. } else {
  9199. y1 = -this.ne.v / 100.0;
  9200. }
  9201. if (this.xe.v > 0) {
  9202. x2 = 1.0 - this.xe.v / 100.0;
  9203. } else {
  9204. y2 = 1.0 + this.xe.v / 100.0;
  9205. }
  9206. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9207. var mult = 0;
  9208. var s = this.finalS;
  9209. var e = this.finalE;
  9210. var type = this.data.sh;
  9211. if (type === 2) {
  9212. if (e === s) {
  9213. mult = ind >= e ? 1 : 0;
  9214. } else {
  9215. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9216. }
  9217. mult = easer(mult);
  9218. } else if (type === 3) {
  9219. if (e === s) {
  9220. mult = ind >= e ? 0 : 1;
  9221. } else {
  9222. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9223. }
  9224. mult = easer(mult);
  9225. } else if (type === 4) {
  9226. if (e === s) {
  9227. mult = 0;
  9228. } else {
  9229. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9230. if (mult < 0.5) {
  9231. mult *= 2;
  9232. } else {
  9233. mult = 1 - 2 * (mult - 0.5);
  9234. }
  9235. }
  9236. mult = easer(mult);
  9237. } else if (type === 5) {
  9238. if (e === s) {
  9239. mult = 0;
  9240. } else {
  9241. var tot = e - s;
  9242. /* ind += 0.5;
  9243. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9244. ind = min(max(0, ind + 0.5 - s), e - s);
  9245. var x = -tot / 2 + ind;
  9246. var a = tot / 2;
  9247. mult = Math.sqrt(1 - (x * x) / (a * a));
  9248. }
  9249. mult = easer(mult);
  9250. } else if (type === 6) {
  9251. if (e === s) {
  9252. mult = 0;
  9253. } else {
  9254. ind = min(max(0, ind + 0.5 - s), e - s);
  9255. mult = (1 + (Math.cos((Math.PI + Math.PI * 2 * (ind) / (e - s))))) / 2; // eslint-disable-line
  9256. }
  9257. mult = easer(mult);
  9258. } else {
  9259. if (ind >= floor(s)) {
  9260. if (ind - s < 0) {
  9261. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9262. } else {
  9263. mult = max(0, min(e - ind, 1));
  9264. }
  9265. }
  9266. mult = easer(mult);
  9267. }
  9268. // Smoothness implementation.
  9269. // The smoothness represents a reduced range of the original [0; 1] range.
  9270. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9271. // Steps are:
  9272. // - find the lower value of the new range (threshold)
  9273. // - if multiplier is smaller than that value, floor it to 0
  9274. // - if it is larger,
  9275. // - subtract the threshold
  9276. // - divide it by the smoothness (this will return the range to [0; 1])
  9277. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9278. if (this.sm.v !== 100) {
  9279. var smoothness = this.sm.v * 0.01;
  9280. if (smoothness === 0) {
  9281. smoothness = 0.00000001;
  9282. }
  9283. var threshold = 0.5 - smoothness * 0.5;
  9284. if (mult < threshold) {
  9285. mult = 0;
  9286. } else {
  9287. mult = (mult - threshold) / smoothness;
  9288. if (mult > 1) {
  9289. mult = 1;
  9290. }
  9291. }
  9292. }
  9293. return mult * this.a.v;
  9294. },
  9295. getValue: function (newCharsFlag) {
  9296. this.iterateDynamicProperties();
  9297. this._mdf = newCharsFlag || this._mdf;
  9298. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9299. if (newCharsFlag && this.data.r === 2) {
  9300. this.e.v = this._currentTextLength;
  9301. }
  9302. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9303. var o = this.o.v / divisor;
  9304. var s = this.s.v / divisor + o;
  9305. var e = (this.e.v / divisor) + o;
  9306. if (s > e) {
  9307. var _s = s;
  9308. s = e;
  9309. e = _s;
  9310. }
  9311. this.finalS = s;
  9312. this.finalE = e;
  9313. },
  9314. };
  9315. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9316. function getTextSelectorProp(elem, data, arr) {
  9317. return new TextSelectorPropFactory(elem, data, arr);
  9318. }
  9319. return {
  9320. getTextSelectorProp: getTextSelectorProp,
  9321. };
  9322. }());
  9323. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9324. var defaultData = { propType: false };
  9325. var getProp = PropertyFactory.getProp;
  9326. var textAnimatorAnimatables = animatorProps.a;
  9327. this.a = {
  9328. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9329. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9330. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9331. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9332. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9333. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9334. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9335. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9336. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9337. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9338. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9339. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9340. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9341. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9342. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9343. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData,
  9344. };
  9345. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9346. this.s.t = animatorProps.s.t;
  9347. }
  9348. function TextAnimatorProperty(textData, renderType, elem) {
  9349. this._isFirstFrame = true;
  9350. this._hasMaskedPath = false;
  9351. this._frameId = -1;
  9352. this._textData = textData;
  9353. this._renderType = renderType;
  9354. this._elem = elem;
  9355. this._animatorsData = createSizedArray(this._textData.a.length);
  9356. this._pathData = {};
  9357. this._moreOptions = {
  9358. alignment: {},
  9359. };
  9360. this.renderedLetters = [];
  9361. this.lettersChangedFlag = false;
  9362. this.initDynamicPropertyContainer(elem);
  9363. }
  9364. TextAnimatorProperty.prototype.searchProperties = function () {
  9365. var i;
  9366. var len = this._textData.a.length;
  9367. var animatorProps;
  9368. var getProp = PropertyFactory.getProp;
  9369. for (i = 0; i < len; i += 1) {
  9370. animatorProps = this._textData.a[i];
  9371. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9372. }
  9373. if (this._textData.p && 'm' in this._textData.p) {
  9374. this._pathData = {
  9375. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9376. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9377. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9378. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9379. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9380. m: this._elem.maskManager.getMaskProperty(this._textData.p.m),
  9381. };
  9382. this._hasMaskedPath = true;
  9383. } else {
  9384. this._hasMaskedPath = false;
  9385. }
  9386. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9387. };
  9388. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9389. this.lettersChangedFlag = lettersChangedFlag;
  9390. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9391. return;
  9392. }
  9393. this._isFirstFrame = false;
  9394. var alignment = this._moreOptions.alignment.v;
  9395. var animators = this._animatorsData;
  9396. var textData = this._textData;
  9397. var matrixHelper = this.mHelper;
  9398. var renderType = this._renderType;
  9399. var renderedLettersCount = this.renderedLetters.length;
  9400. var xPos;
  9401. var yPos;
  9402. var i;
  9403. var len;
  9404. var letters = documentData.l;
  9405. var pathInfo;
  9406. var currentLength;
  9407. var currentPoint;
  9408. var segmentLength;
  9409. var flag;
  9410. var pointInd;
  9411. var segmentInd;
  9412. var prevPoint;
  9413. var points;
  9414. var segments;
  9415. var partialLength;
  9416. var totalLength;
  9417. var perc;
  9418. var tanAngle;
  9419. var mask;
  9420. if (this._hasMaskedPath) {
  9421. mask = this._pathData.m;
  9422. if (!this._pathData.n || this._pathData._mdf) {
  9423. var paths = mask.v;
  9424. if (this._pathData.r.v) {
  9425. paths = paths.reverse();
  9426. }
  9427. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9428. pathInfo = {
  9429. tLength: 0,
  9430. segments: [],
  9431. };
  9432. len = paths._length - 1;
  9433. var bezierData;
  9434. totalLength = 0;
  9435. for (i = 0; i < len; i += 1) {
  9436. bezierData = bez.buildBezierData(paths.v[i],
  9437. paths.v[i + 1],
  9438. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9439. [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9440. pathInfo.tLength += bezierData.segmentLength;
  9441. pathInfo.segments.push(bezierData);
  9442. totalLength += bezierData.segmentLength;
  9443. }
  9444. i = len;
  9445. if (mask.v.c) {
  9446. bezierData = bez.buildBezierData(paths.v[i],
  9447. paths.v[0],
  9448. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9449. [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9450. pathInfo.tLength += bezierData.segmentLength;
  9451. pathInfo.segments.push(bezierData);
  9452. totalLength += bezierData.segmentLength;
  9453. }
  9454. this._pathData.pi = pathInfo;
  9455. }
  9456. pathInfo = this._pathData.pi;
  9457. currentLength = this._pathData.f.v;
  9458. segmentInd = 0;
  9459. pointInd = 1;
  9460. segmentLength = 0;
  9461. flag = true;
  9462. segments = pathInfo.segments;
  9463. if (currentLength < 0 && mask.v.c) {
  9464. if (pathInfo.tLength < Math.abs(currentLength)) {
  9465. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9466. }
  9467. segmentInd = segments.length - 1;
  9468. points = segments[segmentInd].points;
  9469. pointInd = points.length - 1;
  9470. while (currentLength < 0) {
  9471. currentLength += points[pointInd].partialLength;
  9472. pointInd -= 1;
  9473. if (pointInd < 0) {
  9474. segmentInd -= 1;
  9475. points = segments[segmentInd].points;
  9476. pointInd = points.length - 1;
  9477. }
  9478. }
  9479. }
  9480. points = segments[segmentInd].points;
  9481. prevPoint = points[pointInd - 1];
  9482. currentPoint = points[pointInd];
  9483. partialLength = currentPoint.partialLength;
  9484. }
  9485. len = letters.length;
  9486. xPos = 0;
  9487. yPos = 0;
  9488. var yOff = documentData.finalSize * 1.2 * 0.714;
  9489. var firstLine = true;
  9490. var animatorProps;
  9491. var animatorSelector;
  9492. var j;
  9493. var jLen;
  9494. var letterValue;
  9495. jLen = animators.length;
  9496. var mult;
  9497. var ind = -1;
  9498. var offf;
  9499. var xPathPos;
  9500. var yPathPos;
  9501. var initPathPos = currentLength;
  9502. var initSegmentInd = segmentInd;
  9503. var initPointInd = pointInd;
  9504. var currentLine = -1;
  9505. var elemOpacity;
  9506. var sc;
  9507. var sw;
  9508. var fc;
  9509. var k;
  9510. var letterSw;
  9511. var letterSc;
  9512. var letterFc;
  9513. var letterM = '';
  9514. var letterP = this.defaultPropsArray;
  9515. var letterO;
  9516. //
  9517. if (documentData.j === 2 || documentData.j === 1) {
  9518. var animatorJustifyOffset = 0;
  9519. var animatorFirstCharOffset = 0;
  9520. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9521. var lastIndex = 0;
  9522. var isNewLine = true;
  9523. for (i = 0; i < len; i += 1) {
  9524. if (letters[i].n) {
  9525. if (animatorJustifyOffset) {
  9526. animatorJustifyOffset += animatorFirstCharOffset;
  9527. }
  9528. while (lastIndex < i) {
  9529. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9530. lastIndex += 1;
  9531. }
  9532. animatorJustifyOffset = 0;
  9533. isNewLine = true;
  9534. } else {
  9535. for (j = 0; j < jLen; j += 1) {
  9536. animatorProps = animators[j].a;
  9537. if (animatorProps.t.propType) {
  9538. if (isNewLine && documentData.j === 2) {
  9539. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9540. }
  9541. animatorSelector = animators[j].s;
  9542. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9543. if (mult.length) {
  9544. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9545. } else {
  9546. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9547. }
  9548. }
  9549. }
  9550. isNewLine = false;
  9551. }
  9552. }
  9553. if (animatorJustifyOffset) {
  9554. animatorJustifyOffset += animatorFirstCharOffset;
  9555. }
  9556. while (lastIndex < i) {
  9557. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9558. lastIndex += 1;
  9559. }
  9560. }
  9561. //
  9562. for (i = 0; i < len; i += 1) {
  9563. matrixHelper.reset();
  9564. elemOpacity = 1;
  9565. if (letters[i].n) {
  9566. xPos = 0;
  9567. yPos += documentData.yOffset;
  9568. yPos += firstLine ? 1 : 0;
  9569. currentLength = initPathPos;
  9570. firstLine = false;
  9571. if (this._hasMaskedPath) {
  9572. segmentInd = initSegmentInd;
  9573. pointInd = initPointInd;
  9574. points = segments[segmentInd].points;
  9575. prevPoint = points[pointInd - 1];
  9576. currentPoint = points[pointInd];
  9577. partialLength = currentPoint.partialLength;
  9578. segmentLength = 0;
  9579. }
  9580. letterM = '';
  9581. letterFc = '';
  9582. letterSw = '';
  9583. letterO = '';
  9584. letterP = this.defaultPropsArray;
  9585. } else {
  9586. if (this._hasMaskedPath) {
  9587. if (currentLine !== letters[i].line) {
  9588. switch (documentData.j) {
  9589. case 1:
  9590. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9591. break;
  9592. case 2:
  9593. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9594. break;
  9595. default:
  9596. break;
  9597. }
  9598. currentLine = letters[i].line;
  9599. }
  9600. if (ind !== letters[i].ind) {
  9601. if (letters[ind]) {
  9602. currentLength += letters[ind].extra;
  9603. }
  9604. currentLength += letters[i].an / 2;
  9605. ind = letters[i].ind;
  9606. }
  9607. currentLength += (alignment[0] * letters[i].an) * 0.005;
  9608. var animatorOffset = 0;
  9609. for (j = 0; j < jLen; j += 1) {
  9610. animatorProps = animators[j].a;
  9611. if (animatorProps.p.propType) {
  9612. animatorSelector = animators[j].s;
  9613. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9614. if (mult.length) {
  9615. animatorOffset += animatorProps.p.v[0] * mult[0];
  9616. } else {
  9617. animatorOffset += animatorProps.p.v[0] * mult;
  9618. }
  9619. }
  9620. if (animatorProps.a.propType) {
  9621. animatorSelector = animators[j].s;
  9622. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9623. if (mult.length) {
  9624. animatorOffset += animatorProps.a.v[0] * mult[0];
  9625. } else {
  9626. animatorOffset += animatorProps.a.v[0] * mult;
  9627. }
  9628. }
  9629. }
  9630. flag = true;
  9631. // Force alignment only works with a single line for now
  9632. if (this._pathData.a.v) {
  9633. 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);
  9634. currentLength += this._pathData.f.v;
  9635. }
  9636. while (flag) {
  9637. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9638. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9639. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9640. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9641. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, -(alignment[1] * yOff) * 0.01);
  9642. flag = false;
  9643. } else if (points) {
  9644. segmentLength += currentPoint.partialLength;
  9645. pointInd += 1;
  9646. if (pointInd >= points.length) {
  9647. pointInd = 0;
  9648. segmentInd += 1;
  9649. if (!segments[segmentInd]) {
  9650. if (mask.v.c) {
  9651. pointInd = 0;
  9652. segmentInd = 0;
  9653. points = segments[segmentInd].points;
  9654. } else {
  9655. segmentLength -= currentPoint.partialLength;
  9656. points = null;
  9657. }
  9658. } else {
  9659. points = segments[segmentInd].points;
  9660. }
  9661. }
  9662. if (points) {
  9663. prevPoint = currentPoint;
  9664. currentPoint = points[pointInd];
  9665. partialLength = currentPoint.partialLength;
  9666. }
  9667. }
  9668. }
  9669. offf = letters[i].an / 2 - letters[i].add;
  9670. matrixHelper.translate(-offf, 0, 0);
  9671. } else {
  9672. offf = letters[i].an / 2 - letters[i].add;
  9673. matrixHelper.translate(-offf, 0, 0);
  9674. // Grouping alignment
  9675. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, (-alignment[1] * yOff) * 0.01, 0);
  9676. }
  9677. for (j = 0; j < jLen; j += 1) {
  9678. animatorProps = animators[j].a;
  9679. if (animatorProps.t.propType) {
  9680. animatorSelector = animators[j].s;
  9681. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9682. // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9683. if (xPos !== 0 || documentData.j !== 0) {
  9684. if (this._hasMaskedPath) {
  9685. if (mult.length) {
  9686. currentLength += animatorProps.t.v * mult[0];
  9687. } else {
  9688. currentLength += animatorProps.t.v * mult;
  9689. }
  9690. } else if (mult.length) {
  9691. xPos += animatorProps.t.v * mult[0];
  9692. } else {
  9693. xPos += animatorProps.t.v * mult;
  9694. }
  9695. }
  9696. }
  9697. }
  9698. if (documentData.strokeWidthAnim) {
  9699. sw = documentData.sw || 0;
  9700. }
  9701. if (documentData.strokeColorAnim) {
  9702. if (documentData.sc) {
  9703. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  9704. } else {
  9705. sc = [0, 0, 0];
  9706. }
  9707. }
  9708. if (documentData.fillColorAnim && documentData.fc) {
  9709. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  9710. }
  9711. for (j = 0; j < jLen; j += 1) {
  9712. animatorProps = animators[j].a;
  9713. if (animatorProps.a.propType) {
  9714. animatorSelector = animators[j].s;
  9715. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9716. if (mult.length) {
  9717. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  9718. } else {
  9719. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  9720. }
  9721. }
  9722. }
  9723. for (j = 0; j < jLen; j += 1) {
  9724. animatorProps = animators[j].a;
  9725. if (animatorProps.s.propType) {
  9726. animatorSelector = animators[j].s;
  9727. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9728. if (mult.length) {
  9729. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult[0]), 1 + ((animatorProps.s.v[1] - 1) * mult[1]), 1);
  9730. } else {
  9731. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult), 1 + ((animatorProps.s.v[1] - 1) * mult), 1);
  9732. }
  9733. }
  9734. }
  9735. for (j = 0; j < jLen; j += 1) {
  9736. animatorProps = animators[j].a;
  9737. animatorSelector = animators[j].s;
  9738. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9739. if (animatorProps.sk.propType) {
  9740. if (mult.length) {
  9741. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  9742. } else {
  9743. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  9744. }
  9745. }
  9746. if (animatorProps.r.propType) {
  9747. if (mult.length) {
  9748. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  9749. } else {
  9750. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  9751. }
  9752. }
  9753. if (animatorProps.ry.propType) {
  9754. if (mult.length) {
  9755. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  9756. } else {
  9757. matrixHelper.rotateY(animatorProps.ry.v * mult);
  9758. }
  9759. }
  9760. if (animatorProps.rx.propType) {
  9761. if (mult.length) {
  9762. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  9763. } else {
  9764. matrixHelper.rotateX(animatorProps.rx.v * mult);
  9765. }
  9766. }
  9767. if (animatorProps.o.propType) {
  9768. if (mult.length) {
  9769. elemOpacity += ((animatorProps.o.v) * mult[0] - elemOpacity) * mult[0];
  9770. } else {
  9771. elemOpacity += ((animatorProps.o.v) * mult - elemOpacity) * mult;
  9772. }
  9773. }
  9774. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  9775. if (mult.length) {
  9776. sw += animatorProps.sw.v * mult[0];
  9777. } else {
  9778. sw += animatorProps.sw.v * mult;
  9779. }
  9780. }
  9781. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  9782. for (k = 0; k < 3; k += 1) {
  9783. if (mult.length) {
  9784. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  9785. } else {
  9786. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  9787. }
  9788. }
  9789. }
  9790. if (documentData.fillColorAnim && documentData.fc) {
  9791. if (animatorProps.fc.propType) {
  9792. for (k = 0; k < 3; k += 1) {
  9793. if (mult.length) {
  9794. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  9795. } else {
  9796. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  9797. }
  9798. }
  9799. }
  9800. if (animatorProps.fh.propType) {
  9801. if (mult.length) {
  9802. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  9803. } else {
  9804. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  9805. }
  9806. }
  9807. if (animatorProps.fs.propType) {
  9808. if (mult.length) {
  9809. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  9810. } else {
  9811. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  9812. }
  9813. }
  9814. if (animatorProps.fb.propType) {
  9815. if (mult.length) {
  9816. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  9817. } else {
  9818. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  9819. }
  9820. }
  9821. }
  9822. }
  9823. for (j = 0; j < jLen; j += 1) {
  9824. animatorProps = animators[j].a;
  9825. if (animatorProps.p.propType) {
  9826. animatorSelector = animators[j].s;
  9827. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9828. if (this._hasMaskedPath) {
  9829. if (mult.length) {
  9830. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  9831. } else {
  9832. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9833. }
  9834. } else if (mult.length) {
  9835. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  9836. } else {
  9837. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9838. }
  9839. }
  9840. }
  9841. if (documentData.strokeWidthAnim) {
  9842. letterSw = sw < 0 ? 0 : sw;
  9843. }
  9844. if (documentData.strokeColorAnim) {
  9845. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  9846. }
  9847. if (documentData.fillColorAnim && documentData.fc) {
  9848. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  9849. }
  9850. if (this._hasMaskedPath) {
  9851. matrixHelper.translate(0, -documentData.ls);
  9852. matrixHelper.translate(0, (alignment[1] * yOff) * 0.01 + yPos, 0);
  9853. if (this._pathData.p.v) {
  9854. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  9855. var rot = (Math.atan(tanAngle) * 180) / Math.PI;
  9856. if (currentPoint.point[0] < prevPoint.point[0]) {
  9857. rot += 180;
  9858. }
  9859. matrixHelper.rotate((-rot * Math.PI) / 180);
  9860. }
  9861. matrixHelper.translate(xPathPos, yPathPos, 0);
  9862. currentLength -= (alignment[0] * letters[i].an) * 0.005;
  9863. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  9864. currentLength += letters[i].an / 2;
  9865. currentLength += (documentData.tr * 0.001) * documentData.finalSize;
  9866. }
  9867. } else {
  9868. matrixHelper.translate(xPos, yPos, 0);
  9869. if (documentData.ps) {
  9870. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  9871. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9872. }
  9873. switch (documentData.j) {
  9874. case 1:
  9875. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  9876. break;
  9877. case 2:
  9878. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  9879. break;
  9880. default:
  9881. break;
  9882. }
  9883. matrixHelper.translate(0, -documentData.ls);
  9884. matrixHelper.translate(offf, 0, 0);
  9885. matrixHelper.translate((alignment[0] * letters[i].an) * 0.005, (alignment[1] * yOff) * 0.01, 0);
  9886. xPos += letters[i].l + (documentData.tr * 0.001) * documentData.finalSize;
  9887. }
  9888. if (renderType === 'html') {
  9889. letterM = matrixHelper.toCSS();
  9890. } else if (renderType === 'svg') {
  9891. letterM = matrixHelper.to2dCSS();
  9892. } else {
  9893. 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]];
  9894. }
  9895. letterO = elemOpacity;
  9896. }
  9897. if (renderedLettersCount <= i) {
  9898. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  9899. this.renderedLetters.push(letterValue);
  9900. renderedLettersCount += 1;
  9901. this.lettersChangedFlag = true;
  9902. } else {
  9903. letterValue = this.renderedLetters[i];
  9904. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  9905. }
  9906. }
  9907. };
  9908. TextAnimatorProperty.prototype.getValue = function () {
  9909. if (this._elem.globalData.frameId === this._frameId) {
  9910. return;
  9911. }
  9912. this._frameId = this._elem.globalData.frameId;
  9913. this.iterateDynamicProperties();
  9914. };
  9915. TextAnimatorProperty.prototype.mHelper = new Matrix();
  9916. TextAnimatorProperty.prototype.defaultPropsArray = [];
  9917. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  9918. function ITextElement() {
  9919. }
  9920. ITextElement.prototype.initElement = function (data, globalData, comp) {
  9921. this.lettersChangedFlag = true;
  9922. this.initFrame();
  9923. this.initBaseData(data, globalData, comp);
  9924. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  9925. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  9926. this.initTransform(data, globalData, comp);
  9927. this.initHierarchy();
  9928. this.initRenderable();
  9929. this.initRendererElement();
  9930. this.createContainerElements();
  9931. this.createRenderableComponents();
  9932. this.createContent();
  9933. this.hide();
  9934. this.textAnimator.searchProperties(this.dynamicProperties);
  9935. };
  9936. ITextElement.prototype.prepareFrame = function (num) {
  9937. this._mdf = false;
  9938. this.prepareRenderableFrame(num);
  9939. this.prepareProperties(num, this.isInRange);
  9940. };
  9941. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  9942. var j;
  9943. var jLen = shapes.length;
  9944. var pathNodes;
  9945. var shapeStr = '';
  9946. for (j = 0; j < jLen; j += 1) {
  9947. if (shapes[j].ty === 'sh') {
  9948. pathNodes = shapes[j].ks.k;
  9949. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  9950. }
  9951. }
  9952. return shapeStr;
  9953. };
  9954. ITextElement.prototype.updateDocumentData = function (newData, index) {
  9955. this.textProperty.updateDocumentData(newData, index);
  9956. };
  9957. ITextElement.prototype.canResizeFont = function (_canResize) {
  9958. this.textProperty.canResizeFont(_canResize);
  9959. };
  9960. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  9961. this.textProperty.setMinimumFontSize(_fontSize);
  9962. };
  9963. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  9964. if (documentData.ps) {
  9965. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9966. }
  9967. matrixHelper.translate(0, -documentData.ls, 0);
  9968. switch (documentData.j) {
  9969. case 1:
  9970. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  9971. break;
  9972. case 2:
  9973. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  9974. break;
  9975. default:
  9976. break;
  9977. }
  9978. matrixHelper.translate(xPos, yPos, 0);
  9979. };
  9980. ITextElement.prototype.buildColor = function (colorData) {
  9981. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  9982. };
  9983. ITextElement.prototype.emptyProp = new LetterProps();
  9984. ITextElement.prototype.destroy = function () {
  9985. };
  9986. ITextElement.prototype.validateText = function () {
  9987. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  9988. this.buildNewText();
  9989. this.textProperty._isFirstFrame = false;
  9990. this.textProperty._mdf = false;
  9991. }
  9992. };
  9993. var emptyShapeData = {
  9994. shapes: [],
  9995. };
  9996. function SVGTextLottieElement(data, globalData, comp) {
  9997. this.textSpans = [];
  9998. this.renderType = 'svg';
  9999. this.initElement(data, globalData, comp);
  10000. }
  10001. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  10002. SVGTextLottieElement.prototype.createContent = function () {
  10003. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  10004. this.textContainer = createNS('text');
  10005. }
  10006. };
  10007. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  10008. var i = 0;
  10009. var len = textArray.length;
  10010. var textContents = [];
  10011. var currentTextContent = '';
  10012. while (i < len) {
  10013. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  10014. textContents.push(currentTextContent);
  10015. currentTextContent = '';
  10016. } else {
  10017. currentTextContent += textArray[i];
  10018. }
  10019. i += 1;
  10020. }
  10021. textContents.push(currentTextContent);
  10022. return textContents;
  10023. };
  10024. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  10025. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  10026. // but since text internal content gets only rendered once and then it's never rerendered,
  10027. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  10028. // Avoiding cloning is preferred since cloning each character shape data is expensive
  10029. if (data.shapes && data.shapes.length) {
  10030. var shape = data.shapes[0];
  10031. if (shape.it) {
  10032. var shapeItem = shape.it[shape.it.length - 1];
  10033. if (shapeItem.s) {
  10034. shapeItem.s.k[0] = scale;
  10035. shapeItem.s.k[1] = scale;
  10036. }
  10037. }
  10038. }
  10039. return data;
  10040. };
  10041. SVGTextLottieElement.prototype.buildNewText = function () {
  10042. this.addDynamicProperty(this);
  10043. var i;
  10044. var len;
  10045. var documentData = this.textProperty.currentData;
  10046. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  10047. if (documentData.fc) {
  10048. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  10049. } else {
  10050. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  10051. }
  10052. if (documentData.sc) {
  10053. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  10054. this.layerElement.setAttribute('stroke-width', documentData.sw);
  10055. }
  10056. this.layerElement.setAttribute('font-size', documentData.finalSize);
  10057. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10058. if (fontData.fClass) {
  10059. this.layerElement.setAttribute('class', fontData.fClass);
  10060. } else {
  10061. this.layerElement.setAttribute('font-family', fontData.fFamily);
  10062. var fWeight = documentData.fWeight;
  10063. var fStyle = documentData.fStyle;
  10064. this.layerElement.setAttribute('font-style', fStyle);
  10065. this.layerElement.setAttribute('font-weight', fWeight);
  10066. }
  10067. this.layerElement.setAttribute('aria-label', documentData.t);
  10068. var letters = documentData.l || [];
  10069. var usesGlyphs = !!this.globalData.fontManager.chars;
  10070. len = letters.length;
  10071. var tSpan;
  10072. var matrixHelper = this.mHelper;
  10073. var shapeStr = '';
  10074. var singleShape = this.data.singleShape;
  10075. var xPos = 0;
  10076. var yPos = 0;
  10077. var firstLine = true;
  10078. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10079. if (singleShape && !usesGlyphs && !documentData.sz) {
  10080. var tElement = this.textContainer;
  10081. var justify = 'start';
  10082. switch (documentData.j) {
  10083. case 1:
  10084. justify = 'end';
  10085. break;
  10086. case 2:
  10087. justify = 'middle';
  10088. break;
  10089. default:
  10090. justify = 'start';
  10091. break;
  10092. }
  10093. tElement.setAttribute('text-anchor', justify);
  10094. tElement.setAttribute('letter-spacing', trackingOffset);
  10095. var textContent = this.buildTextContents(documentData.finalText);
  10096. len = textContent.length;
  10097. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10098. for (i = 0; i < len; i += 1) {
  10099. tSpan = this.textSpans[i].span || createNS('tspan');
  10100. tSpan.textContent = textContent[i];
  10101. tSpan.setAttribute('x', 0);
  10102. tSpan.setAttribute('y', yPos);
  10103. tSpan.style.display = 'inherit';
  10104. tElement.appendChild(tSpan);
  10105. if (!this.textSpans[i]) {
  10106. this.textSpans[i] = {
  10107. span: null,
  10108. glyph: null,
  10109. };
  10110. }
  10111. this.textSpans[i].span = tSpan;
  10112. yPos += documentData.finalLineHeight;
  10113. }
  10114. this.layerElement.appendChild(tElement);
  10115. } else {
  10116. var cachedSpansLength = this.textSpans.length;
  10117. var charData;
  10118. for (i = 0; i < len; i += 1) {
  10119. if (!this.textSpans[i]) {
  10120. this.textSpans[i] = {
  10121. span: null,
  10122. childSpan: null,
  10123. glyph: null,
  10124. };
  10125. }
  10126. if (!usesGlyphs || !singleShape || i === 0) {
  10127. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10128. if (cachedSpansLength <= i) {
  10129. tSpan.setAttribute('stroke-linecap', 'butt');
  10130. tSpan.setAttribute('stroke-linejoin', 'round');
  10131. tSpan.setAttribute('stroke-miterlimit', '4');
  10132. this.textSpans[i].span = tSpan;
  10133. if (usesGlyphs) {
  10134. var childSpan = createNS('g');
  10135. tSpan.appendChild(childSpan);
  10136. this.textSpans[i].childSpan = childSpan;
  10137. }
  10138. this.textSpans[i].span = tSpan;
  10139. this.layerElement.appendChild(tSpan);
  10140. }
  10141. tSpan.style.display = 'inherit';
  10142. }
  10143. matrixHelper.reset();
  10144. if (singleShape) {
  10145. if (letters[i].n) {
  10146. xPos = -trackingOffset;
  10147. yPos += documentData.yOffset;
  10148. yPos += firstLine ? 1 : 0;
  10149. firstLine = false;
  10150. }
  10151. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10152. xPos += letters[i].l || 0;
  10153. // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10154. xPos += trackingOffset;
  10155. }
  10156. if (usesGlyphs) {
  10157. charData = this.globalData.fontManager.getCharData(
  10158. documentData.finalText[i],
  10159. fontData.fStyle,
  10160. this.globalData.fontManager.getFontByName(documentData.f).fFamily
  10161. );
  10162. var glyphElement;
  10163. // t === 1 means the character has been replaced with an animated shaped
  10164. if (charData.t === 1) {
  10165. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10166. } else {
  10167. var data = emptyShapeData;
  10168. if (charData.data && charData.data.shapes) {
  10169. data = this.buildShapeData(charData.data, documentData.finalSize);
  10170. }
  10171. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10172. }
  10173. if (this.textSpans[i].glyph) {
  10174. var glyph = this.textSpans[i].glyph;
  10175. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10176. glyph.destroy();
  10177. }
  10178. this.textSpans[i].glyph = glyphElement;
  10179. glyphElement._debug = true;
  10180. glyphElement.prepareFrame(0);
  10181. glyphElement.renderFrame();
  10182. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
  10183. // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10184. // this might have issues with strokes and might need a different solution
  10185. if (charData.t === 1) {
  10186. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10187. }
  10188. } else {
  10189. if (singleShape) {
  10190. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10191. }
  10192. tSpan.textContent = letters[i].val;
  10193. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10194. }
  10195. //
  10196. }
  10197. if (singleShape && tSpan) {
  10198. tSpan.setAttribute('d', shapeStr);
  10199. }
  10200. }
  10201. while (i < this.textSpans.length) {
  10202. this.textSpans[i].span.style.display = 'none';
  10203. i += 1;
  10204. }
  10205. this._sizeChanged = true;
  10206. };
  10207. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10208. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10209. this.renderInnerContent();
  10210. if (this._sizeChanged) {
  10211. this._sizeChanged = false;
  10212. var textBox = this.layerElement.getBBox();
  10213. this.bbox = {
  10214. top: textBox.y,
  10215. left: textBox.x,
  10216. width: textBox.width,
  10217. height: textBox.height,
  10218. };
  10219. }
  10220. return this.bbox;
  10221. };
  10222. SVGTextLottieElement.prototype.getValue = function () {
  10223. var i;
  10224. var len = this.textSpans.length;
  10225. var glyphElement;
  10226. this.renderedFrame = this.comp.renderedFrame;
  10227. for (i = 0; i < len; i += 1) {
  10228. glyphElement = this.textSpans[i].glyph;
  10229. if (glyphElement) {
  10230. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10231. if (glyphElement._mdf) {
  10232. this._mdf = true;
  10233. }
  10234. }
  10235. }
  10236. };
  10237. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10238. this.validateText();
  10239. if (!this.data.singleShape || this._mdf) {
  10240. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10241. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10242. this._sizeChanged = true;
  10243. var i;
  10244. var len;
  10245. var renderedLetters = this.textAnimator.renderedLetters;
  10246. var letters = this.textProperty.currentData.l;
  10247. len = letters.length;
  10248. var renderedLetter;
  10249. var textSpan;
  10250. var glyphElement;
  10251. for (i = 0; i < len; i += 1) {
  10252. if (!letters[i].n) {
  10253. renderedLetter = renderedLetters[i];
  10254. textSpan = this.textSpans[i].span;
  10255. glyphElement = this.textSpans[i].glyph;
  10256. if (glyphElement) {
  10257. glyphElement.renderFrame();
  10258. }
  10259. if (renderedLetter._mdf.m) {
  10260. textSpan.setAttribute('transform', renderedLetter.m);
  10261. }
  10262. if (renderedLetter._mdf.o) {
  10263. textSpan.setAttribute('opacity', renderedLetter.o);
  10264. }
  10265. if (renderedLetter._mdf.sw) {
  10266. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10267. }
  10268. if (renderedLetter._mdf.sc) {
  10269. textSpan.setAttribute('stroke', renderedLetter.sc);
  10270. }
  10271. if (renderedLetter._mdf.fc) {
  10272. textSpan.setAttribute('fill', renderedLetter.fc);
  10273. }
  10274. }
  10275. }
  10276. }
  10277. }
  10278. };
  10279. function ISolidElement(data, globalData, comp) {
  10280. this.initElement(data, globalData, comp);
  10281. }
  10282. extendPrototype([IImageElement], ISolidElement);
  10283. ISolidElement.prototype.createContent = function () {
  10284. var rect = createNS('rect');
  10285. /// /rect.style.width = this.data.sw;
  10286. /// /rect.style.height = this.data.sh;
  10287. /// /rect.style.fill = this.data.sc;
  10288. rect.setAttribute('width', this.data.sw);
  10289. rect.setAttribute('height', this.data.sh);
  10290. rect.setAttribute('fill', this.data.sc);
  10291. this.layerElement.appendChild(rect);
  10292. };
  10293. function NullElement(data, globalData, comp) {
  10294. this.initFrame();
  10295. this.initBaseData(data, globalData, comp);
  10296. this.initFrame();
  10297. this.initTransform(data, globalData, comp);
  10298. this.initHierarchy();
  10299. }
  10300. NullElement.prototype.prepareFrame = function (num) {
  10301. this.prepareProperties(num, true);
  10302. };
  10303. NullElement.prototype.renderFrame = function () {
  10304. };
  10305. NullElement.prototype.getBaseElement = function () {
  10306. return null;
  10307. };
  10308. NullElement.prototype.destroy = function () {
  10309. };
  10310. NullElement.prototype.sourceRectAtTime = function () {
  10311. };
  10312. NullElement.prototype.hide = function () {
  10313. };
  10314. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10315. function SVGRendererBase() {
  10316. }
  10317. extendPrototype([BaseRenderer], SVGRendererBase);
  10318. SVGRendererBase.prototype.createNull = function (data) {
  10319. return new NullElement(data, this.globalData, this);
  10320. };
  10321. SVGRendererBase.prototype.createShape = function (data) {
  10322. return new SVGShapeElement(data, this.globalData, this);
  10323. };
  10324. SVGRendererBase.prototype.createText = function (data) {
  10325. return new SVGTextLottieElement(data, this.globalData, this);
  10326. };
  10327. SVGRendererBase.prototype.createImage = function (data) {
  10328. return new IImageElement(data, this.globalData, this);
  10329. };
  10330. SVGRendererBase.prototype.createSolid = function (data) {
  10331. return new ISolidElement(data, this.globalData, this);
  10332. };
  10333. SVGRendererBase.prototype.configAnimation = function (animData) {
  10334. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10335. this.svgElement.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  10336. if (this.renderConfig.viewBoxSize) {
  10337. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10338. } else {
  10339. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10340. }
  10341. if (!this.renderConfig.viewBoxOnly) {
  10342. this.svgElement.setAttribute('width', animData.w);
  10343. this.svgElement.setAttribute('height', animData.h);
  10344. this.svgElement.style.width = '100%';
  10345. this.svgElement.style.height = '100%';
  10346. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10347. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10348. }
  10349. if (this.renderConfig.width) {
  10350. this.svgElement.setAttribute('width', this.renderConfig.width);
  10351. }
  10352. if (this.renderConfig.height) {
  10353. this.svgElement.setAttribute('height', this.renderConfig.height);
  10354. }
  10355. if (this.renderConfig.className) {
  10356. this.svgElement.setAttribute('class', this.renderConfig.className);
  10357. }
  10358. if (this.renderConfig.id) {
  10359. this.svgElement.setAttribute('id', this.renderConfig.id);
  10360. }
  10361. if (this.renderConfig.focusable !== undefined) {
  10362. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10363. }
  10364. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio);
  10365. // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10366. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10367. this.animationItem.wrapper.appendChild(this.svgElement);
  10368. // Mask animation
  10369. var defs = this.globalData.defs;
  10370. this.setupGlobalData(animData, defs);
  10371. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10372. this.data = animData;
  10373. var maskElement = createNS('clipPath');
  10374. var rect = createNS('rect');
  10375. rect.setAttribute('width', animData.w);
  10376. rect.setAttribute('height', animData.h);
  10377. rect.setAttribute('x', 0);
  10378. rect.setAttribute('y', 0);
  10379. var maskId = createElementID();
  10380. maskElement.setAttribute('id', maskId);
  10381. maskElement.appendChild(rect);
  10382. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10383. defs.appendChild(maskElement);
  10384. this.layers = animData.layers;
  10385. this.elements = createSizedArray(animData.layers.length);
  10386. };
  10387. SVGRendererBase.prototype.destroy = function () {
  10388. if (this.animationItem.wrapper) {
  10389. this.animationItem.wrapper.innerText = '';
  10390. }
  10391. this.layerElement = null;
  10392. this.globalData.defs = null;
  10393. var i;
  10394. var len = this.layers ? this.layers.length : 0;
  10395. for (i = 0; i < len; i += 1) {
  10396. if (this.elements[i] && this.elements[i].destroy) {
  10397. this.elements[i].destroy();
  10398. }
  10399. }
  10400. this.elements.length = 0;
  10401. this.destroyed = true;
  10402. this.animationItem = null;
  10403. };
  10404. SVGRendererBase.prototype.updateContainerSize = function () {
  10405. };
  10406. SVGRendererBase.prototype.findIndexByInd = function (ind) {
  10407. var i = 0;
  10408. var len = this.layers.length;
  10409. for (i = 0; i < len; i += 1) {
  10410. if (this.layers[i].ind === ind) {
  10411. return i;
  10412. }
  10413. }
  10414. return -1;
  10415. };
  10416. SVGRendererBase.prototype.buildItem = function (pos) {
  10417. var elements = this.elements;
  10418. if (elements[pos] || this.layers[pos].ty === 99) {
  10419. return;
  10420. }
  10421. elements[pos] = true;
  10422. var element = this.createItem(this.layers[pos]);
  10423. elements[pos] = element;
  10424. if (getExpressionsPlugin()) {
  10425. if (this.layers[pos].ty === 0) {
  10426. this.globalData.projectInterface.registerComposition(element);
  10427. }
  10428. element.initExpressions();
  10429. }
  10430. this.appendElementInPos(element, pos);
  10431. if (this.layers[pos].tt) {
  10432. var elementIndex = ('tp' in this.layers[pos])
  10433. ? this.findIndexByInd(this.layers[pos].tp)
  10434. : pos - 1;
  10435. if (elementIndex === -1) {
  10436. return;
  10437. }
  10438. if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
  10439. this.buildItem(elementIndex);
  10440. this.addPendingElement(element);
  10441. } else {
  10442. var matteElement = elements[elementIndex];
  10443. var matteMask = matteElement.getMatte(this.layers[pos].tt);
  10444. element.setMatte(matteMask);
  10445. }
  10446. }
  10447. };
  10448. SVGRendererBase.prototype.checkPendingElements = function () {
  10449. while (this.pendingElements.length) {
  10450. var element = this.pendingElements.pop();
  10451. element.checkParenting();
  10452. if (element.data.tt) {
  10453. var i = 0;
  10454. var len = this.elements.length;
  10455. while (i < len) {
  10456. if (this.elements[i] === element) {
  10457. var elementIndex = 'tp' in element.data
  10458. ? this.findIndexByInd(element.data.tp)
  10459. : i - 1;
  10460. var matteElement = this.elements[elementIndex];
  10461. var matteMask = matteElement.getMatte(this.layers[i].tt);
  10462. element.setMatte(matteMask);
  10463. break;
  10464. }
  10465. i += 1;
  10466. }
  10467. }
  10468. }
  10469. };
  10470. SVGRendererBase.prototype.renderFrame = function (num) {
  10471. if (this.renderedFrame === num || this.destroyed) {
  10472. return;
  10473. }
  10474. if (num === null) {
  10475. num = this.renderedFrame;
  10476. } else {
  10477. this.renderedFrame = num;
  10478. }
  10479. // console.log('-------');
  10480. // console.log('FRAME ',num);
  10481. this.globalData.frameNum = num;
  10482. this.globalData.frameId += 1;
  10483. this.globalData.projectInterface.currentFrame = num;
  10484. this.globalData._mdf = false;
  10485. var i;
  10486. var len = this.layers.length;
  10487. if (!this.completeLayers) {
  10488. this.checkLayers(num);
  10489. }
  10490. for (i = len - 1; i >= 0; i -= 1) {
  10491. if (this.completeLayers || this.elements[i]) {
  10492. this.elements[i].prepareFrame(num - this.layers[i].st);
  10493. }
  10494. }
  10495. if (this.globalData._mdf) {
  10496. for (i = 0; i < len; i += 1) {
  10497. if (this.completeLayers || this.elements[i]) {
  10498. this.elements[i].renderFrame();
  10499. }
  10500. }
  10501. }
  10502. };
  10503. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10504. var newElement = element.getBaseElement();
  10505. if (!newElement) {
  10506. return;
  10507. }
  10508. var i = 0;
  10509. var nextElement;
  10510. while (i < pos) {
  10511. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10512. nextElement = this.elements[i].getBaseElement();
  10513. }
  10514. i += 1;
  10515. }
  10516. if (nextElement) {
  10517. this.layerElement.insertBefore(newElement, nextElement);
  10518. } else {
  10519. this.layerElement.appendChild(newElement);
  10520. }
  10521. };
  10522. SVGRendererBase.prototype.hide = function () {
  10523. this.layerElement.style.display = 'none';
  10524. };
  10525. SVGRendererBase.prototype.show = function () {
  10526. this.layerElement.style.display = 'block';
  10527. };
  10528. function ICompElement() {}
  10529. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10530. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10531. this.initFrame();
  10532. this.initBaseData(data, globalData, comp);
  10533. this.initTransform(data, globalData, comp);
  10534. this.initRenderable();
  10535. this.initHierarchy();
  10536. this.initRendererElement();
  10537. this.createContainerElements();
  10538. this.createRenderableComponents();
  10539. if (this.data.xt || !globalData.progressiveLoad) {
  10540. this.buildAllItems();
  10541. }
  10542. this.hide();
  10543. };
  10544. /* ICompElement.prototype.hide = function(){
  10545. if(!this.hidden){
  10546. this.hideElement();
  10547. var i,len = this.elements.length;
  10548. for( i = 0; i < len; i+=1 ){
  10549. if(this.elements[i]){
  10550. this.elements[i].hide();
  10551. }
  10552. }
  10553. }
  10554. }; */
  10555. ICompElement.prototype.prepareFrame = function (num) {
  10556. this._mdf = false;
  10557. this.prepareRenderableFrame(num);
  10558. this.prepareProperties(num, this.isInRange);
  10559. if (!this.isInRange && !this.data.xt) {
  10560. return;
  10561. }
  10562. if (!this.tm._placeholder) {
  10563. var timeRemapped = this.tm.v;
  10564. if (timeRemapped === this.data.op) {
  10565. timeRemapped = this.data.op - 1;
  10566. }
  10567. this.renderedFrame = timeRemapped;
  10568. } else {
  10569. this.renderedFrame = num / this.data.sr;
  10570. }
  10571. var i;
  10572. var len = this.elements.length;
  10573. if (!this.completeLayers) {
  10574. this.checkLayers(this.renderedFrame);
  10575. }
  10576. // This iteration needs to be backwards because of how expressions connect between each other
  10577. for (i = len - 1; i >= 0; i -= 1) {
  10578. if (this.completeLayers || this.elements[i]) {
  10579. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10580. if (this.elements[i]._mdf) {
  10581. this._mdf = true;
  10582. }
  10583. }
  10584. }
  10585. };
  10586. ICompElement.prototype.renderInnerContent = function () {
  10587. var i;
  10588. var len = this.layers.length;
  10589. for (i = 0; i < len; i += 1) {
  10590. if (this.completeLayers || this.elements[i]) {
  10591. this.elements[i].renderFrame();
  10592. }
  10593. }
  10594. };
  10595. ICompElement.prototype.setElements = function (elems) {
  10596. this.elements = elems;
  10597. };
  10598. ICompElement.prototype.getElements = function () {
  10599. return this.elements;
  10600. };
  10601. ICompElement.prototype.destroyElements = function () {
  10602. var i;
  10603. var len = this.layers.length;
  10604. for (i = 0; i < len; i += 1) {
  10605. if (this.elements[i]) {
  10606. this.elements[i].destroy();
  10607. }
  10608. }
  10609. };
  10610. ICompElement.prototype.destroy = function () {
  10611. this.destroyElements();
  10612. this.destroyBaseElement();
  10613. };
  10614. function SVGCompElement(data, globalData, comp) {
  10615. this.layers = data.layers;
  10616. this.supports3d = true;
  10617. this.completeLayers = false;
  10618. this.pendingElements = [];
  10619. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10620. this.initElement(data, globalData, comp);
  10621. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  10622. }
  10623. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10624. SVGCompElement.prototype.createComp = function (data) {
  10625. return new SVGCompElement(data, this.globalData, this);
  10626. };
  10627. function SVGRenderer(animationItem, config) {
  10628. this.animationItem = animationItem;
  10629. this.layers = null;
  10630. this.renderedFrame = -1;
  10631. this.svgElement = createNS('svg');
  10632. var ariaLabel = '';
  10633. if (config && config.title) {
  10634. var titleElement = createNS('title');
  10635. var titleId = createElementID();
  10636. titleElement.setAttribute('id', titleId);
  10637. titleElement.textContent = config.title;
  10638. this.svgElement.appendChild(titleElement);
  10639. ariaLabel += titleId;
  10640. }
  10641. if (config && config.description) {
  10642. var descElement = createNS('desc');
  10643. var descId = createElementID();
  10644. descElement.setAttribute('id', descId);
  10645. descElement.textContent = config.description;
  10646. this.svgElement.appendChild(descElement);
  10647. ariaLabel += ' ' + descId;
  10648. }
  10649. if (ariaLabel) {
  10650. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10651. }
  10652. var defs = createNS('defs');
  10653. this.svgElement.appendChild(defs);
  10654. var maskElement = createNS('g');
  10655. this.svgElement.appendChild(maskElement);
  10656. this.layerElement = maskElement;
  10657. this.renderConfig = {
  10658. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  10659. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  10660. contentVisibility: (config && config.contentVisibility) || 'visible',
  10661. progressiveLoad: (config && config.progressiveLoad) || false,
  10662. hideOnTransparent: !((config && config.hideOnTransparent === false)),
  10663. viewBoxOnly: (config && config.viewBoxOnly) || false,
  10664. viewBoxSize: (config && config.viewBoxSize) || false,
  10665. className: (config && config.className) || '',
  10666. id: (config && config.id) || '',
  10667. focusable: config && config.focusable,
  10668. filterSize: {
  10669. width: (config && config.filterSize && config.filterSize.width) || '100%',
  10670. height: (config && config.filterSize && config.filterSize.height) || '100%',
  10671. x: (config && config.filterSize && config.filterSize.x) || '0%',
  10672. y: (config && config.filterSize && config.filterSize.y) || '0%',
  10673. },
  10674. width: (config && config.width),
  10675. height: (config && config.height),
  10676. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  10677. };
  10678. this.globalData = {
  10679. _mdf: false,
  10680. frameNum: -1,
  10681. defs: defs,
  10682. renderConfig: this.renderConfig,
  10683. };
  10684. this.elements = [];
  10685. this.pendingElements = [];
  10686. this.destroyed = false;
  10687. this.rendererType = 'svg';
  10688. }
  10689. extendPrototype([SVGRendererBase], SVGRenderer);
  10690. SVGRenderer.prototype.createComp = function (data) {
  10691. return new SVGCompElement(data, this.globalData, this);
  10692. };
  10693. var registeredEffects = {};
  10694. function CVEffects(elem) {
  10695. var i;
  10696. var len = elem.data.ef ? elem.data.ef.length : 0;
  10697. this.filters = [];
  10698. var filterManager;
  10699. for (i = 0; i < len; i += 1) {
  10700. filterManager = null;
  10701. var type = elem.data.ef[i].ty;
  10702. if (registeredEffects[type]) {
  10703. var Effect = registeredEffects[type].effect;
  10704. filterManager = new Effect(elem.effectsManager.effectElements[i], elem);
  10705. }
  10706. if (filterManager) {
  10707. this.filters.push(filterManager);
  10708. }
  10709. }
  10710. if (this.filters.length) {
  10711. elem.addRenderableComponent(this);
  10712. }
  10713. }
  10714. CVEffects.prototype.renderFrame = function (_isFirstFrame) {
  10715. var i;
  10716. var len = this.filters.length;
  10717. for (i = 0; i < len; i += 1) {
  10718. this.filters[i].renderFrame(_isFirstFrame);
  10719. }
  10720. };
  10721. CVEffects.prototype.getEffects = function (type) {
  10722. var i;
  10723. var len = this.filters.length;
  10724. var effects = [];
  10725. for (i = 0; i < len; i += 1) {
  10726. if (this.filters[i].type === type) {
  10727. effects.push(this.filters[i]);
  10728. }
  10729. }
  10730. return effects;
  10731. };
  10732. function registerEffect(id, effect) {
  10733. registeredEffects[id] = {
  10734. effect,
  10735. };
  10736. }
  10737. function HBaseElement() {}
  10738. HBaseElement.prototype = {
  10739. checkBlendMode: function () {},
  10740. initRendererElement: function () {
  10741. this.baseElement = createTag(this.data.tg || 'div');
  10742. if (this.data.hasMask) {
  10743. this.svgElement = createNS('svg');
  10744. this.layerElement = createNS('g');
  10745. this.maskedElement = this.layerElement;
  10746. this.svgElement.appendChild(this.layerElement);
  10747. this.baseElement.appendChild(this.svgElement);
  10748. } else {
  10749. this.layerElement = this.baseElement;
  10750. }
  10751. styleDiv(this.baseElement);
  10752. },
  10753. createContainerElements: function () {
  10754. this.renderableEffectsManager = new CVEffects(this);
  10755. this.transformedElement = this.baseElement;
  10756. this.maskedElement = this.layerElement;
  10757. if (this.data.ln) {
  10758. this.layerElement.setAttribute('id', this.data.ln);
  10759. }
  10760. if (this.data.cl) {
  10761. this.layerElement.setAttribute('class', this.data.cl);
  10762. }
  10763. if (this.data.bm !== 0) {
  10764. this.setBlendMode();
  10765. }
  10766. },
  10767. renderElement: function () {
  10768. var transformedElementStyle = this.transformedElement ? this.transformedElement.style : {};
  10769. if (this.finalTransform._matMdf) {
  10770. var matrixValue = this.finalTransform.mat.toCSS();
  10771. transformedElementStyle.transform = matrixValue;
  10772. transformedElementStyle.webkitTransform = matrixValue;
  10773. }
  10774. if (this.finalTransform._opMdf) {
  10775. transformedElementStyle.opacity = this.finalTransform.mProp.o.v;
  10776. }
  10777. },
  10778. renderFrame: function () {
  10779. // If it is exported as hidden (data.hd === true) no need to render
  10780. // If it is not visible no need to render
  10781. if (this.data.hd || this.hidden) {
  10782. return;
  10783. }
  10784. this.renderTransform();
  10785. this.renderRenderable();
  10786. this.renderElement();
  10787. this.renderInnerContent();
  10788. if (this._isFirstFrame) {
  10789. this._isFirstFrame = false;
  10790. }
  10791. },
  10792. destroy: function () {
  10793. this.layerElement = null;
  10794. this.transformedElement = null;
  10795. if (this.matteElement) {
  10796. this.matteElement = null;
  10797. }
  10798. if (this.maskManager) {
  10799. this.maskManager.destroy();
  10800. this.maskManager = null;
  10801. }
  10802. },
  10803. createRenderableComponents: function () {
  10804. this.maskManager = new MaskElement(this.data, this, this.globalData);
  10805. },
  10806. addEffects: function () {
  10807. },
  10808. setMatte: function () {},
  10809. };
  10810. HBaseElement.prototype.getBaseElement = SVGBaseElement.prototype.getBaseElement;
  10811. HBaseElement.prototype.destroyBaseElement = HBaseElement.prototype.destroy;
  10812. HBaseElement.prototype.buildElementParenting = BaseRenderer.prototype.buildElementParenting;
  10813. function HSolidElement(data, globalData, comp) {
  10814. this.initElement(data, globalData, comp);
  10815. }
  10816. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], HSolidElement);
  10817. HSolidElement.prototype.createContent = function () {
  10818. var rect;
  10819. if (this.data.hasMask) {
  10820. rect = createNS('rect');
  10821. rect.setAttribute('width', this.data.sw);
  10822. rect.setAttribute('height', this.data.sh);
  10823. rect.setAttribute('fill', this.data.sc);
  10824. this.svgElement.setAttribute('width', this.data.sw);
  10825. this.svgElement.setAttribute('height', this.data.sh);
  10826. } else {
  10827. rect = createTag('div');
  10828. rect.style.width = this.data.sw + 'px';
  10829. rect.style.height = this.data.sh + 'px';
  10830. rect.style.backgroundColor = this.data.sc;
  10831. }
  10832. this.layerElement.appendChild(rect);
  10833. };
  10834. function HShapeElement(data, globalData, comp) {
  10835. // List of drawable elements
  10836. this.shapes = [];
  10837. // Full shape data
  10838. this.shapesData = data.shapes;
  10839. // List of styles that will be applied to shapes
  10840. this.stylesList = [];
  10841. // List of modifiers that will be applied to shapes
  10842. this.shapeModifiers = [];
  10843. // List of items in shape tree
  10844. this.itemsData = [];
  10845. // List of items in previous shape tree
  10846. this.processedElements = [];
  10847. // List of animated components
  10848. this.animatedContents = [];
  10849. this.shapesContainer = createNS('g');
  10850. this.initElement(data, globalData, comp);
  10851. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  10852. // List of elements that have been created
  10853. this.prevViewData = [];
  10854. this.currentBBox = {
  10855. x: 999999,
  10856. y: -999999,
  10857. h: 0,
  10858. w: 0,
  10859. };
  10860. }
  10861. extendPrototype([BaseElement, TransformElement, HSolidElement, SVGShapeElement, HBaseElement, HierarchyElement, FrameElement, RenderableElement], HShapeElement);
  10862. HShapeElement.prototype._renderShapeFrame = HShapeElement.prototype.renderInnerContent;
  10863. HShapeElement.prototype.createContent = function () {
  10864. var cont;
  10865. this.baseElement.style.fontSize = 0;
  10866. if (this.data.hasMask) {
  10867. this.layerElement.appendChild(this.shapesContainer);
  10868. cont = this.svgElement;
  10869. } else {
  10870. cont = createNS('svg');
  10871. var size = this.comp.data ? this.comp.data : this.globalData.compSize;
  10872. cont.setAttribute('width', size.w);
  10873. cont.setAttribute('height', size.h);
  10874. cont.appendChild(this.shapesContainer);
  10875. this.layerElement.appendChild(cont);
  10876. }
  10877. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.shapesContainer, 0, [], true);
  10878. this.filterUniqueShapes();
  10879. this.shapeCont = cont;
  10880. };
  10881. HShapeElement.prototype.getTransformedPoint = function (transformers, point) {
  10882. var i;
  10883. var len = transformers.length;
  10884. for (i = 0; i < len; i += 1) {
  10885. point = transformers[i].mProps.v.applyToPointArray(point[0], point[1], 0);
  10886. }
  10887. return point;
  10888. };
  10889. HShapeElement.prototype.calculateShapeBoundingBox = function (item, boundingBox) {
  10890. var shape = item.sh.v;
  10891. var transformers = item.transformers;
  10892. var i;
  10893. var len = shape._length;
  10894. var vPoint;
  10895. var oPoint;
  10896. var nextIPoint;
  10897. var nextVPoint;
  10898. if (len <= 1) {
  10899. return;
  10900. }
  10901. for (i = 0; i < len - 1; i += 1) {
  10902. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  10903. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  10904. nextIPoint = this.getTransformedPoint(transformers, shape.i[i + 1]);
  10905. nextVPoint = this.getTransformedPoint(transformers, shape.v[i + 1]);
  10906. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  10907. }
  10908. if (shape.c) {
  10909. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  10910. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  10911. nextIPoint = this.getTransformedPoint(transformers, shape.i[0]);
  10912. nextVPoint = this.getTransformedPoint(transformers, shape.v[0]);
  10913. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  10914. }
  10915. };
  10916. HShapeElement.prototype.checkBounds = function (vPoint, oPoint, nextIPoint, nextVPoint, boundingBox) {
  10917. this.getBoundsOfCurve(vPoint, oPoint, nextIPoint, nextVPoint);
  10918. var bounds = this.shapeBoundingBox;
  10919. boundingBox.x = bmMin(bounds.left, boundingBox.x);
  10920. boundingBox.xMax = bmMax(bounds.right, boundingBox.xMax);
  10921. boundingBox.y = bmMin(bounds.top, boundingBox.y);
  10922. boundingBox.yMax = bmMax(bounds.bottom, boundingBox.yMax);
  10923. };
  10924. HShapeElement.prototype.shapeBoundingBox = {
  10925. left: 0,
  10926. right: 0,
  10927. top: 0,
  10928. bottom: 0,
  10929. };
  10930. HShapeElement.prototype.tempBoundingBox = {
  10931. x: 0,
  10932. xMax: 0,
  10933. y: 0,
  10934. yMax: 0,
  10935. width: 0,
  10936. height: 0,
  10937. };
  10938. HShapeElement.prototype.getBoundsOfCurve = function (p0, p1, p2, p3) {
  10939. var bounds = [[p0[0], p3[0]], [p0[1], p3[1]]];
  10940. for (var a, b, c, t, b2ac, t1, t2, i = 0; i < 2; ++i) { // eslint-disable-line no-plusplus
  10941. b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
  10942. a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
  10943. c = 3 * p1[i] - 3 * p0[i];
  10944. b |= 0; // eslint-disable-line no-bitwise
  10945. a |= 0; // eslint-disable-line no-bitwise
  10946. c |= 0; // eslint-disable-line no-bitwise
  10947. if (a === 0 && b === 0) {
  10948. //
  10949. } else if (a === 0) {
  10950. t = -c / b;
  10951. if (t > 0 && t < 1) {
  10952. bounds[i].push(this.calculateF(t, p0, p1, p2, p3, i));
  10953. }
  10954. } else {
  10955. b2ac = b * b - 4 * c * a;
  10956. if (b2ac >= 0) {
  10957. t1 = (-b + bmSqrt(b2ac)) / (2 * a);
  10958. if (t1 > 0 && t1 < 1) bounds[i].push(this.calculateF(t1, p0, p1, p2, p3, i));
  10959. t2 = (-b - bmSqrt(b2ac)) / (2 * a);
  10960. if (t2 > 0 && t2 < 1) bounds[i].push(this.calculateF(t2, p0, p1, p2, p3, i));
  10961. }
  10962. }
  10963. }
  10964. this.shapeBoundingBox.left = bmMin.apply(null, bounds[0]);
  10965. this.shapeBoundingBox.top = bmMin.apply(null, bounds[1]);
  10966. this.shapeBoundingBox.right = bmMax.apply(null, bounds[0]);
  10967. this.shapeBoundingBox.bottom = bmMax.apply(null, bounds[1]);
  10968. };
  10969. HShapeElement.prototype.calculateF = function (t, p0, p1, p2, p3, i) {
  10970. return bmPow(1 - t, 3) * p0[i]
  10971. + 3 * bmPow(1 - t, 2) * t * p1[i]
  10972. + 3 * (1 - t) * bmPow(t, 2) * p2[i]
  10973. + bmPow(t, 3) * p3[i];
  10974. };
  10975. HShapeElement.prototype.calculateBoundingBox = function (itemsData, boundingBox) {
  10976. var i;
  10977. var len = itemsData.length;
  10978. for (i = 0; i < len; i += 1) {
  10979. if (itemsData[i] && itemsData[i].sh) {
  10980. this.calculateShapeBoundingBox(itemsData[i], boundingBox);
  10981. } else if (itemsData[i] && itemsData[i].it) {
  10982. this.calculateBoundingBox(itemsData[i].it, boundingBox);
  10983. } else if (itemsData[i] && itemsData[i].style && itemsData[i].w) {
  10984. this.expandStrokeBoundingBox(itemsData[i].w, boundingBox);
  10985. }
  10986. }
  10987. };
  10988. HShapeElement.prototype.expandStrokeBoundingBox = function (widthProperty, boundingBox) {
  10989. var width = 0;
  10990. if (widthProperty.keyframes) {
  10991. for (var i = 0; i < widthProperty.keyframes.length; i += 1) {
  10992. var kfw = widthProperty.keyframes[i].s;
  10993. if (kfw > width) {
  10994. width = kfw;
  10995. }
  10996. }
  10997. width *= widthProperty.mult;
  10998. } else {
  10999. width = widthProperty.v * widthProperty.mult;
  11000. }
  11001. boundingBox.x -= width;
  11002. boundingBox.xMax += width;
  11003. boundingBox.y -= width;
  11004. boundingBox.yMax += width;
  11005. };
  11006. HShapeElement.prototype.currentBoxContains = function (box) {
  11007. return this.currentBBox.x <= box.x
  11008. && this.currentBBox.y <= box.y
  11009. && this.currentBBox.width + this.currentBBox.x >= box.x + box.width
  11010. && this.currentBBox.height + this.currentBBox.y >= box.y + box.height;
  11011. };
  11012. HShapeElement.prototype.renderInnerContent = function () {
  11013. this._renderShapeFrame();
  11014. if (!this.hidden && (this._isFirstFrame || this._mdf)) {
  11015. var tempBoundingBox = this.tempBoundingBox;
  11016. var max = 999999;
  11017. tempBoundingBox.x = max;
  11018. tempBoundingBox.xMax = -max;
  11019. tempBoundingBox.y = max;
  11020. tempBoundingBox.yMax = -max;
  11021. this.calculateBoundingBox(this.itemsData, tempBoundingBox);
  11022. tempBoundingBox.width = tempBoundingBox.xMax < tempBoundingBox.x ? 0 : tempBoundingBox.xMax - tempBoundingBox.x;
  11023. tempBoundingBox.height = tempBoundingBox.yMax < tempBoundingBox.y ? 0 : tempBoundingBox.yMax - tempBoundingBox.y;
  11024. // var tempBoundingBox = this.shapeCont.getBBox();
  11025. if (this.currentBoxContains(tempBoundingBox)) {
  11026. return;
  11027. }
  11028. var changed = false;
  11029. if (this.currentBBox.w !== tempBoundingBox.width) {
  11030. this.currentBBox.w = tempBoundingBox.width;
  11031. this.shapeCont.setAttribute('width', tempBoundingBox.width);
  11032. changed = true;
  11033. }
  11034. if (this.currentBBox.h !== tempBoundingBox.height) {
  11035. this.currentBBox.h = tempBoundingBox.height;
  11036. this.shapeCont.setAttribute('height', tempBoundingBox.height);
  11037. changed = true;
  11038. }
  11039. if (changed || this.currentBBox.x !== tempBoundingBox.x || this.currentBBox.y !== tempBoundingBox.y) {
  11040. this.currentBBox.w = tempBoundingBox.width;
  11041. this.currentBBox.h = tempBoundingBox.height;
  11042. this.currentBBox.x = tempBoundingBox.x;
  11043. this.currentBBox.y = tempBoundingBox.y;
  11044. this.shapeCont.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  11045. var shapeStyle = this.shapeCont.style;
  11046. var shapeTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  11047. shapeStyle.transform = shapeTransform;
  11048. shapeStyle.webkitTransform = shapeTransform;
  11049. }
  11050. }
  11051. };
  11052. function HTextElement(data, globalData, comp) {
  11053. this.textSpans = [];
  11054. this.textPaths = [];
  11055. this.currentBBox = {
  11056. x: 999999,
  11057. y: -999999,
  11058. h: 0,
  11059. w: 0,
  11060. };
  11061. this.renderType = 'svg';
  11062. this.isMasked = false;
  11063. this.initElement(data, globalData, comp);
  11064. }
  11065. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], HTextElement);
  11066. HTextElement.prototype.createContent = function () {
  11067. this.isMasked = this.checkMasks();
  11068. if (this.isMasked) {
  11069. this.renderType = 'svg';
  11070. this.compW = this.comp.data.w;
  11071. this.compH = this.comp.data.h;
  11072. this.svgElement.setAttribute('width', this.compW);
  11073. this.svgElement.setAttribute('height', this.compH);
  11074. var g = createNS('g');
  11075. this.maskedElement.appendChild(g);
  11076. this.innerElem = g;
  11077. } else {
  11078. this.renderType = 'html';
  11079. this.innerElem = this.layerElement;
  11080. }
  11081. this.checkParenting();
  11082. };
  11083. HTextElement.prototype.buildNewText = function () {
  11084. var documentData = this.textProperty.currentData;
  11085. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  11086. var innerElemStyle = this.innerElem.style;
  11087. var textColor = documentData.fc ? this.buildColor(documentData.fc) : 'rgba(0,0,0,0)';
  11088. innerElemStyle.fill = textColor;
  11089. innerElemStyle.color = textColor;
  11090. if (documentData.sc) {
  11091. innerElemStyle.stroke = this.buildColor(documentData.sc);
  11092. innerElemStyle.strokeWidth = documentData.sw + 'px';
  11093. }
  11094. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  11095. if (!this.globalData.fontManager.chars) {
  11096. innerElemStyle.fontSize = documentData.finalSize + 'px';
  11097. innerElemStyle.lineHeight = documentData.finalSize + 'px';
  11098. if (fontData.fClass) {
  11099. this.innerElem.className = fontData.fClass;
  11100. } else {
  11101. innerElemStyle.fontFamily = fontData.fFamily;
  11102. var fWeight = documentData.fWeight;
  11103. var fStyle = documentData.fStyle;
  11104. innerElemStyle.fontStyle = fStyle;
  11105. innerElemStyle.fontWeight = fWeight;
  11106. }
  11107. }
  11108. var i;
  11109. var len;
  11110. var letters = documentData.l;
  11111. len = letters.length;
  11112. var tSpan;
  11113. var tParent;
  11114. var tCont;
  11115. var matrixHelper = this.mHelper;
  11116. var shapes;
  11117. var shapeStr = '';
  11118. var cnt = 0;
  11119. for (i = 0; i < len; i += 1) {
  11120. if (this.globalData.fontManager.chars) {
  11121. if (!this.textPaths[cnt]) {
  11122. tSpan = createNS('path');
  11123. tSpan.setAttribute('stroke-linecap', lineCapEnum[1]);
  11124. tSpan.setAttribute('stroke-linejoin', lineJoinEnum[2]);
  11125. tSpan.setAttribute('stroke-miterlimit', '4');
  11126. } else {
  11127. tSpan = this.textPaths[cnt];
  11128. }
  11129. if (!this.isMasked) {
  11130. if (this.textSpans[cnt]) {
  11131. tParent = this.textSpans[cnt];
  11132. tCont = tParent.children[0];
  11133. } else {
  11134. tParent = createTag('div');
  11135. tParent.style.lineHeight = 0;
  11136. tCont = createNS('svg');
  11137. tCont.appendChild(tSpan);
  11138. styleDiv(tParent);
  11139. }
  11140. }
  11141. } else if (!this.isMasked) {
  11142. if (this.textSpans[cnt]) {
  11143. tParent = this.textSpans[cnt];
  11144. tSpan = this.textPaths[cnt];
  11145. } else {
  11146. tParent = createTag('span');
  11147. styleDiv(tParent);
  11148. tSpan = createTag('span');
  11149. styleDiv(tSpan);
  11150. tParent.appendChild(tSpan);
  11151. }
  11152. } else {
  11153. tSpan = this.textPaths[cnt] ? this.textPaths[cnt] : createNS('text');
  11154. }
  11155. // tSpan.setAttribute('visibility', 'hidden');
  11156. if (this.globalData.fontManager.chars) {
  11157. var charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  11158. var shapeData;
  11159. if (charData) {
  11160. shapeData = charData.data;
  11161. } else {
  11162. shapeData = null;
  11163. }
  11164. matrixHelper.reset();
  11165. if (shapeData && shapeData.shapes && shapeData.shapes.length) {
  11166. shapes = shapeData.shapes[0].it;
  11167. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  11168. shapeStr = this.createPathShape(matrixHelper, shapes);
  11169. tSpan.setAttribute('d', shapeStr);
  11170. }
  11171. if (!this.isMasked) {
  11172. this.innerElem.appendChild(tParent);
  11173. if (shapeData && shapeData.shapes) {
  11174. // document.body.appendChild is needed to get exact measure of shape
  11175. document.body.appendChild(tCont);
  11176. var boundingBox = tCont.getBBox();
  11177. tCont.setAttribute('width', boundingBox.width + 2);
  11178. tCont.setAttribute('height', boundingBox.height + 2);
  11179. tCont.setAttribute('viewBox', (boundingBox.x - 1) + ' ' + (boundingBox.y - 1) + ' ' + (boundingBox.width + 2) + ' ' + (boundingBox.height + 2));
  11180. var tContStyle = tCont.style;
  11181. var tContTranslation = 'translate(' + (boundingBox.x - 1) + 'px,' + (boundingBox.y - 1) + 'px)';
  11182. tContStyle.transform = tContTranslation;
  11183. tContStyle.webkitTransform = tContTranslation;
  11184. letters[i].yOffset = boundingBox.y - 1;
  11185. } else {
  11186. tCont.setAttribute('width', 1);
  11187. tCont.setAttribute('height', 1);
  11188. }
  11189. tParent.appendChild(tCont);
  11190. } else {
  11191. this.innerElem.appendChild(tSpan);
  11192. }
  11193. } else {
  11194. tSpan.textContent = letters[i].val;
  11195. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  11196. if (!this.isMasked) {
  11197. this.innerElem.appendChild(tParent);
  11198. //
  11199. var tStyle = tSpan.style;
  11200. var tSpanTranslation = 'translate3d(0,' + -documentData.finalSize / 1.2 + 'px,0)';
  11201. tStyle.transform = tSpanTranslation;
  11202. tStyle.webkitTransform = tSpanTranslation;
  11203. } else {
  11204. this.innerElem.appendChild(tSpan);
  11205. }
  11206. }
  11207. //
  11208. if (!this.isMasked) {
  11209. this.textSpans[cnt] = tParent;
  11210. } else {
  11211. this.textSpans[cnt] = tSpan;
  11212. }
  11213. this.textSpans[cnt].style.display = 'block';
  11214. this.textPaths[cnt] = tSpan;
  11215. cnt += 1;
  11216. }
  11217. while (cnt < this.textSpans.length) {
  11218. this.textSpans[cnt].style.display = 'none';
  11219. cnt += 1;
  11220. }
  11221. };
  11222. HTextElement.prototype.renderInnerContent = function () {
  11223. this.validateText();
  11224. var svgStyle;
  11225. if (this.data.singleShape) {
  11226. if (!this._isFirstFrame && !this.lettersChangedFlag) {
  11227. return;
  11228. } if (this.isMasked && this.finalTransform._matMdf) {
  11229. // Todo Benchmark if using this is better than getBBox
  11230. this.svgElement.setAttribute('viewBox', -this.finalTransform.mProp.p.v[0] + ' ' + -this.finalTransform.mProp.p.v[1] + ' ' + this.compW + ' ' + this.compH);
  11231. svgStyle = this.svgElement.style;
  11232. var translation = 'translate(' + -this.finalTransform.mProp.p.v[0] + 'px,' + -this.finalTransform.mProp.p.v[1] + 'px)';
  11233. svgStyle.transform = translation;
  11234. svgStyle.webkitTransform = translation;
  11235. }
  11236. }
  11237. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  11238. if (!this.lettersChangedFlag && !this.textAnimator.lettersChangedFlag) {
  11239. return;
  11240. }
  11241. var i;
  11242. var len;
  11243. var count = 0;
  11244. var renderedLetters = this.textAnimator.renderedLetters;
  11245. var letters = this.textProperty.currentData.l;
  11246. len = letters.length;
  11247. var renderedLetter;
  11248. var textSpan;
  11249. var textPath;
  11250. for (i = 0; i < len; i += 1) {
  11251. if (letters[i].n) {
  11252. count += 1;
  11253. } else {
  11254. textSpan = this.textSpans[i];
  11255. textPath = this.textPaths[i];
  11256. renderedLetter = renderedLetters[count];
  11257. count += 1;
  11258. if (renderedLetter._mdf.m) {
  11259. if (!this.isMasked) {
  11260. textSpan.style.webkitTransform = renderedLetter.m;
  11261. textSpan.style.transform = renderedLetter.m;
  11262. } else {
  11263. textSpan.setAttribute('transform', renderedLetter.m);
  11264. }
  11265. }
  11266. /// /textSpan.setAttribute('opacity',renderedLetter.o);
  11267. textSpan.style.opacity = renderedLetter.o;
  11268. if (renderedLetter.sw && renderedLetter._mdf.sw) {
  11269. textPath.setAttribute('stroke-width', renderedLetter.sw);
  11270. }
  11271. if (renderedLetter.sc && renderedLetter._mdf.sc) {
  11272. textPath.setAttribute('stroke', renderedLetter.sc);
  11273. }
  11274. if (renderedLetter.fc && renderedLetter._mdf.fc) {
  11275. textPath.setAttribute('fill', renderedLetter.fc);
  11276. textPath.style.color = renderedLetter.fc;
  11277. }
  11278. }
  11279. }
  11280. if (this.innerElem.getBBox && !this.hidden && (this._isFirstFrame || this._mdf)) {
  11281. var boundingBox = this.innerElem.getBBox();
  11282. if (this.currentBBox.w !== boundingBox.width) {
  11283. this.currentBBox.w = boundingBox.width;
  11284. this.svgElement.setAttribute('width', boundingBox.width);
  11285. }
  11286. if (this.currentBBox.h !== boundingBox.height) {
  11287. this.currentBBox.h = boundingBox.height;
  11288. this.svgElement.setAttribute('height', boundingBox.height);
  11289. }
  11290. var margin = 1;
  11291. 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)) {
  11292. this.currentBBox.w = boundingBox.width + margin * 2;
  11293. this.currentBBox.h = boundingBox.height + margin * 2;
  11294. this.currentBBox.x = boundingBox.x - margin;
  11295. this.currentBBox.y = boundingBox.y - margin;
  11296. this.svgElement.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  11297. svgStyle = this.svgElement.style;
  11298. var svgTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  11299. svgStyle.transform = svgTransform;
  11300. svgStyle.webkitTransform = svgTransform;
  11301. }
  11302. }
  11303. };
  11304. function HCameraElement(data, globalData, comp) {
  11305. this.initFrame();
  11306. this.initBaseData(data, globalData, comp);
  11307. this.initHierarchy();
  11308. var getProp = PropertyFactory.getProp;
  11309. this.pe = getProp(this, data.pe, 0, 0, this);
  11310. if (data.ks.p.s) {
  11311. this.px = getProp(this, data.ks.p.x, 1, 0, this);
  11312. this.py = getProp(this, data.ks.p.y, 1, 0, this);
  11313. this.pz = getProp(this, data.ks.p.z, 1, 0, this);
  11314. } else {
  11315. this.p = getProp(this, data.ks.p, 1, 0, this);
  11316. }
  11317. if (data.ks.a) {
  11318. this.a = getProp(this, data.ks.a, 1, 0, this);
  11319. }
  11320. if (data.ks.or.k.length && data.ks.or.k[0].to) {
  11321. var i;
  11322. var len = data.ks.or.k.length;
  11323. for (i = 0; i < len; i += 1) {
  11324. data.ks.or.k[i].to = null;
  11325. data.ks.or.k[i].ti = null;
  11326. }
  11327. }
  11328. this.or = getProp(this, data.ks.or, 1, degToRads, this);
  11329. this.or.sh = true;
  11330. this.rx = getProp(this, data.ks.rx, 0, degToRads, this);
  11331. this.ry = getProp(this, data.ks.ry, 0, degToRads, this);
  11332. this.rz = getProp(this, data.ks.rz, 0, degToRads, this);
  11333. this.mat = new Matrix();
  11334. this._prevMat = new Matrix();
  11335. this._isFirstFrame = true;
  11336. // TODO: find a better way to make the HCamera element to be compatible with the LayerInterface and TransformInterface.
  11337. this.finalTransform = {
  11338. mProp: this,
  11339. };
  11340. }
  11341. extendPrototype([BaseElement, FrameElement, HierarchyElement], HCameraElement);
  11342. HCameraElement.prototype.setup = function () {
  11343. var i;
  11344. var len = this.comp.threeDElements.length;
  11345. var comp;
  11346. var perspectiveStyle;
  11347. var containerStyle;
  11348. for (i = 0; i < len; i += 1) {
  11349. // [perspectiveElem,container]
  11350. comp = this.comp.threeDElements[i];
  11351. if (comp.type === '3d') {
  11352. perspectiveStyle = comp.perspectiveElem.style;
  11353. containerStyle = comp.container.style;
  11354. var perspective = this.pe.v + 'px';
  11355. var origin = '0px 0px 0px';
  11356. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  11357. perspectiveStyle.perspective = perspective;
  11358. perspectiveStyle.webkitPerspective = perspective;
  11359. containerStyle.transformOrigin = origin;
  11360. containerStyle.mozTransformOrigin = origin;
  11361. containerStyle.webkitTransformOrigin = origin;
  11362. perspectiveStyle.transform = matrix;
  11363. perspectiveStyle.webkitTransform = matrix;
  11364. }
  11365. }
  11366. };
  11367. HCameraElement.prototype.createElements = function () {
  11368. };
  11369. HCameraElement.prototype.hide = function () {
  11370. };
  11371. HCameraElement.prototype.renderFrame = function () {
  11372. var _mdf = this._isFirstFrame;
  11373. var i;
  11374. var len;
  11375. if (this.hierarchy) {
  11376. len = this.hierarchy.length;
  11377. for (i = 0; i < len; i += 1) {
  11378. _mdf = this.hierarchy[i].finalTransform.mProp._mdf || _mdf;
  11379. }
  11380. }
  11381. 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)) {
  11382. this.mat.reset();
  11383. if (this.hierarchy) {
  11384. len = this.hierarchy.length - 1;
  11385. for (i = len; i >= 0; i -= 1) {
  11386. var mTransf = this.hierarchy[i].finalTransform.mProp;
  11387. this.mat.translate(-mTransf.p.v[0], -mTransf.p.v[1], mTransf.p.v[2]);
  11388. this.mat.rotateX(-mTransf.or.v[0]).rotateY(-mTransf.or.v[1]).rotateZ(mTransf.or.v[2]);
  11389. this.mat.rotateX(-mTransf.rx.v).rotateY(-mTransf.ry.v).rotateZ(mTransf.rz.v);
  11390. this.mat.scale(1 / mTransf.s.v[0], 1 / mTransf.s.v[1], 1 / mTransf.s.v[2]);
  11391. this.mat.translate(mTransf.a.v[0], mTransf.a.v[1], mTransf.a.v[2]);
  11392. }
  11393. }
  11394. if (this.p) {
  11395. this.mat.translate(-this.p.v[0], -this.p.v[1], this.p.v[2]);
  11396. } else {
  11397. this.mat.translate(-this.px.v, -this.py.v, this.pz.v);
  11398. }
  11399. if (this.a) {
  11400. var diffVector;
  11401. if (this.p) {
  11402. 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]];
  11403. } else {
  11404. diffVector = [this.px.v - this.a.v[0], this.py.v - this.a.v[1], this.pz.v - this.a.v[2]];
  11405. }
  11406. var mag = Math.sqrt(Math.pow(diffVector[0], 2) + Math.pow(diffVector[1], 2) + Math.pow(diffVector[2], 2));
  11407. // var lookDir = getNormalizedPoint(getDiffVector(this.a.v,this.p.v));
  11408. var lookDir = [diffVector[0] / mag, diffVector[1] / mag, diffVector[2] / mag];
  11409. var lookLengthOnXZ = Math.sqrt(lookDir[2] * lookDir[2] + lookDir[0] * lookDir[0]);
  11410. var mRotationX = (Math.atan2(lookDir[1], lookLengthOnXZ));
  11411. var mRotationY = (Math.atan2(lookDir[0], -lookDir[2]));
  11412. this.mat.rotateY(mRotationY).rotateX(-mRotationX);
  11413. }
  11414. this.mat.rotateX(-this.rx.v).rotateY(-this.ry.v).rotateZ(this.rz.v);
  11415. this.mat.rotateX(-this.or.v[0]).rotateY(-this.or.v[1]).rotateZ(this.or.v[2]);
  11416. this.mat.translate(this.globalData.compSize.w / 2, this.globalData.compSize.h / 2, 0);
  11417. this.mat.translate(0, 0, this.pe.v);
  11418. var hasMatrixChanged = !this._prevMat.equals(this.mat);
  11419. if ((hasMatrixChanged || this.pe._mdf) && this.comp.threeDElements) {
  11420. len = this.comp.threeDElements.length;
  11421. var comp;
  11422. var perspectiveStyle;
  11423. var containerStyle;
  11424. for (i = 0; i < len; i += 1) {
  11425. comp = this.comp.threeDElements[i];
  11426. if (comp.type === '3d') {
  11427. if (hasMatrixChanged) {
  11428. var matValue = this.mat.toCSS();
  11429. containerStyle = comp.container.style;
  11430. containerStyle.transform = matValue;
  11431. containerStyle.webkitTransform = matValue;
  11432. }
  11433. if (this.pe._mdf) {
  11434. perspectiveStyle = comp.perspectiveElem.style;
  11435. perspectiveStyle.perspective = this.pe.v + 'px';
  11436. perspectiveStyle.webkitPerspective = this.pe.v + 'px';
  11437. }
  11438. }
  11439. }
  11440. this.mat.clone(this._prevMat);
  11441. }
  11442. }
  11443. this._isFirstFrame = false;
  11444. };
  11445. HCameraElement.prototype.prepareFrame = function (num) {
  11446. this.prepareProperties(num, true);
  11447. };
  11448. HCameraElement.prototype.destroy = function () {
  11449. };
  11450. HCameraElement.prototype.getBaseElement = function () { return null; };
  11451. function HImageElement(data, globalData, comp) {
  11452. this.assetData = globalData.getAssetData(data.refId);
  11453. this.initElement(data, globalData, comp);
  11454. }
  11455. extendPrototype([BaseElement, TransformElement, HBaseElement, HSolidElement, HierarchyElement, FrameElement, RenderableElement], HImageElement);
  11456. HImageElement.prototype.createContent = function () {
  11457. var assetPath = this.globalData.getAssetsPath(this.assetData);
  11458. var img = new Image();
  11459. if (this.data.hasMask) {
  11460. this.imageElem = createNS('image');
  11461. this.imageElem.setAttribute('width', this.assetData.w + 'px');
  11462. this.imageElem.setAttribute('height', this.assetData.h + 'px');
  11463. this.imageElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  11464. this.layerElement.appendChild(this.imageElem);
  11465. this.baseElement.setAttribute('width', this.assetData.w);
  11466. this.baseElement.setAttribute('height', this.assetData.h);
  11467. } else {
  11468. this.layerElement.appendChild(img);
  11469. }
  11470. img.crossOrigin = 'anonymous';
  11471. img.src = assetPath;
  11472. if (this.data.ln) {
  11473. this.baseElement.setAttribute('id', this.data.ln);
  11474. }
  11475. };
  11476. function HybridRendererBase(animationItem, config) {
  11477. this.animationItem = animationItem;
  11478. this.layers = null;
  11479. this.renderedFrame = -1;
  11480. this.renderConfig = {
  11481. className: (config && config.className) || '',
  11482. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  11483. hideOnTransparent: !(config && config.hideOnTransparent === false),
  11484. filterSize: {
  11485. width: (config && config.filterSize && config.filterSize.width) || '400%',
  11486. height: (config && config.filterSize && config.filterSize.height) || '400%',
  11487. x: (config && config.filterSize && config.filterSize.x) || '-100%',
  11488. y: (config && config.filterSize && config.filterSize.y) || '-100%',
  11489. },
  11490. };
  11491. this.globalData = {
  11492. _mdf: false,
  11493. frameNum: -1,
  11494. renderConfig: this.renderConfig,
  11495. };
  11496. this.pendingElements = [];
  11497. this.elements = [];
  11498. this.threeDElements = [];
  11499. this.destroyed = false;
  11500. this.camera = null;
  11501. this.supports3d = true;
  11502. this.rendererType = 'html';
  11503. }
  11504. extendPrototype([BaseRenderer], HybridRendererBase);
  11505. HybridRendererBase.prototype.buildItem = SVGRenderer.prototype.buildItem;
  11506. HybridRendererBase.prototype.checkPendingElements = function () {
  11507. while (this.pendingElements.length) {
  11508. var element = this.pendingElements.pop();
  11509. element.checkParenting();
  11510. }
  11511. };
  11512. HybridRendererBase.prototype.appendElementInPos = function (element, pos) {
  11513. var newDOMElement = element.getBaseElement();
  11514. if (!newDOMElement) {
  11515. return;
  11516. }
  11517. var layer = this.layers[pos];
  11518. if (!layer.ddd || !this.supports3d) {
  11519. if (this.threeDElements) {
  11520. this.addTo3dContainer(newDOMElement, pos);
  11521. } else {
  11522. var i = 0;
  11523. var nextDOMElement;
  11524. var nextLayer;
  11525. var tmpDOMElement;
  11526. while (i < pos) {
  11527. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement) {
  11528. nextLayer = this.elements[i];
  11529. tmpDOMElement = this.layers[i].ddd ? this.getThreeDContainerByPos(i) : nextLayer.getBaseElement();
  11530. nextDOMElement = tmpDOMElement || nextDOMElement;
  11531. }
  11532. i += 1;
  11533. }
  11534. if (nextDOMElement) {
  11535. if (!layer.ddd || !this.supports3d) {
  11536. this.layerElement.insertBefore(newDOMElement, nextDOMElement);
  11537. }
  11538. } else if (!layer.ddd || !this.supports3d) {
  11539. this.layerElement.appendChild(newDOMElement);
  11540. }
  11541. }
  11542. } else {
  11543. this.addTo3dContainer(newDOMElement, pos);
  11544. }
  11545. };
  11546. HybridRendererBase.prototype.createShape = function (data) {
  11547. if (!this.supports3d) {
  11548. return new SVGShapeElement(data, this.globalData, this);
  11549. }
  11550. return new HShapeElement(data, this.globalData, this);
  11551. };
  11552. HybridRendererBase.prototype.createText = function (data) {
  11553. if (!this.supports3d) {
  11554. return new SVGTextLottieElement(data, this.globalData, this);
  11555. }
  11556. return new HTextElement(data, this.globalData, this);
  11557. };
  11558. HybridRendererBase.prototype.createCamera = function (data) {
  11559. this.camera = new HCameraElement(data, this.globalData, this);
  11560. return this.camera;
  11561. };
  11562. HybridRendererBase.prototype.createImage = function (data) {
  11563. if (!this.supports3d) {
  11564. return new IImageElement(data, this.globalData, this);
  11565. }
  11566. return new HImageElement(data, this.globalData, this);
  11567. };
  11568. HybridRendererBase.prototype.createSolid = function (data) {
  11569. if (!this.supports3d) {
  11570. return new ISolidElement(data, this.globalData, this);
  11571. }
  11572. return new HSolidElement(data, this.globalData, this);
  11573. };
  11574. HybridRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  11575. HybridRendererBase.prototype.getThreeDContainerByPos = function (pos) {
  11576. var i = 0;
  11577. var len = this.threeDElements.length;
  11578. while (i < len) {
  11579. if (this.threeDElements[i].startPos <= pos && this.threeDElements[i].endPos >= pos) {
  11580. return this.threeDElements[i].perspectiveElem;
  11581. }
  11582. i += 1;
  11583. }
  11584. return null;
  11585. };
  11586. HybridRendererBase.prototype.createThreeDContainer = function (pos, type) {
  11587. var perspectiveElem = createTag('div');
  11588. var style;
  11589. var containerStyle;
  11590. styleDiv(perspectiveElem);
  11591. var container = createTag('div');
  11592. styleDiv(container);
  11593. if (type === '3d') {
  11594. style = perspectiveElem.style;
  11595. style.width = this.globalData.compSize.w + 'px';
  11596. style.height = this.globalData.compSize.h + 'px';
  11597. var center = '50% 50%';
  11598. style.webkitTransformOrigin = center;
  11599. style.mozTransformOrigin = center;
  11600. style.transformOrigin = center;
  11601. containerStyle = container.style;
  11602. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  11603. containerStyle.transform = matrix;
  11604. containerStyle.webkitTransform = matrix;
  11605. }
  11606. perspectiveElem.appendChild(container);
  11607. // this.resizerElem.appendChild(perspectiveElem);
  11608. var threeDContainerData = {
  11609. container: container,
  11610. perspectiveElem: perspectiveElem,
  11611. startPos: pos,
  11612. endPos: pos,
  11613. type: type,
  11614. };
  11615. this.threeDElements.push(threeDContainerData);
  11616. return threeDContainerData;
  11617. };
  11618. HybridRendererBase.prototype.build3dContainers = function () {
  11619. var i;
  11620. var len = this.layers.length;
  11621. var lastThreeDContainerData;
  11622. var currentContainer = '';
  11623. for (i = 0; i < len; i += 1) {
  11624. if (this.layers[i].ddd && this.layers[i].ty !== 3) {
  11625. if (currentContainer !== '3d') {
  11626. currentContainer = '3d';
  11627. lastThreeDContainerData = this.createThreeDContainer(i, '3d');
  11628. }
  11629. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  11630. } else {
  11631. if (currentContainer !== '2d') {
  11632. currentContainer = '2d';
  11633. lastThreeDContainerData = this.createThreeDContainer(i, '2d');
  11634. }
  11635. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  11636. }
  11637. }
  11638. len = this.threeDElements.length;
  11639. for (i = len - 1; i >= 0; i -= 1) {
  11640. this.resizerElem.appendChild(this.threeDElements[i].perspectiveElem);
  11641. }
  11642. };
  11643. HybridRendererBase.prototype.addTo3dContainer = function (elem, pos) {
  11644. var i = 0;
  11645. var len = this.threeDElements.length;
  11646. while (i < len) {
  11647. if (pos <= this.threeDElements[i].endPos) {
  11648. var j = this.threeDElements[i].startPos;
  11649. var nextElement;
  11650. while (j < pos) {
  11651. if (this.elements[j] && this.elements[j].getBaseElement) {
  11652. nextElement = this.elements[j].getBaseElement();
  11653. }
  11654. j += 1;
  11655. }
  11656. if (nextElement) {
  11657. this.threeDElements[i].container.insertBefore(elem, nextElement);
  11658. } else {
  11659. this.threeDElements[i].container.appendChild(elem);
  11660. }
  11661. break;
  11662. }
  11663. i += 1;
  11664. }
  11665. };
  11666. HybridRendererBase.prototype.configAnimation = function (animData) {
  11667. var resizerElem = createTag('div');
  11668. var wrapper = this.animationItem.wrapper;
  11669. var style = resizerElem.style;
  11670. style.width = animData.w + 'px';
  11671. style.height = animData.h + 'px';
  11672. this.resizerElem = resizerElem;
  11673. styleDiv(resizerElem);
  11674. style.transformStyle = 'flat';
  11675. style.mozTransformStyle = 'flat';
  11676. style.webkitTransformStyle = 'flat';
  11677. if (this.renderConfig.className) {
  11678. resizerElem.setAttribute('class', this.renderConfig.className);
  11679. }
  11680. wrapper.appendChild(resizerElem);
  11681. style.overflow = 'hidden';
  11682. var svg = createNS('svg');
  11683. svg.setAttribute('width', '1');
  11684. svg.setAttribute('height', '1');
  11685. styleDiv(svg);
  11686. this.resizerElem.appendChild(svg);
  11687. var defs = createNS('defs');
  11688. svg.appendChild(defs);
  11689. this.data = animData;
  11690. // Mask animation
  11691. this.setupGlobalData(animData, svg);
  11692. this.globalData.defs = defs;
  11693. this.layers = animData.layers;
  11694. this.layerElement = this.resizerElem;
  11695. this.build3dContainers();
  11696. this.updateContainerSize();
  11697. };
  11698. HybridRendererBase.prototype.destroy = function () {
  11699. if (this.animationItem.wrapper) {
  11700. this.animationItem.wrapper.innerText = '';
  11701. }
  11702. this.animationItem.container = null;
  11703. this.globalData.defs = null;
  11704. var i;
  11705. var len = this.layers ? this.layers.length : 0;
  11706. for (i = 0; i < len; i += 1) {
  11707. if (this.elements[i] && this.elements[i].destroy) {
  11708. this.elements[i].destroy();
  11709. }
  11710. }
  11711. this.elements.length = 0;
  11712. this.destroyed = true;
  11713. this.animationItem = null;
  11714. };
  11715. HybridRendererBase.prototype.updateContainerSize = function () {
  11716. var elementWidth = this.animationItem.wrapper.offsetWidth;
  11717. var elementHeight = this.animationItem.wrapper.offsetHeight;
  11718. var elementRel = elementWidth / elementHeight;
  11719. var animationRel = this.globalData.compSize.w / this.globalData.compSize.h;
  11720. var sx;
  11721. var sy;
  11722. var tx;
  11723. var ty;
  11724. if (animationRel > elementRel) {
  11725. sx = elementWidth / (this.globalData.compSize.w);
  11726. sy = elementWidth / (this.globalData.compSize.w);
  11727. tx = 0;
  11728. ty = ((elementHeight - this.globalData.compSize.h * (elementWidth / this.globalData.compSize.w)) / 2);
  11729. } else {
  11730. sx = elementHeight / (this.globalData.compSize.h);
  11731. sy = elementHeight / (this.globalData.compSize.h);
  11732. tx = (elementWidth - this.globalData.compSize.w * (elementHeight / this.globalData.compSize.h)) / 2;
  11733. ty = 0;
  11734. }
  11735. var style = this.resizerElem.style;
  11736. style.webkitTransform = 'matrix3d(' + sx + ',0,0,0,0,' + sy + ',0,0,0,0,1,0,' + tx + ',' + ty + ',0,1)';
  11737. style.transform = style.webkitTransform;
  11738. };
  11739. HybridRendererBase.prototype.renderFrame = SVGRenderer.prototype.renderFrame;
  11740. HybridRendererBase.prototype.hide = function () {
  11741. this.resizerElem.style.display = 'none';
  11742. };
  11743. HybridRendererBase.prototype.show = function () {
  11744. this.resizerElem.style.display = 'block';
  11745. };
  11746. HybridRendererBase.prototype.initItems = function () {
  11747. this.buildAllItems();
  11748. if (this.camera) {
  11749. this.camera.setup();
  11750. } else {
  11751. var cWidth = this.globalData.compSize.w;
  11752. var cHeight = this.globalData.compSize.h;
  11753. var i;
  11754. var len = this.threeDElements.length;
  11755. for (i = 0; i < len; i += 1) {
  11756. var style = this.threeDElements[i].perspectiveElem.style;
  11757. style.webkitPerspective = Math.sqrt(Math.pow(cWidth, 2) + Math.pow(cHeight, 2)) + 'px';
  11758. style.perspective = style.webkitPerspective;
  11759. }
  11760. }
  11761. };
  11762. HybridRendererBase.prototype.searchExtraCompositions = function (assets) {
  11763. var i;
  11764. var len = assets.length;
  11765. var floatingContainer = createTag('div');
  11766. for (i = 0; i < len; i += 1) {
  11767. if (assets[i].xt) {
  11768. var comp = this.createComp(assets[i], floatingContainer, this.globalData.comp, null);
  11769. comp.initExpressions();
  11770. this.globalData.projectInterface.registerComposition(comp);
  11771. }
  11772. }
  11773. };
  11774. function HCompElement(data, globalData, comp) {
  11775. this.layers = data.layers;
  11776. this.supports3d = !data.hasMask;
  11777. this.completeLayers = false;
  11778. this.pendingElements = [];
  11779. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  11780. this.initElement(data, globalData, comp);
  11781. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  11782. }
  11783. extendPrototype([HybridRendererBase, ICompElement, HBaseElement], HCompElement);
  11784. HCompElement.prototype._createBaseContainerElements = HCompElement.prototype.createContainerElements;
  11785. HCompElement.prototype.createContainerElements = function () {
  11786. this._createBaseContainerElements();
  11787. // divElement.style.clip = 'rect(0px, '+this.data.w+'px, '+this.data.h+'px, 0px)';
  11788. if (this.data.hasMask) {
  11789. this.svgElement.setAttribute('width', this.data.w);
  11790. this.svgElement.setAttribute('height', this.data.h);
  11791. this.transformedElement = this.baseElement;
  11792. } else {
  11793. this.transformedElement = this.layerElement;
  11794. }
  11795. };
  11796. HCompElement.prototype.addTo3dContainer = function (elem, pos) {
  11797. var j = 0;
  11798. var nextElement;
  11799. while (j < pos) {
  11800. if (this.elements[j] && this.elements[j].getBaseElement) {
  11801. nextElement = this.elements[j].getBaseElement();
  11802. }
  11803. j += 1;
  11804. }
  11805. if (nextElement) {
  11806. this.layerElement.insertBefore(elem, nextElement);
  11807. } else {
  11808. this.layerElement.appendChild(elem);
  11809. }
  11810. };
  11811. HCompElement.prototype.createComp = function (data) {
  11812. if (!this.supports3d) {
  11813. return new SVGCompElement(data, this.globalData, this);
  11814. }
  11815. return new HCompElement(data, this.globalData, this);
  11816. };
  11817. function HybridRenderer(animationItem, config) {
  11818. this.animationItem = animationItem;
  11819. this.layers = null;
  11820. this.renderedFrame = -1;
  11821. this.renderConfig = {
  11822. className: (config && config.className) || '',
  11823. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  11824. hideOnTransparent: !(config && config.hideOnTransparent === false),
  11825. filterSize: {
  11826. width: (config && config.filterSize && config.filterSize.width) || '400%',
  11827. height: (config && config.filterSize && config.filterSize.height) || '400%',
  11828. x: (config && config.filterSize && config.filterSize.x) || '-100%',
  11829. y: (config && config.filterSize && config.filterSize.y) || '-100%',
  11830. },
  11831. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  11832. };
  11833. this.globalData = {
  11834. _mdf: false,
  11835. frameNum: -1,
  11836. renderConfig: this.renderConfig,
  11837. };
  11838. this.pendingElements = [];
  11839. this.elements = [];
  11840. this.threeDElements = [];
  11841. this.destroyed = false;
  11842. this.camera = null;
  11843. this.supports3d = true;
  11844. this.rendererType = 'html';
  11845. }
  11846. extendPrototype([HybridRendererBase], HybridRenderer);
  11847. HybridRenderer.prototype.createComp = function (data) {
  11848. if (!this.supports3d) {
  11849. return new SVGCompElement(data, this.globalData, this);
  11850. }
  11851. return new HCompElement(data, this.globalData, this);
  11852. };
  11853. // Registering renderers
  11854. registerRenderer('html', HybridRenderer);
  11855. // Registering shape modifiers
  11856. ShapeModifiers.registerModifier('tm', TrimModifier);
  11857. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  11858. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  11859. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  11860. ShapeModifiers.registerModifier('zz', ZigZagModifier);
  11861. ShapeModifiers.registerModifier('op', OffsetPathModifier);
  11862. export { lottie as default };