lottie_html.js 547 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170
  1. (typeof navigator !== "undefined") && (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.lottie = factory());
  5. })(this, (function () { 'use strict';
  6. var svgNS = 'http://www.w3.org/2000/svg';
  7. var locationHref = '';
  8. var _useWebWorker = false;
  9. var initialDefaultFrame = -999999;
  10. var setWebWorker = function setWebWorker(flag) {
  11. _useWebWorker = !!flag;
  12. };
  13. var getWebWorker = function getWebWorker() {
  14. return _useWebWorker;
  15. };
  16. var setLocationHref = function setLocationHref(value) {
  17. locationHref = value;
  18. };
  19. var getLocationHref = function getLocationHref() {
  20. return locationHref;
  21. };
  22. function createTag(type) {
  23. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  24. return document.createElement(type);
  25. }
  26. function extendPrototype(sources, destination) {
  27. var i;
  28. var len = sources.length;
  29. var sourcePrototype;
  30. for (i = 0; i < len; i += 1) {
  31. sourcePrototype = sources[i].prototype;
  32. for (var attr in sourcePrototype) {
  33. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  34. }
  35. }
  36. }
  37. function getDescriptor(object, prop) {
  38. return Object.getOwnPropertyDescriptor(object, prop);
  39. }
  40. function createProxyFunction(prototype) {
  41. function ProxyFunction() {}
  42. ProxyFunction.prototype = prototype;
  43. return ProxyFunction;
  44. }
  45. // import Howl from '../../3rd_party/howler';
  46. var audioControllerFactory = function () {
  47. function AudioController(audioFactory) {
  48. this.audios = [];
  49. this.audioFactory = audioFactory;
  50. this._volume = 1;
  51. this._isMuted = false;
  52. }
  53. AudioController.prototype = {
  54. addAudio: function addAudio(audio) {
  55. this.audios.push(audio);
  56. },
  57. pause: function pause() {
  58. var i;
  59. var len = this.audios.length;
  60. for (i = 0; i < len; i += 1) {
  61. this.audios[i].pause();
  62. }
  63. },
  64. resume: function resume() {
  65. var i;
  66. var len = this.audios.length;
  67. for (i = 0; i < len; i += 1) {
  68. this.audios[i].resume();
  69. }
  70. },
  71. setRate: function setRate(rateValue) {
  72. var i;
  73. var len = this.audios.length;
  74. for (i = 0; i < len; i += 1) {
  75. this.audios[i].setRate(rateValue);
  76. }
  77. },
  78. createAudio: function createAudio(assetPath) {
  79. if (this.audioFactory) {
  80. return this.audioFactory(assetPath);
  81. }
  82. if (window.Howl) {
  83. return new window.Howl({
  84. src: [assetPath]
  85. });
  86. }
  87. return {
  88. isPlaying: false,
  89. play: function play() {
  90. this.isPlaying = true;
  91. },
  92. seek: function seek() {
  93. this.isPlaying = false;
  94. },
  95. playing: function playing() {},
  96. rate: function rate() {},
  97. setVolume: function setVolume() {}
  98. };
  99. },
  100. setAudioFactory: function setAudioFactory(audioFactory) {
  101. this.audioFactory = audioFactory;
  102. },
  103. setVolume: function setVolume(value) {
  104. this._volume = value;
  105. this._updateVolume();
  106. },
  107. mute: function mute() {
  108. this._isMuted = true;
  109. this._updateVolume();
  110. },
  111. unmute: function unmute() {
  112. this._isMuted = false;
  113. this._updateVolume();
  114. },
  115. getVolume: function getVolume() {
  116. return this._volume;
  117. },
  118. _updateVolume: function _updateVolume() {
  119. var i;
  120. var len = this.audios.length;
  121. for (i = 0; i < len; i += 1) {
  122. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  123. }
  124. }
  125. };
  126. return function () {
  127. return new AudioController();
  128. };
  129. }();
  130. var createTypedArray = function () {
  131. function createRegularArray(type, len) {
  132. var i = 0;
  133. var arr = [];
  134. var value;
  135. switch (type) {
  136. case 'int16':
  137. case 'uint8c':
  138. value = 1;
  139. break;
  140. default:
  141. value = 1.1;
  142. break;
  143. }
  144. for (i = 0; i < len; i += 1) {
  145. arr.push(value);
  146. }
  147. return arr;
  148. }
  149. function createTypedArrayFactory(type, len) {
  150. if (type === 'float32') {
  151. return new Float32Array(len);
  152. }
  153. if (type === 'int16') {
  154. return new Int16Array(len);
  155. }
  156. if (type === 'uint8c') {
  157. return new Uint8ClampedArray(len);
  158. }
  159. return createRegularArray(type, len);
  160. }
  161. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  162. return createTypedArrayFactory;
  163. }
  164. return createRegularArray;
  165. }();
  166. function createSizedArray(len) {
  167. return Array.apply(null, {
  168. length: len
  169. });
  170. }
  171. function _typeof$6(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$6 = function _typeof(obj) { return typeof obj; }; } else { _typeof$6 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$6(obj); }
  172. var subframeEnabled = true;
  173. var expressionsPlugin = null;
  174. var expressionsInterfaces = null;
  175. var idPrefix$1 = '';
  176. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  177. var _shouldRoundValues = false;
  178. var bmPow = Math.pow;
  179. var bmSqrt = Math.sqrt;
  180. var bmFloor = Math.floor;
  181. var bmMax = Math.max;
  182. var bmMin = Math.min;
  183. var BMMath = {};
  184. (function () {
  185. var propertyNames = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'atan2', 'ceil', 'cbrt', 'expm1', 'clz32', 'cos', 'cosh', 'exp', 'floor', 'fround', 'hypot', 'imul', 'log', 'log1p', 'log2', 'log10', 'max', 'min', 'pow', 'random', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', 'E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2'];
  186. var i;
  187. var len = propertyNames.length;
  188. for (i = 0; i < len; i += 1) {
  189. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  190. }
  191. })();
  192. function ProjectInterface$1() {
  193. return {};
  194. }
  195. BMMath.random = Math.random;
  196. BMMath.abs = function (val) {
  197. var tOfVal = _typeof$6(val);
  198. if (tOfVal === 'object' && val.length) {
  199. var absArr = createSizedArray(val.length);
  200. var i;
  201. var len = val.length;
  202. for (i = 0; i < len; i += 1) {
  203. absArr[i] = Math.abs(val[i]);
  204. }
  205. return absArr;
  206. }
  207. return Math.abs(val);
  208. };
  209. var defaultCurveSegments = 150;
  210. var degToRads = Math.PI / 180;
  211. var roundCorner = 0.5519;
  212. function roundValues(flag) {
  213. _shouldRoundValues = !!flag;
  214. }
  215. function bmRnd(value) {
  216. if (_shouldRoundValues) {
  217. return Math.round(value);
  218. }
  219. return value;
  220. }
  221. function styleDiv(element) {
  222. element.style.position = 'absolute';
  223. element.style.top = 0;
  224. element.style.left = 0;
  225. element.style.display = 'block';
  226. element.style.transformOrigin = '0 0';
  227. element.style.webkitTransformOrigin = '0 0';
  228. element.style.backfaceVisibility = 'visible';
  229. element.style.webkitBackfaceVisibility = 'visible';
  230. element.style.transformStyle = 'preserve-3d';
  231. element.style.webkitTransformStyle = 'preserve-3d';
  232. element.style.mozTransformStyle = 'preserve-3d';
  233. }
  234. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  235. this.type = type;
  236. this.currentTime = currentTime;
  237. this.totalTime = totalTime;
  238. this.direction = frameMultiplier < 0 ? -1 : 1;
  239. }
  240. function BMCompleteEvent(type, frameMultiplier) {
  241. this.type = type;
  242. this.direction = frameMultiplier < 0 ? -1 : 1;
  243. }
  244. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  245. this.type = type;
  246. this.currentLoop = currentLoop;
  247. this.totalLoops = totalLoops;
  248. this.direction = frameMultiplier < 0 ? -1 : 1;
  249. }
  250. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  251. this.type = type;
  252. this.firstFrame = firstFrame;
  253. this.totalFrames = totalFrames;
  254. }
  255. function BMDestroyEvent(type, target) {
  256. this.type = type;
  257. this.target = target;
  258. }
  259. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  260. this.type = 'renderFrameError';
  261. this.nativeError = nativeError;
  262. this.currentTime = currentTime;
  263. }
  264. function BMConfigErrorEvent(nativeError) {
  265. this.type = 'configError';
  266. this.nativeError = nativeError;
  267. }
  268. function BMAnimationConfigErrorEvent(type, nativeError) {
  269. this.type = type;
  270. this.nativeError = nativeError;
  271. }
  272. var createElementID = function () {
  273. var _count = 0;
  274. return function createID() {
  275. _count += 1;
  276. return idPrefix$1 + '__lottie_element_' + _count;
  277. };
  278. }();
  279. function HSVtoRGB(h, s, v) {
  280. var r;
  281. var g;
  282. var b;
  283. var i;
  284. var f;
  285. var p;
  286. var q;
  287. var t;
  288. i = Math.floor(h * 6);
  289. f = h * 6 - i;
  290. p = v * (1 - s);
  291. q = v * (1 - f * s);
  292. t = v * (1 - (1 - f) * s);
  293. switch (i % 6) {
  294. case 0:
  295. r = v;
  296. g = t;
  297. b = p;
  298. break;
  299. case 1:
  300. r = q;
  301. g = v;
  302. b = p;
  303. break;
  304. case 2:
  305. r = p;
  306. g = v;
  307. b = t;
  308. break;
  309. case 3:
  310. r = p;
  311. g = q;
  312. b = v;
  313. break;
  314. case 4:
  315. r = t;
  316. g = p;
  317. b = v;
  318. break;
  319. case 5:
  320. r = v;
  321. g = p;
  322. b = q;
  323. break;
  324. default:
  325. break;
  326. }
  327. return [r, g, b];
  328. }
  329. function RGBtoHSV(r, g, b) {
  330. var max = Math.max(r, g, b);
  331. var min = Math.min(r, g, b);
  332. var d = max - min;
  333. var h;
  334. var s = max === 0 ? 0 : d / max;
  335. var v = max / 255;
  336. switch (max) {
  337. case min:
  338. h = 0;
  339. break;
  340. case r:
  341. h = g - b + d * (g < b ? 6 : 0);
  342. h /= 6 * d;
  343. break;
  344. case g:
  345. h = b - r + d * 2;
  346. h /= 6 * d;
  347. break;
  348. case b:
  349. h = r - g + d * 4;
  350. h /= 6 * d;
  351. break;
  352. default:
  353. break;
  354. }
  355. return [h, s, v];
  356. }
  357. function addSaturationToRGB(color, offset) {
  358. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  359. hsv[1] += offset;
  360. if (hsv[1] > 1) {
  361. hsv[1] = 1;
  362. } else if (hsv[1] <= 0) {
  363. hsv[1] = 0;
  364. }
  365. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  366. }
  367. function addBrightnessToRGB(color, offset) {
  368. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  369. hsv[2] += offset;
  370. if (hsv[2] > 1) {
  371. hsv[2] = 1;
  372. } else if (hsv[2] < 0) {
  373. hsv[2] = 0;
  374. }
  375. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  376. }
  377. function addHueToRGB(color, offset) {
  378. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  379. hsv[0] += offset / 360;
  380. if (hsv[0] > 1) {
  381. hsv[0] -= 1;
  382. } else if (hsv[0] < 0) {
  383. hsv[0] += 1;
  384. }
  385. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  386. }
  387. var rgbToHex = function () {
  388. var colorMap = [];
  389. var i;
  390. var hex;
  391. for (i = 0; i < 256; i += 1) {
  392. hex = i.toString(16);
  393. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  394. }
  395. return function (r, g, b) {
  396. if (r < 0) {
  397. r = 0;
  398. }
  399. if (g < 0) {
  400. g = 0;
  401. }
  402. if (b < 0) {
  403. b = 0;
  404. }
  405. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  406. };
  407. }();
  408. var setSubframeEnabled = function setSubframeEnabled(flag) {
  409. subframeEnabled = !!flag;
  410. };
  411. var getSubframeEnabled = function getSubframeEnabled() {
  412. return subframeEnabled;
  413. };
  414. var setExpressionsPlugin = function setExpressionsPlugin(value) {
  415. expressionsPlugin = value;
  416. };
  417. var getExpressionsPlugin = function getExpressionsPlugin() {
  418. return expressionsPlugin;
  419. };
  420. var setExpressionInterfaces = function setExpressionInterfaces(value) {
  421. expressionsInterfaces = value;
  422. };
  423. var getExpressionInterfaces = function getExpressionInterfaces() {
  424. return expressionsInterfaces;
  425. };
  426. var setDefaultCurveSegments = function setDefaultCurveSegments(value) {
  427. defaultCurveSegments = value;
  428. };
  429. var getDefaultCurveSegments = function getDefaultCurveSegments() {
  430. return defaultCurveSegments;
  431. };
  432. var setIdPrefix = function setIdPrefix(value) {
  433. idPrefix$1 = value;
  434. };
  435. var getIdPrefix = function getIdPrefix() {
  436. return idPrefix$1;
  437. };
  438. function createNS(type) {
  439. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  440. return document.createElementNS(svgNS, type);
  441. }
  442. function _typeof$5(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$5 = function _typeof(obj) { return typeof obj; }; } else { _typeof$5 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$5(obj); }
  443. var dataManager = function () {
  444. var _counterId = 1;
  445. var processes = [];
  446. var workerFn;
  447. var workerInstance;
  448. var workerProxy = {
  449. onmessage: function onmessage() {},
  450. postMessage: function postMessage(path) {
  451. workerFn({
  452. data: path
  453. });
  454. }
  455. };
  456. var _workerSelf = {
  457. postMessage: function postMessage(data) {
  458. workerProxy.onmessage({
  459. data: data
  460. });
  461. }
  462. };
  463. function createWorker(fn) {
  464. if (window.Worker && window.Blob && getWebWorker()) {
  465. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], {
  466. type: 'text/javascript'
  467. }); // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  468. var url = URL.createObjectURL(blob);
  469. return new Worker(url);
  470. }
  471. workerFn = fn;
  472. return workerProxy;
  473. }
  474. function setupWorker() {
  475. if (!workerInstance) {
  476. workerInstance = createWorker(function workerStart(e) {
  477. function dataFunctionManager() {
  478. function completeLayers(layers, comps) {
  479. var layerData;
  480. var i;
  481. var len = layers.length;
  482. var j;
  483. var jLen;
  484. var k;
  485. var kLen;
  486. for (i = 0; i < len; i += 1) {
  487. layerData = layers[i];
  488. if ('ks' in layerData && !layerData.completed) {
  489. layerData.completed = true;
  490. if (layerData.hasMask) {
  491. var maskProps = layerData.masksProperties;
  492. jLen = maskProps.length;
  493. for (j = 0; j < jLen; j += 1) {
  494. if (maskProps[j].pt.k.i) {
  495. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  496. } else {
  497. kLen = maskProps[j].pt.k.length;
  498. for (k = 0; k < kLen; k += 1) {
  499. if (maskProps[j].pt.k[k].s) {
  500. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  501. }
  502. if (maskProps[j].pt.k[k].e) {
  503. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  504. }
  505. }
  506. }
  507. }
  508. }
  509. if (layerData.ty === 0) {
  510. layerData.layers = findCompLayers(layerData.refId, comps);
  511. completeLayers(layerData.layers, comps);
  512. } else if (layerData.ty === 4) {
  513. completeShapes(layerData.shapes);
  514. } else if (layerData.ty === 5) {
  515. completeText(layerData);
  516. }
  517. }
  518. }
  519. }
  520. function completeChars(chars, assets) {
  521. if (chars) {
  522. var i = 0;
  523. var len = chars.length;
  524. for (i = 0; i < len; i += 1) {
  525. if (chars[i].t === 1) {
  526. // var compData = findComp(chars[i].data.refId, assets);
  527. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets); // chars[i].data.ip = 0;
  528. // chars[i].data.op = 99999;
  529. // chars[i].data.st = 0;
  530. // chars[i].data.sr = 1;
  531. // chars[i].w = compData.w;
  532. // chars[i].data.ks = {
  533. // a: { k: [0, 0, 0], a: 0 },
  534. // p: { k: [0, -compData.h, 0], a: 0 },
  535. // r: { k: 0, a: 0 },
  536. // s: { k: [100, 100], a: 0 },
  537. // o: { k: 100, a: 0 },
  538. // };
  539. completeLayers(chars[i].data.layers, assets);
  540. }
  541. }
  542. }
  543. }
  544. function findComp(id, comps) {
  545. var i = 0;
  546. var len = comps.length;
  547. while (i < len) {
  548. if (comps[i].id === id) {
  549. return comps[i];
  550. }
  551. i += 1;
  552. }
  553. return null;
  554. }
  555. function findCompLayers(id, comps) {
  556. var comp = findComp(id, comps);
  557. if (comp) {
  558. if (!comp.layers.__used) {
  559. comp.layers.__used = true;
  560. return comp.layers;
  561. }
  562. return JSON.parse(JSON.stringify(comp.layers));
  563. }
  564. return null;
  565. }
  566. function completeShapes(arr) {
  567. var i;
  568. var len = arr.length;
  569. var j;
  570. var jLen;
  571. for (i = len - 1; i >= 0; i -= 1) {
  572. if (arr[i].ty === 'sh') {
  573. if (arr[i].ks.k.i) {
  574. convertPathsToAbsoluteValues(arr[i].ks.k);
  575. } else {
  576. jLen = arr[i].ks.k.length;
  577. for (j = 0; j < jLen; j += 1) {
  578. if (arr[i].ks.k[j].s) {
  579. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  580. }
  581. if (arr[i].ks.k[j].e) {
  582. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  583. }
  584. }
  585. }
  586. } else if (arr[i].ty === 'gr') {
  587. completeShapes(arr[i].it);
  588. }
  589. }
  590. }
  591. function convertPathsToAbsoluteValues(path) {
  592. var i;
  593. var len = path.i.length;
  594. for (i = 0; i < len; i += 1) {
  595. path.i[i][0] += path.v[i][0];
  596. path.i[i][1] += path.v[i][1];
  597. path.o[i][0] += path.v[i][0];
  598. path.o[i][1] += path.v[i][1];
  599. }
  600. }
  601. function checkVersion(minimum, animVersionString) {
  602. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  603. if (minimum[0] > animVersion[0]) {
  604. return true;
  605. }
  606. if (animVersion[0] > minimum[0]) {
  607. return false;
  608. }
  609. if (minimum[1] > animVersion[1]) {
  610. return true;
  611. }
  612. if (animVersion[1] > minimum[1]) {
  613. return false;
  614. }
  615. if (minimum[2] > animVersion[2]) {
  616. return true;
  617. }
  618. if (animVersion[2] > minimum[2]) {
  619. return false;
  620. }
  621. return null;
  622. }
  623. var checkText = function () {
  624. var minimumVersion = [4, 4, 14];
  625. function updateTextLayer(textLayer) {
  626. var documentData = textLayer.t.d;
  627. textLayer.t.d = {
  628. k: [{
  629. s: documentData,
  630. t: 0
  631. }]
  632. };
  633. }
  634. function iterateLayers(layers) {
  635. var i;
  636. var len = layers.length;
  637. for (i = 0; i < len; i += 1) {
  638. if (layers[i].ty === 5) {
  639. updateTextLayer(layers[i]);
  640. }
  641. }
  642. }
  643. return function (animationData) {
  644. if (checkVersion(minimumVersion, animationData.v)) {
  645. iterateLayers(animationData.layers);
  646. if (animationData.assets) {
  647. var i;
  648. var len = animationData.assets.length;
  649. for (i = 0; i < len; i += 1) {
  650. if (animationData.assets[i].layers) {
  651. iterateLayers(animationData.assets[i].layers);
  652. }
  653. }
  654. }
  655. }
  656. };
  657. }();
  658. var checkChars = function () {
  659. var minimumVersion = [4, 7, 99];
  660. return function (animationData) {
  661. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  662. var i;
  663. var len = animationData.chars.length;
  664. for (i = 0; i < len; i += 1) {
  665. var charData = animationData.chars[i];
  666. if (charData.data && charData.data.shapes) {
  667. completeShapes(charData.data.shapes);
  668. charData.data.ip = 0;
  669. charData.data.op = 99999;
  670. charData.data.st = 0;
  671. charData.data.sr = 1;
  672. charData.data.ks = {
  673. p: {
  674. k: [0, 0],
  675. a: 0
  676. },
  677. s: {
  678. k: [100, 100],
  679. a: 0
  680. },
  681. a: {
  682. k: [0, 0],
  683. a: 0
  684. },
  685. r: {
  686. k: 0,
  687. a: 0
  688. },
  689. o: {
  690. k: 100,
  691. a: 0
  692. }
  693. };
  694. if (!animationData.chars[i].t) {
  695. charData.data.shapes.push({
  696. ty: 'no'
  697. });
  698. charData.data.shapes[0].it.push({
  699. p: {
  700. k: [0, 0],
  701. a: 0
  702. },
  703. s: {
  704. k: [100, 100],
  705. a: 0
  706. },
  707. a: {
  708. k: [0, 0],
  709. a: 0
  710. },
  711. r: {
  712. k: 0,
  713. a: 0
  714. },
  715. o: {
  716. k: 100,
  717. a: 0
  718. },
  719. sk: {
  720. k: 0,
  721. a: 0
  722. },
  723. sa: {
  724. k: 0,
  725. a: 0
  726. },
  727. ty: 'tr'
  728. });
  729. }
  730. }
  731. }
  732. }
  733. };
  734. }();
  735. var checkPathProperties = function () {
  736. var minimumVersion = [5, 7, 15];
  737. function updateTextLayer(textLayer) {
  738. var pathData = textLayer.t.p;
  739. if (typeof pathData.a === 'number') {
  740. pathData.a = {
  741. a: 0,
  742. k: pathData.a
  743. };
  744. }
  745. if (typeof pathData.p === 'number') {
  746. pathData.p = {
  747. a: 0,
  748. k: pathData.p
  749. };
  750. }
  751. if (typeof pathData.r === 'number') {
  752. pathData.r = {
  753. a: 0,
  754. k: pathData.r
  755. };
  756. }
  757. }
  758. function iterateLayers(layers) {
  759. var i;
  760. var len = layers.length;
  761. for (i = 0; i < len; i += 1) {
  762. if (layers[i].ty === 5) {
  763. updateTextLayer(layers[i]);
  764. }
  765. }
  766. }
  767. return function (animationData) {
  768. if (checkVersion(minimumVersion, animationData.v)) {
  769. iterateLayers(animationData.layers);
  770. if (animationData.assets) {
  771. var i;
  772. var len = animationData.assets.length;
  773. for (i = 0; i < len; i += 1) {
  774. if (animationData.assets[i].layers) {
  775. iterateLayers(animationData.assets[i].layers);
  776. }
  777. }
  778. }
  779. }
  780. };
  781. }();
  782. var checkColors = function () {
  783. var minimumVersion = [4, 1, 9];
  784. function iterateShapes(shapes) {
  785. var i;
  786. var len = shapes.length;
  787. var j;
  788. var jLen;
  789. for (i = 0; i < len; i += 1) {
  790. if (shapes[i].ty === 'gr') {
  791. iterateShapes(shapes[i].it);
  792. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  793. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  794. jLen = shapes[i].c.k.length;
  795. for (j = 0; j < jLen; j += 1) {
  796. if (shapes[i].c.k[j].s) {
  797. shapes[i].c.k[j].s[0] /= 255;
  798. shapes[i].c.k[j].s[1] /= 255;
  799. shapes[i].c.k[j].s[2] /= 255;
  800. shapes[i].c.k[j].s[3] /= 255;
  801. }
  802. if (shapes[i].c.k[j].e) {
  803. shapes[i].c.k[j].e[0] /= 255;
  804. shapes[i].c.k[j].e[1] /= 255;
  805. shapes[i].c.k[j].e[2] /= 255;
  806. shapes[i].c.k[j].e[3] /= 255;
  807. }
  808. }
  809. } else {
  810. shapes[i].c.k[0] /= 255;
  811. shapes[i].c.k[1] /= 255;
  812. shapes[i].c.k[2] /= 255;
  813. shapes[i].c.k[3] /= 255;
  814. }
  815. }
  816. }
  817. }
  818. function iterateLayers(layers) {
  819. var i;
  820. var len = layers.length;
  821. for (i = 0; i < len; i += 1) {
  822. if (layers[i].ty === 4) {
  823. iterateShapes(layers[i].shapes);
  824. }
  825. }
  826. }
  827. return function (animationData) {
  828. if (checkVersion(minimumVersion, animationData.v)) {
  829. iterateLayers(animationData.layers);
  830. if (animationData.assets) {
  831. var i;
  832. var len = animationData.assets.length;
  833. for (i = 0; i < len; i += 1) {
  834. if (animationData.assets[i].layers) {
  835. iterateLayers(animationData.assets[i].layers);
  836. }
  837. }
  838. }
  839. }
  840. };
  841. }();
  842. var checkShapes = function () {
  843. var minimumVersion = [4, 4, 18];
  844. function completeClosingShapes(arr) {
  845. var i;
  846. var len = arr.length;
  847. var j;
  848. var jLen;
  849. for (i = len - 1; i >= 0; i -= 1) {
  850. if (arr[i].ty === 'sh') {
  851. if (arr[i].ks.k.i) {
  852. arr[i].ks.k.c = arr[i].closed;
  853. } else {
  854. jLen = arr[i].ks.k.length;
  855. for (j = 0; j < jLen; j += 1) {
  856. if (arr[i].ks.k[j].s) {
  857. arr[i].ks.k[j].s[0].c = arr[i].closed;
  858. }
  859. if (arr[i].ks.k[j].e) {
  860. arr[i].ks.k[j].e[0].c = arr[i].closed;
  861. }
  862. }
  863. }
  864. } else if (arr[i].ty === 'gr') {
  865. completeClosingShapes(arr[i].it);
  866. }
  867. }
  868. }
  869. function iterateLayers(layers) {
  870. var layerData;
  871. var i;
  872. var len = layers.length;
  873. var j;
  874. var jLen;
  875. var k;
  876. var kLen;
  877. for (i = 0; i < len; i += 1) {
  878. layerData = layers[i];
  879. if (layerData.hasMask) {
  880. var maskProps = layerData.masksProperties;
  881. jLen = maskProps.length;
  882. for (j = 0; j < jLen; j += 1) {
  883. if (maskProps[j].pt.k.i) {
  884. maskProps[j].pt.k.c = maskProps[j].cl;
  885. } else {
  886. kLen = maskProps[j].pt.k.length;
  887. for (k = 0; k < kLen; k += 1) {
  888. if (maskProps[j].pt.k[k].s) {
  889. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  890. }
  891. if (maskProps[j].pt.k[k].e) {
  892. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  893. }
  894. }
  895. }
  896. }
  897. }
  898. if (layerData.ty === 4) {
  899. completeClosingShapes(layerData.shapes);
  900. }
  901. }
  902. }
  903. return function (animationData) {
  904. if (checkVersion(minimumVersion, animationData.v)) {
  905. iterateLayers(animationData.layers);
  906. if (animationData.assets) {
  907. var i;
  908. var len = animationData.assets.length;
  909. for (i = 0; i < len; i += 1) {
  910. if (animationData.assets[i].layers) {
  911. iterateLayers(animationData.assets[i].layers);
  912. }
  913. }
  914. }
  915. }
  916. };
  917. }();
  918. function completeData(animationData) {
  919. if (animationData.__complete) {
  920. return;
  921. }
  922. checkColors(animationData);
  923. checkText(animationData);
  924. checkChars(animationData);
  925. checkPathProperties(animationData);
  926. checkShapes(animationData);
  927. completeLayers(animationData.layers, animationData.assets);
  928. completeChars(animationData.chars, animationData.assets);
  929. animationData.__complete = true;
  930. }
  931. function completeText(data) {
  932. if (data.t.a.length === 0 && !('m' in data.t.p)) {// data.singleShape = true;
  933. }
  934. }
  935. var moduleOb = {};
  936. moduleOb.completeData = completeData;
  937. moduleOb.checkColors = checkColors;
  938. moduleOb.checkChars = checkChars;
  939. moduleOb.checkPathProperties = checkPathProperties;
  940. moduleOb.checkShapes = checkShapes;
  941. moduleOb.completeLayers = completeLayers;
  942. return moduleOb;
  943. }
  944. if (!_workerSelf.dataManager) {
  945. _workerSelf.dataManager = dataFunctionManager();
  946. }
  947. if (!_workerSelf.assetLoader) {
  948. _workerSelf.assetLoader = function () {
  949. function formatResponse(xhr) {
  950. // using typeof doubles the time of execution of this method,
  951. // so if available, it's better to use the header to validate the type
  952. var contentTypeHeader = xhr.getResponseHeader('content-type');
  953. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  954. return xhr.response;
  955. }
  956. if (xhr.response && _typeof$5(xhr.response) === 'object') {
  957. return xhr.response;
  958. }
  959. if (xhr.response && typeof xhr.response === 'string') {
  960. return JSON.parse(xhr.response);
  961. }
  962. if (xhr.responseText) {
  963. return JSON.parse(xhr.responseText);
  964. }
  965. return null;
  966. }
  967. function loadAsset(path, fullPath, callback, errorCallback) {
  968. var response;
  969. var xhr = new XMLHttpRequest(); // set responseType after calling open or IE will break.
  970. try {
  971. // This crashes on Android WebView prior to KitKat
  972. xhr.responseType = 'json';
  973. } catch (err) {} // eslint-disable-line no-empty
  974. xhr.onreadystatechange = function () {
  975. if (xhr.readyState === 4) {
  976. if (xhr.status === 200) {
  977. response = formatResponse(xhr);
  978. callback(response);
  979. } else {
  980. try {
  981. response = formatResponse(xhr);
  982. callback(response);
  983. } catch (err) {
  984. if (errorCallback) {
  985. errorCallback(err);
  986. }
  987. }
  988. }
  989. }
  990. };
  991. try {
  992. // Hack to workaround banner validation
  993. xhr.open(['G', 'E', 'T'].join(''), path, true);
  994. } catch (error) {
  995. // Hack to workaround banner validation
  996. xhr.open(['G', 'E', 'T'].join(''), fullPath + '/' + path, true);
  997. }
  998. xhr.send();
  999. }
  1000. return {
  1001. load: loadAsset
  1002. };
  1003. }();
  1004. }
  1005. if (e.data.type === 'loadAnimation') {
  1006. _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function (data) {
  1007. _workerSelf.dataManager.completeData(data);
  1008. _workerSelf.postMessage({
  1009. id: e.data.id,
  1010. payload: data,
  1011. status: 'success'
  1012. });
  1013. }, function () {
  1014. _workerSelf.postMessage({
  1015. id: e.data.id,
  1016. status: 'error'
  1017. });
  1018. });
  1019. } else if (e.data.type === 'complete') {
  1020. var animation = e.data.animation;
  1021. _workerSelf.dataManager.completeData(animation);
  1022. _workerSelf.postMessage({
  1023. id: e.data.id,
  1024. payload: animation,
  1025. status: 'success'
  1026. });
  1027. } else if (e.data.type === 'loadData') {
  1028. _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function (data) {
  1029. _workerSelf.postMessage({
  1030. id: e.data.id,
  1031. payload: data,
  1032. status: 'success'
  1033. });
  1034. }, function () {
  1035. _workerSelf.postMessage({
  1036. id: e.data.id,
  1037. status: 'error'
  1038. });
  1039. });
  1040. }
  1041. });
  1042. workerInstance.onmessage = function (event) {
  1043. var data = event.data;
  1044. var id = data.id;
  1045. var process = processes[id];
  1046. processes[id] = null;
  1047. if (data.status === 'success') {
  1048. process.onComplete(data.payload);
  1049. } else if (process.onError) {
  1050. process.onError();
  1051. }
  1052. };
  1053. }
  1054. }
  1055. function createProcess(onComplete, onError) {
  1056. _counterId += 1;
  1057. var id = 'processId_' + _counterId;
  1058. processes[id] = {
  1059. onComplete: onComplete,
  1060. onError: onError
  1061. };
  1062. return id;
  1063. }
  1064. function loadAnimation(path, onComplete, onError) {
  1065. setupWorker();
  1066. var processId = createProcess(onComplete, onError);
  1067. workerInstance.postMessage({
  1068. type: 'loadAnimation',
  1069. path: path,
  1070. fullPath: window.location.origin + window.location.pathname,
  1071. id: processId
  1072. });
  1073. }
  1074. function loadData(path, onComplete, onError) {
  1075. setupWorker();
  1076. var processId = createProcess(onComplete, onError);
  1077. workerInstance.postMessage({
  1078. type: 'loadData',
  1079. path: path,
  1080. fullPath: window.location.origin + window.location.pathname,
  1081. id: processId
  1082. });
  1083. }
  1084. function completeAnimation(anim, onComplete, onError) {
  1085. setupWorker();
  1086. var processId = createProcess(onComplete, onError);
  1087. workerInstance.postMessage({
  1088. type: 'complete',
  1089. animation: anim,
  1090. id: processId
  1091. });
  1092. }
  1093. return {
  1094. loadAnimation: loadAnimation,
  1095. loadData: loadData,
  1096. completeAnimation: completeAnimation
  1097. };
  1098. }();
  1099. var ImagePreloader = function () {
  1100. var proxyImage = function () {
  1101. var canvas = createTag('canvas');
  1102. canvas.width = 1;
  1103. canvas.height = 1;
  1104. var ctx = canvas.getContext('2d');
  1105. ctx.fillStyle = 'rgba(0,0,0,0)';
  1106. ctx.fillRect(0, 0, 1, 1);
  1107. return canvas;
  1108. }();
  1109. function imageLoaded() {
  1110. this.loadedAssets += 1;
  1111. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1112. if (this.imagesLoadedCb) {
  1113. this.imagesLoadedCb(null);
  1114. }
  1115. }
  1116. }
  1117. function footageLoaded() {
  1118. this.loadedFootagesCount += 1;
  1119. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1120. if (this.imagesLoadedCb) {
  1121. this.imagesLoadedCb(null);
  1122. }
  1123. }
  1124. }
  1125. function getAssetsPath(assetData, assetsPath, originalPath) {
  1126. var path = '';
  1127. if (assetData.e) {
  1128. path = assetData.p;
  1129. } else if (assetsPath) {
  1130. var imagePath = assetData.p;
  1131. if (imagePath.indexOf('images/') !== -1) {
  1132. imagePath = imagePath.split('/')[1];
  1133. }
  1134. path = assetsPath + imagePath;
  1135. } else {
  1136. path = originalPath;
  1137. path += assetData.u ? assetData.u : '';
  1138. path += assetData.p;
  1139. }
  1140. return path;
  1141. }
  1142. function testImageLoaded(img) {
  1143. var _count = 0;
  1144. var intervalId = setInterval(function () {
  1145. var box = img.getBBox();
  1146. if (box.width || _count > 500) {
  1147. this._imageLoaded();
  1148. clearInterval(intervalId);
  1149. }
  1150. _count += 1;
  1151. }.bind(this), 50);
  1152. }
  1153. function createImageData(assetData) {
  1154. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1155. var img = createNS('image');
  1156. if (isSafari) {
  1157. this.testImageLoaded(img);
  1158. } else {
  1159. img.addEventListener('load', this._imageLoaded, false);
  1160. }
  1161. img.addEventListener('error', function () {
  1162. ob.img = proxyImage;
  1163. this._imageLoaded();
  1164. }.bind(this), false);
  1165. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1166. if (this._elementHelper.append) {
  1167. this._elementHelper.append(img);
  1168. } else {
  1169. this._elementHelper.appendChild(img);
  1170. }
  1171. var ob = {
  1172. img: img,
  1173. assetData: assetData
  1174. };
  1175. return ob;
  1176. }
  1177. function createImgData(assetData) {
  1178. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1179. var img = createTag('img');
  1180. img.crossOrigin = 'anonymous';
  1181. img.addEventListener('load', this._imageLoaded, false);
  1182. img.addEventListener('error', function () {
  1183. ob.img = proxyImage;
  1184. this._imageLoaded();
  1185. }.bind(this), false);
  1186. img.src = path;
  1187. var ob = {
  1188. img: img,
  1189. assetData: assetData
  1190. };
  1191. return ob;
  1192. }
  1193. function createFootageData(data) {
  1194. var ob = {
  1195. assetData: data
  1196. };
  1197. var path = getAssetsPath(data, this.assetsPath, this.path);
  1198. dataManager.loadData(path, function (footageData) {
  1199. ob.img = footageData;
  1200. this._footageLoaded();
  1201. }.bind(this), function () {
  1202. ob.img = {};
  1203. this._footageLoaded();
  1204. }.bind(this));
  1205. return ob;
  1206. }
  1207. function loadAssets(assets, cb) {
  1208. this.imagesLoadedCb = cb;
  1209. var i;
  1210. var len = assets.length;
  1211. for (i = 0; i < len; i += 1) {
  1212. if (!assets[i].layers) {
  1213. if (!assets[i].t || assets[i].t === 'seq') {
  1214. this.totalImages += 1;
  1215. this.images.push(this._createImageData(assets[i]));
  1216. } else if (assets[i].t === 3) {
  1217. this.totalFootages += 1;
  1218. this.images.push(this.createFootageData(assets[i]));
  1219. }
  1220. }
  1221. }
  1222. }
  1223. function setPath(path) {
  1224. this.path = path || '';
  1225. }
  1226. function setAssetsPath(path) {
  1227. this.assetsPath = path || '';
  1228. }
  1229. function getAsset(assetData) {
  1230. var i = 0;
  1231. var len = this.images.length;
  1232. while (i < len) {
  1233. if (this.images[i].assetData === assetData) {
  1234. return this.images[i].img;
  1235. }
  1236. i += 1;
  1237. }
  1238. return null;
  1239. }
  1240. function destroy() {
  1241. this.imagesLoadedCb = null;
  1242. this.images.length = 0;
  1243. }
  1244. function loadedImages() {
  1245. return this.totalImages === this.loadedAssets;
  1246. }
  1247. function loadedFootages() {
  1248. return this.totalFootages === this.loadedFootagesCount;
  1249. }
  1250. function setCacheType(type, elementHelper) {
  1251. if (type === 'svg') {
  1252. this._elementHelper = elementHelper;
  1253. this._createImageData = this.createImageData.bind(this);
  1254. } else {
  1255. this._createImageData = this.createImgData.bind(this);
  1256. }
  1257. }
  1258. function ImagePreloaderFactory() {
  1259. this._imageLoaded = imageLoaded.bind(this);
  1260. this._footageLoaded = footageLoaded.bind(this);
  1261. this.testImageLoaded = testImageLoaded.bind(this);
  1262. this.createFootageData = createFootageData.bind(this);
  1263. this.assetsPath = '';
  1264. this.path = '';
  1265. this.totalImages = 0;
  1266. this.totalFootages = 0;
  1267. this.loadedAssets = 0;
  1268. this.loadedFootagesCount = 0;
  1269. this.imagesLoadedCb = null;
  1270. this.images = [];
  1271. }
  1272. ImagePreloaderFactory.prototype = {
  1273. loadAssets: loadAssets,
  1274. setAssetsPath: setAssetsPath,
  1275. setPath: setPath,
  1276. loadedImages: loadedImages,
  1277. loadedFootages: loadedFootages,
  1278. destroy: destroy,
  1279. getAsset: getAsset,
  1280. createImgData: createImgData,
  1281. createImageData: createImageData,
  1282. imageLoaded: imageLoaded,
  1283. footageLoaded: footageLoaded,
  1284. setCacheType: setCacheType
  1285. };
  1286. return ImagePreloaderFactory;
  1287. }();
  1288. function BaseEvent() {}
  1289. BaseEvent.prototype = {
  1290. triggerEvent: function triggerEvent(eventName, args) {
  1291. if (this._cbs[eventName]) {
  1292. var callbacks = this._cbs[eventName];
  1293. for (var i = 0; i < callbacks.length; i += 1) {
  1294. callbacks[i](args);
  1295. }
  1296. }
  1297. },
  1298. addEventListener: function addEventListener(eventName, callback) {
  1299. if (!this._cbs[eventName]) {
  1300. this._cbs[eventName] = [];
  1301. }
  1302. this._cbs[eventName].push(callback);
  1303. return function () {
  1304. this.removeEventListener(eventName, callback);
  1305. }.bind(this);
  1306. },
  1307. removeEventListener: function removeEventListener(eventName, callback) {
  1308. if (!callback) {
  1309. this._cbs[eventName] = null;
  1310. } else if (this._cbs[eventName]) {
  1311. var i = 0;
  1312. var len = this._cbs[eventName].length;
  1313. while (i < len) {
  1314. if (this._cbs[eventName][i] === callback) {
  1315. this._cbs[eventName].splice(i, 1);
  1316. i -= 1;
  1317. len -= 1;
  1318. }
  1319. i += 1;
  1320. }
  1321. if (!this._cbs[eventName].length) {
  1322. this._cbs[eventName] = null;
  1323. }
  1324. }
  1325. }
  1326. };
  1327. var markerParser = function () {
  1328. function parsePayloadLines(payload) {
  1329. var lines = payload.split('\r\n');
  1330. var keys = {};
  1331. var line;
  1332. var keysCount = 0;
  1333. for (var i = 0; i < lines.length; i += 1) {
  1334. line = lines[i].split(':');
  1335. if (line.length === 2) {
  1336. keys[line[0]] = line[1].trim();
  1337. keysCount += 1;
  1338. }
  1339. }
  1340. if (keysCount === 0) {
  1341. throw new Error();
  1342. }
  1343. return keys;
  1344. }
  1345. return function (_markers) {
  1346. var markers = [];
  1347. for (var i = 0; i < _markers.length; i += 1) {
  1348. var _marker = _markers[i];
  1349. var markerData = {
  1350. time: _marker.tm,
  1351. duration: _marker.dr
  1352. };
  1353. try {
  1354. markerData.payload = JSON.parse(_markers[i].cm);
  1355. } catch (_) {
  1356. try {
  1357. markerData.payload = parsePayloadLines(_markers[i].cm);
  1358. } catch (__) {
  1359. markerData.payload = {
  1360. name: _markers[i].cm
  1361. };
  1362. }
  1363. }
  1364. markers.push(markerData);
  1365. }
  1366. return markers;
  1367. };
  1368. }();
  1369. var ProjectInterface = function () {
  1370. function registerComposition(comp) {
  1371. this.compositions.push(comp);
  1372. }
  1373. return function () {
  1374. function _thisProjectFunction(name) {
  1375. var i = 0;
  1376. var len = this.compositions.length;
  1377. while (i < len) {
  1378. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1379. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1380. this.compositions[i].prepareFrame(this.currentFrame);
  1381. }
  1382. return this.compositions[i].compInterface;
  1383. }
  1384. i += 1;
  1385. }
  1386. return null;
  1387. }
  1388. _thisProjectFunction.compositions = [];
  1389. _thisProjectFunction.currentFrame = 0;
  1390. _thisProjectFunction.registerComposition = registerComposition;
  1391. return _thisProjectFunction;
  1392. };
  1393. }();
  1394. var renderers = {};
  1395. var registerRenderer = function registerRenderer(key, value) {
  1396. renderers[key] = value;
  1397. };
  1398. function getRenderer(key) {
  1399. return renderers[key];
  1400. }
  1401. function getRegisteredRenderer() {
  1402. // Returns canvas by default for compatibility
  1403. if (renderers.canvas) {
  1404. return 'canvas';
  1405. } // Returns any renderer that is registered
  1406. for (var key in renderers) {
  1407. if (renderers[key]) {
  1408. return key;
  1409. }
  1410. }
  1411. return '';
  1412. }
  1413. function _typeof$4(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$4 = function _typeof(obj) { return typeof obj; }; } else { _typeof$4 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$4(obj); }
  1414. var AnimationItem = function AnimationItem() {
  1415. this._cbs = [];
  1416. this.name = '';
  1417. this.path = '';
  1418. this.isLoaded = false;
  1419. this.currentFrame = 0;
  1420. this.currentRawFrame = 0;
  1421. this.firstFrame = 0;
  1422. this.totalFrames = 0;
  1423. this.frameRate = 0;
  1424. this.frameMult = 0;
  1425. this.playSpeed = 1;
  1426. this.playDirection = 1;
  1427. this.playCount = 0;
  1428. this.animationData = {};
  1429. this.assets = [];
  1430. this.isPaused = true;
  1431. this.autoplay = false;
  1432. this.loop = true;
  1433. this.renderer = null;
  1434. this.animationID = createElementID();
  1435. this.assetsPath = '';
  1436. this.timeCompleted = 0;
  1437. this.segmentPos = 0;
  1438. this.isSubframeEnabled = getSubframeEnabled();
  1439. this.segments = [];
  1440. this._idle = true;
  1441. this._completedLoop = false;
  1442. this.projectInterface = ProjectInterface();
  1443. this.imagePreloader = new ImagePreloader();
  1444. this.audioController = audioControllerFactory();
  1445. this.markers = [];
  1446. this.configAnimation = this.configAnimation.bind(this);
  1447. this.onSetupError = this.onSetupError.bind(this);
  1448. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1449. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1450. this.expressionsPlugin = getExpressionsPlugin();
  1451. };
  1452. extendPrototype([BaseEvent], AnimationItem);
  1453. AnimationItem.prototype.setParams = function (params) {
  1454. if (params.wrapper || params.container) {
  1455. this.wrapper = params.wrapper || params.container;
  1456. }
  1457. var animType = 'svg';
  1458. if (params.animType) {
  1459. animType = params.animType;
  1460. } else if (params.renderer) {
  1461. animType = params.renderer;
  1462. }
  1463. var RendererClass = getRenderer(animType);
  1464. this.renderer = new RendererClass(this, params.rendererSettings);
  1465. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1466. this.renderer.setProjectInterface(this.projectInterface);
  1467. this.animType = animType;
  1468. if (params.loop === '' || params.loop === null || params.loop === undefined || params.loop === true) {
  1469. this.loop = true;
  1470. } else if (params.loop === false) {
  1471. this.loop = false;
  1472. } else {
  1473. this.loop = parseInt(params.loop, 10);
  1474. }
  1475. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1476. this.name = params.name ? params.name : '';
  1477. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1478. this.assetsPath = params.assetsPath;
  1479. this.initialSegment = params.initialSegment;
  1480. if (params.audioFactory) {
  1481. this.audioController.setAudioFactory(params.audioFactory);
  1482. }
  1483. if (params.animationData) {
  1484. this.setupAnimation(params.animationData);
  1485. } else if (params.path) {
  1486. if (params.path.lastIndexOf('\\') !== -1) {
  1487. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1488. } else {
  1489. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1490. }
  1491. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1492. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1493. dataManager.loadAnimation(params.path, this.configAnimation, this.onSetupError);
  1494. }
  1495. };
  1496. AnimationItem.prototype.onSetupError = function () {
  1497. this.trigger('data_failed');
  1498. };
  1499. AnimationItem.prototype.setupAnimation = function (data) {
  1500. dataManager.completeAnimation(data, this.configAnimation);
  1501. };
  1502. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1503. if (animationData) {
  1504. if (_typeof$4(animationData) !== 'object') {
  1505. animationData = JSON.parse(animationData);
  1506. }
  1507. }
  1508. var params = {
  1509. wrapper: wrapper,
  1510. animationData: animationData
  1511. };
  1512. var wrapperAttributes = wrapper.attributes;
  1513. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1514. ? wrapperAttributes.getNamedItem('data-animation-path').value : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1515. ? wrapperAttributes.getNamedItem('data-bm-path').value : wrapperAttributes.getNamedItem('bm-path') ? wrapperAttributes.getNamedItem('bm-path').value : '';
  1516. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1517. ? wrapperAttributes.getNamedItem('data-anim-type').value : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1518. ? wrapperAttributes.getNamedItem('data-bm-type').value : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1519. ? wrapperAttributes.getNamedItem('bm-type').value : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1520. ? wrapperAttributes.getNamedItem('data-bm-renderer').value : wrapperAttributes.getNamedItem('bm-renderer') ? wrapperAttributes.getNamedItem('bm-renderer').value : getRegisteredRenderer() || 'canvas';
  1521. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1522. ? wrapperAttributes.getNamedItem('data-anim-loop').value : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1523. ? wrapperAttributes.getNamedItem('data-bm-loop').value : wrapperAttributes.getNamedItem('bm-loop') ? wrapperAttributes.getNamedItem('bm-loop').value : '';
  1524. if (loop === 'false') {
  1525. params.loop = false;
  1526. } else if (loop === 'true') {
  1527. params.loop = true;
  1528. } else if (loop !== '') {
  1529. params.loop = parseInt(loop, 10);
  1530. }
  1531. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1532. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1533. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value : wrapperAttributes.getNamedItem('bm-autoplay') ? wrapperAttributes.getNamedItem('bm-autoplay').value : true;
  1534. params.autoplay = autoplay !== 'false';
  1535. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1536. ? wrapperAttributes.getNamedItem('data-name').value : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1537. ? wrapperAttributes.getNamedItem('data-bm-name').value : wrapperAttributes.getNamedItem('bm-name') ? wrapperAttributes.getNamedItem('bm-name').value : '';
  1538. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1539. ? wrapperAttributes.getNamedItem('data-anim-prerender').value : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1540. ? wrapperAttributes.getNamedItem('data-bm-prerender').value : wrapperAttributes.getNamedItem('bm-prerender') ? wrapperAttributes.getNamedItem('bm-prerender').value : '';
  1541. if (prerender === 'false') {
  1542. params.prerender = false;
  1543. }
  1544. if (!params.path) {
  1545. this.trigger('destroy');
  1546. } else {
  1547. this.setParams(params);
  1548. }
  1549. };
  1550. AnimationItem.prototype.includeLayers = function (data) {
  1551. if (data.op > this.animationData.op) {
  1552. this.animationData.op = data.op;
  1553. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1554. }
  1555. var layers = this.animationData.layers;
  1556. var i;
  1557. var len = layers.length;
  1558. var newLayers = data.layers;
  1559. var j;
  1560. var jLen = newLayers.length;
  1561. for (j = 0; j < jLen; j += 1) {
  1562. i = 0;
  1563. while (i < len) {
  1564. if (layers[i].id === newLayers[j].id) {
  1565. layers[i] = newLayers[j];
  1566. break;
  1567. }
  1568. i += 1;
  1569. }
  1570. }
  1571. if (data.chars || data.fonts) {
  1572. this.renderer.globalData.fontManager.addChars(data.chars);
  1573. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1574. }
  1575. if (data.assets) {
  1576. len = data.assets.length;
  1577. for (i = 0; i < len; i += 1) {
  1578. this.animationData.assets.push(data.assets[i]);
  1579. }
  1580. }
  1581. this.animationData.__complete = false;
  1582. dataManager.completeAnimation(this.animationData, this.onSegmentComplete);
  1583. };
  1584. AnimationItem.prototype.onSegmentComplete = function (data) {
  1585. this.animationData = data;
  1586. var expressionsPlugin = getExpressionsPlugin();
  1587. if (expressionsPlugin) {
  1588. expressionsPlugin.initExpressions(this);
  1589. }
  1590. this.loadNextSegment();
  1591. };
  1592. AnimationItem.prototype.loadNextSegment = function () {
  1593. var segments = this.animationData.segments;
  1594. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1595. this.trigger('data_ready');
  1596. this.timeCompleted = this.totalFrames;
  1597. return;
  1598. }
  1599. var segment = segments.shift();
  1600. this.timeCompleted = segment.time * this.frameRate;
  1601. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1602. this.segmentPos += 1;
  1603. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1604. this.trigger('data_failed');
  1605. }.bind(this));
  1606. };
  1607. AnimationItem.prototype.loadSegments = function () {
  1608. var segments = this.animationData.segments;
  1609. if (!segments) {
  1610. this.timeCompleted = this.totalFrames;
  1611. }
  1612. this.loadNextSegment();
  1613. };
  1614. AnimationItem.prototype.imagesLoaded = function () {
  1615. this.trigger('loaded_images');
  1616. this.checkLoaded();
  1617. };
  1618. AnimationItem.prototype.preloadImages = function () {
  1619. this.imagePreloader.setAssetsPath(this.assetsPath);
  1620. this.imagePreloader.setPath(this.path);
  1621. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1622. };
  1623. AnimationItem.prototype.configAnimation = function (animData) {
  1624. if (!this.renderer) {
  1625. return;
  1626. }
  1627. try {
  1628. this.animationData = animData;
  1629. if (this.initialSegment) {
  1630. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1631. this.firstFrame = Math.round(this.initialSegment[0]);
  1632. } else {
  1633. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1634. this.firstFrame = Math.round(this.animationData.ip);
  1635. }
  1636. this.renderer.configAnimation(animData);
  1637. if (!animData.assets) {
  1638. animData.assets = [];
  1639. }
  1640. this.assets = this.animationData.assets;
  1641. this.frameRate = this.animationData.fr;
  1642. this.frameMult = this.animationData.fr / 1000;
  1643. this.renderer.searchExtraCompositions(animData.assets);
  1644. this.markers = markerParser(animData.markers || []);
  1645. this.trigger('config_ready');
  1646. this.preloadImages();
  1647. this.loadSegments();
  1648. this.updaFrameModifier();
  1649. this.waitForFontsLoaded();
  1650. if (this.isPaused) {
  1651. this.audioController.pause();
  1652. }
  1653. } catch (error) {
  1654. this.triggerConfigError(error);
  1655. }
  1656. };
  1657. AnimationItem.prototype.waitForFontsLoaded = function () {
  1658. if (!this.renderer) {
  1659. return;
  1660. }
  1661. if (this.renderer.globalData.fontManager.isLoaded) {
  1662. this.checkLoaded();
  1663. } else {
  1664. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1665. }
  1666. };
  1667. AnimationItem.prototype.checkLoaded = function () {
  1668. if (!this.isLoaded && this.renderer.globalData.fontManager.isLoaded && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas') && this.imagePreloader.loadedFootages()) {
  1669. this.isLoaded = true;
  1670. var expressionsPlugin = getExpressionsPlugin();
  1671. if (expressionsPlugin) {
  1672. expressionsPlugin.initExpressions(this);
  1673. }
  1674. this.renderer.initItems();
  1675. setTimeout(function () {
  1676. this.trigger('DOMLoaded');
  1677. }.bind(this), 0);
  1678. this.gotoFrame();
  1679. if (this.autoplay) {
  1680. this.play();
  1681. }
  1682. }
  1683. };
  1684. AnimationItem.prototype.resize = function (width, height) {
  1685. // Adding this validation for backwards compatibility in case an event object was being passed down
  1686. var _width = typeof width === 'number' ? width : undefined;
  1687. var _height = typeof height === 'number' ? height : undefined;
  1688. this.renderer.updateContainerSize(_width, _height);
  1689. };
  1690. AnimationItem.prototype.setSubframe = function (flag) {
  1691. this.isSubframeEnabled = !!flag;
  1692. };
  1693. AnimationItem.prototype.gotoFrame = function () {
  1694. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1695. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1696. this.currentFrame = this.timeCompleted;
  1697. }
  1698. this.trigger('enterFrame');
  1699. this.renderFrame();
  1700. this.trigger('drawnFrame');
  1701. };
  1702. AnimationItem.prototype.renderFrame = function () {
  1703. if (this.isLoaded === false || !this.renderer) {
  1704. return;
  1705. }
  1706. try {
  1707. if (this.expressionsPlugin) {
  1708. this.expressionsPlugin.resetFrame();
  1709. }
  1710. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1711. } catch (error) {
  1712. this.triggerRenderFrameError(error);
  1713. }
  1714. };
  1715. AnimationItem.prototype.play = function (name) {
  1716. if (name && this.name !== name) {
  1717. return;
  1718. }
  1719. if (this.isPaused === true) {
  1720. this.isPaused = false;
  1721. this.trigger('_play');
  1722. this.audioController.resume();
  1723. if (this._idle) {
  1724. this._idle = false;
  1725. this.trigger('_active');
  1726. }
  1727. }
  1728. };
  1729. AnimationItem.prototype.pause = function (name) {
  1730. if (name && this.name !== name) {
  1731. return;
  1732. }
  1733. if (this.isPaused === false) {
  1734. this.isPaused = true;
  1735. this.trigger('_pause');
  1736. this._idle = true;
  1737. this.trigger('_idle');
  1738. this.audioController.pause();
  1739. }
  1740. };
  1741. AnimationItem.prototype.togglePause = function (name) {
  1742. if (name && this.name !== name) {
  1743. return;
  1744. }
  1745. if (this.isPaused === true) {
  1746. this.play();
  1747. } else {
  1748. this.pause();
  1749. }
  1750. };
  1751. AnimationItem.prototype.stop = function (name) {
  1752. if (name && this.name !== name) {
  1753. return;
  1754. }
  1755. this.pause();
  1756. this.playCount = 0;
  1757. this._completedLoop = false;
  1758. this.setCurrentRawFrameValue(0);
  1759. };
  1760. AnimationItem.prototype.getMarkerData = function (markerName) {
  1761. var marker;
  1762. for (var i = 0; i < this.markers.length; i += 1) {
  1763. marker = this.markers[i];
  1764. if (marker.payload && marker.payload.name === markerName) {
  1765. return marker;
  1766. }
  1767. }
  1768. return null;
  1769. };
  1770. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1771. if (name && this.name !== name) {
  1772. return;
  1773. }
  1774. var numValue = Number(value);
  1775. if (isNaN(numValue)) {
  1776. var marker = this.getMarkerData(value);
  1777. if (marker) {
  1778. this.goToAndStop(marker.time, true);
  1779. }
  1780. } else if (isFrame) {
  1781. this.setCurrentRawFrameValue(value);
  1782. } else {
  1783. this.setCurrentRawFrameValue(value * this.frameModifier);
  1784. }
  1785. this.pause();
  1786. };
  1787. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1788. if (name && this.name !== name) {
  1789. return;
  1790. }
  1791. var numValue = Number(value);
  1792. if (isNaN(numValue)) {
  1793. var marker = this.getMarkerData(value);
  1794. if (marker) {
  1795. if (!marker.duration) {
  1796. this.goToAndStop(marker.time, true);
  1797. } else {
  1798. this.playSegments([marker.time, marker.time + marker.duration], true);
  1799. }
  1800. }
  1801. } else {
  1802. this.goToAndStop(numValue, isFrame, name);
  1803. }
  1804. this.play();
  1805. };
  1806. AnimationItem.prototype.advanceTime = function (value) {
  1807. if (this.isPaused === true || this.isLoaded === false) {
  1808. return;
  1809. }
  1810. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1811. var _isComplete = false; // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1812. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1813. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1814. if (!this.loop || this.playCount === this.loop) {
  1815. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1816. _isComplete = true;
  1817. nextValue = this.totalFrames - 1;
  1818. }
  1819. } else if (nextValue >= this.totalFrames) {
  1820. this.playCount += 1;
  1821. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1822. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1823. this._completedLoop = true;
  1824. this.trigger('loopComplete');
  1825. }
  1826. } else {
  1827. this.setCurrentRawFrameValue(nextValue);
  1828. }
  1829. } else if (nextValue < 0) {
  1830. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1831. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) {
  1832. // eslint-disable-line no-plusplus
  1833. this.setCurrentRawFrameValue(this.totalFrames + nextValue % this.totalFrames);
  1834. if (!this._completedLoop) {
  1835. this._completedLoop = true;
  1836. } else {
  1837. this.trigger('loopComplete');
  1838. }
  1839. } else {
  1840. _isComplete = true;
  1841. nextValue = 0;
  1842. }
  1843. }
  1844. } else {
  1845. this.setCurrentRawFrameValue(nextValue);
  1846. }
  1847. if (_isComplete) {
  1848. this.setCurrentRawFrameValue(nextValue);
  1849. this.pause();
  1850. this.trigger('complete');
  1851. }
  1852. };
  1853. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1854. this.playCount = 0;
  1855. if (arr[1] < arr[0]) {
  1856. if (this.frameModifier > 0) {
  1857. if (this.playSpeed < 0) {
  1858. this.setSpeed(-this.playSpeed);
  1859. } else {
  1860. this.setDirection(-1);
  1861. }
  1862. }
  1863. this.totalFrames = arr[0] - arr[1];
  1864. this.timeCompleted = this.totalFrames;
  1865. this.firstFrame = arr[1];
  1866. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1867. } else if (arr[1] > arr[0]) {
  1868. if (this.frameModifier < 0) {
  1869. if (this.playSpeed < 0) {
  1870. this.setSpeed(-this.playSpeed);
  1871. } else {
  1872. this.setDirection(1);
  1873. }
  1874. }
  1875. this.totalFrames = arr[1] - arr[0];
  1876. this.timeCompleted = this.totalFrames;
  1877. this.firstFrame = arr[0];
  1878. this.setCurrentRawFrameValue(0.001 + offset);
  1879. }
  1880. this.trigger('segmentStart');
  1881. };
  1882. AnimationItem.prototype.setSegment = function (init, end) {
  1883. var pendingFrame = -1;
  1884. if (this.isPaused) {
  1885. if (this.currentRawFrame + this.firstFrame < init) {
  1886. pendingFrame = init;
  1887. } else if (this.currentRawFrame + this.firstFrame > end) {
  1888. pendingFrame = end - init;
  1889. }
  1890. }
  1891. this.firstFrame = init;
  1892. this.totalFrames = end - init;
  1893. this.timeCompleted = this.totalFrames;
  1894. if (pendingFrame !== -1) {
  1895. this.goToAndStop(pendingFrame, true);
  1896. }
  1897. };
  1898. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1899. if (forceFlag) {
  1900. this.segments.length = 0;
  1901. }
  1902. if (_typeof$4(arr[0]) === 'object') {
  1903. var i;
  1904. var len = arr.length;
  1905. for (i = 0; i < len; i += 1) {
  1906. this.segments.push(arr[i]);
  1907. }
  1908. } else {
  1909. this.segments.push(arr);
  1910. }
  1911. if (this.segments.length && forceFlag) {
  1912. this.adjustSegment(this.segments.shift(), 0);
  1913. }
  1914. if (this.isPaused) {
  1915. this.play();
  1916. }
  1917. };
  1918. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1919. this.segments.length = 0;
  1920. this.segments.push([this.animationData.ip, this.animationData.op]);
  1921. if (forceFlag) {
  1922. this.checkSegments(0);
  1923. }
  1924. };
  1925. AnimationItem.prototype.checkSegments = function (offset) {
  1926. if (this.segments.length) {
  1927. this.adjustSegment(this.segments.shift(), offset);
  1928. return true;
  1929. }
  1930. return false;
  1931. };
  1932. AnimationItem.prototype.destroy = function (name) {
  1933. if (name && this.name !== name || !this.renderer) {
  1934. return;
  1935. }
  1936. this.renderer.destroy();
  1937. this.imagePreloader.destroy();
  1938. this.trigger('destroy');
  1939. this._cbs = null;
  1940. this.onEnterFrame = null;
  1941. this.onLoopComplete = null;
  1942. this.onComplete = null;
  1943. this.onSegmentStart = null;
  1944. this.onDestroy = null;
  1945. this.renderer = null;
  1946. this.expressionsPlugin = null;
  1947. this.imagePreloader = null;
  1948. this.projectInterface = null;
  1949. };
  1950. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1951. this.currentRawFrame = value;
  1952. this.gotoFrame();
  1953. };
  1954. AnimationItem.prototype.setSpeed = function (val) {
  1955. this.playSpeed = val;
  1956. this.updaFrameModifier();
  1957. };
  1958. AnimationItem.prototype.setDirection = function (val) {
  1959. this.playDirection = val < 0 ? -1 : 1;
  1960. this.updaFrameModifier();
  1961. };
  1962. AnimationItem.prototype.setLoop = function (isLooping) {
  1963. this.loop = isLooping;
  1964. };
  1965. AnimationItem.prototype.setVolume = function (val, name) {
  1966. if (name && this.name !== name) {
  1967. return;
  1968. }
  1969. this.audioController.setVolume(val);
  1970. };
  1971. AnimationItem.prototype.getVolume = function () {
  1972. return this.audioController.getVolume();
  1973. };
  1974. AnimationItem.prototype.mute = function (name) {
  1975. if (name && this.name !== name) {
  1976. return;
  1977. }
  1978. this.audioController.mute();
  1979. };
  1980. AnimationItem.prototype.unmute = function (name) {
  1981. if (name && this.name !== name) {
  1982. return;
  1983. }
  1984. this.audioController.unmute();
  1985. };
  1986. AnimationItem.prototype.updaFrameModifier = function () {
  1987. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1988. this.audioController.setRate(this.playSpeed * this.playDirection);
  1989. };
  1990. AnimationItem.prototype.getPath = function () {
  1991. return this.path;
  1992. };
  1993. AnimationItem.prototype.getAssetsPath = function (assetData) {
  1994. var path = '';
  1995. if (assetData.e) {
  1996. path = assetData.p;
  1997. } else if (this.assetsPath) {
  1998. var imagePath = assetData.p;
  1999. if (imagePath.indexOf('images/') !== -1) {
  2000. imagePath = imagePath.split('/')[1];
  2001. }
  2002. path = this.assetsPath + imagePath;
  2003. } else {
  2004. path = this.path;
  2005. path += assetData.u ? assetData.u : '';
  2006. path += assetData.p;
  2007. }
  2008. return path;
  2009. };
  2010. AnimationItem.prototype.getAssetData = function (id) {
  2011. var i = 0;
  2012. var len = this.assets.length;
  2013. while (i < len) {
  2014. if (id === this.assets[i].id) {
  2015. return this.assets[i];
  2016. }
  2017. i += 1;
  2018. }
  2019. return null;
  2020. };
  2021. AnimationItem.prototype.hide = function () {
  2022. this.renderer.hide();
  2023. };
  2024. AnimationItem.prototype.show = function () {
  2025. this.renderer.show();
  2026. };
  2027. AnimationItem.prototype.getDuration = function (isFrame) {
  2028. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  2029. };
  2030. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  2031. try {
  2032. var element = this.renderer.getElementByPath(path);
  2033. element.updateDocumentData(documentData, index);
  2034. } catch (error) {// TODO: decide how to handle catch case
  2035. }
  2036. };
  2037. AnimationItem.prototype.trigger = function (name) {
  2038. if (this._cbs && this._cbs[name]) {
  2039. switch (name) {
  2040. case 'enterFrame':
  2041. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  2042. break;
  2043. case 'drawnFrame':
  2044. this.drawnFrameEvent.currentTime = this.currentFrame;
  2045. this.drawnFrameEvent.totalTime = this.totalFrames;
  2046. this.drawnFrameEvent.direction = this.frameModifier;
  2047. this.triggerEvent(name, this.drawnFrameEvent);
  2048. break;
  2049. case 'loopComplete':
  2050. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2051. break;
  2052. case 'complete':
  2053. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  2054. break;
  2055. case 'segmentStart':
  2056. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2057. break;
  2058. case 'destroy':
  2059. this.triggerEvent(name, new BMDestroyEvent(name, this));
  2060. break;
  2061. default:
  2062. this.triggerEvent(name);
  2063. }
  2064. }
  2065. if (name === 'enterFrame' && this.onEnterFrame) {
  2066. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  2067. }
  2068. if (name === 'loopComplete' && this.onLoopComplete) {
  2069. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2070. }
  2071. if (name === 'complete' && this.onComplete) {
  2072. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  2073. }
  2074. if (name === 'segmentStart' && this.onSegmentStart) {
  2075. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2076. }
  2077. if (name === 'destroy' && this.onDestroy) {
  2078. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  2079. }
  2080. };
  2081. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  2082. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2083. this.triggerEvent('error', error);
  2084. if (this.onError) {
  2085. this.onError.call(this, error);
  2086. }
  2087. };
  2088. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2089. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2090. this.triggerEvent('error', error);
  2091. if (this.onError) {
  2092. this.onError.call(this, error);
  2093. }
  2094. };
  2095. var animationManager = function () {
  2096. var moduleOb = {};
  2097. var registeredAnimations = [];
  2098. var initTime = 0;
  2099. var len = 0;
  2100. var playingAnimationsNum = 0;
  2101. var _stopped = true;
  2102. var _isFrozen = false;
  2103. function removeElement(ev) {
  2104. var i = 0;
  2105. var animItem = ev.target;
  2106. while (i < len) {
  2107. if (registeredAnimations[i].animation === animItem) {
  2108. registeredAnimations.splice(i, 1);
  2109. i -= 1;
  2110. len -= 1;
  2111. if (!animItem.isPaused) {
  2112. subtractPlayingCount();
  2113. }
  2114. }
  2115. i += 1;
  2116. }
  2117. }
  2118. function registerAnimation(element, animationData) {
  2119. if (!element) {
  2120. return null;
  2121. }
  2122. var i = 0;
  2123. while (i < len) {
  2124. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2125. return registeredAnimations[i].animation;
  2126. }
  2127. i += 1;
  2128. }
  2129. var animItem = new AnimationItem();
  2130. setupAnimation(animItem, element);
  2131. animItem.setData(element, animationData);
  2132. return animItem;
  2133. }
  2134. function getRegisteredAnimations() {
  2135. var i;
  2136. var lenAnims = registeredAnimations.length;
  2137. var animations = [];
  2138. for (i = 0; i < lenAnims; i += 1) {
  2139. animations.push(registeredAnimations[i].animation);
  2140. }
  2141. return animations;
  2142. }
  2143. function addPlayingCount() {
  2144. playingAnimationsNum += 1;
  2145. activate();
  2146. }
  2147. function subtractPlayingCount() {
  2148. playingAnimationsNum -= 1;
  2149. }
  2150. function setupAnimation(animItem, element) {
  2151. animItem.addEventListener('destroy', removeElement);
  2152. animItem.addEventListener('_active', addPlayingCount);
  2153. animItem.addEventListener('_idle', subtractPlayingCount);
  2154. registeredAnimations.push({
  2155. elem: element,
  2156. animation: animItem
  2157. });
  2158. len += 1;
  2159. }
  2160. function loadAnimation(params) {
  2161. var animItem = new AnimationItem();
  2162. setupAnimation(animItem, null);
  2163. animItem.setParams(params);
  2164. return animItem;
  2165. }
  2166. function setSpeed(val, animation) {
  2167. var i;
  2168. for (i = 0; i < len; i += 1) {
  2169. registeredAnimations[i].animation.setSpeed(val, animation);
  2170. }
  2171. }
  2172. function setDirection(val, animation) {
  2173. var i;
  2174. for (i = 0; i < len; i += 1) {
  2175. registeredAnimations[i].animation.setDirection(val, animation);
  2176. }
  2177. }
  2178. function play(animation) {
  2179. var i;
  2180. for (i = 0; i < len; i += 1) {
  2181. registeredAnimations[i].animation.play(animation);
  2182. }
  2183. }
  2184. function resume(nowTime) {
  2185. var elapsedTime = nowTime - initTime;
  2186. var i;
  2187. for (i = 0; i < len; i += 1) {
  2188. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2189. }
  2190. initTime = nowTime;
  2191. if (playingAnimationsNum && !_isFrozen) {
  2192. window.requestAnimationFrame(resume);
  2193. } else {
  2194. _stopped = true;
  2195. }
  2196. }
  2197. function first(nowTime) {
  2198. initTime = nowTime;
  2199. window.requestAnimationFrame(resume);
  2200. }
  2201. function pause(animation) {
  2202. var i;
  2203. for (i = 0; i < len; i += 1) {
  2204. registeredAnimations[i].animation.pause(animation);
  2205. }
  2206. }
  2207. function goToAndStop(value, isFrame, animation) {
  2208. var i;
  2209. for (i = 0; i < len; i += 1) {
  2210. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2211. }
  2212. }
  2213. function stop(animation) {
  2214. var i;
  2215. for (i = 0; i < len; i += 1) {
  2216. registeredAnimations[i].animation.stop(animation);
  2217. }
  2218. }
  2219. function togglePause(animation) {
  2220. var i;
  2221. for (i = 0; i < len; i += 1) {
  2222. registeredAnimations[i].animation.togglePause(animation);
  2223. }
  2224. }
  2225. function destroy(animation) {
  2226. var i;
  2227. for (i = len - 1; i >= 0; i -= 1) {
  2228. registeredAnimations[i].animation.destroy(animation);
  2229. }
  2230. }
  2231. function searchAnimations(animationData, standalone, renderer) {
  2232. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')), [].slice.call(document.getElementsByClassName('bodymovin')));
  2233. var i;
  2234. var lenAnims = animElements.length;
  2235. for (i = 0; i < lenAnims; i += 1) {
  2236. if (renderer) {
  2237. animElements[i].setAttribute('data-bm-type', renderer);
  2238. }
  2239. registerAnimation(animElements[i], animationData);
  2240. }
  2241. if (standalone && lenAnims === 0) {
  2242. if (!renderer) {
  2243. renderer = 'svg';
  2244. }
  2245. var body = document.getElementsByTagName('body')[0];
  2246. body.innerText = '';
  2247. var div = createTag('div');
  2248. div.style.width = '100%';
  2249. div.style.height = '100%';
  2250. div.setAttribute('data-bm-type', renderer);
  2251. body.appendChild(div);
  2252. registerAnimation(div, animationData);
  2253. }
  2254. }
  2255. function resize() {
  2256. var i;
  2257. for (i = 0; i < len; i += 1) {
  2258. registeredAnimations[i].animation.resize();
  2259. }
  2260. }
  2261. function activate() {
  2262. if (!_isFrozen && playingAnimationsNum) {
  2263. if (_stopped) {
  2264. window.requestAnimationFrame(first);
  2265. _stopped = false;
  2266. }
  2267. }
  2268. }
  2269. function freeze() {
  2270. _isFrozen = true;
  2271. }
  2272. function unfreeze() {
  2273. _isFrozen = false;
  2274. activate();
  2275. }
  2276. function setVolume(val, animation) {
  2277. var i;
  2278. for (i = 0; i < len; i += 1) {
  2279. registeredAnimations[i].animation.setVolume(val, animation);
  2280. }
  2281. }
  2282. function mute(animation) {
  2283. var i;
  2284. for (i = 0; i < len; i += 1) {
  2285. registeredAnimations[i].animation.mute(animation);
  2286. }
  2287. }
  2288. function unmute(animation) {
  2289. var i;
  2290. for (i = 0; i < len; i += 1) {
  2291. registeredAnimations[i].animation.unmute(animation);
  2292. }
  2293. }
  2294. moduleOb.registerAnimation = registerAnimation;
  2295. moduleOb.loadAnimation = loadAnimation;
  2296. moduleOb.setSpeed = setSpeed;
  2297. moduleOb.setDirection = setDirection;
  2298. moduleOb.play = play;
  2299. moduleOb.pause = pause;
  2300. moduleOb.stop = stop;
  2301. moduleOb.togglePause = togglePause;
  2302. moduleOb.searchAnimations = searchAnimations;
  2303. moduleOb.resize = resize; // moduleOb.start = start;
  2304. moduleOb.goToAndStop = goToAndStop;
  2305. moduleOb.destroy = destroy;
  2306. moduleOb.freeze = freeze;
  2307. moduleOb.unfreeze = unfreeze;
  2308. moduleOb.setVolume = setVolume;
  2309. moduleOb.mute = mute;
  2310. moduleOb.unmute = unmute;
  2311. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2312. return moduleOb;
  2313. }();
  2314. /* eslint-disable */
  2315. var BezierFactory = function () {
  2316. /**
  2317. * BezierEasing - use bezier curve for transition easing function
  2318. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2319. *
  2320. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2321. * Usage:
  2322. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2323. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2324. *
  2325. */
  2326. var ob = {};
  2327. ob.getBezierEasing = getBezierEasing;
  2328. var beziers = {};
  2329. function getBezierEasing(a, b, c, d, nm) {
  2330. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2331. if (beziers[str]) {
  2332. return beziers[str];
  2333. }
  2334. var bezEasing = new BezierEasing([a, b, c, d]);
  2335. beziers[str] = bezEasing;
  2336. return bezEasing;
  2337. } // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2338. var NEWTON_ITERATIONS = 4;
  2339. var NEWTON_MIN_SLOPE = 0.001;
  2340. var SUBDIVISION_PRECISION = 0.0000001;
  2341. var SUBDIVISION_MAX_ITERATIONS = 10;
  2342. var kSplineTableSize = 11;
  2343. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2344. var float32ArraySupported = typeof Float32Array === 'function';
  2345. function A(aA1, aA2) {
  2346. return 1.0 - 3.0 * aA2 + 3.0 * aA1;
  2347. }
  2348. function B(aA1, aA2) {
  2349. return 3.0 * aA2 - 6.0 * aA1;
  2350. }
  2351. function C(aA1) {
  2352. return 3.0 * aA1;
  2353. } // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2354. function calcBezier(aT, aA1, aA2) {
  2355. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2356. } // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2357. function getSlope(aT, aA1, aA2) {
  2358. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2359. }
  2360. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2361. var currentX,
  2362. currentT,
  2363. i = 0;
  2364. do {
  2365. currentT = aA + (aB - aA) / 2.0;
  2366. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2367. if (currentX > 0.0) {
  2368. aB = currentT;
  2369. } else {
  2370. aA = currentT;
  2371. }
  2372. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2373. return currentT;
  2374. }
  2375. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2376. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2377. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2378. if (currentSlope === 0.0) return aGuessT;
  2379. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2380. aGuessT -= currentX / currentSlope;
  2381. }
  2382. return aGuessT;
  2383. }
  2384. /**
  2385. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2386. */
  2387. function BezierEasing(points) {
  2388. this._p = points;
  2389. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2390. this._precomputed = false;
  2391. this.get = this.get.bind(this);
  2392. }
  2393. BezierEasing.prototype = {
  2394. get: function get(x) {
  2395. var mX1 = this._p[0],
  2396. mY1 = this._p[1],
  2397. mX2 = this._p[2],
  2398. mY2 = this._p[3];
  2399. if (!this._precomputed) this._precompute();
  2400. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2401. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2402. if (x === 0) return 0;
  2403. if (x === 1) return 1;
  2404. return calcBezier(this._getTForX(x), mY1, mY2);
  2405. },
  2406. // Private part
  2407. _precompute: function _precompute() {
  2408. var mX1 = this._p[0],
  2409. mY1 = this._p[1],
  2410. mX2 = this._p[2],
  2411. mY2 = this._p[3];
  2412. this._precomputed = true;
  2413. if (mX1 !== mY1 || mX2 !== mY2) {
  2414. this._calcSampleValues();
  2415. }
  2416. },
  2417. _calcSampleValues: function _calcSampleValues() {
  2418. var mX1 = this._p[0],
  2419. mX2 = this._p[2];
  2420. for (var i = 0; i < kSplineTableSize; ++i) {
  2421. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2422. }
  2423. },
  2424. /**
  2425. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2426. */
  2427. _getTForX: function _getTForX(aX) {
  2428. var mX1 = this._p[0],
  2429. mX2 = this._p[2],
  2430. mSampleValues = this._mSampleValues;
  2431. var intervalStart = 0.0;
  2432. var currentSample = 1;
  2433. var lastSample = kSplineTableSize - 1;
  2434. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2435. intervalStart += kSampleStepSize;
  2436. }
  2437. --currentSample; // Interpolate to provide an initial guess for t
  2438. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2439. var guessForT = intervalStart + dist * kSampleStepSize;
  2440. var initialSlope = getSlope(guessForT, mX1, mX2);
  2441. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2442. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2443. }
  2444. if (initialSlope === 0.0) {
  2445. return guessForT;
  2446. }
  2447. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2448. }
  2449. };
  2450. return ob;
  2451. }();
  2452. var pooling = function () {
  2453. function _double(arr) {
  2454. return arr.concat(createSizedArray(arr.length));
  2455. }
  2456. return {
  2457. "double": _double
  2458. };
  2459. }();
  2460. var poolFactory = function () {
  2461. return function (initialLength, _create, _release) {
  2462. var _length = 0;
  2463. var _maxLength = initialLength;
  2464. var pool = createSizedArray(_maxLength);
  2465. var ob = {
  2466. newElement: newElement,
  2467. release: release
  2468. };
  2469. function newElement() {
  2470. var element;
  2471. if (_length) {
  2472. _length -= 1;
  2473. element = pool[_length];
  2474. } else {
  2475. element = _create();
  2476. }
  2477. return element;
  2478. }
  2479. function release(element) {
  2480. if (_length === _maxLength) {
  2481. pool = pooling["double"](pool);
  2482. _maxLength *= 2;
  2483. }
  2484. if (_release) {
  2485. _release(element);
  2486. }
  2487. pool[_length] = element;
  2488. _length += 1;
  2489. }
  2490. return ob;
  2491. };
  2492. }();
  2493. var bezierLengthPool = function () {
  2494. function create() {
  2495. return {
  2496. addedLength: 0,
  2497. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2498. lengths: createTypedArray('float32', getDefaultCurveSegments())
  2499. };
  2500. }
  2501. return poolFactory(8, create);
  2502. }();
  2503. var segmentsLengthPool = function () {
  2504. function create() {
  2505. return {
  2506. lengths: [],
  2507. totalLength: 0
  2508. };
  2509. }
  2510. function release(element) {
  2511. var i;
  2512. var len = element.lengths.length;
  2513. for (i = 0; i < len; i += 1) {
  2514. bezierLengthPool.release(element.lengths[i]);
  2515. }
  2516. element.lengths.length = 0;
  2517. }
  2518. return poolFactory(8, create, release);
  2519. }();
  2520. function bezFunction() {
  2521. var math = Math;
  2522. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2523. var det1 = x1 * y2 + y1 * x3 + x2 * y3 - x3 * y2 - y3 * x1 - x2 * y1;
  2524. return det1 > -0.001 && det1 < 0.001;
  2525. }
  2526. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2527. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2528. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2529. }
  2530. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2531. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2532. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2533. var diffDist;
  2534. if (dist1 > dist2) {
  2535. if (dist1 > dist3) {
  2536. diffDist = dist1 - dist2 - dist3;
  2537. } else {
  2538. diffDist = dist3 - dist2 - dist1;
  2539. }
  2540. } else if (dist3 > dist2) {
  2541. diffDist = dist3 - dist2 - dist1;
  2542. } else {
  2543. diffDist = dist2 - dist1 - dist3;
  2544. }
  2545. return diffDist > -0.0001 && diffDist < 0.0001;
  2546. }
  2547. var getBezierLength = function () {
  2548. return function (pt1, pt2, pt3, pt4) {
  2549. var curveSegments = getDefaultCurveSegments();
  2550. var k;
  2551. var i;
  2552. var len;
  2553. var ptCoord;
  2554. var perc;
  2555. var addedLength = 0;
  2556. var ptDistance;
  2557. var point = [];
  2558. var lastPoint = [];
  2559. var lengthData = bezierLengthPool.newElement();
  2560. len = pt3.length;
  2561. for (k = 0; k < curveSegments; k += 1) {
  2562. perc = k / (curveSegments - 1);
  2563. ptDistance = 0;
  2564. for (i = 0; i < len; i += 1) {
  2565. 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];
  2566. point[i] = ptCoord;
  2567. if (lastPoint[i] !== null) {
  2568. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2569. }
  2570. lastPoint[i] = point[i];
  2571. }
  2572. if (ptDistance) {
  2573. ptDistance = bmSqrt(ptDistance);
  2574. addedLength += ptDistance;
  2575. }
  2576. lengthData.percents[k] = perc;
  2577. lengthData.lengths[k] = addedLength;
  2578. }
  2579. lengthData.addedLength = addedLength;
  2580. return lengthData;
  2581. };
  2582. }();
  2583. function getSegmentsLength(shapeData) {
  2584. var segmentsLength = segmentsLengthPool.newElement();
  2585. var closed = shapeData.c;
  2586. var pathV = shapeData.v;
  2587. var pathO = shapeData.o;
  2588. var pathI = shapeData.i;
  2589. var i;
  2590. var len = shapeData._length;
  2591. var lengths = segmentsLength.lengths;
  2592. var totalLength = 0;
  2593. for (i = 0; i < len - 1; i += 1) {
  2594. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2595. totalLength += lengths[i].addedLength;
  2596. }
  2597. if (closed && len) {
  2598. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2599. totalLength += lengths[i].addedLength;
  2600. }
  2601. segmentsLength.totalLength = totalLength;
  2602. return segmentsLength;
  2603. }
  2604. function BezierData(length) {
  2605. this.segmentLength = 0;
  2606. this.points = new Array(length);
  2607. }
  2608. function PointData(partial, point) {
  2609. this.partialLength = partial;
  2610. this.point = point;
  2611. }
  2612. var buildBezierData = function () {
  2613. var storedData = {};
  2614. return function (pt1, pt2, pt3, pt4) {
  2615. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2616. if (!storedData[bezierName]) {
  2617. var curveSegments = getDefaultCurveSegments();
  2618. var k;
  2619. var i;
  2620. var len;
  2621. var ptCoord;
  2622. var perc;
  2623. var addedLength = 0;
  2624. var ptDistance;
  2625. var point;
  2626. var lastPoint = null;
  2627. 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])) {
  2628. curveSegments = 2;
  2629. }
  2630. var bezierData = new BezierData(curveSegments);
  2631. len = pt3.length;
  2632. for (k = 0; k < curveSegments; k += 1) {
  2633. point = createSizedArray(len);
  2634. perc = k / (curveSegments - 1);
  2635. ptDistance = 0;
  2636. for (i = 0; i < len; i += 1) {
  2637. 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];
  2638. point[i] = ptCoord;
  2639. if (lastPoint !== null) {
  2640. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2641. }
  2642. }
  2643. ptDistance = bmSqrt(ptDistance);
  2644. addedLength += ptDistance;
  2645. bezierData.points[k] = new PointData(ptDistance, point);
  2646. lastPoint = point;
  2647. }
  2648. bezierData.segmentLength = addedLength;
  2649. storedData[bezierName] = bezierData;
  2650. }
  2651. return storedData[bezierName];
  2652. };
  2653. }();
  2654. function getDistancePerc(perc, bezierData) {
  2655. var percents = bezierData.percents;
  2656. var lengths = bezierData.lengths;
  2657. var len = percents.length;
  2658. var initPos = bmFloor((len - 1) * perc);
  2659. var lengthPos = perc * bezierData.addedLength;
  2660. var lPerc = 0;
  2661. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2662. return percents[initPos];
  2663. }
  2664. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2665. var flag = true;
  2666. while (flag) {
  2667. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2668. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2669. flag = false;
  2670. } else {
  2671. initPos += dir;
  2672. }
  2673. if (initPos < 0 || initPos >= len - 1) {
  2674. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2675. if (initPos === len - 1) {
  2676. return percents[initPos];
  2677. }
  2678. flag = false;
  2679. }
  2680. }
  2681. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2682. }
  2683. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2684. var t1 = getDistancePerc(percent, bezierData);
  2685. var u1 = 1 - t1;
  2686. 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;
  2687. 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;
  2688. return [ptX, ptY];
  2689. }
  2690. var bezierSegmentPoints = createTypedArray('float32', 8);
  2691. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2692. if (startPerc < 0) {
  2693. startPerc = 0;
  2694. } else if (startPerc > 1) {
  2695. startPerc = 1;
  2696. }
  2697. var t0 = getDistancePerc(startPerc, bezierData);
  2698. endPerc = endPerc > 1 ? 1 : endPerc;
  2699. var t1 = getDistancePerc(endPerc, bezierData);
  2700. var i;
  2701. var len = pt1.length;
  2702. var u0 = 1 - t0;
  2703. var u1 = 1 - t1;
  2704. var u0u0u0 = u0 * u0 * u0;
  2705. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2706. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2707. var t0t0t0 = t0 * t0 * t0; //
  2708. var u0u0u1 = u0 * u0 * u1;
  2709. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2710. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2711. var t0t0t1 = t0 * t0 * t1; //
  2712. var u0u1u1 = u0 * u1 * u1;
  2713. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2714. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2715. var t0t1t1 = t0 * t1 * t1; //
  2716. var u1u1u1 = u1 * u1 * u1;
  2717. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2718. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2719. var t1t1t1 = t1 * t1 * t1;
  2720. for (i = 0; i < len; i += 1) {
  2721. 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
  2722. 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
  2723. 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
  2724. 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
  2725. }
  2726. return bezierSegmentPoints;
  2727. }
  2728. return {
  2729. getSegmentsLength: getSegmentsLength,
  2730. getNewSegment: getNewSegment,
  2731. getPointInSegment: getPointInSegment,
  2732. buildBezierData: buildBezierData,
  2733. pointOnLine2D: pointOnLine2D,
  2734. pointOnLine3D: pointOnLine3D
  2735. };
  2736. }
  2737. var bez = bezFunction();
  2738. var initFrame = initialDefaultFrame;
  2739. var mathAbs = Math.abs;
  2740. function interpolateValue(frameNum, caching) {
  2741. var offsetTime = this.offsetTime;
  2742. var newValue;
  2743. if (this.propType === 'multidimensional') {
  2744. newValue = createTypedArray('float32', this.pv.length);
  2745. }
  2746. var iterationIndex = caching.lastIndex;
  2747. var i = iterationIndex;
  2748. var len = this.keyframes.length - 1;
  2749. var flag = true;
  2750. var keyData;
  2751. var nextKeyData;
  2752. var keyframeMetadata;
  2753. while (flag) {
  2754. keyData = this.keyframes[i];
  2755. nextKeyData = this.keyframes[i + 1];
  2756. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2757. if (keyData.h) {
  2758. keyData = nextKeyData;
  2759. }
  2760. iterationIndex = 0;
  2761. break;
  2762. }
  2763. if (nextKeyData.t - offsetTime > frameNum) {
  2764. iterationIndex = i;
  2765. break;
  2766. }
  2767. if (i < len - 1) {
  2768. i += 1;
  2769. } else {
  2770. iterationIndex = 0;
  2771. flag = false;
  2772. }
  2773. }
  2774. keyframeMetadata = this.keyframesMetadata[i] || {};
  2775. var k;
  2776. var kLen;
  2777. var perc;
  2778. var jLen;
  2779. var j;
  2780. var fnc;
  2781. var nextKeyTime = nextKeyData.t - offsetTime;
  2782. var keyTime = keyData.t - offsetTime;
  2783. var endValue;
  2784. if (keyData.to) {
  2785. if (!keyframeMetadata.bezierData) {
  2786. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2787. }
  2788. var bezierData = keyframeMetadata.bezierData;
  2789. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2790. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2791. kLen = bezierData.points[ind].point.length;
  2792. for (k = 0; k < kLen; k += 1) {
  2793. newValue[k] = bezierData.points[ind].point[k];
  2794. } // caching._lastKeyframeIndex = -1;
  2795. } else {
  2796. if (keyframeMetadata.__fnct) {
  2797. fnc = keyframeMetadata.__fnct;
  2798. } else {
  2799. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2800. keyframeMetadata.__fnct = fnc;
  2801. }
  2802. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2803. var distanceInLine = bezierData.segmentLength * perc;
  2804. var segmentPerc;
  2805. var addedLength = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastAddedLength : 0;
  2806. j = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastPoint : 0;
  2807. flag = true;
  2808. jLen = bezierData.points.length;
  2809. while (flag) {
  2810. addedLength += bezierData.points[j].partialLength;
  2811. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2812. kLen = bezierData.points[j].point.length;
  2813. for (k = 0; k < kLen; k += 1) {
  2814. newValue[k] = bezierData.points[j].point[k];
  2815. }
  2816. break;
  2817. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2818. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2819. kLen = bezierData.points[j].point.length;
  2820. for (k = 0; k < kLen; k += 1) {
  2821. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2822. }
  2823. break;
  2824. }
  2825. if (j < jLen - 1) {
  2826. j += 1;
  2827. } else {
  2828. flag = false;
  2829. }
  2830. }
  2831. caching._lastPoint = j;
  2832. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2833. caching._lastKeyframeIndex = i;
  2834. }
  2835. } else {
  2836. var outX;
  2837. var outY;
  2838. var inX;
  2839. var inY;
  2840. var keyValue;
  2841. len = keyData.s.length;
  2842. endValue = nextKeyData.s || keyData.e;
  2843. if (this.sh && keyData.h !== 1) {
  2844. if (frameNum >= nextKeyTime) {
  2845. newValue[0] = endValue[0];
  2846. newValue[1] = endValue[1];
  2847. newValue[2] = endValue[2];
  2848. } else if (frameNum <= keyTime) {
  2849. newValue[0] = keyData.s[0];
  2850. newValue[1] = keyData.s[1];
  2851. newValue[2] = keyData.s[2];
  2852. } else {
  2853. var quatStart = createQuaternion(keyData.s);
  2854. var quatEnd = createQuaternion(endValue);
  2855. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2856. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2857. }
  2858. } else {
  2859. for (i = 0; i < len; i += 1) {
  2860. if (keyData.h !== 1) {
  2861. if (frameNum >= nextKeyTime) {
  2862. perc = 1;
  2863. } else if (frameNum < keyTime) {
  2864. perc = 0;
  2865. } else {
  2866. if (keyData.o.x.constructor === Array) {
  2867. if (!keyframeMetadata.__fnct) {
  2868. keyframeMetadata.__fnct = [];
  2869. }
  2870. if (!keyframeMetadata.__fnct[i]) {
  2871. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2872. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2873. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2874. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2875. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2876. keyframeMetadata.__fnct[i] = fnc;
  2877. } else {
  2878. fnc = keyframeMetadata.__fnct[i];
  2879. }
  2880. } else if (!keyframeMetadata.__fnct) {
  2881. outX = keyData.o.x;
  2882. outY = keyData.o.y;
  2883. inX = keyData.i.x;
  2884. inY = keyData.i.y;
  2885. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2886. keyData.keyframeMetadata = fnc;
  2887. } else {
  2888. fnc = keyframeMetadata.__fnct;
  2889. }
  2890. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2891. }
  2892. }
  2893. endValue = nextKeyData.s || keyData.e;
  2894. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2895. if (this.propType === 'multidimensional') {
  2896. newValue[i] = keyValue;
  2897. } else {
  2898. newValue = keyValue;
  2899. }
  2900. }
  2901. }
  2902. }
  2903. caching.lastIndex = iterationIndex;
  2904. return newValue;
  2905. } // based on @Toji's https://github.com/toji/gl-matrix/
  2906. function slerp(a, b, t) {
  2907. var out = [];
  2908. var ax = a[0];
  2909. var ay = a[1];
  2910. var az = a[2];
  2911. var aw = a[3];
  2912. var bx = b[0];
  2913. var by = b[1];
  2914. var bz = b[2];
  2915. var bw = b[3];
  2916. var omega;
  2917. var cosom;
  2918. var sinom;
  2919. var scale0;
  2920. var scale1;
  2921. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2922. if (cosom < 0.0) {
  2923. cosom = -cosom;
  2924. bx = -bx;
  2925. by = -by;
  2926. bz = -bz;
  2927. bw = -bw;
  2928. }
  2929. if (1.0 - cosom > 0.000001) {
  2930. omega = Math.acos(cosom);
  2931. sinom = Math.sin(omega);
  2932. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2933. scale1 = Math.sin(t * omega) / sinom;
  2934. } else {
  2935. scale0 = 1.0 - t;
  2936. scale1 = t;
  2937. }
  2938. out[0] = scale0 * ax + scale1 * bx;
  2939. out[1] = scale0 * ay + scale1 * by;
  2940. out[2] = scale0 * az + scale1 * bz;
  2941. out[3] = scale0 * aw + scale1 * bw;
  2942. return out;
  2943. }
  2944. function quaternionToEuler(out, quat) {
  2945. var qx = quat[0];
  2946. var qy = quat[1];
  2947. var qz = quat[2];
  2948. var qw = quat[3];
  2949. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2950. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2951. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2952. out[0] = heading / degToRads;
  2953. out[1] = attitude / degToRads;
  2954. out[2] = bank / degToRads;
  2955. }
  2956. function createQuaternion(values) {
  2957. var heading = values[0] * degToRads;
  2958. var attitude = values[1] * degToRads;
  2959. var bank = values[2] * degToRads;
  2960. var c1 = Math.cos(heading / 2);
  2961. var c2 = Math.cos(attitude / 2);
  2962. var c3 = Math.cos(bank / 2);
  2963. var s1 = Math.sin(heading / 2);
  2964. var s2 = Math.sin(attitude / 2);
  2965. var s3 = Math.sin(bank / 2);
  2966. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2967. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2968. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2969. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2970. return [x, y, z, w];
  2971. }
  2972. function getValueAtCurrentTime() {
  2973. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2974. var initTime = this.keyframes[0].t - this.offsetTime;
  2975. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2976. if (!(frameNum === this._caching.lastFrame || this._caching.lastFrame !== initFrame && (this._caching.lastFrame >= endTime && frameNum >= endTime || this._caching.lastFrame < initTime && frameNum < initTime))) {
  2977. if (this._caching.lastFrame >= frameNum) {
  2978. this._caching._lastKeyframeIndex = -1;
  2979. this._caching.lastIndex = 0;
  2980. }
  2981. var renderResult = this.interpolateValue(frameNum, this._caching);
  2982. this.pv = renderResult;
  2983. }
  2984. this._caching.lastFrame = frameNum;
  2985. return this.pv;
  2986. }
  2987. function setVValue(val) {
  2988. var multipliedValue;
  2989. if (this.propType === 'unidimensional') {
  2990. multipliedValue = val * this.mult;
  2991. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  2992. this.v = multipliedValue;
  2993. this._mdf = true;
  2994. }
  2995. } else {
  2996. var i = 0;
  2997. var len = this.v.length;
  2998. while (i < len) {
  2999. multipliedValue = val[i] * this.mult;
  3000. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  3001. this.v[i] = multipliedValue;
  3002. this._mdf = true;
  3003. }
  3004. i += 1;
  3005. }
  3006. }
  3007. }
  3008. function processEffectsSequence() {
  3009. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  3010. return;
  3011. }
  3012. if (this.lock) {
  3013. this.setVValue(this.pv);
  3014. return;
  3015. }
  3016. this.lock = true;
  3017. this._mdf = this._isFirstFrame;
  3018. var i;
  3019. var len = this.effectsSequence.length;
  3020. var finalValue = this.kf ? this.pv : this.data.k;
  3021. for (i = 0; i < len; i += 1) {
  3022. finalValue = this.effectsSequence[i](finalValue);
  3023. }
  3024. this.setVValue(finalValue);
  3025. this._isFirstFrame = false;
  3026. this.lock = false;
  3027. this.frameId = this.elem.globalData.frameId;
  3028. }
  3029. function addEffect(effectFunction) {
  3030. this.effectsSequence.push(effectFunction);
  3031. this.container.addDynamicProperty(this);
  3032. }
  3033. function ValueProperty(elem, data, mult, container) {
  3034. this.propType = 'unidimensional';
  3035. this.mult = mult || 1;
  3036. this.data = data;
  3037. this.v = mult ? data.k * mult : data.k;
  3038. this.pv = data.k;
  3039. this._mdf = false;
  3040. this.elem = elem;
  3041. this.container = container;
  3042. this.comp = elem.comp;
  3043. this.k = false;
  3044. this.kf = false;
  3045. this.vel = 0;
  3046. this.effectsSequence = [];
  3047. this._isFirstFrame = true;
  3048. this.getValue = processEffectsSequence;
  3049. this.setVValue = setVValue;
  3050. this.addEffect = addEffect;
  3051. }
  3052. function MultiDimensionalProperty(elem, data, mult, container) {
  3053. this.propType = 'multidimensional';
  3054. this.mult = mult || 1;
  3055. this.data = data;
  3056. this._mdf = false;
  3057. this.elem = elem;
  3058. this.container = container;
  3059. this.comp = elem.comp;
  3060. this.k = false;
  3061. this.kf = false;
  3062. this.frameId = -1;
  3063. var i;
  3064. var len = data.k.length;
  3065. this.v = createTypedArray('float32', len);
  3066. this.pv = createTypedArray('float32', len);
  3067. this.vel = createTypedArray('float32', len);
  3068. for (i = 0; i < len; i += 1) {
  3069. this.v[i] = data.k[i] * this.mult;
  3070. this.pv[i] = data.k[i];
  3071. }
  3072. this._isFirstFrame = true;
  3073. this.effectsSequence = [];
  3074. this.getValue = processEffectsSequence;
  3075. this.setVValue = setVValue;
  3076. this.addEffect = addEffect;
  3077. }
  3078. function KeyframedValueProperty(elem, data, mult, container) {
  3079. this.propType = 'unidimensional';
  3080. this.keyframes = data.k;
  3081. this.keyframesMetadata = [];
  3082. this.offsetTime = elem.data.st;
  3083. this.frameId = -1;
  3084. this._caching = {
  3085. lastFrame: initFrame,
  3086. lastIndex: 0,
  3087. value: 0,
  3088. _lastKeyframeIndex: -1
  3089. };
  3090. this.k = true;
  3091. this.kf = true;
  3092. this.data = data;
  3093. this.mult = mult || 1;
  3094. this.elem = elem;
  3095. this.container = container;
  3096. this.comp = elem.comp;
  3097. this.v = initFrame;
  3098. this.pv = initFrame;
  3099. this._isFirstFrame = true;
  3100. this.getValue = processEffectsSequence;
  3101. this.setVValue = setVValue;
  3102. this.interpolateValue = interpolateValue;
  3103. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3104. this.addEffect = addEffect;
  3105. }
  3106. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3107. this.propType = 'multidimensional';
  3108. var i;
  3109. var len = data.k.length;
  3110. var s;
  3111. var e;
  3112. var to;
  3113. var ti;
  3114. for (i = 0; i < len - 1; i += 1) {
  3115. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3116. s = data.k[i].s;
  3117. e = data.k[i + 1].s;
  3118. to = data.k[i].to;
  3119. ti = data.k[i].ti;
  3120. 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])) {
  3121. data.k[i].to = null;
  3122. data.k[i].ti = null;
  3123. }
  3124. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3125. if (s.length === 2 || s[2] === e[2] && to[2] === 0 && ti[2] === 0) {
  3126. data.k[i].to = null;
  3127. data.k[i].ti = null;
  3128. }
  3129. }
  3130. }
  3131. }
  3132. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3133. this.data = data;
  3134. this.keyframes = data.k;
  3135. this.keyframesMetadata = [];
  3136. this.offsetTime = elem.data.st;
  3137. this.k = true;
  3138. this.kf = true;
  3139. this._isFirstFrame = true;
  3140. this.mult = mult || 1;
  3141. this.elem = elem;
  3142. this.container = container;
  3143. this.comp = elem.comp;
  3144. this.getValue = processEffectsSequence;
  3145. this.setVValue = setVValue;
  3146. this.interpolateValue = interpolateValue;
  3147. this.frameId = -1;
  3148. var arrLen = data.k[0].s.length;
  3149. this.v = createTypedArray('float32', arrLen);
  3150. this.pv = createTypedArray('float32', arrLen);
  3151. for (i = 0; i < arrLen; i += 1) {
  3152. this.v[i] = initFrame;
  3153. this.pv[i] = initFrame;
  3154. }
  3155. this._caching = {
  3156. lastFrame: initFrame,
  3157. lastIndex: 0,
  3158. value: createTypedArray('float32', arrLen)
  3159. };
  3160. this.addEffect = addEffect;
  3161. }
  3162. var PropertyFactory = function () {
  3163. function getProp(elem, data, type, mult, container) {
  3164. if (data.sid) {
  3165. data = elem.globalData.slotManager.getProp(data);
  3166. }
  3167. var p;
  3168. if (!data.k.length) {
  3169. p = new ValueProperty(elem, data, mult, container);
  3170. } else if (typeof data.k[0] === 'number') {
  3171. p = new MultiDimensionalProperty(elem, data, mult, container);
  3172. } else {
  3173. switch (type) {
  3174. case 0:
  3175. p = new KeyframedValueProperty(elem, data, mult, container);
  3176. break;
  3177. case 1:
  3178. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3179. break;
  3180. default:
  3181. break;
  3182. }
  3183. }
  3184. if (p.effectsSequence.length) {
  3185. container.addDynamicProperty(p);
  3186. }
  3187. return p;
  3188. }
  3189. var ob = {
  3190. getProp: getProp
  3191. };
  3192. return ob;
  3193. }();
  3194. function DynamicPropertyContainer() {}
  3195. DynamicPropertyContainer.prototype = {
  3196. addDynamicProperty: function addDynamicProperty(prop) {
  3197. if (this.dynamicProperties.indexOf(prop) === -1) {
  3198. this.dynamicProperties.push(prop);
  3199. this.container.addDynamicProperty(this);
  3200. this._isAnimated = true;
  3201. }
  3202. },
  3203. iterateDynamicProperties: function iterateDynamicProperties() {
  3204. this._mdf = false;
  3205. var i;
  3206. var len = this.dynamicProperties.length;
  3207. for (i = 0; i < len; i += 1) {
  3208. this.dynamicProperties[i].getValue();
  3209. if (this.dynamicProperties[i]._mdf) {
  3210. this._mdf = true;
  3211. }
  3212. }
  3213. },
  3214. initDynamicPropertyContainer: function initDynamicPropertyContainer(container) {
  3215. this.container = container;
  3216. this.dynamicProperties = [];
  3217. this._mdf = false;
  3218. this._isAnimated = false;
  3219. }
  3220. };
  3221. var pointPool = function () {
  3222. function create() {
  3223. return createTypedArray('float32', 2);
  3224. }
  3225. return poolFactory(8, create);
  3226. }();
  3227. function ShapePath() {
  3228. this.c = false;
  3229. this._length = 0;
  3230. this._maxLength = 8;
  3231. this.v = createSizedArray(this._maxLength);
  3232. this.o = createSizedArray(this._maxLength);
  3233. this.i = createSizedArray(this._maxLength);
  3234. }
  3235. ShapePath.prototype.setPathData = function (closed, len) {
  3236. this.c = closed;
  3237. this.setLength(len);
  3238. var i = 0;
  3239. while (i < len) {
  3240. this.v[i] = pointPool.newElement();
  3241. this.o[i] = pointPool.newElement();
  3242. this.i[i] = pointPool.newElement();
  3243. i += 1;
  3244. }
  3245. };
  3246. ShapePath.prototype.setLength = function (len) {
  3247. while (this._maxLength < len) {
  3248. this.doubleArrayLength();
  3249. }
  3250. this._length = len;
  3251. };
  3252. ShapePath.prototype.doubleArrayLength = function () {
  3253. this.v = this.v.concat(createSizedArray(this._maxLength));
  3254. this.i = this.i.concat(createSizedArray(this._maxLength));
  3255. this.o = this.o.concat(createSizedArray(this._maxLength));
  3256. this._maxLength *= 2;
  3257. };
  3258. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3259. var arr;
  3260. this._length = Math.max(this._length, pos + 1);
  3261. if (this._length >= this._maxLength) {
  3262. this.doubleArrayLength();
  3263. }
  3264. switch (type) {
  3265. case 'v':
  3266. arr = this.v;
  3267. break;
  3268. case 'i':
  3269. arr = this.i;
  3270. break;
  3271. case 'o':
  3272. arr = this.o;
  3273. break;
  3274. default:
  3275. arr = [];
  3276. break;
  3277. }
  3278. if (!arr[pos] || arr[pos] && !replace) {
  3279. arr[pos] = pointPool.newElement();
  3280. }
  3281. arr[pos][0] = x;
  3282. arr[pos][1] = y;
  3283. };
  3284. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3285. this.setXYAt(vX, vY, 'v', pos, replace);
  3286. this.setXYAt(oX, oY, 'o', pos, replace);
  3287. this.setXYAt(iX, iY, 'i', pos, replace);
  3288. };
  3289. ShapePath.prototype.reverse = function () {
  3290. var newPath = new ShapePath();
  3291. newPath.setPathData(this.c, this._length);
  3292. var vertices = this.v;
  3293. var outPoints = this.o;
  3294. var inPoints = this.i;
  3295. var init = 0;
  3296. if (this.c) {
  3297. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3298. init = 1;
  3299. }
  3300. var cnt = this._length - 1;
  3301. var len = this._length;
  3302. var i;
  3303. for (i = init; i < len; i += 1) {
  3304. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3305. cnt -= 1;
  3306. }
  3307. return newPath;
  3308. };
  3309. ShapePath.prototype.length = function () {
  3310. return this._length;
  3311. };
  3312. var shapePool = function () {
  3313. function create() {
  3314. return new ShapePath();
  3315. }
  3316. function release(shapePath) {
  3317. var len = shapePath._length;
  3318. var i;
  3319. for (i = 0; i < len; i += 1) {
  3320. pointPool.release(shapePath.v[i]);
  3321. pointPool.release(shapePath.i[i]);
  3322. pointPool.release(shapePath.o[i]);
  3323. shapePath.v[i] = null;
  3324. shapePath.i[i] = null;
  3325. shapePath.o[i] = null;
  3326. }
  3327. shapePath._length = 0;
  3328. shapePath.c = false;
  3329. }
  3330. function clone(shape) {
  3331. var cloned = factory.newElement();
  3332. var i;
  3333. var len = shape._length === undefined ? shape.v.length : shape._length;
  3334. cloned.setLength(len);
  3335. cloned.c = shape.c;
  3336. for (i = 0; i < len; i += 1) {
  3337. 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);
  3338. }
  3339. return cloned;
  3340. }
  3341. var factory = poolFactory(4, create, release);
  3342. factory.clone = clone;
  3343. return factory;
  3344. }();
  3345. function ShapeCollection() {
  3346. this._length = 0;
  3347. this._maxLength = 4;
  3348. this.shapes = createSizedArray(this._maxLength);
  3349. }
  3350. ShapeCollection.prototype.addShape = function (shapeData) {
  3351. if (this._length === this._maxLength) {
  3352. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3353. this._maxLength *= 2;
  3354. }
  3355. this.shapes[this._length] = shapeData;
  3356. this._length += 1;
  3357. };
  3358. ShapeCollection.prototype.releaseShapes = function () {
  3359. var i;
  3360. for (i = 0; i < this._length; i += 1) {
  3361. shapePool.release(this.shapes[i]);
  3362. }
  3363. this._length = 0;
  3364. };
  3365. var shapeCollectionPool = function () {
  3366. var ob = {
  3367. newShapeCollection: newShapeCollection,
  3368. release: release
  3369. };
  3370. var _length = 0;
  3371. var _maxLength = 4;
  3372. var pool = createSizedArray(_maxLength);
  3373. function newShapeCollection() {
  3374. var shapeCollection;
  3375. if (_length) {
  3376. _length -= 1;
  3377. shapeCollection = pool[_length];
  3378. } else {
  3379. shapeCollection = new ShapeCollection();
  3380. }
  3381. return shapeCollection;
  3382. }
  3383. function release(shapeCollection) {
  3384. var i;
  3385. var len = shapeCollection._length;
  3386. for (i = 0; i < len; i += 1) {
  3387. shapePool.release(shapeCollection.shapes[i]);
  3388. }
  3389. shapeCollection._length = 0;
  3390. if (_length === _maxLength) {
  3391. pool = pooling["double"](pool);
  3392. _maxLength *= 2;
  3393. }
  3394. pool[_length] = shapeCollection;
  3395. _length += 1;
  3396. }
  3397. return ob;
  3398. }();
  3399. var ShapePropertyFactory = function () {
  3400. var initFrame = -999999;
  3401. function interpolateShape(frameNum, previousValue, caching) {
  3402. var iterationIndex = caching.lastIndex;
  3403. var keyPropS;
  3404. var keyPropE;
  3405. var isHold;
  3406. var j;
  3407. var k;
  3408. var jLen;
  3409. var kLen;
  3410. var perc;
  3411. var vertexValue;
  3412. var kf = this.keyframes;
  3413. if (frameNum < kf[0].t - this.offsetTime) {
  3414. keyPropS = kf[0].s[0];
  3415. isHold = true;
  3416. iterationIndex = 0;
  3417. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3418. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3419. /* if(kf[kf.length - 1].s){
  3420. keyPropS = kf[kf.length - 1].s[0];
  3421. }else{
  3422. keyPropS = kf[kf.length - 2].e[0];
  3423. } */
  3424. isHold = true;
  3425. } else {
  3426. var i = iterationIndex;
  3427. var len = kf.length - 1;
  3428. var flag = true;
  3429. var keyData;
  3430. var nextKeyData;
  3431. var keyframeMetadata;
  3432. while (flag) {
  3433. keyData = kf[i];
  3434. nextKeyData = kf[i + 1];
  3435. if (nextKeyData.t - this.offsetTime > frameNum) {
  3436. break;
  3437. }
  3438. if (i < len - 1) {
  3439. i += 1;
  3440. } else {
  3441. flag = false;
  3442. }
  3443. }
  3444. keyframeMetadata = this.keyframesMetadata[i] || {};
  3445. isHold = keyData.h === 1;
  3446. iterationIndex = i;
  3447. if (!isHold) {
  3448. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3449. perc = 1;
  3450. } else if (frameNum < keyData.t - this.offsetTime) {
  3451. perc = 0;
  3452. } else {
  3453. var fnc;
  3454. if (keyframeMetadata.__fnct) {
  3455. fnc = keyframeMetadata.__fnct;
  3456. } else {
  3457. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3458. keyframeMetadata.__fnct = fnc;
  3459. }
  3460. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / (nextKeyData.t - this.offsetTime - (keyData.t - this.offsetTime)));
  3461. }
  3462. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3463. }
  3464. keyPropS = keyData.s[0];
  3465. }
  3466. jLen = previousValue._length;
  3467. kLen = keyPropS.i[0].length;
  3468. caching.lastIndex = iterationIndex;
  3469. for (j = 0; j < jLen; j += 1) {
  3470. for (k = 0; k < kLen; k += 1) {
  3471. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3472. previousValue.i[j][k] = vertexValue;
  3473. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3474. previousValue.o[j][k] = vertexValue;
  3475. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3476. previousValue.v[j][k] = vertexValue;
  3477. }
  3478. }
  3479. }
  3480. function interpolateShapeCurrentTime() {
  3481. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3482. var initTime = this.keyframes[0].t - this.offsetTime;
  3483. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3484. var lastFrame = this._caching.lastFrame;
  3485. if (!(lastFrame !== initFrame && (lastFrame < initTime && frameNum < initTime || lastFrame > endTime && frameNum > endTime))) {
  3486. /// /
  3487. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3488. this.interpolateShape(frameNum, this.pv, this._caching); /// /
  3489. }
  3490. this._caching.lastFrame = frameNum;
  3491. return this.pv;
  3492. }
  3493. function resetShape() {
  3494. this.paths = this.localShapeCollection;
  3495. }
  3496. function shapesEqual(shape1, shape2) {
  3497. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3498. return false;
  3499. }
  3500. var i;
  3501. var len = shape1._length;
  3502. for (i = 0; i < len; i += 1) {
  3503. if (shape1.v[i][0] !== shape2.v[i][0] || shape1.v[i][1] !== shape2.v[i][1] || shape1.o[i][0] !== shape2.o[i][0] || shape1.o[i][1] !== shape2.o[i][1] || shape1.i[i][0] !== shape2.i[i][0] || shape1.i[i][1] !== shape2.i[i][1]) {
  3504. return false;
  3505. }
  3506. }
  3507. return true;
  3508. }
  3509. function setVValue(newPath) {
  3510. if (!shapesEqual(this.v, newPath)) {
  3511. this.v = shapePool.clone(newPath);
  3512. this.localShapeCollection.releaseShapes();
  3513. this.localShapeCollection.addShape(this.v);
  3514. this._mdf = true;
  3515. this.paths = this.localShapeCollection;
  3516. }
  3517. }
  3518. function processEffectsSequence() {
  3519. if (this.elem.globalData.frameId === this.frameId) {
  3520. return;
  3521. }
  3522. if (!this.effectsSequence.length) {
  3523. this._mdf = false;
  3524. return;
  3525. }
  3526. if (this.lock) {
  3527. this.setVValue(this.pv);
  3528. return;
  3529. }
  3530. this.lock = true;
  3531. this._mdf = false;
  3532. var finalValue;
  3533. if (this.kf) {
  3534. finalValue = this.pv;
  3535. } else if (this.data.ks) {
  3536. finalValue = this.data.ks.k;
  3537. } else {
  3538. finalValue = this.data.pt.k;
  3539. }
  3540. var i;
  3541. var len = this.effectsSequence.length;
  3542. for (i = 0; i < len; i += 1) {
  3543. finalValue = this.effectsSequence[i](finalValue);
  3544. }
  3545. this.setVValue(finalValue);
  3546. this.lock = false;
  3547. this.frameId = this.elem.globalData.frameId;
  3548. }
  3549. function ShapeProperty(elem, data, type) {
  3550. this.propType = 'shape';
  3551. this.comp = elem.comp;
  3552. this.container = elem;
  3553. this.elem = elem;
  3554. this.data = data;
  3555. this.k = false;
  3556. this.kf = false;
  3557. this._mdf = false;
  3558. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3559. this.v = shapePool.clone(pathData);
  3560. this.pv = shapePool.clone(this.v);
  3561. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3562. this.paths = this.localShapeCollection;
  3563. this.paths.addShape(this.v);
  3564. this.reset = resetShape;
  3565. this.effectsSequence = [];
  3566. }
  3567. function addEffect(effectFunction) {
  3568. this.effectsSequence.push(effectFunction);
  3569. this.container.addDynamicProperty(this);
  3570. }
  3571. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3572. ShapeProperty.prototype.getValue = processEffectsSequence;
  3573. ShapeProperty.prototype.setVValue = setVValue;
  3574. ShapeProperty.prototype.addEffect = addEffect;
  3575. function KeyframedShapeProperty(elem, data, type) {
  3576. this.propType = 'shape';
  3577. this.comp = elem.comp;
  3578. this.elem = elem;
  3579. this.container = elem;
  3580. this.offsetTime = elem.data.st;
  3581. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3582. this.keyframesMetadata = [];
  3583. this.k = true;
  3584. this.kf = true;
  3585. var len = this.keyframes[0].s[0].i.length;
  3586. this.v = shapePool.newElement();
  3587. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3588. this.pv = shapePool.clone(this.v);
  3589. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3590. this.paths = this.localShapeCollection;
  3591. this.paths.addShape(this.v);
  3592. this.lastFrame = initFrame;
  3593. this.reset = resetShape;
  3594. this._caching = {
  3595. lastFrame: initFrame,
  3596. lastIndex: 0
  3597. };
  3598. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3599. }
  3600. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3601. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3602. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3603. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3604. var EllShapeProperty = function () {
  3605. var cPoint = roundCorner;
  3606. function EllShapePropertyFactory(elem, data) {
  3607. this.v = shapePool.newElement();
  3608. this.v.setPathData(true, 4);
  3609. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3610. this.paths = this.localShapeCollection;
  3611. this.localShapeCollection.addShape(this.v);
  3612. this.d = data.d;
  3613. this.elem = elem;
  3614. this.comp = elem.comp;
  3615. this.frameId = -1;
  3616. this.initDynamicPropertyContainer(elem);
  3617. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3618. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3619. if (this.dynamicProperties.length) {
  3620. this.k = true;
  3621. } else {
  3622. this.k = false;
  3623. this.convertEllToPath();
  3624. }
  3625. }
  3626. EllShapePropertyFactory.prototype = {
  3627. reset: resetShape,
  3628. getValue: function getValue() {
  3629. if (this.elem.globalData.frameId === this.frameId) {
  3630. return;
  3631. }
  3632. this.frameId = this.elem.globalData.frameId;
  3633. this.iterateDynamicProperties();
  3634. if (this._mdf) {
  3635. this.convertEllToPath();
  3636. }
  3637. },
  3638. convertEllToPath: function convertEllToPath() {
  3639. var p0 = this.p.v[0];
  3640. var p1 = this.p.v[1];
  3641. var s0 = this.s.v[0] / 2;
  3642. var s1 = this.s.v[1] / 2;
  3643. var _cw = this.d !== 3;
  3644. var _v = this.v;
  3645. _v.v[0][0] = p0;
  3646. _v.v[0][1] = p1 - s1;
  3647. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3648. _v.v[1][1] = p1;
  3649. _v.v[2][0] = p0;
  3650. _v.v[2][1] = p1 + s1;
  3651. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3652. _v.v[3][1] = p1;
  3653. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3654. _v.i[0][1] = p1 - s1;
  3655. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3656. _v.i[1][1] = p1 - s1 * cPoint;
  3657. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3658. _v.i[2][1] = p1 + s1;
  3659. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3660. _v.i[3][1] = p1 + s1 * cPoint;
  3661. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3662. _v.o[0][1] = p1 - s1;
  3663. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3664. _v.o[1][1] = p1 + s1 * cPoint;
  3665. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3666. _v.o[2][1] = p1 + s1;
  3667. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3668. _v.o[3][1] = p1 - s1 * cPoint;
  3669. }
  3670. };
  3671. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3672. return EllShapePropertyFactory;
  3673. }();
  3674. var StarShapeProperty = function () {
  3675. function StarShapePropertyFactory(elem, data) {
  3676. this.v = shapePool.newElement();
  3677. this.v.setPathData(true, 0);
  3678. this.elem = elem;
  3679. this.comp = elem.comp;
  3680. this.data = data;
  3681. this.frameId = -1;
  3682. this.d = data.d;
  3683. this.initDynamicPropertyContainer(elem);
  3684. if (data.sy === 1) {
  3685. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3686. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3687. this.convertToPath = this.convertStarToPath;
  3688. } else {
  3689. this.convertToPath = this.convertPolygonToPath;
  3690. }
  3691. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3692. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3693. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3694. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3695. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3696. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3697. this.localShapeCollection.addShape(this.v);
  3698. this.paths = this.localShapeCollection;
  3699. if (this.dynamicProperties.length) {
  3700. this.k = true;
  3701. } else {
  3702. this.k = false;
  3703. this.convertToPath();
  3704. }
  3705. }
  3706. StarShapePropertyFactory.prototype = {
  3707. reset: resetShape,
  3708. getValue: function getValue() {
  3709. if (this.elem.globalData.frameId === this.frameId) {
  3710. return;
  3711. }
  3712. this.frameId = this.elem.globalData.frameId;
  3713. this.iterateDynamicProperties();
  3714. if (this._mdf) {
  3715. this.convertToPath();
  3716. }
  3717. },
  3718. convertStarToPath: function convertStarToPath() {
  3719. var numPts = Math.floor(this.pt.v) * 2;
  3720. var angle = Math.PI * 2 / numPts;
  3721. /* this.v.v.length = numPts;
  3722. this.v.i.length = numPts;
  3723. this.v.o.length = numPts; */
  3724. var longFlag = true;
  3725. var longRad = this.or.v;
  3726. var shortRad = this.ir.v;
  3727. var longRound = this.os.v;
  3728. var shortRound = this.is.v;
  3729. var longPerimSegment = 2 * Math.PI * longRad / (numPts * 2);
  3730. var shortPerimSegment = 2 * Math.PI * shortRad / (numPts * 2);
  3731. var i;
  3732. var rad;
  3733. var roundness;
  3734. var perimSegment;
  3735. var currentAng = -Math.PI / 2;
  3736. currentAng += this.r.v;
  3737. var dir = this.data.d === 3 ? -1 : 1;
  3738. this.v._length = 0;
  3739. for (i = 0; i < numPts; i += 1) {
  3740. rad = longFlag ? longRad : shortRad;
  3741. roundness = longFlag ? longRound : shortRound;
  3742. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3743. var x = rad * Math.cos(currentAng);
  3744. var y = rad * Math.sin(currentAng);
  3745. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3746. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3747. x += +this.p.v[0];
  3748. y += +this.p.v[1];
  3749. 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);
  3750. /* this.v.v[i] = [x,y];
  3751. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3752. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3753. this.v._length = numPts; */
  3754. longFlag = !longFlag;
  3755. currentAng += angle * dir;
  3756. }
  3757. },
  3758. convertPolygonToPath: function convertPolygonToPath() {
  3759. var numPts = Math.floor(this.pt.v);
  3760. var angle = Math.PI * 2 / numPts;
  3761. var rad = this.or.v;
  3762. var roundness = this.os.v;
  3763. var perimSegment = 2 * Math.PI * rad / (numPts * 4);
  3764. var i;
  3765. var currentAng = -Math.PI * 0.5;
  3766. var dir = this.data.d === 3 ? -1 : 1;
  3767. currentAng += this.r.v;
  3768. this.v._length = 0;
  3769. for (i = 0; i < numPts; i += 1) {
  3770. var x = rad * Math.cos(currentAng);
  3771. var y = rad * Math.sin(currentAng);
  3772. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3773. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3774. x += +this.p.v[0];
  3775. y += +this.p.v[1];
  3776. 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);
  3777. currentAng += angle * dir;
  3778. }
  3779. this.paths.length = 0;
  3780. this.paths[0] = this.v;
  3781. }
  3782. };
  3783. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3784. return StarShapePropertyFactory;
  3785. }();
  3786. var RectShapeProperty = function () {
  3787. function RectShapePropertyFactory(elem, data) {
  3788. this.v = shapePool.newElement();
  3789. this.v.c = true;
  3790. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3791. this.localShapeCollection.addShape(this.v);
  3792. this.paths = this.localShapeCollection;
  3793. this.elem = elem;
  3794. this.comp = elem.comp;
  3795. this.frameId = -1;
  3796. this.d = data.d;
  3797. this.initDynamicPropertyContainer(elem);
  3798. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3799. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3800. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3801. if (this.dynamicProperties.length) {
  3802. this.k = true;
  3803. } else {
  3804. this.k = false;
  3805. this.convertRectToPath();
  3806. }
  3807. }
  3808. RectShapePropertyFactory.prototype = {
  3809. convertRectToPath: function convertRectToPath() {
  3810. var p0 = this.p.v[0];
  3811. var p1 = this.p.v[1];
  3812. var v0 = this.s.v[0] / 2;
  3813. var v1 = this.s.v[1] / 2;
  3814. var round = bmMin(v0, v1, this.r.v);
  3815. var cPoint = round * (1 - roundCorner);
  3816. this.v._length = 0;
  3817. if (this.d === 2 || this.d === 1) {
  3818. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3819. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3820. if (round !== 0) {
  3821. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3822. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3823. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3824. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3825. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3826. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3827. } else {
  3828. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3829. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3830. }
  3831. } else {
  3832. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3833. if (round !== 0) {
  3834. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3835. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3836. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3837. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3838. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3839. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3840. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3841. } else {
  3842. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3843. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3844. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3845. }
  3846. }
  3847. },
  3848. getValue: function getValue() {
  3849. if (this.elem.globalData.frameId === this.frameId) {
  3850. return;
  3851. }
  3852. this.frameId = this.elem.globalData.frameId;
  3853. this.iterateDynamicProperties();
  3854. if (this._mdf) {
  3855. this.convertRectToPath();
  3856. }
  3857. },
  3858. reset: resetShape
  3859. };
  3860. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3861. return RectShapePropertyFactory;
  3862. }();
  3863. function getShapeProp(elem, data, type) {
  3864. var prop;
  3865. if (type === 3 || type === 4) {
  3866. var dataProp = type === 3 ? data.pt : data.ks;
  3867. var keys = dataProp.k;
  3868. if (keys.length) {
  3869. prop = new KeyframedShapeProperty(elem, data, type);
  3870. } else {
  3871. prop = new ShapeProperty(elem, data, type);
  3872. }
  3873. } else if (type === 5) {
  3874. prop = new RectShapeProperty(elem, data);
  3875. } else if (type === 6) {
  3876. prop = new EllShapeProperty(elem, data);
  3877. } else if (type === 7) {
  3878. prop = new StarShapeProperty(elem, data);
  3879. }
  3880. if (prop.k) {
  3881. elem.addDynamicProperty(prop);
  3882. }
  3883. return prop;
  3884. }
  3885. function getConstructorFunction() {
  3886. return ShapeProperty;
  3887. }
  3888. function getKeyframedConstructorFunction() {
  3889. return KeyframedShapeProperty;
  3890. }
  3891. var ob = {};
  3892. ob.getShapeProp = getShapeProp;
  3893. ob.getConstructorFunction = getConstructorFunction;
  3894. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3895. return ob;
  3896. }();
  3897. /*!
  3898. Transformation Matrix v2.0
  3899. (c) Epistemex 2014-2015
  3900. www.epistemex.com
  3901. By Ken Fyrstenberg
  3902. Contributions by leeoniya.
  3903. License: MIT, header required.
  3904. */
  3905. /**
  3906. * 2D transformation matrix object initialized with identity matrix.
  3907. *
  3908. * The matrix can synchronize a canvas context by supplying the context
  3909. * as an argument, or later apply current absolute transform to an
  3910. * existing context.
  3911. *
  3912. * All values are handled as floating point values.
  3913. *
  3914. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3915. * @prop {number} a - scale x
  3916. * @prop {number} b - shear y
  3917. * @prop {number} c - shear x
  3918. * @prop {number} d - scale y
  3919. * @prop {number} e - translate x
  3920. * @prop {number} f - translate y
  3921. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3922. * @constructor
  3923. */
  3924. var Matrix = function () {
  3925. var _cos = Math.cos;
  3926. var _sin = Math.sin;
  3927. var _tan = Math.tan;
  3928. var _rnd = Math.round;
  3929. function reset() {
  3930. this.props[0] = 1;
  3931. this.props[1] = 0;
  3932. this.props[2] = 0;
  3933. this.props[3] = 0;
  3934. this.props[4] = 0;
  3935. this.props[5] = 1;
  3936. this.props[6] = 0;
  3937. this.props[7] = 0;
  3938. this.props[8] = 0;
  3939. this.props[9] = 0;
  3940. this.props[10] = 1;
  3941. this.props[11] = 0;
  3942. this.props[12] = 0;
  3943. this.props[13] = 0;
  3944. this.props[14] = 0;
  3945. this.props[15] = 1;
  3946. return this;
  3947. }
  3948. function rotate(angle) {
  3949. if (angle === 0) {
  3950. return this;
  3951. }
  3952. var mCos = _cos(angle);
  3953. var mSin = _sin(angle);
  3954. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3955. }
  3956. function rotateX(angle) {
  3957. if (angle === 0) {
  3958. return this;
  3959. }
  3960. var mCos = _cos(angle);
  3961. var mSin = _sin(angle);
  3962. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3963. }
  3964. function rotateY(angle) {
  3965. if (angle === 0) {
  3966. return this;
  3967. }
  3968. var mCos = _cos(angle);
  3969. var mSin = _sin(angle);
  3970. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3971. }
  3972. function rotateZ(angle) {
  3973. if (angle === 0) {
  3974. return this;
  3975. }
  3976. var mCos = _cos(angle);
  3977. var mSin = _sin(angle);
  3978. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3979. }
  3980. function shear(sx, sy) {
  3981. return this._t(1, sy, sx, 1, 0, 0);
  3982. }
  3983. function skew(ax, ay) {
  3984. return this.shear(_tan(ax), _tan(ay));
  3985. }
  3986. function skewFromAxis(ax, angle) {
  3987. var mCos = _cos(angle);
  3988. var mSin = _sin(angle);
  3989. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  3990. }
  3991. function scale(sx, sy, sz) {
  3992. if (!sz && sz !== 0) {
  3993. sz = 1;
  3994. }
  3995. if (sx === 1 && sy === 1 && sz === 1) {
  3996. return this;
  3997. }
  3998. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  3999. }
  4000. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  4001. this.props[0] = a;
  4002. this.props[1] = b;
  4003. this.props[2] = c;
  4004. this.props[3] = d;
  4005. this.props[4] = e;
  4006. this.props[5] = f;
  4007. this.props[6] = g;
  4008. this.props[7] = h;
  4009. this.props[8] = i;
  4010. this.props[9] = j;
  4011. this.props[10] = k;
  4012. this.props[11] = l;
  4013. this.props[12] = m;
  4014. this.props[13] = n;
  4015. this.props[14] = o;
  4016. this.props[15] = p;
  4017. return this;
  4018. }
  4019. function translate(tx, ty, tz) {
  4020. tz = tz || 0;
  4021. if (tx !== 0 || ty !== 0 || tz !== 0) {
  4022. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  4023. }
  4024. return this;
  4025. }
  4026. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  4027. var _p = this.props;
  4028. 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) {
  4029. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  4030. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  4031. _p[12] = _p[12] * a2 + _p[15] * m2;
  4032. _p[13] = _p[13] * f2 + _p[15] * n2;
  4033. _p[14] = _p[14] * k2 + _p[15] * o2;
  4034. _p[15] *= p2; // }
  4035. this._identityCalculated = false;
  4036. return this;
  4037. }
  4038. var a1 = _p[0];
  4039. var b1 = _p[1];
  4040. var c1 = _p[2];
  4041. var d1 = _p[3];
  4042. var e1 = _p[4];
  4043. var f1 = _p[5];
  4044. var g1 = _p[6];
  4045. var h1 = _p[7];
  4046. var i1 = _p[8];
  4047. var j1 = _p[9];
  4048. var k1 = _p[10];
  4049. var l1 = _p[11];
  4050. var m1 = _p[12];
  4051. var n1 = _p[13];
  4052. var o1 = _p[14];
  4053. var p1 = _p[15];
  4054. /* matrix order (canvas compatible):
  4055. * ace
  4056. * bdf
  4057. * 001
  4058. */
  4059. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  4060. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  4061. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  4062. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  4063. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  4064. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  4065. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  4066. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  4067. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  4068. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  4069. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  4070. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  4071. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  4072. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  4073. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  4074. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  4075. this._identityCalculated = false;
  4076. return this;
  4077. }
  4078. function multiply(matrix) {
  4079. var matrixProps = matrix.props;
  4080. return this.transform(matrixProps[0], matrixProps[1], matrixProps[2], matrixProps[3], matrixProps[4], matrixProps[5], matrixProps[6], matrixProps[7], matrixProps[8], matrixProps[9], matrixProps[10], matrixProps[11], matrixProps[12], matrixProps[13], matrixProps[14], matrixProps[15]);
  4081. }
  4082. function isIdentity() {
  4083. if (!this._identityCalculated) {
  4084. 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);
  4085. this._identityCalculated = true;
  4086. }
  4087. return this._identity;
  4088. }
  4089. function equals(matr) {
  4090. var i = 0;
  4091. while (i < 16) {
  4092. if (matr.props[i] !== this.props[i]) {
  4093. return false;
  4094. }
  4095. i += 1;
  4096. }
  4097. return true;
  4098. }
  4099. function clone(matr) {
  4100. var i;
  4101. for (i = 0; i < 16; i += 1) {
  4102. matr.props[i] = this.props[i];
  4103. }
  4104. return matr;
  4105. }
  4106. function cloneFromProps(props) {
  4107. var i;
  4108. for (i = 0; i < 16; i += 1) {
  4109. this.props[i] = props[i];
  4110. }
  4111. }
  4112. function applyToPoint(x, y, z) {
  4113. return {
  4114. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4115. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4116. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]
  4117. };
  4118. /* return {
  4119. x: x * me.a + y * me.c + me.e,
  4120. y: x * me.b + y * me.d + me.f
  4121. }; */
  4122. }
  4123. function applyToX(x, y, z) {
  4124. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4125. }
  4126. function applyToY(x, y, z) {
  4127. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4128. }
  4129. function applyToZ(x, y, z) {
  4130. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4131. }
  4132. function getInverseMatrix() {
  4133. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4134. var a = this.props[5] / determinant;
  4135. var b = -this.props[1] / determinant;
  4136. var c = -this.props[4] / determinant;
  4137. var d = this.props[0] / determinant;
  4138. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4139. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4140. var inverseMatrix = new Matrix();
  4141. inverseMatrix.props[0] = a;
  4142. inverseMatrix.props[1] = b;
  4143. inverseMatrix.props[4] = c;
  4144. inverseMatrix.props[5] = d;
  4145. inverseMatrix.props[12] = e;
  4146. inverseMatrix.props[13] = f;
  4147. return inverseMatrix;
  4148. }
  4149. function inversePoint(pt) {
  4150. var inverseMatrix = this.getInverseMatrix();
  4151. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4152. }
  4153. function inversePoints(pts) {
  4154. var i;
  4155. var len = pts.length;
  4156. var retPts = [];
  4157. for (i = 0; i < len; i += 1) {
  4158. retPts[i] = inversePoint(pts[i]);
  4159. }
  4160. return retPts;
  4161. }
  4162. function applyToTriplePoints(pt1, pt2, pt3) {
  4163. var arr = createTypedArray('float32', 6);
  4164. if (this.isIdentity()) {
  4165. arr[0] = pt1[0];
  4166. arr[1] = pt1[1];
  4167. arr[2] = pt2[0];
  4168. arr[3] = pt2[1];
  4169. arr[4] = pt3[0];
  4170. arr[5] = pt3[1];
  4171. } else {
  4172. var p0 = this.props[0];
  4173. var p1 = this.props[1];
  4174. var p4 = this.props[4];
  4175. var p5 = this.props[5];
  4176. var p12 = this.props[12];
  4177. var p13 = this.props[13];
  4178. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4179. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4180. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4181. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4182. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4183. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4184. }
  4185. return arr;
  4186. }
  4187. function applyToPointArray(x, y, z) {
  4188. var arr;
  4189. if (this.isIdentity()) {
  4190. arr = [x, y, z];
  4191. } else {
  4192. arr = [x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12], x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13], x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]];
  4193. }
  4194. return arr;
  4195. }
  4196. function applyToPointStringified(x, y) {
  4197. if (this.isIdentity()) {
  4198. return x + ',' + y;
  4199. }
  4200. var _p = this.props;
  4201. 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;
  4202. }
  4203. function toCSS() {
  4204. // 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.
  4205. /* if(this.isIdentity()) {
  4206. return '';
  4207. } */
  4208. var i = 0;
  4209. var props = this.props;
  4210. var cssValue = 'matrix3d(';
  4211. var v = 10000;
  4212. while (i < 16) {
  4213. cssValue += _rnd(props[i] * v) / v;
  4214. cssValue += i === 15 ? ')' : ',';
  4215. i += 1;
  4216. }
  4217. return cssValue;
  4218. }
  4219. function roundMatrixProperty(val) {
  4220. var v = 10000;
  4221. if (val < 0.000001 && val > 0 || val > -0.000001 && val < 0) {
  4222. return _rnd(val * v) / v;
  4223. }
  4224. return val;
  4225. }
  4226. function to2dCSS() {
  4227. // 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.
  4228. /* if(this.isIdentity()) {
  4229. return '';
  4230. } */
  4231. var props = this.props;
  4232. var _a = roundMatrixProperty(props[0]);
  4233. var _b = roundMatrixProperty(props[1]);
  4234. var _c = roundMatrixProperty(props[4]);
  4235. var _d = roundMatrixProperty(props[5]);
  4236. var _e = roundMatrixProperty(props[12]);
  4237. var _f = roundMatrixProperty(props[13]);
  4238. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4239. }
  4240. return function () {
  4241. this.reset = reset;
  4242. this.rotate = rotate;
  4243. this.rotateX = rotateX;
  4244. this.rotateY = rotateY;
  4245. this.rotateZ = rotateZ;
  4246. this.skew = skew;
  4247. this.skewFromAxis = skewFromAxis;
  4248. this.shear = shear;
  4249. this.scale = scale;
  4250. this.setTransform = setTransform;
  4251. this.translate = translate;
  4252. this.transform = transform;
  4253. this.multiply = multiply;
  4254. this.applyToPoint = applyToPoint;
  4255. this.applyToX = applyToX;
  4256. this.applyToY = applyToY;
  4257. this.applyToZ = applyToZ;
  4258. this.applyToPointArray = applyToPointArray;
  4259. this.applyToTriplePoints = applyToTriplePoints;
  4260. this.applyToPointStringified = applyToPointStringified;
  4261. this.toCSS = toCSS;
  4262. this.to2dCSS = to2dCSS;
  4263. this.clone = clone;
  4264. this.cloneFromProps = cloneFromProps;
  4265. this.equals = equals;
  4266. this.inversePoints = inversePoints;
  4267. this.inversePoint = inversePoint;
  4268. this.getInverseMatrix = getInverseMatrix;
  4269. this._t = this.transform;
  4270. this.isIdentity = isIdentity;
  4271. this._identity = true;
  4272. this._identityCalculated = false;
  4273. this.props = createTypedArray('float32', 16);
  4274. this.reset();
  4275. };
  4276. }();
  4277. function _typeof$3(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$3 = function _typeof(obj) { return typeof obj; }; } else { _typeof$3 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$3(obj); }
  4278. var lottie = {};
  4279. var standalone = '__[STANDALONE]__';
  4280. var animationData = '__[ANIMATIONDATA]__';
  4281. var renderer = '';
  4282. function setLocation(href) {
  4283. setLocationHref(href);
  4284. }
  4285. function searchAnimations() {
  4286. if (standalone === true) {
  4287. animationManager.searchAnimations(animationData, standalone, renderer);
  4288. } else {
  4289. animationManager.searchAnimations();
  4290. }
  4291. }
  4292. function setSubframeRendering(flag) {
  4293. setSubframeEnabled(flag);
  4294. }
  4295. function setPrefix(prefix) {
  4296. setIdPrefix(prefix);
  4297. }
  4298. function loadAnimation(params) {
  4299. if (standalone === true) {
  4300. params.animationData = JSON.parse(animationData);
  4301. }
  4302. return animationManager.loadAnimation(params);
  4303. }
  4304. function setQuality(value) {
  4305. if (typeof value === 'string') {
  4306. switch (value) {
  4307. case 'high':
  4308. setDefaultCurveSegments(200);
  4309. break;
  4310. default:
  4311. case 'medium':
  4312. setDefaultCurveSegments(50);
  4313. break;
  4314. case 'low':
  4315. setDefaultCurveSegments(10);
  4316. break;
  4317. }
  4318. } else if (!isNaN(value) && value > 1) {
  4319. setDefaultCurveSegments(value);
  4320. }
  4321. if (getDefaultCurveSegments() >= 50) {
  4322. roundValues(false);
  4323. } else {
  4324. roundValues(true);
  4325. }
  4326. }
  4327. function inBrowser() {
  4328. return typeof navigator !== 'undefined';
  4329. }
  4330. function installPlugin(type, plugin) {
  4331. if (type === 'expressions') {
  4332. setExpressionsPlugin(plugin);
  4333. }
  4334. }
  4335. function getFactory(name) {
  4336. switch (name) {
  4337. case 'propertyFactory':
  4338. return PropertyFactory;
  4339. case 'shapePropertyFactory':
  4340. return ShapePropertyFactory;
  4341. case 'matrix':
  4342. return Matrix;
  4343. default:
  4344. return null;
  4345. }
  4346. }
  4347. lottie.play = animationManager.play;
  4348. lottie.pause = animationManager.pause;
  4349. lottie.setLocationHref = setLocation;
  4350. lottie.togglePause = animationManager.togglePause;
  4351. lottie.setSpeed = animationManager.setSpeed;
  4352. lottie.setDirection = animationManager.setDirection;
  4353. lottie.stop = animationManager.stop;
  4354. lottie.searchAnimations = searchAnimations;
  4355. lottie.registerAnimation = animationManager.registerAnimation;
  4356. lottie.loadAnimation = loadAnimation;
  4357. lottie.setSubframeRendering = setSubframeRendering;
  4358. lottie.resize = animationManager.resize; // lottie.start = start;
  4359. lottie.goToAndStop = animationManager.goToAndStop;
  4360. lottie.destroy = animationManager.destroy;
  4361. lottie.setQuality = setQuality;
  4362. lottie.inBrowser = inBrowser;
  4363. lottie.installPlugin = installPlugin;
  4364. lottie.freeze = animationManager.freeze;
  4365. lottie.unfreeze = animationManager.unfreeze;
  4366. lottie.setVolume = animationManager.setVolume;
  4367. lottie.mute = animationManager.mute;
  4368. lottie.unmute = animationManager.unmute;
  4369. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4370. lottie.useWebWorker = setWebWorker;
  4371. lottie.setIDPrefix = setPrefix;
  4372. lottie.__getFactory = getFactory;
  4373. lottie.version = '5.12.2';
  4374. function checkReady() {
  4375. if (document.readyState === 'complete') {
  4376. clearInterval(readyStateCheckInterval);
  4377. searchAnimations();
  4378. }
  4379. }
  4380. function getQueryVariable(variable) {
  4381. var vars = queryString.split('&');
  4382. for (var i = 0; i < vars.length; i += 1) {
  4383. var pair = vars[i].split('=');
  4384. if (decodeURIComponent(pair[0]) == variable) {
  4385. // eslint-disable-line eqeqeq
  4386. return decodeURIComponent(pair[1]);
  4387. }
  4388. }
  4389. return null;
  4390. }
  4391. var queryString = '';
  4392. if (standalone) {
  4393. var scripts = document.getElementsByTagName('script');
  4394. var index = scripts.length - 1;
  4395. var myScript = scripts[index] || {
  4396. src: ''
  4397. };
  4398. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4399. renderer = getQueryVariable('renderer');
  4400. }
  4401. var readyStateCheckInterval = setInterval(checkReady, 100); // this adds bodymovin to the window object for backwards compatibility
  4402. try {
  4403. if (!((typeof exports === "undefined" ? "undefined" : _typeof$3(exports)) === 'object' && typeof module !== 'undefined') && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4404. ) {
  4405. window.bodymovin = lottie;
  4406. }
  4407. } catch (err) {//
  4408. }
  4409. var ShapeModifiers = function () {
  4410. var ob = {};
  4411. var modifiers = {};
  4412. ob.registerModifier = registerModifier;
  4413. ob.getModifier = getModifier;
  4414. function registerModifier(nm, factory) {
  4415. if (!modifiers[nm]) {
  4416. modifiers[nm] = factory;
  4417. }
  4418. }
  4419. function getModifier(nm, elem, data) {
  4420. return new modifiers[nm](elem, data);
  4421. }
  4422. return ob;
  4423. }();
  4424. function ShapeModifier() {}
  4425. ShapeModifier.prototype.initModifierProperties = function () {};
  4426. ShapeModifier.prototype.addShapeToModifier = function () {};
  4427. ShapeModifier.prototype.addShape = function (data) {
  4428. if (!this.closed) {
  4429. // 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.
  4430. data.sh.container.addDynamicProperty(data.sh);
  4431. var shapeData = {
  4432. shape: data.sh,
  4433. data: data,
  4434. localShapeCollection: shapeCollectionPool.newShapeCollection()
  4435. };
  4436. this.shapes.push(shapeData);
  4437. this.addShapeToModifier(shapeData);
  4438. if (this._isAnimated) {
  4439. data.setAsAnimated();
  4440. }
  4441. }
  4442. };
  4443. ShapeModifier.prototype.init = function (elem, data) {
  4444. this.shapes = [];
  4445. this.elem = elem;
  4446. this.initDynamicPropertyContainer(elem);
  4447. this.initModifierProperties(elem, data);
  4448. this.frameId = initialDefaultFrame;
  4449. this.closed = false;
  4450. this.k = false;
  4451. if (this.dynamicProperties.length) {
  4452. this.k = true;
  4453. } else {
  4454. this.getValue(true);
  4455. }
  4456. };
  4457. ShapeModifier.prototype.processKeys = function () {
  4458. if (this.elem.globalData.frameId === this.frameId) {
  4459. return;
  4460. }
  4461. this.frameId = this.elem.globalData.frameId;
  4462. this.iterateDynamicProperties();
  4463. };
  4464. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4465. function TrimModifier() {}
  4466. extendPrototype([ShapeModifier], TrimModifier);
  4467. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4468. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4469. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4470. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4471. this.sValue = 0;
  4472. this.eValue = 0;
  4473. this.getValue = this.processKeys;
  4474. this.m = data.m;
  4475. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4476. };
  4477. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4478. shapeData.pathsData = [];
  4479. };
  4480. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4481. var segments = [];
  4482. if (e <= 1) {
  4483. segments.push({
  4484. s: s,
  4485. e: e
  4486. });
  4487. } else if (s >= 1) {
  4488. segments.push({
  4489. s: s - 1,
  4490. e: e - 1
  4491. });
  4492. } else {
  4493. segments.push({
  4494. s: s,
  4495. e: 1
  4496. });
  4497. segments.push({
  4498. s: 0,
  4499. e: e - 1
  4500. });
  4501. }
  4502. var shapeSegments = [];
  4503. var i;
  4504. var len = segments.length;
  4505. var segmentOb;
  4506. for (i = 0; i < len; i += 1) {
  4507. segmentOb = segments[i];
  4508. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4509. var shapeS;
  4510. var shapeE;
  4511. if (segmentOb.s * totalModifierLength <= addedLength) {
  4512. shapeS = 0;
  4513. } else {
  4514. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4515. }
  4516. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4517. shapeE = 1;
  4518. } else {
  4519. shapeE = (segmentOb.e * totalModifierLength - addedLength) / shapeLength;
  4520. }
  4521. shapeSegments.push([shapeS, shapeE]);
  4522. }
  4523. }
  4524. if (!shapeSegments.length) {
  4525. shapeSegments.push([0, 0]);
  4526. }
  4527. return shapeSegments;
  4528. };
  4529. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4530. var i;
  4531. var len = pathsData.length;
  4532. for (i = 0; i < len; i += 1) {
  4533. segmentsLengthPool.release(pathsData[i]);
  4534. }
  4535. pathsData.length = 0;
  4536. return pathsData;
  4537. };
  4538. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4539. var s;
  4540. var e;
  4541. if (this._mdf || _isFirstFrame) {
  4542. var o = this.o.v % 360 / 360;
  4543. if (o < 0) {
  4544. o += 1;
  4545. }
  4546. if (this.s.v > 1) {
  4547. s = 1 + o;
  4548. } else if (this.s.v < 0) {
  4549. s = 0 + o;
  4550. } else {
  4551. s = this.s.v + o;
  4552. }
  4553. if (this.e.v > 1) {
  4554. e = 1 + o;
  4555. } else if (this.e.v < 0) {
  4556. e = 0 + o;
  4557. } else {
  4558. e = this.e.v + o;
  4559. }
  4560. if (s > e) {
  4561. var _s = s;
  4562. s = e;
  4563. e = _s;
  4564. }
  4565. s = Math.round(s * 10000) * 0.0001;
  4566. e = Math.round(e * 10000) * 0.0001;
  4567. this.sValue = s;
  4568. this.eValue = e;
  4569. } else {
  4570. s = this.sValue;
  4571. e = this.eValue;
  4572. }
  4573. var shapePaths;
  4574. var i;
  4575. var len = this.shapes.length;
  4576. var j;
  4577. var jLen;
  4578. var pathsData;
  4579. var pathData;
  4580. var totalShapeLength;
  4581. var totalModifierLength = 0;
  4582. if (e === s) {
  4583. for (i = 0; i < len; i += 1) {
  4584. this.shapes[i].localShapeCollection.releaseShapes();
  4585. this.shapes[i].shape._mdf = true;
  4586. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4587. if (this._mdf) {
  4588. this.shapes[i].pathsData.length = 0;
  4589. }
  4590. }
  4591. } else if (!(e === 1 && s === 0 || e === 0 && s === 1)) {
  4592. var segments = [];
  4593. var shapeData;
  4594. var localShapeCollection;
  4595. for (i = 0; i < len; i += 1) {
  4596. shapeData = this.shapes[i]; // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4597. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4598. shapeData.shape.paths = shapeData.localShapeCollection;
  4599. } else {
  4600. shapePaths = shapeData.shape.paths;
  4601. jLen = shapePaths._length;
  4602. totalShapeLength = 0;
  4603. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4604. totalShapeLength = shapeData.totalShapeLength;
  4605. } else {
  4606. pathsData = this.releasePathsData(shapeData.pathsData);
  4607. for (j = 0; j < jLen; j += 1) {
  4608. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4609. pathsData.push(pathData);
  4610. totalShapeLength += pathData.totalLength;
  4611. }
  4612. shapeData.totalShapeLength = totalShapeLength;
  4613. shapeData.pathsData = pathsData;
  4614. }
  4615. totalModifierLength += totalShapeLength;
  4616. shapeData.shape._mdf = true;
  4617. }
  4618. }
  4619. var shapeS = s;
  4620. var shapeE = e;
  4621. var addedLength = 0;
  4622. var edges;
  4623. for (i = len - 1; i >= 0; i -= 1) {
  4624. shapeData = this.shapes[i];
  4625. if (shapeData.shape._mdf) {
  4626. localShapeCollection = shapeData.localShapeCollection;
  4627. localShapeCollection.releaseShapes(); // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4628. if (this.m === 2 && len > 1) {
  4629. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4630. addedLength += shapeData.totalShapeLength;
  4631. } else {
  4632. edges = [[shapeS, shapeE]];
  4633. }
  4634. jLen = edges.length;
  4635. for (j = 0; j < jLen; j += 1) {
  4636. shapeS = edges[j][0];
  4637. shapeE = edges[j][1];
  4638. segments.length = 0;
  4639. if (shapeE <= 1) {
  4640. segments.push({
  4641. s: shapeData.totalShapeLength * shapeS,
  4642. e: shapeData.totalShapeLength * shapeE
  4643. });
  4644. } else if (shapeS >= 1) {
  4645. segments.push({
  4646. s: shapeData.totalShapeLength * (shapeS - 1),
  4647. e: shapeData.totalShapeLength * (shapeE - 1)
  4648. });
  4649. } else {
  4650. segments.push({
  4651. s: shapeData.totalShapeLength * shapeS,
  4652. e: shapeData.totalShapeLength
  4653. });
  4654. segments.push({
  4655. s: 0,
  4656. e: shapeData.totalShapeLength * (shapeE - 1)
  4657. });
  4658. }
  4659. var newShapesData = this.addShapes(shapeData, segments[0]);
  4660. if (segments[0].s !== segments[0].e) {
  4661. if (segments.length > 1) {
  4662. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4663. if (lastShapeInCollection.c) {
  4664. var lastShape = newShapesData.pop();
  4665. this.addPaths(newShapesData, localShapeCollection);
  4666. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4667. } else {
  4668. this.addPaths(newShapesData, localShapeCollection);
  4669. newShapesData = this.addShapes(shapeData, segments[1]);
  4670. }
  4671. }
  4672. this.addPaths(newShapesData, localShapeCollection);
  4673. }
  4674. }
  4675. shapeData.shape.paths = localShapeCollection;
  4676. }
  4677. }
  4678. } else if (this._mdf) {
  4679. for (i = 0; i < len; i += 1) {
  4680. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4681. // Don't remove this even if it's losing cached info.
  4682. this.shapes[i].pathsData.length = 0;
  4683. this.shapes[i].shape._mdf = true;
  4684. }
  4685. }
  4686. };
  4687. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4688. var i;
  4689. var len = newPaths.length;
  4690. for (i = 0; i < len; i += 1) {
  4691. localShapeCollection.addShape(newPaths[i]);
  4692. }
  4693. };
  4694. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4695. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4696. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4697. if (newShape) {
  4698. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4699. }
  4700. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4701. };
  4702. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4703. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4704. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4705. if (newShape) {
  4706. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4707. }
  4708. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4709. };
  4710. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4711. var pathsData = shapeData.pathsData;
  4712. var shapePaths = shapeData.shape.paths.shapes;
  4713. var i;
  4714. var len = shapeData.shape.paths._length;
  4715. var j;
  4716. var jLen;
  4717. var addedLength = 0;
  4718. var currentLengthData;
  4719. var segmentCount;
  4720. var lengths;
  4721. var segment;
  4722. var shapes = [];
  4723. var initPos;
  4724. var newShape = true;
  4725. if (!shapePath) {
  4726. shapePath = shapePool.newElement();
  4727. segmentCount = 0;
  4728. initPos = 0;
  4729. } else {
  4730. segmentCount = shapePath._length;
  4731. initPos = shapePath._length;
  4732. }
  4733. shapes.push(shapePath);
  4734. for (i = 0; i < len; i += 1) {
  4735. lengths = pathsData[i].lengths;
  4736. shapePath.c = shapePaths[i].c;
  4737. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4738. for (j = 1; j < jLen; j += 1) {
  4739. currentLengthData = lengths[j - 1];
  4740. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4741. addedLength += currentLengthData.addedLength;
  4742. shapePath.c = false;
  4743. } else if (addedLength > shapeSegment.e) {
  4744. shapePath.c = false;
  4745. break;
  4746. } else {
  4747. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4748. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4749. newShape = false;
  4750. } else {
  4751. 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]);
  4752. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape); // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4753. newShape = false;
  4754. shapePath.c = false;
  4755. }
  4756. addedLength += currentLengthData.addedLength;
  4757. segmentCount += 1;
  4758. }
  4759. }
  4760. if (shapePaths[i].c && lengths.length) {
  4761. currentLengthData = lengths[j - 1];
  4762. if (addedLength <= shapeSegment.e) {
  4763. var segmentLength = lengths[j - 1].addedLength;
  4764. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4765. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4766. newShape = false;
  4767. } else {
  4768. 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]);
  4769. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape); // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4770. newShape = false;
  4771. shapePath.c = false;
  4772. }
  4773. } else {
  4774. shapePath.c = false;
  4775. }
  4776. addedLength += currentLengthData.addedLength;
  4777. segmentCount += 1;
  4778. }
  4779. if (shapePath._length) {
  4780. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4781. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4782. }
  4783. if (addedLength > shapeSegment.e) {
  4784. break;
  4785. }
  4786. if (i < len - 1) {
  4787. shapePath = shapePool.newElement();
  4788. newShape = true;
  4789. shapes.push(shapePath);
  4790. segmentCount = 0;
  4791. }
  4792. }
  4793. return shapes;
  4794. };
  4795. function PuckerAndBloatModifier() {}
  4796. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4797. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4798. this.getValue = this.processKeys;
  4799. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4800. this._isAnimated = !!this.amount.effectsSequence.length;
  4801. };
  4802. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4803. var percent = amount / 100;
  4804. var centerPoint = [0, 0];
  4805. var pathLength = path._length;
  4806. var i = 0;
  4807. for (i = 0; i < pathLength; i += 1) {
  4808. centerPoint[0] += path.v[i][0];
  4809. centerPoint[1] += path.v[i][1];
  4810. }
  4811. centerPoint[0] /= pathLength;
  4812. centerPoint[1] /= pathLength;
  4813. var clonedPath = shapePool.newElement();
  4814. clonedPath.c = path.c;
  4815. var vX;
  4816. var vY;
  4817. var oX;
  4818. var oY;
  4819. var iX;
  4820. var iY;
  4821. for (i = 0; i < pathLength; i += 1) {
  4822. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4823. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4824. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4825. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4826. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4827. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4828. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4829. }
  4830. return clonedPath;
  4831. };
  4832. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4833. var shapePaths;
  4834. var i;
  4835. var len = this.shapes.length;
  4836. var j;
  4837. var jLen;
  4838. var amount = this.amount.v;
  4839. if (amount !== 0) {
  4840. var shapeData;
  4841. var localShapeCollection;
  4842. for (i = 0; i < len; i += 1) {
  4843. shapeData = this.shapes[i];
  4844. localShapeCollection = shapeData.localShapeCollection;
  4845. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4846. localShapeCollection.releaseShapes();
  4847. shapeData.shape._mdf = true;
  4848. shapePaths = shapeData.shape.paths.shapes;
  4849. jLen = shapeData.shape.paths._length;
  4850. for (j = 0; j < jLen; j += 1) {
  4851. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4852. }
  4853. }
  4854. shapeData.shape.paths = shapeData.localShapeCollection;
  4855. }
  4856. }
  4857. if (!this.dynamicProperties.length) {
  4858. this._mdf = false;
  4859. }
  4860. };
  4861. var TransformPropertyFactory = function () {
  4862. var defaultVector = [0, 0];
  4863. function applyToMatrix(mat) {
  4864. var _mdf = this._mdf;
  4865. this.iterateDynamicProperties();
  4866. this._mdf = this._mdf || _mdf;
  4867. if (this.a) {
  4868. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4869. }
  4870. if (this.s) {
  4871. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4872. }
  4873. if (this.sk) {
  4874. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4875. }
  4876. if (this.r) {
  4877. mat.rotate(-this.r.v);
  4878. } else {
  4879. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  4880. }
  4881. if (this.data.p.s) {
  4882. if (this.data.p.z) {
  4883. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4884. } else {
  4885. mat.translate(this.px.v, this.py.v, 0);
  4886. }
  4887. } else {
  4888. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4889. }
  4890. }
  4891. function processKeys(forceRender) {
  4892. if (this.elem.globalData.frameId === this.frameId) {
  4893. return;
  4894. }
  4895. if (this._isDirty) {
  4896. this.precalculateMatrix();
  4897. this._isDirty = false;
  4898. }
  4899. this.iterateDynamicProperties();
  4900. if (this._mdf || forceRender) {
  4901. var frameRate;
  4902. this.v.cloneFromProps(this.pre.props);
  4903. if (this.appliedTransformations < 1) {
  4904. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4905. }
  4906. if (this.appliedTransformations < 2) {
  4907. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4908. }
  4909. if (this.sk && this.appliedTransformations < 3) {
  4910. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4911. }
  4912. if (this.r && this.appliedTransformations < 4) {
  4913. this.v.rotate(-this.r.v);
  4914. } else if (!this.r && this.appliedTransformations < 4) {
  4915. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  4916. }
  4917. if (this.autoOriented) {
  4918. var v1;
  4919. var v2;
  4920. frameRate = this.elem.globalData.frameRate;
  4921. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4922. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4923. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4924. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4925. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4926. v1 = this.p.getValueAtTime(this.p.keyframes[this.p.keyframes.length - 1].t / frameRate, 0);
  4927. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4928. } else {
  4929. v1 = this.p.pv;
  4930. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4931. }
  4932. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4933. v1 = [];
  4934. v2 = [];
  4935. var px = this.px;
  4936. var py = this.py;
  4937. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4938. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4939. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4940. v2[0] = px.getValueAtTime(px.keyframes[0].t / frameRate, 0);
  4941. v2[1] = py.getValueAtTime(py.keyframes[0].t / frameRate, 0);
  4942. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4943. v1[0] = px.getValueAtTime(px.keyframes[px.keyframes.length - 1].t / frameRate, 0);
  4944. v1[1] = py.getValueAtTime(py.keyframes[py.keyframes.length - 1].t / frameRate, 0);
  4945. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4946. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4947. } else {
  4948. v1 = [px.pv, py.pv];
  4949. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4950. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4951. }
  4952. } else {
  4953. v2 = defaultVector;
  4954. v1 = v2;
  4955. }
  4956. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4957. }
  4958. if (this.data.p && this.data.p.s) {
  4959. if (this.data.p.z) {
  4960. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4961. } else {
  4962. this.v.translate(this.px.v, this.py.v, 0);
  4963. }
  4964. } else {
  4965. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4966. }
  4967. }
  4968. this.frameId = this.elem.globalData.frameId;
  4969. }
  4970. function precalculateMatrix() {
  4971. this.appliedTransformations = 0;
  4972. this.pre.reset();
  4973. if (!this.a.effectsSequence.length) {
  4974. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4975. this.appliedTransformations = 1;
  4976. } else {
  4977. return;
  4978. }
  4979. if (!this.s.effectsSequence.length) {
  4980. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4981. this.appliedTransformations = 2;
  4982. } else {
  4983. return;
  4984. }
  4985. if (this.sk) {
  4986. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  4987. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  4988. this.appliedTransformations = 3;
  4989. } else {
  4990. return;
  4991. }
  4992. }
  4993. if (this.r) {
  4994. if (!this.r.effectsSequence.length) {
  4995. this.pre.rotate(-this.r.v);
  4996. this.appliedTransformations = 4;
  4997. }
  4998. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  4999. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  5000. this.appliedTransformations = 4;
  5001. }
  5002. }
  5003. function autoOrient() {//
  5004. // var prevP = this.getValueAtTime();
  5005. }
  5006. function addDynamicProperty(prop) {
  5007. this._addDynamicProperty(prop);
  5008. this.elem.addDynamicProperty(prop);
  5009. this._isDirty = true;
  5010. }
  5011. function TransformProperty(elem, data, container) {
  5012. this.elem = elem;
  5013. this.frameId = -1;
  5014. this.propType = 'transform';
  5015. this.data = data;
  5016. this.v = new Matrix(); // Precalculated matrix with non animated properties
  5017. this.pre = new Matrix();
  5018. this.appliedTransformations = 0;
  5019. this.initDynamicPropertyContainer(container || elem);
  5020. if (data.p && data.p.s) {
  5021. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  5022. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  5023. if (data.p.z) {
  5024. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  5025. }
  5026. } else {
  5027. this.p = PropertyFactory.getProp(elem, data.p || {
  5028. k: [0, 0, 0]
  5029. }, 1, 0, this);
  5030. }
  5031. if (data.rx) {
  5032. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  5033. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  5034. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  5035. if (data.or.k[0].ti) {
  5036. var i;
  5037. var len = data.or.k.length;
  5038. for (i = 0; i < len; i += 1) {
  5039. data.or.k[i].to = null;
  5040. data.or.k[i].ti = null;
  5041. }
  5042. }
  5043. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this); // sh Indicates it needs to be capped between -180 and 180
  5044. this.or.sh = true;
  5045. } else {
  5046. this.r = PropertyFactory.getProp(elem, data.r || {
  5047. k: 0
  5048. }, 0, degToRads, this);
  5049. }
  5050. if (data.sk) {
  5051. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  5052. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  5053. }
  5054. this.a = PropertyFactory.getProp(elem, data.a || {
  5055. k: [0, 0, 0]
  5056. }, 1, 0, this);
  5057. this.s = PropertyFactory.getProp(elem, data.s || {
  5058. k: [100, 100, 100]
  5059. }, 1, 0.01, this); // 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.
  5060. if (data.o) {
  5061. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  5062. } else {
  5063. this.o = {
  5064. _mdf: false,
  5065. v: 1
  5066. };
  5067. }
  5068. this._isDirty = true;
  5069. if (!this.dynamicProperties.length) {
  5070. this.getValue(true);
  5071. }
  5072. }
  5073. TransformProperty.prototype = {
  5074. applyToMatrix: applyToMatrix,
  5075. getValue: processKeys,
  5076. precalculateMatrix: precalculateMatrix,
  5077. autoOrient: autoOrient
  5078. };
  5079. extendPrototype([DynamicPropertyContainer], TransformProperty);
  5080. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  5081. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  5082. function getTransformProperty(elem, data, container) {
  5083. return new TransformProperty(elem, data, container);
  5084. }
  5085. return {
  5086. getTransformProperty: getTransformProperty
  5087. };
  5088. }();
  5089. function RepeaterModifier() {}
  5090. extendPrototype([ShapeModifier], RepeaterModifier);
  5091. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5092. this.getValue = this.processKeys;
  5093. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5094. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5095. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5096. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5097. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5098. this.data = data;
  5099. if (!this.dynamicProperties.length) {
  5100. this.getValue(true);
  5101. }
  5102. this._isAnimated = !!this.dynamicProperties.length;
  5103. this.pMatrix = new Matrix();
  5104. this.rMatrix = new Matrix();
  5105. this.sMatrix = new Matrix();
  5106. this.tMatrix = new Matrix();
  5107. this.matrix = new Matrix();
  5108. };
  5109. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5110. var dir = inv ? -1 : 1;
  5111. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5112. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5113. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5114. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5115. rMatrix.rotate(-transform.r.v * dir * perc);
  5116. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5117. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5118. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5119. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5120. };
  5121. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5122. this.elem = elem;
  5123. this.arr = arr;
  5124. this.pos = pos;
  5125. this.elemsData = elemsData;
  5126. this._currentCopies = 0;
  5127. this._elements = [];
  5128. this._groups = [];
  5129. this.frameId = -1;
  5130. this.initDynamicPropertyContainer(elem);
  5131. this.initModifierProperties(elem, arr[pos]);
  5132. while (pos > 0) {
  5133. pos -= 1; // this._elements.unshift(arr.splice(pos,1)[0]);
  5134. this._elements.unshift(arr[pos]);
  5135. }
  5136. if (this.dynamicProperties.length) {
  5137. this.k = true;
  5138. } else {
  5139. this.getValue(true);
  5140. }
  5141. };
  5142. RepeaterModifier.prototype.resetElements = function (elements) {
  5143. var i;
  5144. var len = elements.length;
  5145. for (i = 0; i < len; i += 1) {
  5146. elements[i]._processed = false;
  5147. if (elements[i].ty === 'gr') {
  5148. this.resetElements(elements[i].it);
  5149. }
  5150. }
  5151. };
  5152. RepeaterModifier.prototype.cloneElements = function (elements) {
  5153. var newElements = JSON.parse(JSON.stringify(elements));
  5154. this.resetElements(newElements);
  5155. return newElements;
  5156. };
  5157. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5158. var i;
  5159. var len = elements.length;
  5160. for (i = 0; i < len; i += 1) {
  5161. elements[i]._render = renderFlag;
  5162. if (elements[i].ty === 'gr') {
  5163. this.changeGroupRender(elements[i].it, renderFlag);
  5164. }
  5165. }
  5166. };
  5167. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5168. var items;
  5169. var itemsTransform;
  5170. var i;
  5171. var dir;
  5172. var cont;
  5173. var hasReloaded = false;
  5174. if (this._mdf || _isFirstFrame) {
  5175. var copies = Math.ceil(this.c.v);
  5176. if (this._groups.length < copies) {
  5177. while (this._groups.length < copies) {
  5178. var group = {
  5179. it: this.cloneElements(this._elements),
  5180. ty: 'gr'
  5181. };
  5182. group.it.push({
  5183. a: {
  5184. a: 0,
  5185. ix: 1,
  5186. k: [0, 0]
  5187. },
  5188. nm: 'Transform',
  5189. o: {
  5190. a: 0,
  5191. ix: 7,
  5192. k: 100
  5193. },
  5194. p: {
  5195. a: 0,
  5196. ix: 2,
  5197. k: [0, 0]
  5198. },
  5199. r: {
  5200. a: 1,
  5201. ix: 6,
  5202. k: [{
  5203. s: 0,
  5204. e: 0,
  5205. t: 0
  5206. }, {
  5207. s: 0,
  5208. e: 0,
  5209. t: 1
  5210. }]
  5211. },
  5212. s: {
  5213. a: 0,
  5214. ix: 3,
  5215. k: [100, 100]
  5216. },
  5217. sa: {
  5218. a: 0,
  5219. ix: 5,
  5220. k: 0
  5221. },
  5222. sk: {
  5223. a: 0,
  5224. ix: 4,
  5225. k: 0
  5226. },
  5227. ty: 'tr'
  5228. });
  5229. this.arr.splice(0, 0, group);
  5230. this._groups.splice(0, 0, group);
  5231. this._currentCopies += 1;
  5232. }
  5233. this.elem.reloadShapes();
  5234. hasReloaded = true;
  5235. }
  5236. cont = 0;
  5237. var renderFlag;
  5238. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5239. renderFlag = cont < copies;
  5240. this._groups[i]._render = renderFlag;
  5241. this.changeGroupRender(this._groups[i].it, renderFlag);
  5242. if (!renderFlag) {
  5243. var elems = this.elemsData[i].it;
  5244. var transformData = elems[elems.length - 1];
  5245. if (transformData.transform.op.v !== 0) {
  5246. transformData.transform.op._mdf = true;
  5247. transformData.transform.op.v = 0;
  5248. } else {
  5249. transformData.transform.op._mdf = false;
  5250. }
  5251. }
  5252. cont += 1;
  5253. }
  5254. this._currentCopies = copies; /// /
  5255. var offset = this.o.v;
  5256. var offsetModulo = offset % 1;
  5257. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5258. var pProps = this.pMatrix.props;
  5259. var rProps = this.rMatrix.props;
  5260. var sProps = this.sMatrix.props;
  5261. this.pMatrix.reset();
  5262. this.rMatrix.reset();
  5263. this.sMatrix.reset();
  5264. this.tMatrix.reset();
  5265. this.matrix.reset();
  5266. var iteration = 0;
  5267. if (offset > 0) {
  5268. while (iteration < roundOffset) {
  5269. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5270. iteration += 1;
  5271. }
  5272. if (offsetModulo) {
  5273. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5274. iteration += offsetModulo;
  5275. }
  5276. } else if (offset < 0) {
  5277. while (iteration > roundOffset) {
  5278. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5279. iteration -= 1;
  5280. }
  5281. if (offsetModulo) {
  5282. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5283. iteration -= offsetModulo;
  5284. }
  5285. }
  5286. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5287. dir = this.data.m === 1 ? 1 : -1;
  5288. cont = this._currentCopies;
  5289. var j;
  5290. var jLen;
  5291. while (cont) {
  5292. items = this.elemsData[i].it;
  5293. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5294. jLen = itemsTransform.length;
  5295. items[items.length - 1].transform.mProps._mdf = true;
  5296. items[items.length - 1].transform.op._mdf = true;
  5297. items[items.length - 1].transform.op.v = this._currentCopies === 1 ? this.so.v : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5298. if (iteration !== 0) {
  5299. if (i !== 0 && dir === 1 || i !== this._currentCopies - 1 && dir === -1) {
  5300. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5301. }
  5302. 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]);
  5303. 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]);
  5304. 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]);
  5305. for (j = 0; j < jLen; j += 1) {
  5306. itemsTransform[j] = this.matrix.props[j];
  5307. }
  5308. this.matrix.reset();
  5309. } else {
  5310. this.matrix.reset();
  5311. for (j = 0; j < jLen; j += 1) {
  5312. itemsTransform[j] = this.matrix.props[j];
  5313. }
  5314. }
  5315. iteration += 1;
  5316. cont -= 1;
  5317. i += dir;
  5318. }
  5319. } else {
  5320. cont = this._currentCopies;
  5321. i = 0;
  5322. dir = 1;
  5323. while (cont) {
  5324. items = this.elemsData[i].it;
  5325. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5326. items[items.length - 1].transform.mProps._mdf = false;
  5327. items[items.length - 1].transform.op._mdf = false;
  5328. cont -= 1;
  5329. i += dir;
  5330. }
  5331. }
  5332. return hasReloaded;
  5333. };
  5334. RepeaterModifier.prototype.addShape = function () {};
  5335. function RoundCornersModifier() {}
  5336. extendPrototype([ShapeModifier], RoundCornersModifier);
  5337. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5338. this.getValue = this.processKeys;
  5339. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5340. this._isAnimated = !!this.rd.effectsSequence.length;
  5341. };
  5342. RoundCornersModifier.prototype.processPath = function (path, round) {
  5343. var clonedPath = shapePool.newElement();
  5344. clonedPath.c = path.c;
  5345. var i;
  5346. var len = path._length;
  5347. var currentV;
  5348. var currentI;
  5349. var currentO;
  5350. var closerV;
  5351. var distance;
  5352. var newPosPerc;
  5353. var index = 0;
  5354. var vX;
  5355. var vY;
  5356. var oX;
  5357. var oY;
  5358. var iX;
  5359. var iY;
  5360. for (i = 0; i < len; i += 1) {
  5361. currentV = path.v[i];
  5362. currentO = path.o[i];
  5363. currentI = path.i[i];
  5364. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5365. if ((i === 0 || i === len - 1) && !path.c) {
  5366. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5367. /* clonedPath.v[index] = currentV;
  5368. clonedPath.o[index] = currentO;
  5369. clonedPath.i[index] = currentI; */
  5370. index += 1;
  5371. } else {
  5372. if (i === 0) {
  5373. closerV = path.v[len - 1];
  5374. } else {
  5375. closerV = path.v[i - 1];
  5376. }
  5377. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5378. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5379. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5380. vX = iX;
  5381. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5382. vY = iY;
  5383. oX = vX - (vX - currentV[0]) * roundCorner;
  5384. oY = vY - (vY - currentV[1]) * roundCorner;
  5385. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5386. index += 1;
  5387. if (i === len - 1) {
  5388. closerV = path.v[0];
  5389. } else {
  5390. closerV = path.v[i + 1];
  5391. }
  5392. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5393. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5394. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5395. vX = oX;
  5396. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5397. vY = oY;
  5398. iX = vX - (vX - currentV[0]) * roundCorner;
  5399. iY = vY - (vY - currentV[1]) * roundCorner;
  5400. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5401. index += 1;
  5402. }
  5403. } else {
  5404. 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);
  5405. index += 1;
  5406. }
  5407. }
  5408. return clonedPath;
  5409. };
  5410. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5411. var shapePaths;
  5412. var i;
  5413. var len = this.shapes.length;
  5414. var j;
  5415. var jLen;
  5416. var rd = this.rd.v;
  5417. if (rd !== 0) {
  5418. var shapeData;
  5419. var localShapeCollection;
  5420. for (i = 0; i < len; i += 1) {
  5421. shapeData = this.shapes[i];
  5422. localShapeCollection = shapeData.localShapeCollection;
  5423. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5424. localShapeCollection.releaseShapes();
  5425. shapeData.shape._mdf = true;
  5426. shapePaths = shapeData.shape.paths.shapes;
  5427. jLen = shapeData.shape.paths._length;
  5428. for (j = 0; j < jLen; j += 1) {
  5429. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5430. }
  5431. }
  5432. shapeData.shape.paths = shapeData.localShapeCollection;
  5433. }
  5434. }
  5435. if (!this.dynamicProperties.length) {
  5436. this._mdf = false;
  5437. }
  5438. };
  5439. function floatEqual(a, b) {
  5440. return Math.abs(a - b) * 100000 <= Math.min(Math.abs(a), Math.abs(b));
  5441. }
  5442. function floatZero(f) {
  5443. return Math.abs(f) <= 0.00001;
  5444. }
  5445. function lerp(p0, p1, amount) {
  5446. return p0 * (1 - amount) + p1 * amount;
  5447. }
  5448. function lerpPoint(p0, p1, amount) {
  5449. return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
  5450. }
  5451. function quadRoots(a, b, c) {
  5452. // no root
  5453. if (a === 0) return [];
  5454. var s = b * b - 4 * a * c; // Complex roots
  5455. if (s < 0) return [];
  5456. var singleRoot = -b / (2 * a); // 1 root
  5457. if (s === 0) return [singleRoot];
  5458. var delta = Math.sqrt(s) / (2 * a); // 2 roots
  5459. return [singleRoot - delta, singleRoot + delta];
  5460. }
  5461. function polynomialCoefficients(p0, p1, p2, p3) {
  5462. return [-p0 + 3 * p1 - 3 * p2 + p3, 3 * p0 - 6 * p1 + 3 * p2, -3 * p0 + 3 * p1, p0];
  5463. }
  5464. function singlePoint(p) {
  5465. return new PolynomialBezier(p, p, p, p, false);
  5466. }
  5467. function PolynomialBezier(p0, p1, p2, p3, linearize) {
  5468. if (linearize && pointEqual(p0, p1)) {
  5469. p1 = lerpPoint(p0, p3, 1 / 3);
  5470. }
  5471. if (linearize && pointEqual(p2, p3)) {
  5472. p2 = lerpPoint(p0, p3, 2 / 3);
  5473. }
  5474. var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
  5475. var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
  5476. this.a = [coeffx[0], coeffy[0]];
  5477. this.b = [coeffx[1], coeffy[1]];
  5478. this.c = [coeffx[2], coeffy[2]];
  5479. this.d = [coeffx[3], coeffy[3]];
  5480. this.points = [p0, p1, p2, p3];
  5481. }
  5482. PolynomialBezier.prototype.point = function (t) {
  5483. return [((this.a[0] * t + this.b[0]) * t + this.c[0]) * t + this.d[0], ((this.a[1] * t + this.b[1]) * t + this.c[1]) * t + this.d[1]];
  5484. };
  5485. PolynomialBezier.prototype.derivative = function (t) {
  5486. return [(3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0], (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1]];
  5487. };
  5488. PolynomialBezier.prototype.tangentAngle = function (t) {
  5489. var p = this.derivative(t);
  5490. return Math.atan2(p[1], p[0]);
  5491. };
  5492. PolynomialBezier.prototype.normalAngle = function (t) {
  5493. var p = this.derivative(t);
  5494. return Math.atan2(p[0], p[1]);
  5495. };
  5496. PolynomialBezier.prototype.inflectionPoints = function () {
  5497. var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
  5498. if (floatZero(denom)) return [];
  5499. var tcusp = -0.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1]) / denom;
  5500. var square = tcusp * tcusp - 1 / 3 * (this.b[1] * this.c[0] - this.b[0] * this.c[1]) / denom;
  5501. if (square < 0) return [];
  5502. var root = Math.sqrt(square);
  5503. if (floatZero(root)) {
  5504. if (root > 0 && root < 1) return [tcusp];
  5505. return [];
  5506. }
  5507. return [tcusp - root, tcusp + root].filter(function (r) {
  5508. return r > 0 && r < 1;
  5509. });
  5510. };
  5511. PolynomialBezier.prototype.split = function (t) {
  5512. if (t <= 0) return [singlePoint(this.points[0]), this];
  5513. if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
  5514. var p10 = lerpPoint(this.points[0], this.points[1], t);
  5515. var p11 = lerpPoint(this.points[1], this.points[2], t);
  5516. var p12 = lerpPoint(this.points[2], this.points[3], t);
  5517. var p20 = lerpPoint(p10, p11, t);
  5518. var p21 = lerpPoint(p11, p12, t);
  5519. var p3 = lerpPoint(p20, p21, t);
  5520. return [new PolynomialBezier(this.points[0], p10, p20, p3, true), new PolynomialBezier(p3, p21, p12, this.points[3], true)];
  5521. };
  5522. function extrema(bez, comp) {
  5523. var min = bez.points[0][comp];
  5524. var max = bez.points[bez.points.length - 1][comp];
  5525. if (min > max) {
  5526. var e = max;
  5527. max = min;
  5528. min = e;
  5529. } // Derivative roots to find min/max
  5530. var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
  5531. for (var i = 0; i < f.length; i += 1) {
  5532. if (f[i] > 0 && f[i] < 1) {
  5533. var val = bez.point(f[i])[comp];
  5534. if (val < min) min = val;else if (val > max) max = val;
  5535. }
  5536. }
  5537. return {
  5538. min: min,
  5539. max: max
  5540. };
  5541. }
  5542. PolynomialBezier.prototype.bounds = function () {
  5543. return {
  5544. x: extrema(this, 0),
  5545. y: extrema(this, 1)
  5546. };
  5547. };
  5548. PolynomialBezier.prototype.boundingBox = function () {
  5549. var bounds = this.bounds();
  5550. return {
  5551. left: bounds.x.min,
  5552. right: bounds.x.max,
  5553. top: bounds.y.min,
  5554. bottom: bounds.y.max,
  5555. width: bounds.x.max - bounds.x.min,
  5556. height: bounds.y.max - bounds.y.min,
  5557. cx: (bounds.x.max + bounds.x.min) / 2,
  5558. cy: (bounds.y.max + bounds.y.min) / 2
  5559. };
  5560. };
  5561. function intersectData(bez, t1, t2) {
  5562. var box = bez.boundingBox();
  5563. return {
  5564. cx: box.cx,
  5565. cy: box.cy,
  5566. width: box.width,
  5567. height: box.height,
  5568. bez: bez,
  5569. t: (t1 + t2) / 2,
  5570. t1: t1,
  5571. t2: t2
  5572. };
  5573. }
  5574. function splitData(data) {
  5575. var split = data.bez.split(0.5);
  5576. return [intersectData(split[0], data.t1, data.t), intersectData(split[1], data.t, data.t2)];
  5577. }
  5578. function boxIntersect(b1, b2) {
  5579. return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
  5580. }
  5581. function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
  5582. if (!boxIntersect(d1, d2)) return;
  5583. if (depth >= maxRecursion || d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance) {
  5584. intersections.push([d1.t, d2.t]);
  5585. return;
  5586. }
  5587. var d1s = splitData(d1);
  5588. var d2s = splitData(d2);
  5589. intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5590. intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5591. intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5592. intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5593. }
  5594. PolynomialBezier.prototype.intersections = function (other, tolerance, maxRecursion) {
  5595. if (tolerance === undefined) tolerance = 2;
  5596. if (maxRecursion === undefined) maxRecursion = 7;
  5597. var intersections = [];
  5598. intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
  5599. return intersections;
  5600. };
  5601. PolynomialBezier.shapeSegment = function (shapePath, index) {
  5602. var nextIndex = (index + 1) % shapePath.length();
  5603. return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
  5604. };
  5605. PolynomialBezier.shapeSegmentInverted = function (shapePath, index) {
  5606. var nextIndex = (index + 1) % shapePath.length();
  5607. return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
  5608. };
  5609. function crossProduct(a, b) {
  5610. return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
  5611. }
  5612. function lineIntersection(start1, end1, start2, end2) {
  5613. var v1 = [start1[0], start1[1], 1];
  5614. var v2 = [end1[0], end1[1], 1];
  5615. var v3 = [start2[0], start2[1], 1];
  5616. var v4 = [end2[0], end2[1], 1];
  5617. var r = crossProduct(crossProduct(v1, v2), crossProduct(v3, v4));
  5618. if (floatZero(r[2])) return null;
  5619. return [r[0] / r[2], r[1] / r[2]];
  5620. }
  5621. function polarOffset(p, angle, length) {
  5622. return [p[0] + Math.cos(angle) * length, p[1] - Math.sin(angle) * length];
  5623. }
  5624. function pointDistance(p1, p2) {
  5625. return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
  5626. }
  5627. function pointEqual(p1, p2) {
  5628. return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
  5629. }
  5630. function ZigZagModifier() {}
  5631. extendPrototype([ShapeModifier], ZigZagModifier);
  5632. ZigZagModifier.prototype.initModifierProperties = function (elem, data) {
  5633. this.getValue = this.processKeys;
  5634. this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
  5635. this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5636. this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
  5637. this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
  5638. };
  5639. function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
  5640. var angO = angle - Math.PI / 2;
  5641. var angI = angle + Math.PI / 2;
  5642. var px = point[0] + Math.cos(angle) * direction * amplitude;
  5643. var py = point[1] - Math.sin(angle) * direction * amplitude;
  5644. outputBezier.setTripleAt(px, py, px + Math.cos(angO) * outAmplitude, py - Math.sin(angO) * outAmplitude, px + Math.cos(angI) * inAmplitude, py - Math.sin(angI) * inAmplitude, outputBezier.length());
  5645. }
  5646. function getPerpendicularVector(pt1, pt2) {
  5647. var vector = [pt2[0] - pt1[0], pt2[1] - pt1[1]];
  5648. var rot = -Math.PI * 0.5;
  5649. var rotatedVector = [Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1], Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1]];
  5650. return rotatedVector;
  5651. }
  5652. function getProjectingAngle(path, cur) {
  5653. var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
  5654. var nextIndex = (cur + 1) % path.length();
  5655. var prevPoint = path.v[prevIndex];
  5656. var nextPoint = path.v[nextIndex];
  5657. var pVector = getPerpendicularVector(prevPoint, nextPoint);
  5658. return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
  5659. }
  5660. function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
  5661. var angle = getProjectingAngle(path, cur);
  5662. var point = path.v[cur % path._length];
  5663. var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
  5664. var nextPoint = path.v[(cur + 1) % path._length];
  5665. var prevDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2)) : 0;
  5666. var nextDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2)) : 0;
  5667. setPoint(outputBezier, path.v[cur % path._length], angle, direction, amplitude, nextDist / ((frequency + 1) * 2), prevDist / ((frequency + 1) * 2), pointType);
  5668. }
  5669. function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
  5670. for (var i = 0; i < frequency; i += 1) {
  5671. var t = (i + 1) / (frequency + 1);
  5672. var dist = pointType === 2 ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2)) : 0;
  5673. var angle = segment.normalAngle(t);
  5674. var point = segment.point(t);
  5675. setPoint(outputBezier, point, angle, direction, amplitude, dist / ((frequency + 1) * 2), dist / ((frequency + 1) * 2), pointType);
  5676. direction = -direction;
  5677. }
  5678. return direction;
  5679. }
  5680. ZigZagModifier.prototype.processPath = function (path, amplitude, frequency, pointType) {
  5681. var count = path._length;
  5682. var clonedPath = shapePool.newElement();
  5683. clonedPath.c = path.c;
  5684. if (!path.c) {
  5685. count -= 1;
  5686. }
  5687. if (count === 0) return clonedPath;
  5688. var direction = -1;
  5689. var segment = PolynomialBezier.shapeSegment(path, 0);
  5690. zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
  5691. for (var i = 0; i < count; i += 1) {
  5692. direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
  5693. if (i === count - 1 && !path.c) {
  5694. segment = null;
  5695. } else {
  5696. segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
  5697. }
  5698. zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
  5699. }
  5700. return clonedPath;
  5701. };
  5702. ZigZagModifier.prototype.processShapes = function (_isFirstFrame) {
  5703. var shapePaths;
  5704. var i;
  5705. var len = this.shapes.length;
  5706. var j;
  5707. var jLen;
  5708. var amplitude = this.amplitude.v;
  5709. var frequency = Math.max(0, Math.round(this.frequency.v));
  5710. var pointType = this.pointsType.v;
  5711. if (amplitude !== 0) {
  5712. var shapeData;
  5713. var localShapeCollection;
  5714. for (i = 0; i < len; i += 1) {
  5715. shapeData = this.shapes[i];
  5716. localShapeCollection = shapeData.localShapeCollection;
  5717. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5718. localShapeCollection.releaseShapes();
  5719. shapeData.shape._mdf = true;
  5720. shapePaths = shapeData.shape.paths.shapes;
  5721. jLen = shapeData.shape.paths._length;
  5722. for (j = 0; j < jLen; j += 1) {
  5723. localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
  5724. }
  5725. }
  5726. shapeData.shape.paths = shapeData.localShapeCollection;
  5727. }
  5728. }
  5729. if (!this.dynamicProperties.length) {
  5730. this._mdf = false;
  5731. }
  5732. };
  5733. function linearOffset(p1, p2, amount) {
  5734. var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
  5735. return [polarOffset(p1, angle, amount), polarOffset(p2, angle, amount)];
  5736. }
  5737. function offsetSegment(segment, amount) {
  5738. var p0;
  5739. var p1a;
  5740. var p1b;
  5741. var p2b;
  5742. var p2a;
  5743. var p3;
  5744. var e;
  5745. e = linearOffset(segment.points[0], segment.points[1], amount);
  5746. p0 = e[0];
  5747. p1a = e[1];
  5748. e = linearOffset(segment.points[1], segment.points[2], amount);
  5749. p1b = e[0];
  5750. p2b = e[1];
  5751. e = linearOffset(segment.points[2], segment.points[3], amount);
  5752. p2a = e[0];
  5753. p3 = e[1];
  5754. var p1 = lineIntersection(p0, p1a, p1b, p2b);
  5755. if (p1 === null) p1 = p1a;
  5756. var p2 = lineIntersection(p2a, p3, p1b, p2b);
  5757. if (p2 === null) p2 = p2a;
  5758. return new PolynomialBezier(p0, p1, p2, p3);
  5759. }
  5760. function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
  5761. var p0 = seg1.points[3];
  5762. var p1 = seg2.points[0]; // Bevel
  5763. if (lineJoin === 3) return p0; // Connected, they don't need a joint
  5764. if (pointEqual(p0, p1)) return p0; // Round
  5765. if (lineJoin === 2) {
  5766. var angleOut = -seg1.tangentAngle(1);
  5767. var angleIn = -seg2.tangentAngle(0) + Math.PI;
  5768. var center = lineIntersection(p0, polarOffset(p0, angleOut + Math.PI / 2, 100), p1, polarOffset(p1, angleOut + Math.PI / 2, 100));
  5769. var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
  5770. var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
  5771. outputBezier.setXYAt(tan[0], tan[1], 'o', outputBezier.length() - 1);
  5772. tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
  5773. outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
  5774. return p1;
  5775. } // Miter
  5776. var t0 = pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2];
  5777. var t1 = pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1];
  5778. var intersection = lineIntersection(t0, p0, p1, t1);
  5779. if (intersection && pointDistance(intersection, p0) < miterLimit) {
  5780. outputBezier.setTripleAt(intersection[0], intersection[1], intersection[0], intersection[1], intersection[0], intersection[1], outputBezier.length());
  5781. return intersection;
  5782. }
  5783. return p0;
  5784. }
  5785. function getIntersection(a, b) {
  5786. var intersect = a.intersections(b);
  5787. if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
  5788. if (intersect.length) return intersect[0];
  5789. return null;
  5790. }
  5791. function pruneSegmentIntersection(a, b) {
  5792. var outa = a.slice();
  5793. var outb = b.slice();
  5794. var intersect = getIntersection(a[a.length - 1], b[0]);
  5795. if (intersect) {
  5796. outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
  5797. outb[0] = b[0].split(intersect[1])[1];
  5798. }
  5799. if (a.length > 1 && b.length > 1) {
  5800. intersect = getIntersection(a[0], b[b.length - 1]);
  5801. if (intersect) {
  5802. return [[a[0].split(intersect[0])[0]], [b[b.length - 1].split(intersect[1])[1]]];
  5803. }
  5804. }
  5805. return [outa, outb];
  5806. }
  5807. function pruneIntersections(segments) {
  5808. var e;
  5809. for (var i = 1; i < segments.length; i += 1) {
  5810. e = pruneSegmentIntersection(segments[i - 1], segments[i]);
  5811. segments[i - 1] = e[0];
  5812. segments[i] = e[1];
  5813. }
  5814. if (segments.length > 1) {
  5815. e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
  5816. segments[segments.length - 1] = e[0];
  5817. segments[0] = e[1];
  5818. }
  5819. return segments;
  5820. }
  5821. function offsetSegmentSplit(segment, amount) {
  5822. /*
  5823. We split each bezier segment into smaller pieces based
  5824. on inflection points, this ensures the control point
  5825. polygon is convex.
  5826. (A cubic bezier can have none, one, or two inflection points)
  5827. */
  5828. var flex = segment.inflectionPoints();
  5829. var left;
  5830. var right;
  5831. var split;
  5832. var mid;
  5833. if (flex.length === 0) {
  5834. return [offsetSegment(segment, amount)];
  5835. }
  5836. if (flex.length === 1 || floatEqual(flex[1], 1)) {
  5837. split = segment.split(flex[0]);
  5838. left = split[0];
  5839. right = split[1];
  5840. return [offsetSegment(left, amount), offsetSegment(right, amount)];
  5841. }
  5842. split = segment.split(flex[0]);
  5843. left = split[0];
  5844. var t = (flex[1] - flex[0]) / (1 - flex[0]);
  5845. split = split[1].split(t);
  5846. mid = split[0];
  5847. right = split[1];
  5848. return [offsetSegment(left, amount), offsetSegment(mid, amount), offsetSegment(right, amount)];
  5849. }
  5850. function OffsetPathModifier() {}
  5851. extendPrototype([ShapeModifier], OffsetPathModifier);
  5852. OffsetPathModifier.prototype.initModifierProperties = function (elem, data) {
  5853. this.getValue = this.processKeys;
  5854. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  5855. this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
  5856. this.lineJoin = data.lj;
  5857. this._isAnimated = this.amount.effectsSequence.length !== 0;
  5858. };
  5859. OffsetPathModifier.prototype.processPath = function (inputBezier, amount, lineJoin, miterLimit) {
  5860. var outputBezier = shapePool.newElement();
  5861. outputBezier.c = inputBezier.c;
  5862. var count = inputBezier.length();
  5863. if (!inputBezier.c) {
  5864. count -= 1;
  5865. }
  5866. var i;
  5867. var j;
  5868. var segment;
  5869. var multiSegments = [];
  5870. for (i = 0; i < count; i += 1) {
  5871. segment = PolynomialBezier.shapeSegment(inputBezier, i);
  5872. multiSegments.push(offsetSegmentSplit(segment, amount));
  5873. }
  5874. if (!inputBezier.c) {
  5875. for (i = count - 1; i >= 0; i -= 1) {
  5876. segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
  5877. multiSegments.push(offsetSegmentSplit(segment, amount));
  5878. }
  5879. }
  5880. multiSegments = pruneIntersections(multiSegments); // Add bezier segments to the output and apply line joints
  5881. var lastPoint = null;
  5882. var lastSeg = null;
  5883. for (i = 0; i < multiSegments.length; i += 1) {
  5884. var multiSegment = multiSegments[i];
  5885. if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
  5886. lastSeg = multiSegment[multiSegment.length - 1];
  5887. for (j = 0; j < multiSegment.length; j += 1) {
  5888. segment = multiSegment[j];
  5889. if (lastPoint && pointEqual(segment.points[0], lastPoint)) {
  5890. outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], 'o', outputBezier.length() - 1);
  5891. } else {
  5892. outputBezier.setTripleAt(segment.points[0][0], segment.points[0][1], segment.points[1][0], segment.points[1][1], segment.points[0][0], segment.points[0][1], outputBezier.length());
  5893. }
  5894. outputBezier.setTripleAt(segment.points[3][0], segment.points[3][1], segment.points[3][0], segment.points[3][1], segment.points[2][0], segment.points[2][1], outputBezier.length());
  5895. lastPoint = segment.points[3];
  5896. }
  5897. }
  5898. if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
  5899. return outputBezier;
  5900. };
  5901. OffsetPathModifier.prototype.processShapes = function (_isFirstFrame) {
  5902. var shapePaths;
  5903. var i;
  5904. var len = this.shapes.length;
  5905. var j;
  5906. var jLen;
  5907. var amount = this.amount.v;
  5908. var miterLimit = this.miterLimit.v;
  5909. var lineJoin = this.lineJoin;
  5910. if (amount !== 0) {
  5911. var shapeData;
  5912. var localShapeCollection;
  5913. for (i = 0; i < len; i += 1) {
  5914. shapeData = this.shapes[i];
  5915. localShapeCollection = shapeData.localShapeCollection;
  5916. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5917. localShapeCollection.releaseShapes();
  5918. shapeData.shape._mdf = true;
  5919. shapePaths = shapeData.shape.paths.shapes;
  5920. jLen = shapeData.shape.paths._length;
  5921. for (j = 0; j < jLen; j += 1) {
  5922. localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
  5923. }
  5924. }
  5925. shapeData.shape.paths = shapeData.localShapeCollection;
  5926. }
  5927. }
  5928. if (!this.dynamicProperties.length) {
  5929. this._mdf = false;
  5930. }
  5931. };
  5932. function getFontProperties(fontData) {
  5933. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5934. var fWeight = 'normal';
  5935. var fStyle = 'normal';
  5936. var len = styles.length;
  5937. var styleName;
  5938. for (var i = 0; i < len; i += 1) {
  5939. styleName = styles[i].toLowerCase();
  5940. switch (styleName) {
  5941. case 'italic':
  5942. fStyle = 'italic';
  5943. break;
  5944. case 'bold':
  5945. fWeight = '700';
  5946. break;
  5947. case 'black':
  5948. fWeight = '900';
  5949. break;
  5950. case 'medium':
  5951. fWeight = '500';
  5952. break;
  5953. case 'regular':
  5954. case 'normal':
  5955. fWeight = '400';
  5956. break;
  5957. case 'light':
  5958. case 'thin':
  5959. fWeight = '200';
  5960. break;
  5961. default:
  5962. break;
  5963. }
  5964. }
  5965. return {
  5966. style: fStyle,
  5967. weight: fontData.fWeight || fWeight
  5968. };
  5969. }
  5970. var FontManager = function () {
  5971. var maxWaitingTime = 5000;
  5972. var emptyChar = {
  5973. w: 0,
  5974. size: 0,
  5975. shapes: [],
  5976. data: {
  5977. shapes: []
  5978. }
  5979. };
  5980. var combinedCharacters = []; // Hindi characters
  5981. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366, 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379, 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  5982. var BLACK_FLAG_CODE_POINT = 127988;
  5983. var CANCEL_TAG_CODE_POINT = 917631;
  5984. var A_TAG_CODE_POINT = 917601;
  5985. var Z_TAG_CODE_POINT = 917626;
  5986. var VARIATION_SELECTOR_16_CODE_POINT = 65039;
  5987. var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
  5988. var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
  5989. var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
  5990. var surrogateModifiers = ['d83cdffb', 'd83cdffc', 'd83cdffd', 'd83cdffe', 'd83cdfff'];
  5991. function trimFontOptions(font) {
  5992. var familyArray = font.split(',');
  5993. var i;
  5994. var len = familyArray.length;
  5995. var enabledFamilies = [];
  5996. for (i = 0; i < len; i += 1) {
  5997. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  5998. enabledFamilies.push(familyArray[i]);
  5999. }
  6000. }
  6001. return enabledFamilies.join(',');
  6002. }
  6003. function setUpNode(font, family) {
  6004. var parentNode = createTag('span'); // Node is invisible to screen readers.
  6005. parentNode.setAttribute('aria-hidden', true);
  6006. parentNode.style.fontFamily = family;
  6007. var node = createTag('span'); // Characters that vary significantly among different fonts
  6008. node.innerText = 'giItT1WQy@!-/#'; // Visible - so we can measure it - but not on the screen
  6009. parentNode.style.position = 'absolute';
  6010. parentNode.style.left = '-10000px';
  6011. parentNode.style.top = '-10000px'; // Large font size makes even subtle changes obvious
  6012. parentNode.style.fontSize = '300px'; // Reset any font properties
  6013. parentNode.style.fontVariant = 'normal';
  6014. parentNode.style.fontStyle = 'normal';
  6015. parentNode.style.fontWeight = 'normal';
  6016. parentNode.style.letterSpacing = '0';
  6017. parentNode.appendChild(node);
  6018. document.body.appendChild(parentNode); // Remember width with no applied web font
  6019. var width = node.offsetWidth;
  6020. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  6021. return {
  6022. node: node,
  6023. w: width,
  6024. parent: parentNode
  6025. };
  6026. }
  6027. function checkLoadedFonts() {
  6028. var i;
  6029. var len = this.fonts.length;
  6030. var node;
  6031. var w;
  6032. var loadedCount = len;
  6033. for (i = 0; i < len; i += 1) {
  6034. if (this.fonts[i].loaded) {
  6035. loadedCount -= 1;
  6036. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  6037. this.fonts[i].loaded = true;
  6038. } else {
  6039. node = this.fonts[i].monoCase.node;
  6040. w = this.fonts[i].monoCase.w;
  6041. if (node.offsetWidth !== w) {
  6042. loadedCount -= 1;
  6043. this.fonts[i].loaded = true;
  6044. } else {
  6045. node = this.fonts[i].sansCase.node;
  6046. w = this.fonts[i].sansCase.w;
  6047. if (node.offsetWidth !== w) {
  6048. loadedCount -= 1;
  6049. this.fonts[i].loaded = true;
  6050. }
  6051. }
  6052. if (this.fonts[i].loaded) {
  6053. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  6054. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  6055. }
  6056. }
  6057. }
  6058. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  6059. setTimeout(this.checkLoadedFontsBinded, 20);
  6060. } else {
  6061. setTimeout(this.setIsLoadedBinded, 10);
  6062. }
  6063. }
  6064. function createHelper(fontData, def) {
  6065. var engine = document.body && def ? 'svg' : 'canvas';
  6066. var helper;
  6067. var fontProps = getFontProperties(fontData);
  6068. if (engine === 'svg') {
  6069. var tHelper = createNS('text');
  6070. tHelper.style.fontSize = '100px'; // tHelper.style.fontFamily = fontData.fFamily;
  6071. tHelper.setAttribute('font-family', fontData.fFamily);
  6072. tHelper.setAttribute('font-style', fontProps.style);
  6073. tHelper.setAttribute('font-weight', fontProps.weight);
  6074. tHelper.textContent = '1';
  6075. if (fontData.fClass) {
  6076. tHelper.style.fontFamily = 'inherit';
  6077. tHelper.setAttribute('class', fontData.fClass);
  6078. } else {
  6079. tHelper.style.fontFamily = fontData.fFamily;
  6080. }
  6081. def.appendChild(tHelper);
  6082. helper = tHelper;
  6083. } else {
  6084. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  6085. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  6086. helper = tCanvasHelper;
  6087. }
  6088. function measure(text) {
  6089. if (engine === 'svg') {
  6090. helper.textContent = text;
  6091. return helper.getComputedTextLength();
  6092. }
  6093. return helper.measureText(text).width;
  6094. }
  6095. return {
  6096. measureText: measure
  6097. };
  6098. }
  6099. function addFonts(fontData, defs) {
  6100. if (!fontData) {
  6101. this.isLoaded = true;
  6102. return;
  6103. }
  6104. if (this.chars) {
  6105. this.isLoaded = true;
  6106. this.fonts = fontData.list;
  6107. return;
  6108. }
  6109. if (!document.body) {
  6110. this.isLoaded = true;
  6111. fontData.list.forEach(function (data) {
  6112. data.helper = createHelper(data);
  6113. data.cache = {};
  6114. });
  6115. this.fonts = fontData.list;
  6116. return;
  6117. }
  6118. var fontArr = fontData.list;
  6119. var i;
  6120. var len = fontArr.length;
  6121. var _pendingFonts = len;
  6122. for (i = 0; i < len; i += 1) {
  6123. var shouldLoadFont = true;
  6124. var loadedSelector;
  6125. var j;
  6126. fontArr[i].loaded = false;
  6127. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  6128. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  6129. if (!fontArr[i].fPath) {
  6130. fontArr[i].loaded = true;
  6131. _pendingFonts -= 1;
  6132. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  6133. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  6134. if (loadedSelector.length > 0) {
  6135. shouldLoadFont = false;
  6136. }
  6137. if (shouldLoadFont) {
  6138. var s = createTag('style');
  6139. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  6140. s.setAttribute('f-origin', fontArr[i].origin);
  6141. s.setAttribute('f-family', fontArr[i].fFamily);
  6142. s.type = 'text/css';
  6143. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  6144. defs.appendChild(s);
  6145. }
  6146. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  6147. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  6148. for (j = 0; j < loadedSelector.length; j += 1) {
  6149. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  6150. // Font is already loaded
  6151. shouldLoadFont = false;
  6152. }
  6153. }
  6154. if (shouldLoadFont) {
  6155. var l = createTag('link');
  6156. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  6157. l.setAttribute('f-origin', fontArr[i].origin);
  6158. l.type = 'text/css';
  6159. l.rel = 'stylesheet';
  6160. l.href = fontArr[i].fPath;
  6161. document.body.appendChild(l);
  6162. }
  6163. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  6164. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  6165. for (j = 0; j < loadedSelector.length; j += 1) {
  6166. if (fontArr[i].fPath === loadedSelector[j].src) {
  6167. // Font is already loaded
  6168. shouldLoadFont = false;
  6169. }
  6170. }
  6171. if (shouldLoadFont) {
  6172. var sc = createTag('link');
  6173. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  6174. sc.setAttribute('f-origin', fontArr[i].origin);
  6175. sc.setAttribute('rel', 'stylesheet');
  6176. sc.setAttribute('href', fontArr[i].fPath);
  6177. defs.appendChild(sc);
  6178. }
  6179. }
  6180. fontArr[i].helper = createHelper(fontArr[i], defs);
  6181. fontArr[i].cache = {};
  6182. this.fonts.push(fontArr[i]);
  6183. }
  6184. if (_pendingFonts === 0) {
  6185. this.isLoaded = true;
  6186. } else {
  6187. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  6188. // Adding this timeout seems to fix it
  6189. setTimeout(this.checkLoadedFonts.bind(this), 100);
  6190. }
  6191. }
  6192. function addChars(chars) {
  6193. if (!chars) {
  6194. return;
  6195. }
  6196. if (!this.chars) {
  6197. this.chars = [];
  6198. }
  6199. var i;
  6200. var len = chars.length;
  6201. var j;
  6202. var jLen = this.chars.length;
  6203. var found;
  6204. for (i = 0; i < len; i += 1) {
  6205. j = 0;
  6206. found = false;
  6207. while (j < jLen) {
  6208. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  6209. found = true;
  6210. }
  6211. j += 1;
  6212. }
  6213. if (!found) {
  6214. this.chars.push(chars[i]);
  6215. jLen += 1;
  6216. }
  6217. }
  6218. }
  6219. function getCharData(_char, style, font) {
  6220. var i = 0;
  6221. var len = this.chars.length;
  6222. while (i < len) {
  6223. if (this.chars[i].ch === _char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  6224. return this.chars[i];
  6225. }
  6226. i += 1;
  6227. }
  6228. if ((typeof _char === 'string' && _char.charCodeAt(0) !== 13 || !_char) && console && console.warn // eslint-disable-line no-console
  6229. && !this._warned) {
  6230. this._warned = true;
  6231. console.warn('Missing character from exported characters list: ', _char, style, font); // eslint-disable-line no-console
  6232. }
  6233. return emptyChar;
  6234. }
  6235. function measureText(_char2, fontName, size) {
  6236. var fontData = this.getFontByName(fontName); // Using the char instead of char.charCodeAt(0)
  6237. // to avoid collisions between equal chars
  6238. var index = _char2;
  6239. if (!fontData.cache[index]) {
  6240. var tHelper = fontData.helper;
  6241. if (_char2 === ' ') {
  6242. var doubleSize = tHelper.measureText('|' + _char2 + '|');
  6243. var singleSize = tHelper.measureText('||');
  6244. fontData.cache[index] = (doubleSize - singleSize) / 100;
  6245. } else {
  6246. fontData.cache[index] = tHelper.measureText(_char2) / 100;
  6247. }
  6248. }
  6249. return fontData.cache[index] * size;
  6250. }
  6251. function getFontByName(name) {
  6252. var i = 0;
  6253. var len = this.fonts.length;
  6254. while (i < len) {
  6255. if (this.fonts[i].fName === name) {
  6256. return this.fonts[i];
  6257. }
  6258. i += 1;
  6259. }
  6260. return this.fonts[0];
  6261. }
  6262. function getCodePoint(string) {
  6263. var codePoint = 0;
  6264. var first = string.charCodeAt(0);
  6265. if (first >= 0xD800 && first <= 0xDBFF) {
  6266. var second = string.charCodeAt(1);
  6267. if (second >= 0xDC00 && second <= 0xDFFF) {
  6268. codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  6269. }
  6270. }
  6271. return codePoint;
  6272. } // Skin tone modifiers
  6273. function isModifier(firstCharCode, secondCharCode) {
  6274. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  6275. return surrogateModifiers.indexOf(sum) !== -1;
  6276. }
  6277. function isZeroWidthJoiner(charCode) {
  6278. return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
  6279. } // This codepoint may change the appearance of the preceding character.
  6280. // If that is a symbol, dingbat or emoji, U+FE0F forces it to be rendered
  6281. // as a colorful image as compared to a monochrome text variant.
  6282. function isVariationSelector(charCode) {
  6283. return charCode === VARIATION_SELECTOR_16_CODE_POINT;
  6284. } // The regional indicator symbols are a set of 26 alphabetic Unicode
  6285. /// characters (A–Z) intended to be used to encode ISO 3166-1 alpha-2
  6286. // two-letter country codes in a way that allows optional special treatment.
  6287. function isRegionalCode(string) {
  6288. var codePoint = getCodePoint(string);
  6289. if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) {
  6290. return true;
  6291. }
  6292. return false;
  6293. } // Some Emoji implementations represent combinations of
  6294. // two “regional indicator” letters as a single flag symbol.
  6295. function isFlagEmoji(string) {
  6296. return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
  6297. }
  6298. function isCombinedCharacter(_char3) {
  6299. return combinedCharacters.indexOf(_char3) !== -1;
  6300. } // Regional flags start with a BLACK_FLAG_CODE_POINT
  6301. // folowed by 5 chars in the TAG range
  6302. // and end with a CANCEL_TAG_CODE_POINT
  6303. function isRegionalFlag(text, index) {
  6304. var codePoint = getCodePoint(text.substr(index, 2));
  6305. if (codePoint !== BLACK_FLAG_CODE_POINT) {
  6306. return false;
  6307. }
  6308. var count = 0;
  6309. index += 2;
  6310. while (count < 5) {
  6311. codePoint = getCodePoint(text.substr(index, 2));
  6312. if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) {
  6313. return false;
  6314. }
  6315. count += 1;
  6316. index += 2;
  6317. }
  6318. return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
  6319. }
  6320. function setIsLoaded() {
  6321. this.isLoaded = true;
  6322. }
  6323. var Font = function Font() {
  6324. this.fonts = [];
  6325. this.chars = null;
  6326. this.typekitLoaded = 0;
  6327. this.isLoaded = false;
  6328. this._warned = false;
  6329. this.initTime = Date.now();
  6330. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  6331. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  6332. };
  6333. Font.isModifier = isModifier;
  6334. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  6335. Font.isFlagEmoji = isFlagEmoji;
  6336. Font.isRegionalCode = isRegionalCode;
  6337. Font.isCombinedCharacter = isCombinedCharacter;
  6338. Font.isRegionalFlag = isRegionalFlag;
  6339. Font.isVariationSelector = isVariationSelector;
  6340. Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
  6341. var fontPrototype = {
  6342. addChars: addChars,
  6343. addFonts: addFonts,
  6344. getCharData: getCharData,
  6345. getFontByName: getFontByName,
  6346. measureText: measureText,
  6347. checkLoadedFonts: checkLoadedFonts,
  6348. setIsLoaded: setIsLoaded
  6349. };
  6350. Font.prototype = fontPrototype;
  6351. return Font;
  6352. }();
  6353. function SlotManager(animationData) {
  6354. this.animationData = animationData;
  6355. }
  6356. SlotManager.prototype.getProp = function (data) {
  6357. if (this.animationData.slots && this.animationData.slots[data.sid]) {
  6358. return Object.assign(data, this.animationData.slots[data.sid].p);
  6359. }
  6360. return data;
  6361. };
  6362. function slotFactory(animationData) {
  6363. return new SlotManager(animationData);
  6364. }
  6365. function RenderableElement() {}
  6366. RenderableElement.prototype = {
  6367. initRenderable: function initRenderable() {
  6368. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6369. this.isInRange = false; // layer's display state
  6370. this.hidden = false; // If layer's transparency equals 0, it can be hidden
  6371. this.isTransparent = false; // list of animated components
  6372. this.renderableComponents = [];
  6373. },
  6374. addRenderableComponent: function addRenderableComponent(component) {
  6375. if (this.renderableComponents.indexOf(component) === -1) {
  6376. this.renderableComponents.push(component);
  6377. }
  6378. },
  6379. removeRenderableComponent: function removeRenderableComponent(component) {
  6380. if (this.renderableComponents.indexOf(component) !== -1) {
  6381. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6382. }
  6383. },
  6384. prepareRenderableFrame: function prepareRenderableFrame(num) {
  6385. this.checkLayerLimits(num);
  6386. },
  6387. checkTransparency: function checkTransparency() {
  6388. if (this.finalTransform.mProp.o.v <= 0) {
  6389. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  6390. this.isTransparent = true;
  6391. this.hide();
  6392. }
  6393. } else if (this.isTransparent) {
  6394. this.isTransparent = false;
  6395. this.show();
  6396. }
  6397. },
  6398. /**
  6399. * @function
  6400. * Initializes frame related properties.
  6401. *
  6402. * @param {number} num
  6403. * current frame number in Layer's time
  6404. *
  6405. */
  6406. checkLayerLimits: function checkLayerLimits(num) {
  6407. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  6408. if (this.isInRange !== true) {
  6409. this.globalData._mdf = true;
  6410. this._mdf = true;
  6411. this.isInRange = true;
  6412. this.show();
  6413. }
  6414. } else if (this.isInRange !== false) {
  6415. this.globalData._mdf = true;
  6416. this.isInRange = false;
  6417. this.hide();
  6418. }
  6419. },
  6420. renderRenderable: function renderRenderable() {
  6421. var i;
  6422. var len = this.renderableComponents.length;
  6423. for (i = 0; i < len; i += 1) {
  6424. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6425. }
  6426. /* this.maskManager.renderFrame(this.finalTransform.mat);
  6427. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  6428. },
  6429. sourceRectAtTime: function sourceRectAtTime() {
  6430. return {
  6431. top: 0,
  6432. left: 0,
  6433. width: 100,
  6434. height: 100
  6435. };
  6436. },
  6437. getLayerSize: function getLayerSize() {
  6438. if (this.data.ty === 5) {
  6439. return {
  6440. w: this.data.textData.width,
  6441. h: this.data.textData.height
  6442. };
  6443. }
  6444. return {
  6445. w: this.data.width,
  6446. h: this.data.height
  6447. };
  6448. }
  6449. };
  6450. var getBlendMode = function () {
  6451. var blendModeEnums = {
  6452. 0: 'source-over',
  6453. 1: 'multiply',
  6454. 2: 'screen',
  6455. 3: 'overlay',
  6456. 4: 'darken',
  6457. 5: 'lighten',
  6458. 6: 'color-dodge',
  6459. 7: 'color-burn',
  6460. 8: 'hard-light',
  6461. 9: 'soft-light',
  6462. 10: 'difference',
  6463. 11: 'exclusion',
  6464. 12: 'hue',
  6465. 13: 'saturation',
  6466. 14: 'color',
  6467. 15: 'luminosity'
  6468. };
  6469. return function (mode) {
  6470. return blendModeEnums[mode] || '';
  6471. };
  6472. }();
  6473. function SliderEffect(data, elem, container) {
  6474. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6475. }
  6476. function AngleEffect(data, elem, container) {
  6477. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6478. }
  6479. function ColorEffect(data, elem, container) {
  6480. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6481. }
  6482. function PointEffect(data, elem, container) {
  6483. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6484. }
  6485. function LayerIndexEffect(data, elem, container) {
  6486. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6487. }
  6488. function MaskIndexEffect(data, elem, container) {
  6489. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6490. }
  6491. function CheckboxEffect(data, elem, container) {
  6492. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6493. }
  6494. function NoValueEffect() {
  6495. this.p = {};
  6496. }
  6497. function EffectsManager(data, element) {
  6498. var effects = data.ef || [];
  6499. this.effectElements = [];
  6500. var i;
  6501. var len = effects.length;
  6502. var effectItem;
  6503. for (i = 0; i < len; i += 1) {
  6504. effectItem = new GroupEffect(effects[i], element);
  6505. this.effectElements.push(effectItem);
  6506. }
  6507. }
  6508. function GroupEffect(data, element) {
  6509. this.init(data, element);
  6510. }
  6511. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6512. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6513. GroupEffect.prototype.init = function (data, element) {
  6514. this.data = data;
  6515. this.effectElements = [];
  6516. this.initDynamicPropertyContainer(element);
  6517. var i;
  6518. var len = this.data.ef.length;
  6519. var eff;
  6520. var effects = this.data.ef;
  6521. for (i = 0; i < len; i += 1) {
  6522. eff = null;
  6523. switch (effects[i].ty) {
  6524. case 0:
  6525. eff = new SliderEffect(effects[i], element, this);
  6526. break;
  6527. case 1:
  6528. eff = new AngleEffect(effects[i], element, this);
  6529. break;
  6530. case 2:
  6531. eff = new ColorEffect(effects[i], element, this);
  6532. break;
  6533. case 3:
  6534. eff = new PointEffect(effects[i], element, this);
  6535. break;
  6536. case 4:
  6537. case 7:
  6538. eff = new CheckboxEffect(effects[i], element, this);
  6539. break;
  6540. case 10:
  6541. eff = new LayerIndexEffect(effects[i], element, this);
  6542. break;
  6543. case 11:
  6544. eff = new MaskIndexEffect(effects[i], element, this);
  6545. break;
  6546. case 5:
  6547. eff = new EffectsManager(effects[i], element, this);
  6548. break;
  6549. // case 6:
  6550. default:
  6551. eff = new NoValueEffect(effects[i], element, this);
  6552. break;
  6553. }
  6554. if (eff) {
  6555. this.effectElements.push(eff);
  6556. }
  6557. }
  6558. };
  6559. function BaseElement() {}
  6560. BaseElement.prototype = {
  6561. checkMasks: function checkMasks() {
  6562. if (!this.data.hasMask) {
  6563. return false;
  6564. }
  6565. var i = 0;
  6566. var len = this.data.masksProperties.length;
  6567. while (i < len) {
  6568. if (this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false) {
  6569. return true;
  6570. }
  6571. i += 1;
  6572. }
  6573. return false;
  6574. },
  6575. initExpressions: function initExpressions() {
  6576. var expressionsInterfaces = getExpressionInterfaces();
  6577. if (!expressionsInterfaces) {
  6578. return;
  6579. }
  6580. var LayerExpressionInterface = expressionsInterfaces('layer');
  6581. var EffectsExpressionInterface = expressionsInterfaces('effects');
  6582. var ShapeExpressionInterface = expressionsInterfaces('shape');
  6583. var TextExpressionInterface = expressionsInterfaces('text');
  6584. var CompExpressionInterface = expressionsInterfaces('comp');
  6585. this.layerInterface = LayerExpressionInterface(this);
  6586. if (this.data.hasMask && this.maskManager) {
  6587. this.layerInterface.registerMaskInterface(this.maskManager);
  6588. }
  6589. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
  6590. this.layerInterface.registerEffectsInterface(effectsInterface);
  6591. if (this.data.ty === 0 || this.data.xt) {
  6592. this.compInterface = CompExpressionInterface(this);
  6593. } else if (this.data.ty === 4) {
  6594. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
  6595. this.layerInterface.content = this.layerInterface.shapeInterface;
  6596. } else if (this.data.ty === 5) {
  6597. this.layerInterface.textInterface = TextExpressionInterface(this);
  6598. this.layerInterface.text = this.layerInterface.textInterface;
  6599. }
  6600. },
  6601. setBlendMode: function setBlendMode() {
  6602. var blendModeValue = getBlendMode(this.data.bm);
  6603. var elem = this.baseElement || this.layerElement;
  6604. elem.style['mix-blend-mode'] = blendModeValue;
  6605. },
  6606. initBaseData: function initBaseData(data, globalData, comp) {
  6607. this.globalData = globalData;
  6608. this.comp = comp;
  6609. this.data = data;
  6610. this.layerId = createElementID(); // Stretch factor for old animations missing this property.
  6611. if (!this.data.sr) {
  6612. this.data.sr = 1;
  6613. } // effects manager
  6614. this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
  6615. },
  6616. getType: function getType() {
  6617. return this.type;
  6618. },
  6619. sourceRectAtTime: function sourceRectAtTime() {}
  6620. };
  6621. /**
  6622. * @file
  6623. * Handles element's layer frame update.
  6624. * Checks layer in point and out point
  6625. *
  6626. */
  6627. function FrameElement() {}
  6628. FrameElement.prototype = {
  6629. /**
  6630. * @function
  6631. * Initializes frame related properties.
  6632. *
  6633. */
  6634. initFrame: function initFrame() {
  6635. // set to true when inpoint is rendered
  6636. this._isFirstFrame = false; // list of animated properties
  6637. this.dynamicProperties = []; // If layer has been modified in current tick this will be true
  6638. this._mdf = false;
  6639. },
  6640. /**
  6641. * @function
  6642. * Calculates all dynamic values
  6643. *
  6644. * @param {number} num
  6645. * current frame number in Layer's time
  6646. * @param {boolean} isVisible
  6647. * if layers is currently in range
  6648. *
  6649. */
  6650. prepareProperties: function prepareProperties(num, isVisible) {
  6651. var i;
  6652. var len = this.dynamicProperties.length;
  6653. for (i = 0; i < len; i += 1) {
  6654. if (isVisible || this._isParent && this.dynamicProperties[i].propType === 'transform') {
  6655. this.dynamicProperties[i].getValue();
  6656. if (this.dynamicProperties[i]._mdf) {
  6657. this.globalData._mdf = true;
  6658. this._mdf = true;
  6659. }
  6660. }
  6661. }
  6662. },
  6663. addDynamicProperty: function addDynamicProperty(prop) {
  6664. if (this.dynamicProperties.indexOf(prop) === -1) {
  6665. this.dynamicProperties.push(prop);
  6666. }
  6667. }
  6668. };
  6669. function FootageElement(data, globalData, comp) {
  6670. this.initFrame();
  6671. this.initRenderable();
  6672. this.assetData = globalData.getAssetData(data.refId);
  6673. this.footageData = globalData.imageLoader.getAsset(this.assetData);
  6674. this.initBaseData(data, globalData, comp);
  6675. }
  6676. FootageElement.prototype.prepareFrame = function () {};
  6677. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  6678. FootageElement.prototype.getBaseElement = function () {
  6679. return null;
  6680. };
  6681. FootageElement.prototype.renderFrame = function () {};
  6682. FootageElement.prototype.destroy = function () {};
  6683. FootageElement.prototype.initExpressions = function () {
  6684. var expressionsInterfaces = getExpressionInterfaces();
  6685. if (!expressionsInterfaces) {
  6686. return;
  6687. }
  6688. var FootageInterface = expressionsInterfaces('footage');
  6689. this.layerInterface = FootageInterface(this);
  6690. };
  6691. FootageElement.prototype.getFootageData = function () {
  6692. return this.footageData;
  6693. };
  6694. function AudioElement(data, globalData, comp) {
  6695. this.initFrame();
  6696. this.initRenderable();
  6697. this.assetData = globalData.getAssetData(data.refId);
  6698. this.initBaseData(data, globalData, comp);
  6699. this._isPlaying = false;
  6700. this._canPlay = false;
  6701. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6702. this.audio = this.globalData.audioController.createAudio(assetPath);
  6703. this._currentTime = 0;
  6704. this.globalData.audioController.addAudio(this);
  6705. this._volumeMultiplier = 1;
  6706. this._volume = 1;
  6707. this._previousVolume = null;
  6708. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  6709. _placeholder: true
  6710. };
  6711. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : {
  6712. k: [100]
  6713. }, 1, 0.01, this);
  6714. }
  6715. AudioElement.prototype.prepareFrame = function (num) {
  6716. this.prepareRenderableFrame(num, true);
  6717. this.prepareProperties(num, true);
  6718. if (!this.tm._placeholder) {
  6719. var timeRemapped = this.tm.v;
  6720. this._currentTime = timeRemapped;
  6721. } else {
  6722. this._currentTime = num / this.data.sr;
  6723. }
  6724. this._volume = this.lv.v[0];
  6725. var totalVolume = this._volume * this._volumeMultiplier;
  6726. if (this._previousVolume !== totalVolume) {
  6727. this._previousVolume = totalVolume;
  6728. this.audio.volume(totalVolume);
  6729. }
  6730. };
  6731. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  6732. AudioElement.prototype.renderFrame = function () {
  6733. if (this.isInRange && this._canPlay) {
  6734. if (!this._isPlaying) {
  6735. this.audio.play();
  6736. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6737. this._isPlaying = true;
  6738. } else if (!this.audio.playing() || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1) {
  6739. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6740. }
  6741. }
  6742. };
  6743. AudioElement.prototype.show = function () {// this.audio.play()
  6744. };
  6745. AudioElement.prototype.hide = function () {
  6746. this.audio.pause();
  6747. this._isPlaying = false;
  6748. };
  6749. AudioElement.prototype.pause = function () {
  6750. this.audio.pause();
  6751. this._isPlaying = false;
  6752. this._canPlay = false;
  6753. };
  6754. AudioElement.prototype.resume = function () {
  6755. this._canPlay = true;
  6756. };
  6757. AudioElement.prototype.setRate = function (rateValue) {
  6758. this.audio.rate(rateValue);
  6759. };
  6760. AudioElement.prototype.volume = function (volumeValue) {
  6761. this._volumeMultiplier = volumeValue;
  6762. this._previousVolume = volumeValue * this._volume;
  6763. this.audio.volume(this._previousVolume);
  6764. };
  6765. AudioElement.prototype.getBaseElement = function () {
  6766. return null;
  6767. };
  6768. AudioElement.prototype.destroy = function () {};
  6769. AudioElement.prototype.sourceRectAtTime = function () {};
  6770. AudioElement.prototype.initExpressions = function () {};
  6771. function BaseRenderer() {}
  6772. BaseRenderer.prototype.checkLayers = function (num) {
  6773. var i;
  6774. var len = this.layers.length;
  6775. var data;
  6776. this.completeLayers = true;
  6777. for (i = len - 1; i >= 0; i -= 1) {
  6778. if (!this.elements[i]) {
  6779. data = this.layers[i];
  6780. if (data.ip - data.st <= num - this.layers[i].st && data.op - data.st > num - this.layers[i].st) {
  6781. this.buildItem(i);
  6782. }
  6783. }
  6784. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  6785. }
  6786. this.checkPendingElements();
  6787. };
  6788. BaseRenderer.prototype.createItem = function (layer) {
  6789. switch (layer.ty) {
  6790. case 2:
  6791. return this.createImage(layer);
  6792. case 0:
  6793. return this.createComp(layer);
  6794. case 1:
  6795. return this.createSolid(layer);
  6796. case 3:
  6797. return this.createNull(layer);
  6798. case 4:
  6799. return this.createShape(layer);
  6800. case 5:
  6801. return this.createText(layer);
  6802. case 6:
  6803. return this.createAudio(layer);
  6804. case 13:
  6805. return this.createCamera(layer);
  6806. case 15:
  6807. return this.createFootage(layer);
  6808. default:
  6809. return this.createNull(layer);
  6810. }
  6811. };
  6812. BaseRenderer.prototype.createCamera = function () {
  6813. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  6814. };
  6815. BaseRenderer.prototype.createAudio = function (data) {
  6816. return new AudioElement(data, this.globalData, this);
  6817. };
  6818. BaseRenderer.prototype.createFootage = function (data) {
  6819. return new FootageElement(data, this.globalData, this);
  6820. };
  6821. BaseRenderer.prototype.buildAllItems = function () {
  6822. var i;
  6823. var len = this.layers.length;
  6824. for (i = 0; i < len; i += 1) {
  6825. this.buildItem(i);
  6826. }
  6827. this.checkPendingElements();
  6828. };
  6829. BaseRenderer.prototype.includeLayers = function (newLayers) {
  6830. this.completeLayers = false;
  6831. var i;
  6832. var len = newLayers.length;
  6833. var j;
  6834. var jLen = this.layers.length;
  6835. for (i = 0; i < len; i += 1) {
  6836. j = 0;
  6837. while (j < jLen) {
  6838. if (this.layers[j].id === newLayers[i].id) {
  6839. this.layers[j] = newLayers[i];
  6840. break;
  6841. }
  6842. j += 1;
  6843. }
  6844. }
  6845. };
  6846. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  6847. this.globalData.projectInterface = pInterface;
  6848. };
  6849. BaseRenderer.prototype.initItems = function () {
  6850. if (!this.globalData.progressiveLoad) {
  6851. this.buildAllItems();
  6852. }
  6853. };
  6854. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  6855. var elements = this.elements;
  6856. var layers = this.layers;
  6857. var i = 0;
  6858. var len = layers.length;
  6859. while (i < len) {
  6860. if (layers[i].ind == parentName) {
  6861. // eslint-disable-line eqeqeq
  6862. if (!elements[i] || elements[i] === true) {
  6863. this.buildItem(i);
  6864. this.addPendingElement(element);
  6865. } else {
  6866. hierarchy.push(elements[i]);
  6867. elements[i].setAsParent();
  6868. if (layers[i].parent !== undefined) {
  6869. this.buildElementParenting(element, layers[i].parent, hierarchy);
  6870. } else {
  6871. element.setHierarchy(hierarchy);
  6872. }
  6873. }
  6874. }
  6875. i += 1;
  6876. }
  6877. };
  6878. BaseRenderer.prototype.addPendingElement = function (element) {
  6879. this.pendingElements.push(element);
  6880. };
  6881. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  6882. var i;
  6883. var len = assets.length;
  6884. for (i = 0; i < len; i += 1) {
  6885. if (assets[i].xt) {
  6886. var comp = this.createComp(assets[i]);
  6887. comp.initExpressions();
  6888. this.globalData.projectInterface.registerComposition(comp);
  6889. }
  6890. }
  6891. };
  6892. BaseRenderer.prototype.getElementById = function (ind) {
  6893. var i;
  6894. var len = this.elements.length;
  6895. for (i = 0; i < len; i += 1) {
  6896. if (this.elements[i].data.ind === ind) {
  6897. return this.elements[i];
  6898. }
  6899. }
  6900. return null;
  6901. };
  6902. BaseRenderer.prototype.getElementByPath = function (path) {
  6903. var pathValue = path.shift();
  6904. var element;
  6905. if (typeof pathValue === 'number') {
  6906. element = this.elements[pathValue];
  6907. } else {
  6908. var i;
  6909. var len = this.elements.length;
  6910. for (i = 0; i < len; i += 1) {
  6911. if (this.elements[i].data.nm === pathValue) {
  6912. element = this.elements[i];
  6913. break;
  6914. }
  6915. }
  6916. }
  6917. if (path.length === 0) {
  6918. return element;
  6919. }
  6920. return element.getElementByPath(path);
  6921. };
  6922. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  6923. this.globalData.fontManager = new FontManager();
  6924. this.globalData.slotManager = slotFactory(animData);
  6925. this.globalData.fontManager.addChars(animData.chars);
  6926. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  6927. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  6928. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  6929. this.globalData.imageLoader = this.animationItem.imagePreloader;
  6930. this.globalData.audioController = this.animationItem.audioController;
  6931. this.globalData.frameId = 0;
  6932. this.globalData.frameRate = animData.fr;
  6933. this.globalData.nm = animData.nm;
  6934. this.globalData.compSize = {
  6935. w: animData.w,
  6936. h: animData.h
  6937. };
  6938. };
  6939. var effectTypes = {
  6940. TRANSFORM_EFFECT: 'transformEFfect'
  6941. };
  6942. function TransformElement() {}
  6943. TransformElement.prototype = {
  6944. initTransform: function initTransform() {
  6945. var mat = new Matrix();
  6946. this.finalTransform = {
  6947. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : {
  6948. o: 0
  6949. },
  6950. _matMdf: false,
  6951. _localMatMdf: false,
  6952. _opMdf: false,
  6953. mat: mat,
  6954. localMat: mat,
  6955. localOpacity: 1
  6956. };
  6957. if (this.data.ao) {
  6958. this.finalTransform.mProp.autoOriented = true;
  6959. } // TODO: check TYPE 11: Guided elements
  6960. if (this.data.ty !== 11) {// this.createElements();
  6961. }
  6962. },
  6963. renderTransform: function renderTransform() {
  6964. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  6965. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  6966. if (this.hierarchy) {
  6967. var mat;
  6968. var finalMat = this.finalTransform.mat;
  6969. var i = 0;
  6970. var len = this.hierarchy.length; // Checking if any of the transformation matrices in the hierarchy chain has changed.
  6971. if (!this.finalTransform._matMdf) {
  6972. while (i < len) {
  6973. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  6974. this.finalTransform._matMdf = true;
  6975. break;
  6976. }
  6977. i += 1;
  6978. }
  6979. }
  6980. if (this.finalTransform._matMdf) {
  6981. mat = this.finalTransform.mProp.v.props;
  6982. finalMat.cloneFromProps(mat);
  6983. for (i = 0; i < len; i += 1) {
  6984. finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
  6985. }
  6986. }
  6987. }
  6988. if (this.finalTransform._matMdf) {
  6989. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  6990. }
  6991. if (this.finalTransform._opMdf) {
  6992. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  6993. }
  6994. },
  6995. renderLocalTransform: function renderLocalTransform() {
  6996. if (this.localTransforms) {
  6997. var i = 0;
  6998. var len = this.localTransforms.length;
  6999. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7000. if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) {
  7001. while (i < len) {
  7002. if (this.localTransforms[i]._mdf) {
  7003. this.finalTransform._localMatMdf = true;
  7004. }
  7005. if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
  7006. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7007. this.finalTransform._opMdf = true;
  7008. }
  7009. i += 1;
  7010. }
  7011. }
  7012. if (this.finalTransform._localMatMdf) {
  7013. var localMat = this.finalTransform.localMat;
  7014. this.localTransforms[0].matrix.clone(localMat);
  7015. for (i = 1; i < len; i += 1) {
  7016. var lmat = this.localTransforms[i].matrix;
  7017. localMat.multiply(lmat);
  7018. }
  7019. localMat.multiply(this.finalTransform.mat);
  7020. }
  7021. if (this.finalTransform._opMdf) {
  7022. var localOp = this.finalTransform.localOpacity;
  7023. for (i = 0; i < len; i += 1) {
  7024. localOp *= this.localTransforms[i].opacity * 0.01;
  7025. }
  7026. this.finalTransform.localOpacity = localOp;
  7027. }
  7028. }
  7029. },
  7030. searchEffectTransforms: function searchEffectTransforms() {
  7031. if (this.renderableEffectsManager) {
  7032. var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  7033. if (transformEffects.length) {
  7034. this.localTransforms = [];
  7035. this.finalTransform.localMat = new Matrix();
  7036. var i = 0;
  7037. var len = transformEffects.length;
  7038. for (i = 0; i < len; i += 1) {
  7039. this.localTransforms.push(transformEffects[i]);
  7040. }
  7041. }
  7042. }
  7043. },
  7044. globalToLocal: function globalToLocal(pt) {
  7045. var transforms = [];
  7046. transforms.push(this.finalTransform);
  7047. var flag = true;
  7048. var comp = this.comp;
  7049. while (flag) {
  7050. if (comp.finalTransform) {
  7051. if (comp.data.hasMask) {
  7052. transforms.splice(0, 0, comp.finalTransform);
  7053. }
  7054. comp = comp.comp;
  7055. } else {
  7056. flag = false;
  7057. }
  7058. }
  7059. var i;
  7060. var len = transforms.length;
  7061. var ptNew;
  7062. for (i = 0; i < len; i += 1) {
  7063. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0); // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7064. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7065. }
  7066. return pt;
  7067. },
  7068. mHelper: new Matrix()
  7069. };
  7070. function MaskElement(data, element, globalData) {
  7071. this.data = data;
  7072. this.element = element;
  7073. this.globalData = globalData;
  7074. this.storedData = [];
  7075. this.masksProperties = this.data.masksProperties || [];
  7076. this.maskElement = null;
  7077. var defs = this.globalData.defs;
  7078. var i;
  7079. var len = this.masksProperties ? this.masksProperties.length : 0;
  7080. this.viewData = createSizedArray(len);
  7081. this.solidPath = '';
  7082. var path;
  7083. var properties = this.masksProperties;
  7084. var count = 0;
  7085. var currentMasks = [];
  7086. var j;
  7087. var jLen;
  7088. var layerId = createElementID();
  7089. var rect;
  7090. var expansor;
  7091. var feMorph;
  7092. var x;
  7093. var maskType = 'clipPath';
  7094. var maskRef = 'clip-path';
  7095. for (i = 0; i < len; i += 1) {
  7096. if (properties[i].mode !== 'a' && properties[i].mode !== 'n' || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7097. maskType = 'mask';
  7098. maskRef = 'mask';
  7099. }
  7100. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7101. rect = createNS('rect');
  7102. rect.setAttribute('fill', '#ffffff');
  7103. rect.setAttribute('width', this.element.comp.data.w || 0);
  7104. rect.setAttribute('height', this.element.comp.data.h || 0);
  7105. currentMasks.push(rect);
  7106. } else {
  7107. rect = null;
  7108. }
  7109. path = createNS('path');
  7110. if (properties[i].mode === 'n') {
  7111. // TODO move this to a factory or to a constructor
  7112. this.viewData[i] = {
  7113. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7114. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7115. elem: path,
  7116. lastPath: ''
  7117. };
  7118. defs.appendChild(path);
  7119. } else {
  7120. count += 1;
  7121. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7122. path.setAttribute('clip-rule', 'nonzero');
  7123. var filterID;
  7124. if (properties[i].x.k !== 0) {
  7125. maskType = 'mask';
  7126. maskRef = 'mask';
  7127. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7128. filterID = createElementID();
  7129. expansor = createNS('filter');
  7130. expansor.setAttribute('id', filterID);
  7131. feMorph = createNS('feMorphology');
  7132. feMorph.setAttribute('operator', 'erode');
  7133. feMorph.setAttribute('in', 'SourceGraphic');
  7134. feMorph.setAttribute('radius', '0');
  7135. expansor.appendChild(feMorph);
  7136. defs.appendChild(expansor);
  7137. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7138. } else {
  7139. feMorph = null;
  7140. x = null;
  7141. } // TODO move this to a factory or to a constructor
  7142. this.storedData[i] = {
  7143. elem: path,
  7144. x: x,
  7145. expan: feMorph,
  7146. lastPath: '',
  7147. lastOperator: '',
  7148. filterId: filterID,
  7149. lastRadius: 0
  7150. };
  7151. if (properties[i].mode === 'i') {
  7152. jLen = currentMasks.length;
  7153. var g = createNS('g');
  7154. for (j = 0; j < jLen; j += 1) {
  7155. g.appendChild(currentMasks[j]);
  7156. }
  7157. var mask = createNS('mask');
  7158. mask.setAttribute('mask-type', 'alpha');
  7159. mask.setAttribute('id', layerId + '_' + count);
  7160. mask.appendChild(path);
  7161. defs.appendChild(mask);
  7162. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7163. currentMasks.length = 0;
  7164. currentMasks.push(g);
  7165. } else {
  7166. currentMasks.push(path);
  7167. }
  7168. if (properties[i].inv && !this.solidPath) {
  7169. this.solidPath = this.createLayerSolidPath();
  7170. } // TODO move this to a factory or to a constructor
  7171. this.viewData[i] = {
  7172. elem: path,
  7173. lastPath: '',
  7174. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7175. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7176. invRect: rect
  7177. };
  7178. if (!this.viewData[i].prop.k) {
  7179. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7180. }
  7181. }
  7182. }
  7183. this.maskElement = createNS(maskType);
  7184. len = currentMasks.length;
  7185. for (i = 0; i < len; i += 1) {
  7186. this.maskElement.appendChild(currentMasks[i]);
  7187. }
  7188. if (count > 0) {
  7189. this.maskElement.setAttribute('id', layerId);
  7190. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7191. defs.appendChild(this.maskElement);
  7192. }
  7193. if (this.viewData.length) {
  7194. this.element.addRenderableComponent(this);
  7195. }
  7196. }
  7197. MaskElement.prototype.getMaskProperty = function (pos) {
  7198. return this.viewData[pos].prop;
  7199. };
  7200. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7201. var finalMat = this.element.finalTransform.mat;
  7202. var i;
  7203. var len = this.masksProperties.length;
  7204. for (i = 0; i < len; i += 1) {
  7205. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7206. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7207. }
  7208. if (this.viewData[i].op._mdf || isFirstFrame) {
  7209. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7210. }
  7211. if (this.masksProperties[i].mode !== 'n') {
  7212. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7213. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7214. }
  7215. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7216. var feMorph = this.storedData[i].expan;
  7217. if (this.storedData[i].x.v < 0) {
  7218. if (this.storedData[i].lastOperator !== 'erode') {
  7219. this.storedData[i].lastOperator = 'erode';
  7220. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7221. }
  7222. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7223. } else {
  7224. if (this.storedData[i].lastOperator !== 'dilate') {
  7225. this.storedData[i].lastOperator = 'dilate';
  7226. this.storedData[i].elem.setAttribute('filter', null);
  7227. }
  7228. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7229. }
  7230. }
  7231. }
  7232. }
  7233. };
  7234. MaskElement.prototype.getMaskelement = function () {
  7235. return this.maskElement;
  7236. };
  7237. MaskElement.prototype.createLayerSolidPath = function () {
  7238. var path = 'M0,0 ';
  7239. path += ' h' + this.globalData.compSize.w;
  7240. path += ' v' + this.globalData.compSize.h;
  7241. path += ' h-' + this.globalData.compSize.w;
  7242. path += ' v-' + this.globalData.compSize.h + ' ';
  7243. return path;
  7244. };
  7245. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7246. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7247. var i;
  7248. var len;
  7249. len = pathNodes._length;
  7250. for (i = 1; i < len; i += 1) {
  7251. // 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];
  7252. 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];
  7253. } // 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];
  7254. if (pathNodes.c && len > 1) {
  7255. 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];
  7256. } // pathNodes.__renderedString = pathString;
  7257. if (viewData.lastPath !== pathString) {
  7258. var pathShapeValue = '';
  7259. if (viewData.elem) {
  7260. if (pathNodes.c) {
  7261. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7262. }
  7263. viewData.elem.setAttribute('d', pathShapeValue);
  7264. }
  7265. viewData.lastPath = pathString;
  7266. }
  7267. };
  7268. MaskElement.prototype.destroy = function () {
  7269. this.element = null;
  7270. this.globalData = null;
  7271. this.maskElement = null;
  7272. this.data = null;
  7273. this.masksProperties = null;
  7274. };
  7275. var filtersFactory = function () {
  7276. var ob = {};
  7277. ob.createFilter = createFilter;
  7278. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7279. function createFilter(filId, skipCoordinates) {
  7280. var fil = createNS('filter');
  7281. fil.setAttribute('id', filId);
  7282. if (skipCoordinates !== true) {
  7283. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7284. fil.setAttribute('x', '0%');
  7285. fil.setAttribute('y', '0%');
  7286. fil.setAttribute('width', '100%');
  7287. fil.setAttribute('height', '100%');
  7288. }
  7289. return fil;
  7290. }
  7291. function createAlphaToLuminanceFilter() {
  7292. var feColorMatrix = createNS('feColorMatrix');
  7293. feColorMatrix.setAttribute('type', 'matrix');
  7294. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7295. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7296. return feColorMatrix;
  7297. }
  7298. return ob;
  7299. }();
  7300. var featureSupport = function () {
  7301. var ob = {
  7302. maskType: true,
  7303. svgLumaHidden: true,
  7304. offscreenCanvas: typeof OffscreenCanvas !== 'undefined'
  7305. };
  7306. 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)) {
  7307. ob.maskType = false;
  7308. }
  7309. if (/firefox/i.test(navigator.userAgent)) {
  7310. ob.svgLumaHidden = false;
  7311. }
  7312. return ob;
  7313. }();
  7314. var registeredEffects$1 = {};
  7315. var idPrefix = 'filter_result_';
  7316. function SVGEffects(elem) {
  7317. var i;
  7318. var source = 'SourceGraphic';
  7319. var len = elem.data.ef ? elem.data.ef.length : 0;
  7320. var filId = createElementID();
  7321. var fil = filtersFactory.createFilter(filId, true);
  7322. var count = 0;
  7323. this.filters = [];
  7324. var filterManager;
  7325. for (i = 0; i < len; i += 1) {
  7326. filterManager = null;
  7327. var type = elem.data.ef[i].ty;
  7328. if (registeredEffects$1[type]) {
  7329. var Effect = registeredEffects$1[type].effect;
  7330. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7331. source = idPrefix + count;
  7332. if (registeredEffects$1[type].countsAsEffect) {
  7333. count += 1;
  7334. }
  7335. }
  7336. if (filterManager) {
  7337. this.filters.push(filterManager);
  7338. }
  7339. }
  7340. if (count) {
  7341. elem.globalData.defs.appendChild(fil);
  7342. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7343. }
  7344. if (this.filters.length) {
  7345. elem.addRenderableComponent(this);
  7346. }
  7347. }
  7348. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7349. var i;
  7350. var len = this.filters.length;
  7351. for (i = 0; i < len; i += 1) {
  7352. this.filters[i].renderFrame(_isFirstFrame);
  7353. }
  7354. };
  7355. SVGEffects.prototype.getEffects = function (type) {
  7356. var i;
  7357. var len = this.filters.length;
  7358. var effects = [];
  7359. for (i = 0; i < len; i += 1) {
  7360. if (this.filters[i].type === type) {
  7361. effects.push(this.filters[i]);
  7362. }
  7363. }
  7364. return effects;
  7365. };
  7366. function registerEffect$1(id, effect, countsAsEffect) {
  7367. registeredEffects$1[id] = {
  7368. effect: effect,
  7369. countsAsEffect: countsAsEffect
  7370. };
  7371. }
  7372. function SVGBaseElement() {}
  7373. SVGBaseElement.prototype = {
  7374. initRendererElement: function initRendererElement() {
  7375. this.layerElement = createNS('g');
  7376. },
  7377. createContainerElements: function createContainerElements() {
  7378. this.matteElement = createNS('g');
  7379. this.transformedElement = this.layerElement;
  7380. this.maskedElement = this.layerElement;
  7381. this._sizeChanged = false;
  7382. var layerElementParent = null; // If this layer acts as a mask for the following layer
  7383. if (this.data.td) {
  7384. this.matteMasks = {};
  7385. var gg = createNS('g');
  7386. gg.setAttribute('id', this.layerId);
  7387. gg.appendChild(this.layerElement);
  7388. layerElementParent = gg;
  7389. this.globalData.defs.appendChild(gg);
  7390. } else if (this.data.tt) {
  7391. this.matteElement.appendChild(this.layerElement);
  7392. layerElementParent = this.matteElement;
  7393. this.baseElement = this.matteElement;
  7394. } else {
  7395. this.baseElement = this.layerElement;
  7396. }
  7397. if (this.data.ln) {
  7398. this.layerElement.setAttribute('id', this.data.ln);
  7399. }
  7400. if (this.data.cl) {
  7401. this.layerElement.setAttribute('class', this.data.cl);
  7402. } // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7403. if (this.data.ty === 0 && !this.data.hd) {
  7404. var cp = createNS('clipPath');
  7405. var pt = createNS('path');
  7406. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7407. var clipId = createElementID();
  7408. cp.setAttribute('id', clipId);
  7409. cp.appendChild(pt);
  7410. this.globalData.defs.appendChild(cp);
  7411. if (this.checkMasks()) {
  7412. var cpGroup = createNS('g');
  7413. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7414. cpGroup.appendChild(this.layerElement);
  7415. this.transformedElement = cpGroup;
  7416. if (layerElementParent) {
  7417. layerElementParent.appendChild(this.transformedElement);
  7418. } else {
  7419. this.baseElement = this.transformedElement;
  7420. }
  7421. } else {
  7422. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7423. }
  7424. }
  7425. if (this.data.bm !== 0) {
  7426. this.setBlendMode();
  7427. }
  7428. },
  7429. renderElement: function renderElement() {
  7430. if (this.finalTransform._localMatMdf) {
  7431. this.transformedElement.setAttribute('transform', this.finalTransform.localMat.to2dCSS());
  7432. }
  7433. if (this.finalTransform._opMdf) {
  7434. this.transformedElement.setAttribute('opacity', this.finalTransform.localOpacity);
  7435. }
  7436. },
  7437. destroyBaseElement: function destroyBaseElement() {
  7438. this.layerElement = null;
  7439. this.matteElement = null;
  7440. this.maskManager.destroy();
  7441. },
  7442. getBaseElement: function getBaseElement() {
  7443. if (this.data.hd) {
  7444. return null;
  7445. }
  7446. return this.baseElement;
  7447. },
  7448. createRenderableComponents: function createRenderableComponents() {
  7449. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7450. this.renderableEffectsManager = new SVGEffects(this);
  7451. this.searchEffectTransforms();
  7452. },
  7453. getMatte: function getMatte(matteType) {
  7454. // This should not be a common case. But for backward compatibility, we'll create the matte object.
  7455. // It solves animations that have two consecutive layers marked as matte masks.
  7456. // Which is an undefined behavior in AE.
  7457. if (!this.matteMasks) {
  7458. this.matteMasks = {};
  7459. }
  7460. if (!this.matteMasks[matteType]) {
  7461. var id = this.layerId + '_' + matteType;
  7462. var filId;
  7463. var fil;
  7464. var useElement;
  7465. var gg;
  7466. if (matteType === 1 || matteType === 3) {
  7467. var masker = createNS('mask');
  7468. masker.setAttribute('id', id);
  7469. masker.setAttribute('mask-type', matteType === 3 ? 'luminance' : 'alpha');
  7470. useElement = createNS('use');
  7471. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7472. masker.appendChild(useElement);
  7473. this.globalData.defs.appendChild(masker);
  7474. if (!featureSupport.maskType && matteType === 1) {
  7475. masker.setAttribute('mask-type', 'luminance');
  7476. filId = createElementID();
  7477. fil = filtersFactory.createFilter(filId);
  7478. this.globalData.defs.appendChild(fil);
  7479. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7480. gg = createNS('g');
  7481. gg.appendChild(useElement);
  7482. masker.appendChild(gg);
  7483. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7484. }
  7485. } else if (matteType === 2) {
  7486. var maskGroup = createNS('mask');
  7487. maskGroup.setAttribute('id', id);
  7488. maskGroup.setAttribute('mask-type', 'alpha');
  7489. var maskGrouper = createNS('g');
  7490. maskGroup.appendChild(maskGrouper);
  7491. filId = createElementID();
  7492. fil = filtersFactory.createFilter(filId); /// /
  7493. var feCTr = createNS('feComponentTransfer');
  7494. feCTr.setAttribute('in', 'SourceGraphic');
  7495. fil.appendChild(feCTr);
  7496. var feFunc = createNS('feFuncA');
  7497. feFunc.setAttribute('type', 'table');
  7498. feFunc.setAttribute('tableValues', '1.0 0.0');
  7499. feCTr.appendChild(feFunc); /// /
  7500. this.globalData.defs.appendChild(fil);
  7501. var alphaRect = createNS('rect');
  7502. alphaRect.setAttribute('width', this.comp.data.w);
  7503. alphaRect.setAttribute('height', this.comp.data.h);
  7504. alphaRect.setAttribute('x', '0');
  7505. alphaRect.setAttribute('y', '0');
  7506. alphaRect.setAttribute('fill', '#ffffff');
  7507. alphaRect.setAttribute('opacity', '0');
  7508. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7509. maskGrouper.appendChild(alphaRect);
  7510. useElement = createNS('use');
  7511. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7512. maskGrouper.appendChild(useElement);
  7513. if (!featureSupport.maskType) {
  7514. maskGroup.setAttribute('mask-type', 'luminance');
  7515. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7516. gg = createNS('g');
  7517. maskGrouper.appendChild(alphaRect);
  7518. gg.appendChild(this.layerElement);
  7519. maskGrouper.appendChild(gg);
  7520. }
  7521. this.globalData.defs.appendChild(maskGroup);
  7522. }
  7523. this.matteMasks[matteType] = id;
  7524. }
  7525. return this.matteMasks[matteType];
  7526. },
  7527. setMatte: function setMatte(id) {
  7528. if (!this.matteElement) {
  7529. return;
  7530. }
  7531. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7532. }
  7533. };
  7534. /**
  7535. * @file
  7536. * Handles AE's layer parenting property.
  7537. *
  7538. */
  7539. function HierarchyElement() {}
  7540. HierarchyElement.prototype = {
  7541. /**
  7542. * @function
  7543. * Initializes hierarchy properties
  7544. *
  7545. */
  7546. initHierarchy: function initHierarchy() {
  7547. // element's parent list
  7548. this.hierarchy = []; // if element is parent of another layer _isParent will be true
  7549. this._isParent = false;
  7550. this.checkParenting();
  7551. },
  7552. /**
  7553. * @function
  7554. * Sets layer's hierarchy.
  7555. * @param {array} hierarch
  7556. * layer's parent list
  7557. *
  7558. */
  7559. setHierarchy: function setHierarchy(hierarchy) {
  7560. this.hierarchy = hierarchy;
  7561. },
  7562. /**
  7563. * @function
  7564. * Sets layer as parent.
  7565. *
  7566. */
  7567. setAsParent: function setAsParent() {
  7568. this._isParent = true;
  7569. },
  7570. /**
  7571. * @function
  7572. * Searches layer's parenting chain
  7573. *
  7574. */
  7575. checkParenting: function checkParenting() {
  7576. if (this.data.parent !== undefined) {
  7577. this.comp.buildElementParenting(this, this.data.parent, []);
  7578. }
  7579. }
  7580. };
  7581. function RenderableDOMElement() {}
  7582. (function () {
  7583. var _prototype = {
  7584. initElement: function initElement(data, globalData, comp) {
  7585. this.initFrame();
  7586. this.initBaseData(data, globalData, comp);
  7587. this.initTransform(data, globalData, comp);
  7588. this.initHierarchy();
  7589. this.initRenderable();
  7590. this.initRendererElement();
  7591. this.createContainerElements();
  7592. this.createRenderableComponents();
  7593. this.createContent();
  7594. this.hide();
  7595. },
  7596. hide: function hide() {
  7597. // console.log('HIDE', this);
  7598. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7599. var elem = this.baseElement || this.layerElement;
  7600. elem.style.display = 'none';
  7601. this.hidden = true;
  7602. }
  7603. },
  7604. show: function show() {
  7605. // console.log('SHOW', this);
  7606. if (this.isInRange && !this.isTransparent) {
  7607. if (!this.data.hd) {
  7608. var elem = this.baseElement || this.layerElement;
  7609. elem.style.display = 'block';
  7610. }
  7611. this.hidden = false;
  7612. this._isFirstFrame = true;
  7613. }
  7614. },
  7615. renderFrame: function renderFrame() {
  7616. // If it is exported as hidden (data.hd === true) no need to render
  7617. // If it is not visible no need to render
  7618. if (this.data.hd || this.hidden) {
  7619. return;
  7620. }
  7621. this.renderTransform();
  7622. this.renderRenderable();
  7623. this.renderLocalTransform();
  7624. this.renderElement();
  7625. this.renderInnerContent();
  7626. if (this._isFirstFrame) {
  7627. this._isFirstFrame = false;
  7628. }
  7629. },
  7630. renderInnerContent: function renderInnerContent() {},
  7631. prepareFrame: function prepareFrame(num) {
  7632. this._mdf = false;
  7633. this.prepareRenderableFrame(num);
  7634. this.prepareProperties(num, this.isInRange);
  7635. this.checkTransparency();
  7636. },
  7637. destroy: function destroy() {
  7638. this.innerElem = null;
  7639. this.destroyBaseElement();
  7640. }
  7641. };
  7642. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  7643. })();
  7644. function IImageElement(data, globalData, comp) {
  7645. this.assetData = globalData.getAssetData(data.refId);
  7646. if (this.assetData && this.assetData.sid) {
  7647. this.assetData = globalData.slotManager.getProp(this.assetData);
  7648. }
  7649. this.initElement(data, globalData, comp);
  7650. this.sourceRect = {
  7651. top: 0,
  7652. left: 0,
  7653. width: this.assetData.w,
  7654. height: this.assetData.h
  7655. };
  7656. }
  7657. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  7658. IImageElement.prototype.createContent = function () {
  7659. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7660. this.innerElem = createNS('image');
  7661. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  7662. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  7663. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7664. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  7665. this.layerElement.appendChild(this.innerElem);
  7666. };
  7667. IImageElement.prototype.sourceRectAtTime = function () {
  7668. return this.sourceRect;
  7669. };
  7670. function ProcessedElement(element, position) {
  7671. this.elem = element;
  7672. this.pos = position;
  7673. }
  7674. function IShapeElement() {}
  7675. IShapeElement.prototype = {
  7676. addShapeToModifiers: function addShapeToModifiers(data) {
  7677. var i;
  7678. var len = this.shapeModifiers.length;
  7679. for (i = 0; i < len; i += 1) {
  7680. this.shapeModifiers[i].addShape(data);
  7681. }
  7682. },
  7683. isShapeInAnimatedModifiers: function isShapeInAnimatedModifiers(data) {
  7684. var i = 0;
  7685. var len = this.shapeModifiers.length;
  7686. while (i < len) {
  7687. if (this.shapeModifiers[i].isAnimatedWithShape(data)) {
  7688. return true;
  7689. }
  7690. }
  7691. return false;
  7692. },
  7693. renderModifiers: function renderModifiers() {
  7694. if (!this.shapeModifiers.length) {
  7695. return;
  7696. }
  7697. var i;
  7698. var len = this.shapes.length;
  7699. for (i = 0; i < len; i += 1) {
  7700. this.shapes[i].sh.reset();
  7701. }
  7702. len = this.shapeModifiers.length;
  7703. var shouldBreakProcess;
  7704. for (i = len - 1; i >= 0; i -= 1) {
  7705. shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame); // workaround to fix cases where a repeater resets the shape so the following processes get called twice
  7706. // TODO: find a better solution for this
  7707. if (shouldBreakProcess) {
  7708. break;
  7709. }
  7710. }
  7711. },
  7712. searchProcessedElement: function searchProcessedElement(elem) {
  7713. var elements = this.processedElements;
  7714. var i = 0;
  7715. var len = elements.length;
  7716. while (i < len) {
  7717. if (elements[i].elem === elem) {
  7718. return elements[i].pos;
  7719. }
  7720. i += 1;
  7721. }
  7722. return 0;
  7723. },
  7724. addProcessedElement: function addProcessedElement(elem, pos) {
  7725. var elements = this.processedElements;
  7726. var i = elements.length;
  7727. while (i) {
  7728. i -= 1;
  7729. if (elements[i].elem === elem) {
  7730. elements[i].pos = pos;
  7731. return;
  7732. }
  7733. }
  7734. elements.push(new ProcessedElement(elem, pos));
  7735. },
  7736. prepareFrame: function prepareFrame(num) {
  7737. this.prepareRenderableFrame(num);
  7738. this.prepareProperties(num, this.isInRange);
  7739. }
  7740. };
  7741. var lineCapEnum = {
  7742. 1: 'butt',
  7743. 2: 'round',
  7744. 3: 'square'
  7745. };
  7746. var lineJoinEnum = {
  7747. 1: 'miter',
  7748. 2: 'round',
  7749. 3: 'bevel'
  7750. };
  7751. function SVGShapeData(transformers, level, shape) {
  7752. this.caches = [];
  7753. this.styles = [];
  7754. this.transformers = transformers;
  7755. this.lStr = '';
  7756. this.sh = shape;
  7757. this.lvl = level; // TODO find if there are some cases where _isAnimated can be false.
  7758. // For now, since shapes add up with other shapes. They have to be calculated every time.
  7759. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  7760. this._isAnimated = !!shape.k; // TODO: commenting this for now since all shapes are animated
  7761. var i = 0;
  7762. var len = transformers.length;
  7763. while (i < len) {
  7764. if (transformers[i].mProps.dynamicProperties.length) {
  7765. this._isAnimated = true;
  7766. break;
  7767. }
  7768. i += 1;
  7769. }
  7770. }
  7771. SVGShapeData.prototype.setAsAnimated = function () {
  7772. this._isAnimated = true;
  7773. };
  7774. function SVGStyleData(data, level) {
  7775. this.data = data;
  7776. this.type = data.ty;
  7777. this.d = '';
  7778. this.lvl = level;
  7779. this._mdf = false;
  7780. this.closed = data.hd === true;
  7781. this.pElem = createNS('path');
  7782. this.msElem = null;
  7783. }
  7784. SVGStyleData.prototype.reset = function () {
  7785. this.d = '';
  7786. this._mdf = false;
  7787. };
  7788. function DashProperty(elem, data, renderer, container) {
  7789. this.elem = elem;
  7790. this.frameId = -1;
  7791. this.dataProps = createSizedArray(data.length);
  7792. this.renderer = renderer;
  7793. this.k = false;
  7794. this.dashStr = '';
  7795. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  7796. this.dashoffset = createTypedArray('float32', 1);
  7797. this.initDynamicPropertyContainer(container);
  7798. var i;
  7799. var len = data.length || 0;
  7800. var prop;
  7801. for (i = 0; i < len; i += 1) {
  7802. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  7803. this.k = prop.k || this.k;
  7804. this.dataProps[i] = {
  7805. n: data[i].n,
  7806. p: prop
  7807. };
  7808. }
  7809. if (!this.k) {
  7810. this.getValue(true);
  7811. }
  7812. this._isAnimated = this.k;
  7813. }
  7814. DashProperty.prototype.getValue = function (forceRender) {
  7815. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  7816. return;
  7817. }
  7818. this.frameId = this.elem.globalData.frameId;
  7819. this.iterateDynamicProperties();
  7820. this._mdf = this._mdf || forceRender;
  7821. if (this._mdf) {
  7822. var i = 0;
  7823. var len = this.dataProps.length;
  7824. if (this.renderer === 'svg') {
  7825. this.dashStr = '';
  7826. }
  7827. for (i = 0; i < len; i += 1) {
  7828. if (this.dataProps[i].n !== 'o') {
  7829. if (this.renderer === 'svg') {
  7830. this.dashStr += ' ' + this.dataProps[i].p.v;
  7831. } else {
  7832. this.dashArray[i] = this.dataProps[i].p.v;
  7833. }
  7834. } else {
  7835. this.dashoffset[0] = this.dataProps[i].p.v;
  7836. }
  7837. }
  7838. }
  7839. };
  7840. extendPrototype([DynamicPropertyContainer], DashProperty);
  7841. function SVGStrokeStyleData(elem, data, styleOb) {
  7842. this.initDynamicPropertyContainer(elem);
  7843. this.getValue = this.iterateDynamicProperties;
  7844. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7845. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  7846. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  7847. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7848. this.style = styleOb;
  7849. this._isAnimated = !!this._isAnimated;
  7850. }
  7851. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  7852. function SVGFillStyleData(elem, data, styleOb) {
  7853. this.initDynamicPropertyContainer(elem);
  7854. this.getValue = this.iterateDynamicProperties;
  7855. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7856. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7857. this.style = styleOb;
  7858. }
  7859. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  7860. function SVGNoStyleData(elem, data, styleOb) {
  7861. this.initDynamicPropertyContainer(elem);
  7862. this.getValue = this.iterateDynamicProperties;
  7863. this.style = styleOb;
  7864. }
  7865. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  7866. function GradientProperty(elem, data, container) {
  7867. this.data = data;
  7868. this.c = createTypedArray('uint8c', data.p * 4);
  7869. var cLength = data.k.k[0].s ? data.k.k[0].s.length - data.p * 4 : data.k.k.length - data.p * 4;
  7870. this.o = createTypedArray('float32', cLength);
  7871. this._cmdf = false;
  7872. this._omdf = false;
  7873. this._collapsable = this.checkCollapsable();
  7874. this._hasOpacity = cLength;
  7875. this.initDynamicPropertyContainer(container);
  7876. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  7877. this.k = this.prop.k;
  7878. this.getValue(true);
  7879. }
  7880. GradientProperty.prototype.comparePoints = function (values, points) {
  7881. var i = 0;
  7882. var len = this.o.length / 2;
  7883. var diff;
  7884. while (i < len) {
  7885. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  7886. if (diff > 0.01) {
  7887. return false;
  7888. }
  7889. i += 1;
  7890. }
  7891. return true;
  7892. };
  7893. GradientProperty.prototype.checkCollapsable = function () {
  7894. if (this.o.length / 2 !== this.c.length / 4) {
  7895. return false;
  7896. }
  7897. if (this.data.k.k[0].s) {
  7898. var i = 0;
  7899. var len = this.data.k.k.length;
  7900. while (i < len) {
  7901. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  7902. return false;
  7903. }
  7904. i += 1;
  7905. }
  7906. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  7907. return false;
  7908. }
  7909. return true;
  7910. };
  7911. GradientProperty.prototype.getValue = function (forceRender) {
  7912. this.prop.getValue();
  7913. this._mdf = false;
  7914. this._cmdf = false;
  7915. this._omdf = false;
  7916. if (this.prop._mdf || forceRender) {
  7917. var i;
  7918. var len = this.data.p * 4;
  7919. var mult;
  7920. var val;
  7921. for (i = 0; i < len; i += 1) {
  7922. mult = i % 4 === 0 ? 100 : 255;
  7923. val = Math.round(this.prop.v[i] * mult);
  7924. if (this.c[i] !== val) {
  7925. this.c[i] = val;
  7926. this._cmdf = !forceRender;
  7927. }
  7928. }
  7929. if (this.o.length) {
  7930. len = this.prop.v.length;
  7931. for (i = this.data.p * 4; i < len; i += 1) {
  7932. mult = i % 2 === 0 ? 100 : 1;
  7933. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  7934. if (this.o[i - this.data.p * 4] !== val) {
  7935. this.o[i - this.data.p * 4] = val;
  7936. this._omdf = !forceRender;
  7937. }
  7938. }
  7939. }
  7940. this._mdf = !forceRender;
  7941. }
  7942. };
  7943. extendPrototype([DynamicPropertyContainer], GradientProperty);
  7944. function SVGGradientFillStyleData(elem, data, styleOb) {
  7945. this.initDynamicPropertyContainer(elem);
  7946. this.getValue = this.iterateDynamicProperties;
  7947. this.initGradientData(elem, data, styleOb);
  7948. }
  7949. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  7950. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7951. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  7952. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  7953. this.h = PropertyFactory.getProp(elem, data.h || {
  7954. k: 0
  7955. }, 0, 0.01, this);
  7956. this.a = PropertyFactory.getProp(elem, data.a || {
  7957. k: 0
  7958. }, 0, degToRads, this);
  7959. this.g = new GradientProperty(elem, data.g, this);
  7960. this.style = styleOb;
  7961. this.stops = [];
  7962. this.setGradientData(styleOb.pElem, data);
  7963. this.setGradientOpacity(data, styleOb);
  7964. this._isAnimated = !!this._isAnimated;
  7965. };
  7966. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  7967. var gradientId = createElementID();
  7968. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  7969. gfill.setAttribute('id', gradientId);
  7970. gfill.setAttribute('spreadMethod', 'pad');
  7971. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  7972. var stops = [];
  7973. var stop;
  7974. var j;
  7975. var jLen;
  7976. jLen = data.g.p * 4;
  7977. for (j = 0; j < jLen; j += 4) {
  7978. stop = createNS('stop');
  7979. gfill.appendChild(stop);
  7980. stops.push(stop);
  7981. }
  7982. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  7983. this.gf = gfill;
  7984. this.cst = stops;
  7985. };
  7986. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  7987. if (this.g._hasOpacity && !this.g._collapsable) {
  7988. var stop;
  7989. var j;
  7990. var jLen;
  7991. var mask = createNS('mask');
  7992. var maskElement = createNS('path');
  7993. mask.appendChild(maskElement);
  7994. var opacityId = createElementID();
  7995. var maskId = createElementID();
  7996. mask.setAttribute('id', maskId);
  7997. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  7998. opFill.setAttribute('id', opacityId);
  7999. opFill.setAttribute('spreadMethod', 'pad');
  8000. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8001. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8002. var stops = this.stops;
  8003. for (j = data.g.p * 4; j < jLen; j += 2) {
  8004. stop = createNS('stop');
  8005. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8006. opFill.appendChild(stop);
  8007. stops.push(stop);
  8008. }
  8009. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8010. if (data.ty === 'gs') {
  8011. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8012. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8013. if (data.lj === 1) {
  8014. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8015. }
  8016. }
  8017. this.of = opFill;
  8018. this.ms = mask;
  8019. this.ost = stops;
  8020. this.maskId = maskId;
  8021. styleOb.msElem = maskElement;
  8022. }
  8023. };
  8024. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8025. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8026. this.initDynamicPropertyContainer(elem);
  8027. this.getValue = this.iterateDynamicProperties;
  8028. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8029. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8030. this.initGradientData(elem, data, styleOb);
  8031. this._isAnimated = !!this._isAnimated;
  8032. }
  8033. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8034. function ShapeGroupData() {
  8035. this.it = [];
  8036. this.prevViewData = [];
  8037. this.gr = createNS('g');
  8038. }
  8039. function SVGTransformData(mProps, op, container) {
  8040. this.transform = {
  8041. mProps: mProps,
  8042. op: op,
  8043. container: container
  8044. };
  8045. this.elements = [];
  8046. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8047. }
  8048. var buildShapeString = function buildShapeString(pathNodes, length, closed, mat) {
  8049. if (length === 0) {
  8050. return '';
  8051. }
  8052. var _o = pathNodes.o;
  8053. var _i = pathNodes.i;
  8054. var _v = pathNodes.v;
  8055. var i;
  8056. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8057. for (i = 1; i < length; i += 1) {
  8058. 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]);
  8059. }
  8060. if (closed && length) {
  8061. 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]);
  8062. shapeString += 'z';
  8063. }
  8064. return shapeString;
  8065. };
  8066. var SVGElementsRenderer = function () {
  8067. var _identityMatrix = new Matrix();
  8068. var _matrixHelper = new Matrix();
  8069. var ob = {
  8070. createRenderFunction: createRenderFunction
  8071. };
  8072. function createRenderFunction(data) {
  8073. switch (data.ty) {
  8074. case 'fl':
  8075. return renderFill;
  8076. case 'gf':
  8077. return renderGradient;
  8078. case 'gs':
  8079. return renderGradientStroke;
  8080. case 'st':
  8081. return renderStroke;
  8082. case 'sh':
  8083. case 'el':
  8084. case 'rc':
  8085. case 'sr':
  8086. return renderPath;
  8087. case 'tr':
  8088. return renderContentTransform;
  8089. case 'no':
  8090. return renderNoop;
  8091. default:
  8092. return null;
  8093. }
  8094. }
  8095. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8096. if (isFirstFrame || itemData.transform.op._mdf) {
  8097. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8098. }
  8099. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8100. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8101. }
  8102. }
  8103. function renderNoop() {}
  8104. function renderPath(styleData, itemData, isFirstFrame) {
  8105. var j;
  8106. var jLen;
  8107. var pathStringTransformed;
  8108. var redraw;
  8109. var pathNodes;
  8110. var l;
  8111. var lLen = itemData.styles.length;
  8112. var lvl = itemData.lvl;
  8113. var paths;
  8114. var mat;
  8115. var iterations;
  8116. var k;
  8117. for (l = 0; l < lLen; l += 1) {
  8118. redraw = itemData.sh._mdf || isFirstFrame;
  8119. if (itemData.styles[l].lvl < lvl) {
  8120. mat = _matrixHelper.reset();
  8121. iterations = lvl - itemData.styles[l].lvl;
  8122. k = itemData.transformers.length - 1;
  8123. while (!redraw && iterations > 0) {
  8124. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8125. iterations -= 1;
  8126. k -= 1;
  8127. }
  8128. if (redraw) {
  8129. iterations = lvl - itemData.styles[l].lvl;
  8130. k = itemData.transformers.length - 1;
  8131. while (iterations > 0) {
  8132. mat.multiply(itemData.transformers[k].mProps.v);
  8133. iterations -= 1;
  8134. k -= 1;
  8135. }
  8136. }
  8137. } else {
  8138. mat = _identityMatrix;
  8139. }
  8140. paths = itemData.sh.paths;
  8141. jLen = paths._length;
  8142. if (redraw) {
  8143. pathStringTransformed = '';
  8144. for (j = 0; j < jLen; j += 1) {
  8145. pathNodes = paths.shapes[j];
  8146. if (pathNodes && pathNodes._length) {
  8147. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8148. }
  8149. }
  8150. itemData.caches[l] = pathStringTransformed;
  8151. } else {
  8152. pathStringTransformed = itemData.caches[l];
  8153. }
  8154. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8155. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8156. }
  8157. }
  8158. function renderFill(styleData, itemData, isFirstFrame) {
  8159. var styleElem = itemData.style;
  8160. if (itemData.c._mdf || isFirstFrame) {
  8161. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8162. }
  8163. if (itemData.o._mdf || isFirstFrame) {
  8164. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8165. }
  8166. }
  8167. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8168. renderGradient(styleData, itemData, isFirstFrame);
  8169. renderStroke(styleData, itemData, isFirstFrame);
  8170. }
  8171. function renderGradient(styleData, itemData, isFirstFrame) {
  8172. var gfill = itemData.gf;
  8173. var hasOpacity = itemData.g._hasOpacity;
  8174. var pt1 = itemData.s.v;
  8175. var pt2 = itemData.e.v;
  8176. if (itemData.o._mdf || isFirstFrame) {
  8177. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8178. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8179. }
  8180. if (itemData.s._mdf || isFirstFrame) {
  8181. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8182. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8183. gfill.setAttribute(attr1, pt1[0]);
  8184. gfill.setAttribute(attr2, pt1[1]);
  8185. if (hasOpacity && !itemData.g._collapsable) {
  8186. itemData.of.setAttribute(attr1, pt1[0]);
  8187. itemData.of.setAttribute(attr2, pt1[1]);
  8188. }
  8189. }
  8190. var stops;
  8191. var i;
  8192. var len;
  8193. var stop;
  8194. if (itemData.g._cmdf || isFirstFrame) {
  8195. stops = itemData.cst;
  8196. var cValues = itemData.g.c;
  8197. len = stops.length;
  8198. for (i = 0; i < len; i += 1) {
  8199. stop = stops[i];
  8200. stop.setAttribute('offset', cValues[i * 4] + '%');
  8201. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8202. }
  8203. }
  8204. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8205. var oValues = itemData.g.o;
  8206. if (itemData.g._collapsable) {
  8207. stops = itemData.cst;
  8208. } else {
  8209. stops = itemData.ost;
  8210. }
  8211. len = stops.length;
  8212. for (i = 0; i < len; i += 1) {
  8213. stop = stops[i];
  8214. if (!itemData.g._collapsable) {
  8215. stop.setAttribute('offset', oValues[i * 2] + '%');
  8216. }
  8217. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8218. }
  8219. }
  8220. if (styleData.t === 1) {
  8221. if (itemData.e._mdf || isFirstFrame) {
  8222. gfill.setAttribute('x2', pt2[0]);
  8223. gfill.setAttribute('y2', pt2[1]);
  8224. if (hasOpacity && !itemData.g._collapsable) {
  8225. itemData.of.setAttribute('x2', pt2[0]);
  8226. itemData.of.setAttribute('y2', pt2[1]);
  8227. }
  8228. }
  8229. } else {
  8230. var rad;
  8231. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8232. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8233. gfill.setAttribute('r', rad);
  8234. if (hasOpacity && !itemData.g._collapsable) {
  8235. itemData.of.setAttribute('r', rad);
  8236. }
  8237. }
  8238. if (itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8239. if (!rad) {
  8240. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8241. }
  8242. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8243. var percent = itemData.h.v;
  8244. if (percent >= 1) {
  8245. percent = 0.99;
  8246. } else if (percent <= -1) {
  8247. percent = -0.99;
  8248. }
  8249. var dist = rad * percent;
  8250. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8251. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8252. gfill.setAttribute('fx', x);
  8253. gfill.setAttribute('fy', y);
  8254. if (hasOpacity && !itemData.g._collapsable) {
  8255. itemData.of.setAttribute('fx', x);
  8256. itemData.of.setAttribute('fy', y);
  8257. }
  8258. } // gfill.setAttribute('fy','200');
  8259. }
  8260. }
  8261. function renderStroke(styleData, itemData, isFirstFrame) {
  8262. var styleElem = itemData.style;
  8263. var d = itemData.d;
  8264. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8265. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8266. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8267. }
  8268. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8269. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8270. }
  8271. if (itemData.o._mdf || isFirstFrame) {
  8272. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8273. }
  8274. if (itemData.w._mdf || isFirstFrame) {
  8275. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8276. if (styleElem.msElem) {
  8277. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8278. }
  8279. }
  8280. }
  8281. return ob;
  8282. }();
  8283. function SVGShapeElement(data, globalData, comp) {
  8284. // List of drawable elements
  8285. this.shapes = []; // Full shape data
  8286. this.shapesData = data.shapes; // List of styles that will be applied to shapes
  8287. this.stylesList = []; // List of modifiers that will be applied to shapes
  8288. this.shapeModifiers = []; // List of items in shape tree
  8289. this.itemsData = []; // List of items in previous shape tree
  8290. this.processedElements = []; // List of animated components
  8291. this.animatedContents = [];
  8292. this.initElement(data, globalData, comp); // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8293. // List of elements that have been created
  8294. this.prevViewData = []; // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8295. }
  8296. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8297. SVGShapeElement.prototype.initSecondaryElement = function () {};
  8298. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8299. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8300. SVGShapeElement.prototype.createContent = function () {
  8301. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8302. this.filterUniqueShapes();
  8303. };
  8304. /*
  8305. This method searches for multiple shapes that affect a single element and one of them is animated
  8306. */
  8307. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8308. var i;
  8309. var len = this.shapes.length;
  8310. var shape;
  8311. var j;
  8312. var jLen = this.stylesList.length;
  8313. var style;
  8314. var tempShapes = [];
  8315. var areAnimated = false;
  8316. for (j = 0; j < jLen; j += 1) {
  8317. style = this.stylesList[j];
  8318. areAnimated = false;
  8319. tempShapes.length = 0;
  8320. for (i = 0; i < len; i += 1) {
  8321. shape = this.shapes[i];
  8322. if (shape.styles.indexOf(style) !== -1) {
  8323. tempShapes.push(shape);
  8324. areAnimated = shape._isAnimated || areAnimated;
  8325. }
  8326. }
  8327. if (tempShapes.length > 1 && areAnimated) {
  8328. this.setShapesAsAnimated(tempShapes);
  8329. }
  8330. }
  8331. };
  8332. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8333. var i;
  8334. var len = shapes.length;
  8335. for (i = 0; i < len; i += 1) {
  8336. shapes[i].setAsAnimated();
  8337. }
  8338. };
  8339. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8340. // TODO: prevent drawing of hidden styles
  8341. var elementData;
  8342. var styleOb = new SVGStyleData(data, level);
  8343. var pathElement = styleOb.pElem;
  8344. if (data.ty === 'st') {
  8345. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8346. } else if (data.ty === 'fl') {
  8347. elementData = new SVGFillStyleData(this, data, styleOb);
  8348. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8349. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8350. elementData = new GradientConstructor(this, data, styleOb);
  8351. this.globalData.defs.appendChild(elementData.gf);
  8352. if (elementData.maskId) {
  8353. this.globalData.defs.appendChild(elementData.ms);
  8354. this.globalData.defs.appendChild(elementData.of);
  8355. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8356. }
  8357. } else if (data.ty === 'no') {
  8358. elementData = new SVGNoStyleData(this, data, styleOb);
  8359. }
  8360. if (data.ty === 'st' || data.ty === 'gs') {
  8361. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8362. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8363. pathElement.setAttribute('fill-opacity', '0');
  8364. if (data.lj === 1) {
  8365. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8366. }
  8367. }
  8368. if (data.r === 2) {
  8369. pathElement.setAttribute('fill-rule', 'evenodd');
  8370. }
  8371. if (data.ln) {
  8372. pathElement.setAttribute('id', data.ln);
  8373. }
  8374. if (data.cl) {
  8375. pathElement.setAttribute('class', data.cl);
  8376. }
  8377. if (data.bm) {
  8378. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8379. }
  8380. this.stylesList.push(styleOb);
  8381. this.addToAnimatedContents(data, elementData);
  8382. return elementData;
  8383. };
  8384. SVGShapeElement.prototype.createGroupElement = function (data) {
  8385. var elementData = new ShapeGroupData();
  8386. if (data.ln) {
  8387. elementData.gr.setAttribute('id', data.ln);
  8388. }
  8389. if (data.cl) {
  8390. elementData.gr.setAttribute('class', data.cl);
  8391. }
  8392. if (data.bm) {
  8393. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8394. }
  8395. return elementData;
  8396. };
  8397. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8398. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8399. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8400. this.addToAnimatedContents(data, elementData);
  8401. return elementData;
  8402. };
  8403. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8404. var ty = 4;
  8405. if (data.ty === 'rc') {
  8406. ty = 5;
  8407. } else if (data.ty === 'el') {
  8408. ty = 6;
  8409. } else if (data.ty === 'sr') {
  8410. ty = 7;
  8411. }
  8412. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8413. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8414. this.shapes.push(elementData);
  8415. this.addShapeToModifiers(elementData);
  8416. this.addToAnimatedContents(data, elementData);
  8417. return elementData;
  8418. };
  8419. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8420. var i = 0;
  8421. var len = this.animatedContents.length;
  8422. while (i < len) {
  8423. if (this.animatedContents[i].element === element) {
  8424. return;
  8425. }
  8426. i += 1;
  8427. }
  8428. this.animatedContents.push({
  8429. fn: SVGElementsRenderer.createRenderFunction(data),
  8430. element: element,
  8431. data: data
  8432. });
  8433. };
  8434. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8435. var arr = elementData.styles;
  8436. var j;
  8437. var jLen = this.stylesList.length;
  8438. for (j = 0; j < jLen; j += 1) {
  8439. if (!this.stylesList[j].closed) {
  8440. arr.push(this.stylesList[j]);
  8441. }
  8442. }
  8443. };
  8444. SVGShapeElement.prototype.reloadShapes = function () {
  8445. this._isFirstFrame = true;
  8446. var i;
  8447. var len = this.itemsData.length;
  8448. for (i = 0; i < len; i += 1) {
  8449. this.prevViewData[i] = this.itemsData[i];
  8450. }
  8451. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8452. this.filterUniqueShapes();
  8453. len = this.dynamicProperties.length;
  8454. for (i = 0; i < len; i += 1) {
  8455. this.dynamicProperties[i].getValue();
  8456. }
  8457. this.renderModifiers();
  8458. };
  8459. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8460. var ownTransformers = [].concat(transformers);
  8461. var i;
  8462. var len = arr.length - 1;
  8463. var j;
  8464. var jLen;
  8465. var ownStyles = [];
  8466. var ownModifiers = [];
  8467. var currentTransform;
  8468. var modifier;
  8469. var processedPos;
  8470. for (i = len; i >= 0; i -= 1) {
  8471. processedPos = this.searchProcessedElement(arr[i]);
  8472. if (!processedPos) {
  8473. arr[i]._render = render;
  8474. } else {
  8475. itemsData[i] = prevViewData[processedPos - 1];
  8476. }
  8477. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8478. if (!processedPos) {
  8479. itemsData[i] = this.createStyleElement(arr[i], level);
  8480. } else {
  8481. itemsData[i].style.closed = false;
  8482. }
  8483. if (arr[i]._render) {
  8484. if (itemsData[i].style.pElem.parentNode !== container) {
  8485. container.appendChild(itemsData[i].style.pElem);
  8486. }
  8487. }
  8488. ownStyles.push(itemsData[i].style);
  8489. } else if (arr[i].ty === 'gr') {
  8490. if (!processedPos) {
  8491. itemsData[i] = this.createGroupElement(arr[i]);
  8492. } else {
  8493. jLen = itemsData[i].it.length;
  8494. for (j = 0; j < jLen; j += 1) {
  8495. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8496. }
  8497. }
  8498. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8499. if (arr[i]._render) {
  8500. if (itemsData[i].gr.parentNode !== container) {
  8501. container.appendChild(itemsData[i].gr);
  8502. }
  8503. }
  8504. } else if (arr[i].ty === 'tr') {
  8505. if (!processedPos) {
  8506. itemsData[i] = this.createTransformElement(arr[i], container);
  8507. }
  8508. currentTransform = itemsData[i].transform;
  8509. ownTransformers.push(currentTransform);
  8510. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8511. if (!processedPos) {
  8512. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8513. }
  8514. this.setElementStyles(itemsData[i]);
  8515. } 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') {
  8516. if (!processedPos) {
  8517. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8518. modifier.init(this, arr[i]);
  8519. itemsData[i] = modifier;
  8520. this.shapeModifiers.push(modifier);
  8521. } else {
  8522. modifier = itemsData[i];
  8523. modifier.closed = false;
  8524. }
  8525. ownModifiers.push(modifier);
  8526. } else if (arr[i].ty === 'rp') {
  8527. if (!processedPos) {
  8528. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8529. itemsData[i] = modifier;
  8530. modifier.init(this, arr, i, itemsData);
  8531. this.shapeModifiers.push(modifier);
  8532. render = false;
  8533. } else {
  8534. modifier = itemsData[i];
  8535. modifier.closed = true;
  8536. }
  8537. ownModifiers.push(modifier);
  8538. }
  8539. this.addProcessedElement(arr[i], i + 1);
  8540. }
  8541. len = ownStyles.length;
  8542. for (i = 0; i < len; i += 1) {
  8543. ownStyles[i].closed = true;
  8544. }
  8545. len = ownModifiers.length;
  8546. for (i = 0; i < len; i += 1) {
  8547. ownModifiers[i].closed = true;
  8548. }
  8549. };
  8550. SVGShapeElement.prototype.renderInnerContent = function () {
  8551. this.renderModifiers();
  8552. var i;
  8553. var len = this.stylesList.length;
  8554. for (i = 0; i < len; i += 1) {
  8555. this.stylesList[i].reset();
  8556. }
  8557. this.renderShape();
  8558. for (i = 0; i < len; i += 1) {
  8559. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8560. if (this.stylesList[i].msElem) {
  8561. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d); // Adding M0 0 fixes same mask bug on all browsers
  8562. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8563. }
  8564. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8565. }
  8566. }
  8567. };
  8568. SVGShapeElement.prototype.renderShape = function () {
  8569. var i;
  8570. var len = this.animatedContents.length;
  8571. var animatedContent;
  8572. for (i = 0; i < len; i += 1) {
  8573. animatedContent = this.animatedContents[i];
  8574. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8575. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8576. }
  8577. }
  8578. };
  8579. SVGShapeElement.prototype.destroy = function () {
  8580. this.destroyBaseElement();
  8581. this.shapesData = null;
  8582. this.itemsData = null;
  8583. };
  8584. function LetterProps(o, sw, sc, fc, m, p) {
  8585. this.o = o;
  8586. this.sw = sw;
  8587. this.sc = sc;
  8588. this.fc = fc;
  8589. this.m = m;
  8590. this.p = p;
  8591. this._mdf = {
  8592. o: true,
  8593. sw: !!sw,
  8594. sc: !!sc,
  8595. fc: !!fc,
  8596. m: true,
  8597. p: true
  8598. };
  8599. }
  8600. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  8601. this._mdf.o = false;
  8602. this._mdf.sw = false;
  8603. this._mdf.sc = false;
  8604. this._mdf.fc = false;
  8605. this._mdf.m = false;
  8606. this._mdf.p = false;
  8607. var updated = false;
  8608. if (this.o !== o) {
  8609. this.o = o;
  8610. this._mdf.o = true;
  8611. updated = true;
  8612. }
  8613. if (this.sw !== sw) {
  8614. this.sw = sw;
  8615. this._mdf.sw = true;
  8616. updated = true;
  8617. }
  8618. if (this.sc !== sc) {
  8619. this.sc = sc;
  8620. this._mdf.sc = true;
  8621. updated = true;
  8622. }
  8623. if (this.fc !== fc) {
  8624. this.fc = fc;
  8625. this._mdf.fc = true;
  8626. updated = true;
  8627. }
  8628. if (this.m !== m) {
  8629. this.m = m;
  8630. this._mdf.m = true;
  8631. updated = true;
  8632. }
  8633. 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])) {
  8634. this.p = p;
  8635. this._mdf.p = true;
  8636. updated = true;
  8637. }
  8638. return updated;
  8639. };
  8640. function TextProperty(elem, data) {
  8641. this._frameId = initialDefaultFrame;
  8642. this.pv = '';
  8643. this.v = '';
  8644. this.kf = false;
  8645. this._isFirstFrame = true;
  8646. this._mdf = false;
  8647. if (data.d && data.d.sid) {
  8648. data.d = elem.globalData.slotManager.getProp(data.d);
  8649. }
  8650. this.data = data;
  8651. this.elem = elem;
  8652. this.comp = this.elem.comp;
  8653. this.keysIndex = 0;
  8654. this.canResize = false;
  8655. this.minimumFontSize = 1;
  8656. this.effectsSequence = [];
  8657. this.currentData = {
  8658. ascent: 0,
  8659. boxWidth: this.defaultBoxWidth,
  8660. f: '',
  8661. fStyle: '',
  8662. fWeight: '',
  8663. fc: '',
  8664. j: '',
  8665. justifyOffset: '',
  8666. l: [],
  8667. lh: 0,
  8668. lineWidths: [],
  8669. ls: '',
  8670. of: '',
  8671. s: '',
  8672. sc: '',
  8673. sw: 0,
  8674. t: 0,
  8675. tr: 0,
  8676. sz: 0,
  8677. ps: null,
  8678. fillColorAnim: false,
  8679. strokeColorAnim: false,
  8680. strokeWidthAnim: false,
  8681. yOffset: 0,
  8682. finalSize: 0,
  8683. finalText: [],
  8684. finalLineHeight: 0,
  8685. __complete: false
  8686. };
  8687. this.copyData(this.currentData, this.data.d.k[0].s);
  8688. if (!this.searchProperty()) {
  8689. this.completeTextData(this.currentData);
  8690. }
  8691. }
  8692. TextProperty.prototype.defaultBoxWidth = [0, 0];
  8693. TextProperty.prototype.copyData = function (obj, data) {
  8694. for (var s in data) {
  8695. if (Object.prototype.hasOwnProperty.call(data, s)) {
  8696. obj[s] = data[s];
  8697. }
  8698. }
  8699. return obj;
  8700. };
  8701. TextProperty.prototype.setCurrentData = function (data) {
  8702. if (!data.__complete) {
  8703. this.completeTextData(data);
  8704. }
  8705. this.currentData = data;
  8706. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  8707. this._mdf = true;
  8708. };
  8709. TextProperty.prototype.searchProperty = function () {
  8710. return this.searchKeyframes();
  8711. };
  8712. TextProperty.prototype.searchKeyframes = function () {
  8713. this.kf = this.data.d.k.length > 1;
  8714. if (this.kf) {
  8715. this.addEffect(this.getKeyframeValue.bind(this));
  8716. }
  8717. return this.kf;
  8718. };
  8719. TextProperty.prototype.addEffect = function (effectFunction) {
  8720. this.effectsSequence.push(effectFunction);
  8721. this.elem.addDynamicProperty(this);
  8722. };
  8723. TextProperty.prototype.getValue = function (_finalValue) {
  8724. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  8725. return;
  8726. }
  8727. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  8728. var currentValue = this.currentData;
  8729. var currentIndex = this.keysIndex;
  8730. if (this.lock) {
  8731. this.setCurrentData(this.currentData);
  8732. return;
  8733. }
  8734. this.lock = true;
  8735. this._mdf = false;
  8736. var i;
  8737. var len = this.effectsSequence.length;
  8738. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  8739. for (i = 0; i < len; i += 1) {
  8740. // Checking if index changed to prevent creating a new object every time the expression updates.
  8741. if (currentIndex !== this.keysIndex) {
  8742. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  8743. } else {
  8744. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  8745. }
  8746. }
  8747. if (currentValue !== finalValue) {
  8748. this.setCurrentData(finalValue);
  8749. }
  8750. this.v = this.currentData;
  8751. this.pv = this.v;
  8752. this.lock = false;
  8753. this.frameId = this.elem.globalData.frameId;
  8754. };
  8755. TextProperty.prototype.getKeyframeValue = function () {
  8756. var textKeys = this.data.d.k;
  8757. var frameNum = this.elem.comp.renderedFrame;
  8758. var i = 0;
  8759. var len = textKeys.length;
  8760. while (i <= len - 1) {
  8761. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  8762. break;
  8763. }
  8764. i += 1;
  8765. }
  8766. if (this.keysIndex !== i) {
  8767. this.keysIndex = i;
  8768. }
  8769. return this.data.d.k[this.keysIndex].s;
  8770. };
  8771. TextProperty.prototype.buildFinalText = function (text) {
  8772. var charactersArray = [];
  8773. var i = 0;
  8774. var len = text.length;
  8775. var charCode;
  8776. var secondCharCode;
  8777. var shouldCombine = false;
  8778. var shouldCombineNext = false;
  8779. var currentChars = '';
  8780. while (i < len) {
  8781. shouldCombine = shouldCombineNext;
  8782. shouldCombineNext = false;
  8783. charCode = text.charCodeAt(i);
  8784. currentChars = text.charAt(i);
  8785. if (FontManager.isCombinedCharacter(charCode)) {
  8786. shouldCombine = true; // It's a potential surrogate pair (this is the High surrogate)
  8787. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  8788. if (FontManager.isRegionalFlag(text, i)) {
  8789. currentChars = text.substr(i, 14);
  8790. } else {
  8791. secondCharCode = text.charCodeAt(i + 1); // It's a surrogate pair (this is the Low surrogate)
  8792. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  8793. if (FontManager.isModifier(charCode, secondCharCode)) {
  8794. currentChars = text.substr(i, 2);
  8795. shouldCombine = true;
  8796. } else if (FontManager.isFlagEmoji(text.substr(i, 4))) {
  8797. currentChars = text.substr(i, 4);
  8798. } else {
  8799. currentChars = text.substr(i, 2);
  8800. }
  8801. }
  8802. }
  8803. } else if (charCode > 0xDBFF) {
  8804. secondCharCode = text.charCodeAt(i + 1);
  8805. if (FontManager.isVariationSelector(charCode)) {
  8806. shouldCombine = true;
  8807. }
  8808. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  8809. shouldCombine = true;
  8810. shouldCombineNext = true;
  8811. }
  8812. if (shouldCombine) {
  8813. charactersArray[charactersArray.length - 1] += currentChars;
  8814. shouldCombine = false;
  8815. } else {
  8816. charactersArray.push(currentChars);
  8817. }
  8818. i += currentChars.length;
  8819. }
  8820. return charactersArray;
  8821. };
  8822. TextProperty.prototype.completeTextData = function (documentData) {
  8823. documentData.__complete = true;
  8824. var fontManager = this.elem.globalData.fontManager;
  8825. var data = this.data;
  8826. var letters = [];
  8827. var i;
  8828. var len;
  8829. var newLineFlag;
  8830. var index = 0;
  8831. var val;
  8832. var anchorGrouping = data.m.g;
  8833. var currentSize = 0;
  8834. var currentPos = 0;
  8835. var currentLine = 0;
  8836. var lineWidths = [];
  8837. var lineWidth = 0;
  8838. var maxLineWidth = 0;
  8839. var j;
  8840. var jLen;
  8841. var fontData = fontManager.getFontByName(documentData.f);
  8842. var charData;
  8843. var cLength = 0;
  8844. var fontProps = getFontProperties(fontData);
  8845. documentData.fWeight = fontProps.weight;
  8846. documentData.fStyle = fontProps.style;
  8847. documentData.finalSize = documentData.s;
  8848. documentData.finalText = this.buildFinalText(documentData.t);
  8849. len = documentData.finalText.length;
  8850. documentData.finalLineHeight = documentData.lh;
  8851. var trackingOffset = documentData.tr / 1000 * documentData.finalSize;
  8852. var charCode;
  8853. if (documentData.sz) {
  8854. var flag = true;
  8855. var boxWidth = documentData.sz[0];
  8856. var boxHeight = documentData.sz[1];
  8857. var currentHeight;
  8858. var finalText;
  8859. while (flag) {
  8860. finalText = this.buildFinalText(documentData.t);
  8861. currentHeight = 0;
  8862. lineWidth = 0;
  8863. len = finalText.length;
  8864. trackingOffset = documentData.tr / 1000 * documentData.finalSize;
  8865. var lastSpaceIndex = -1;
  8866. for (i = 0; i < len; i += 1) {
  8867. charCode = finalText[i].charCodeAt(0);
  8868. newLineFlag = false;
  8869. if (finalText[i] === ' ') {
  8870. lastSpaceIndex = i;
  8871. } else if (charCode === 13 || charCode === 3) {
  8872. lineWidth = 0;
  8873. newLineFlag = true;
  8874. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8875. }
  8876. if (fontManager.chars) {
  8877. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  8878. cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
  8879. } else {
  8880. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  8881. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  8882. }
  8883. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  8884. if (lastSpaceIndex === -1) {
  8885. len += 1;
  8886. } else {
  8887. i = lastSpaceIndex;
  8888. }
  8889. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8890. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r'); // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  8891. lastSpaceIndex = -1;
  8892. lineWidth = 0;
  8893. } else {
  8894. lineWidth += cLength;
  8895. lineWidth += trackingOffset;
  8896. }
  8897. }
  8898. currentHeight += fontData.ascent * documentData.finalSize / 100;
  8899. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  8900. documentData.finalSize -= 1;
  8901. documentData.finalLineHeight = documentData.finalSize * documentData.lh / documentData.s;
  8902. } else {
  8903. documentData.finalText = finalText;
  8904. len = documentData.finalText.length;
  8905. flag = false;
  8906. }
  8907. }
  8908. }
  8909. lineWidth = -trackingOffset;
  8910. cLength = 0;
  8911. var uncollapsedSpaces = 0;
  8912. var currentChar;
  8913. for (i = 0; i < len; i += 1) {
  8914. newLineFlag = false;
  8915. currentChar = documentData.finalText[i];
  8916. charCode = currentChar.charCodeAt(0);
  8917. if (charCode === 13 || charCode === 3) {
  8918. uncollapsedSpaces = 0;
  8919. lineWidths.push(lineWidth);
  8920. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  8921. lineWidth = -2 * trackingOffset;
  8922. val = '';
  8923. newLineFlag = true;
  8924. currentLine += 1;
  8925. } else {
  8926. val = currentChar;
  8927. }
  8928. if (fontManager.chars) {
  8929. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  8930. cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
  8931. } else {
  8932. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  8933. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  8934. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  8935. } //
  8936. if (currentChar === ' ') {
  8937. uncollapsedSpaces += cLength + trackingOffset;
  8938. } else {
  8939. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  8940. uncollapsedSpaces = 0;
  8941. }
  8942. letters.push({
  8943. l: cLength,
  8944. an: cLength,
  8945. add: currentSize,
  8946. n: newLineFlag,
  8947. anIndexes: [],
  8948. val: val,
  8949. line: currentLine,
  8950. animatorJustifyOffset: 0
  8951. });
  8952. if (anchorGrouping == 2) {
  8953. // eslint-disable-line eqeqeq
  8954. currentSize += cLength;
  8955. if (val === '' || val === ' ' || i === len - 1) {
  8956. if (val === '' || val === ' ') {
  8957. currentSize -= cLength;
  8958. }
  8959. while (currentPos <= i) {
  8960. letters[currentPos].an = currentSize;
  8961. letters[currentPos].ind = index;
  8962. letters[currentPos].extra = cLength;
  8963. currentPos += 1;
  8964. }
  8965. index += 1;
  8966. currentSize = 0;
  8967. }
  8968. } else if (anchorGrouping == 3) {
  8969. // eslint-disable-line eqeqeq
  8970. currentSize += cLength;
  8971. if (val === '' || i === len - 1) {
  8972. if (val === '') {
  8973. currentSize -= cLength;
  8974. }
  8975. while (currentPos <= i) {
  8976. letters[currentPos].an = currentSize;
  8977. letters[currentPos].ind = index;
  8978. letters[currentPos].extra = cLength;
  8979. currentPos += 1;
  8980. }
  8981. currentSize = 0;
  8982. index += 1;
  8983. }
  8984. } else {
  8985. letters[index].ind = index;
  8986. letters[index].extra = 0;
  8987. index += 1;
  8988. }
  8989. }
  8990. documentData.l = letters;
  8991. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  8992. lineWidths.push(lineWidth);
  8993. if (documentData.sz) {
  8994. documentData.boxWidth = documentData.sz[0];
  8995. documentData.justifyOffset = 0;
  8996. } else {
  8997. documentData.boxWidth = maxLineWidth;
  8998. switch (documentData.j) {
  8999. case 1:
  9000. documentData.justifyOffset = -documentData.boxWidth;
  9001. break;
  9002. case 2:
  9003. documentData.justifyOffset = -documentData.boxWidth / 2;
  9004. break;
  9005. default:
  9006. documentData.justifyOffset = 0;
  9007. }
  9008. }
  9009. documentData.lineWidths = lineWidths;
  9010. var animators = data.a;
  9011. var animatorData;
  9012. var letterData;
  9013. jLen = animators.length;
  9014. var based;
  9015. var ind;
  9016. var indexes = [];
  9017. for (j = 0; j < jLen; j += 1) {
  9018. animatorData = animators[j];
  9019. if (animatorData.a.sc) {
  9020. documentData.strokeColorAnim = true;
  9021. }
  9022. if (animatorData.a.sw) {
  9023. documentData.strokeWidthAnim = true;
  9024. }
  9025. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9026. documentData.fillColorAnim = true;
  9027. }
  9028. ind = 0;
  9029. based = animatorData.s.b;
  9030. for (i = 0; i < len; i += 1) {
  9031. letterData = letters[i];
  9032. letterData.anIndexes[j] = ind;
  9033. 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)) {
  9034. // eslint-disable-line eqeqeq
  9035. if (animatorData.s.rn === 1) {
  9036. indexes.push(ind);
  9037. }
  9038. ind += 1;
  9039. }
  9040. }
  9041. data.a[j].s.totalChars = ind;
  9042. var currentInd = -1;
  9043. var newInd;
  9044. if (animatorData.s.rn === 1) {
  9045. for (i = 0; i < len; i += 1) {
  9046. letterData = letters[i];
  9047. if (currentInd != letterData.anIndexes[j]) {
  9048. // eslint-disable-line eqeqeq
  9049. currentInd = letterData.anIndexes[j];
  9050. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9051. }
  9052. letterData.anIndexes[j] = newInd;
  9053. }
  9054. }
  9055. }
  9056. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9057. documentData.ls = documentData.ls || 0;
  9058. documentData.ascent = fontData.ascent * documentData.finalSize / 100;
  9059. };
  9060. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9061. index = index === undefined ? this.keysIndex : index;
  9062. var dData = this.copyData({}, this.data.d.k[index].s);
  9063. dData = this.copyData(dData, newData);
  9064. this.data.d.k[index].s = dData;
  9065. this.recalculate(index);
  9066. this.setCurrentData(dData);
  9067. this.elem.addDynamicProperty(this);
  9068. };
  9069. TextProperty.prototype.recalculate = function (index) {
  9070. var dData = this.data.d.k[index].s;
  9071. dData.__complete = false;
  9072. this.keysIndex = 0;
  9073. this._isFirstFrame = true;
  9074. this.getValue(dData);
  9075. };
  9076. TextProperty.prototype.canResizeFont = function (_canResize) {
  9077. this.canResize = _canResize;
  9078. this.recalculate(this.keysIndex);
  9079. this.elem.addDynamicProperty(this);
  9080. };
  9081. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9082. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9083. this.recalculate(this.keysIndex);
  9084. this.elem.addDynamicProperty(this);
  9085. };
  9086. var TextSelectorProp = function () {
  9087. var max = Math.max;
  9088. var min = Math.min;
  9089. var floor = Math.floor;
  9090. function TextSelectorPropFactory(elem, data) {
  9091. this._currentTextLength = -1;
  9092. this.k = false;
  9093. this.data = data;
  9094. this.elem = elem;
  9095. this.comp = elem.comp;
  9096. this.finalS = 0;
  9097. this.finalE = 0;
  9098. this.initDynamicPropertyContainer(elem);
  9099. this.s = PropertyFactory.getProp(elem, data.s || {
  9100. k: 0
  9101. }, 0, 0, this);
  9102. if ('e' in data) {
  9103. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9104. } else {
  9105. this.e = {
  9106. v: 100
  9107. };
  9108. }
  9109. this.o = PropertyFactory.getProp(elem, data.o || {
  9110. k: 0
  9111. }, 0, 0, this);
  9112. this.xe = PropertyFactory.getProp(elem, data.xe || {
  9113. k: 0
  9114. }, 0, 0, this);
  9115. this.ne = PropertyFactory.getProp(elem, data.ne || {
  9116. k: 0
  9117. }, 0, 0, this);
  9118. this.sm = PropertyFactory.getProp(elem, data.sm || {
  9119. k: 100
  9120. }, 0, 0, this);
  9121. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9122. if (!this.dynamicProperties.length) {
  9123. this.getValue();
  9124. }
  9125. }
  9126. TextSelectorPropFactory.prototype = {
  9127. getMult: function getMult(ind) {
  9128. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9129. this.getValue();
  9130. }
  9131. var x1 = 0;
  9132. var y1 = 0;
  9133. var x2 = 1;
  9134. var y2 = 1;
  9135. if (this.ne.v > 0) {
  9136. x1 = this.ne.v / 100.0;
  9137. } else {
  9138. y1 = -this.ne.v / 100.0;
  9139. }
  9140. if (this.xe.v > 0) {
  9141. x2 = 1.0 - this.xe.v / 100.0;
  9142. } else {
  9143. y2 = 1.0 + this.xe.v / 100.0;
  9144. }
  9145. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9146. var mult = 0;
  9147. var s = this.finalS;
  9148. var e = this.finalE;
  9149. var type = this.data.sh;
  9150. if (type === 2) {
  9151. if (e === s) {
  9152. mult = ind >= e ? 1 : 0;
  9153. } else {
  9154. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9155. }
  9156. mult = easer(mult);
  9157. } else if (type === 3) {
  9158. if (e === s) {
  9159. mult = ind >= e ? 0 : 1;
  9160. } else {
  9161. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9162. }
  9163. mult = easer(mult);
  9164. } else if (type === 4) {
  9165. if (e === s) {
  9166. mult = 0;
  9167. } else {
  9168. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9169. if (mult < 0.5) {
  9170. mult *= 2;
  9171. } else {
  9172. mult = 1 - 2 * (mult - 0.5);
  9173. }
  9174. }
  9175. mult = easer(mult);
  9176. } else if (type === 5) {
  9177. if (e === s) {
  9178. mult = 0;
  9179. } else {
  9180. var tot = e - s;
  9181. /* ind += 0.5;
  9182. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9183. ind = min(max(0, ind + 0.5 - s), e - s);
  9184. var x = -tot / 2 + ind;
  9185. var a = tot / 2;
  9186. mult = Math.sqrt(1 - x * x / (a * a));
  9187. }
  9188. mult = easer(mult);
  9189. } else if (type === 6) {
  9190. if (e === s) {
  9191. mult = 0;
  9192. } else {
  9193. ind = min(max(0, ind + 0.5 - s), e - s);
  9194. mult = (1 + Math.cos(Math.PI + Math.PI * 2 * ind / (e - s))) / 2; // eslint-disable-line
  9195. }
  9196. mult = easer(mult);
  9197. } else {
  9198. if (ind >= floor(s)) {
  9199. if (ind - s < 0) {
  9200. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9201. } else {
  9202. mult = max(0, min(e - ind, 1));
  9203. }
  9204. }
  9205. mult = easer(mult);
  9206. } // Smoothness implementation.
  9207. // The smoothness represents a reduced range of the original [0; 1] range.
  9208. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9209. // Steps are:
  9210. // - find the lower value of the new range (threshold)
  9211. // - if multiplier is smaller than that value, floor it to 0
  9212. // - if it is larger,
  9213. // - subtract the threshold
  9214. // - divide it by the smoothness (this will return the range to [0; 1])
  9215. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9216. if (this.sm.v !== 100) {
  9217. var smoothness = this.sm.v * 0.01;
  9218. if (smoothness === 0) {
  9219. smoothness = 0.00000001;
  9220. }
  9221. var threshold = 0.5 - smoothness * 0.5;
  9222. if (mult < threshold) {
  9223. mult = 0;
  9224. } else {
  9225. mult = (mult - threshold) / smoothness;
  9226. if (mult > 1) {
  9227. mult = 1;
  9228. }
  9229. }
  9230. }
  9231. return mult * this.a.v;
  9232. },
  9233. getValue: function getValue(newCharsFlag) {
  9234. this.iterateDynamicProperties();
  9235. this._mdf = newCharsFlag || this._mdf;
  9236. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9237. if (newCharsFlag && this.data.r === 2) {
  9238. this.e.v = this._currentTextLength;
  9239. }
  9240. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9241. var o = this.o.v / divisor;
  9242. var s = this.s.v / divisor + o;
  9243. var e = this.e.v / divisor + o;
  9244. if (s > e) {
  9245. var _s = s;
  9246. s = e;
  9247. e = _s;
  9248. }
  9249. this.finalS = s;
  9250. this.finalE = e;
  9251. }
  9252. };
  9253. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9254. function getTextSelectorProp(elem, data, arr) {
  9255. return new TextSelectorPropFactory(elem, data, arr);
  9256. }
  9257. return {
  9258. getTextSelectorProp: getTextSelectorProp
  9259. };
  9260. }();
  9261. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9262. var defaultData = {
  9263. propType: false
  9264. };
  9265. var getProp = PropertyFactory.getProp;
  9266. var textAnimatorAnimatables = animatorProps.a;
  9267. this.a = {
  9268. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9269. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9270. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9271. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9272. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9273. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9274. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9275. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9276. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9277. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9278. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9279. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9280. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9281. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9282. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9283. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData
  9284. };
  9285. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9286. this.s.t = animatorProps.s.t;
  9287. }
  9288. function TextAnimatorProperty(textData, renderType, elem) {
  9289. this._isFirstFrame = true;
  9290. this._hasMaskedPath = false;
  9291. this._frameId = -1;
  9292. this._textData = textData;
  9293. this._renderType = renderType;
  9294. this._elem = elem;
  9295. this._animatorsData = createSizedArray(this._textData.a.length);
  9296. this._pathData = {};
  9297. this._moreOptions = {
  9298. alignment: {}
  9299. };
  9300. this.renderedLetters = [];
  9301. this.lettersChangedFlag = false;
  9302. this.initDynamicPropertyContainer(elem);
  9303. }
  9304. TextAnimatorProperty.prototype.searchProperties = function () {
  9305. var i;
  9306. var len = this._textData.a.length;
  9307. var animatorProps;
  9308. var getProp = PropertyFactory.getProp;
  9309. for (i = 0; i < len; i += 1) {
  9310. animatorProps = this._textData.a[i];
  9311. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9312. }
  9313. if (this._textData.p && 'm' in this._textData.p) {
  9314. this._pathData = {
  9315. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9316. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9317. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9318. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9319. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9320. m: this._elem.maskManager.getMaskProperty(this._textData.p.m)
  9321. };
  9322. this._hasMaskedPath = true;
  9323. } else {
  9324. this._hasMaskedPath = false;
  9325. }
  9326. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9327. };
  9328. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9329. this.lettersChangedFlag = lettersChangedFlag;
  9330. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9331. return;
  9332. }
  9333. this._isFirstFrame = false;
  9334. var alignment = this._moreOptions.alignment.v;
  9335. var animators = this._animatorsData;
  9336. var textData = this._textData;
  9337. var matrixHelper = this.mHelper;
  9338. var renderType = this._renderType;
  9339. var renderedLettersCount = this.renderedLetters.length;
  9340. var xPos;
  9341. var yPos;
  9342. var i;
  9343. var len;
  9344. var letters = documentData.l;
  9345. var pathInfo;
  9346. var currentLength;
  9347. var currentPoint;
  9348. var segmentLength;
  9349. var flag;
  9350. var pointInd;
  9351. var segmentInd;
  9352. var prevPoint;
  9353. var points;
  9354. var segments;
  9355. var partialLength;
  9356. var totalLength;
  9357. var perc;
  9358. var tanAngle;
  9359. var mask;
  9360. if (this._hasMaskedPath) {
  9361. mask = this._pathData.m;
  9362. if (!this._pathData.n || this._pathData._mdf) {
  9363. var paths = mask.v;
  9364. if (this._pathData.r.v) {
  9365. paths = paths.reverse();
  9366. } // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9367. pathInfo = {
  9368. tLength: 0,
  9369. segments: []
  9370. };
  9371. len = paths._length - 1;
  9372. var bezierData;
  9373. totalLength = 0;
  9374. for (i = 0; i < len; i += 1) {
  9375. bezierData = bez.buildBezierData(paths.v[i], paths.v[i + 1], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9376. pathInfo.tLength += bezierData.segmentLength;
  9377. pathInfo.segments.push(bezierData);
  9378. totalLength += bezierData.segmentLength;
  9379. }
  9380. i = len;
  9381. if (mask.v.c) {
  9382. bezierData = bez.buildBezierData(paths.v[i], paths.v[0], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9383. pathInfo.tLength += bezierData.segmentLength;
  9384. pathInfo.segments.push(bezierData);
  9385. totalLength += bezierData.segmentLength;
  9386. }
  9387. this._pathData.pi = pathInfo;
  9388. }
  9389. pathInfo = this._pathData.pi;
  9390. currentLength = this._pathData.f.v;
  9391. segmentInd = 0;
  9392. pointInd = 1;
  9393. segmentLength = 0;
  9394. flag = true;
  9395. segments = pathInfo.segments;
  9396. if (currentLength < 0 && mask.v.c) {
  9397. if (pathInfo.tLength < Math.abs(currentLength)) {
  9398. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9399. }
  9400. segmentInd = segments.length - 1;
  9401. points = segments[segmentInd].points;
  9402. pointInd = points.length - 1;
  9403. while (currentLength < 0) {
  9404. currentLength += points[pointInd].partialLength;
  9405. pointInd -= 1;
  9406. if (pointInd < 0) {
  9407. segmentInd -= 1;
  9408. points = segments[segmentInd].points;
  9409. pointInd = points.length - 1;
  9410. }
  9411. }
  9412. }
  9413. points = segments[segmentInd].points;
  9414. prevPoint = points[pointInd - 1];
  9415. currentPoint = points[pointInd];
  9416. partialLength = currentPoint.partialLength;
  9417. }
  9418. len = letters.length;
  9419. xPos = 0;
  9420. yPos = 0;
  9421. var yOff = documentData.finalSize * 1.2 * 0.714;
  9422. var firstLine = true;
  9423. var animatorProps;
  9424. var animatorSelector;
  9425. var j;
  9426. var jLen;
  9427. var letterValue;
  9428. jLen = animators.length;
  9429. var mult;
  9430. var ind = -1;
  9431. var offf;
  9432. var xPathPos;
  9433. var yPathPos;
  9434. var initPathPos = currentLength;
  9435. var initSegmentInd = segmentInd;
  9436. var initPointInd = pointInd;
  9437. var currentLine = -1;
  9438. var elemOpacity;
  9439. var sc;
  9440. var sw;
  9441. var fc;
  9442. var k;
  9443. var letterSw;
  9444. var letterSc;
  9445. var letterFc;
  9446. var letterM = '';
  9447. var letterP = this.defaultPropsArray;
  9448. var letterO; //
  9449. if (documentData.j === 2 || documentData.j === 1) {
  9450. var animatorJustifyOffset = 0;
  9451. var animatorFirstCharOffset = 0;
  9452. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9453. var lastIndex = 0;
  9454. var isNewLine = true;
  9455. for (i = 0; i < len; i += 1) {
  9456. if (letters[i].n) {
  9457. if (animatorJustifyOffset) {
  9458. animatorJustifyOffset += animatorFirstCharOffset;
  9459. }
  9460. while (lastIndex < i) {
  9461. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9462. lastIndex += 1;
  9463. }
  9464. animatorJustifyOffset = 0;
  9465. isNewLine = true;
  9466. } else {
  9467. for (j = 0; j < jLen; j += 1) {
  9468. animatorProps = animators[j].a;
  9469. if (animatorProps.t.propType) {
  9470. if (isNewLine && documentData.j === 2) {
  9471. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9472. }
  9473. animatorSelector = animators[j].s;
  9474. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9475. if (mult.length) {
  9476. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9477. } else {
  9478. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9479. }
  9480. }
  9481. }
  9482. isNewLine = false;
  9483. }
  9484. }
  9485. if (animatorJustifyOffset) {
  9486. animatorJustifyOffset += animatorFirstCharOffset;
  9487. }
  9488. while (lastIndex < i) {
  9489. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9490. lastIndex += 1;
  9491. }
  9492. } //
  9493. for (i = 0; i < len; i += 1) {
  9494. matrixHelper.reset();
  9495. elemOpacity = 1;
  9496. if (letters[i].n) {
  9497. xPos = 0;
  9498. yPos += documentData.yOffset;
  9499. yPos += firstLine ? 1 : 0;
  9500. currentLength = initPathPos;
  9501. firstLine = false;
  9502. if (this._hasMaskedPath) {
  9503. segmentInd = initSegmentInd;
  9504. pointInd = initPointInd;
  9505. points = segments[segmentInd].points;
  9506. prevPoint = points[pointInd - 1];
  9507. currentPoint = points[pointInd];
  9508. partialLength = currentPoint.partialLength;
  9509. segmentLength = 0;
  9510. }
  9511. letterM = '';
  9512. letterFc = '';
  9513. letterSw = '';
  9514. letterO = '';
  9515. letterP = this.defaultPropsArray;
  9516. } else {
  9517. if (this._hasMaskedPath) {
  9518. if (currentLine !== letters[i].line) {
  9519. switch (documentData.j) {
  9520. case 1:
  9521. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9522. break;
  9523. case 2:
  9524. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9525. break;
  9526. default:
  9527. break;
  9528. }
  9529. currentLine = letters[i].line;
  9530. }
  9531. if (ind !== letters[i].ind) {
  9532. if (letters[ind]) {
  9533. currentLength += letters[ind].extra;
  9534. }
  9535. currentLength += letters[i].an / 2;
  9536. ind = letters[i].ind;
  9537. }
  9538. currentLength += alignment[0] * letters[i].an * 0.005;
  9539. var animatorOffset = 0;
  9540. for (j = 0; j < jLen; j += 1) {
  9541. animatorProps = animators[j].a;
  9542. if (animatorProps.p.propType) {
  9543. animatorSelector = animators[j].s;
  9544. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9545. if (mult.length) {
  9546. animatorOffset += animatorProps.p.v[0] * mult[0];
  9547. } else {
  9548. animatorOffset += animatorProps.p.v[0] * mult;
  9549. }
  9550. }
  9551. if (animatorProps.a.propType) {
  9552. animatorSelector = animators[j].s;
  9553. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9554. if (mult.length) {
  9555. animatorOffset += animatorProps.a.v[0] * mult[0];
  9556. } else {
  9557. animatorOffset += animatorProps.a.v[0] * mult;
  9558. }
  9559. }
  9560. }
  9561. flag = true; // Force alignment only works with a single line for now
  9562. if (this._pathData.a.v) {
  9563. 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);
  9564. currentLength += this._pathData.f.v;
  9565. }
  9566. while (flag) {
  9567. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9568. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9569. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9570. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9571. matrixHelper.translate(-alignment[0] * letters[i].an * 0.005, -(alignment[1] * yOff) * 0.01);
  9572. flag = false;
  9573. } else if (points) {
  9574. segmentLength += currentPoint.partialLength;
  9575. pointInd += 1;
  9576. if (pointInd >= points.length) {
  9577. pointInd = 0;
  9578. segmentInd += 1;
  9579. if (!segments[segmentInd]) {
  9580. if (mask.v.c) {
  9581. pointInd = 0;
  9582. segmentInd = 0;
  9583. points = segments[segmentInd].points;
  9584. } else {
  9585. segmentLength -= currentPoint.partialLength;
  9586. points = null;
  9587. }
  9588. } else {
  9589. points = segments[segmentInd].points;
  9590. }
  9591. }
  9592. if (points) {
  9593. prevPoint = currentPoint;
  9594. currentPoint = points[pointInd];
  9595. partialLength = currentPoint.partialLength;
  9596. }
  9597. }
  9598. }
  9599. offf = letters[i].an / 2 - letters[i].add;
  9600. matrixHelper.translate(-offf, 0, 0);
  9601. } else {
  9602. offf = letters[i].an / 2 - letters[i].add;
  9603. matrixHelper.translate(-offf, 0, 0); // Grouping alignment
  9604. matrixHelper.translate(-alignment[0] * letters[i].an * 0.005, -alignment[1] * yOff * 0.01, 0);
  9605. }
  9606. for (j = 0; j < jLen; j += 1) {
  9607. animatorProps = animators[j].a;
  9608. if (animatorProps.t.propType) {
  9609. animatorSelector = animators[j].s;
  9610. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9611. if (xPos !== 0 || documentData.j !== 0) {
  9612. if (this._hasMaskedPath) {
  9613. if (mult.length) {
  9614. currentLength += animatorProps.t.v * mult[0];
  9615. } else {
  9616. currentLength += animatorProps.t.v * mult;
  9617. }
  9618. } else if (mult.length) {
  9619. xPos += animatorProps.t.v * mult[0];
  9620. } else {
  9621. xPos += animatorProps.t.v * mult;
  9622. }
  9623. }
  9624. }
  9625. }
  9626. if (documentData.strokeWidthAnim) {
  9627. sw = documentData.sw || 0;
  9628. }
  9629. if (documentData.strokeColorAnim) {
  9630. if (documentData.sc) {
  9631. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  9632. } else {
  9633. sc = [0, 0, 0];
  9634. }
  9635. }
  9636. if (documentData.fillColorAnim && documentData.fc) {
  9637. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  9638. }
  9639. for (j = 0; j < jLen; j += 1) {
  9640. animatorProps = animators[j].a;
  9641. if (animatorProps.a.propType) {
  9642. animatorSelector = animators[j].s;
  9643. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9644. if (mult.length) {
  9645. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  9646. } else {
  9647. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  9648. }
  9649. }
  9650. }
  9651. for (j = 0; j < jLen; j += 1) {
  9652. animatorProps = animators[j].a;
  9653. if (animatorProps.s.propType) {
  9654. animatorSelector = animators[j].s;
  9655. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9656. if (mult.length) {
  9657. matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult[0], 1 + (animatorProps.s.v[1] - 1) * mult[1], 1);
  9658. } else {
  9659. matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult, 1 + (animatorProps.s.v[1] - 1) * mult, 1);
  9660. }
  9661. }
  9662. }
  9663. for (j = 0; j < jLen; j += 1) {
  9664. animatorProps = animators[j].a;
  9665. animatorSelector = animators[j].s;
  9666. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9667. if (animatorProps.sk.propType) {
  9668. if (mult.length) {
  9669. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  9670. } else {
  9671. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  9672. }
  9673. }
  9674. if (animatorProps.r.propType) {
  9675. if (mult.length) {
  9676. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  9677. } else {
  9678. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  9679. }
  9680. }
  9681. if (animatorProps.ry.propType) {
  9682. if (mult.length) {
  9683. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  9684. } else {
  9685. matrixHelper.rotateY(animatorProps.ry.v * mult);
  9686. }
  9687. }
  9688. if (animatorProps.rx.propType) {
  9689. if (mult.length) {
  9690. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  9691. } else {
  9692. matrixHelper.rotateX(animatorProps.rx.v * mult);
  9693. }
  9694. }
  9695. if (animatorProps.o.propType) {
  9696. if (mult.length) {
  9697. elemOpacity += (animatorProps.o.v * mult[0] - elemOpacity) * mult[0];
  9698. } else {
  9699. elemOpacity += (animatorProps.o.v * mult - elemOpacity) * mult;
  9700. }
  9701. }
  9702. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  9703. if (mult.length) {
  9704. sw += animatorProps.sw.v * mult[0];
  9705. } else {
  9706. sw += animatorProps.sw.v * mult;
  9707. }
  9708. }
  9709. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  9710. for (k = 0; k < 3; k += 1) {
  9711. if (mult.length) {
  9712. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  9713. } else {
  9714. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  9715. }
  9716. }
  9717. }
  9718. if (documentData.fillColorAnim && documentData.fc) {
  9719. if (animatorProps.fc.propType) {
  9720. for (k = 0; k < 3; k += 1) {
  9721. if (mult.length) {
  9722. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  9723. } else {
  9724. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  9725. }
  9726. }
  9727. }
  9728. if (animatorProps.fh.propType) {
  9729. if (mult.length) {
  9730. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  9731. } else {
  9732. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  9733. }
  9734. }
  9735. if (animatorProps.fs.propType) {
  9736. if (mult.length) {
  9737. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  9738. } else {
  9739. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  9740. }
  9741. }
  9742. if (animatorProps.fb.propType) {
  9743. if (mult.length) {
  9744. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  9745. } else {
  9746. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  9747. }
  9748. }
  9749. }
  9750. }
  9751. for (j = 0; j < jLen; j += 1) {
  9752. animatorProps = animators[j].a;
  9753. if (animatorProps.p.propType) {
  9754. animatorSelector = animators[j].s;
  9755. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9756. if (this._hasMaskedPath) {
  9757. if (mult.length) {
  9758. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  9759. } else {
  9760. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9761. }
  9762. } else if (mult.length) {
  9763. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  9764. } else {
  9765. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9766. }
  9767. }
  9768. }
  9769. if (documentData.strokeWidthAnim) {
  9770. letterSw = sw < 0 ? 0 : sw;
  9771. }
  9772. if (documentData.strokeColorAnim) {
  9773. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  9774. }
  9775. if (documentData.fillColorAnim && documentData.fc) {
  9776. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  9777. }
  9778. if (this._hasMaskedPath) {
  9779. matrixHelper.translate(0, -documentData.ls);
  9780. matrixHelper.translate(0, alignment[1] * yOff * 0.01 + yPos, 0);
  9781. if (this._pathData.p.v) {
  9782. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  9783. var rot = Math.atan(tanAngle) * 180 / Math.PI;
  9784. if (currentPoint.point[0] < prevPoint.point[0]) {
  9785. rot += 180;
  9786. }
  9787. matrixHelper.rotate(-rot * Math.PI / 180);
  9788. }
  9789. matrixHelper.translate(xPathPos, yPathPos, 0);
  9790. currentLength -= alignment[0] * letters[i].an * 0.005;
  9791. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  9792. currentLength += letters[i].an / 2;
  9793. currentLength += documentData.tr * 0.001 * documentData.finalSize;
  9794. }
  9795. } else {
  9796. matrixHelper.translate(xPos, yPos, 0);
  9797. if (documentData.ps) {
  9798. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  9799. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9800. }
  9801. switch (documentData.j) {
  9802. case 1:
  9803. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  9804. break;
  9805. case 2:
  9806. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  9807. break;
  9808. default:
  9809. break;
  9810. }
  9811. matrixHelper.translate(0, -documentData.ls);
  9812. matrixHelper.translate(offf, 0, 0);
  9813. matrixHelper.translate(alignment[0] * letters[i].an * 0.005, alignment[1] * yOff * 0.01, 0);
  9814. xPos += letters[i].l + documentData.tr * 0.001 * documentData.finalSize;
  9815. }
  9816. if (renderType === 'html') {
  9817. letterM = matrixHelper.toCSS();
  9818. } else if (renderType === 'svg') {
  9819. letterM = matrixHelper.to2dCSS();
  9820. } else {
  9821. 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]];
  9822. }
  9823. letterO = elemOpacity;
  9824. }
  9825. if (renderedLettersCount <= i) {
  9826. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  9827. this.renderedLetters.push(letterValue);
  9828. renderedLettersCount += 1;
  9829. this.lettersChangedFlag = true;
  9830. } else {
  9831. letterValue = this.renderedLetters[i];
  9832. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  9833. }
  9834. }
  9835. };
  9836. TextAnimatorProperty.prototype.getValue = function () {
  9837. if (this._elem.globalData.frameId === this._frameId) {
  9838. return;
  9839. }
  9840. this._frameId = this._elem.globalData.frameId;
  9841. this.iterateDynamicProperties();
  9842. };
  9843. TextAnimatorProperty.prototype.mHelper = new Matrix();
  9844. TextAnimatorProperty.prototype.defaultPropsArray = [];
  9845. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  9846. function ITextElement() {}
  9847. ITextElement.prototype.initElement = function (data, globalData, comp) {
  9848. this.lettersChangedFlag = true;
  9849. this.initFrame();
  9850. this.initBaseData(data, globalData, comp);
  9851. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  9852. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  9853. this.initTransform(data, globalData, comp);
  9854. this.initHierarchy();
  9855. this.initRenderable();
  9856. this.initRendererElement();
  9857. this.createContainerElements();
  9858. this.createRenderableComponents();
  9859. this.createContent();
  9860. this.hide();
  9861. this.textAnimator.searchProperties(this.dynamicProperties);
  9862. };
  9863. ITextElement.prototype.prepareFrame = function (num) {
  9864. this._mdf = false;
  9865. this.prepareRenderableFrame(num);
  9866. this.prepareProperties(num, this.isInRange);
  9867. };
  9868. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  9869. var j;
  9870. var jLen = shapes.length;
  9871. var pathNodes;
  9872. var shapeStr = '';
  9873. for (j = 0; j < jLen; j += 1) {
  9874. if (shapes[j].ty === 'sh') {
  9875. pathNodes = shapes[j].ks.k;
  9876. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  9877. }
  9878. }
  9879. return shapeStr;
  9880. };
  9881. ITextElement.prototype.updateDocumentData = function (newData, index) {
  9882. this.textProperty.updateDocumentData(newData, index);
  9883. };
  9884. ITextElement.prototype.canResizeFont = function (_canResize) {
  9885. this.textProperty.canResizeFont(_canResize);
  9886. };
  9887. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  9888. this.textProperty.setMinimumFontSize(_fontSize);
  9889. };
  9890. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  9891. if (documentData.ps) {
  9892. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9893. }
  9894. matrixHelper.translate(0, -documentData.ls, 0);
  9895. switch (documentData.j) {
  9896. case 1:
  9897. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  9898. break;
  9899. case 2:
  9900. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  9901. break;
  9902. default:
  9903. break;
  9904. }
  9905. matrixHelper.translate(xPos, yPos, 0);
  9906. };
  9907. ITextElement.prototype.buildColor = function (colorData) {
  9908. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  9909. };
  9910. ITextElement.prototype.emptyProp = new LetterProps();
  9911. ITextElement.prototype.destroy = function () {};
  9912. ITextElement.prototype.validateText = function () {
  9913. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  9914. this.buildNewText();
  9915. this.textProperty._isFirstFrame = false;
  9916. this.textProperty._mdf = false;
  9917. }
  9918. };
  9919. var emptyShapeData = {
  9920. shapes: []
  9921. };
  9922. function SVGTextLottieElement(data, globalData, comp) {
  9923. this.textSpans = [];
  9924. this.renderType = 'svg';
  9925. this.initElement(data, globalData, comp);
  9926. }
  9927. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  9928. SVGTextLottieElement.prototype.createContent = function () {
  9929. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  9930. this.textContainer = createNS('text');
  9931. }
  9932. };
  9933. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  9934. var i = 0;
  9935. var len = textArray.length;
  9936. var textContents = [];
  9937. var currentTextContent = '';
  9938. while (i < len) {
  9939. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  9940. textContents.push(currentTextContent);
  9941. currentTextContent = '';
  9942. } else {
  9943. currentTextContent += textArray[i];
  9944. }
  9945. i += 1;
  9946. }
  9947. textContents.push(currentTextContent);
  9948. return textContents;
  9949. };
  9950. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  9951. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  9952. // but since text internal content gets only rendered once and then it's never rerendered,
  9953. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  9954. // Avoiding cloning is preferred since cloning each character shape data is expensive
  9955. if (data.shapes && data.shapes.length) {
  9956. var shape = data.shapes[0];
  9957. if (shape.it) {
  9958. var shapeItem = shape.it[shape.it.length - 1];
  9959. if (shapeItem.s) {
  9960. shapeItem.s.k[0] = scale;
  9961. shapeItem.s.k[1] = scale;
  9962. }
  9963. }
  9964. }
  9965. return data;
  9966. };
  9967. SVGTextLottieElement.prototype.buildNewText = function () {
  9968. this.addDynamicProperty(this);
  9969. var i;
  9970. var len;
  9971. var documentData = this.textProperty.currentData;
  9972. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  9973. if (documentData.fc) {
  9974. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  9975. } else {
  9976. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  9977. }
  9978. if (documentData.sc) {
  9979. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  9980. this.layerElement.setAttribute('stroke-width', documentData.sw);
  9981. }
  9982. this.layerElement.setAttribute('font-size', documentData.finalSize);
  9983. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  9984. if (fontData.fClass) {
  9985. this.layerElement.setAttribute('class', fontData.fClass);
  9986. } else {
  9987. this.layerElement.setAttribute('font-family', fontData.fFamily);
  9988. var fWeight = documentData.fWeight;
  9989. var fStyle = documentData.fStyle;
  9990. this.layerElement.setAttribute('font-style', fStyle);
  9991. this.layerElement.setAttribute('font-weight', fWeight);
  9992. }
  9993. this.layerElement.setAttribute('aria-label', documentData.t);
  9994. var letters = documentData.l || [];
  9995. var usesGlyphs = !!this.globalData.fontManager.chars;
  9996. len = letters.length;
  9997. var tSpan;
  9998. var matrixHelper = this.mHelper;
  9999. var shapeStr = '';
  10000. var singleShape = this.data.singleShape;
  10001. var xPos = 0;
  10002. var yPos = 0;
  10003. var firstLine = true;
  10004. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10005. if (singleShape && !usesGlyphs && !documentData.sz) {
  10006. var tElement = this.textContainer;
  10007. var justify = 'start';
  10008. switch (documentData.j) {
  10009. case 1:
  10010. justify = 'end';
  10011. break;
  10012. case 2:
  10013. justify = 'middle';
  10014. break;
  10015. default:
  10016. justify = 'start';
  10017. break;
  10018. }
  10019. tElement.setAttribute('text-anchor', justify);
  10020. tElement.setAttribute('letter-spacing', trackingOffset);
  10021. var textContent = this.buildTextContents(documentData.finalText);
  10022. len = textContent.length;
  10023. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10024. for (i = 0; i < len; i += 1) {
  10025. tSpan = this.textSpans[i].span || createNS('tspan');
  10026. tSpan.textContent = textContent[i];
  10027. tSpan.setAttribute('x', 0);
  10028. tSpan.setAttribute('y', yPos);
  10029. tSpan.style.display = 'inherit';
  10030. tElement.appendChild(tSpan);
  10031. if (!this.textSpans[i]) {
  10032. this.textSpans[i] = {
  10033. span: null,
  10034. glyph: null
  10035. };
  10036. }
  10037. this.textSpans[i].span = tSpan;
  10038. yPos += documentData.finalLineHeight;
  10039. }
  10040. this.layerElement.appendChild(tElement);
  10041. } else {
  10042. var cachedSpansLength = this.textSpans.length;
  10043. var charData;
  10044. for (i = 0; i < len; i += 1) {
  10045. if (!this.textSpans[i]) {
  10046. this.textSpans[i] = {
  10047. span: null,
  10048. childSpan: null,
  10049. glyph: null
  10050. };
  10051. }
  10052. if (!usesGlyphs || !singleShape || i === 0) {
  10053. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10054. if (cachedSpansLength <= i) {
  10055. tSpan.setAttribute('stroke-linecap', 'butt');
  10056. tSpan.setAttribute('stroke-linejoin', 'round');
  10057. tSpan.setAttribute('stroke-miterlimit', '4');
  10058. this.textSpans[i].span = tSpan;
  10059. if (usesGlyphs) {
  10060. var childSpan = createNS('g');
  10061. tSpan.appendChild(childSpan);
  10062. this.textSpans[i].childSpan = childSpan;
  10063. }
  10064. this.textSpans[i].span = tSpan;
  10065. this.layerElement.appendChild(tSpan);
  10066. }
  10067. tSpan.style.display = 'inherit';
  10068. }
  10069. matrixHelper.reset();
  10070. if (singleShape) {
  10071. if (letters[i].n) {
  10072. xPos = -trackingOffset;
  10073. yPos += documentData.yOffset;
  10074. yPos += firstLine ? 1 : 0;
  10075. firstLine = false;
  10076. }
  10077. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10078. xPos += letters[i].l || 0; // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10079. xPos += trackingOffset;
  10080. }
  10081. if (usesGlyphs) {
  10082. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  10083. var glyphElement; // t === 1 means the character has been replaced with an animated shaped
  10084. if (charData.t === 1) {
  10085. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10086. } else {
  10087. var data = emptyShapeData;
  10088. if (charData.data && charData.data.shapes) {
  10089. data = this.buildShapeData(charData.data, documentData.finalSize);
  10090. }
  10091. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10092. }
  10093. if (this.textSpans[i].glyph) {
  10094. var glyph = this.textSpans[i].glyph;
  10095. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10096. glyph.destroy();
  10097. }
  10098. this.textSpans[i].glyph = glyphElement;
  10099. glyphElement._debug = true;
  10100. glyphElement.prepareFrame(0);
  10101. glyphElement.renderFrame();
  10102. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement); // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10103. // this might have issues with strokes and might need a different solution
  10104. if (charData.t === 1) {
  10105. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10106. }
  10107. } else {
  10108. if (singleShape) {
  10109. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10110. }
  10111. tSpan.textContent = letters[i].val;
  10112. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10113. } //
  10114. }
  10115. if (singleShape && tSpan) {
  10116. tSpan.setAttribute('d', shapeStr);
  10117. }
  10118. }
  10119. while (i < this.textSpans.length) {
  10120. this.textSpans[i].span.style.display = 'none';
  10121. i += 1;
  10122. }
  10123. this._sizeChanged = true;
  10124. };
  10125. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10126. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10127. this.renderInnerContent();
  10128. if (this._sizeChanged) {
  10129. this._sizeChanged = false;
  10130. var textBox = this.layerElement.getBBox();
  10131. this.bbox = {
  10132. top: textBox.y,
  10133. left: textBox.x,
  10134. width: textBox.width,
  10135. height: textBox.height
  10136. };
  10137. }
  10138. return this.bbox;
  10139. };
  10140. SVGTextLottieElement.prototype.getValue = function () {
  10141. var i;
  10142. var len = this.textSpans.length;
  10143. var glyphElement;
  10144. this.renderedFrame = this.comp.renderedFrame;
  10145. for (i = 0; i < len; i += 1) {
  10146. glyphElement = this.textSpans[i].glyph;
  10147. if (glyphElement) {
  10148. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10149. if (glyphElement._mdf) {
  10150. this._mdf = true;
  10151. }
  10152. }
  10153. }
  10154. };
  10155. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10156. this.validateText();
  10157. if (!this.data.singleShape || this._mdf) {
  10158. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10159. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10160. this._sizeChanged = true;
  10161. var i;
  10162. var len;
  10163. var renderedLetters = this.textAnimator.renderedLetters;
  10164. var letters = this.textProperty.currentData.l;
  10165. len = letters.length;
  10166. var renderedLetter;
  10167. var textSpan;
  10168. var glyphElement;
  10169. for (i = 0; i < len; i += 1) {
  10170. if (!letters[i].n) {
  10171. renderedLetter = renderedLetters[i];
  10172. textSpan = this.textSpans[i].span;
  10173. glyphElement = this.textSpans[i].glyph;
  10174. if (glyphElement) {
  10175. glyphElement.renderFrame();
  10176. }
  10177. if (renderedLetter._mdf.m) {
  10178. textSpan.setAttribute('transform', renderedLetter.m);
  10179. }
  10180. if (renderedLetter._mdf.o) {
  10181. textSpan.setAttribute('opacity', renderedLetter.o);
  10182. }
  10183. if (renderedLetter._mdf.sw) {
  10184. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10185. }
  10186. if (renderedLetter._mdf.sc) {
  10187. textSpan.setAttribute('stroke', renderedLetter.sc);
  10188. }
  10189. if (renderedLetter._mdf.fc) {
  10190. textSpan.setAttribute('fill', renderedLetter.fc);
  10191. }
  10192. }
  10193. }
  10194. }
  10195. }
  10196. };
  10197. function ISolidElement(data, globalData, comp) {
  10198. this.initElement(data, globalData, comp);
  10199. }
  10200. extendPrototype([IImageElement], ISolidElement);
  10201. ISolidElement.prototype.createContent = function () {
  10202. var rect = createNS('rect'); /// /rect.style.width = this.data.sw;
  10203. /// /rect.style.height = this.data.sh;
  10204. /// /rect.style.fill = this.data.sc;
  10205. rect.setAttribute('width', this.data.sw);
  10206. rect.setAttribute('height', this.data.sh);
  10207. rect.setAttribute('fill', this.data.sc);
  10208. this.layerElement.appendChild(rect);
  10209. };
  10210. function NullElement(data, globalData, comp) {
  10211. this.initFrame();
  10212. this.initBaseData(data, globalData, comp);
  10213. this.initFrame();
  10214. this.initTransform(data, globalData, comp);
  10215. this.initHierarchy();
  10216. }
  10217. NullElement.prototype.prepareFrame = function (num) {
  10218. this.prepareProperties(num, true);
  10219. };
  10220. NullElement.prototype.renderFrame = function () {};
  10221. NullElement.prototype.getBaseElement = function () {
  10222. return null;
  10223. };
  10224. NullElement.prototype.destroy = function () {};
  10225. NullElement.prototype.sourceRectAtTime = function () {};
  10226. NullElement.prototype.hide = function () {};
  10227. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10228. function SVGRendererBase() {}
  10229. extendPrototype([BaseRenderer], SVGRendererBase);
  10230. SVGRendererBase.prototype.createNull = function (data) {
  10231. return new NullElement(data, this.globalData, this);
  10232. };
  10233. SVGRendererBase.prototype.createShape = function (data) {
  10234. return new SVGShapeElement(data, this.globalData, this);
  10235. };
  10236. SVGRendererBase.prototype.createText = function (data) {
  10237. return new SVGTextLottieElement(data, this.globalData, this);
  10238. };
  10239. SVGRendererBase.prototype.createImage = function (data) {
  10240. return new IImageElement(data, this.globalData, this);
  10241. };
  10242. SVGRendererBase.prototype.createSolid = function (data) {
  10243. return new ISolidElement(data, this.globalData, this);
  10244. };
  10245. SVGRendererBase.prototype.configAnimation = function (animData) {
  10246. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10247. this.svgElement.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  10248. if (this.renderConfig.viewBoxSize) {
  10249. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10250. } else {
  10251. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10252. }
  10253. if (!this.renderConfig.viewBoxOnly) {
  10254. this.svgElement.setAttribute('width', animData.w);
  10255. this.svgElement.setAttribute('height', animData.h);
  10256. this.svgElement.style.width = '100%';
  10257. this.svgElement.style.height = '100%';
  10258. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10259. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10260. }
  10261. if (this.renderConfig.width) {
  10262. this.svgElement.setAttribute('width', this.renderConfig.width);
  10263. }
  10264. if (this.renderConfig.height) {
  10265. this.svgElement.setAttribute('height', this.renderConfig.height);
  10266. }
  10267. if (this.renderConfig.className) {
  10268. this.svgElement.setAttribute('class', this.renderConfig.className);
  10269. }
  10270. if (this.renderConfig.id) {
  10271. this.svgElement.setAttribute('id', this.renderConfig.id);
  10272. }
  10273. if (this.renderConfig.focusable !== undefined) {
  10274. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10275. }
  10276. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio); // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10277. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10278. this.animationItem.wrapper.appendChild(this.svgElement); // Mask animation
  10279. var defs = this.globalData.defs;
  10280. this.setupGlobalData(animData, defs);
  10281. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10282. this.data = animData;
  10283. var maskElement = createNS('clipPath');
  10284. var rect = createNS('rect');
  10285. rect.setAttribute('width', animData.w);
  10286. rect.setAttribute('height', animData.h);
  10287. rect.setAttribute('x', 0);
  10288. rect.setAttribute('y', 0);
  10289. var maskId = createElementID();
  10290. maskElement.setAttribute('id', maskId);
  10291. maskElement.appendChild(rect);
  10292. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10293. defs.appendChild(maskElement);
  10294. this.layers = animData.layers;
  10295. this.elements = createSizedArray(animData.layers.length);
  10296. };
  10297. SVGRendererBase.prototype.destroy = function () {
  10298. if (this.animationItem.wrapper) {
  10299. this.animationItem.wrapper.innerText = '';
  10300. }
  10301. this.layerElement = null;
  10302. this.globalData.defs = null;
  10303. var i;
  10304. var len = this.layers ? this.layers.length : 0;
  10305. for (i = 0; i < len; i += 1) {
  10306. if (this.elements[i] && this.elements[i].destroy) {
  10307. this.elements[i].destroy();
  10308. }
  10309. }
  10310. this.elements.length = 0;
  10311. this.destroyed = true;
  10312. this.animationItem = null;
  10313. };
  10314. SVGRendererBase.prototype.updateContainerSize = function () {};
  10315. SVGRendererBase.prototype.findIndexByInd = function (ind) {
  10316. var i = 0;
  10317. var len = this.layers.length;
  10318. for (i = 0; i < len; i += 1) {
  10319. if (this.layers[i].ind === ind) {
  10320. return i;
  10321. }
  10322. }
  10323. return -1;
  10324. };
  10325. SVGRendererBase.prototype.buildItem = function (pos) {
  10326. var elements = this.elements;
  10327. if (elements[pos] || this.layers[pos].ty === 99) {
  10328. return;
  10329. }
  10330. elements[pos] = true;
  10331. var element = this.createItem(this.layers[pos]);
  10332. elements[pos] = element;
  10333. if (getExpressionsPlugin()) {
  10334. if (this.layers[pos].ty === 0) {
  10335. this.globalData.projectInterface.registerComposition(element);
  10336. }
  10337. element.initExpressions();
  10338. }
  10339. this.appendElementInPos(element, pos);
  10340. if (this.layers[pos].tt) {
  10341. var elementIndex = 'tp' in this.layers[pos] ? this.findIndexByInd(this.layers[pos].tp) : pos - 1;
  10342. if (elementIndex === -1) {
  10343. return;
  10344. }
  10345. if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
  10346. this.buildItem(elementIndex);
  10347. this.addPendingElement(element);
  10348. } else {
  10349. var matteElement = elements[elementIndex];
  10350. var matteMask = matteElement.getMatte(this.layers[pos].tt);
  10351. element.setMatte(matteMask);
  10352. }
  10353. }
  10354. };
  10355. SVGRendererBase.prototype.checkPendingElements = function () {
  10356. while (this.pendingElements.length) {
  10357. var element = this.pendingElements.pop();
  10358. element.checkParenting();
  10359. if (element.data.tt) {
  10360. var i = 0;
  10361. var len = this.elements.length;
  10362. while (i < len) {
  10363. if (this.elements[i] === element) {
  10364. var elementIndex = 'tp' in element.data ? this.findIndexByInd(element.data.tp) : i - 1;
  10365. var matteElement = this.elements[elementIndex];
  10366. var matteMask = matteElement.getMatte(this.layers[i].tt);
  10367. element.setMatte(matteMask);
  10368. break;
  10369. }
  10370. i += 1;
  10371. }
  10372. }
  10373. }
  10374. };
  10375. SVGRendererBase.prototype.renderFrame = function (num) {
  10376. if (this.renderedFrame === num || this.destroyed) {
  10377. return;
  10378. }
  10379. if (num === null) {
  10380. num = this.renderedFrame;
  10381. } else {
  10382. this.renderedFrame = num;
  10383. } // console.log('-------');
  10384. // console.log('FRAME ',num);
  10385. this.globalData.frameNum = num;
  10386. this.globalData.frameId += 1;
  10387. this.globalData.projectInterface.currentFrame = num;
  10388. this.globalData._mdf = false;
  10389. var i;
  10390. var len = this.layers.length;
  10391. if (!this.completeLayers) {
  10392. this.checkLayers(num);
  10393. }
  10394. for (i = len - 1; i >= 0; i -= 1) {
  10395. if (this.completeLayers || this.elements[i]) {
  10396. this.elements[i].prepareFrame(num - this.layers[i].st);
  10397. }
  10398. }
  10399. if (this.globalData._mdf) {
  10400. for (i = 0; i < len; i += 1) {
  10401. if (this.completeLayers || this.elements[i]) {
  10402. this.elements[i].renderFrame();
  10403. }
  10404. }
  10405. }
  10406. };
  10407. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10408. var newElement = element.getBaseElement();
  10409. if (!newElement) {
  10410. return;
  10411. }
  10412. var i = 0;
  10413. var nextElement;
  10414. while (i < pos) {
  10415. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10416. nextElement = this.elements[i].getBaseElement();
  10417. }
  10418. i += 1;
  10419. }
  10420. if (nextElement) {
  10421. this.layerElement.insertBefore(newElement, nextElement);
  10422. } else {
  10423. this.layerElement.appendChild(newElement);
  10424. }
  10425. };
  10426. SVGRendererBase.prototype.hide = function () {
  10427. this.layerElement.style.display = 'none';
  10428. };
  10429. SVGRendererBase.prototype.show = function () {
  10430. this.layerElement.style.display = 'block';
  10431. };
  10432. function ICompElement() {}
  10433. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10434. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10435. this.initFrame();
  10436. this.initBaseData(data, globalData, comp);
  10437. this.initTransform(data, globalData, comp);
  10438. this.initRenderable();
  10439. this.initHierarchy();
  10440. this.initRendererElement();
  10441. this.createContainerElements();
  10442. this.createRenderableComponents();
  10443. if (this.data.xt || !globalData.progressiveLoad) {
  10444. this.buildAllItems();
  10445. }
  10446. this.hide();
  10447. };
  10448. /* ICompElement.prototype.hide = function(){
  10449. if(!this.hidden){
  10450. this.hideElement();
  10451. var i,len = this.elements.length;
  10452. for( i = 0; i < len; i+=1 ){
  10453. if(this.elements[i]){
  10454. this.elements[i].hide();
  10455. }
  10456. }
  10457. }
  10458. }; */
  10459. ICompElement.prototype.prepareFrame = function (num) {
  10460. this._mdf = false;
  10461. this.prepareRenderableFrame(num);
  10462. this.prepareProperties(num, this.isInRange);
  10463. if (!this.isInRange && !this.data.xt) {
  10464. return;
  10465. }
  10466. if (!this.tm._placeholder) {
  10467. var timeRemapped = this.tm.v;
  10468. if (timeRemapped === this.data.op) {
  10469. timeRemapped = this.data.op - 1;
  10470. }
  10471. this.renderedFrame = timeRemapped;
  10472. } else {
  10473. this.renderedFrame = num / this.data.sr;
  10474. }
  10475. var i;
  10476. var len = this.elements.length;
  10477. if (!this.completeLayers) {
  10478. this.checkLayers(this.renderedFrame);
  10479. } // This iteration needs to be backwards because of how expressions connect between each other
  10480. for (i = len - 1; i >= 0; i -= 1) {
  10481. if (this.completeLayers || this.elements[i]) {
  10482. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10483. if (this.elements[i]._mdf) {
  10484. this._mdf = true;
  10485. }
  10486. }
  10487. }
  10488. };
  10489. ICompElement.prototype.renderInnerContent = function () {
  10490. var i;
  10491. var len = this.layers.length;
  10492. for (i = 0; i < len; i += 1) {
  10493. if (this.completeLayers || this.elements[i]) {
  10494. this.elements[i].renderFrame();
  10495. }
  10496. }
  10497. };
  10498. ICompElement.prototype.setElements = function (elems) {
  10499. this.elements = elems;
  10500. };
  10501. ICompElement.prototype.getElements = function () {
  10502. return this.elements;
  10503. };
  10504. ICompElement.prototype.destroyElements = function () {
  10505. var i;
  10506. var len = this.layers.length;
  10507. for (i = 0; i < len; i += 1) {
  10508. if (this.elements[i]) {
  10509. this.elements[i].destroy();
  10510. }
  10511. }
  10512. };
  10513. ICompElement.prototype.destroy = function () {
  10514. this.destroyElements();
  10515. this.destroyBaseElement();
  10516. };
  10517. function SVGCompElement(data, globalData, comp) {
  10518. this.layers = data.layers;
  10519. this.supports3d = true;
  10520. this.completeLayers = false;
  10521. this.pendingElements = [];
  10522. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10523. this.initElement(data, globalData, comp);
  10524. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  10525. _placeholder: true
  10526. };
  10527. }
  10528. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10529. SVGCompElement.prototype.createComp = function (data) {
  10530. return new SVGCompElement(data, this.globalData, this);
  10531. };
  10532. function SVGRenderer(animationItem, config) {
  10533. this.animationItem = animationItem;
  10534. this.layers = null;
  10535. this.renderedFrame = -1;
  10536. this.svgElement = createNS('svg');
  10537. var ariaLabel = '';
  10538. if (config && config.title) {
  10539. var titleElement = createNS('title');
  10540. var titleId = createElementID();
  10541. titleElement.setAttribute('id', titleId);
  10542. titleElement.textContent = config.title;
  10543. this.svgElement.appendChild(titleElement);
  10544. ariaLabel += titleId;
  10545. }
  10546. if (config && config.description) {
  10547. var descElement = createNS('desc');
  10548. var descId = createElementID();
  10549. descElement.setAttribute('id', descId);
  10550. descElement.textContent = config.description;
  10551. this.svgElement.appendChild(descElement);
  10552. ariaLabel += ' ' + descId;
  10553. }
  10554. if (ariaLabel) {
  10555. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10556. }
  10557. var defs = createNS('defs');
  10558. this.svgElement.appendChild(defs);
  10559. var maskElement = createNS('g');
  10560. this.svgElement.appendChild(maskElement);
  10561. this.layerElement = maskElement;
  10562. this.renderConfig = {
  10563. preserveAspectRatio: config && config.preserveAspectRatio || 'xMidYMid meet',
  10564. imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || 'xMidYMid slice',
  10565. contentVisibility: config && config.contentVisibility || 'visible',
  10566. progressiveLoad: config && config.progressiveLoad || false,
  10567. hideOnTransparent: !(config && config.hideOnTransparent === false),
  10568. viewBoxOnly: config && config.viewBoxOnly || false,
  10569. viewBoxSize: config && config.viewBoxSize || false,
  10570. className: config && config.className || '',
  10571. id: config && config.id || '',
  10572. focusable: config && config.focusable,
  10573. filterSize: {
  10574. width: config && config.filterSize && config.filterSize.width || '100%',
  10575. height: config && config.filterSize && config.filterSize.height || '100%',
  10576. x: config && config.filterSize && config.filterSize.x || '0%',
  10577. y: config && config.filterSize && config.filterSize.y || '0%'
  10578. },
  10579. width: config && config.width,
  10580. height: config && config.height,
  10581. runExpressions: !config || config.runExpressions === undefined || config.runExpressions
  10582. };
  10583. this.globalData = {
  10584. _mdf: false,
  10585. frameNum: -1,
  10586. defs: defs,
  10587. renderConfig: this.renderConfig
  10588. };
  10589. this.elements = [];
  10590. this.pendingElements = [];
  10591. this.destroyed = false;
  10592. this.rendererType = 'svg';
  10593. }
  10594. extendPrototype([SVGRendererBase], SVGRenderer);
  10595. SVGRenderer.prototype.createComp = function (data) {
  10596. return new SVGCompElement(data, this.globalData, this);
  10597. };
  10598. var registeredEffects = {};
  10599. function CVEffects(elem) {
  10600. var i;
  10601. var len = elem.data.ef ? elem.data.ef.length : 0;
  10602. this.filters = [];
  10603. var filterManager;
  10604. for (i = 0; i < len; i += 1) {
  10605. filterManager = null;
  10606. var type = elem.data.ef[i].ty;
  10607. if (registeredEffects[type]) {
  10608. var Effect = registeredEffects[type].effect;
  10609. filterManager = new Effect(elem.effectsManager.effectElements[i], elem);
  10610. }
  10611. if (filterManager) {
  10612. this.filters.push(filterManager);
  10613. }
  10614. }
  10615. if (this.filters.length) {
  10616. elem.addRenderableComponent(this);
  10617. }
  10618. }
  10619. CVEffects.prototype.renderFrame = function (_isFirstFrame) {
  10620. var i;
  10621. var len = this.filters.length;
  10622. for (i = 0; i < len; i += 1) {
  10623. this.filters[i].renderFrame(_isFirstFrame);
  10624. }
  10625. };
  10626. CVEffects.prototype.getEffects = function (type) {
  10627. var i;
  10628. var len = this.filters.length;
  10629. var effects = [];
  10630. for (i = 0; i < len; i += 1) {
  10631. if (this.filters[i].type === type) {
  10632. effects.push(this.filters[i]);
  10633. }
  10634. }
  10635. return effects;
  10636. };
  10637. function registerEffect(id, effect) {
  10638. registeredEffects[id] = {
  10639. effect: effect
  10640. };
  10641. }
  10642. function HBaseElement() {}
  10643. HBaseElement.prototype = {
  10644. checkBlendMode: function checkBlendMode() {},
  10645. initRendererElement: function initRendererElement() {
  10646. this.baseElement = createTag(this.data.tg || 'div');
  10647. if (this.data.hasMask) {
  10648. this.svgElement = createNS('svg');
  10649. this.layerElement = createNS('g');
  10650. this.maskedElement = this.layerElement;
  10651. this.svgElement.appendChild(this.layerElement);
  10652. this.baseElement.appendChild(this.svgElement);
  10653. } else {
  10654. this.layerElement = this.baseElement;
  10655. }
  10656. styleDiv(this.baseElement);
  10657. },
  10658. createContainerElements: function createContainerElements() {
  10659. this.renderableEffectsManager = new CVEffects(this);
  10660. this.transformedElement = this.baseElement;
  10661. this.maskedElement = this.layerElement;
  10662. if (this.data.ln) {
  10663. this.layerElement.setAttribute('id', this.data.ln);
  10664. }
  10665. if (this.data.cl) {
  10666. this.layerElement.setAttribute('class', this.data.cl);
  10667. }
  10668. if (this.data.bm !== 0) {
  10669. this.setBlendMode();
  10670. }
  10671. },
  10672. renderElement: function renderElement() {
  10673. var transformedElementStyle = this.transformedElement ? this.transformedElement.style : {};
  10674. if (this.finalTransform._matMdf) {
  10675. var matrixValue = this.finalTransform.mat.toCSS();
  10676. transformedElementStyle.transform = matrixValue;
  10677. transformedElementStyle.webkitTransform = matrixValue;
  10678. }
  10679. if (this.finalTransform._opMdf) {
  10680. transformedElementStyle.opacity = this.finalTransform.mProp.o.v;
  10681. }
  10682. },
  10683. renderFrame: function renderFrame() {
  10684. // If it is exported as hidden (data.hd === true) no need to render
  10685. // If it is not visible no need to render
  10686. if (this.data.hd || this.hidden) {
  10687. return;
  10688. }
  10689. this.renderTransform();
  10690. this.renderRenderable();
  10691. this.renderElement();
  10692. this.renderInnerContent();
  10693. if (this._isFirstFrame) {
  10694. this._isFirstFrame = false;
  10695. }
  10696. },
  10697. destroy: function destroy() {
  10698. this.layerElement = null;
  10699. this.transformedElement = null;
  10700. if (this.matteElement) {
  10701. this.matteElement = null;
  10702. }
  10703. if (this.maskManager) {
  10704. this.maskManager.destroy();
  10705. this.maskManager = null;
  10706. }
  10707. },
  10708. createRenderableComponents: function createRenderableComponents() {
  10709. this.maskManager = new MaskElement(this.data, this, this.globalData);
  10710. },
  10711. addEffects: function addEffects() {},
  10712. setMatte: function setMatte() {}
  10713. };
  10714. HBaseElement.prototype.getBaseElement = SVGBaseElement.prototype.getBaseElement;
  10715. HBaseElement.prototype.destroyBaseElement = HBaseElement.prototype.destroy;
  10716. HBaseElement.prototype.buildElementParenting = BaseRenderer.prototype.buildElementParenting;
  10717. function HSolidElement(data, globalData, comp) {
  10718. this.initElement(data, globalData, comp);
  10719. }
  10720. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], HSolidElement);
  10721. HSolidElement.prototype.createContent = function () {
  10722. var rect;
  10723. if (this.data.hasMask) {
  10724. rect = createNS('rect');
  10725. rect.setAttribute('width', this.data.sw);
  10726. rect.setAttribute('height', this.data.sh);
  10727. rect.setAttribute('fill', this.data.sc);
  10728. this.svgElement.setAttribute('width', this.data.sw);
  10729. this.svgElement.setAttribute('height', this.data.sh);
  10730. } else {
  10731. rect = createTag('div');
  10732. rect.style.width = this.data.sw + 'px';
  10733. rect.style.height = this.data.sh + 'px';
  10734. rect.style.backgroundColor = this.data.sc;
  10735. }
  10736. this.layerElement.appendChild(rect);
  10737. };
  10738. function HShapeElement(data, globalData, comp) {
  10739. // List of drawable elements
  10740. this.shapes = []; // Full shape data
  10741. this.shapesData = data.shapes; // List of styles that will be applied to shapes
  10742. this.stylesList = []; // List of modifiers that will be applied to shapes
  10743. this.shapeModifiers = []; // List of items in shape tree
  10744. this.itemsData = []; // List of items in previous shape tree
  10745. this.processedElements = []; // List of animated components
  10746. this.animatedContents = [];
  10747. this.shapesContainer = createNS('g');
  10748. this.initElement(data, globalData, comp); // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  10749. // List of elements that have been created
  10750. this.prevViewData = [];
  10751. this.currentBBox = {
  10752. x: 999999,
  10753. y: -999999,
  10754. h: 0,
  10755. w: 0
  10756. };
  10757. }
  10758. extendPrototype([BaseElement, TransformElement, HSolidElement, SVGShapeElement, HBaseElement, HierarchyElement, FrameElement, RenderableElement], HShapeElement);
  10759. HShapeElement.prototype._renderShapeFrame = HShapeElement.prototype.renderInnerContent;
  10760. HShapeElement.prototype.createContent = function () {
  10761. var cont;
  10762. this.baseElement.style.fontSize = 0;
  10763. if (this.data.hasMask) {
  10764. this.layerElement.appendChild(this.shapesContainer);
  10765. cont = this.svgElement;
  10766. } else {
  10767. cont = createNS('svg');
  10768. var size = this.comp.data ? this.comp.data : this.globalData.compSize;
  10769. cont.setAttribute('width', size.w);
  10770. cont.setAttribute('height', size.h);
  10771. cont.appendChild(this.shapesContainer);
  10772. this.layerElement.appendChild(cont);
  10773. }
  10774. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.shapesContainer, 0, [], true);
  10775. this.filterUniqueShapes();
  10776. this.shapeCont = cont;
  10777. };
  10778. HShapeElement.prototype.getTransformedPoint = function (transformers, point) {
  10779. var i;
  10780. var len = transformers.length;
  10781. for (i = 0; i < len; i += 1) {
  10782. point = transformers[i].mProps.v.applyToPointArray(point[0], point[1], 0);
  10783. }
  10784. return point;
  10785. };
  10786. HShapeElement.prototype.calculateShapeBoundingBox = function (item, boundingBox) {
  10787. var shape = item.sh.v;
  10788. var transformers = item.transformers;
  10789. var i;
  10790. var len = shape._length;
  10791. var vPoint;
  10792. var oPoint;
  10793. var nextIPoint;
  10794. var nextVPoint;
  10795. if (len <= 1) {
  10796. return;
  10797. }
  10798. for (i = 0; i < len - 1; i += 1) {
  10799. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  10800. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  10801. nextIPoint = this.getTransformedPoint(transformers, shape.i[i + 1]);
  10802. nextVPoint = this.getTransformedPoint(transformers, shape.v[i + 1]);
  10803. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  10804. }
  10805. if (shape.c) {
  10806. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  10807. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  10808. nextIPoint = this.getTransformedPoint(transformers, shape.i[0]);
  10809. nextVPoint = this.getTransformedPoint(transformers, shape.v[0]);
  10810. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  10811. }
  10812. };
  10813. HShapeElement.prototype.checkBounds = function (vPoint, oPoint, nextIPoint, nextVPoint, boundingBox) {
  10814. this.getBoundsOfCurve(vPoint, oPoint, nextIPoint, nextVPoint);
  10815. var bounds = this.shapeBoundingBox;
  10816. boundingBox.x = bmMin(bounds.left, boundingBox.x);
  10817. boundingBox.xMax = bmMax(bounds.right, boundingBox.xMax);
  10818. boundingBox.y = bmMin(bounds.top, boundingBox.y);
  10819. boundingBox.yMax = bmMax(bounds.bottom, boundingBox.yMax);
  10820. };
  10821. HShapeElement.prototype.shapeBoundingBox = {
  10822. left: 0,
  10823. right: 0,
  10824. top: 0,
  10825. bottom: 0
  10826. };
  10827. HShapeElement.prototype.tempBoundingBox = {
  10828. x: 0,
  10829. xMax: 0,
  10830. y: 0,
  10831. yMax: 0,
  10832. width: 0,
  10833. height: 0
  10834. };
  10835. HShapeElement.prototype.getBoundsOfCurve = function (p0, p1, p2, p3) {
  10836. var bounds = [[p0[0], p3[0]], [p0[1], p3[1]]];
  10837. for (var a, b, c, t, b2ac, t1, t2, i = 0; i < 2; ++i) {
  10838. // eslint-disable-line no-plusplus
  10839. b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
  10840. a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
  10841. c = 3 * p1[i] - 3 * p0[i];
  10842. b |= 0; // eslint-disable-line no-bitwise
  10843. a |= 0; // eslint-disable-line no-bitwise
  10844. c |= 0; // eslint-disable-line no-bitwise
  10845. if (a === 0 && b === 0) {//
  10846. } else if (a === 0) {
  10847. t = -c / b;
  10848. if (t > 0 && t < 1) {
  10849. bounds[i].push(this.calculateF(t, p0, p1, p2, p3, i));
  10850. }
  10851. } else {
  10852. b2ac = b * b - 4 * c * a;
  10853. if (b2ac >= 0) {
  10854. t1 = (-b + bmSqrt(b2ac)) / (2 * a);
  10855. if (t1 > 0 && t1 < 1) bounds[i].push(this.calculateF(t1, p0, p1, p2, p3, i));
  10856. t2 = (-b - bmSqrt(b2ac)) / (2 * a);
  10857. if (t2 > 0 && t2 < 1) bounds[i].push(this.calculateF(t2, p0, p1, p2, p3, i));
  10858. }
  10859. }
  10860. }
  10861. this.shapeBoundingBox.left = bmMin.apply(null, bounds[0]);
  10862. this.shapeBoundingBox.top = bmMin.apply(null, bounds[1]);
  10863. this.shapeBoundingBox.right = bmMax.apply(null, bounds[0]);
  10864. this.shapeBoundingBox.bottom = bmMax.apply(null, bounds[1]);
  10865. };
  10866. HShapeElement.prototype.calculateF = function (t, p0, p1, p2, p3, i) {
  10867. return bmPow(1 - t, 3) * p0[i] + 3 * bmPow(1 - t, 2) * t * p1[i] + 3 * (1 - t) * bmPow(t, 2) * p2[i] + bmPow(t, 3) * p3[i];
  10868. };
  10869. HShapeElement.prototype.calculateBoundingBox = function (itemsData, boundingBox) {
  10870. var i;
  10871. var len = itemsData.length;
  10872. for (i = 0; i < len; i += 1) {
  10873. if (itemsData[i] && itemsData[i].sh) {
  10874. this.calculateShapeBoundingBox(itemsData[i], boundingBox);
  10875. } else if (itemsData[i] && itemsData[i].it) {
  10876. this.calculateBoundingBox(itemsData[i].it, boundingBox);
  10877. } else if (itemsData[i] && itemsData[i].style && itemsData[i].w) {
  10878. this.expandStrokeBoundingBox(itemsData[i].w, boundingBox);
  10879. }
  10880. }
  10881. };
  10882. HShapeElement.prototype.expandStrokeBoundingBox = function (widthProperty, boundingBox) {
  10883. var width = 0;
  10884. if (widthProperty.keyframes) {
  10885. for (var i = 0; i < widthProperty.keyframes.length; i += 1) {
  10886. var kfw = widthProperty.keyframes[i].s;
  10887. if (kfw > width) {
  10888. width = kfw;
  10889. }
  10890. }
  10891. width *= widthProperty.mult;
  10892. } else {
  10893. width = widthProperty.v * widthProperty.mult;
  10894. }
  10895. boundingBox.x -= width;
  10896. boundingBox.xMax += width;
  10897. boundingBox.y -= width;
  10898. boundingBox.yMax += width;
  10899. };
  10900. HShapeElement.prototype.currentBoxContains = function (box) {
  10901. return this.currentBBox.x <= box.x && this.currentBBox.y <= box.y && this.currentBBox.width + this.currentBBox.x >= box.x + box.width && this.currentBBox.height + this.currentBBox.y >= box.y + box.height;
  10902. };
  10903. HShapeElement.prototype.renderInnerContent = function () {
  10904. this._renderShapeFrame();
  10905. if (!this.hidden && (this._isFirstFrame || this._mdf)) {
  10906. var tempBoundingBox = this.tempBoundingBox;
  10907. var max = 999999;
  10908. tempBoundingBox.x = max;
  10909. tempBoundingBox.xMax = -max;
  10910. tempBoundingBox.y = max;
  10911. tempBoundingBox.yMax = -max;
  10912. this.calculateBoundingBox(this.itemsData, tempBoundingBox);
  10913. tempBoundingBox.width = tempBoundingBox.xMax < tempBoundingBox.x ? 0 : tempBoundingBox.xMax - tempBoundingBox.x;
  10914. tempBoundingBox.height = tempBoundingBox.yMax < tempBoundingBox.y ? 0 : tempBoundingBox.yMax - tempBoundingBox.y; // var tempBoundingBox = this.shapeCont.getBBox();
  10915. if (this.currentBoxContains(tempBoundingBox)) {
  10916. return;
  10917. }
  10918. var changed = false;
  10919. if (this.currentBBox.w !== tempBoundingBox.width) {
  10920. this.currentBBox.w = tempBoundingBox.width;
  10921. this.shapeCont.setAttribute('width', tempBoundingBox.width);
  10922. changed = true;
  10923. }
  10924. if (this.currentBBox.h !== tempBoundingBox.height) {
  10925. this.currentBBox.h = tempBoundingBox.height;
  10926. this.shapeCont.setAttribute('height', tempBoundingBox.height);
  10927. changed = true;
  10928. }
  10929. if (changed || this.currentBBox.x !== tempBoundingBox.x || this.currentBBox.y !== tempBoundingBox.y) {
  10930. this.currentBBox.w = tempBoundingBox.width;
  10931. this.currentBBox.h = tempBoundingBox.height;
  10932. this.currentBBox.x = tempBoundingBox.x;
  10933. this.currentBBox.y = tempBoundingBox.y;
  10934. this.shapeCont.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  10935. var shapeStyle = this.shapeCont.style;
  10936. var shapeTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  10937. shapeStyle.transform = shapeTransform;
  10938. shapeStyle.webkitTransform = shapeTransform;
  10939. }
  10940. }
  10941. };
  10942. function HTextElement(data, globalData, comp) {
  10943. this.textSpans = [];
  10944. this.textPaths = [];
  10945. this.currentBBox = {
  10946. x: 999999,
  10947. y: -999999,
  10948. h: 0,
  10949. w: 0
  10950. };
  10951. this.renderType = 'svg';
  10952. this.isMasked = false;
  10953. this.initElement(data, globalData, comp);
  10954. }
  10955. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], HTextElement);
  10956. HTextElement.prototype.createContent = function () {
  10957. this.isMasked = this.checkMasks();
  10958. if (this.isMasked) {
  10959. this.renderType = 'svg';
  10960. this.compW = this.comp.data.w;
  10961. this.compH = this.comp.data.h;
  10962. this.svgElement.setAttribute('width', this.compW);
  10963. this.svgElement.setAttribute('height', this.compH);
  10964. var g = createNS('g');
  10965. this.maskedElement.appendChild(g);
  10966. this.innerElem = g;
  10967. } else {
  10968. this.renderType = 'html';
  10969. this.innerElem = this.layerElement;
  10970. }
  10971. this.checkParenting();
  10972. };
  10973. HTextElement.prototype.buildNewText = function () {
  10974. var documentData = this.textProperty.currentData;
  10975. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  10976. var innerElemStyle = this.innerElem.style;
  10977. var textColor = documentData.fc ? this.buildColor(documentData.fc) : 'rgba(0,0,0,0)';
  10978. innerElemStyle.fill = textColor;
  10979. innerElemStyle.color = textColor;
  10980. if (documentData.sc) {
  10981. innerElemStyle.stroke = this.buildColor(documentData.sc);
  10982. innerElemStyle.strokeWidth = documentData.sw + 'px';
  10983. }
  10984. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10985. if (!this.globalData.fontManager.chars) {
  10986. innerElemStyle.fontSize = documentData.finalSize + 'px';
  10987. innerElemStyle.lineHeight = documentData.finalSize + 'px';
  10988. if (fontData.fClass) {
  10989. this.innerElem.className = fontData.fClass;
  10990. } else {
  10991. innerElemStyle.fontFamily = fontData.fFamily;
  10992. var fWeight = documentData.fWeight;
  10993. var fStyle = documentData.fStyle;
  10994. innerElemStyle.fontStyle = fStyle;
  10995. innerElemStyle.fontWeight = fWeight;
  10996. }
  10997. }
  10998. var i;
  10999. var len;
  11000. var letters = documentData.l;
  11001. len = letters.length;
  11002. var tSpan;
  11003. var tParent;
  11004. var tCont;
  11005. var matrixHelper = this.mHelper;
  11006. var shapes;
  11007. var shapeStr = '';
  11008. var cnt = 0;
  11009. for (i = 0; i < len; i += 1) {
  11010. if (this.globalData.fontManager.chars) {
  11011. if (!this.textPaths[cnt]) {
  11012. tSpan = createNS('path');
  11013. tSpan.setAttribute('stroke-linecap', lineCapEnum[1]);
  11014. tSpan.setAttribute('stroke-linejoin', lineJoinEnum[2]);
  11015. tSpan.setAttribute('stroke-miterlimit', '4');
  11016. } else {
  11017. tSpan = this.textPaths[cnt];
  11018. }
  11019. if (!this.isMasked) {
  11020. if (this.textSpans[cnt]) {
  11021. tParent = this.textSpans[cnt];
  11022. tCont = tParent.children[0];
  11023. } else {
  11024. tParent = createTag('div');
  11025. tParent.style.lineHeight = 0;
  11026. tCont = createNS('svg');
  11027. tCont.appendChild(tSpan);
  11028. styleDiv(tParent);
  11029. }
  11030. }
  11031. } else if (!this.isMasked) {
  11032. if (this.textSpans[cnt]) {
  11033. tParent = this.textSpans[cnt];
  11034. tSpan = this.textPaths[cnt];
  11035. } else {
  11036. tParent = createTag('span');
  11037. styleDiv(tParent);
  11038. tSpan = createTag('span');
  11039. styleDiv(tSpan);
  11040. tParent.appendChild(tSpan);
  11041. }
  11042. } else {
  11043. tSpan = this.textPaths[cnt] ? this.textPaths[cnt] : createNS('text');
  11044. } // tSpan.setAttribute('visibility', 'hidden');
  11045. if (this.globalData.fontManager.chars) {
  11046. var charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  11047. var shapeData;
  11048. if (charData) {
  11049. shapeData = charData.data;
  11050. } else {
  11051. shapeData = null;
  11052. }
  11053. matrixHelper.reset();
  11054. if (shapeData && shapeData.shapes && shapeData.shapes.length) {
  11055. shapes = shapeData.shapes[0].it;
  11056. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  11057. shapeStr = this.createPathShape(matrixHelper, shapes);
  11058. tSpan.setAttribute('d', shapeStr);
  11059. }
  11060. if (!this.isMasked) {
  11061. this.innerElem.appendChild(tParent);
  11062. if (shapeData && shapeData.shapes) {
  11063. // document.body.appendChild is needed to get exact measure of shape
  11064. document.body.appendChild(tCont);
  11065. var boundingBox = tCont.getBBox();
  11066. tCont.setAttribute('width', boundingBox.width + 2);
  11067. tCont.setAttribute('height', boundingBox.height + 2);
  11068. tCont.setAttribute('viewBox', boundingBox.x - 1 + ' ' + (boundingBox.y - 1) + ' ' + (boundingBox.width + 2) + ' ' + (boundingBox.height + 2));
  11069. var tContStyle = tCont.style;
  11070. var tContTranslation = 'translate(' + (boundingBox.x - 1) + 'px,' + (boundingBox.y - 1) + 'px)';
  11071. tContStyle.transform = tContTranslation;
  11072. tContStyle.webkitTransform = tContTranslation;
  11073. letters[i].yOffset = boundingBox.y - 1;
  11074. } else {
  11075. tCont.setAttribute('width', 1);
  11076. tCont.setAttribute('height', 1);
  11077. }
  11078. tParent.appendChild(tCont);
  11079. } else {
  11080. this.innerElem.appendChild(tSpan);
  11081. }
  11082. } else {
  11083. tSpan.textContent = letters[i].val;
  11084. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  11085. if (!this.isMasked) {
  11086. this.innerElem.appendChild(tParent); //
  11087. var tStyle = tSpan.style;
  11088. var tSpanTranslation = 'translate3d(0,' + -documentData.finalSize / 1.2 + 'px,0)';
  11089. tStyle.transform = tSpanTranslation;
  11090. tStyle.webkitTransform = tSpanTranslation;
  11091. } else {
  11092. this.innerElem.appendChild(tSpan);
  11093. }
  11094. } //
  11095. if (!this.isMasked) {
  11096. this.textSpans[cnt] = tParent;
  11097. } else {
  11098. this.textSpans[cnt] = tSpan;
  11099. }
  11100. this.textSpans[cnt].style.display = 'block';
  11101. this.textPaths[cnt] = tSpan;
  11102. cnt += 1;
  11103. }
  11104. while (cnt < this.textSpans.length) {
  11105. this.textSpans[cnt].style.display = 'none';
  11106. cnt += 1;
  11107. }
  11108. };
  11109. HTextElement.prototype.renderInnerContent = function () {
  11110. this.validateText();
  11111. var svgStyle;
  11112. if (this.data.singleShape) {
  11113. if (!this._isFirstFrame && !this.lettersChangedFlag) {
  11114. return;
  11115. }
  11116. if (this.isMasked && this.finalTransform._matMdf) {
  11117. // Todo Benchmark if using this is better than getBBox
  11118. this.svgElement.setAttribute('viewBox', -this.finalTransform.mProp.p.v[0] + ' ' + -this.finalTransform.mProp.p.v[1] + ' ' + this.compW + ' ' + this.compH);
  11119. svgStyle = this.svgElement.style;
  11120. var translation = 'translate(' + -this.finalTransform.mProp.p.v[0] + 'px,' + -this.finalTransform.mProp.p.v[1] + 'px)';
  11121. svgStyle.transform = translation;
  11122. svgStyle.webkitTransform = translation;
  11123. }
  11124. }
  11125. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  11126. if (!this.lettersChangedFlag && !this.textAnimator.lettersChangedFlag) {
  11127. return;
  11128. }
  11129. var i;
  11130. var len;
  11131. var count = 0;
  11132. var renderedLetters = this.textAnimator.renderedLetters;
  11133. var letters = this.textProperty.currentData.l;
  11134. len = letters.length;
  11135. var renderedLetter;
  11136. var textSpan;
  11137. var textPath;
  11138. for (i = 0; i < len; i += 1) {
  11139. if (letters[i].n) {
  11140. count += 1;
  11141. } else {
  11142. textSpan = this.textSpans[i];
  11143. textPath = this.textPaths[i];
  11144. renderedLetter = renderedLetters[count];
  11145. count += 1;
  11146. if (renderedLetter._mdf.m) {
  11147. if (!this.isMasked) {
  11148. textSpan.style.webkitTransform = renderedLetter.m;
  11149. textSpan.style.transform = renderedLetter.m;
  11150. } else {
  11151. textSpan.setAttribute('transform', renderedLetter.m);
  11152. }
  11153. } /// /textSpan.setAttribute('opacity',renderedLetter.o);
  11154. textSpan.style.opacity = renderedLetter.o;
  11155. if (renderedLetter.sw && renderedLetter._mdf.sw) {
  11156. textPath.setAttribute('stroke-width', renderedLetter.sw);
  11157. }
  11158. if (renderedLetter.sc && renderedLetter._mdf.sc) {
  11159. textPath.setAttribute('stroke', renderedLetter.sc);
  11160. }
  11161. if (renderedLetter.fc && renderedLetter._mdf.fc) {
  11162. textPath.setAttribute('fill', renderedLetter.fc);
  11163. textPath.style.color = renderedLetter.fc;
  11164. }
  11165. }
  11166. }
  11167. if (this.innerElem.getBBox && !this.hidden && (this._isFirstFrame || this._mdf)) {
  11168. var boundingBox = this.innerElem.getBBox();
  11169. if (this.currentBBox.w !== boundingBox.width) {
  11170. this.currentBBox.w = boundingBox.width;
  11171. this.svgElement.setAttribute('width', boundingBox.width);
  11172. }
  11173. if (this.currentBBox.h !== boundingBox.height) {
  11174. this.currentBBox.h = boundingBox.height;
  11175. this.svgElement.setAttribute('height', boundingBox.height);
  11176. }
  11177. var margin = 1;
  11178. 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) {
  11179. this.currentBBox.w = boundingBox.width + margin * 2;
  11180. this.currentBBox.h = boundingBox.height + margin * 2;
  11181. this.currentBBox.x = boundingBox.x - margin;
  11182. this.currentBBox.y = boundingBox.y - margin;
  11183. this.svgElement.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  11184. svgStyle = this.svgElement.style;
  11185. var svgTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  11186. svgStyle.transform = svgTransform;
  11187. svgStyle.webkitTransform = svgTransform;
  11188. }
  11189. }
  11190. };
  11191. function HCameraElement(data, globalData, comp) {
  11192. this.initFrame();
  11193. this.initBaseData(data, globalData, comp);
  11194. this.initHierarchy();
  11195. var getProp = PropertyFactory.getProp;
  11196. this.pe = getProp(this, data.pe, 0, 0, this);
  11197. if (data.ks.p.s) {
  11198. this.px = getProp(this, data.ks.p.x, 1, 0, this);
  11199. this.py = getProp(this, data.ks.p.y, 1, 0, this);
  11200. this.pz = getProp(this, data.ks.p.z, 1, 0, this);
  11201. } else {
  11202. this.p = getProp(this, data.ks.p, 1, 0, this);
  11203. }
  11204. if (data.ks.a) {
  11205. this.a = getProp(this, data.ks.a, 1, 0, this);
  11206. }
  11207. if (data.ks.or.k.length && data.ks.or.k[0].to) {
  11208. var i;
  11209. var len = data.ks.or.k.length;
  11210. for (i = 0; i < len; i += 1) {
  11211. data.ks.or.k[i].to = null;
  11212. data.ks.or.k[i].ti = null;
  11213. }
  11214. }
  11215. this.or = getProp(this, data.ks.or, 1, degToRads, this);
  11216. this.or.sh = true;
  11217. this.rx = getProp(this, data.ks.rx, 0, degToRads, this);
  11218. this.ry = getProp(this, data.ks.ry, 0, degToRads, this);
  11219. this.rz = getProp(this, data.ks.rz, 0, degToRads, this);
  11220. this.mat = new Matrix();
  11221. this._prevMat = new Matrix();
  11222. this._isFirstFrame = true; // TODO: find a better way to make the HCamera element to be compatible with the LayerInterface and TransformInterface.
  11223. this.finalTransform = {
  11224. mProp: this
  11225. };
  11226. }
  11227. extendPrototype([BaseElement, FrameElement, HierarchyElement], HCameraElement);
  11228. HCameraElement.prototype.setup = function () {
  11229. var i;
  11230. var len = this.comp.threeDElements.length;
  11231. var comp;
  11232. var perspectiveStyle;
  11233. var containerStyle;
  11234. for (i = 0; i < len; i += 1) {
  11235. // [perspectiveElem,container]
  11236. comp = this.comp.threeDElements[i];
  11237. if (comp.type === '3d') {
  11238. perspectiveStyle = comp.perspectiveElem.style;
  11239. containerStyle = comp.container.style;
  11240. var perspective = this.pe.v + 'px';
  11241. var origin = '0px 0px 0px';
  11242. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  11243. perspectiveStyle.perspective = perspective;
  11244. perspectiveStyle.webkitPerspective = perspective;
  11245. containerStyle.transformOrigin = origin;
  11246. containerStyle.mozTransformOrigin = origin;
  11247. containerStyle.webkitTransformOrigin = origin;
  11248. perspectiveStyle.transform = matrix;
  11249. perspectiveStyle.webkitTransform = matrix;
  11250. }
  11251. }
  11252. };
  11253. HCameraElement.prototype.createElements = function () {};
  11254. HCameraElement.prototype.hide = function () {};
  11255. HCameraElement.prototype.renderFrame = function () {
  11256. var _mdf = this._isFirstFrame;
  11257. var i;
  11258. var len;
  11259. if (this.hierarchy) {
  11260. len = this.hierarchy.length;
  11261. for (i = 0; i < len; i += 1) {
  11262. _mdf = this.hierarchy[i].finalTransform.mProp._mdf || _mdf;
  11263. }
  11264. }
  11265. 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) {
  11266. this.mat.reset();
  11267. if (this.hierarchy) {
  11268. len = this.hierarchy.length - 1;
  11269. for (i = len; i >= 0; i -= 1) {
  11270. var mTransf = this.hierarchy[i].finalTransform.mProp;
  11271. this.mat.translate(-mTransf.p.v[0], -mTransf.p.v[1], mTransf.p.v[2]);
  11272. this.mat.rotateX(-mTransf.or.v[0]).rotateY(-mTransf.or.v[1]).rotateZ(mTransf.or.v[2]);
  11273. this.mat.rotateX(-mTransf.rx.v).rotateY(-mTransf.ry.v).rotateZ(mTransf.rz.v);
  11274. this.mat.scale(1 / mTransf.s.v[0], 1 / mTransf.s.v[1], 1 / mTransf.s.v[2]);
  11275. this.mat.translate(mTransf.a.v[0], mTransf.a.v[1], mTransf.a.v[2]);
  11276. }
  11277. }
  11278. if (this.p) {
  11279. this.mat.translate(-this.p.v[0], -this.p.v[1], this.p.v[2]);
  11280. } else {
  11281. this.mat.translate(-this.px.v, -this.py.v, this.pz.v);
  11282. }
  11283. if (this.a) {
  11284. var diffVector;
  11285. if (this.p) {
  11286. 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]];
  11287. } else {
  11288. diffVector = [this.px.v - this.a.v[0], this.py.v - this.a.v[1], this.pz.v - this.a.v[2]];
  11289. }
  11290. var mag = Math.sqrt(Math.pow(diffVector[0], 2) + Math.pow(diffVector[1], 2) + Math.pow(diffVector[2], 2)); // var lookDir = getNormalizedPoint(getDiffVector(this.a.v,this.p.v));
  11291. var lookDir = [diffVector[0] / mag, diffVector[1] / mag, diffVector[2] / mag];
  11292. var lookLengthOnXZ = Math.sqrt(lookDir[2] * lookDir[2] + lookDir[0] * lookDir[0]);
  11293. var mRotationX = Math.atan2(lookDir[1], lookLengthOnXZ);
  11294. var mRotationY = Math.atan2(lookDir[0], -lookDir[2]);
  11295. this.mat.rotateY(mRotationY).rotateX(-mRotationX);
  11296. }
  11297. this.mat.rotateX(-this.rx.v).rotateY(-this.ry.v).rotateZ(this.rz.v);
  11298. this.mat.rotateX(-this.or.v[0]).rotateY(-this.or.v[1]).rotateZ(this.or.v[2]);
  11299. this.mat.translate(this.globalData.compSize.w / 2, this.globalData.compSize.h / 2, 0);
  11300. this.mat.translate(0, 0, this.pe.v);
  11301. var hasMatrixChanged = !this._prevMat.equals(this.mat);
  11302. if ((hasMatrixChanged || this.pe._mdf) && this.comp.threeDElements) {
  11303. len = this.comp.threeDElements.length;
  11304. var comp;
  11305. var perspectiveStyle;
  11306. var containerStyle;
  11307. for (i = 0; i < len; i += 1) {
  11308. comp = this.comp.threeDElements[i];
  11309. if (comp.type === '3d') {
  11310. if (hasMatrixChanged) {
  11311. var matValue = this.mat.toCSS();
  11312. containerStyle = comp.container.style;
  11313. containerStyle.transform = matValue;
  11314. containerStyle.webkitTransform = matValue;
  11315. }
  11316. if (this.pe._mdf) {
  11317. perspectiveStyle = comp.perspectiveElem.style;
  11318. perspectiveStyle.perspective = this.pe.v + 'px';
  11319. perspectiveStyle.webkitPerspective = this.pe.v + 'px';
  11320. }
  11321. }
  11322. }
  11323. this.mat.clone(this._prevMat);
  11324. }
  11325. }
  11326. this._isFirstFrame = false;
  11327. };
  11328. HCameraElement.prototype.prepareFrame = function (num) {
  11329. this.prepareProperties(num, true);
  11330. };
  11331. HCameraElement.prototype.destroy = function () {};
  11332. HCameraElement.prototype.getBaseElement = function () {
  11333. return null;
  11334. };
  11335. function HImageElement(data, globalData, comp) {
  11336. this.assetData = globalData.getAssetData(data.refId);
  11337. this.initElement(data, globalData, comp);
  11338. }
  11339. extendPrototype([BaseElement, TransformElement, HBaseElement, HSolidElement, HierarchyElement, FrameElement, RenderableElement], HImageElement);
  11340. HImageElement.prototype.createContent = function () {
  11341. var assetPath = this.globalData.getAssetsPath(this.assetData);
  11342. var img = new Image();
  11343. if (this.data.hasMask) {
  11344. this.imageElem = createNS('image');
  11345. this.imageElem.setAttribute('width', this.assetData.w + 'px');
  11346. this.imageElem.setAttribute('height', this.assetData.h + 'px');
  11347. this.imageElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  11348. this.layerElement.appendChild(this.imageElem);
  11349. this.baseElement.setAttribute('width', this.assetData.w);
  11350. this.baseElement.setAttribute('height', this.assetData.h);
  11351. } else {
  11352. this.layerElement.appendChild(img);
  11353. }
  11354. img.crossOrigin = 'anonymous';
  11355. img.src = assetPath;
  11356. if (this.data.ln) {
  11357. this.baseElement.setAttribute('id', this.data.ln);
  11358. }
  11359. };
  11360. function HybridRendererBase(animationItem, config) {
  11361. this.animationItem = animationItem;
  11362. this.layers = null;
  11363. this.renderedFrame = -1;
  11364. this.renderConfig = {
  11365. className: config && config.className || '',
  11366. imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || 'xMidYMid slice',
  11367. hideOnTransparent: !(config && config.hideOnTransparent === false),
  11368. filterSize: {
  11369. width: config && config.filterSize && config.filterSize.width || '400%',
  11370. height: config && config.filterSize && config.filterSize.height || '400%',
  11371. x: config && config.filterSize && config.filterSize.x || '-100%',
  11372. y: config && config.filterSize && config.filterSize.y || '-100%'
  11373. }
  11374. };
  11375. this.globalData = {
  11376. _mdf: false,
  11377. frameNum: -1,
  11378. renderConfig: this.renderConfig
  11379. };
  11380. this.pendingElements = [];
  11381. this.elements = [];
  11382. this.threeDElements = [];
  11383. this.destroyed = false;
  11384. this.camera = null;
  11385. this.supports3d = true;
  11386. this.rendererType = 'html';
  11387. }
  11388. extendPrototype([BaseRenderer], HybridRendererBase);
  11389. HybridRendererBase.prototype.buildItem = SVGRenderer.prototype.buildItem;
  11390. HybridRendererBase.prototype.checkPendingElements = function () {
  11391. while (this.pendingElements.length) {
  11392. var element = this.pendingElements.pop();
  11393. element.checkParenting();
  11394. }
  11395. };
  11396. HybridRendererBase.prototype.appendElementInPos = function (element, pos) {
  11397. var newDOMElement = element.getBaseElement();
  11398. if (!newDOMElement) {
  11399. return;
  11400. }
  11401. var layer = this.layers[pos];
  11402. if (!layer.ddd || !this.supports3d) {
  11403. if (this.threeDElements) {
  11404. this.addTo3dContainer(newDOMElement, pos);
  11405. } else {
  11406. var i = 0;
  11407. var nextDOMElement;
  11408. var nextLayer;
  11409. var tmpDOMElement;
  11410. while (i < pos) {
  11411. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement) {
  11412. nextLayer = this.elements[i];
  11413. tmpDOMElement = this.layers[i].ddd ? this.getThreeDContainerByPos(i) : nextLayer.getBaseElement();
  11414. nextDOMElement = tmpDOMElement || nextDOMElement;
  11415. }
  11416. i += 1;
  11417. }
  11418. if (nextDOMElement) {
  11419. if (!layer.ddd || !this.supports3d) {
  11420. this.layerElement.insertBefore(newDOMElement, nextDOMElement);
  11421. }
  11422. } else if (!layer.ddd || !this.supports3d) {
  11423. this.layerElement.appendChild(newDOMElement);
  11424. }
  11425. }
  11426. } else {
  11427. this.addTo3dContainer(newDOMElement, pos);
  11428. }
  11429. };
  11430. HybridRendererBase.prototype.createShape = function (data) {
  11431. if (!this.supports3d) {
  11432. return new SVGShapeElement(data, this.globalData, this);
  11433. }
  11434. return new HShapeElement(data, this.globalData, this);
  11435. };
  11436. HybridRendererBase.prototype.createText = function (data) {
  11437. if (!this.supports3d) {
  11438. return new SVGTextLottieElement(data, this.globalData, this);
  11439. }
  11440. return new HTextElement(data, this.globalData, this);
  11441. };
  11442. HybridRendererBase.prototype.createCamera = function (data) {
  11443. this.camera = new HCameraElement(data, this.globalData, this);
  11444. return this.camera;
  11445. };
  11446. HybridRendererBase.prototype.createImage = function (data) {
  11447. if (!this.supports3d) {
  11448. return new IImageElement(data, this.globalData, this);
  11449. }
  11450. return new HImageElement(data, this.globalData, this);
  11451. };
  11452. HybridRendererBase.prototype.createSolid = function (data) {
  11453. if (!this.supports3d) {
  11454. return new ISolidElement(data, this.globalData, this);
  11455. }
  11456. return new HSolidElement(data, this.globalData, this);
  11457. };
  11458. HybridRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  11459. HybridRendererBase.prototype.getThreeDContainerByPos = function (pos) {
  11460. var i = 0;
  11461. var len = this.threeDElements.length;
  11462. while (i < len) {
  11463. if (this.threeDElements[i].startPos <= pos && this.threeDElements[i].endPos >= pos) {
  11464. return this.threeDElements[i].perspectiveElem;
  11465. }
  11466. i += 1;
  11467. }
  11468. return null;
  11469. };
  11470. HybridRendererBase.prototype.createThreeDContainer = function (pos, type) {
  11471. var perspectiveElem = createTag('div');
  11472. var style;
  11473. var containerStyle;
  11474. styleDiv(perspectiveElem);
  11475. var container = createTag('div');
  11476. styleDiv(container);
  11477. if (type === '3d') {
  11478. style = perspectiveElem.style;
  11479. style.width = this.globalData.compSize.w + 'px';
  11480. style.height = this.globalData.compSize.h + 'px';
  11481. var center = '50% 50%';
  11482. style.webkitTransformOrigin = center;
  11483. style.mozTransformOrigin = center;
  11484. style.transformOrigin = center;
  11485. containerStyle = container.style;
  11486. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  11487. containerStyle.transform = matrix;
  11488. containerStyle.webkitTransform = matrix;
  11489. }
  11490. perspectiveElem.appendChild(container); // this.resizerElem.appendChild(perspectiveElem);
  11491. var threeDContainerData = {
  11492. container: container,
  11493. perspectiveElem: perspectiveElem,
  11494. startPos: pos,
  11495. endPos: pos,
  11496. type: type
  11497. };
  11498. this.threeDElements.push(threeDContainerData);
  11499. return threeDContainerData;
  11500. };
  11501. HybridRendererBase.prototype.build3dContainers = function () {
  11502. var i;
  11503. var len = this.layers.length;
  11504. var lastThreeDContainerData;
  11505. var currentContainer = '';
  11506. for (i = 0; i < len; i += 1) {
  11507. if (this.layers[i].ddd && this.layers[i].ty !== 3) {
  11508. if (currentContainer !== '3d') {
  11509. currentContainer = '3d';
  11510. lastThreeDContainerData = this.createThreeDContainer(i, '3d');
  11511. }
  11512. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  11513. } else {
  11514. if (currentContainer !== '2d') {
  11515. currentContainer = '2d';
  11516. lastThreeDContainerData = this.createThreeDContainer(i, '2d');
  11517. }
  11518. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  11519. }
  11520. }
  11521. len = this.threeDElements.length;
  11522. for (i = len - 1; i >= 0; i -= 1) {
  11523. this.resizerElem.appendChild(this.threeDElements[i].perspectiveElem);
  11524. }
  11525. };
  11526. HybridRendererBase.prototype.addTo3dContainer = function (elem, pos) {
  11527. var i = 0;
  11528. var len = this.threeDElements.length;
  11529. while (i < len) {
  11530. if (pos <= this.threeDElements[i].endPos) {
  11531. var j = this.threeDElements[i].startPos;
  11532. var nextElement;
  11533. while (j < pos) {
  11534. if (this.elements[j] && this.elements[j].getBaseElement) {
  11535. nextElement = this.elements[j].getBaseElement();
  11536. }
  11537. j += 1;
  11538. }
  11539. if (nextElement) {
  11540. this.threeDElements[i].container.insertBefore(elem, nextElement);
  11541. } else {
  11542. this.threeDElements[i].container.appendChild(elem);
  11543. }
  11544. break;
  11545. }
  11546. i += 1;
  11547. }
  11548. };
  11549. HybridRendererBase.prototype.configAnimation = function (animData) {
  11550. var resizerElem = createTag('div');
  11551. var wrapper = this.animationItem.wrapper;
  11552. var style = resizerElem.style;
  11553. style.width = animData.w + 'px';
  11554. style.height = animData.h + 'px';
  11555. this.resizerElem = resizerElem;
  11556. styleDiv(resizerElem);
  11557. style.transformStyle = 'flat';
  11558. style.mozTransformStyle = 'flat';
  11559. style.webkitTransformStyle = 'flat';
  11560. if (this.renderConfig.className) {
  11561. resizerElem.setAttribute('class', this.renderConfig.className);
  11562. }
  11563. wrapper.appendChild(resizerElem);
  11564. style.overflow = 'hidden';
  11565. var svg = createNS('svg');
  11566. svg.setAttribute('width', '1');
  11567. svg.setAttribute('height', '1');
  11568. styleDiv(svg);
  11569. this.resizerElem.appendChild(svg);
  11570. var defs = createNS('defs');
  11571. svg.appendChild(defs);
  11572. this.data = animData; // Mask animation
  11573. this.setupGlobalData(animData, svg);
  11574. this.globalData.defs = defs;
  11575. this.layers = animData.layers;
  11576. this.layerElement = this.resizerElem;
  11577. this.build3dContainers();
  11578. this.updateContainerSize();
  11579. };
  11580. HybridRendererBase.prototype.destroy = function () {
  11581. if (this.animationItem.wrapper) {
  11582. this.animationItem.wrapper.innerText = '';
  11583. }
  11584. this.animationItem.container = null;
  11585. this.globalData.defs = null;
  11586. var i;
  11587. var len = this.layers ? this.layers.length : 0;
  11588. for (i = 0; i < len; i += 1) {
  11589. if (this.elements[i] && this.elements[i].destroy) {
  11590. this.elements[i].destroy();
  11591. }
  11592. }
  11593. this.elements.length = 0;
  11594. this.destroyed = true;
  11595. this.animationItem = null;
  11596. };
  11597. HybridRendererBase.prototype.updateContainerSize = function () {
  11598. var elementWidth = this.animationItem.wrapper.offsetWidth;
  11599. var elementHeight = this.animationItem.wrapper.offsetHeight;
  11600. var elementRel = elementWidth / elementHeight;
  11601. var animationRel = this.globalData.compSize.w / this.globalData.compSize.h;
  11602. var sx;
  11603. var sy;
  11604. var tx;
  11605. var ty;
  11606. if (animationRel > elementRel) {
  11607. sx = elementWidth / this.globalData.compSize.w;
  11608. sy = elementWidth / this.globalData.compSize.w;
  11609. tx = 0;
  11610. ty = (elementHeight - this.globalData.compSize.h * (elementWidth / this.globalData.compSize.w)) / 2;
  11611. } else {
  11612. sx = elementHeight / this.globalData.compSize.h;
  11613. sy = elementHeight / this.globalData.compSize.h;
  11614. tx = (elementWidth - this.globalData.compSize.w * (elementHeight / this.globalData.compSize.h)) / 2;
  11615. ty = 0;
  11616. }
  11617. var style = this.resizerElem.style;
  11618. style.webkitTransform = 'matrix3d(' + sx + ',0,0,0,0,' + sy + ',0,0,0,0,1,0,' + tx + ',' + ty + ',0,1)';
  11619. style.transform = style.webkitTransform;
  11620. };
  11621. HybridRendererBase.prototype.renderFrame = SVGRenderer.prototype.renderFrame;
  11622. HybridRendererBase.prototype.hide = function () {
  11623. this.resizerElem.style.display = 'none';
  11624. };
  11625. HybridRendererBase.prototype.show = function () {
  11626. this.resizerElem.style.display = 'block';
  11627. };
  11628. HybridRendererBase.prototype.initItems = function () {
  11629. this.buildAllItems();
  11630. if (this.camera) {
  11631. this.camera.setup();
  11632. } else {
  11633. var cWidth = this.globalData.compSize.w;
  11634. var cHeight = this.globalData.compSize.h;
  11635. var i;
  11636. var len = this.threeDElements.length;
  11637. for (i = 0; i < len; i += 1) {
  11638. var style = this.threeDElements[i].perspectiveElem.style;
  11639. style.webkitPerspective = Math.sqrt(Math.pow(cWidth, 2) + Math.pow(cHeight, 2)) + 'px';
  11640. style.perspective = style.webkitPerspective;
  11641. }
  11642. }
  11643. };
  11644. HybridRendererBase.prototype.searchExtraCompositions = function (assets) {
  11645. var i;
  11646. var len = assets.length;
  11647. var floatingContainer = createTag('div');
  11648. for (i = 0; i < len; i += 1) {
  11649. if (assets[i].xt) {
  11650. var comp = this.createComp(assets[i], floatingContainer, this.globalData.comp, null);
  11651. comp.initExpressions();
  11652. this.globalData.projectInterface.registerComposition(comp);
  11653. }
  11654. }
  11655. };
  11656. function HCompElement(data, globalData, comp) {
  11657. this.layers = data.layers;
  11658. this.supports3d = !data.hasMask;
  11659. this.completeLayers = false;
  11660. this.pendingElements = [];
  11661. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  11662. this.initElement(data, globalData, comp);
  11663. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  11664. _placeholder: true
  11665. };
  11666. }
  11667. extendPrototype([HybridRendererBase, ICompElement, HBaseElement], HCompElement);
  11668. HCompElement.prototype._createBaseContainerElements = HCompElement.prototype.createContainerElements;
  11669. HCompElement.prototype.createContainerElements = function () {
  11670. this._createBaseContainerElements(); // divElement.style.clip = 'rect(0px, '+this.data.w+'px, '+this.data.h+'px, 0px)';
  11671. if (this.data.hasMask) {
  11672. this.svgElement.setAttribute('width', this.data.w);
  11673. this.svgElement.setAttribute('height', this.data.h);
  11674. this.transformedElement = this.baseElement;
  11675. } else {
  11676. this.transformedElement = this.layerElement;
  11677. }
  11678. };
  11679. HCompElement.prototype.addTo3dContainer = function (elem, pos) {
  11680. var j = 0;
  11681. var nextElement;
  11682. while (j < pos) {
  11683. if (this.elements[j] && this.elements[j].getBaseElement) {
  11684. nextElement = this.elements[j].getBaseElement();
  11685. }
  11686. j += 1;
  11687. }
  11688. if (nextElement) {
  11689. this.layerElement.insertBefore(elem, nextElement);
  11690. } else {
  11691. this.layerElement.appendChild(elem);
  11692. }
  11693. };
  11694. HCompElement.prototype.createComp = function (data) {
  11695. if (!this.supports3d) {
  11696. return new SVGCompElement(data, this.globalData, this);
  11697. }
  11698. return new HCompElement(data, this.globalData, this);
  11699. };
  11700. function HybridRenderer(animationItem, config) {
  11701. this.animationItem = animationItem;
  11702. this.layers = null;
  11703. this.renderedFrame = -1;
  11704. this.renderConfig = {
  11705. className: config && config.className || '',
  11706. imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || 'xMidYMid slice',
  11707. hideOnTransparent: !(config && config.hideOnTransparent === false),
  11708. filterSize: {
  11709. width: config && config.filterSize && config.filterSize.width || '400%',
  11710. height: config && config.filterSize && config.filterSize.height || '400%',
  11711. x: config && config.filterSize && config.filterSize.x || '-100%',
  11712. y: config && config.filterSize && config.filterSize.y || '-100%'
  11713. },
  11714. runExpressions: !config || config.runExpressions === undefined || config.runExpressions
  11715. };
  11716. this.globalData = {
  11717. _mdf: false,
  11718. frameNum: -1,
  11719. renderConfig: this.renderConfig
  11720. };
  11721. this.pendingElements = [];
  11722. this.elements = [];
  11723. this.threeDElements = [];
  11724. this.destroyed = false;
  11725. this.camera = null;
  11726. this.supports3d = true;
  11727. this.rendererType = 'html';
  11728. }
  11729. extendPrototype([HybridRendererBase], HybridRenderer);
  11730. HybridRenderer.prototype.createComp = function (data) {
  11731. if (!this.supports3d) {
  11732. return new SVGCompElement(data, this.globalData, this);
  11733. }
  11734. return new HCompElement(data, this.globalData, this);
  11735. };
  11736. registerRenderer('html', HybridRenderer); // Registering shape modifiers
  11737. ShapeModifiers.registerModifier('tm', TrimModifier);
  11738. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  11739. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  11740. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  11741. ShapeModifiers.registerModifier('zz', ZigZagModifier);
  11742. ShapeModifiers.registerModifier('op', OffsetPathModifier);
  11743. var CompExpressionInterface = function () {
  11744. return function (comp) {
  11745. function _thisLayerFunction(name) {
  11746. var i = 0;
  11747. var len = comp.layers.length;
  11748. while (i < len) {
  11749. if (comp.layers[i].nm === name || comp.layers[i].ind === name) {
  11750. return comp.elements[i].layerInterface;
  11751. }
  11752. i += 1;
  11753. }
  11754. return null; // return {active:false};
  11755. }
  11756. Object.defineProperty(_thisLayerFunction, '_name', {
  11757. value: comp.data.nm
  11758. });
  11759. _thisLayerFunction.layer = _thisLayerFunction;
  11760. _thisLayerFunction.pixelAspect = 1;
  11761. _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h;
  11762. _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w;
  11763. _thisLayerFunction.pixelAspect = 1;
  11764. _thisLayerFunction.frameDuration = 1 / comp.globalData.frameRate;
  11765. _thisLayerFunction.displayStartTime = 0;
  11766. _thisLayerFunction.numLayers = comp.layers.length;
  11767. return _thisLayerFunction;
  11768. };
  11769. }();
  11770. function _typeof$2(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); }
  11771. /* eslint-disable */
  11772. /*
  11773. Copyright 2014 David Bau.
  11774. Permission is hereby granted, free of charge, to any person obtaining
  11775. a copy of this software and associated documentation files (the
  11776. "Software"), to deal in the Software without restriction, including
  11777. without limitation the rights to use, copy, modify, merge, publish,
  11778. distribute, sublicense, and/or sell copies of the Software, and to
  11779. permit persons to whom the Software is furnished to do so, subject to
  11780. the following conditions:
  11781. The above copyright notice and this permission notice shall be
  11782. included in all copies or substantial portions of the Software.
  11783. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  11784. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11785. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  11786. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  11787. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  11788. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  11789. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  11790. */
  11791. function seedRandom(pool, math) {
  11792. //
  11793. // The following constants are related to IEEE 754 limits.
  11794. //
  11795. var global = this,
  11796. width = 256,
  11797. // each RC4 output is 0 <= x < 256
  11798. chunks = 6,
  11799. // at least six RC4 outputs for each double
  11800. digits = 52,
  11801. // there are 52 significant digits in a double
  11802. rngname = 'random',
  11803. // rngname: name for Math.random and Math.seedrandom
  11804. startdenom = math.pow(width, chunks),
  11805. significance = math.pow(2, digits),
  11806. overflow = significance * 2,
  11807. mask = width - 1,
  11808. nodecrypto; // node.js crypto module, initialized at the bottom.
  11809. //
  11810. // seedrandom()
  11811. // This is the seedrandom function described above.
  11812. //
  11813. function seedrandom(seed, options, callback) {
  11814. var key = [];
  11815. options = options === true ? {
  11816. entropy: true
  11817. } : options || {}; // Flatten the seed string or build one from local entropy if needed.
  11818. var shortseed = mixkey(flatten(options.entropy ? [seed, tostring(pool)] : seed === null ? autoseed() : seed, 3), key); // Use the seed to initialize an ARC4 generator.
  11819. var arc4 = new ARC4(key); // This function returns a random double in [0, 1) that contains
  11820. // randomness in every bit of the mantissa of the IEEE 754 value.
  11821. var prng = function prng() {
  11822. var n = arc4.g(chunks),
  11823. // Start with a numerator n < 2 ^ 48
  11824. d = startdenom,
  11825. // and denominator d = 2 ^ 48.
  11826. x = 0; // and no 'extra last byte'.
  11827. while (n < significance) {
  11828. // Fill up all significant digits by
  11829. n = (n + x) * width; // shifting numerator and
  11830. d *= width; // denominator and generating a
  11831. x = arc4.g(1); // new least-significant-byte.
  11832. }
  11833. while (n >= overflow) {
  11834. // To avoid rounding up, before adding
  11835. n /= 2; // last byte, shift everything
  11836. d /= 2; // right using integer math until
  11837. x >>>= 1; // we have exactly the desired bits.
  11838. }
  11839. return (n + x) / d; // Form the number within [0, 1).
  11840. };
  11841. prng.int32 = function () {
  11842. return arc4.g(4) | 0;
  11843. };
  11844. prng.quick = function () {
  11845. return arc4.g(4) / 0x100000000;
  11846. };
  11847. prng["double"] = prng; // Mix the randomness into accumulated entropy.
  11848. mixkey(tostring(arc4.S), pool); // Calling convention: what to return as a function of prng, seed, is_math.
  11849. return (options.pass || callback || function (prng, seed, is_math_call, state) {
  11850. if (state) {
  11851. // Load the arc4 state from the given state if it has an S array.
  11852. if (state.S) {
  11853. copy(state, arc4);
  11854. } // Only provide the .state method if requested via options.state.
  11855. prng.state = function () {
  11856. return copy(arc4, {});
  11857. };
  11858. } // If called as a method of Math (Math.seedrandom()), mutate
  11859. // Math.random because that is how seedrandom.js has worked since v1.0.
  11860. if (is_math_call) {
  11861. math[rngname] = prng;
  11862. return seed;
  11863. } // Otherwise, it is a newer calling convention, so return the
  11864. // prng directly.
  11865. else return prng;
  11866. })(prng, shortseed, 'global' in options ? options.global : this == math, options.state);
  11867. }
  11868. math['seed' + rngname] = seedrandom; //
  11869. // ARC4
  11870. //
  11871. // An ARC4 implementation. The constructor takes a key in the form of
  11872. // an array of at most (width) integers that should be 0 <= x < (width).
  11873. //
  11874. // The g(count) method returns a pseudorandom integer that concatenates
  11875. // the next (count) outputs from ARC4. Its return value is a number x
  11876. // that is in the range 0 <= x < (width ^ count).
  11877. //
  11878. function ARC4(key) {
  11879. var t,
  11880. keylen = key.length,
  11881. me = this,
  11882. i = 0,
  11883. j = me.i = me.j = 0,
  11884. s = me.S = []; // The empty key [] is treated as [0].
  11885. if (!keylen) {
  11886. key = [keylen++];
  11887. } // Set up S using the standard key scheduling algorithm.
  11888. while (i < width) {
  11889. s[i] = i++;
  11890. }
  11891. for (i = 0; i < width; i++) {
  11892. s[i] = s[j = mask & j + key[i % keylen] + (t = s[i])];
  11893. s[j] = t;
  11894. } // The "g" method returns the next (count) outputs as one number.
  11895. me.g = function (count) {
  11896. // Using instance members instead of closure state nearly doubles speed.
  11897. var t,
  11898. r = 0,
  11899. i = me.i,
  11900. j = me.j,
  11901. s = me.S;
  11902. while (count--) {
  11903. t = s[i = mask & i + 1];
  11904. r = r * width + s[mask & (s[i] = s[j = mask & j + t]) + (s[j] = t)];
  11905. }
  11906. me.i = i;
  11907. me.j = j;
  11908. return r; // For robust unpredictability, the function call below automatically
  11909. // discards an initial batch of values. This is called RC4-drop[256].
  11910. // See http://google.com/search?q=rsa+fluhrer+response&btnI
  11911. };
  11912. } //
  11913. // copy()
  11914. // Copies internal state of ARC4 to or from a plain object.
  11915. //
  11916. function copy(f, t) {
  11917. t.i = f.i;
  11918. t.j = f.j;
  11919. t.S = f.S.slice();
  11920. return t;
  11921. } //
  11922. // flatten()
  11923. // Converts an object tree to nested arrays of strings.
  11924. //
  11925. function flatten(obj, depth) {
  11926. var result = [],
  11927. typ = _typeof$2(obj),
  11928. prop;
  11929. if (depth && typ == 'object') {
  11930. for (prop in obj) {
  11931. try {
  11932. result.push(flatten(obj[prop], depth - 1));
  11933. } catch (e) {}
  11934. }
  11935. }
  11936. return result.length ? result : typ == 'string' ? obj : obj + '\0';
  11937. } //
  11938. // mixkey()
  11939. // Mixes a string seed into a key that is an array of integers, and
  11940. // returns a shortened string seed that is equivalent to the result key.
  11941. //
  11942. function mixkey(seed, key) {
  11943. var stringseed = seed + '',
  11944. smear,
  11945. j = 0;
  11946. while (j < stringseed.length) {
  11947. key[mask & j] = mask & (smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++);
  11948. }
  11949. return tostring(key);
  11950. } //
  11951. // autoseed()
  11952. // Returns an object for autoseeding, using window.crypto and Node crypto
  11953. // module if available.
  11954. //
  11955. function autoseed() {
  11956. try {
  11957. if (nodecrypto) {
  11958. return tostring(nodecrypto.randomBytes(width));
  11959. }
  11960. var out = new Uint8Array(width);
  11961. (global.crypto || global.msCrypto).getRandomValues(out);
  11962. return tostring(out);
  11963. } catch (e) {
  11964. var browser = global.navigator,
  11965. plugins = browser && browser.plugins;
  11966. return [+new Date(), global, plugins, global.screen, tostring(pool)];
  11967. }
  11968. } //
  11969. // tostring()
  11970. // Converts an array of charcodes to a string
  11971. //
  11972. function tostring(a) {
  11973. return String.fromCharCode.apply(0, a);
  11974. } //
  11975. // When seedrandom.js is loaded, we immediately mix a few bits
  11976. // from the built-in RNG into the entropy pool. Because we do
  11977. // not want to interfere with deterministic PRNG state later,
  11978. // seedrandom will not call math.random on its own again after
  11979. // initialization.
  11980. //
  11981. mixkey(math.random(), pool); //
  11982. // Nodejs and AMD support: export the implementation as a module using
  11983. // either convention.
  11984. //
  11985. // End anonymous scope, and pass initial values.
  11986. }
  11987. ;
  11988. function initialize$2(BMMath) {
  11989. seedRandom([], BMMath);
  11990. }
  11991. var propTypes = {
  11992. SHAPE: 'shape'
  11993. };
  11994. function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
  11995. var ExpressionManager = function () {
  11996. 'use strict';
  11997. var ob = {};
  11998. var Math = BMMath;
  11999. var window = null;
  12000. var document = null;
  12001. var XMLHttpRequest = null;
  12002. var fetch = null;
  12003. var frames = null;
  12004. var _lottieGlobal = {};
  12005. initialize$2(BMMath);
  12006. function resetFrame() {
  12007. _lottieGlobal = {};
  12008. }
  12009. function $bm_isInstanceOfArray(arr) {
  12010. return arr.constructor === Array || arr.constructor === Float32Array;
  12011. }
  12012. function isNumerable(tOfV, v) {
  12013. return tOfV === 'number' || v instanceof Number || tOfV === 'boolean' || tOfV === 'string';
  12014. }
  12015. function $bm_neg(a) {
  12016. var tOfA = _typeof$1(a);
  12017. if (tOfA === 'number' || a instanceof Number || tOfA === 'boolean') {
  12018. return -a;
  12019. }
  12020. if ($bm_isInstanceOfArray(a)) {
  12021. var i;
  12022. var lenA = a.length;
  12023. var retArr = [];
  12024. for (i = 0; i < lenA; i += 1) {
  12025. retArr[i] = -a[i];
  12026. }
  12027. return retArr;
  12028. }
  12029. if (a.propType) {
  12030. return a.v;
  12031. }
  12032. return -a;
  12033. }
  12034. var easeInBez = BezierFactory.getBezierEasing(0.333, 0, 0.833, 0.833, 'easeIn').get;
  12035. var easeOutBez = BezierFactory.getBezierEasing(0.167, 0.167, 0.667, 1, 'easeOut').get;
  12036. var easeInOutBez = BezierFactory.getBezierEasing(0.33, 0, 0.667, 1, 'easeInOut').get;
  12037. function sum(a, b) {
  12038. var tOfA = _typeof$1(a);
  12039. var tOfB = _typeof$1(b);
  12040. if (isNumerable(tOfA, a) && isNumerable(tOfB, b) || tOfA === 'string' || tOfB === 'string') {
  12041. return a + b;
  12042. }
  12043. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12044. a = a.slice(0);
  12045. a[0] += b;
  12046. return a;
  12047. }
  12048. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12049. b = b.slice(0);
  12050. b[0] = a + b[0];
  12051. return b;
  12052. }
  12053. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  12054. var i = 0;
  12055. var lenA = a.length;
  12056. var lenB = b.length;
  12057. var retArr = [];
  12058. while (i < lenA || i < lenB) {
  12059. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  12060. retArr[i] = a[i] + b[i];
  12061. } else {
  12062. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  12063. }
  12064. i += 1;
  12065. }
  12066. return retArr;
  12067. }
  12068. return 0;
  12069. }
  12070. var add = sum;
  12071. function sub(a, b) {
  12072. var tOfA = _typeof$1(a);
  12073. var tOfB = _typeof$1(b);
  12074. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12075. if (tOfA === 'string') {
  12076. a = parseInt(a, 10);
  12077. }
  12078. if (tOfB === 'string') {
  12079. b = parseInt(b, 10);
  12080. }
  12081. return a - b;
  12082. }
  12083. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12084. a = a.slice(0);
  12085. a[0] -= b;
  12086. return a;
  12087. }
  12088. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12089. b = b.slice(0);
  12090. b[0] = a - b[0];
  12091. return b;
  12092. }
  12093. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  12094. var i = 0;
  12095. var lenA = a.length;
  12096. var lenB = b.length;
  12097. var retArr = [];
  12098. while (i < lenA || i < lenB) {
  12099. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  12100. retArr[i] = a[i] - b[i];
  12101. } else {
  12102. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  12103. }
  12104. i += 1;
  12105. }
  12106. return retArr;
  12107. }
  12108. return 0;
  12109. }
  12110. function mul(a, b) {
  12111. var tOfA = _typeof$1(a);
  12112. var tOfB = _typeof$1(b);
  12113. var arr;
  12114. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12115. return a * b;
  12116. }
  12117. var i;
  12118. var len;
  12119. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12120. len = a.length;
  12121. arr = createTypedArray('float32', len);
  12122. for (i = 0; i < len; i += 1) {
  12123. arr[i] = a[i] * b;
  12124. }
  12125. return arr;
  12126. }
  12127. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12128. len = b.length;
  12129. arr = createTypedArray('float32', len);
  12130. for (i = 0; i < len; i += 1) {
  12131. arr[i] = a * b[i];
  12132. }
  12133. return arr;
  12134. }
  12135. return 0;
  12136. }
  12137. function div(a, b) {
  12138. var tOfA = _typeof$1(a);
  12139. var tOfB = _typeof$1(b);
  12140. var arr;
  12141. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12142. return a / b;
  12143. }
  12144. var i;
  12145. var len;
  12146. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12147. len = a.length;
  12148. arr = createTypedArray('float32', len);
  12149. for (i = 0; i < len; i += 1) {
  12150. arr[i] = a[i] / b;
  12151. }
  12152. return arr;
  12153. }
  12154. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12155. len = b.length;
  12156. arr = createTypedArray('float32', len);
  12157. for (i = 0; i < len; i += 1) {
  12158. arr[i] = a / b[i];
  12159. }
  12160. return arr;
  12161. }
  12162. return 0;
  12163. }
  12164. function mod(a, b) {
  12165. if (typeof a === 'string') {
  12166. a = parseInt(a, 10);
  12167. }
  12168. if (typeof b === 'string') {
  12169. b = parseInt(b, 10);
  12170. }
  12171. return a % b;
  12172. }
  12173. var $bm_sum = sum;
  12174. var $bm_sub = sub;
  12175. var $bm_mul = mul;
  12176. var $bm_div = div;
  12177. var $bm_mod = mod;
  12178. function clamp(num, min, max) {
  12179. if (min > max) {
  12180. var mm = max;
  12181. max = min;
  12182. min = mm;
  12183. }
  12184. return Math.min(Math.max(num, min), max);
  12185. }
  12186. function radiansToDegrees(val) {
  12187. return val / degToRads;
  12188. }
  12189. var radians_to_degrees = radiansToDegrees;
  12190. function degreesToRadians(val) {
  12191. return val * degToRads;
  12192. }
  12193. var degrees_to_radians = radiansToDegrees;
  12194. var helperLengthArray = [0, 0, 0, 0, 0, 0];
  12195. function length(arr1, arr2) {
  12196. if (typeof arr1 === 'number' || arr1 instanceof Number) {
  12197. arr2 = arr2 || 0;
  12198. return Math.abs(arr1 - arr2);
  12199. }
  12200. if (!arr2) {
  12201. arr2 = helperLengthArray;
  12202. }
  12203. var i;
  12204. var len = Math.min(arr1.length, arr2.length);
  12205. var addedLength = 0;
  12206. for (i = 0; i < len; i += 1) {
  12207. addedLength += Math.pow(arr2[i] - arr1[i], 2);
  12208. }
  12209. return Math.sqrt(addedLength);
  12210. }
  12211. function normalize(vec) {
  12212. return div(vec, length(vec));
  12213. }
  12214. function rgbToHsl(val) {
  12215. var r = val[0];
  12216. var g = val[1];
  12217. var b = val[2];
  12218. var max = Math.max(r, g, b);
  12219. var min = Math.min(r, g, b);
  12220. var h;
  12221. var s;
  12222. var l = (max + min) / 2;
  12223. if (max === min) {
  12224. h = 0; // achromatic
  12225. s = 0; // achromatic
  12226. } else {
  12227. var d = max - min;
  12228. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  12229. switch (max) {
  12230. case r:
  12231. h = (g - b) / d + (g < b ? 6 : 0);
  12232. break;
  12233. case g:
  12234. h = (b - r) / d + 2;
  12235. break;
  12236. case b:
  12237. h = (r - g) / d + 4;
  12238. break;
  12239. default:
  12240. break;
  12241. }
  12242. h /= 6;
  12243. }
  12244. return [h, s, l, val[3]];
  12245. }
  12246. function hue2rgb(p, q, t) {
  12247. if (t < 0) t += 1;
  12248. if (t > 1) t -= 1;
  12249. if (t < 1 / 6) return p + (q - p) * 6 * t;
  12250. if (t < 1 / 2) return q;
  12251. if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
  12252. return p;
  12253. }
  12254. function hslToRgb(val) {
  12255. var h = val[0];
  12256. var s = val[1];
  12257. var l = val[2];
  12258. var r;
  12259. var g;
  12260. var b;
  12261. if (s === 0) {
  12262. r = l; // achromatic
  12263. b = l; // achromatic
  12264. g = l; // achromatic
  12265. } else {
  12266. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  12267. var p = 2 * l - q;
  12268. r = hue2rgb(p, q, h + 1 / 3);
  12269. g = hue2rgb(p, q, h);
  12270. b = hue2rgb(p, q, h - 1 / 3);
  12271. }
  12272. return [r, g, b, val[3]];
  12273. }
  12274. function linear(t, tMin, tMax, value1, value2) {
  12275. if (value1 === undefined || value2 === undefined) {
  12276. value1 = tMin;
  12277. value2 = tMax;
  12278. tMin = 0;
  12279. tMax = 1;
  12280. }
  12281. if (tMax < tMin) {
  12282. var _tMin = tMax;
  12283. tMax = tMin;
  12284. tMin = _tMin;
  12285. }
  12286. if (t <= tMin) {
  12287. return value1;
  12288. }
  12289. if (t >= tMax) {
  12290. return value2;
  12291. }
  12292. var perc = tMax === tMin ? 0 : (t - tMin) / (tMax - tMin);
  12293. if (!value1.length) {
  12294. return value1 + (value2 - value1) * perc;
  12295. }
  12296. var i;
  12297. var len = value1.length;
  12298. var arr = createTypedArray('float32', len);
  12299. for (i = 0; i < len; i += 1) {
  12300. arr[i] = value1[i] + (value2[i] - value1[i]) * perc;
  12301. }
  12302. return arr;
  12303. }
  12304. function random(min, max) {
  12305. if (max === undefined) {
  12306. if (min === undefined) {
  12307. min = 0;
  12308. max = 1;
  12309. } else {
  12310. max = min;
  12311. min = undefined;
  12312. }
  12313. }
  12314. if (max.length) {
  12315. var i;
  12316. var len = max.length;
  12317. if (!min) {
  12318. min = createTypedArray('float32', len);
  12319. }
  12320. var arr = createTypedArray('float32', len);
  12321. var rnd = BMMath.random();
  12322. for (i = 0; i < len; i += 1) {
  12323. arr[i] = min[i] + rnd * (max[i] - min[i]);
  12324. }
  12325. return arr;
  12326. }
  12327. if (min === undefined) {
  12328. min = 0;
  12329. }
  12330. var rndm = BMMath.random();
  12331. return min + rndm * (max - min);
  12332. }
  12333. function createPath(points, inTangents, outTangents, closed) {
  12334. var i;
  12335. var len = points.length;
  12336. var path = shapePool.newElement();
  12337. path.setPathData(!!closed, len);
  12338. var arrPlaceholder = [0, 0];
  12339. var inVertexPoint;
  12340. var outVertexPoint;
  12341. for (i = 0; i < len; i += 1) {
  12342. inVertexPoint = inTangents && inTangents[i] ? inTangents[i] : arrPlaceholder;
  12343. outVertexPoint = outTangents && outTangents[i] ? outTangents[i] : arrPlaceholder;
  12344. path.setTripleAt(points[i][0], points[i][1], outVertexPoint[0] + points[i][0], outVertexPoint[1] + points[i][1], inVertexPoint[0] + points[i][0], inVertexPoint[1] + points[i][1], i, true);
  12345. }
  12346. return path;
  12347. }
  12348. function initiateExpression(elem, data, property) {
  12349. // Bail out if we don't want expressions
  12350. function noOp(_value) {
  12351. return _value;
  12352. }
  12353. if (!elem.globalData.renderConfig.runExpressions) {
  12354. return noOp;
  12355. }
  12356. var val = data.x;
  12357. var needsVelocity = /velocity(?![\w\d])/.test(val);
  12358. var _needsRandom = val.indexOf('random') !== -1;
  12359. var elemType = elem.data.ty;
  12360. var transform;
  12361. var $bm_transform;
  12362. var content;
  12363. var effect;
  12364. var thisProperty = property;
  12365. thisProperty.valueAtTime = thisProperty.getValueAtTime;
  12366. Object.defineProperty(thisProperty, 'value', {
  12367. get: function get() {
  12368. return thisProperty.v;
  12369. }
  12370. });
  12371. elem.comp.frameDuration = 1 / elem.comp.globalData.frameRate;
  12372. elem.comp.displayStartTime = 0;
  12373. var inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  12374. var outPoint = elem.data.op / elem.comp.globalData.frameRate;
  12375. var width = elem.data.sw ? elem.data.sw : 0;
  12376. var height = elem.data.sh ? elem.data.sh : 0;
  12377. var name = elem.data.nm;
  12378. var loopIn;
  12379. var loop_in;
  12380. var loopOut;
  12381. var loop_out;
  12382. var smooth;
  12383. var toWorld;
  12384. var fromWorld;
  12385. var fromComp;
  12386. var toComp;
  12387. var fromCompToSurface;
  12388. var position;
  12389. var rotation;
  12390. var anchorPoint;
  12391. var scale;
  12392. var thisLayer;
  12393. var thisComp;
  12394. var mask;
  12395. var valueAtTime;
  12396. var velocityAtTime;
  12397. var scoped_bm_rt; // val = val.replace(/(\\?"|')((http)(s)?(:\/))?\/.*?(\\?"|')/g, "\"\""); // deter potential network calls
  12398. var expression_function = eval('[function _expression_function(){' + val + ';scoped_bm_rt=$bm_rt}]')[0]; // eslint-disable-line no-eval
  12399. var numKeys = property.kf ? data.k.length : 0;
  12400. var active = !this.data || this.data.hd !== true;
  12401. var wiggle = function wiggle(freq, amp) {
  12402. var iWiggle;
  12403. var j;
  12404. var lenWiggle = this.pv.length ? this.pv.length : 1;
  12405. var addedAmps = createTypedArray('float32', lenWiggle);
  12406. freq = 5;
  12407. var iterations = Math.floor(time * freq);
  12408. iWiggle = 0;
  12409. j = 0;
  12410. while (iWiggle < iterations) {
  12411. // var rnd = BMMath.random();
  12412. for (j = 0; j < lenWiggle; j += 1) {
  12413. addedAmps[j] += -amp + amp * 2 * BMMath.random(); // addedAmps[j] += -amp + amp*2*rnd;
  12414. }
  12415. iWiggle += 1;
  12416. } // var rnd2 = BMMath.random();
  12417. var periods = time * freq;
  12418. var perc = periods - Math.floor(periods);
  12419. var arr = createTypedArray('float32', lenWiggle);
  12420. if (lenWiggle > 1) {
  12421. for (j = 0; j < lenWiggle; j += 1) {
  12422. arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc; // arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc;
  12423. // arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc);
  12424. }
  12425. return arr;
  12426. }
  12427. return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc;
  12428. }.bind(this);
  12429. if (thisProperty.loopIn) {
  12430. loopIn = thisProperty.loopIn.bind(thisProperty);
  12431. loop_in = loopIn;
  12432. }
  12433. if (thisProperty.loopOut) {
  12434. loopOut = thisProperty.loopOut.bind(thisProperty);
  12435. loop_out = loopOut;
  12436. }
  12437. if (thisProperty.smooth) {
  12438. smooth = thisProperty.smooth.bind(thisProperty);
  12439. }
  12440. function loopInDuration(type, duration) {
  12441. return loopIn(type, duration, true);
  12442. }
  12443. function loopOutDuration(type, duration) {
  12444. return loopOut(type, duration, true);
  12445. }
  12446. if (this.getValueAtTime) {
  12447. valueAtTime = this.getValueAtTime.bind(this);
  12448. }
  12449. if (this.getVelocityAtTime) {
  12450. velocityAtTime = this.getVelocityAtTime.bind(this);
  12451. }
  12452. var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface);
  12453. function lookAt(elem1, elem2) {
  12454. var fVec = [elem2[0] - elem1[0], elem2[1] - elem1[1], elem2[2] - elem1[2]];
  12455. var pitch = Math.atan2(fVec[0], Math.sqrt(fVec[1] * fVec[1] + fVec[2] * fVec[2])) / degToRads;
  12456. var yaw = -Math.atan2(fVec[1], fVec[2]) / degToRads;
  12457. return [yaw, pitch, 0];
  12458. }
  12459. function easeOut(t, tMin, tMax, val1, val2) {
  12460. return applyEase(easeOutBez, t, tMin, tMax, val1, val2);
  12461. }
  12462. function easeIn(t, tMin, tMax, val1, val2) {
  12463. return applyEase(easeInBez, t, tMin, tMax, val1, val2);
  12464. }
  12465. function ease(t, tMin, tMax, val1, val2) {
  12466. return applyEase(easeInOutBez, t, tMin, tMax, val1, val2);
  12467. }
  12468. function applyEase(fn, t, tMin, tMax, val1, val2) {
  12469. if (val1 === undefined) {
  12470. val1 = tMin;
  12471. val2 = tMax;
  12472. } else {
  12473. t = (t - tMin) / (tMax - tMin);
  12474. }
  12475. if (t > 1) {
  12476. t = 1;
  12477. } else if (t < 0) {
  12478. t = 0;
  12479. }
  12480. var mult = fn(t);
  12481. if ($bm_isInstanceOfArray(val1)) {
  12482. var iKey;
  12483. var lenKey = val1.length;
  12484. var arr = createTypedArray('float32', lenKey);
  12485. for (iKey = 0; iKey < lenKey; iKey += 1) {
  12486. arr[iKey] = (val2[iKey] - val1[iKey]) * mult + val1[iKey];
  12487. }
  12488. return arr;
  12489. }
  12490. return (val2 - val1) * mult + val1;
  12491. }
  12492. function nearestKey(time) {
  12493. var iKey;
  12494. var lenKey = data.k.length;
  12495. var index;
  12496. var keyTime;
  12497. if (!data.k.length || typeof data.k[0] === 'number') {
  12498. index = 0;
  12499. keyTime = 0;
  12500. } else {
  12501. index = -1;
  12502. time *= elem.comp.globalData.frameRate;
  12503. if (time < data.k[0].t) {
  12504. index = 1;
  12505. keyTime = data.k[0].t;
  12506. } else {
  12507. for (iKey = 0; iKey < lenKey - 1; iKey += 1) {
  12508. if (time === data.k[iKey].t) {
  12509. index = iKey + 1;
  12510. keyTime = data.k[iKey].t;
  12511. break;
  12512. } else if (time > data.k[iKey].t && time < data.k[iKey + 1].t) {
  12513. if (time - data.k[iKey].t > data.k[iKey + 1].t - time) {
  12514. index = iKey + 2;
  12515. keyTime = data.k[iKey + 1].t;
  12516. } else {
  12517. index = iKey + 1;
  12518. keyTime = data.k[iKey].t;
  12519. }
  12520. break;
  12521. }
  12522. }
  12523. if (index === -1) {
  12524. index = iKey + 1;
  12525. keyTime = data.k[iKey].t;
  12526. }
  12527. }
  12528. }
  12529. var obKey = {};
  12530. obKey.index = index;
  12531. obKey.time = keyTime / elem.comp.globalData.frameRate;
  12532. return obKey;
  12533. }
  12534. function key(ind) {
  12535. var obKey;
  12536. var iKey;
  12537. var lenKey;
  12538. if (!data.k.length || typeof data.k[0] === 'number') {
  12539. throw new Error('The property has no keyframe at index ' + ind);
  12540. }
  12541. ind -= 1;
  12542. obKey = {
  12543. time: data.k[ind].t / elem.comp.globalData.frameRate,
  12544. value: []
  12545. };
  12546. var arr = Object.prototype.hasOwnProperty.call(data.k[ind], 's') ? data.k[ind].s : data.k[ind - 1].e;
  12547. lenKey = arr.length;
  12548. for (iKey = 0; iKey < lenKey; iKey += 1) {
  12549. obKey[iKey] = arr[iKey];
  12550. obKey.value[iKey] = arr[iKey];
  12551. }
  12552. return obKey;
  12553. }
  12554. function framesToTime(fr, fps) {
  12555. if (!fps) {
  12556. fps = elem.comp.globalData.frameRate;
  12557. }
  12558. return fr / fps;
  12559. }
  12560. function timeToFrames(t, fps) {
  12561. if (!t && t !== 0) {
  12562. t = time;
  12563. }
  12564. if (!fps) {
  12565. fps = elem.comp.globalData.frameRate;
  12566. }
  12567. return t * fps;
  12568. }
  12569. function seedRandom(seed) {
  12570. BMMath.seedrandom(randSeed + seed);
  12571. }
  12572. function sourceRectAtTime() {
  12573. return elem.sourceRectAtTime();
  12574. }
  12575. function substring(init, end) {
  12576. if (typeof value === 'string') {
  12577. if (end === undefined) {
  12578. return value.substring(init);
  12579. }
  12580. return value.substring(init, end);
  12581. }
  12582. return '';
  12583. }
  12584. function substr(init, end) {
  12585. if (typeof value === 'string') {
  12586. if (end === undefined) {
  12587. return value.substr(init);
  12588. }
  12589. return value.substr(init, end);
  12590. }
  12591. return '';
  12592. }
  12593. function posterizeTime(framesPerSecond) {
  12594. time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond;
  12595. value = valueAtTime(time);
  12596. }
  12597. var time;
  12598. var velocity;
  12599. var value;
  12600. var text;
  12601. var textIndex;
  12602. var textTotal;
  12603. var selectorValue;
  12604. var index = elem.data.ind;
  12605. var hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  12606. var parent;
  12607. var randSeed = Math.floor(Math.random() * 1000000);
  12608. var globalData = elem.globalData;
  12609. function executeExpression(_value) {
  12610. // globalData.pushExpression();
  12611. value = _value;
  12612. if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') {
  12613. return value;
  12614. }
  12615. if (this.propType === 'textSelector') {
  12616. textIndex = this.textIndex;
  12617. textTotal = this.textTotal;
  12618. selectorValue = this.selectorValue;
  12619. }
  12620. if (!thisLayer) {
  12621. text = elem.layerInterface.text;
  12622. thisLayer = elem.layerInterface;
  12623. thisComp = elem.comp.compInterface;
  12624. toWorld = thisLayer.toWorld.bind(thisLayer);
  12625. fromWorld = thisLayer.fromWorld.bind(thisLayer);
  12626. fromComp = thisLayer.fromComp.bind(thisLayer);
  12627. toComp = thisLayer.toComp.bind(thisLayer);
  12628. mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null;
  12629. fromCompToSurface = fromComp;
  12630. }
  12631. if (!transform) {
  12632. transform = elem.layerInterface('ADBE Transform Group');
  12633. $bm_transform = transform;
  12634. if (transform) {
  12635. anchorPoint = transform.anchorPoint;
  12636. /* position = transform.position;
  12637. rotation = transform.rotation;
  12638. scale = transform.scale; */
  12639. }
  12640. }
  12641. if (elemType === 4 && !content) {
  12642. content = thisLayer('ADBE Root Vectors Group');
  12643. }
  12644. if (!effect) {
  12645. effect = thisLayer(4);
  12646. }
  12647. hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  12648. if (hasParent && !parent) {
  12649. parent = elem.hierarchy[0].layerInterface;
  12650. }
  12651. time = this.comp.renderedFrame / this.comp.globalData.frameRate;
  12652. if (_needsRandom) {
  12653. seedRandom(randSeed + time);
  12654. }
  12655. if (needsVelocity) {
  12656. velocity = velocityAtTime(time);
  12657. }
  12658. expression_function();
  12659. this.frameExpressionId = elem.globalData.frameId; // TODO: Check if it's possible to return on ShapeInterface the .v value
  12660. // Changed this to a ternary operation because Rollup failed compiling it correctly
  12661. scoped_bm_rt = scoped_bm_rt.propType === propTypes.SHAPE ? scoped_bm_rt.v : scoped_bm_rt;
  12662. return scoped_bm_rt;
  12663. } // Bundlers will see these as dead code and unless we reference them
  12664. executeExpression.__preventDeadCodeRemoval = [$bm_transform, anchorPoint, time, velocity, inPoint, outPoint, width, height, name, loop_in, loop_out, smooth, toComp, fromCompToSurface, toWorld, fromWorld, mask, position, rotation, scale, thisComp, numKeys, active, wiggle, loopInDuration, loopOutDuration, comp, lookAt, easeOut, easeIn, ease, nearestKey, key, text, textIndex, textTotal, selectorValue, framesToTime, timeToFrames, sourceRectAtTime, substring, substr, posterizeTime, index, globalData];
  12665. return executeExpression;
  12666. }
  12667. ob.initiateExpression = initiateExpression;
  12668. ob.__preventDeadCodeRemoval = [window, document, XMLHttpRequest, fetch, frames, $bm_neg, add, $bm_sum, $bm_sub, $bm_mul, $bm_div, $bm_mod, clamp, radians_to_degrees, degreesToRadians, degrees_to_radians, normalize, rgbToHsl, hslToRgb, linear, random, createPath, _lottieGlobal];
  12669. ob.resetFrame = resetFrame;
  12670. return ob;
  12671. }();
  12672. var Expressions = function () {
  12673. var ob = {};
  12674. ob.initExpressions = initExpressions;
  12675. ob.resetFrame = ExpressionManager.resetFrame;
  12676. function initExpressions(animation) {
  12677. var stackCount = 0;
  12678. var registers = [];
  12679. function pushExpression() {
  12680. stackCount += 1;
  12681. }
  12682. function popExpression() {
  12683. stackCount -= 1;
  12684. if (stackCount === 0) {
  12685. releaseInstances();
  12686. }
  12687. }
  12688. function registerExpressionProperty(expression) {
  12689. if (registers.indexOf(expression) === -1) {
  12690. registers.push(expression);
  12691. }
  12692. }
  12693. function releaseInstances() {
  12694. var i;
  12695. var len = registers.length;
  12696. for (i = 0; i < len; i += 1) {
  12697. registers[i].release();
  12698. }
  12699. registers.length = 0;
  12700. }
  12701. animation.renderer.compInterface = CompExpressionInterface(animation.renderer);
  12702. animation.renderer.globalData.projectInterface.registerComposition(animation.renderer);
  12703. animation.renderer.globalData.pushExpression = pushExpression;
  12704. animation.renderer.globalData.popExpression = popExpression;
  12705. animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty;
  12706. }
  12707. return ob;
  12708. }();
  12709. var MaskManagerInterface = function () {
  12710. function MaskInterface(mask, data) {
  12711. this._mask = mask;
  12712. this._data = data;
  12713. }
  12714. Object.defineProperty(MaskInterface.prototype, 'maskPath', {
  12715. get: function get() {
  12716. if (this._mask.prop.k) {
  12717. this._mask.prop.getValue();
  12718. }
  12719. return this._mask.prop;
  12720. }
  12721. });
  12722. Object.defineProperty(MaskInterface.prototype, 'maskOpacity', {
  12723. get: function get() {
  12724. if (this._mask.op.k) {
  12725. this._mask.op.getValue();
  12726. }
  12727. return this._mask.op.v * 100;
  12728. }
  12729. });
  12730. var MaskManager = function MaskManager(maskManager) {
  12731. var _masksInterfaces = createSizedArray(maskManager.viewData.length);
  12732. var i;
  12733. var len = maskManager.viewData.length;
  12734. for (i = 0; i < len; i += 1) {
  12735. _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]);
  12736. }
  12737. var maskFunction = function maskFunction(name) {
  12738. i = 0;
  12739. while (i < len) {
  12740. if (maskManager.masksProperties[i].nm === name) {
  12741. return _masksInterfaces[i];
  12742. }
  12743. i += 1;
  12744. }
  12745. return null;
  12746. };
  12747. return maskFunction;
  12748. };
  12749. return MaskManager;
  12750. }();
  12751. var ExpressionPropertyInterface = function () {
  12752. var defaultUnidimensionalValue = {
  12753. pv: 0,
  12754. v: 0,
  12755. mult: 1
  12756. };
  12757. var defaultMultidimensionalValue = {
  12758. pv: [0, 0, 0],
  12759. v: [0, 0, 0],
  12760. mult: 1
  12761. };
  12762. function completeProperty(expressionValue, property, type) {
  12763. Object.defineProperty(expressionValue, 'velocity', {
  12764. get: function get() {
  12765. return property.getVelocityAtTime(property.comp.currentFrame);
  12766. }
  12767. });
  12768. expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0;
  12769. expressionValue.key = function (pos) {
  12770. if (!expressionValue.numKeys) {
  12771. return 0;
  12772. }
  12773. var value = '';
  12774. if ('s' in property.keyframes[pos - 1]) {
  12775. value = property.keyframes[pos - 1].s;
  12776. } else if ('e' in property.keyframes[pos - 2]) {
  12777. value = property.keyframes[pos - 2].e;
  12778. } else {
  12779. value = property.keyframes[pos - 2].s;
  12780. }
  12781. var valueProp = type === 'unidimensional' ? new Number(value) : Object.assign({}, value); // eslint-disable-line no-new-wrappers
  12782. valueProp.time = property.keyframes[pos - 1].t / property.elem.comp.globalData.frameRate;
  12783. valueProp.value = type === 'unidimensional' ? value[0] : value;
  12784. return valueProp;
  12785. };
  12786. expressionValue.valueAtTime = property.getValueAtTime;
  12787. expressionValue.speedAtTime = property.getSpeedAtTime;
  12788. expressionValue.velocityAtTime = property.getVelocityAtTime;
  12789. expressionValue.propertyGroup = property.propertyGroup;
  12790. }
  12791. function UnidimensionalPropertyInterface(property) {
  12792. if (!property || !('pv' in property)) {
  12793. property = defaultUnidimensionalValue;
  12794. }
  12795. var mult = 1 / property.mult;
  12796. var val = property.pv * mult;
  12797. var expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  12798. expressionValue.value = val;
  12799. completeProperty(expressionValue, property, 'unidimensional');
  12800. return function () {
  12801. if (property.k) {
  12802. property.getValue();
  12803. }
  12804. val = property.v * mult;
  12805. if (expressionValue.value !== val) {
  12806. expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  12807. expressionValue.value = val;
  12808. completeProperty(expressionValue, property, 'unidimensional');
  12809. }
  12810. return expressionValue;
  12811. };
  12812. }
  12813. function MultidimensionalPropertyInterface(property) {
  12814. if (!property || !('pv' in property)) {
  12815. property = defaultMultidimensionalValue;
  12816. }
  12817. var mult = 1 / property.mult;
  12818. var len = property.data && property.data.l || property.pv.length;
  12819. var expressionValue = createTypedArray('float32', len);
  12820. var arrValue = createTypedArray('float32', len);
  12821. expressionValue.value = arrValue;
  12822. completeProperty(expressionValue, property, 'multidimensional');
  12823. return function () {
  12824. if (property.k) {
  12825. property.getValue();
  12826. }
  12827. for (var i = 0; i < len; i += 1) {
  12828. arrValue[i] = property.v[i] * mult;
  12829. expressionValue[i] = arrValue[i];
  12830. }
  12831. return expressionValue;
  12832. };
  12833. } // TODO: try to avoid using this getter
  12834. function defaultGetter() {
  12835. return defaultUnidimensionalValue;
  12836. }
  12837. return function (property) {
  12838. if (!property) {
  12839. return defaultGetter;
  12840. }
  12841. if (property.propType === 'unidimensional') {
  12842. return UnidimensionalPropertyInterface(property);
  12843. }
  12844. return MultidimensionalPropertyInterface(property);
  12845. };
  12846. }();
  12847. var TransformExpressionInterface = function () {
  12848. return function (transform) {
  12849. function _thisFunction(name) {
  12850. switch (name) {
  12851. case 'scale':
  12852. case 'Scale':
  12853. case 'ADBE Scale':
  12854. case 6:
  12855. return _thisFunction.scale;
  12856. case 'rotation':
  12857. case 'Rotation':
  12858. case 'ADBE Rotation':
  12859. case 'ADBE Rotate Z':
  12860. case 10:
  12861. return _thisFunction.rotation;
  12862. case 'ADBE Rotate X':
  12863. return _thisFunction.xRotation;
  12864. case 'ADBE Rotate Y':
  12865. return _thisFunction.yRotation;
  12866. case 'position':
  12867. case 'Position':
  12868. case 'ADBE Position':
  12869. case 2:
  12870. return _thisFunction.position;
  12871. case 'ADBE Position_0':
  12872. return _thisFunction.xPosition;
  12873. case 'ADBE Position_1':
  12874. return _thisFunction.yPosition;
  12875. case 'ADBE Position_2':
  12876. return _thisFunction.zPosition;
  12877. case 'anchorPoint':
  12878. case 'AnchorPoint':
  12879. case 'Anchor Point':
  12880. case 'ADBE AnchorPoint':
  12881. case 1:
  12882. return _thisFunction.anchorPoint;
  12883. case 'opacity':
  12884. case 'Opacity':
  12885. case 11:
  12886. return _thisFunction.opacity;
  12887. default:
  12888. return null;
  12889. }
  12890. }
  12891. Object.defineProperty(_thisFunction, 'rotation', {
  12892. get: ExpressionPropertyInterface(transform.r || transform.rz)
  12893. });
  12894. Object.defineProperty(_thisFunction, 'zRotation', {
  12895. get: ExpressionPropertyInterface(transform.rz || transform.r)
  12896. });
  12897. Object.defineProperty(_thisFunction, 'xRotation', {
  12898. get: ExpressionPropertyInterface(transform.rx)
  12899. });
  12900. Object.defineProperty(_thisFunction, 'yRotation', {
  12901. get: ExpressionPropertyInterface(transform.ry)
  12902. });
  12903. Object.defineProperty(_thisFunction, 'scale', {
  12904. get: ExpressionPropertyInterface(transform.s)
  12905. });
  12906. var _px;
  12907. var _py;
  12908. var _pz;
  12909. var _transformFactory;
  12910. if (transform.p) {
  12911. _transformFactory = ExpressionPropertyInterface(transform.p);
  12912. } else {
  12913. _px = ExpressionPropertyInterface(transform.px);
  12914. _py = ExpressionPropertyInterface(transform.py);
  12915. if (transform.pz) {
  12916. _pz = ExpressionPropertyInterface(transform.pz);
  12917. }
  12918. }
  12919. Object.defineProperty(_thisFunction, 'position', {
  12920. get: function get() {
  12921. if (transform.p) {
  12922. return _transformFactory();
  12923. }
  12924. return [_px(), _py(), _pz ? _pz() : 0];
  12925. }
  12926. });
  12927. Object.defineProperty(_thisFunction, 'xPosition', {
  12928. get: ExpressionPropertyInterface(transform.px)
  12929. });
  12930. Object.defineProperty(_thisFunction, 'yPosition', {
  12931. get: ExpressionPropertyInterface(transform.py)
  12932. });
  12933. Object.defineProperty(_thisFunction, 'zPosition', {
  12934. get: ExpressionPropertyInterface(transform.pz)
  12935. });
  12936. Object.defineProperty(_thisFunction, 'anchorPoint', {
  12937. get: ExpressionPropertyInterface(transform.a)
  12938. });
  12939. Object.defineProperty(_thisFunction, 'opacity', {
  12940. get: ExpressionPropertyInterface(transform.o)
  12941. });
  12942. Object.defineProperty(_thisFunction, 'skew', {
  12943. get: ExpressionPropertyInterface(transform.sk)
  12944. });
  12945. Object.defineProperty(_thisFunction, 'skewAxis', {
  12946. get: ExpressionPropertyInterface(transform.sa)
  12947. });
  12948. Object.defineProperty(_thisFunction, 'orientation', {
  12949. get: ExpressionPropertyInterface(transform.or)
  12950. });
  12951. return _thisFunction;
  12952. };
  12953. }();
  12954. var LayerExpressionInterface = function () {
  12955. function getMatrix(time) {
  12956. var toWorldMat = new Matrix();
  12957. if (time !== undefined) {
  12958. var propMatrix = this._elem.finalTransform.mProp.getValueAtTime(time);
  12959. propMatrix.clone(toWorldMat);
  12960. } else {
  12961. var transformMat = this._elem.finalTransform.mProp;
  12962. transformMat.applyToMatrix(toWorldMat);
  12963. }
  12964. return toWorldMat;
  12965. }
  12966. function toWorldVec(arr, time) {
  12967. var toWorldMat = this.getMatrix(time);
  12968. toWorldMat.props[12] = 0;
  12969. toWorldMat.props[13] = 0;
  12970. toWorldMat.props[14] = 0;
  12971. return this.applyPoint(toWorldMat, arr);
  12972. }
  12973. function toWorld(arr, time) {
  12974. var toWorldMat = this.getMatrix(time);
  12975. return this.applyPoint(toWorldMat, arr);
  12976. }
  12977. function fromWorldVec(arr, time) {
  12978. var toWorldMat = this.getMatrix(time);
  12979. toWorldMat.props[12] = 0;
  12980. toWorldMat.props[13] = 0;
  12981. toWorldMat.props[14] = 0;
  12982. return this.invertPoint(toWorldMat, arr);
  12983. }
  12984. function fromWorld(arr, time) {
  12985. var toWorldMat = this.getMatrix(time);
  12986. return this.invertPoint(toWorldMat, arr);
  12987. }
  12988. function applyPoint(matrix, arr) {
  12989. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  12990. var i;
  12991. var len = this._elem.hierarchy.length;
  12992. for (i = 0; i < len; i += 1) {
  12993. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  12994. }
  12995. }
  12996. return matrix.applyToPointArray(arr[0], arr[1], arr[2] || 0);
  12997. }
  12998. function invertPoint(matrix, arr) {
  12999. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  13000. var i;
  13001. var len = this._elem.hierarchy.length;
  13002. for (i = 0; i < len; i += 1) {
  13003. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  13004. }
  13005. }
  13006. return matrix.inversePoint(arr);
  13007. }
  13008. function fromComp(arr) {
  13009. var toWorldMat = new Matrix();
  13010. toWorldMat.reset();
  13011. this._elem.finalTransform.mProp.applyToMatrix(toWorldMat);
  13012. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  13013. var i;
  13014. var len = this._elem.hierarchy.length;
  13015. for (i = 0; i < len; i += 1) {
  13016. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  13017. }
  13018. return toWorldMat.inversePoint(arr);
  13019. }
  13020. return toWorldMat.inversePoint(arr);
  13021. }
  13022. function sampleImage() {
  13023. return [1, 1, 1, 1];
  13024. }
  13025. return function (elem) {
  13026. var transformInterface;
  13027. function _registerMaskInterface(maskManager) {
  13028. _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem);
  13029. }
  13030. function _registerEffectsInterface(effects) {
  13031. _thisLayerFunction.effect = effects;
  13032. }
  13033. function _thisLayerFunction(name) {
  13034. switch (name) {
  13035. case 'ADBE Root Vectors Group':
  13036. case 'Contents':
  13037. case 2:
  13038. return _thisLayerFunction.shapeInterface;
  13039. case 1:
  13040. case 6:
  13041. case 'Transform':
  13042. case 'transform':
  13043. case 'ADBE Transform Group':
  13044. return transformInterface;
  13045. case 4:
  13046. case 'ADBE Effect Parade':
  13047. case 'effects':
  13048. case 'Effects':
  13049. return _thisLayerFunction.effect;
  13050. case 'ADBE Text Properties':
  13051. return _thisLayerFunction.textInterface;
  13052. default:
  13053. return null;
  13054. }
  13055. }
  13056. _thisLayerFunction.getMatrix = getMatrix;
  13057. _thisLayerFunction.invertPoint = invertPoint;
  13058. _thisLayerFunction.applyPoint = applyPoint;
  13059. _thisLayerFunction.toWorld = toWorld;
  13060. _thisLayerFunction.toWorldVec = toWorldVec;
  13061. _thisLayerFunction.fromWorld = fromWorld;
  13062. _thisLayerFunction.fromWorldVec = fromWorldVec;
  13063. _thisLayerFunction.toComp = toWorld;
  13064. _thisLayerFunction.fromComp = fromComp;
  13065. _thisLayerFunction.sampleImage = sampleImage;
  13066. _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem);
  13067. _thisLayerFunction._elem = elem;
  13068. transformInterface = TransformExpressionInterface(elem.finalTransform.mProp);
  13069. var anchorPointDescriptor = getDescriptor(transformInterface, 'anchorPoint');
  13070. Object.defineProperties(_thisLayerFunction, {
  13071. hasParent: {
  13072. get: function get() {
  13073. return elem.hierarchy.length;
  13074. }
  13075. },
  13076. parent: {
  13077. get: function get() {
  13078. return elem.hierarchy[0].layerInterface;
  13079. }
  13080. },
  13081. rotation: getDescriptor(transformInterface, 'rotation'),
  13082. scale: getDescriptor(transformInterface, 'scale'),
  13083. position: getDescriptor(transformInterface, 'position'),
  13084. opacity: getDescriptor(transformInterface, 'opacity'),
  13085. anchorPoint: anchorPointDescriptor,
  13086. anchor_point: anchorPointDescriptor,
  13087. transform: {
  13088. get: function get() {
  13089. return transformInterface;
  13090. }
  13091. },
  13092. active: {
  13093. get: function get() {
  13094. return elem.isInRange;
  13095. }
  13096. }
  13097. });
  13098. _thisLayerFunction.startTime = elem.data.st;
  13099. _thisLayerFunction.index = elem.data.ind;
  13100. _thisLayerFunction.source = elem.data.refId;
  13101. _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100;
  13102. _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100;
  13103. _thisLayerFunction.inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  13104. _thisLayerFunction.outPoint = elem.data.op / elem.comp.globalData.frameRate;
  13105. _thisLayerFunction._name = elem.data.nm;
  13106. _thisLayerFunction.registerMaskInterface = _registerMaskInterface;
  13107. _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface;
  13108. return _thisLayerFunction;
  13109. };
  13110. }();
  13111. var propertyGroupFactory = function () {
  13112. return function (interfaceFunction, parentPropertyGroup) {
  13113. return function (val) {
  13114. val = val === undefined ? 1 : val;
  13115. if (val <= 0) {
  13116. return interfaceFunction;
  13117. }
  13118. return parentPropertyGroup(val - 1);
  13119. };
  13120. };
  13121. }();
  13122. var PropertyInterface = function () {
  13123. return function (propertyName, propertyGroup) {
  13124. var interfaceFunction = {
  13125. _name: propertyName
  13126. };
  13127. function _propertyGroup(val) {
  13128. val = val === undefined ? 1 : val;
  13129. if (val <= 0) {
  13130. return interfaceFunction;
  13131. }
  13132. return propertyGroup(val - 1);
  13133. }
  13134. return _propertyGroup;
  13135. };
  13136. }();
  13137. var EffectsExpressionInterface = function () {
  13138. var ob = {
  13139. createEffectsInterface: createEffectsInterface
  13140. };
  13141. function createEffectsInterface(elem, propertyGroup) {
  13142. if (elem.effectsManager) {
  13143. var effectElements = [];
  13144. var effectsData = elem.data.ef;
  13145. var i;
  13146. var len = elem.effectsManager.effectElements.length;
  13147. for (i = 0; i < len; i += 1) {
  13148. effectElements.push(createGroupInterface(effectsData[i], elem.effectsManager.effectElements[i], propertyGroup, elem));
  13149. }
  13150. var effects = elem.data.ef || [];
  13151. var groupInterface = function groupInterface(name) {
  13152. i = 0;
  13153. len = effects.length;
  13154. while (i < len) {
  13155. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  13156. return effectElements[i];
  13157. }
  13158. i += 1;
  13159. }
  13160. return null;
  13161. };
  13162. Object.defineProperty(groupInterface, 'numProperties', {
  13163. get: function get() {
  13164. return effects.length;
  13165. }
  13166. });
  13167. return groupInterface;
  13168. }
  13169. return null;
  13170. }
  13171. function createGroupInterface(data, elements, propertyGroup, elem) {
  13172. function groupInterface(name) {
  13173. var effects = data.ef;
  13174. var i = 0;
  13175. var len = effects.length;
  13176. while (i < len) {
  13177. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  13178. if (effects[i].ty === 5) {
  13179. return effectElements[i];
  13180. }
  13181. return effectElements[i]();
  13182. }
  13183. i += 1;
  13184. }
  13185. throw new Error();
  13186. }
  13187. var _propertyGroup = propertyGroupFactory(groupInterface, propertyGroup);
  13188. var effectElements = [];
  13189. var i;
  13190. var len = data.ef.length;
  13191. for (i = 0; i < len; i += 1) {
  13192. if (data.ef[i].ty === 5) {
  13193. effectElements.push(createGroupInterface(data.ef[i], elements.effectElements[i], elements.effectElements[i].propertyGroup, elem));
  13194. } else {
  13195. effectElements.push(createValueInterface(elements.effectElements[i], data.ef[i].ty, elem, _propertyGroup));
  13196. }
  13197. }
  13198. if (data.mn === 'ADBE Color Control') {
  13199. Object.defineProperty(groupInterface, 'color', {
  13200. get: function get() {
  13201. return effectElements[0]();
  13202. }
  13203. });
  13204. }
  13205. Object.defineProperties(groupInterface, {
  13206. numProperties: {
  13207. get: function get() {
  13208. return data.np;
  13209. }
  13210. },
  13211. _name: {
  13212. value: data.nm
  13213. },
  13214. propertyGroup: {
  13215. value: _propertyGroup
  13216. }
  13217. });
  13218. groupInterface.enabled = data.en !== 0;
  13219. groupInterface.active = groupInterface.enabled;
  13220. return groupInterface;
  13221. }
  13222. function createValueInterface(element, type, elem, propertyGroup) {
  13223. var expressionProperty = ExpressionPropertyInterface(element.p);
  13224. function interfaceFunction() {
  13225. if (type === 10) {
  13226. return elem.comp.compInterface(element.p.v);
  13227. }
  13228. return expressionProperty();
  13229. }
  13230. if (element.p.setGroupProperty) {
  13231. element.p.setGroupProperty(PropertyInterface('', propertyGroup));
  13232. }
  13233. return interfaceFunction;
  13234. }
  13235. return ob;
  13236. }();
  13237. var ShapePathInterface = function () {
  13238. return function pathInterfaceFactory(shape, view, propertyGroup) {
  13239. var prop = view.sh;
  13240. function interfaceFunction(val) {
  13241. if (val === 'Shape' || val === 'shape' || val === 'Path' || val === 'path' || val === 'ADBE Vector Shape' || val === 2) {
  13242. return interfaceFunction.path;
  13243. }
  13244. return null;
  13245. }
  13246. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13247. prop.setGroupProperty(PropertyInterface('Path', _propertyGroup));
  13248. Object.defineProperties(interfaceFunction, {
  13249. path: {
  13250. get: function get() {
  13251. if (prop.k) {
  13252. prop.getValue();
  13253. }
  13254. return prop;
  13255. }
  13256. },
  13257. shape: {
  13258. get: function get() {
  13259. if (prop.k) {
  13260. prop.getValue();
  13261. }
  13262. return prop;
  13263. }
  13264. },
  13265. _name: {
  13266. value: shape.nm
  13267. },
  13268. ix: {
  13269. value: shape.ix
  13270. },
  13271. propertyIndex: {
  13272. value: shape.ix
  13273. },
  13274. mn: {
  13275. value: shape.mn
  13276. },
  13277. propertyGroup: {
  13278. value: propertyGroup
  13279. }
  13280. });
  13281. return interfaceFunction;
  13282. };
  13283. }();
  13284. var ShapeExpressionInterface = function () {
  13285. function iterateElements(shapes, view, propertyGroup) {
  13286. var arr = [];
  13287. var i;
  13288. var len = shapes ? shapes.length : 0;
  13289. for (i = 0; i < len; i += 1) {
  13290. if (shapes[i].ty === 'gr') {
  13291. arr.push(groupInterfaceFactory(shapes[i], view[i], propertyGroup));
  13292. } else if (shapes[i].ty === 'fl') {
  13293. arr.push(fillInterfaceFactory(shapes[i], view[i], propertyGroup));
  13294. } else if (shapes[i].ty === 'st') {
  13295. arr.push(strokeInterfaceFactory(shapes[i], view[i], propertyGroup));
  13296. } else if (shapes[i].ty === 'tm') {
  13297. arr.push(trimInterfaceFactory(shapes[i], view[i], propertyGroup));
  13298. } else if (shapes[i].ty === 'tr') {// arr.push(transformInterfaceFactory(shapes[i],view[i],propertyGroup));
  13299. } else if (shapes[i].ty === 'el') {
  13300. arr.push(ellipseInterfaceFactory(shapes[i], view[i], propertyGroup));
  13301. } else if (shapes[i].ty === 'sr') {
  13302. arr.push(starInterfaceFactory(shapes[i], view[i], propertyGroup));
  13303. } else if (shapes[i].ty === 'sh') {
  13304. arr.push(ShapePathInterface(shapes[i], view[i], propertyGroup));
  13305. } else if (shapes[i].ty === 'rc') {
  13306. arr.push(rectInterfaceFactory(shapes[i], view[i], propertyGroup));
  13307. } else if (shapes[i].ty === 'rd') {
  13308. arr.push(roundedInterfaceFactory(shapes[i], view[i], propertyGroup));
  13309. } else if (shapes[i].ty === 'rp') {
  13310. arr.push(repeaterInterfaceFactory(shapes[i], view[i], propertyGroup));
  13311. } else if (shapes[i].ty === 'gf') {
  13312. arr.push(gradientFillInterfaceFactory(shapes[i], view[i], propertyGroup));
  13313. } else {
  13314. arr.push(defaultInterfaceFactory(shapes[i], view[i], propertyGroup));
  13315. }
  13316. }
  13317. return arr;
  13318. }
  13319. function contentsInterfaceFactory(shape, view, propertyGroup) {
  13320. var interfaces;
  13321. var interfaceFunction = function _interfaceFunction(value) {
  13322. var i = 0;
  13323. var len = interfaces.length;
  13324. while (i < len) {
  13325. if (interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value) {
  13326. return interfaces[i];
  13327. }
  13328. i += 1;
  13329. }
  13330. if (typeof value === 'number') {
  13331. return interfaces[value - 1];
  13332. }
  13333. return null;
  13334. };
  13335. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13336. interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup);
  13337. interfaceFunction.numProperties = interfaces.length;
  13338. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  13339. interfaceFunction.transform = transformInterface;
  13340. interfaceFunction.propertyIndex = shape.cix;
  13341. interfaceFunction._name = shape.nm;
  13342. return interfaceFunction;
  13343. }
  13344. function groupInterfaceFactory(shape, view, propertyGroup) {
  13345. var interfaceFunction = function _interfaceFunction(value) {
  13346. switch (value) {
  13347. case 'ADBE Vectors Group':
  13348. case 'Contents':
  13349. case 2:
  13350. return interfaceFunction.content;
  13351. // Not necessary for now. Keeping them here in case a new case appears
  13352. // case 'ADBE Vector Transform Group':
  13353. // case 3:
  13354. default:
  13355. return interfaceFunction.transform;
  13356. }
  13357. };
  13358. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13359. var content = contentsInterfaceFactory(shape, view, interfaceFunction.propertyGroup);
  13360. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  13361. interfaceFunction.content = content;
  13362. interfaceFunction.transform = transformInterface;
  13363. Object.defineProperty(interfaceFunction, '_name', {
  13364. get: function get() {
  13365. return shape.nm;
  13366. }
  13367. }); // interfaceFunction.content = interfaceFunction;
  13368. interfaceFunction.numProperties = shape.np;
  13369. interfaceFunction.propertyIndex = shape.ix;
  13370. interfaceFunction.nm = shape.nm;
  13371. interfaceFunction.mn = shape.mn;
  13372. return interfaceFunction;
  13373. }
  13374. function fillInterfaceFactory(shape, view, propertyGroup) {
  13375. function interfaceFunction(val) {
  13376. if (val === 'Color' || val === 'color') {
  13377. return interfaceFunction.color;
  13378. }
  13379. if (val === 'Opacity' || val === 'opacity') {
  13380. return interfaceFunction.opacity;
  13381. }
  13382. return null;
  13383. }
  13384. Object.defineProperties(interfaceFunction, {
  13385. color: {
  13386. get: ExpressionPropertyInterface(view.c)
  13387. },
  13388. opacity: {
  13389. get: ExpressionPropertyInterface(view.o)
  13390. },
  13391. _name: {
  13392. value: shape.nm
  13393. },
  13394. mn: {
  13395. value: shape.mn
  13396. }
  13397. });
  13398. view.c.setGroupProperty(PropertyInterface('Color', propertyGroup));
  13399. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  13400. return interfaceFunction;
  13401. }
  13402. function gradientFillInterfaceFactory(shape, view, propertyGroup) {
  13403. function interfaceFunction(val) {
  13404. if (val === 'Start Point' || val === 'start point') {
  13405. return interfaceFunction.startPoint;
  13406. }
  13407. if (val === 'End Point' || val === 'end point') {
  13408. return interfaceFunction.endPoint;
  13409. }
  13410. if (val === 'Opacity' || val === 'opacity') {
  13411. return interfaceFunction.opacity;
  13412. }
  13413. return null;
  13414. }
  13415. Object.defineProperties(interfaceFunction, {
  13416. startPoint: {
  13417. get: ExpressionPropertyInterface(view.s)
  13418. },
  13419. endPoint: {
  13420. get: ExpressionPropertyInterface(view.e)
  13421. },
  13422. opacity: {
  13423. get: ExpressionPropertyInterface(view.o)
  13424. },
  13425. type: {
  13426. get: function get() {
  13427. return 'a';
  13428. }
  13429. },
  13430. _name: {
  13431. value: shape.nm
  13432. },
  13433. mn: {
  13434. value: shape.mn
  13435. }
  13436. });
  13437. view.s.setGroupProperty(PropertyInterface('Start Point', propertyGroup));
  13438. view.e.setGroupProperty(PropertyInterface('End Point', propertyGroup));
  13439. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  13440. return interfaceFunction;
  13441. }
  13442. function defaultInterfaceFactory() {
  13443. function interfaceFunction() {
  13444. return null;
  13445. }
  13446. return interfaceFunction;
  13447. }
  13448. function strokeInterfaceFactory(shape, view, propertyGroup) {
  13449. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13450. var _dashPropertyGroup = propertyGroupFactory(dashOb, _propertyGroup);
  13451. function addPropertyToDashOb(i) {
  13452. Object.defineProperty(dashOb, shape.d[i].nm, {
  13453. get: ExpressionPropertyInterface(view.d.dataProps[i].p)
  13454. });
  13455. }
  13456. var i;
  13457. var len = shape.d ? shape.d.length : 0;
  13458. var dashOb = {};
  13459. for (i = 0; i < len; i += 1) {
  13460. addPropertyToDashOb(i);
  13461. view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup);
  13462. }
  13463. function interfaceFunction(val) {
  13464. if (val === 'Color' || val === 'color') {
  13465. return interfaceFunction.color;
  13466. }
  13467. if (val === 'Opacity' || val === 'opacity') {
  13468. return interfaceFunction.opacity;
  13469. }
  13470. if (val === 'Stroke Width' || val === 'stroke width') {
  13471. return interfaceFunction.strokeWidth;
  13472. }
  13473. return null;
  13474. }
  13475. Object.defineProperties(interfaceFunction, {
  13476. color: {
  13477. get: ExpressionPropertyInterface(view.c)
  13478. },
  13479. opacity: {
  13480. get: ExpressionPropertyInterface(view.o)
  13481. },
  13482. strokeWidth: {
  13483. get: ExpressionPropertyInterface(view.w)
  13484. },
  13485. dash: {
  13486. get: function get() {
  13487. return dashOb;
  13488. }
  13489. },
  13490. _name: {
  13491. value: shape.nm
  13492. },
  13493. mn: {
  13494. value: shape.mn
  13495. }
  13496. });
  13497. view.c.setGroupProperty(PropertyInterface('Color', _propertyGroup));
  13498. view.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  13499. view.w.setGroupProperty(PropertyInterface('Stroke Width', _propertyGroup));
  13500. return interfaceFunction;
  13501. }
  13502. function trimInterfaceFactory(shape, view, propertyGroup) {
  13503. function interfaceFunction(val) {
  13504. if (val === shape.e.ix || val === 'End' || val === 'end') {
  13505. return interfaceFunction.end;
  13506. }
  13507. if (val === shape.s.ix) {
  13508. return interfaceFunction.start;
  13509. }
  13510. if (val === shape.o.ix) {
  13511. return interfaceFunction.offset;
  13512. }
  13513. return null;
  13514. }
  13515. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13516. interfaceFunction.propertyIndex = shape.ix;
  13517. view.s.setGroupProperty(PropertyInterface('Start', _propertyGroup));
  13518. view.e.setGroupProperty(PropertyInterface('End', _propertyGroup));
  13519. view.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  13520. interfaceFunction.propertyIndex = shape.ix;
  13521. interfaceFunction.propertyGroup = propertyGroup;
  13522. Object.defineProperties(interfaceFunction, {
  13523. start: {
  13524. get: ExpressionPropertyInterface(view.s)
  13525. },
  13526. end: {
  13527. get: ExpressionPropertyInterface(view.e)
  13528. },
  13529. offset: {
  13530. get: ExpressionPropertyInterface(view.o)
  13531. },
  13532. _name: {
  13533. value: shape.nm
  13534. }
  13535. });
  13536. interfaceFunction.mn = shape.mn;
  13537. return interfaceFunction;
  13538. }
  13539. function transformInterfaceFactory(shape, view, propertyGroup) {
  13540. function interfaceFunction(value) {
  13541. if (shape.a.ix === value || value === 'Anchor Point') {
  13542. return interfaceFunction.anchorPoint;
  13543. }
  13544. if (shape.o.ix === value || value === 'Opacity') {
  13545. return interfaceFunction.opacity;
  13546. }
  13547. if (shape.p.ix === value || value === 'Position') {
  13548. return interfaceFunction.position;
  13549. }
  13550. if (shape.r.ix === value || value === 'Rotation' || value === 'ADBE Vector Rotation') {
  13551. return interfaceFunction.rotation;
  13552. }
  13553. if (shape.s.ix === value || value === 'Scale') {
  13554. return interfaceFunction.scale;
  13555. }
  13556. if (shape.sk && shape.sk.ix === value || value === 'Skew') {
  13557. return interfaceFunction.skew;
  13558. }
  13559. if (shape.sa && shape.sa.ix === value || value === 'Skew Axis') {
  13560. return interfaceFunction.skewAxis;
  13561. }
  13562. return null;
  13563. }
  13564. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13565. view.transform.mProps.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  13566. view.transform.mProps.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  13567. view.transform.mProps.a.setGroupProperty(PropertyInterface('Anchor Point', _propertyGroup));
  13568. view.transform.mProps.s.setGroupProperty(PropertyInterface('Scale', _propertyGroup));
  13569. view.transform.mProps.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  13570. if (view.transform.mProps.sk) {
  13571. view.transform.mProps.sk.setGroupProperty(PropertyInterface('Skew', _propertyGroup));
  13572. view.transform.mProps.sa.setGroupProperty(PropertyInterface('Skew Angle', _propertyGroup));
  13573. }
  13574. view.transform.op.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  13575. Object.defineProperties(interfaceFunction, {
  13576. opacity: {
  13577. get: ExpressionPropertyInterface(view.transform.mProps.o)
  13578. },
  13579. position: {
  13580. get: ExpressionPropertyInterface(view.transform.mProps.p)
  13581. },
  13582. anchorPoint: {
  13583. get: ExpressionPropertyInterface(view.transform.mProps.a)
  13584. },
  13585. scale: {
  13586. get: ExpressionPropertyInterface(view.transform.mProps.s)
  13587. },
  13588. rotation: {
  13589. get: ExpressionPropertyInterface(view.transform.mProps.r)
  13590. },
  13591. skew: {
  13592. get: ExpressionPropertyInterface(view.transform.mProps.sk)
  13593. },
  13594. skewAxis: {
  13595. get: ExpressionPropertyInterface(view.transform.mProps.sa)
  13596. },
  13597. _name: {
  13598. value: shape.nm
  13599. }
  13600. });
  13601. interfaceFunction.ty = 'tr';
  13602. interfaceFunction.mn = shape.mn;
  13603. interfaceFunction.propertyGroup = propertyGroup;
  13604. return interfaceFunction;
  13605. }
  13606. function ellipseInterfaceFactory(shape, view, propertyGroup) {
  13607. function interfaceFunction(value) {
  13608. if (shape.p.ix === value) {
  13609. return interfaceFunction.position;
  13610. }
  13611. if (shape.s.ix === value) {
  13612. return interfaceFunction.size;
  13613. }
  13614. return null;
  13615. }
  13616. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13617. interfaceFunction.propertyIndex = shape.ix;
  13618. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  13619. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  13620. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  13621. Object.defineProperties(interfaceFunction, {
  13622. size: {
  13623. get: ExpressionPropertyInterface(prop.s)
  13624. },
  13625. position: {
  13626. get: ExpressionPropertyInterface(prop.p)
  13627. },
  13628. _name: {
  13629. value: shape.nm
  13630. }
  13631. });
  13632. interfaceFunction.mn = shape.mn;
  13633. return interfaceFunction;
  13634. }
  13635. function starInterfaceFactory(shape, view, propertyGroup) {
  13636. function interfaceFunction(value) {
  13637. if (shape.p.ix === value) {
  13638. return interfaceFunction.position;
  13639. }
  13640. if (shape.r.ix === value) {
  13641. return interfaceFunction.rotation;
  13642. }
  13643. if (shape.pt.ix === value) {
  13644. return interfaceFunction.points;
  13645. }
  13646. if (shape.or.ix === value || value === 'ADBE Vector Star Outer Radius') {
  13647. return interfaceFunction.outerRadius;
  13648. }
  13649. if (shape.os.ix === value) {
  13650. return interfaceFunction.outerRoundness;
  13651. }
  13652. if (shape.ir && (shape.ir.ix === value || value === 'ADBE Vector Star Inner Radius')) {
  13653. return interfaceFunction.innerRadius;
  13654. }
  13655. if (shape.is && shape.is.ix === value) {
  13656. return interfaceFunction.innerRoundness;
  13657. }
  13658. return null;
  13659. }
  13660. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13661. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  13662. interfaceFunction.propertyIndex = shape.ix;
  13663. prop.or.setGroupProperty(PropertyInterface('Outer Radius', _propertyGroup));
  13664. prop.os.setGroupProperty(PropertyInterface('Outer Roundness', _propertyGroup));
  13665. prop.pt.setGroupProperty(PropertyInterface('Points', _propertyGroup));
  13666. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  13667. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  13668. if (shape.ir) {
  13669. prop.ir.setGroupProperty(PropertyInterface('Inner Radius', _propertyGroup));
  13670. prop.is.setGroupProperty(PropertyInterface('Inner Roundness', _propertyGroup));
  13671. }
  13672. Object.defineProperties(interfaceFunction, {
  13673. position: {
  13674. get: ExpressionPropertyInterface(prop.p)
  13675. },
  13676. rotation: {
  13677. get: ExpressionPropertyInterface(prop.r)
  13678. },
  13679. points: {
  13680. get: ExpressionPropertyInterface(prop.pt)
  13681. },
  13682. outerRadius: {
  13683. get: ExpressionPropertyInterface(prop.or)
  13684. },
  13685. outerRoundness: {
  13686. get: ExpressionPropertyInterface(prop.os)
  13687. },
  13688. innerRadius: {
  13689. get: ExpressionPropertyInterface(prop.ir)
  13690. },
  13691. innerRoundness: {
  13692. get: ExpressionPropertyInterface(prop.is)
  13693. },
  13694. _name: {
  13695. value: shape.nm
  13696. }
  13697. });
  13698. interfaceFunction.mn = shape.mn;
  13699. return interfaceFunction;
  13700. }
  13701. function rectInterfaceFactory(shape, view, propertyGroup) {
  13702. function interfaceFunction(value) {
  13703. if (shape.p.ix === value) {
  13704. return interfaceFunction.position;
  13705. }
  13706. if (shape.r.ix === value) {
  13707. return interfaceFunction.roundness;
  13708. }
  13709. if (shape.s.ix === value || value === 'Size' || value === 'ADBE Vector Rect Size') {
  13710. return interfaceFunction.size;
  13711. }
  13712. return null;
  13713. }
  13714. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13715. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  13716. interfaceFunction.propertyIndex = shape.ix;
  13717. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  13718. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  13719. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  13720. Object.defineProperties(interfaceFunction, {
  13721. position: {
  13722. get: ExpressionPropertyInterface(prop.p)
  13723. },
  13724. roundness: {
  13725. get: ExpressionPropertyInterface(prop.r)
  13726. },
  13727. size: {
  13728. get: ExpressionPropertyInterface(prop.s)
  13729. },
  13730. _name: {
  13731. value: shape.nm
  13732. }
  13733. });
  13734. interfaceFunction.mn = shape.mn;
  13735. return interfaceFunction;
  13736. }
  13737. function roundedInterfaceFactory(shape, view, propertyGroup) {
  13738. function interfaceFunction(value) {
  13739. if (shape.r.ix === value || value === 'Round Corners 1') {
  13740. return interfaceFunction.radius;
  13741. }
  13742. return null;
  13743. }
  13744. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13745. var prop = view;
  13746. interfaceFunction.propertyIndex = shape.ix;
  13747. prop.rd.setGroupProperty(PropertyInterface('Radius', _propertyGroup));
  13748. Object.defineProperties(interfaceFunction, {
  13749. radius: {
  13750. get: ExpressionPropertyInterface(prop.rd)
  13751. },
  13752. _name: {
  13753. value: shape.nm
  13754. }
  13755. });
  13756. interfaceFunction.mn = shape.mn;
  13757. return interfaceFunction;
  13758. }
  13759. function repeaterInterfaceFactory(shape, view, propertyGroup) {
  13760. function interfaceFunction(value) {
  13761. if (shape.c.ix === value || value === 'Copies') {
  13762. return interfaceFunction.copies;
  13763. }
  13764. if (shape.o.ix === value || value === 'Offset') {
  13765. return interfaceFunction.offset;
  13766. }
  13767. return null;
  13768. }
  13769. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13770. var prop = view;
  13771. interfaceFunction.propertyIndex = shape.ix;
  13772. prop.c.setGroupProperty(PropertyInterface('Copies', _propertyGroup));
  13773. prop.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  13774. Object.defineProperties(interfaceFunction, {
  13775. copies: {
  13776. get: ExpressionPropertyInterface(prop.c)
  13777. },
  13778. offset: {
  13779. get: ExpressionPropertyInterface(prop.o)
  13780. },
  13781. _name: {
  13782. value: shape.nm
  13783. }
  13784. });
  13785. interfaceFunction.mn = shape.mn;
  13786. return interfaceFunction;
  13787. }
  13788. return function (shapes, view, propertyGroup) {
  13789. var interfaces;
  13790. function _interfaceFunction(value) {
  13791. if (typeof value === 'number') {
  13792. value = value === undefined ? 1 : value;
  13793. if (value === 0) {
  13794. return propertyGroup;
  13795. }
  13796. return interfaces[value - 1];
  13797. }
  13798. var i = 0;
  13799. var len = interfaces.length;
  13800. while (i < len) {
  13801. if (interfaces[i]._name === value) {
  13802. return interfaces[i];
  13803. }
  13804. i += 1;
  13805. }
  13806. return null;
  13807. }
  13808. function parentGroupWrapper() {
  13809. return propertyGroup;
  13810. }
  13811. _interfaceFunction.propertyGroup = propertyGroupFactory(_interfaceFunction, parentGroupWrapper);
  13812. interfaces = iterateElements(shapes, view, _interfaceFunction.propertyGroup);
  13813. _interfaceFunction.numProperties = interfaces.length;
  13814. _interfaceFunction._name = 'Contents';
  13815. return _interfaceFunction;
  13816. };
  13817. }();
  13818. var TextExpressionInterface = function () {
  13819. return function (elem) {
  13820. var _sourceText;
  13821. function _thisLayerFunction(name) {
  13822. switch (name) {
  13823. case 'ADBE Text Document':
  13824. return _thisLayerFunction.sourceText;
  13825. default:
  13826. return null;
  13827. }
  13828. }
  13829. Object.defineProperty(_thisLayerFunction, 'sourceText', {
  13830. get: function get() {
  13831. elem.textProperty.getValue();
  13832. var stringValue = elem.textProperty.currentData.t;
  13833. if (!_sourceText || stringValue !== _sourceText.value) {
  13834. _sourceText = new String(stringValue); // eslint-disable-line no-new-wrappers
  13835. // If stringValue is an empty string, eval returns undefined, so it has to be returned as a String primitive
  13836. _sourceText.value = stringValue || new String(stringValue); // eslint-disable-line no-new-wrappers
  13837. Object.defineProperty(_sourceText, 'style', {
  13838. get: function get() {
  13839. return {
  13840. fillColor: elem.textProperty.currentData.fc
  13841. };
  13842. }
  13843. });
  13844. }
  13845. return _sourceText;
  13846. }
  13847. });
  13848. return _thisLayerFunction;
  13849. };
  13850. }();
  13851. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13852. var FootageInterface = function () {
  13853. var outlineInterfaceFactory = function outlineInterfaceFactory(elem) {
  13854. var currentPropertyName = '';
  13855. var currentProperty = elem.getFootageData();
  13856. function init() {
  13857. currentPropertyName = '';
  13858. currentProperty = elem.getFootageData();
  13859. return searchProperty;
  13860. }
  13861. function searchProperty(value) {
  13862. if (currentProperty[value]) {
  13863. currentPropertyName = value;
  13864. currentProperty = currentProperty[value];
  13865. if (_typeof(currentProperty) === 'object') {
  13866. return searchProperty;
  13867. }
  13868. return currentProperty;
  13869. }
  13870. var propertyNameIndex = value.indexOf(currentPropertyName);
  13871. if (propertyNameIndex !== -1) {
  13872. var index = parseInt(value.substr(propertyNameIndex + currentPropertyName.length), 10);
  13873. currentProperty = currentProperty[index];
  13874. if (_typeof(currentProperty) === 'object') {
  13875. return searchProperty;
  13876. }
  13877. return currentProperty;
  13878. }
  13879. return '';
  13880. }
  13881. return init;
  13882. };
  13883. var dataInterfaceFactory = function dataInterfaceFactory(elem) {
  13884. function interfaceFunction(value) {
  13885. if (value === 'Outline') {
  13886. return interfaceFunction.outlineInterface();
  13887. }
  13888. return null;
  13889. }
  13890. interfaceFunction._name = 'Outline';
  13891. interfaceFunction.outlineInterface = outlineInterfaceFactory(elem);
  13892. return interfaceFunction;
  13893. };
  13894. return function (elem) {
  13895. function _interfaceFunction(value) {
  13896. if (value === 'Data') {
  13897. return _interfaceFunction.dataInterface;
  13898. }
  13899. return null;
  13900. }
  13901. _interfaceFunction._name = 'Data';
  13902. _interfaceFunction.dataInterface = dataInterfaceFactory(elem);
  13903. return _interfaceFunction;
  13904. };
  13905. }();
  13906. var interfaces = {
  13907. layer: LayerExpressionInterface,
  13908. effects: EffectsExpressionInterface,
  13909. comp: CompExpressionInterface,
  13910. shape: ShapeExpressionInterface,
  13911. text: TextExpressionInterface,
  13912. footage: FootageInterface
  13913. };
  13914. function getInterface(type) {
  13915. return interfaces[type] || null;
  13916. }
  13917. var expressionHelpers = function () {
  13918. function searchExpressions(elem, data, prop) {
  13919. if (data.x) {
  13920. prop.k = true;
  13921. prop.x = true;
  13922. prop.initiateExpression = ExpressionManager.initiateExpression;
  13923. prop.effectsSequence.push(prop.initiateExpression(elem, data, prop).bind(prop));
  13924. }
  13925. }
  13926. function getValueAtTime(frameNum) {
  13927. frameNum *= this.elem.globalData.frameRate;
  13928. frameNum -= this.offsetTime;
  13929. if (frameNum !== this._cachingAtTime.lastFrame) {
  13930. this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
  13931. this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
  13932. this._cachingAtTime.lastFrame = frameNum;
  13933. }
  13934. return this._cachingAtTime.value;
  13935. }
  13936. function getSpeedAtTime(frameNum) {
  13937. var delta = -0.01;
  13938. var v1 = this.getValueAtTime(frameNum);
  13939. var v2 = this.getValueAtTime(frameNum + delta);
  13940. var speed = 0;
  13941. if (v1.length) {
  13942. var i;
  13943. for (i = 0; i < v1.length; i += 1) {
  13944. speed += Math.pow(v2[i] - v1[i], 2);
  13945. }
  13946. speed = Math.sqrt(speed) * 100;
  13947. } else {
  13948. speed = 0;
  13949. }
  13950. return speed;
  13951. }
  13952. function getVelocityAtTime(frameNum) {
  13953. if (this.vel !== undefined) {
  13954. return this.vel;
  13955. }
  13956. var delta = -0.001; // frameNum += this.elem.data.st;
  13957. var v1 = this.getValueAtTime(frameNum);
  13958. var v2 = this.getValueAtTime(frameNum + delta);
  13959. var velocity;
  13960. if (v1.length) {
  13961. velocity = createTypedArray('float32', v1.length);
  13962. var i;
  13963. for (i = 0; i < v1.length; i += 1) {
  13964. // removing frameRate
  13965. // if needed, don't add it here
  13966. // velocity[i] = this.elem.globalData.frameRate*((v2[i] - v1[i])/delta);
  13967. velocity[i] = (v2[i] - v1[i]) / delta;
  13968. }
  13969. } else {
  13970. velocity = (v2 - v1) / delta;
  13971. }
  13972. return velocity;
  13973. }
  13974. function getStaticValueAtTime() {
  13975. return this.pv;
  13976. }
  13977. function setGroupProperty(propertyGroup) {
  13978. this.propertyGroup = propertyGroup;
  13979. }
  13980. return {
  13981. searchExpressions: searchExpressions,
  13982. getSpeedAtTime: getSpeedAtTime,
  13983. getVelocityAtTime: getVelocityAtTime,
  13984. getValueAtTime: getValueAtTime,
  13985. getStaticValueAtTime: getStaticValueAtTime,
  13986. setGroupProperty: setGroupProperty
  13987. };
  13988. }();
  13989. function addPropertyDecorator() {
  13990. function loopOut(type, duration, durationFlag) {
  13991. if (!this.k || !this.keyframes) {
  13992. return this.pv;
  13993. }
  13994. type = type ? type.toLowerCase() : '';
  13995. var currentFrame = this.comp.renderedFrame;
  13996. var keyframes = this.keyframes;
  13997. var lastKeyFrame = keyframes[keyframes.length - 1].t;
  13998. if (currentFrame <= lastKeyFrame) {
  13999. return this.pv;
  14000. }
  14001. var cycleDuration;
  14002. var firstKeyFrame;
  14003. if (!durationFlag) {
  14004. if (!duration || duration > keyframes.length - 1) {
  14005. duration = keyframes.length - 1;
  14006. }
  14007. firstKeyFrame = keyframes[keyframes.length - 1 - duration].t;
  14008. cycleDuration = lastKeyFrame - firstKeyFrame;
  14009. } else {
  14010. if (!duration) {
  14011. cycleDuration = Math.max(0, lastKeyFrame - this.elem.data.ip);
  14012. } else {
  14013. cycleDuration = Math.abs(lastKeyFrame - this.elem.comp.globalData.frameRate * duration);
  14014. }
  14015. firstKeyFrame = lastKeyFrame - cycleDuration;
  14016. }
  14017. var i;
  14018. var len;
  14019. var ret;
  14020. if (type === 'pingpong') {
  14021. var iterations = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  14022. if (iterations % 2 !== 0) {
  14023. return this.getValueAtTime((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14024. }
  14025. } else if (type === 'offset') {
  14026. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  14027. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  14028. var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14029. var repeats = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  14030. if (this.pv.length) {
  14031. ret = new Array(initV.length);
  14032. len = ret.length;
  14033. for (i = 0; i < len; i += 1) {
  14034. ret[i] = (endV[i] - initV[i]) * repeats + current[i];
  14035. }
  14036. return ret;
  14037. }
  14038. return (endV - initV) * repeats + current;
  14039. } else if (type === 'continue') {
  14040. var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  14041. var nextLastValue = this.getValueAtTime((lastKeyFrame - 0.001) / this.comp.globalData.frameRate, 0);
  14042. if (this.pv.length) {
  14043. ret = new Array(lastValue.length);
  14044. len = ret.length;
  14045. for (i = 0; i < len; i += 1) {
  14046. ret[i] = lastValue[i] + (lastValue[i] - nextLastValue[i]) * ((currentFrame - lastKeyFrame) / this.comp.globalData.frameRate) / 0.0005; // eslint-disable-line
  14047. }
  14048. return ret;
  14049. }
  14050. return lastValue + (lastValue - nextLastValue) * ((currentFrame - lastKeyFrame) / 0.001);
  14051. }
  14052. return this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14053. }
  14054. function loopIn(type, duration, durationFlag) {
  14055. if (!this.k) {
  14056. return this.pv;
  14057. }
  14058. type = type ? type.toLowerCase() : '';
  14059. var currentFrame = this.comp.renderedFrame;
  14060. var keyframes = this.keyframes;
  14061. var firstKeyFrame = keyframes[0].t;
  14062. if (currentFrame >= firstKeyFrame) {
  14063. return this.pv;
  14064. }
  14065. var cycleDuration;
  14066. var lastKeyFrame;
  14067. if (!durationFlag) {
  14068. if (!duration || duration > keyframes.length - 1) {
  14069. duration = keyframes.length - 1;
  14070. }
  14071. lastKeyFrame = keyframes[duration].t;
  14072. cycleDuration = lastKeyFrame - firstKeyFrame;
  14073. } else {
  14074. if (!duration) {
  14075. cycleDuration = Math.max(0, this.elem.data.op - firstKeyFrame);
  14076. } else {
  14077. cycleDuration = Math.abs(this.elem.comp.globalData.frameRate * duration);
  14078. }
  14079. lastKeyFrame = firstKeyFrame + cycleDuration;
  14080. }
  14081. var i;
  14082. var len;
  14083. var ret;
  14084. if (type === 'pingpong') {
  14085. var iterations = Math.floor((firstKeyFrame - currentFrame) / cycleDuration);
  14086. if (iterations % 2 === 0) {
  14087. return this.getValueAtTime(((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14088. }
  14089. } else if (type === 'offset') {
  14090. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  14091. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  14092. var current = this.getValueAtTime((cycleDuration - (firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
  14093. var repeats = Math.floor((firstKeyFrame - currentFrame) / cycleDuration) + 1;
  14094. if (this.pv.length) {
  14095. ret = new Array(initV.length);
  14096. len = ret.length;
  14097. for (i = 0; i < len; i += 1) {
  14098. ret[i] = current[i] - (endV[i] - initV[i]) * repeats;
  14099. }
  14100. return ret;
  14101. }
  14102. return current - (endV - initV) * repeats;
  14103. } else if (type === 'continue') {
  14104. var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  14105. var nextFirstValue = this.getValueAtTime((firstKeyFrame + 0.001) / this.comp.globalData.frameRate, 0);
  14106. if (this.pv.length) {
  14107. ret = new Array(firstValue.length);
  14108. len = ret.length;
  14109. for (i = 0; i < len; i += 1) {
  14110. ret[i] = firstValue[i] + (firstValue[i] - nextFirstValue[i]) * (firstKeyFrame - currentFrame) / 0.001;
  14111. }
  14112. return ret;
  14113. }
  14114. return firstValue + (firstValue - nextFirstValue) * (firstKeyFrame - currentFrame) / 0.001;
  14115. }
  14116. return this.getValueAtTime((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14117. }
  14118. function smooth(width, samples) {
  14119. if (!this.k) {
  14120. return this.pv;
  14121. }
  14122. width = (width || 0.4) * 0.5;
  14123. samples = Math.floor(samples || 5);
  14124. if (samples <= 1) {
  14125. return this.pv;
  14126. }
  14127. var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate;
  14128. var initFrame = currentTime - width;
  14129. var endFrame = currentTime + width;
  14130. var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1;
  14131. var i = 0;
  14132. var j = 0;
  14133. var value;
  14134. if (this.pv.length) {
  14135. value = createTypedArray('float32', this.pv.length);
  14136. } else {
  14137. value = 0;
  14138. }
  14139. var sampleValue;
  14140. while (i < samples) {
  14141. sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency);
  14142. if (this.pv.length) {
  14143. for (j = 0; j < this.pv.length; j += 1) {
  14144. value[j] += sampleValue[j];
  14145. }
  14146. } else {
  14147. value += sampleValue;
  14148. }
  14149. i += 1;
  14150. }
  14151. if (this.pv.length) {
  14152. for (j = 0; j < this.pv.length; j += 1) {
  14153. value[j] /= samples;
  14154. }
  14155. } else {
  14156. value /= samples;
  14157. }
  14158. return value;
  14159. }
  14160. function getTransformValueAtTime(time) {
  14161. if (!this._transformCachingAtTime) {
  14162. this._transformCachingAtTime = {
  14163. v: new Matrix()
  14164. };
  14165. } /// /
  14166. var matrix = this._transformCachingAtTime.v;
  14167. matrix.cloneFromProps(this.pre.props);
  14168. if (this.appliedTransformations < 1) {
  14169. var anchor = this.a.getValueAtTime(time);
  14170. matrix.translate(-anchor[0] * this.a.mult, -anchor[1] * this.a.mult, anchor[2] * this.a.mult);
  14171. }
  14172. if (this.appliedTransformations < 2) {
  14173. var scale = this.s.getValueAtTime(time);
  14174. matrix.scale(scale[0] * this.s.mult, scale[1] * this.s.mult, scale[2] * this.s.mult);
  14175. }
  14176. if (this.sk && this.appliedTransformations < 3) {
  14177. var skew = this.sk.getValueAtTime(time);
  14178. var skewAxis = this.sa.getValueAtTime(time);
  14179. matrix.skewFromAxis(-skew * this.sk.mult, skewAxis * this.sa.mult);
  14180. }
  14181. if (this.r && this.appliedTransformations < 4) {
  14182. var rotation = this.r.getValueAtTime(time);
  14183. matrix.rotate(-rotation * this.r.mult);
  14184. } else if (!this.r && this.appliedTransformations < 4) {
  14185. var rotationZ = this.rz.getValueAtTime(time);
  14186. var rotationY = this.ry.getValueAtTime(time);
  14187. var rotationX = this.rx.getValueAtTime(time);
  14188. var orientation = this.or.getValueAtTime(time);
  14189. matrix.rotateZ(-rotationZ * this.rz.mult).rotateY(rotationY * this.ry.mult).rotateX(rotationX * this.rx.mult).rotateZ(-orientation[2] * this.or.mult).rotateY(orientation[1] * this.or.mult).rotateX(orientation[0] * this.or.mult);
  14190. }
  14191. if (this.data.p && this.data.p.s) {
  14192. var positionX = this.px.getValueAtTime(time);
  14193. var positionY = this.py.getValueAtTime(time);
  14194. if (this.data.p.z) {
  14195. var positionZ = this.pz.getValueAtTime(time);
  14196. matrix.translate(positionX * this.px.mult, positionY * this.py.mult, -positionZ * this.pz.mult);
  14197. } else {
  14198. matrix.translate(positionX * this.px.mult, positionY * this.py.mult, 0);
  14199. }
  14200. } else {
  14201. var position = this.p.getValueAtTime(time);
  14202. matrix.translate(position[0] * this.p.mult, position[1] * this.p.mult, -position[2] * this.p.mult);
  14203. }
  14204. return matrix; /// /
  14205. }
  14206. function getTransformStaticValueAtTime() {
  14207. return this.v.clone(new Matrix());
  14208. }
  14209. var getTransformProperty = TransformPropertyFactory.getTransformProperty;
  14210. TransformPropertyFactory.getTransformProperty = function (elem, data, container) {
  14211. var prop = getTransformProperty(elem, data, container);
  14212. if (prop.dynamicProperties.length) {
  14213. prop.getValueAtTime = getTransformValueAtTime.bind(prop);
  14214. } else {
  14215. prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop);
  14216. }
  14217. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  14218. return prop;
  14219. };
  14220. var propertyGetProp = PropertyFactory.getProp;
  14221. PropertyFactory.getProp = function (elem, data, type, mult, container) {
  14222. var prop = propertyGetProp(elem, data, type, mult, container); // prop.getVelocityAtTime = getVelocityAtTime;
  14223. // prop.loopOut = loopOut;
  14224. // prop.loopIn = loopIn;
  14225. if (prop.kf) {
  14226. prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop);
  14227. } else {
  14228. prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop);
  14229. }
  14230. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  14231. prop.loopOut = loopOut;
  14232. prop.loopIn = loopIn;
  14233. prop.smooth = smooth;
  14234. prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop);
  14235. prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop);
  14236. prop.numKeys = data.a === 1 ? data.k.length : 0;
  14237. prop.propertyIndex = data.ix;
  14238. var value = 0;
  14239. if (type !== 0) {
  14240. value = createTypedArray('float32', data.a === 1 ? data.k[0].s.length : data.k.length);
  14241. }
  14242. prop._cachingAtTime = {
  14243. lastFrame: initialDefaultFrame,
  14244. lastIndex: 0,
  14245. value: value
  14246. };
  14247. expressionHelpers.searchExpressions(elem, data, prop);
  14248. if (prop.k) {
  14249. container.addDynamicProperty(prop);
  14250. }
  14251. return prop;
  14252. };
  14253. function getShapeValueAtTime(frameNum) {
  14254. // For now this caching object is created only when needed instead of creating it when the shape is initialized.
  14255. if (!this._cachingAtTime) {
  14256. this._cachingAtTime = {
  14257. shapeValue: shapePool.clone(this.pv),
  14258. lastIndex: 0,
  14259. lastTime: initialDefaultFrame
  14260. };
  14261. }
  14262. frameNum *= this.elem.globalData.frameRate;
  14263. frameNum -= this.offsetTime;
  14264. if (frameNum !== this._cachingAtTime.lastTime) {
  14265. this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0;
  14266. this._cachingAtTime.lastTime = frameNum;
  14267. this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime);
  14268. }
  14269. return this._cachingAtTime.shapeValue;
  14270. }
  14271. var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction();
  14272. var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction();
  14273. function ShapeExpressions() {}
  14274. ShapeExpressions.prototype = {
  14275. vertices: function vertices(prop, time) {
  14276. if (this.k) {
  14277. this.getValue();
  14278. }
  14279. var shapePath = this.v;
  14280. if (time !== undefined) {
  14281. shapePath = this.getValueAtTime(time, 0);
  14282. }
  14283. var i;
  14284. var len = shapePath._length;
  14285. var vertices = shapePath[prop];
  14286. var points = shapePath.v;
  14287. var arr = createSizedArray(len);
  14288. for (i = 0; i < len; i += 1) {
  14289. if (prop === 'i' || prop === 'o') {
  14290. arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]];
  14291. } else {
  14292. arr[i] = [vertices[i][0], vertices[i][1]];
  14293. }
  14294. }
  14295. return arr;
  14296. },
  14297. points: function points(time) {
  14298. return this.vertices('v', time);
  14299. },
  14300. inTangents: function inTangents(time) {
  14301. return this.vertices('i', time);
  14302. },
  14303. outTangents: function outTangents(time) {
  14304. return this.vertices('o', time);
  14305. },
  14306. isClosed: function isClosed() {
  14307. return this.v.c;
  14308. },
  14309. pointOnPath: function pointOnPath(perc, time) {
  14310. var shapePath = this.v;
  14311. if (time !== undefined) {
  14312. shapePath = this.getValueAtTime(time, 0);
  14313. }
  14314. if (!this._segmentsLength) {
  14315. this._segmentsLength = bez.getSegmentsLength(shapePath);
  14316. }
  14317. var segmentsLength = this._segmentsLength;
  14318. var lengths = segmentsLength.lengths;
  14319. var lengthPos = segmentsLength.totalLength * perc;
  14320. var i = 0;
  14321. var len = lengths.length;
  14322. var accumulatedLength = 0;
  14323. var pt;
  14324. while (i < len) {
  14325. if (accumulatedLength + lengths[i].addedLength > lengthPos) {
  14326. var initIndex = i;
  14327. var endIndex = shapePath.c && i === len - 1 ? 0 : i + 1;
  14328. var segmentPerc = (lengthPos - accumulatedLength) / lengths[i].addedLength;
  14329. pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]);
  14330. break;
  14331. } else {
  14332. accumulatedLength += lengths[i].addedLength;
  14333. }
  14334. i += 1;
  14335. }
  14336. if (!pt) {
  14337. pt = shapePath.c ? [shapePath.v[0][0], shapePath.v[0][1]] : [shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1]];
  14338. }
  14339. return pt;
  14340. },
  14341. vectorOnPath: function vectorOnPath(perc, time, vectorType) {
  14342. // perc doesn't use triple equality because it can be a Number object as well as a primitive.
  14343. if (perc == 1) {
  14344. // eslint-disable-line eqeqeq
  14345. perc = this.v.c;
  14346. } else if (perc == 0) {
  14347. // eslint-disable-line eqeqeq
  14348. perc = 0.999;
  14349. }
  14350. var pt1 = this.pointOnPath(perc, time);
  14351. var pt2 = this.pointOnPath(perc + 0.001, time);
  14352. var xLength = pt2[0] - pt1[0];
  14353. var yLength = pt2[1] - pt1[1];
  14354. var magnitude = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2));
  14355. if (magnitude === 0) {
  14356. return [0, 0];
  14357. }
  14358. var unitVector = vectorType === 'tangent' ? [xLength / magnitude, yLength / magnitude] : [-yLength / magnitude, xLength / magnitude];
  14359. return unitVector;
  14360. },
  14361. tangentOnPath: function tangentOnPath(perc, time) {
  14362. return this.vectorOnPath(perc, time, 'tangent');
  14363. },
  14364. normalOnPath: function normalOnPath(perc, time) {
  14365. return this.vectorOnPath(perc, time, 'normal');
  14366. },
  14367. setGroupProperty: expressionHelpers.setGroupProperty,
  14368. getValueAtTime: expressionHelpers.getStaticValueAtTime
  14369. };
  14370. extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction);
  14371. extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction);
  14372. KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime;
  14373. KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression;
  14374. var propertyGetShapeProp = ShapePropertyFactory.getShapeProp;
  14375. ShapePropertyFactory.getShapeProp = function (elem, data, type, arr, trims) {
  14376. var prop = propertyGetShapeProp(elem, data, type, arr, trims);
  14377. prop.propertyIndex = data.ix;
  14378. prop.lock = false;
  14379. if (type === 3) {
  14380. expressionHelpers.searchExpressions(elem, data.pt, prop);
  14381. } else if (type === 4) {
  14382. expressionHelpers.searchExpressions(elem, data.ks, prop);
  14383. }
  14384. if (prop.k) {
  14385. elem.addDynamicProperty(prop);
  14386. }
  14387. return prop;
  14388. };
  14389. }
  14390. function initialize$1() {
  14391. addPropertyDecorator();
  14392. }
  14393. function addDecorator() {
  14394. function searchExpressions() {
  14395. if (this.data.d.x) {
  14396. this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem, this.data.d, this);
  14397. this.addEffect(this.getExpressionValue.bind(this));
  14398. return true;
  14399. }
  14400. return null;
  14401. }
  14402. TextProperty.prototype.getExpressionValue = function (currentValue, text) {
  14403. var newValue = this.calculateExpression(text);
  14404. if (currentValue.t !== newValue) {
  14405. var newData = {};
  14406. this.copyData(newData, currentValue);
  14407. newData.t = newValue.toString();
  14408. newData.__complete = false;
  14409. return newData;
  14410. }
  14411. return currentValue;
  14412. };
  14413. TextProperty.prototype.searchProperty = function () {
  14414. var isKeyframed = this.searchKeyframes();
  14415. var hasExpressions = this.searchExpressions();
  14416. this.kf = isKeyframed || hasExpressions;
  14417. return this.kf;
  14418. };
  14419. TextProperty.prototype.searchExpressions = searchExpressions;
  14420. }
  14421. function initialize() {
  14422. addDecorator();
  14423. }
  14424. function SVGComposableEffect() {}
  14425. SVGComposableEffect.prototype = {
  14426. createMergeNode: function createMergeNode(resultId, ins) {
  14427. var feMerge = createNS('feMerge');
  14428. feMerge.setAttribute('result', resultId);
  14429. var feMergeNode;
  14430. var i;
  14431. for (i = 0; i < ins.length; i += 1) {
  14432. feMergeNode = createNS('feMergeNode');
  14433. feMergeNode.setAttribute('in', ins[i]);
  14434. feMerge.appendChild(feMergeNode);
  14435. feMerge.appendChild(feMergeNode);
  14436. }
  14437. return feMerge;
  14438. }
  14439. };
  14440. var linearFilterValue = '0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0';
  14441. function SVGTintFilter(filter, filterManager, elem, id, source) {
  14442. this.filterManager = filterManager;
  14443. var feColorMatrix = createNS('feColorMatrix');
  14444. feColorMatrix.setAttribute('type', 'matrix');
  14445. feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB');
  14446. feColorMatrix.setAttribute('values', linearFilterValue + ' 1 0');
  14447. this.linearFilter = feColorMatrix;
  14448. feColorMatrix.setAttribute('result', id + '_tint_1');
  14449. filter.appendChild(feColorMatrix);
  14450. feColorMatrix = createNS('feColorMatrix');
  14451. feColorMatrix.setAttribute('type', 'matrix');
  14452. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  14453. feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0');
  14454. feColorMatrix.setAttribute('result', id + '_tint_2');
  14455. filter.appendChild(feColorMatrix);
  14456. this.matrixFilter = feColorMatrix;
  14457. var feMerge = this.createMergeNode(id, [source, id + '_tint_1', id + '_tint_2']);
  14458. filter.appendChild(feMerge);
  14459. }
  14460. extendPrototype([SVGComposableEffect], SVGTintFilter);
  14461. SVGTintFilter.prototype.renderFrame = function (forceRender) {
  14462. if (forceRender || this.filterManager._mdf) {
  14463. var colorBlack = this.filterManager.effectElements[0].p.v;
  14464. var colorWhite = this.filterManager.effectElements[1].p.v;
  14465. var opacity = this.filterManager.effectElements[2].p.v / 100;
  14466. this.linearFilter.setAttribute('values', linearFilterValue + ' ' + opacity + ' 0');
  14467. this.matrixFilter.setAttribute('values', colorWhite[0] - colorBlack[0] + ' 0 0 0 ' + colorBlack[0] + ' ' + (colorWhite[1] - colorBlack[1]) + ' 0 0 0 ' + colorBlack[1] + ' ' + (colorWhite[2] - colorBlack[2]) + ' 0 0 0 ' + colorBlack[2] + ' 0 0 0 1 0');
  14468. }
  14469. };
  14470. function SVGFillFilter(filter, filterManager, elem, id) {
  14471. this.filterManager = filterManager;
  14472. var feColorMatrix = createNS('feColorMatrix');
  14473. feColorMatrix.setAttribute('type', 'matrix');
  14474. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  14475. feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0');
  14476. feColorMatrix.setAttribute('result', id);
  14477. filter.appendChild(feColorMatrix);
  14478. this.matrixFilter = feColorMatrix;
  14479. }
  14480. SVGFillFilter.prototype.renderFrame = function (forceRender) {
  14481. if (forceRender || this.filterManager._mdf) {
  14482. var color = this.filterManager.effectElements[2].p.v;
  14483. var opacity = this.filterManager.effectElements[6].p.v;
  14484. this.matrixFilter.setAttribute('values', '0 0 0 0 ' + color[0] + ' 0 0 0 0 ' + color[1] + ' 0 0 0 0 ' + color[2] + ' 0 0 0 ' + opacity + ' 0');
  14485. }
  14486. };
  14487. function SVGStrokeEffect(fil, filterManager, elem) {
  14488. this.initialized = false;
  14489. this.filterManager = filterManager;
  14490. this.elem = elem;
  14491. this.paths = [];
  14492. }
  14493. SVGStrokeEffect.prototype.initialize = function () {
  14494. var elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes;
  14495. var path;
  14496. var groupPath;
  14497. var i;
  14498. var len;
  14499. if (this.filterManager.effectElements[1].p.v === 1) {
  14500. len = this.elem.maskManager.masksProperties.length;
  14501. i = 0;
  14502. } else {
  14503. i = this.filterManager.effectElements[0].p.v - 1;
  14504. len = i + 1;
  14505. }
  14506. groupPath = createNS('g');
  14507. groupPath.setAttribute('fill', 'none');
  14508. groupPath.setAttribute('stroke-linecap', 'round');
  14509. groupPath.setAttribute('stroke-dashoffset', 1);
  14510. for (i; i < len; i += 1) {
  14511. path = createNS('path');
  14512. groupPath.appendChild(path);
  14513. this.paths.push({
  14514. p: path,
  14515. m: i
  14516. });
  14517. }
  14518. if (this.filterManager.effectElements[10].p.v === 3) {
  14519. var mask = createNS('mask');
  14520. var id = createElementID();
  14521. mask.setAttribute('id', id);
  14522. mask.setAttribute('mask-type', 'alpha');
  14523. mask.appendChild(groupPath);
  14524. this.elem.globalData.defs.appendChild(mask);
  14525. var g = createNS('g');
  14526. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  14527. while (elemChildren[0]) {
  14528. g.appendChild(elemChildren[0]);
  14529. }
  14530. this.elem.layerElement.appendChild(g);
  14531. this.masker = mask;
  14532. groupPath.setAttribute('stroke', '#fff');
  14533. } else if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) {
  14534. if (this.filterManager.effectElements[10].p.v === 2) {
  14535. elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes;
  14536. while (elemChildren.length) {
  14537. this.elem.layerElement.removeChild(elemChildren[0]);
  14538. }
  14539. }
  14540. this.elem.layerElement.appendChild(groupPath);
  14541. this.elem.layerElement.removeAttribute('mask');
  14542. groupPath.setAttribute('stroke', '#fff');
  14543. }
  14544. this.initialized = true;
  14545. this.pathMasker = groupPath;
  14546. };
  14547. SVGStrokeEffect.prototype.renderFrame = function (forceRender) {
  14548. if (!this.initialized) {
  14549. this.initialize();
  14550. }
  14551. var i;
  14552. var len = this.paths.length;
  14553. var mask;
  14554. var path;
  14555. for (i = 0; i < len; i += 1) {
  14556. if (this.paths[i].m !== -1) {
  14557. mask = this.elem.maskManager.viewData[this.paths[i].m];
  14558. path = this.paths[i].p;
  14559. if (forceRender || this.filterManager._mdf || mask.prop._mdf) {
  14560. path.setAttribute('d', mask.lastPath);
  14561. }
  14562. if (forceRender || this.filterManager.effectElements[9].p._mdf || this.filterManager.effectElements[4].p._mdf || this.filterManager.effectElements[7].p._mdf || this.filterManager.effectElements[8].p._mdf || mask.prop._mdf) {
  14563. var dasharrayValue;
  14564. if (this.filterManager.effectElements[7].p.v !== 0 || this.filterManager.effectElements[8].p.v !== 100) {
  14565. var s = Math.min(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01;
  14566. var e = Math.max(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01;
  14567. var l = path.getTotalLength();
  14568. dasharrayValue = '0 0 0 ' + l * s + ' ';
  14569. var lineLength = l * (e - s);
  14570. var segment = 1 + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01;
  14571. var units = Math.floor(lineLength / segment);
  14572. var j;
  14573. for (j = 0; j < units; j += 1) {
  14574. dasharrayValue += '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01 + ' ';
  14575. }
  14576. dasharrayValue += '0 ' + l * 10 + ' 0 0';
  14577. } else {
  14578. dasharrayValue = '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01;
  14579. }
  14580. path.setAttribute('stroke-dasharray', dasharrayValue);
  14581. }
  14582. }
  14583. }
  14584. if (forceRender || this.filterManager.effectElements[4].p._mdf) {
  14585. this.pathMasker.setAttribute('stroke-width', this.filterManager.effectElements[4].p.v * 2);
  14586. }
  14587. if (forceRender || this.filterManager.effectElements[6].p._mdf) {
  14588. this.pathMasker.setAttribute('opacity', this.filterManager.effectElements[6].p.v);
  14589. }
  14590. if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) {
  14591. if (forceRender || this.filterManager.effectElements[3].p._mdf) {
  14592. var color = this.filterManager.effectElements[3].p.v;
  14593. this.pathMasker.setAttribute('stroke', 'rgb(' + bmFloor(color[0] * 255) + ',' + bmFloor(color[1] * 255) + ',' + bmFloor(color[2] * 255) + ')');
  14594. }
  14595. }
  14596. };
  14597. function SVGTritoneFilter(filter, filterManager, elem, id) {
  14598. this.filterManager = filterManager;
  14599. var feColorMatrix = createNS('feColorMatrix');
  14600. feColorMatrix.setAttribute('type', 'matrix');
  14601. feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB');
  14602. feColorMatrix.setAttribute('values', '0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0');
  14603. filter.appendChild(feColorMatrix);
  14604. var feComponentTransfer = createNS('feComponentTransfer');
  14605. feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB');
  14606. feComponentTransfer.setAttribute('result', id);
  14607. this.matrixFilter = feComponentTransfer;
  14608. var feFuncR = createNS('feFuncR');
  14609. feFuncR.setAttribute('type', 'table');
  14610. feComponentTransfer.appendChild(feFuncR);
  14611. this.feFuncR = feFuncR;
  14612. var feFuncG = createNS('feFuncG');
  14613. feFuncG.setAttribute('type', 'table');
  14614. feComponentTransfer.appendChild(feFuncG);
  14615. this.feFuncG = feFuncG;
  14616. var feFuncB = createNS('feFuncB');
  14617. feFuncB.setAttribute('type', 'table');
  14618. feComponentTransfer.appendChild(feFuncB);
  14619. this.feFuncB = feFuncB;
  14620. filter.appendChild(feComponentTransfer);
  14621. }
  14622. SVGTritoneFilter.prototype.renderFrame = function (forceRender) {
  14623. if (forceRender || this.filterManager._mdf) {
  14624. var color1 = this.filterManager.effectElements[0].p.v;
  14625. var color2 = this.filterManager.effectElements[1].p.v;
  14626. var color3 = this.filterManager.effectElements[2].p.v;
  14627. var tableR = color3[0] + ' ' + color2[0] + ' ' + color1[0];
  14628. var tableG = color3[1] + ' ' + color2[1] + ' ' + color1[1];
  14629. var tableB = color3[2] + ' ' + color2[2] + ' ' + color1[2];
  14630. this.feFuncR.setAttribute('tableValues', tableR);
  14631. this.feFuncG.setAttribute('tableValues', tableG);
  14632. this.feFuncB.setAttribute('tableValues', tableB);
  14633. }
  14634. };
  14635. function SVGProLevelsFilter(filter, filterManager, elem, id) {
  14636. this.filterManager = filterManager;
  14637. var effectElements = this.filterManager.effectElements;
  14638. var feComponentTransfer = createNS('feComponentTransfer'); // Red
  14639. if (effectElements[10].p.k || effectElements[10].p.v !== 0 || effectElements[11].p.k || effectElements[11].p.v !== 1 || effectElements[12].p.k || effectElements[12].p.v !== 1 || effectElements[13].p.k || effectElements[13].p.v !== 0 || effectElements[14].p.k || effectElements[14].p.v !== 1) {
  14640. this.feFuncR = this.createFeFunc('feFuncR', feComponentTransfer);
  14641. } // Green
  14642. if (effectElements[17].p.k || effectElements[17].p.v !== 0 || effectElements[18].p.k || effectElements[18].p.v !== 1 || effectElements[19].p.k || effectElements[19].p.v !== 1 || effectElements[20].p.k || effectElements[20].p.v !== 0 || effectElements[21].p.k || effectElements[21].p.v !== 1) {
  14643. this.feFuncG = this.createFeFunc('feFuncG', feComponentTransfer);
  14644. } // Blue
  14645. if (effectElements[24].p.k || effectElements[24].p.v !== 0 || effectElements[25].p.k || effectElements[25].p.v !== 1 || effectElements[26].p.k || effectElements[26].p.v !== 1 || effectElements[27].p.k || effectElements[27].p.v !== 0 || effectElements[28].p.k || effectElements[28].p.v !== 1) {
  14646. this.feFuncB = this.createFeFunc('feFuncB', feComponentTransfer);
  14647. } // Alpha
  14648. if (effectElements[31].p.k || effectElements[31].p.v !== 0 || effectElements[32].p.k || effectElements[32].p.v !== 1 || effectElements[33].p.k || effectElements[33].p.v !== 1 || effectElements[34].p.k || effectElements[34].p.v !== 0 || effectElements[35].p.k || effectElements[35].p.v !== 1) {
  14649. this.feFuncA = this.createFeFunc('feFuncA', feComponentTransfer);
  14650. } // RGB
  14651. if (this.feFuncR || this.feFuncG || this.feFuncB || this.feFuncA) {
  14652. feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB');
  14653. filter.appendChild(feComponentTransfer);
  14654. }
  14655. if (effectElements[3].p.k || effectElements[3].p.v !== 0 || effectElements[4].p.k || effectElements[4].p.v !== 1 || effectElements[5].p.k || effectElements[5].p.v !== 1 || effectElements[6].p.k || effectElements[6].p.v !== 0 || effectElements[7].p.k || effectElements[7].p.v !== 1) {
  14656. feComponentTransfer = createNS('feComponentTransfer');
  14657. feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB');
  14658. feComponentTransfer.setAttribute('result', id);
  14659. filter.appendChild(feComponentTransfer);
  14660. this.feFuncRComposed = this.createFeFunc('feFuncR', feComponentTransfer);
  14661. this.feFuncGComposed = this.createFeFunc('feFuncG', feComponentTransfer);
  14662. this.feFuncBComposed = this.createFeFunc('feFuncB', feComponentTransfer);
  14663. }
  14664. }
  14665. SVGProLevelsFilter.prototype.createFeFunc = function (type, feComponentTransfer) {
  14666. var feFunc = createNS(type);
  14667. feFunc.setAttribute('type', 'table');
  14668. feComponentTransfer.appendChild(feFunc);
  14669. return feFunc;
  14670. };
  14671. SVGProLevelsFilter.prototype.getTableValue = function (inputBlack, inputWhite, gamma, outputBlack, outputWhite) {
  14672. var cnt = 0;
  14673. var segments = 256;
  14674. var perc;
  14675. var min = Math.min(inputBlack, inputWhite);
  14676. var max = Math.max(inputBlack, inputWhite);
  14677. var table = Array.call(null, {
  14678. length: segments
  14679. });
  14680. var colorValue;
  14681. var pos = 0;
  14682. var outputDelta = outputWhite - outputBlack;
  14683. var inputDelta = inputWhite - inputBlack;
  14684. while (cnt <= 256) {
  14685. perc = cnt / 256;
  14686. if (perc <= min) {
  14687. colorValue = inputDelta < 0 ? outputWhite : outputBlack;
  14688. } else if (perc >= max) {
  14689. colorValue = inputDelta < 0 ? outputBlack : outputWhite;
  14690. } else {
  14691. colorValue = outputBlack + outputDelta * Math.pow((perc - inputBlack) / inputDelta, 1 / gamma);
  14692. }
  14693. table[pos] = colorValue;
  14694. pos += 1;
  14695. cnt += 256 / (segments - 1);
  14696. }
  14697. return table.join(' ');
  14698. };
  14699. SVGProLevelsFilter.prototype.renderFrame = function (forceRender) {
  14700. if (forceRender || this.filterManager._mdf) {
  14701. var val;
  14702. var effectElements = this.filterManager.effectElements;
  14703. if (this.feFuncRComposed && (forceRender || effectElements[3].p._mdf || effectElements[4].p._mdf || effectElements[5].p._mdf || effectElements[6].p._mdf || effectElements[7].p._mdf)) {
  14704. val = this.getTableValue(effectElements[3].p.v, effectElements[4].p.v, effectElements[5].p.v, effectElements[6].p.v, effectElements[7].p.v);
  14705. this.feFuncRComposed.setAttribute('tableValues', val);
  14706. this.feFuncGComposed.setAttribute('tableValues', val);
  14707. this.feFuncBComposed.setAttribute('tableValues', val);
  14708. }
  14709. if (this.feFuncR && (forceRender || effectElements[10].p._mdf || effectElements[11].p._mdf || effectElements[12].p._mdf || effectElements[13].p._mdf || effectElements[14].p._mdf)) {
  14710. val = this.getTableValue(effectElements[10].p.v, effectElements[11].p.v, effectElements[12].p.v, effectElements[13].p.v, effectElements[14].p.v);
  14711. this.feFuncR.setAttribute('tableValues', val);
  14712. }
  14713. if (this.feFuncG && (forceRender || effectElements[17].p._mdf || effectElements[18].p._mdf || effectElements[19].p._mdf || effectElements[20].p._mdf || effectElements[21].p._mdf)) {
  14714. val = this.getTableValue(effectElements[17].p.v, effectElements[18].p.v, effectElements[19].p.v, effectElements[20].p.v, effectElements[21].p.v);
  14715. this.feFuncG.setAttribute('tableValues', val);
  14716. }
  14717. if (this.feFuncB && (forceRender || effectElements[24].p._mdf || effectElements[25].p._mdf || effectElements[26].p._mdf || effectElements[27].p._mdf || effectElements[28].p._mdf)) {
  14718. val = this.getTableValue(effectElements[24].p.v, effectElements[25].p.v, effectElements[26].p.v, effectElements[27].p.v, effectElements[28].p.v);
  14719. this.feFuncB.setAttribute('tableValues', val);
  14720. }
  14721. if (this.feFuncA && (forceRender || effectElements[31].p._mdf || effectElements[32].p._mdf || effectElements[33].p._mdf || effectElements[34].p._mdf || effectElements[35].p._mdf)) {
  14722. val = this.getTableValue(effectElements[31].p.v, effectElements[32].p.v, effectElements[33].p.v, effectElements[34].p.v, effectElements[35].p.v);
  14723. this.feFuncA.setAttribute('tableValues', val);
  14724. }
  14725. }
  14726. };
  14727. function SVGDropShadowEffect(filter, filterManager, elem, id, source) {
  14728. var globalFilterSize = filterManager.container.globalData.renderConfig.filterSize;
  14729. var filterSize = filterManager.data.fs || globalFilterSize;
  14730. filter.setAttribute('x', filterSize.x || globalFilterSize.x);
  14731. filter.setAttribute('y', filterSize.y || globalFilterSize.y);
  14732. filter.setAttribute('width', filterSize.width || globalFilterSize.width);
  14733. filter.setAttribute('height', filterSize.height || globalFilterSize.height);
  14734. this.filterManager = filterManager;
  14735. var feGaussianBlur = createNS('feGaussianBlur');
  14736. feGaussianBlur.setAttribute('in', 'SourceAlpha');
  14737. feGaussianBlur.setAttribute('result', id + '_drop_shadow_1');
  14738. feGaussianBlur.setAttribute('stdDeviation', '0');
  14739. this.feGaussianBlur = feGaussianBlur;
  14740. filter.appendChild(feGaussianBlur);
  14741. var feOffset = createNS('feOffset');
  14742. feOffset.setAttribute('dx', '25');
  14743. feOffset.setAttribute('dy', '0');
  14744. feOffset.setAttribute('in', id + '_drop_shadow_1');
  14745. feOffset.setAttribute('result', id + '_drop_shadow_2');
  14746. this.feOffset = feOffset;
  14747. filter.appendChild(feOffset);
  14748. var feFlood = createNS('feFlood');
  14749. feFlood.setAttribute('flood-color', '#00ff00');
  14750. feFlood.setAttribute('flood-opacity', '1');
  14751. feFlood.setAttribute('result', id + '_drop_shadow_3');
  14752. this.feFlood = feFlood;
  14753. filter.appendChild(feFlood);
  14754. var feComposite = createNS('feComposite');
  14755. feComposite.setAttribute('in', id + '_drop_shadow_3');
  14756. feComposite.setAttribute('in2', id + '_drop_shadow_2');
  14757. feComposite.setAttribute('operator', 'in');
  14758. feComposite.setAttribute('result', id + '_drop_shadow_4');
  14759. filter.appendChild(feComposite);
  14760. var feMerge = this.createMergeNode(id, [id + '_drop_shadow_4', source]);
  14761. filter.appendChild(feMerge); //
  14762. }
  14763. extendPrototype([SVGComposableEffect], SVGDropShadowEffect);
  14764. SVGDropShadowEffect.prototype.renderFrame = function (forceRender) {
  14765. if (forceRender || this.filterManager._mdf) {
  14766. if (forceRender || this.filterManager.effectElements[4].p._mdf) {
  14767. this.feGaussianBlur.setAttribute('stdDeviation', this.filterManager.effectElements[4].p.v / 4);
  14768. }
  14769. if (forceRender || this.filterManager.effectElements[0].p._mdf) {
  14770. var col = this.filterManager.effectElements[0].p.v;
  14771. this.feFlood.setAttribute('flood-color', rgbToHex(Math.round(col[0] * 255), Math.round(col[1] * 255), Math.round(col[2] * 255)));
  14772. }
  14773. if (forceRender || this.filterManager.effectElements[1].p._mdf) {
  14774. this.feFlood.setAttribute('flood-opacity', this.filterManager.effectElements[1].p.v / 255);
  14775. }
  14776. if (forceRender || this.filterManager.effectElements[2].p._mdf || this.filterManager.effectElements[3].p._mdf) {
  14777. var distance = this.filterManager.effectElements[3].p.v;
  14778. var angle = (this.filterManager.effectElements[2].p.v - 90) * degToRads;
  14779. var x = distance * Math.cos(angle);
  14780. var y = distance * Math.sin(angle);
  14781. this.feOffset.setAttribute('dx', x);
  14782. this.feOffset.setAttribute('dy', y);
  14783. }
  14784. }
  14785. };
  14786. var _svgMatteSymbols = [];
  14787. function SVGMatte3Effect(filterElem, filterManager, elem) {
  14788. this.initialized = false;
  14789. this.filterManager = filterManager;
  14790. this.filterElem = filterElem;
  14791. this.elem = elem;
  14792. elem.matteElement = createNS('g');
  14793. elem.matteElement.appendChild(elem.layerElement);
  14794. elem.matteElement.appendChild(elem.transformedElement);
  14795. elem.baseElement = elem.matteElement;
  14796. }
  14797. SVGMatte3Effect.prototype.findSymbol = function (mask) {
  14798. var i = 0;
  14799. var len = _svgMatteSymbols.length;
  14800. while (i < len) {
  14801. if (_svgMatteSymbols[i] === mask) {
  14802. return _svgMatteSymbols[i];
  14803. }
  14804. i += 1;
  14805. }
  14806. return null;
  14807. };
  14808. SVGMatte3Effect.prototype.replaceInParent = function (mask, symbolId) {
  14809. var parentNode = mask.layerElement.parentNode;
  14810. if (!parentNode) {
  14811. return;
  14812. }
  14813. var children = parentNode.children;
  14814. var i = 0;
  14815. var len = children.length;
  14816. while (i < len) {
  14817. if (children[i] === mask.layerElement) {
  14818. break;
  14819. }
  14820. i += 1;
  14821. }
  14822. var nextChild;
  14823. if (i <= len - 2) {
  14824. nextChild = children[i + 1];
  14825. }
  14826. var useElem = createNS('use');
  14827. useElem.setAttribute('href', '#' + symbolId);
  14828. if (nextChild) {
  14829. parentNode.insertBefore(useElem, nextChild);
  14830. } else {
  14831. parentNode.appendChild(useElem);
  14832. }
  14833. };
  14834. SVGMatte3Effect.prototype.setElementAsMask = function (elem, mask) {
  14835. if (!this.findSymbol(mask)) {
  14836. var symbolId = createElementID();
  14837. var masker = createNS('mask');
  14838. masker.setAttribute('id', mask.layerId);
  14839. masker.setAttribute('mask-type', 'alpha');
  14840. _svgMatteSymbols.push(mask);
  14841. var defs = elem.globalData.defs;
  14842. defs.appendChild(masker);
  14843. var symbol = createNS('symbol');
  14844. symbol.setAttribute('id', symbolId);
  14845. this.replaceInParent(mask, symbolId);
  14846. symbol.appendChild(mask.layerElement);
  14847. defs.appendChild(symbol);
  14848. var useElem = createNS('use');
  14849. useElem.setAttribute('href', '#' + symbolId);
  14850. masker.appendChild(useElem);
  14851. mask.data.hd = false;
  14852. mask.show();
  14853. }
  14854. elem.setMatte(mask.layerId);
  14855. };
  14856. SVGMatte3Effect.prototype.initialize = function () {
  14857. var ind = this.filterManager.effectElements[0].p.v;
  14858. var elements = this.elem.comp.elements;
  14859. var i = 0;
  14860. var len = elements.length;
  14861. while (i < len) {
  14862. if (elements[i] && elements[i].data.ind === ind) {
  14863. this.setElementAsMask(this.elem, elements[i]);
  14864. }
  14865. i += 1;
  14866. }
  14867. this.initialized = true;
  14868. };
  14869. SVGMatte3Effect.prototype.renderFrame = function () {
  14870. if (!this.initialized) {
  14871. this.initialize();
  14872. }
  14873. };
  14874. function SVGGaussianBlurEffect(filter, filterManager, elem, id) {
  14875. // Outset the filter region by 100% on all sides to accommodate blur expansion.
  14876. filter.setAttribute('x', '-100%');
  14877. filter.setAttribute('y', '-100%');
  14878. filter.setAttribute('width', '300%');
  14879. filter.setAttribute('height', '300%');
  14880. this.filterManager = filterManager;
  14881. var feGaussianBlur = createNS('feGaussianBlur');
  14882. feGaussianBlur.setAttribute('result', id);
  14883. filter.appendChild(feGaussianBlur);
  14884. this.feGaussianBlur = feGaussianBlur;
  14885. }
  14886. SVGGaussianBlurEffect.prototype.renderFrame = function (forceRender) {
  14887. if (forceRender || this.filterManager._mdf) {
  14888. // Empirical value, matching AE's blur appearance.
  14889. var kBlurrinessToSigma = 0.3;
  14890. var sigma = this.filterManager.effectElements[0].p.v * kBlurrinessToSigma; // Dimensions mapping:
  14891. //
  14892. // 1 -> horizontal & vertical
  14893. // 2 -> horizontal only
  14894. // 3 -> vertical only
  14895. //
  14896. var dimensions = this.filterManager.effectElements[1].p.v;
  14897. var sigmaX = dimensions == 3 ? 0 : sigma; // eslint-disable-line eqeqeq
  14898. var sigmaY = dimensions == 2 ? 0 : sigma; // eslint-disable-line eqeqeq
  14899. this.feGaussianBlur.setAttribute('stdDeviation', sigmaX + ' ' + sigmaY); // Repeat edges mapping:
  14900. //
  14901. // 0 -> off -> duplicate
  14902. // 1 -> on -> wrap
  14903. var edgeMode = this.filterManager.effectElements[2].p.v == 1 ? 'wrap' : 'duplicate'; // eslint-disable-line eqeqeq
  14904. this.feGaussianBlur.setAttribute('edgeMode', edgeMode);
  14905. }
  14906. };
  14907. function TransformEffect() {}
  14908. TransformEffect.prototype.init = function (effectsManager) {
  14909. this.effectsManager = effectsManager;
  14910. this.type = effectTypes.TRANSFORM_EFFECT;
  14911. this.matrix = new Matrix();
  14912. this.opacity = -1;
  14913. this._mdf = false;
  14914. this._opMdf = false;
  14915. };
  14916. TransformEffect.prototype.renderFrame = function (forceFrame) {
  14917. this._opMdf = false;
  14918. this._mdf = false;
  14919. if (forceFrame || this.effectsManager._mdf) {
  14920. var effectElements = this.effectsManager.effectElements;
  14921. var anchor = effectElements[0].p.v;
  14922. var position = effectElements[1].p.v;
  14923. var isUniformScale = effectElements[2].p.v === 1;
  14924. var scaleHeight = effectElements[3].p.v;
  14925. var scaleWidth = isUniformScale ? scaleHeight : effectElements[4].p.v;
  14926. var skew = effectElements[5].p.v;
  14927. var skewAxis = effectElements[6].p.v;
  14928. var rotation = effectElements[7].p.v;
  14929. this.matrix.reset();
  14930. this.matrix.translate(-anchor[0], -anchor[1], anchor[2]);
  14931. this.matrix.scale(scaleWidth * 0.01, scaleHeight * 0.01, 1);
  14932. this.matrix.rotate(-rotation * degToRads);
  14933. this.matrix.skewFromAxis(-skew * degToRads, (skewAxis + 90) * degToRads);
  14934. this.matrix.translate(position[0], position[1], 0);
  14935. this._mdf = true;
  14936. if (this.opacity !== effectElements[8].p.v) {
  14937. this.opacity = effectElements[8].p.v;
  14938. this._opMdf = true;
  14939. }
  14940. }
  14941. };
  14942. function SVGTransformEffect(_, filterManager) {
  14943. this.init(filterManager);
  14944. }
  14945. extendPrototype([TransformEffect], SVGTransformEffect);
  14946. setExpressionsPlugin(Expressions);
  14947. setExpressionInterfaces(getInterface);
  14948. initialize$1();
  14949. initialize();
  14950. registerEffect$1(20, SVGTintFilter, true);
  14951. registerEffect$1(21, SVGFillFilter, true);
  14952. registerEffect$1(22, SVGStrokeEffect, false);
  14953. registerEffect$1(23, SVGTritoneFilter, true);
  14954. registerEffect$1(24, SVGProLevelsFilter, true);
  14955. registerEffect$1(25, SVGDropShadowEffect, true);
  14956. registerEffect$1(28, SVGMatte3Effect, false);
  14957. registerEffect$1(29, SVGGaussianBlurEffect, true);
  14958. registerEffect$1(35, SVGTransformEffect, false);
  14959. return lottie;
  14960. }));