lottie_canvas.min.js 511 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363
  1. const svgNS = 'http://www.w3.org/2000/svg';
  2. let locationHref = '';
  3. let _useWebWorker = false;
  4. const initialDefaultFrame = -999999;
  5. const setWebWorker = (flag) => { _useWebWorker = !!flag; };
  6. const getWebWorker = () => _useWebWorker;
  7. const setLocationHref = (value) => { locationHref = value; };
  8. const getLocationHref = () => locationHref;
  9. function createTag(type) {
  10. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  11. return document.createElement(type);
  12. }
  13. function extendPrototype(sources, destination) {
  14. var i;
  15. var len = sources.length;
  16. var sourcePrototype;
  17. for (i = 0; i < len; i += 1) {
  18. sourcePrototype = sources[i].prototype;
  19. for (var attr in sourcePrototype) {
  20. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  21. }
  22. }
  23. }
  24. function getDescriptor(object, prop) {
  25. return Object.getOwnPropertyDescriptor(object, prop);
  26. }
  27. function createProxyFunction(prototype) {
  28. function ProxyFunction() {}
  29. ProxyFunction.prototype = prototype;
  30. return ProxyFunction;
  31. }
  32. // import Howl from '../../3rd_party/howler';
  33. const audioControllerFactory = (function () {
  34. function AudioController(audioFactory) {
  35. this.audios = [];
  36. this.audioFactory = audioFactory;
  37. this._volume = 1;
  38. this._isMuted = false;
  39. }
  40. AudioController.prototype = {
  41. addAudio: function (audio) {
  42. this.audios.push(audio);
  43. },
  44. pause: function () {
  45. var i;
  46. var len = this.audios.length;
  47. for (i = 0; i < len; i += 1) {
  48. this.audios[i].pause();
  49. }
  50. },
  51. resume: function () {
  52. var i;
  53. var len = this.audios.length;
  54. for (i = 0; i < len; i += 1) {
  55. this.audios[i].resume();
  56. }
  57. },
  58. setRate: function (rateValue) {
  59. var i;
  60. var len = this.audios.length;
  61. for (i = 0; i < len; i += 1) {
  62. this.audios[i].setRate(rateValue);
  63. }
  64. },
  65. createAudio: function (assetPath) {
  66. if (this.audioFactory) {
  67. return this.audioFactory(assetPath);
  68. } if (window.Howl) {
  69. return new window.Howl({
  70. src: [assetPath],
  71. });
  72. }
  73. return {
  74. isPlaying: false,
  75. play: function () { this.isPlaying = true; },
  76. seek: function () { this.isPlaying = false; },
  77. playing: function () {},
  78. rate: function () {},
  79. setVolume: function () {},
  80. };
  81. },
  82. setAudioFactory: function (audioFactory) {
  83. this.audioFactory = audioFactory;
  84. },
  85. setVolume: function (value) {
  86. this._volume = value;
  87. this._updateVolume();
  88. },
  89. mute: function () {
  90. this._isMuted = true;
  91. this._updateVolume();
  92. },
  93. unmute: function () {
  94. this._isMuted = false;
  95. this._updateVolume();
  96. },
  97. getVolume: function () {
  98. return this._volume;
  99. },
  100. _updateVolume: function () {
  101. var i;
  102. var len = this.audios.length;
  103. for (i = 0; i < len; i += 1) {
  104. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  105. }
  106. },
  107. };
  108. return function () {
  109. return new AudioController();
  110. };
  111. }());
  112. const createTypedArray = (function () {
  113. function createRegularArray(type, len) {
  114. var i = 0;
  115. var arr = [];
  116. var value;
  117. switch (type) {
  118. case 'int16':
  119. case 'uint8c':
  120. value = 1;
  121. break;
  122. default:
  123. value = 1.1;
  124. break;
  125. }
  126. for (i = 0; i < len; i += 1) {
  127. arr.push(value);
  128. }
  129. return arr;
  130. }
  131. function createTypedArrayFactory(type, len) {
  132. if (type === 'float32') {
  133. return new Float32Array(len);
  134. } if (type === 'int16') {
  135. return new Int16Array(len);
  136. } if (type === 'uint8c') {
  137. return new Uint8ClampedArray(len);
  138. }
  139. return createRegularArray(type, len);
  140. }
  141. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  142. return createTypedArrayFactory;
  143. }
  144. return createRegularArray;
  145. }());
  146. function createSizedArray(len) {
  147. return Array.apply(null, { length: len });
  148. }
  149. let subframeEnabled = true;
  150. let expressionsPlugin = null;
  151. let expressionsInterfaces = null;
  152. let idPrefix$1 = '';
  153. const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  154. let _shouldRoundValues = false;
  155. const bmPow = Math.pow;
  156. const bmSqrt = Math.sqrt;
  157. const bmFloor = Math.floor;
  158. const bmMax = Math.max;
  159. const bmMin = Math.min;
  160. const BMMath = {};
  161. (function () {
  162. var propertyNames = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'atan2', 'ceil', 'cbrt', 'expm1', 'clz32', 'cos', 'cosh', 'exp', 'floor', 'fround', 'hypot', 'imul', 'log', 'log1p', 'log2', 'log10', 'max', 'min', 'pow', 'random', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', 'E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2'];
  163. var i;
  164. var len = propertyNames.length;
  165. for (i = 0; i < len; i += 1) {
  166. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  167. }
  168. }());
  169. function ProjectInterface$1() { return {}; }
  170. BMMath.random = Math.random;
  171. BMMath.abs = function (val) {
  172. var tOfVal = typeof val;
  173. if (tOfVal === 'object' && val.length) {
  174. var absArr = createSizedArray(val.length);
  175. var i;
  176. var len = val.length;
  177. for (i = 0; i < len; i += 1) {
  178. absArr[i] = Math.abs(val[i]);
  179. }
  180. return absArr;
  181. }
  182. return Math.abs(val);
  183. };
  184. let defaultCurveSegments = 150;
  185. const degToRads = Math.PI / 180;
  186. const roundCorner = 0.5519;
  187. function roundValues(flag) {
  188. _shouldRoundValues = !!flag;
  189. }
  190. function bmRnd(value) {
  191. if (_shouldRoundValues) {
  192. return Math.round(value);
  193. }
  194. return value;
  195. }
  196. function styleDiv(element) {
  197. element.style.position = 'absolute';
  198. element.style.top = 0;
  199. element.style.left = 0;
  200. element.style.display = 'block';
  201. element.style.transformOrigin = '0 0';
  202. element.style.webkitTransformOrigin = '0 0';
  203. element.style.backfaceVisibility = 'visible';
  204. element.style.webkitBackfaceVisibility = 'visible';
  205. element.style.transformStyle = 'preserve-3d';
  206. element.style.webkitTransformStyle = 'preserve-3d';
  207. element.style.mozTransformStyle = 'preserve-3d';
  208. }
  209. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  210. this.type = type;
  211. this.currentTime = currentTime;
  212. this.totalTime = totalTime;
  213. this.direction = frameMultiplier < 0 ? -1 : 1;
  214. }
  215. function BMCompleteEvent(type, frameMultiplier) {
  216. this.type = type;
  217. this.direction = frameMultiplier < 0 ? -1 : 1;
  218. }
  219. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  220. this.type = type;
  221. this.currentLoop = currentLoop;
  222. this.totalLoops = totalLoops;
  223. this.direction = frameMultiplier < 0 ? -1 : 1;
  224. }
  225. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  226. this.type = type;
  227. this.firstFrame = firstFrame;
  228. this.totalFrames = totalFrames;
  229. }
  230. function BMDestroyEvent(type, target) {
  231. this.type = type;
  232. this.target = target;
  233. }
  234. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  235. this.type = 'renderFrameError';
  236. this.nativeError = nativeError;
  237. this.currentTime = currentTime;
  238. }
  239. function BMConfigErrorEvent(nativeError) {
  240. this.type = 'configError';
  241. this.nativeError = nativeError;
  242. }
  243. function BMAnimationConfigErrorEvent(type, nativeError) {
  244. this.type = type;
  245. this.nativeError = nativeError;
  246. }
  247. const createElementID = (function () {
  248. var _count = 0;
  249. return function createID() {
  250. _count += 1;
  251. return idPrefix$1 + '__lottie_element_' + _count;
  252. };
  253. }());
  254. function HSVtoRGB(h, s, v) {
  255. var r;
  256. var g;
  257. var b;
  258. var i;
  259. var f;
  260. var p;
  261. var q;
  262. var t;
  263. i = Math.floor(h * 6);
  264. f = h * 6 - i;
  265. p = v * (1 - s);
  266. q = v * (1 - f * s);
  267. t = v * (1 - (1 - f) * s);
  268. switch (i % 6) {
  269. case 0: r = v; g = t; b = p; break;
  270. case 1: r = q; g = v; b = p; break;
  271. case 2: r = p; g = v; b = t; break;
  272. case 3: r = p; g = q; b = v; break;
  273. case 4: r = t; g = p; b = v; break;
  274. case 5: r = v; g = p; b = q; break;
  275. default: break;
  276. }
  277. return [r,
  278. g,
  279. b];
  280. }
  281. function RGBtoHSV(r, g, b) {
  282. var max = Math.max(r, g, b);
  283. var min = Math.min(r, g, b);
  284. var d = max - min;
  285. var h;
  286. var s = (max === 0 ? 0 : d / max);
  287. var v = max / 255;
  288. switch (max) {
  289. case min: h = 0; break;
  290. case r: h = (g - b) + d * (g < b ? 6 : 0); h /= 6 * d; break;
  291. case g: h = (b - r) + d * 2; h /= 6 * d; break;
  292. case b: h = (r - g) + d * 4; h /= 6 * d; break;
  293. default: break;
  294. }
  295. return [
  296. h,
  297. s,
  298. v,
  299. ];
  300. }
  301. function addSaturationToRGB(color, offset) {
  302. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  303. hsv[1] += offset;
  304. if (hsv[1] > 1) {
  305. hsv[1] = 1;
  306. } else if (hsv[1] <= 0) {
  307. hsv[1] = 0;
  308. }
  309. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  310. }
  311. function addBrightnessToRGB(color, offset) {
  312. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  313. hsv[2] += offset;
  314. if (hsv[2] > 1) {
  315. hsv[2] = 1;
  316. } else if (hsv[2] < 0) {
  317. hsv[2] = 0;
  318. }
  319. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  320. }
  321. function addHueToRGB(color, offset) {
  322. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  323. hsv[0] += offset / 360;
  324. if (hsv[0] > 1) {
  325. hsv[0] -= 1;
  326. } else if (hsv[0] < 0) {
  327. hsv[0] += 1;
  328. }
  329. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  330. }
  331. const rgbToHex = (function () {
  332. var colorMap = [];
  333. var i;
  334. var hex;
  335. for (i = 0; i < 256; i += 1) {
  336. hex = i.toString(16);
  337. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  338. }
  339. return function (r, g, b) {
  340. if (r < 0) {
  341. r = 0;
  342. }
  343. if (g < 0) {
  344. g = 0;
  345. }
  346. if (b < 0) {
  347. b = 0;
  348. }
  349. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  350. };
  351. }());
  352. const setSubframeEnabled = (flag) => { subframeEnabled = !!flag; };
  353. const getSubframeEnabled = () => subframeEnabled;
  354. const setExpressionsPlugin = (value) => { expressionsPlugin = value; };
  355. const getExpressionsPlugin = () => expressionsPlugin;
  356. const setExpressionInterfaces = (value) => { expressionsInterfaces = value; };
  357. const getExpressionInterfaces = () => expressionsInterfaces;
  358. const setDefaultCurveSegments = (value) => { defaultCurveSegments = value; };
  359. const getDefaultCurveSegments = () => defaultCurveSegments;
  360. const setIdPrefix = (value) => { idPrefix$1 = value; };
  361. const getIdPrefix = () => idPrefix$1;
  362. function createNS(type) {
  363. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  364. return document.createElementNS(svgNS, type);
  365. }
  366. const dataManager = (function () {
  367. var _counterId = 1;
  368. var processes = [];
  369. var workerFn;
  370. var workerInstance;
  371. var workerProxy = {
  372. onmessage: function () {
  373. },
  374. postMessage: function (path) {
  375. workerFn({
  376. data: path,
  377. });
  378. },
  379. };
  380. var _workerSelf = {
  381. postMessage: function (data) {
  382. workerProxy.onmessage({
  383. data: data,
  384. });
  385. },
  386. };
  387. function createWorker(fn) {
  388. if (window.Worker && window.Blob && getWebWorker()) {
  389. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  390. // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  391. var url = URL.createObjectURL(blob);
  392. return new Worker(url);
  393. }
  394. workerFn = fn;
  395. return workerProxy;
  396. }
  397. function setupWorker() {
  398. if (!workerInstance) {
  399. workerInstance = createWorker(function workerStart(e) {
  400. function dataFunctionManager() {
  401. function completeLayers(layers, comps) {
  402. var layerData;
  403. var i;
  404. var len = layers.length;
  405. var j;
  406. var jLen;
  407. var k;
  408. var kLen;
  409. for (i = 0; i < len; i += 1) {
  410. layerData = layers[i];
  411. if (('ks' in layerData) && !layerData.completed) {
  412. layerData.completed = true;
  413. if (layerData.hasMask) {
  414. var maskProps = layerData.masksProperties;
  415. jLen = maskProps.length;
  416. for (j = 0; j < jLen; j += 1) {
  417. if (maskProps[j].pt.k.i) {
  418. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  419. } else {
  420. kLen = maskProps[j].pt.k.length;
  421. for (k = 0; k < kLen; k += 1) {
  422. if (maskProps[j].pt.k[k].s) {
  423. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  424. }
  425. if (maskProps[j].pt.k[k].e) {
  426. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  427. }
  428. }
  429. }
  430. }
  431. }
  432. if (layerData.ty === 0) {
  433. layerData.layers = findCompLayers(layerData.refId, comps);
  434. completeLayers(layerData.layers, comps);
  435. } else if (layerData.ty === 4) {
  436. completeShapes(layerData.shapes);
  437. } else if (layerData.ty === 5) {
  438. completeText(layerData);
  439. }
  440. }
  441. }
  442. }
  443. function completeChars(chars, assets) {
  444. if (chars) {
  445. var i = 0;
  446. var len = chars.length;
  447. for (i = 0; i < len; i += 1) {
  448. if (chars[i].t === 1) {
  449. // var compData = findComp(chars[i].data.refId, assets);
  450. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
  451. // chars[i].data.ip = 0;
  452. // chars[i].data.op = 99999;
  453. // chars[i].data.st = 0;
  454. // chars[i].data.sr = 1;
  455. // chars[i].w = compData.w;
  456. // chars[i].data.ks = {
  457. // a: { k: [0, 0, 0], a: 0 },
  458. // p: { k: [0, -compData.h, 0], a: 0 },
  459. // r: { k: 0, a: 0 },
  460. // s: { k: [100, 100], a: 0 },
  461. // o: { k: 100, a: 0 },
  462. // };
  463. completeLayers(chars[i].data.layers, assets);
  464. }
  465. }
  466. }
  467. }
  468. function findComp(id, comps) {
  469. var i = 0;
  470. var len = comps.length;
  471. while (i < len) {
  472. if (comps[i].id === id) {
  473. return comps[i];
  474. }
  475. i += 1;
  476. }
  477. return null;
  478. }
  479. function findCompLayers(id, comps) {
  480. var comp = findComp(id, comps);
  481. if (comp) {
  482. if (!comp.layers.__used) {
  483. comp.layers.__used = true;
  484. return comp.layers;
  485. }
  486. return JSON.parse(JSON.stringify(comp.layers));
  487. }
  488. return null;
  489. }
  490. function completeShapes(arr) {
  491. var i;
  492. var len = arr.length;
  493. var j;
  494. var jLen;
  495. for (i = len - 1; i >= 0; i -= 1) {
  496. if (arr[i].ty === 'sh') {
  497. if (arr[i].ks.k.i) {
  498. convertPathsToAbsoluteValues(arr[i].ks.k);
  499. } else {
  500. jLen = arr[i].ks.k.length;
  501. for (j = 0; j < jLen; j += 1) {
  502. if (arr[i].ks.k[j].s) {
  503. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  504. }
  505. if (arr[i].ks.k[j].e) {
  506. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  507. }
  508. }
  509. }
  510. } else if (arr[i].ty === 'gr') {
  511. completeShapes(arr[i].it);
  512. }
  513. }
  514. }
  515. function convertPathsToAbsoluteValues(path) {
  516. var i;
  517. var len = path.i.length;
  518. for (i = 0; i < len; i += 1) {
  519. path.i[i][0] += path.v[i][0];
  520. path.i[i][1] += path.v[i][1];
  521. path.o[i][0] += path.v[i][0];
  522. path.o[i][1] += path.v[i][1];
  523. }
  524. }
  525. function checkVersion(minimum, animVersionString) {
  526. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  527. if (minimum[0] > animVersion[0]) {
  528. return true;
  529. } if (animVersion[0] > minimum[0]) {
  530. return false;
  531. }
  532. if (minimum[1] > animVersion[1]) {
  533. return true;
  534. } if (animVersion[1] > minimum[1]) {
  535. return false;
  536. }
  537. if (minimum[2] > animVersion[2]) {
  538. return true;
  539. } if (animVersion[2] > minimum[2]) {
  540. return false;
  541. }
  542. return null;
  543. }
  544. var checkText = (function () {
  545. var minimumVersion = [4, 4, 14];
  546. function updateTextLayer(textLayer) {
  547. var documentData = textLayer.t.d;
  548. textLayer.t.d = {
  549. k: [
  550. {
  551. s: documentData,
  552. t: 0,
  553. },
  554. ],
  555. };
  556. }
  557. function iterateLayers(layers) {
  558. var i;
  559. var len = layers.length;
  560. for (i = 0; i < len; i += 1) {
  561. if (layers[i].ty === 5) {
  562. updateTextLayer(layers[i]);
  563. }
  564. }
  565. }
  566. return function (animationData) {
  567. if (checkVersion(minimumVersion, animationData.v)) {
  568. iterateLayers(animationData.layers);
  569. if (animationData.assets) {
  570. var i;
  571. var len = animationData.assets.length;
  572. for (i = 0; i < len; i += 1) {
  573. if (animationData.assets[i].layers) {
  574. iterateLayers(animationData.assets[i].layers);
  575. }
  576. }
  577. }
  578. }
  579. };
  580. }());
  581. var checkChars = (function () {
  582. var minimumVersion = [4, 7, 99];
  583. return function (animationData) {
  584. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  585. var i;
  586. var len = animationData.chars.length;
  587. for (i = 0; i < len; i += 1) {
  588. var charData = animationData.chars[i];
  589. if (charData.data && charData.data.shapes) {
  590. completeShapes(charData.data.shapes);
  591. charData.data.ip = 0;
  592. charData.data.op = 99999;
  593. charData.data.st = 0;
  594. charData.data.sr = 1;
  595. charData.data.ks = {
  596. p: { k: [0, 0], a: 0 },
  597. s: { k: [100, 100], a: 0 },
  598. a: { k: [0, 0], a: 0 },
  599. r: { k: 0, a: 0 },
  600. o: { k: 100, a: 0 },
  601. };
  602. if (!animationData.chars[i].t) {
  603. charData.data.shapes.push(
  604. {
  605. ty: 'no',
  606. }
  607. );
  608. charData.data.shapes[0].it.push(
  609. {
  610. p: { k: [0, 0], a: 0 },
  611. s: { k: [100, 100], a: 0 },
  612. a: { k: [0, 0], a: 0 },
  613. r: { k: 0, a: 0 },
  614. o: { k: 100, a: 0 },
  615. sk: { k: 0, a: 0 },
  616. sa: { k: 0, a: 0 },
  617. ty: 'tr',
  618. }
  619. );
  620. }
  621. }
  622. }
  623. }
  624. };
  625. }());
  626. var checkPathProperties = (function () {
  627. var minimumVersion = [5, 7, 15];
  628. function updateTextLayer(textLayer) {
  629. var pathData = textLayer.t.p;
  630. if (typeof pathData.a === 'number') {
  631. pathData.a = {
  632. a: 0,
  633. k: pathData.a,
  634. };
  635. }
  636. if (typeof pathData.p === 'number') {
  637. pathData.p = {
  638. a: 0,
  639. k: pathData.p,
  640. };
  641. }
  642. if (typeof pathData.r === 'number') {
  643. pathData.r = {
  644. a: 0,
  645. k: pathData.r,
  646. };
  647. }
  648. }
  649. function iterateLayers(layers) {
  650. var i;
  651. var len = layers.length;
  652. for (i = 0; i < len; i += 1) {
  653. if (layers[i].ty === 5) {
  654. updateTextLayer(layers[i]);
  655. }
  656. }
  657. }
  658. return function (animationData) {
  659. if (checkVersion(minimumVersion, animationData.v)) {
  660. iterateLayers(animationData.layers);
  661. if (animationData.assets) {
  662. var i;
  663. var len = animationData.assets.length;
  664. for (i = 0; i < len; i += 1) {
  665. if (animationData.assets[i].layers) {
  666. iterateLayers(animationData.assets[i].layers);
  667. }
  668. }
  669. }
  670. }
  671. };
  672. }());
  673. var checkColors = (function () {
  674. var minimumVersion = [4, 1, 9];
  675. function iterateShapes(shapes) {
  676. var i;
  677. var len = shapes.length;
  678. var j;
  679. var jLen;
  680. for (i = 0; i < len; i += 1) {
  681. if (shapes[i].ty === 'gr') {
  682. iterateShapes(shapes[i].it);
  683. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  684. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  685. jLen = shapes[i].c.k.length;
  686. for (j = 0; j < jLen; j += 1) {
  687. if (shapes[i].c.k[j].s) {
  688. shapes[i].c.k[j].s[0] /= 255;
  689. shapes[i].c.k[j].s[1] /= 255;
  690. shapes[i].c.k[j].s[2] /= 255;
  691. shapes[i].c.k[j].s[3] /= 255;
  692. }
  693. if (shapes[i].c.k[j].e) {
  694. shapes[i].c.k[j].e[0] /= 255;
  695. shapes[i].c.k[j].e[1] /= 255;
  696. shapes[i].c.k[j].e[2] /= 255;
  697. shapes[i].c.k[j].e[3] /= 255;
  698. }
  699. }
  700. } else {
  701. shapes[i].c.k[0] /= 255;
  702. shapes[i].c.k[1] /= 255;
  703. shapes[i].c.k[2] /= 255;
  704. shapes[i].c.k[3] /= 255;
  705. }
  706. }
  707. }
  708. }
  709. function iterateLayers(layers) {
  710. var i;
  711. var len = layers.length;
  712. for (i = 0; i < len; i += 1) {
  713. if (layers[i].ty === 4) {
  714. iterateShapes(layers[i].shapes);
  715. }
  716. }
  717. }
  718. return function (animationData) {
  719. if (checkVersion(minimumVersion, animationData.v)) {
  720. iterateLayers(animationData.layers);
  721. if (animationData.assets) {
  722. var i;
  723. var len = animationData.assets.length;
  724. for (i = 0; i < len; i += 1) {
  725. if (animationData.assets[i].layers) {
  726. iterateLayers(animationData.assets[i].layers);
  727. }
  728. }
  729. }
  730. }
  731. };
  732. }());
  733. var checkShapes = (function () {
  734. var minimumVersion = [4, 4, 18];
  735. function completeClosingShapes(arr) {
  736. var i;
  737. var len = arr.length;
  738. var j;
  739. var jLen;
  740. for (i = len - 1; i >= 0; i -= 1) {
  741. if (arr[i].ty === 'sh') {
  742. if (arr[i].ks.k.i) {
  743. arr[i].ks.k.c = arr[i].closed;
  744. } else {
  745. jLen = arr[i].ks.k.length;
  746. for (j = 0; j < jLen; j += 1) {
  747. if (arr[i].ks.k[j].s) {
  748. arr[i].ks.k[j].s[0].c = arr[i].closed;
  749. }
  750. if (arr[i].ks.k[j].e) {
  751. arr[i].ks.k[j].e[0].c = arr[i].closed;
  752. }
  753. }
  754. }
  755. } else if (arr[i].ty === 'gr') {
  756. completeClosingShapes(arr[i].it);
  757. }
  758. }
  759. }
  760. function iterateLayers(layers) {
  761. var layerData;
  762. var i;
  763. var len = layers.length;
  764. var j;
  765. var jLen;
  766. var k;
  767. var kLen;
  768. for (i = 0; i < len; i += 1) {
  769. layerData = layers[i];
  770. if (layerData.hasMask) {
  771. var maskProps = layerData.masksProperties;
  772. jLen = maskProps.length;
  773. for (j = 0; j < jLen; j += 1) {
  774. if (maskProps[j].pt.k.i) {
  775. maskProps[j].pt.k.c = maskProps[j].cl;
  776. } else {
  777. kLen = maskProps[j].pt.k.length;
  778. for (k = 0; k < kLen; k += 1) {
  779. if (maskProps[j].pt.k[k].s) {
  780. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  781. }
  782. if (maskProps[j].pt.k[k].e) {
  783. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  784. }
  785. }
  786. }
  787. }
  788. }
  789. if (layerData.ty === 4) {
  790. completeClosingShapes(layerData.shapes);
  791. }
  792. }
  793. }
  794. return function (animationData) {
  795. if (checkVersion(minimumVersion, animationData.v)) {
  796. iterateLayers(animationData.layers);
  797. if (animationData.assets) {
  798. var i;
  799. var len = animationData.assets.length;
  800. for (i = 0; i < len; i += 1) {
  801. if (animationData.assets[i].layers) {
  802. iterateLayers(animationData.assets[i].layers);
  803. }
  804. }
  805. }
  806. }
  807. };
  808. }());
  809. function completeData(animationData) {
  810. if (animationData.__complete) {
  811. return;
  812. }
  813. checkColors(animationData);
  814. checkText(animationData);
  815. checkChars(animationData);
  816. checkPathProperties(animationData);
  817. checkShapes(animationData);
  818. completeLayers(animationData.layers, animationData.assets);
  819. completeChars(animationData.chars, animationData.assets);
  820. animationData.__complete = true;
  821. }
  822. function completeText(data) {
  823. if (data.t.a.length === 0 && !('m' in data.t.p)) {
  824. // data.singleShape = true;
  825. }
  826. }
  827. var moduleOb = {};
  828. moduleOb.completeData = completeData;
  829. moduleOb.checkColors = checkColors;
  830. moduleOb.checkChars = checkChars;
  831. moduleOb.checkPathProperties = checkPathProperties;
  832. moduleOb.checkShapes = checkShapes;
  833. moduleOb.completeLayers = completeLayers;
  834. return moduleOb;
  835. }
  836. if (!_workerSelf.dataManager) {
  837. _workerSelf.dataManager = dataFunctionManager();
  838. }
  839. if (!_workerSelf.assetLoader) {
  840. _workerSelf.assetLoader = (function () {
  841. function formatResponse(xhr) {
  842. // using typeof doubles the time of execution of this method,
  843. // so if available, it's better to use the header to validate the type
  844. var contentTypeHeader = xhr.getResponseHeader('content-type');
  845. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  846. return xhr.response;
  847. }
  848. if (xhr.response && typeof xhr.response === 'object') {
  849. return xhr.response;
  850. } if (xhr.response && typeof xhr.response === 'string') {
  851. return JSON.parse(xhr.response);
  852. } if (xhr.responseText) {
  853. return JSON.parse(xhr.responseText);
  854. }
  855. return null;
  856. }
  857. function loadAsset(path, fullPath, callback, errorCallback) {
  858. var response;
  859. var xhr = new XMLHttpRequest();
  860. // set responseType after calling open or IE will break.
  861. try {
  862. // This crashes on Android WebView prior to KitKat
  863. xhr.responseType = 'json';
  864. } catch (err) {} // eslint-disable-line no-empty
  865. xhr.onreadystatechange = function () {
  866. if (xhr.readyState === 4) {
  867. if (xhr.status === 200) {
  868. response = formatResponse(xhr);
  869. callback(response);
  870. } else {
  871. try {
  872. response = formatResponse(xhr);
  873. callback(response);
  874. } catch (err) {
  875. if (errorCallback) {
  876. errorCallback(err);
  877. }
  878. }
  879. }
  880. }
  881. };
  882. try {
  883. // Hack to workaround banner validation
  884. xhr.open(['G', 'E', 'T'].join(''), path, true);
  885. } catch (error) {
  886. // Hack to workaround banner validation
  887. xhr.open(['G', 'E', 'T'].join(''), fullPath + '/' + path, true);
  888. }
  889. xhr.send();
  890. }
  891. return {
  892. load: loadAsset,
  893. };
  894. }());
  895. }
  896. if (e.data.type === 'loadAnimation') {
  897. _workerSelf.assetLoader.load(
  898. e.data.path,
  899. e.data.fullPath,
  900. function (data) {
  901. _workerSelf.dataManager.completeData(data);
  902. _workerSelf.postMessage({
  903. id: e.data.id,
  904. payload: data,
  905. status: 'success',
  906. });
  907. },
  908. function () {
  909. _workerSelf.postMessage({
  910. id: e.data.id,
  911. status: 'error',
  912. });
  913. }
  914. );
  915. } else if (e.data.type === 'complete') {
  916. var animation = e.data.animation;
  917. _workerSelf.dataManager.completeData(animation);
  918. _workerSelf.postMessage({
  919. id: e.data.id,
  920. payload: animation,
  921. status: 'success',
  922. });
  923. } else if (e.data.type === 'loadData') {
  924. _workerSelf.assetLoader.load(
  925. e.data.path,
  926. e.data.fullPath,
  927. function (data) {
  928. _workerSelf.postMessage({
  929. id: e.data.id,
  930. payload: data,
  931. status: 'success',
  932. });
  933. },
  934. function () {
  935. _workerSelf.postMessage({
  936. id: e.data.id,
  937. status: 'error',
  938. });
  939. }
  940. );
  941. }
  942. });
  943. workerInstance.onmessage = function (event) {
  944. var data = event.data;
  945. var id = data.id;
  946. var process = processes[id];
  947. processes[id] = null;
  948. if (data.status === 'success') {
  949. process.onComplete(data.payload);
  950. } else if (process.onError) {
  951. process.onError();
  952. }
  953. };
  954. }
  955. }
  956. function createProcess(onComplete, onError) {
  957. _counterId += 1;
  958. var id = 'processId_' + _counterId;
  959. processes[id] = {
  960. onComplete: onComplete,
  961. onError: onError,
  962. };
  963. return id;
  964. }
  965. function loadAnimation(path, onComplete, onError) {
  966. setupWorker();
  967. var processId = createProcess(onComplete, onError);
  968. workerInstance.postMessage({
  969. type: 'loadAnimation',
  970. path: path,
  971. fullPath: window.location.origin + window.location.pathname,
  972. id: processId,
  973. });
  974. }
  975. function loadData(path, onComplete, onError) {
  976. setupWorker();
  977. var processId = createProcess(onComplete, onError);
  978. workerInstance.postMessage({
  979. type: 'loadData',
  980. path: path,
  981. fullPath: window.location.origin + window.location.pathname,
  982. id: processId,
  983. });
  984. }
  985. function completeAnimation(anim, onComplete, onError) {
  986. setupWorker();
  987. var processId = createProcess(onComplete, onError);
  988. workerInstance.postMessage({
  989. type: 'complete',
  990. animation: anim,
  991. id: processId,
  992. });
  993. }
  994. return {
  995. loadAnimation: loadAnimation,
  996. loadData: loadData,
  997. completeAnimation: completeAnimation,
  998. };
  999. }());
  1000. const ImagePreloader = (function () {
  1001. var proxyImage = (function () {
  1002. var canvas = createTag('canvas');
  1003. canvas.width = 1;
  1004. canvas.height = 1;
  1005. var ctx = canvas.getContext('2d');
  1006. ctx.fillStyle = 'rgba(0,0,0,0)';
  1007. ctx.fillRect(0, 0, 1, 1);
  1008. return canvas;
  1009. }());
  1010. function imageLoaded() {
  1011. this.loadedAssets += 1;
  1012. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1013. if (this.imagesLoadedCb) {
  1014. this.imagesLoadedCb(null);
  1015. }
  1016. }
  1017. }
  1018. function footageLoaded() {
  1019. this.loadedFootagesCount += 1;
  1020. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1021. if (this.imagesLoadedCb) {
  1022. this.imagesLoadedCb(null);
  1023. }
  1024. }
  1025. }
  1026. function getAssetsPath(assetData, assetsPath, originalPath) {
  1027. var path = '';
  1028. if (assetData.e) {
  1029. path = assetData.p;
  1030. } else if (assetsPath) {
  1031. var imagePath = assetData.p;
  1032. if (imagePath.indexOf('images/') !== -1) {
  1033. imagePath = imagePath.split('/')[1];
  1034. }
  1035. path = assetsPath + imagePath;
  1036. } else {
  1037. path = originalPath;
  1038. path += assetData.u ? assetData.u : '';
  1039. path += assetData.p;
  1040. }
  1041. return path;
  1042. }
  1043. function testImageLoaded(img) {
  1044. var _count = 0;
  1045. var intervalId = setInterval(function () {
  1046. var box = img.getBBox();
  1047. if (box.width || _count > 500) {
  1048. this._imageLoaded();
  1049. clearInterval(intervalId);
  1050. }
  1051. _count += 1;
  1052. }.bind(this), 50);
  1053. }
  1054. function createImageData(assetData) {
  1055. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1056. var img = createNS('image');
  1057. if (isSafari) {
  1058. this.testImageLoaded(img);
  1059. } else {
  1060. img.addEventListener('load', this._imageLoaded, false);
  1061. }
  1062. img.addEventListener('error', function () {
  1063. ob.img = proxyImage;
  1064. this._imageLoaded();
  1065. }.bind(this), false);
  1066. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1067. if (this._elementHelper.append) {
  1068. this._elementHelper.append(img);
  1069. } else {
  1070. this._elementHelper.appendChild(img);
  1071. }
  1072. var ob = {
  1073. img: img,
  1074. assetData: assetData,
  1075. };
  1076. return ob;
  1077. }
  1078. function createImgData(assetData) {
  1079. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1080. var img = createTag('img');
  1081. img.crossOrigin = 'anonymous';
  1082. img.addEventListener('load', this._imageLoaded, false);
  1083. img.addEventListener('error', function () {
  1084. ob.img = proxyImage;
  1085. this._imageLoaded();
  1086. }.bind(this), false);
  1087. img.src = path;
  1088. var ob = {
  1089. img: img,
  1090. assetData: assetData,
  1091. };
  1092. return ob;
  1093. }
  1094. function createFootageData(data) {
  1095. var ob = {
  1096. assetData: data,
  1097. };
  1098. var path = getAssetsPath(data, this.assetsPath, this.path);
  1099. dataManager.loadData(path, function (footageData) {
  1100. ob.img = footageData;
  1101. this._footageLoaded();
  1102. }.bind(this), function () {
  1103. ob.img = {};
  1104. this._footageLoaded();
  1105. }.bind(this));
  1106. return ob;
  1107. }
  1108. function loadAssets(assets, cb) {
  1109. this.imagesLoadedCb = cb;
  1110. var i;
  1111. var len = assets.length;
  1112. for (i = 0; i < len; i += 1) {
  1113. if (!assets[i].layers) {
  1114. if (!assets[i].t || assets[i].t === 'seq') {
  1115. this.totalImages += 1;
  1116. this.images.push(this._createImageData(assets[i]));
  1117. } else if (assets[i].t === 3) {
  1118. this.totalFootages += 1;
  1119. this.images.push(this.createFootageData(assets[i]));
  1120. }
  1121. }
  1122. }
  1123. }
  1124. function setPath(path) {
  1125. this.path = path || '';
  1126. }
  1127. function setAssetsPath(path) {
  1128. this.assetsPath = path || '';
  1129. }
  1130. function getAsset(assetData) {
  1131. var i = 0;
  1132. var len = this.images.length;
  1133. while (i < len) {
  1134. if (this.images[i].assetData === assetData) {
  1135. return this.images[i].img;
  1136. }
  1137. i += 1;
  1138. }
  1139. return null;
  1140. }
  1141. function destroy() {
  1142. this.imagesLoadedCb = null;
  1143. this.images.length = 0;
  1144. }
  1145. function loadedImages() {
  1146. return this.totalImages === this.loadedAssets;
  1147. }
  1148. function loadedFootages() {
  1149. return this.totalFootages === this.loadedFootagesCount;
  1150. }
  1151. function setCacheType(type, elementHelper) {
  1152. if (type === 'svg') {
  1153. this._elementHelper = elementHelper;
  1154. this._createImageData = this.createImageData.bind(this);
  1155. } else {
  1156. this._createImageData = this.createImgData.bind(this);
  1157. }
  1158. }
  1159. function ImagePreloaderFactory() {
  1160. this._imageLoaded = imageLoaded.bind(this);
  1161. this._footageLoaded = footageLoaded.bind(this);
  1162. this.testImageLoaded = testImageLoaded.bind(this);
  1163. this.createFootageData = createFootageData.bind(this);
  1164. this.assetsPath = '';
  1165. this.path = '';
  1166. this.totalImages = 0;
  1167. this.totalFootages = 0;
  1168. this.loadedAssets = 0;
  1169. this.loadedFootagesCount = 0;
  1170. this.imagesLoadedCb = null;
  1171. this.images = [];
  1172. }
  1173. ImagePreloaderFactory.prototype = {
  1174. loadAssets: loadAssets,
  1175. setAssetsPath: setAssetsPath,
  1176. setPath: setPath,
  1177. loadedImages: loadedImages,
  1178. loadedFootages: loadedFootages,
  1179. destroy: destroy,
  1180. getAsset: getAsset,
  1181. createImgData: createImgData,
  1182. createImageData: createImageData,
  1183. imageLoaded: imageLoaded,
  1184. footageLoaded: footageLoaded,
  1185. setCacheType: setCacheType,
  1186. };
  1187. return ImagePreloaderFactory;
  1188. }());
  1189. function BaseEvent() {}
  1190. BaseEvent.prototype = {
  1191. triggerEvent: function (eventName, args) {
  1192. if (this._cbs[eventName]) {
  1193. var callbacks = this._cbs[eventName];
  1194. for (var i = 0; i < callbacks.length; i += 1) {
  1195. callbacks[i](args);
  1196. }
  1197. }
  1198. },
  1199. addEventListener: function (eventName, callback) {
  1200. if (!this._cbs[eventName]) {
  1201. this._cbs[eventName] = [];
  1202. }
  1203. this._cbs[eventName].push(callback);
  1204. return function () {
  1205. this.removeEventListener(eventName, callback);
  1206. }.bind(this);
  1207. },
  1208. removeEventListener: function (eventName, callback) {
  1209. if (!callback) {
  1210. this._cbs[eventName] = null;
  1211. } else if (this._cbs[eventName]) {
  1212. var i = 0;
  1213. var len = this._cbs[eventName].length;
  1214. while (i < len) {
  1215. if (this._cbs[eventName][i] === callback) {
  1216. this._cbs[eventName].splice(i, 1);
  1217. i -= 1;
  1218. len -= 1;
  1219. }
  1220. i += 1;
  1221. }
  1222. if (!this._cbs[eventName].length) {
  1223. this._cbs[eventName] = null;
  1224. }
  1225. }
  1226. },
  1227. };
  1228. const markerParser = (
  1229. function () {
  1230. function parsePayloadLines(payload) {
  1231. var lines = payload.split('\r\n');
  1232. var keys = {};
  1233. var line;
  1234. var keysCount = 0;
  1235. for (var i = 0; i < lines.length; i += 1) {
  1236. line = lines[i].split(':');
  1237. if (line.length === 2) {
  1238. keys[line[0]] = line[1].trim();
  1239. keysCount += 1;
  1240. }
  1241. }
  1242. if (keysCount === 0) {
  1243. throw new Error();
  1244. }
  1245. return keys;
  1246. }
  1247. return function (_markers) {
  1248. var markers = [];
  1249. for (var i = 0; i < _markers.length; i += 1) {
  1250. var _marker = _markers[i];
  1251. var markerData = {
  1252. time: _marker.tm,
  1253. duration: _marker.dr,
  1254. };
  1255. try {
  1256. markerData.payload = JSON.parse(_markers[i].cm);
  1257. } catch (_) {
  1258. try {
  1259. markerData.payload = parsePayloadLines(_markers[i].cm);
  1260. } catch (__) {
  1261. markerData.payload = {
  1262. name: _markers[i].cm,
  1263. };
  1264. }
  1265. }
  1266. markers.push(markerData);
  1267. }
  1268. return markers;
  1269. };
  1270. }());
  1271. const ProjectInterface = (function () {
  1272. function registerComposition(comp) {
  1273. this.compositions.push(comp);
  1274. }
  1275. return function () {
  1276. function _thisProjectFunction(name) {
  1277. var i = 0;
  1278. var len = this.compositions.length;
  1279. while (i < len) {
  1280. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1281. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1282. this.compositions[i].prepareFrame(this.currentFrame);
  1283. }
  1284. return this.compositions[i].compInterface;
  1285. }
  1286. i += 1;
  1287. }
  1288. return null;
  1289. }
  1290. _thisProjectFunction.compositions = [];
  1291. _thisProjectFunction.currentFrame = 0;
  1292. _thisProjectFunction.registerComposition = registerComposition;
  1293. return _thisProjectFunction;
  1294. };
  1295. }());
  1296. const renderers = {};
  1297. const registerRenderer = (key, value) => {
  1298. renderers[key] = value;
  1299. };
  1300. function getRenderer(key) {
  1301. return renderers[key];
  1302. }
  1303. function getRegisteredRenderer() {
  1304. // Returns canvas by default for compatibility
  1305. if (renderers.canvas) {
  1306. return 'canvas';
  1307. }
  1308. // Returns any renderer that is registered
  1309. for (const key in renderers) {
  1310. if (renderers[key]) {
  1311. return key;
  1312. }
  1313. }
  1314. return '';
  1315. }
  1316. const AnimationItem = function () {
  1317. this._cbs = [];
  1318. this.name = '';
  1319. this.path = '';
  1320. this.isLoaded = false;
  1321. this.currentFrame = 0;
  1322. this.currentRawFrame = 0;
  1323. this.firstFrame = 0;
  1324. this.totalFrames = 0;
  1325. this.frameRate = 0;
  1326. this.frameMult = 0;
  1327. this.playSpeed = 1;
  1328. this.playDirection = 1;
  1329. this.playCount = 0;
  1330. this.animationData = {};
  1331. this.assets = [];
  1332. this.isPaused = true;
  1333. this.autoplay = false;
  1334. this.loop = true;
  1335. this.renderer = null;
  1336. this.animationID = createElementID();
  1337. this.assetsPath = '';
  1338. this.timeCompleted = 0;
  1339. this.segmentPos = 0;
  1340. this.isSubframeEnabled = getSubframeEnabled();
  1341. this.segments = [];
  1342. this._idle = true;
  1343. this._completedLoop = false;
  1344. this.projectInterface = ProjectInterface();
  1345. this.imagePreloader = new ImagePreloader();
  1346. this.audioController = audioControllerFactory();
  1347. this.markers = [];
  1348. this.configAnimation = this.configAnimation.bind(this);
  1349. this.onSetupError = this.onSetupError.bind(this);
  1350. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1351. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1352. this.expressionsPlugin = getExpressionsPlugin();
  1353. };
  1354. extendPrototype([BaseEvent], AnimationItem);
  1355. AnimationItem.prototype.setParams = function (params) {
  1356. if (params.wrapper || params.container) {
  1357. this.wrapper = params.wrapper || params.container;
  1358. }
  1359. var animType = 'svg';
  1360. if (params.animType) {
  1361. animType = params.animType;
  1362. } else if (params.renderer) {
  1363. animType = params.renderer;
  1364. }
  1365. const RendererClass = getRenderer(animType);
  1366. this.renderer = new RendererClass(this, params.rendererSettings);
  1367. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1368. this.renderer.setProjectInterface(this.projectInterface);
  1369. this.animType = animType;
  1370. if (params.loop === ''
  1371. || params.loop === null
  1372. || params.loop === undefined
  1373. || params.loop === true) {
  1374. this.loop = true;
  1375. } else if (params.loop === false) {
  1376. this.loop = false;
  1377. } else {
  1378. this.loop = parseInt(params.loop, 10);
  1379. }
  1380. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1381. this.name = params.name ? params.name : '';
  1382. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1383. this.assetsPath = params.assetsPath;
  1384. this.initialSegment = params.initialSegment;
  1385. if (params.audioFactory) {
  1386. this.audioController.setAudioFactory(params.audioFactory);
  1387. }
  1388. if (params.animationData) {
  1389. this.setupAnimation(params.animationData);
  1390. } else if (params.path) {
  1391. if (params.path.lastIndexOf('\\') !== -1) {
  1392. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1393. } else {
  1394. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1395. }
  1396. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1397. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1398. dataManager.loadAnimation(
  1399. params.path,
  1400. this.configAnimation,
  1401. this.onSetupError
  1402. );
  1403. }
  1404. };
  1405. AnimationItem.prototype.onSetupError = function () {
  1406. this.trigger('data_failed');
  1407. };
  1408. AnimationItem.prototype.setupAnimation = function (data) {
  1409. dataManager.completeAnimation(
  1410. data,
  1411. this.configAnimation
  1412. );
  1413. };
  1414. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1415. if (animationData) {
  1416. if (typeof animationData !== 'object') {
  1417. animationData = JSON.parse(animationData);
  1418. }
  1419. }
  1420. var params = {
  1421. wrapper: wrapper,
  1422. animationData: animationData,
  1423. };
  1424. var wrapperAttributes = wrapper.attributes;
  1425. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1426. ? wrapperAttributes.getNamedItem('data-animation-path').value
  1427. : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1428. ? wrapperAttributes.getNamedItem('data-bm-path').value
  1429. : wrapperAttributes.getNamedItem('bm-path')
  1430. ? wrapperAttributes.getNamedItem('bm-path').value
  1431. : '';
  1432. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1433. ? wrapperAttributes.getNamedItem('data-anim-type').value
  1434. : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1435. ? wrapperAttributes.getNamedItem('data-bm-type').value
  1436. : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1437. ? wrapperAttributes.getNamedItem('bm-type').value
  1438. : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1439. ? wrapperAttributes.getNamedItem('data-bm-renderer').value
  1440. : wrapperAttributes.getNamedItem('bm-renderer')
  1441. ? wrapperAttributes.getNamedItem('bm-renderer').value
  1442. : getRegisteredRenderer() || 'canvas';
  1443. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1444. ? wrapperAttributes.getNamedItem('data-anim-loop').value
  1445. : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1446. ? wrapperAttributes.getNamedItem('data-bm-loop').value
  1447. : wrapperAttributes.getNamedItem('bm-loop')
  1448. ? wrapperAttributes.getNamedItem('bm-loop').value
  1449. : '';
  1450. if (loop === 'false') {
  1451. params.loop = false;
  1452. } else if (loop === 'true') {
  1453. params.loop = true;
  1454. } else if (loop !== '') {
  1455. params.loop = parseInt(loop, 10);
  1456. }
  1457. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1458. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value
  1459. : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1460. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value
  1461. : wrapperAttributes.getNamedItem('bm-autoplay')
  1462. ? wrapperAttributes.getNamedItem('bm-autoplay').value
  1463. : true;
  1464. params.autoplay = autoplay !== 'false';
  1465. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1466. ? wrapperAttributes.getNamedItem('data-name').value
  1467. : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1468. ? wrapperAttributes.getNamedItem('data-bm-name').value
  1469. : wrapperAttributes.getNamedItem('bm-name')
  1470. ? wrapperAttributes.getNamedItem('bm-name').value
  1471. : '';
  1472. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1473. ? wrapperAttributes.getNamedItem('data-anim-prerender').value
  1474. : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1475. ? wrapperAttributes.getNamedItem('data-bm-prerender').value
  1476. : wrapperAttributes.getNamedItem('bm-prerender')
  1477. ? wrapperAttributes.getNamedItem('bm-prerender').value
  1478. : '';
  1479. if (prerender === 'false') {
  1480. params.prerender = false;
  1481. }
  1482. if (!params.path) {
  1483. this.trigger('destroy');
  1484. } else {
  1485. this.setParams(params);
  1486. }
  1487. };
  1488. AnimationItem.prototype.includeLayers = function (data) {
  1489. if (data.op > this.animationData.op) {
  1490. this.animationData.op = data.op;
  1491. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1492. }
  1493. var layers = this.animationData.layers;
  1494. var i;
  1495. var len = layers.length;
  1496. var newLayers = data.layers;
  1497. var j;
  1498. var jLen = newLayers.length;
  1499. for (j = 0; j < jLen; j += 1) {
  1500. i = 0;
  1501. while (i < len) {
  1502. if (layers[i].id === newLayers[j].id) {
  1503. layers[i] = newLayers[j];
  1504. break;
  1505. }
  1506. i += 1;
  1507. }
  1508. }
  1509. if (data.chars || data.fonts) {
  1510. this.renderer.globalData.fontManager.addChars(data.chars);
  1511. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1512. }
  1513. if (data.assets) {
  1514. len = data.assets.length;
  1515. for (i = 0; i < len; i += 1) {
  1516. this.animationData.assets.push(data.assets[i]);
  1517. }
  1518. }
  1519. this.animationData.__complete = false;
  1520. dataManager.completeAnimation(
  1521. this.animationData,
  1522. this.onSegmentComplete
  1523. );
  1524. };
  1525. AnimationItem.prototype.onSegmentComplete = function (data) {
  1526. this.animationData = data;
  1527. var expressionsPlugin = getExpressionsPlugin();
  1528. if (expressionsPlugin) {
  1529. expressionsPlugin.initExpressions(this);
  1530. }
  1531. this.loadNextSegment();
  1532. };
  1533. AnimationItem.prototype.loadNextSegment = function () {
  1534. var segments = this.animationData.segments;
  1535. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1536. this.trigger('data_ready');
  1537. this.timeCompleted = this.totalFrames;
  1538. return;
  1539. }
  1540. var segment = segments.shift();
  1541. this.timeCompleted = segment.time * this.frameRate;
  1542. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1543. this.segmentPos += 1;
  1544. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1545. this.trigger('data_failed');
  1546. }.bind(this));
  1547. };
  1548. AnimationItem.prototype.loadSegments = function () {
  1549. var segments = this.animationData.segments;
  1550. if (!segments) {
  1551. this.timeCompleted = this.totalFrames;
  1552. }
  1553. this.loadNextSegment();
  1554. };
  1555. AnimationItem.prototype.imagesLoaded = function () {
  1556. this.trigger('loaded_images');
  1557. this.checkLoaded();
  1558. };
  1559. AnimationItem.prototype.preloadImages = function () {
  1560. this.imagePreloader.setAssetsPath(this.assetsPath);
  1561. this.imagePreloader.setPath(this.path);
  1562. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1563. };
  1564. AnimationItem.prototype.configAnimation = function (animData) {
  1565. if (!this.renderer) {
  1566. return;
  1567. }
  1568. try {
  1569. this.animationData = animData;
  1570. if (this.initialSegment) {
  1571. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1572. this.firstFrame = Math.round(this.initialSegment[0]);
  1573. } else {
  1574. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1575. this.firstFrame = Math.round(this.animationData.ip);
  1576. }
  1577. this.renderer.configAnimation(animData);
  1578. if (!animData.assets) {
  1579. animData.assets = [];
  1580. }
  1581. this.assets = this.animationData.assets;
  1582. this.frameRate = this.animationData.fr;
  1583. this.frameMult = this.animationData.fr / 1000;
  1584. this.renderer.searchExtraCompositions(animData.assets);
  1585. this.markers = markerParser(animData.markers || []);
  1586. this.trigger('config_ready');
  1587. this.preloadImages();
  1588. this.loadSegments();
  1589. this.updaFrameModifier();
  1590. this.waitForFontsLoaded();
  1591. if (this.isPaused) {
  1592. this.audioController.pause();
  1593. }
  1594. } catch (error) {
  1595. this.triggerConfigError(error);
  1596. }
  1597. };
  1598. AnimationItem.prototype.waitForFontsLoaded = function () {
  1599. if (!this.renderer) {
  1600. return;
  1601. }
  1602. if (this.renderer.globalData.fontManager.isLoaded) {
  1603. this.checkLoaded();
  1604. } else {
  1605. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1606. }
  1607. };
  1608. AnimationItem.prototype.checkLoaded = function () {
  1609. if (!this.isLoaded
  1610. && this.renderer.globalData.fontManager.isLoaded
  1611. && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas')
  1612. && (this.imagePreloader.loadedFootages())
  1613. ) {
  1614. this.isLoaded = true;
  1615. var expressionsPlugin = getExpressionsPlugin();
  1616. if (expressionsPlugin) {
  1617. expressionsPlugin.initExpressions(this);
  1618. }
  1619. this.renderer.initItems();
  1620. setTimeout(function () {
  1621. this.trigger('DOMLoaded');
  1622. }.bind(this), 0);
  1623. this.gotoFrame();
  1624. if (this.autoplay) {
  1625. this.play();
  1626. }
  1627. }
  1628. };
  1629. AnimationItem.prototype.resize = function (width, height) {
  1630. // Adding this validation for backwards compatibility in case an event object was being passed down
  1631. var _width = typeof width === 'number' ? width : undefined;
  1632. var _height = typeof height === 'number' ? height : undefined;
  1633. this.renderer.updateContainerSize(_width, _height);
  1634. };
  1635. AnimationItem.prototype.setSubframe = function (flag) {
  1636. this.isSubframeEnabled = !!flag;
  1637. };
  1638. AnimationItem.prototype.gotoFrame = function () {
  1639. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1640. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1641. this.currentFrame = this.timeCompleted;
  1642. }
  1643. this.trigger('enterFrame');
  1644. this.renderFrame();
  1645. this.trigger('drawnFrame');
  1646. };
  1647. AnimationItem.prototype.renderFrame = function () {
  1648. if (this.isLoaded === false || !this.renderer) {
  1649. return;
  1650. }
  1651. try {
  1652. if (this.expressionsPlugin) {
  1653. this.expressionsPlugin.resetFrame();
  1654. }
  1655. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1656. } catch (error) {
  1657. this.triggerRenderFrameError(error);
  1658. }
  1659. };
  1660. AnimationItem.prototype.play = function (name) {
  1661. if (name && this.name !== name) {
  1662. return;
  1663. }
  1664. if (this.isPaused === true) {
  1665. this.isPaused = false;
  1666. this.trigger('_play');
  1667. this.audioController.resume();
  1668. if (this._idle) {
  1669. this._idle = false;
  1670. this.trigger('_active');
  1671. }
  1672. }
  1673. };
  1674. AnimationItem.prototype.pause = function (name) {
  1675. if (name && this.name !== name) {
  1676. return;
  1677. }
  1678. if (this.isPaused === false) {
  1679. this.isPaused = true;
  1680. this.trigger('_pause');
  1681. this._idle = true;
  1682. this.trigger('_idle');
  1683. this.audioController.pause();
  1684. }
  1685. };
  1686. AnimationItem.prototype.togglePause = function (name) {
  1687. if (name && this.name !== name) {
  1688. return;
  1689. }
  1690. if (this.isPaused === true) {
  1691. this.play();
  1692. } else {
  1693. this.pause();
  1694. }
  1695. };
  1696. AnimationItem.prototype.stop = function (name) {
  1697. if (name && this.name !== name) {
  1698. return;
  1699. }
  1700. this.pause();
  1701. this.playCount = 0;
  1702. this._completedLoop = false;
  1703. this.setCurrentRawFrameValue(0);
  1704. };
  1705. AnimationItem.prototype.getMarkerData = function (markerName) {
  1706. var marker;
  1707. for (var i = 0; i < this.markers.length; i += 1) {
  1708. marker = this.markers[i];
  1709. if (marker.payload && marker.payload.name === markerName) {
  1710. return marker;
  1711. }
  1712. }
  1713. return null;
  1714. };
  1715. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1716. if (name && this.name !== name) {
  1717. return;
  1718. }
  1719. var numValue = Number(value);
  1720. if (isNaN(numValue)) {
  1721. var marker = this.getMarkerData(value);
  1722. if (marker) {
  1723. this.goToAndStop(marker.time, true);
  1724. }
  1725. } else if (isFrame) {
  1726. this.setCurrentRawFrameValue(value);
  1727. } else {
  1728. this.setCurrentRawFrameValue(value * this.frameModifier);
  1729. }
  1730. this.pause();
  1731. };
  1732. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1733. if (name && this.name !== name) {
  1734. return;
  1735. }
  1736. var numValue = Number(value);
  1737. if (isNaN(numValue)) {
  1738. var marker = this.getMarkerData(value);
  1739. if (marker) {
  1740. if (!marker.duration) {
  1741. this.goToAndStop(marker.time, true);
  1742. } else {
  1743. this.playSegments([marker.time, marker.time + marker.duration], true);
  1744. }
  1745. }
  1746. } else {
  1747. this.goToAndStop(numValue, isFrame, name);
  1748. }
  1749. this.play();
  1750. };
  1751. AnimationItem.prototype.advanceTime = function (value) {
  1752. if (this.isPaused === true || this.isLoaded === false) {
  1753. return;
  1754. }
  1755. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1756. var _isComplete = false;
  1757. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1758. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1759. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1760. if (!this.loop || this.playCount === this.loop) {
  1761. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1762. _isComplete = true;
  1763. nextValue = this.totalFrames - 1;
  1764. }
  1765. } else if (nextValue >= this.totalFrames) {
  1766. this.playCount += 1;
  1767. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1768. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1769. this._completedLoop = true;
  1770. this.trigger('loopComplete');
  1771. }
  1772. } else {
  1773. this.setCurrentRawFrameValue(nextValue);
  1774. }
  1775. } else if (nextValue < 0) {
  1776. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1777. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) { // eslint-disable-line no-plusplus
  1778. this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames));
  1779. if (!this._completedLoop) {
  1780. this._completedLoop = true;
  1781. } else {
  1782. this.trigger('loopComplete');
  1783. }
  1784. } else {
  1785. _isComplete = true;
  1786. nextValue = 0;
  1787. }
  1788. }
  1789. } else {
  1790. this.setCurrentRawFrameValue(nextValue);
  1791. }
  1792. if (_isComplete) {
  1793. this.setCurrentRawFrameValue(nextValue);
  1794. this.pause();
  1795. this.trigger('complete');
  1796. }
  1797. };
  1798. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1799. this.playCount = 0;
  1800. if (arr[1] < arr[0]) {
  1801. if (this.frameModifier > 0) {
  1802. if (this.playSpeed < 0) {
  1803. this.setSpeed(-this.playSpeed);
  1804. } else {
  1805. this.setDirection(-1);
  1806. }
  1807. }
  1808. this.totalFrames = arr[0] - arr[1];
  1809. this.timeCompleted = this.totalFrames;
  1810. this.firstFrame = arr[1];
  1811. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1812. } else if (arr[1] > arr[0]) {
  1813. if (this.frameModifier < 0) {
  1814. if (this.playSpeed < 0) {
  1815. this.setSpeed(-this.playSpeed);
  1816. } else {
  1817. this.setDirection(1);
  1818. }
  1819. }
  1820. this.totalFrames = arr[1] - arr[0];
  1821. this.timeCompleted = this.totalFrames;
  1822. this.firstFrame = arr[0];
  1823. this.setCurrentRawFrameValue(0.001 + offset);
  1824. }
  1825. this.trigger('segmentStart');
  1826. };
  1827. AnimationItem.prototype.setSegment = function (init, end) {
  1828. var pendingFrame = -1;
  1829. if (this.isPaused) {
  1830. if (this.currentRawFrame + this.firstFrame < init) {
  1831. pendingFrame = init;
  1832. } else if (this.currentRawFrame + this.firstFrame > end) {
  1833. pendingFrame = end - init;
  1834. }
  1835. }
  1836. this.firstFrame = init;
  1837. this.totalFrames = end - init;
  1838. this.timeCompleted = this.totalFrames;
  1839. if (pendingFrame !== -1) {
  1840. this.goToAndStop(pendingFrame, true);
  1841. }
  1842. };
  1843. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1844. if (forceFlag) {
  1845. this.segments.length = 0;
  1846. }
  1847. if (typeof arr[0] === 'object') {
  1848. var i;
  1849. var len = arr.length;
  1850. for (i = 0; i < len; i += 1) {
  1851. this.segments.push(arr[i]);
  1852. }
  1853. } else {
  1854. this.segments.push(arr);
  1855. }
  1856. if (this.segments.length && forceFlag) {
  1857. this.adjustSegment(this.segments.shift(), 0);
  1858. }
  1859. if (this.isPaused) {
  1860. this.play();
  1861. }
  1862. };
  1863. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1864. this.segments.length = 0;
  1865. this.segments.push([this.animationData.ip, this.animationData.op]);
  1866. if (forceFlag) {
  1867. this.checkSegments(0);
  1868. }
  1869. };
  1870. AnimationItem.prototype.checkSegments = function (offset) {
  1871. if (this.segments.length) {
  1872. this.adjustSegment(this.segments.shift(), offset);
  1873. return true;
  1874. }
  1875. return false;
  1876. };
  1877. AnimationItem.prototype.destroy = function (name) {
  1878. if ((name && this.name !== name) || !this.renderer) {
  1879. return;
  1880. }
  1881. this.renderer.destroy();
  1882. this.imagePreloader.destroy();
  1883. this.trigger('destroy');
  1884. this._cbs = null;
  1885. this.onEnterFrame = null;
  1886. this.onLoopComplete = null;
  1887. this.onComplete = null;
  1888. this.onSegmentStart = null;
  1889. this.onDestroy = null;
  1890. this.renderer = null;
  1891. this.expressionsPlugin = null;
  1892. this.imagePreloader = null;
  1893. this.projectInterface = null;
  1894. };
  1895. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1896. this.currentRawFrame = value;
  1897. this.gotoFrame();
  1898. };
  1899. AnimationItem.prototype.setSpeed = function (val) {
  1900. this.playSpeed = val;
  1901. this.updaFrameModifier();
  1902. };
  1903. AnimationItem.prototype.setDirection = function (val) {
  1904. this.playDirection = val < 0 ? -1 : 1;
  1905. this.updaFrameModifier();
  1906. };
  1907. AnimationItem.prototype.setLoop = function (isLooping) {
  1908. this.loop = isLooping;
  1909. };
  1910. AnimationItem.prototype.setVolume = function (val, name) {
  1911. if (name && this.name !== name) {
  1912. return;
  1913. }
  1914. this.audioController.setVolume(val);
  1915. };
  1916. AnimationItem.prototype.getVolume = function () {
  1917. return this.audioController.getVolume();
  1918. };
  1919. AnimationItem.prototype.mute = function (name) {
  1920. if (name && this.name !== name) {
  1921. return;
  1922. }
  1923. this.audioController.mute();
  1924. };
  1925. AnimationItem.prototype.unmute = function (name) {
  1926. if (name && this.name !== name) {
  1927. return;
  1928. }
  1929. this.audioController.unmute();
  1930. };
  1931. AnimationItem.prototype.updaFrameModifier = function () {
  1932. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1933. this.audioController.setRate(this.playSpeed * this.playDirection);
  1934. };
  1935. AnimationItem.prototype.getPath = function () {
  1936. return this.path;
  1937. };
  1938. AnimationItem.prototype.getAssetsPath = function (assetData) {
  1939. var path = '';
  1940. if (assetData.e) {
  1941. path = assetData.p;
  1942. } else if (this.assetsPath) {
  1943. var imagePath = assetData.p;
  1944. if (imagePath.indexOf('images/') !== -1) {
  1945. imagePath = imagePath.split('/')[1];
  1946. }
  1947. path = this.assetsPath + imagePath;
  1948. } else {
  1949. path = this.path;
  1950. path += assetData.u ? assetData.u : '';
  1951. path += assetData.p;
  1952. }
  1953. return path;
  1954. };
  1955. AnimationItem.prototype.getAssetData = function (id) {
  1956. var i = 0;
  1957. var len = this.assets.length;
  1958. while (i < len) {
  1959. if (id === this.assets[i].id) {
  1960. return this.assets[i];
  1961. }
  1962. i += 1;
  1963. }
  1964. return null;
  1965. };
  1966. AnimationItem.prototype.hide = function () {
  1967. this.renderer.hide();
  1968. };
  1969. AnimationItem.prototype.show = function () {
  1970. this.renderer.show();
  1971. };
  1972. AnimationItem.prototype.getDuration = function (isFrame) {
  1973. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  1974. };
  1975. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  1976. try {
  1977. var element = this.renderer.getElementByPath(path);
  1978. element.updateDocumentData(documentData, index);
  1979. } catch (error) {
  1980. // TODO: decide how to handle catch case
  1981. }
  1982. };
  1983. AnimationItem.prototype.trigger = function (name) {
  1984. if (this._cbs && this._cbs[name]) {
  1985. switch (name) {
  1986. case 'enterFrame':
  1987. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  1988. break;
  1989. case 'drawnFrame':
  1990. this.drawnFrameEvent.currentTime = this.currentFrame;
  1991. this.drawnFrameEvent.totalTime = this.totalFrames;
  1992. this.drawnFrameEvent.direction = this.frameModifier;
  1993. this.triggerEvent(name, this.drawnFrameEvent);
  1994. break;
  1995. case 'loopComplete':
  1996. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  1997. break;
  1998. case 'complete':
  1999. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  2000. break;
  2001. case 'segmentStart':
  2002. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2003. break;
  2004. case 'destroy':
  2005. this.triggerEvent(name, new BMDestroyEvent(name, this));
  2006. break;
  2007. default:
  2008. this.triggerEvent(name);
  2009. }
  2010. }
  2011. if (name === 'enterFrame' && this.onEnterFrame) {
  2012. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  2013. }
  2014. if (name === 'loopComplete' && this.onLoopComplete) {
  2015. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2016. }
  2017. if (name === 'complete' && this.onComplete) {
  2018. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  2019. }
  2020. if (name === 'segmentStart' && this.onSegmentStart) {
  2021. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2022. }
  2023. if (name === 'destroy' && this.onDestroy) {
  2024. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  2025. }
  2026. };
  2027. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  2028. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2029. this.triggerEvent('error', error);
  2030. if (this.onError) {
  2031. this.onError.call(this, error);
  2032. }
  2033. };
  2034. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2035. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2036. this.triggerEvent('error', error);
  2037. if (this.onError) {
  2038. this.onError.call(this, error);
  2039. }
  2040. };
  2041. const animationManager = (function () {
  2042. var moduleOb = {};
  2043. var registeredAnimations = [];
  2044. var initTime = 0;
  2045. var len = 0;
  2046. var playingAnimationsNum = 0;
  2047. var _stopped = true;
  2048. var _isFrozen = false;
  2049. function removeElement(ev) {
  2050. var i = 0;
  2051. var animItem = ev.target;
  2052. while (i < len) {
  2053. if (registeredAnimations[i].animation === animItem) {
  2054. registeredAnimations.splice(i, 1);
  2055. i -= 1;
  2056. len -= 1;
  2057. if (!animItem.isPaused) {
  2058. subtractPlayingCount();
  2059. }
  2060. }
  2061. i += 1;
  2062. }
  2063. }
  2064. function registerAnimation(element, animationData) {
  2065. if (!element) {
  2066. return null;
  2067. }
  2068. var i = 0;
  2069. while (i < len) {
  2070. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2071. return registeredAnimations[i].animation;
  2072. }
  2073. i += 1;
  2074. }
  2075. var animItem = new AnimationItem();
  2076. setupAnimation(animItem, element);
  2077. animItem.setData(element, animationData);
  2078. return animItem;
  2079. }
  2080. function getRegisteredAnimations() {
  2081. var i;
  2082. var lenAnims = registeredAnimations.length;
  2083. var animations = [];
  2084. for (i = 0; i < lenAnims; i += 1) {
  2085. animations.push(registeredAnimations[i].animation);
  2086. }
  2087. return animations;
  2088. }
  2089. function addPlayingCount() {
  2090. playingAnimationsNum += 1;
  2091. activate();
  2092. }
  2093. function subtractPlayingCount() {
  2094. playingAnimationsNum -= 1;
  2095. }
  2096. function setupAnimation(animItem, element) {
  2097. animItem.addEventListener('destroy', removeElement);
  2098. animItem.addEventListener('_active', addPlayingCount);
  2099. animItem.addEventListener('_idle', subtractPlayingCount);
  2100. registeredAnimations.push({ elem: element, animation: animItem });
  2101. len += 1;
  2102. }
  2103. function loadAnimation(params) {
  2104. var animItem = new AnimationItem();
  2105. setupAnimation(animItem, null);
  2106. animItem.setParams(params);
  2107. return animItem;
  2108. }
  2109. function setSpeed(val, animation) {
  2110. var i;
  2111. for (i = 0; i < len; i += 1) {
  2112. registeredAnimations[i].animation.setSpeed(val, animation);
  2113. }
  2114. }
  2115. function setDirection(val, animation) {
  2116. var i;
  2117. for (i = 0; i < len; i += 1) {
  2118. registeredAnimations[i].animation.setDirection(val, animation);
  2119. }
  2120. }
  2121. function play(animation) {
  2122. var i;
  2123. for (i = 0; i < len; i += 1) {
  2124. registeredAnimations[i].animation.play(animation);
  2125. }
  2126. }
  2127. function resume(nowTime) {
  2128. var elapsedTime = nowTime - initTime;
  2129. var i;
  2130. for (i = 0; i < len; i += 1) {
  2131. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2132. }
  2133. initTime = nowTime;
  2134. if (playingAnimationsNum && !_isFrozen) {
  2135. window.requestAnimationFrame(resume);
  2136. } else {
  2137. _stopped = true;
  2138. }
  2139. }
  2140. function first(nowTime) {
  2141. initTime = nowTime;
  2142. window.requestAnimationFrame(resume);
  2143. }
  2144. function pause(animation) {
  2145. var i;
  2146. for (i = 0; i < len; i += 1) {
  2147. registeredAnimations[i].animation.pause(animation);
  2148. }
  2149. }
  2150. function goToAndStop(value, isFrame, animation) {
  2151. var i;
  2152. for (i = 0; i < len; i += 1) {
  2153. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2154. }
  2155. }
  2156. function stop(animation) {
  2157. var i;
  2158. for (i = 0; i < len; i += 1) {
  2159. registeredAnimations[i].animation.stop(animation);
  2160. }
  2161. }
  2162. function togglePause(animation) {
  2163. var i;
  2164. for (i = 0; i < len; i += 1) {
  2165. registeredAnimations[i].animation.togglePause(animation);
  2166. }
  2167. }
  2168. function destroy(animation) {
  2169. var i;
  2170. for (i = (len - 1); i >= 0; i -= 1) {
  2171. registeredAnimations[i].animation.destroy(animation);
  2172. }
  2173. }
  2174. function searchAnimations(animationData, standalone, renderer) {
  2175. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')),
  2176. [].slice.call(document.getElementsByClassName('bodymovin')));
  2177. var i;
  2178. var lenAnims = animElements.length;
  2179. for (i = 0; i < lenAnims; i += 1) {
  2180. if (renderer) {
  2181. animElements[i].setAttribute('data-bm-type', renderer);
  2182. }
  2183. registerAnimation(animElements[i], animationData);
  2184. }
  2185. if (standalone && lenAnims === 0) {
  2186. if (!renderer) {
  2187. renderer = 'svg';
  2188. }
  2189. var body = document.getElementsByTagName('body')[0];
  2190. body.innerText = '';
  2191. var div = createTag('div');
  2192. div.style.width = '100%';
  2193. div.style.height = '100%';
  2194. div.setAttribute('data-bm-type', renderer);
  2195. body.appendChild(div);
  2196. registerAnimation(div, animationData);
  2197. }
  2198. }
  2199. function resize() {
  2200. var i;
  2201. for (i = 0; i < len; i += 1) {
  2202. registeredAnimations[i].animation.resize();
  2203. }
  2204. }
  2205. function activate() {
  2206. if (!_isFrozen && playingAnimationsNum) {
  2207. if (_stopped) {
  2208. window.requestAnimationFrame(first);
  2209. _stopped = false;
  2210. }
  2211. }
  2212. }
  2213. function freeze() {
  2214. _isFrozen = true;
  2215. }
  2216. function unfreeze() {
  2217. _isFrozen = false;
  2218. activate();
  2219. }
  2220. function setVolume(val, animation) {
  2221. var i;
  2222. for (i = 0; i < len; i += 1) {
  2223. registeredAnimations[i].animation.setVolume(val, animation);
  2224. }
  2225. }
  2226. function mute(animation) {
  2227. var i;
  2228. for (i = 0; i < len; i += 1) {
  2229. registeredAnimations[i].animation.mute(animation);
  2230. }
  2231. }
  2232. function unmute(animation) {
  2233. var i;
  2234. for (i = 0; i < len; i += 1) {
  2235. registeredAnimations[i].animation.unmute(animation);
  2236. }
  2237. }
  2238. moduleOb.registerAnimation = registerAnimation;
  2239. moduleOb.loadAnimation = loadAnimation;
  2240. moduleOb.setSpeed = setSpeed;
  2241. moduleOb.setDirection = setDirection;
  2242. moduleOb.play = play;
  2243. moduleOb.pause = pause;
  2244. moduleOb.stop = stop;
  2245. moduleOb.togglePause = togglePause;
  2246. moduleOb.searchAnimations = searchAnimations;
  2247. moduleOb.resize = resize;
  2248. // moduleOb.start = start;
  2249. moduleOb.goToAndStop = goToAndStop;
  2250. moduleOb.destroy = destroy;
  2251. moduleOb.freeze = freeze;
  2252. moduleOb.unfreeze = unfreeze;
  2253. moduleOb.setVolume = setVolume;
  2254. moduleOb.mute = mute;
  2255. moduleOb.unmute = unmute;
  2256. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2257. return moduleOb;
  2258. }());
  2259. /* eslint-disable */
  2260. const BezierFactory = (function () {
  2261. /**
  2262. * BezierEasing - use bezier curve for transition easing function
  2263. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2264. *
  2265. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2266. * Usage:
  2267. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2268. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2269. *
  2270. */
  2271. var ob = {};
  2272. ob.getBezierEasing = getBezierEasing;
  2273. var beziers = {};
  2274. function getBezierEasing(a, b, c, d, nm) {
  2275. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2276. if (beziers[str]) {
  2277. return beziers[str];
  2278. }
  2279. var bezEasing = new BezierEasing([a, b, c, d]);
  2280. beziers[str] = bezEasing;
  2281. return bezEasing;
  2282. }
  2283. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2284. var NEWTON_ITERATIONS = 4;
  2285. var NEWTON_MIN_SLOPE = 0.001;
  2286. var SUBDIVISION_PRECISION = 0.0000001;
  2287. var SUBDIVISION_MAX_ITERATIONS = 10;
  2288. var kSplineTableSize = 11;
  2289. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2290. var float32ArraySupported = typeof Float32Array === 'function';
  2291. function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
  2292. function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
  2293. function C(aA1) { return 3.0 * aA1; }
  2294. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2295. function calcBezier(aT, aA1, aA2) {
  2296. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2297. }
  2298. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2299. function getSlope(aT, aA1, aA2) {
  2300. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2301. }
  2302. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2303. var currentX,
  2304. currentT,
  2305. i = 0;
  2306. do {
  2307. currentT = aA + (aB - aA) / 2.0;
  2308. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2309. if (currentX > 0.0) {
  2310. aB = currentT;
  2311. } else {
  2312. aA = currentT;
  2313. }
  2314. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2315. return currentT;
  2316. }
  2317. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2318. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2319. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2320. if (currentSlope === 0.0) return aGuessT;
  2321. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2322. aGuessT -= currentX / currentSlope;
  2323. }
  2324. return aGuessT;
  2325. }
  2326. /**
  2327. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2328. */
  2329. function BezierEasing(points) {
  2330. this._p = points;
  2331. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2332. this._precomputed = false;
  2333. this.get = this.get.bind(this);
  2334. }
  2335. BezierEasing.prototype = {
  2336. get: function (x) {
  2337. var mX1 = this._p[0],
  2338. mY1 = this._p[1],
  2339. mX2 = this._p[2],
  2340. mY2 = this._p[3];
  2341. if (!this._precomputed) this._precompute();
  2342. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2343. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2344. if (x === 0) return 0;
  2345. if (x === 1) return 1;
  2346. return calcBezier(this._getTForX(x), mY1, mY2);
  2347. },
  2348. // Private part
  2349. _precompute: function () {
  2350. var mX1 = this._p[0],
  2351. mY1 = this._p[1],
  2352. mX2 = this._p[2],
  2353. mY2 = this._p[3];
  2354. this._precomputed = true;
  2355. if (mX1 !== mY1 || mX2 !== mY2) { this._calcSampleValues(); }
  2356. },
  2357. _calcSampleValues: function () {
  2358. var mX1 = this._p[0],
  2359. mX2 = this._p[2];
  2360. for (var i = 0; i < kSplineTableSize; ++i) {
  2361. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2362. }
  2363. },
  2364. /**
  2365. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2366. */
  2367. _getTForX: function (aX) {
  2368. var mX1 = this._p[0],
  2369. mX2 = this._p[2],
  2370. mSampleValues = this._mSampleValues;
  2371. var intervalStart = 0.0;
  2372. var currentSample = 1;
  2373. var lastSample = kSplineTableSize - 1;
  2374. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2375. intervalStart += kSampleStepSize;
  2376. }
  2377. --currentSample;
  2378. // Interpolate to provide an initial guess for t
  2379. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2380. var guessForT = intervalStart + dist * kSampleStepSize;
  2381. var initialSlope = getSlope(guessForT, mX1, mX2);
  2382. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2383. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2384. } if (initialSlope === 0.0) {
  2385. return guessForT;
  2386. }
  2387. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2388. },
  2389. };
  2390. return ob;
  2391. }());
  2392. const pooling = (function () {
  2393. function double(arr) {
  2394. return arr.concat(createSizedArray(arr.length));
  2395. }
  2396. return {
  2397. double: double,
  2398. };
  2399. }());
  2400. const poolFactory = (function () {
  2401. return function (initialLength, _create, _release) {
  2402. var _length = 0;
  2403. var _maxLength = initialLength;
  2404. var pool = createSizedArray(_maxLength);
  2405. var ob = {
  2406. newElement: newElement,
  2407. release: release,
  2408. };
  2409. function newElement() {
  2410. var element;
  2411. if (_length) {
  2412. _length -= 1;
  2413. element = pool[_length];
  2414. } else {
  2415. element = _create();
  2416. }
  2417. return element;
  2418. }
  2419. function release(element) {
  2420. if (_length === _maxLength) {
  2421. pool = pooling.double(pool);
  2422. _maxLength *= 2;
  2423. }
  2424. if (_release) {
  2425. _release(element);
  2426. }
  2427. pool[_length] = element;
  2428. _length += 1;
  2429. }
  2430. return ob;
  2431. };
  2432. }());
  2433. const bezierLengthPool = (function () {
  2434. function create() {
  2435. return {
  2436. addedLength: 0,
  2437. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2438. lengths: createTypedArray('float32', getDefaultCurveSegments()),
  2439. };
  2440. }
  2441. return poolFactory(8, create);
  2442. }());
  2443. const segmentsLengthPool = (function () {
  2444. function create() {
  2445. return {
  2446. lengths: [],
  2447. totalLength: 0,
  2448. };
  2449. }
  2450. function release(element) {
  2451. var i;
  2452. var len = element.lengths.length;
  2453. for (i = 0; i < len; i += 1) {
  2454. bezierLengthPool.release(element.lengths[i]);
  2455. }
  2456. element.lengths.length = 0;
  2457. }
  2458. return poolFactory(8, create, release);
  2459. }());
  2460. function bezFunction() {
  2461. var math = Math;
  2462. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2463. var det1 = (x1 * y2) + (y1 * x3) + (x2 * y3) - (x3 * y2) - (y3 * x1) - (x2 * y1);
  2464. return det1 > -0.001 && det1 < 0.001;
  2465. }
  2466. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2467. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2468. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2469. }
  2470. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2471. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2472. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2473. var diffDist;
  2474. if (dist1 > dist2) {
  2475. if (dist1 > dist3) {
  2476. diffDist = dist1 - dist2 - dist3;
  2477. } else {
  2478. diffDist = dist3 - dist2 - dist1;
  2479. }
  2480. } else if (dist3 > dist2) {
  2481. diffDist = dist3 - dist2 - dist1;
  2482. } else {
  2483. diffDist = dist2 - dist1 - dist3;
  2484. }
  2485. return diffDist > -0.0001 && diffDist < 0.0001;
  2486. }
  2487. var getBezierLength = (function () {
  2488. return function (pt1, pt2, pt3, pt4) {
  2489. var curveSegments = getDefaultCurveSegments();
  2490. var k;
  2491. var i;
  2492. var len;
  2493. var ptCoord;
  2494. var perc;
  2495. var addedLength = 0;
  2496. var ptDistance;
  2497. var point = [];
  2498. var lastPoint = [];
  2499. var lengthData = bezierLengthPool.newElement();
  2500. len = pt3.length;
  2501. for (k = 0; k < curveSegments; k += 1) {
  2502. perc = k / (curveSegments - 1);
  2503. ptDistance = 0;
  2504. for (i = 0; i < len; i += 1) {
  2505. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * pt3[i] + 3 * (1 - perc) * bmPow(perc, 2) * pt4[i] + bmPow(perc, 3) * pt2[i];
  2506. point[i] = ptCoord;
  2507. if (lastPoint[i] !== null) {
  2508. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2509. }
  2510. lastPoint[i] = point[i];
  2511. }
  2512. if (ptDistance) {
  2513. ptDistance = bmSqrt(ptDistance);
  2514. addedLength += ptDistance;
  2515. }
  2516. lengthData.percents[k] = perc;
  2517. lengthData.lengths[k] = addedLength;
  2518. }
  2519. lengthData.addedLength = addedLength;
  2520. return lengthData;
  2521. };
  2522. }());
  2523. function getSegmentsLength(shapeData) {
  2524. var segmentsLength = segmentsLengthPool.newElement();
  2525. var closed = shapeData.c;
  2526. var pathV = shapeData.v;
  2527. var pathO = shapeData.o;
  2528. var pathI = shapeData.i;
  2529. var i;
  2530. var len = shapeData._length;
  2531. var lengths = segmentsLength.lengths;
  2532. var totalLength = 0;
  2533. for (i = 0; i < len - 1; i += 1) {
  2534. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2535. totalLength += lengths[i].addedLength;
  2536. }
  2537. if (closed && len) {
  2538. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2539. totalLength += lengths[i].addedLength;
  2540. }
  2541. segmentsLength.totalLength = totalLength;
  2542. return segmentsLength;
  2543. }
  2544. function BezierData(length) {
  2545. this.segmentLength = 0;
  2546. this.points = new Array(length);
  2547. }
  2548. function PointData(partial, point) {
  2549. this.partialLength = partial;
  2550. this.point = point;
  2551. }
  2552. var buildBezierData = (function () {
  2553. var storedData = {};
  2554. return function (pt1, pt2, pt3, pt4) {
  2555. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2556. if (!storedData[bezierName]) {
  2557. var curveSegments = getDefaultCurveSegments();
  2558. var k;
  2559. var i;
  2560. var len;
  2561. var ptCoord;
  2562. var perc;
  2563. var addedLength = 0;
  2564. var ptDistance;
  2565. var point;
  2566. var lastPoint = null;
  2567. if (pt1.length === 2 && (pt1[0] !== pt2[0] || pt1[1] !== pt2[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt1[0] + pt3[0], pt1[1] + pt3[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt2[0] + pt4[0], pt2[1] + pt4[1])) {
  2568. curveSegments = 2;
  2569. }
  2570. var bezierData = new BezierData(curveSegments);
  2571. len = pt3.length;
  2572. for (k = 0; k < curveSegments; k += 1) {
  2573. point = createSizedArray(len);
  2574. perc = k / (curveSegments - 1);
  2575. ptDistance = 0;
  2576. for (i = 0; i < len; i += 1) {
  2577. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * (pt1[i] + pt3[i]) + 3 * (1 - perc) * bmPow(perc, 2) * (pt2[i] + pt4[i]) + bmPow(perc, 3) * pt2[i];
  2578. point[i] = ptCoord;
  2579. if (lastPoint !== null) {
  2580. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2581. }
  2582. }
  2583. ptDistance = bmSqrt(ptDistance);
  2584. addedLength += ptDistance;
  2585. bezierData.points[k] = new PointData(ptDistance, point);
  2586. lastPoint = point;
  2587. }
  2588. bezierData.segmentLength = addedLength;
  2589. storedData[bezierName] = bezierData;
  2590. }
  2591. return storedData[bezierName];
  2592. };
  2593. }());
  2594. function getDistancePerc(perc, bezierData) {
  2595. var percents = bezierData.percents;
  2596. var lengths = bezierData.lengths;
  2597. var len = percents.length;
  2598. var initPos = bmFloor((len - 1) * perc);
  2599. var lengthPos = perc * bezierData.addedLength;
  2600. var lPerc = 0;
  2601. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2602. return percents[initPos];
  2603. }
  2604. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2605. var flag = true;
  2606. while (flag) {
  2607. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2608. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2609. flag = false;
  2610. } else {
  2611. initPos += dir;
  2612. }
  2613. if (initPos < 0 || initPos >= len - 1) {
  2614. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2615. if (initPos === len - 1) {
  2616. return percents[initPos];
  2617. }
  2618. flag = false;
  2619. }
  2620. }
  2621. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2622. }
  2623. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2624. var t1 = getDistancePerc(percent, bezierData);
  2625. var u1 = 1 - t1;
  2626. var ptX = math.round((u1 * u1 * u1 * pt1[0] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[0] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[0] + t1 * t1 * t1 * pt2[0]) * 1000) / 1000;
  2627. var ptY = math.round((u1 * u1 * u1 * pt1[1] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[1] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[1] + t1 * t1 * t1 * pt2[1]) * 1000) / 1000;
  2628. return [ptX, ptY];
  2629. }
  2630. var bezierSegmentPoints = createTypedArray('float32', 8);
  2631. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2632. if (startPerc < 0) {
  2633. startPerc = 0;
  2634. } else if (startPerc > 1) {
  2635. startPerc = 1;
  2636. }
  2637. var t0 = getDistancePerc(startPerc, bezierData);
  2638. endPerc = endPerc > 1 ? 1 : endPerc;
  2639. var t1 = getDistancePerc(endPerc, bezierData);
  2640. var i;
  2641. var len = pt1.length;
  2642. var u0 = 1 - t0;
  2643. var u1 = 1 - t1;
  2644. var u0u0u0 = u0 * u0 * u0;
  2645. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2646. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2647. var t0t0t0 = t0 * t0 * t0;
  2648. //
  2649. var u0u0u1 = u0 * u0 * u1;
  2650. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2651. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2652. var t0t0t1 = t0 * t0 * t1;
  2653. //
  2654. var u0u1u1 = u0 * u1 * u1;
  2655. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2656. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2657. var t0t1t1 = t0 * t1 * t1;
  2658. //
  2659. var u1u1u1 = u1 * u1 * u1;
  2660. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2661. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2662. var t1t1t1 = t1 * t1 * t1;
  2663. for (i = 0; i < len; i += 1) {
  2664. bezierSegmentPoints[i * 4] = math.round((u0u0u0 * pt1[i] + t0u0u0_3 * pt3[i] + t0t0u0_3 * pt4[i] + t0t0t0 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2665. bezierSegmentPoints[i * 4 + 1] = math.round((u0u0u1 * pt1[i] + t0u0u1_3 * pt3[i] + t0t0u1_3 * pt4[i] + t0t0t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2666. bezierSegmentPoints[i * 4 + 2] = math.round((u0u1u1 * pt1[i] + t0u1u1_3 * pt3[i] + t0t1u1_3 * pt4[i] + t0t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2667. bezierSegmentPoints[i * 4 + 3] = math.round((u1u1u1 * pt1[i] + t1u1u1_3 * pt3[i] + t1t1u1_3 * pt4[i] + t1t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2668. }
  2669. return bezierSegmentPoints;
  2670. }
  2671. return {
  2672. getSegmentsLength: getSegmentsLength,
  2673. getNewSegment: getNewSegment,
  2674. getPointInSegment: getPointInSegment,
  2675. buildBezierData: buildBezierData,
  2676. pointOnLine2D: pointOnLine2D,
  2677. pointOnLine3D: pointOnLine3D,
  2678. };
  2679. }
  2680. const bez = bezFunction();
  2681. var initFrame = initialDefaultFrame;
  2682. var mathAbs = Math.abs;
  2683. function interpolateValue(frameNum, caching) {
  2684. var offsetTime = this.offsetTime;
  2685. var newValue;
  2686. if (this.propType === 'multidimensional') {
  2687. newValue = createTypedArray('float32', this.pv.length);
  2688. }
  2689. var iterationIndex = caching.lastIndex;
  2690. var i = iterationIndex;
  2691. var len = this.keyframes.length - 1;
  2692. var flag = true;
  2693. var keyData;
  2694. var nextKeyData;
  2695. var keyframeMetadata;
  2696. while (flag) {
  2697. keyData = this.keyframes[i];
  2698. nextKeyData = this.keyframes[i + 1];
  2699. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2700. if (keyData.h) {
  2701. keyData = nextKeyData;
  2702. }
  2703. iterationIndex = 0;
  2704. break;
  2705. }
  2706. if ((nextKeyData.t - offsetTime) > frameNum) {
  2707. iterationIndex = i;
  2708. break;
  2709. }
  2710. if (i < len - 1) {
  2711. i += 1;
  2712. } else {
  2713. iterationIndex = 0;
  2714. flag = false;
  2715. }
  2716. }
  2717. keyframeMetadata = this.keyframesMetadata[i] || {};
  2718. var k;
  2719. var kLen;
  2720. var perc;
  2721. var jLen;
  2722. var j;
  2723. var fnc;
  2724. var nextKeyTime = nextKeyData.t - offsetTime;
  2725. var keyTime = keyData.t - offsetTime;
  2726. var endValue;
  2727. if (keyData.to) {
  2728. if (!keyframeMetadata.bezierData) {
  2729. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2730. }
  2731. var bezierData = keyframeMetadata.bezierData;
  2732. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2733. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2734. kLen = bezierData.points[ind].point.length;
  2735. for (k = 0; k < kLen; k += 1) {
  2736. newValue[k] = bezierData.points[ind].point[k];
  2737. }
  2738. // caching._lastKeyframeIndex = -1;
  2739. } else {
  2740. if (keyframeMetadata.__fnct) {
  2741. fnc = keyframeMetadata.__fnct;
  2742. } else {
  2743. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2744. keyframeMetadata.__fnct = fnc;
  2745. }
  2746. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2747. var distanceInLine = bezierData.segmentLength * perc;
  2748. var segmentPerc;
  2749. var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0;
  2750. j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0;
  2751. flag = true;
  2752. jLen = bezierData.points.length;
  2753. while (flag) {
  2754. addedLength += bezierData.points[j].partialLength;
  2755. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2756. kLen = bezierData.points[j].point.length;
  2757. for (k = 0; k < kLen; k += 1) {
  2758. newValue[k] = bezierData.points[j].point[k];
  2759. }
  2760. break;
  2761. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2762. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2763. kLen = bezierData.points[j].point.length;
  2764. for (k = 0; k < kLen; k += 1) {
  2765. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2766. }
  2767. break;
  2768. }
  2769. if (j < jLen - 1) {
  2770. j += 1;
  2771. } else {
  2772. flag = false;
  2773. }
  2774. }
  2775. caching._lastPoint = j;
  2776. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2777. caching._lastKeyframeIndex = i;
  2778. }
  2779. } else {
  2780. var outX;
  2781. var outY;
  2782. var inX;
  2783. var inY;
  2784. var keyValue;
  2785. len = keyData.s.length;
  2786. endValue = nextKeyData.s || keyData.e;
  2787. if (this.sh && keyData.h !== 1) {
  2788. if (frameNum >= nextKeyTime) {
  2789. newValue[0] = endValue[0];
  2790. newValue[1] = endValue[1];
  2791. newValue[2] = endValue[2];
  2792. } else if (frameNum <= keyTime) {
  2793. newValue[0] = keyData.s[0];
  2794. newValue[1] = keyData.s[1];
  2795. newValue[2] = keyData.s[2];
  2796. } else {
  2797. var quatStart = createQuaternion(keyData.s);
  2798. var quatEnd = createQuaternion(endValue);
  2799. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2800. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2801. }
  2802. } else {
  2803. for (i = 0; i < len; i += 1) {
  2804. if (keyData.h !== 1) {
  2805. if (frameNum >= nextKeyTime) {
  2806. perc = 1;
  2807. } else if (frameNum < keyTime) {
  2808. perc = 0;
  2809. } else {
  2810. if (keyData.o.x.constructor === Array) {
  2811. if (!keyframeMetadata.__fnct) {
  2812. keyframeMetadata.__fnct = [];
  2813. }
  2814. if (!keyframeMetadata.__fnct[i]) {
  2815. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2816. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2817. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2818. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2819. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2820. keyframeMetadata.__fnct[i] = fnc;
  2821. } else {
  2822. fnc = keyframeMetadata.__fnct[i];
  2823. }
  2824. } else if (!keyframeMetadata.__fnct) {
  2825. outX = keyData.o.x;
  2826. outY = keyData.o.y;
  2827. inX = keyData.i.x;
  2828. inY = keyData.i.y;
  2829. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2830. keyData.keyframeMetadata = fnc;
  2831. } else {
  2832. fnc = keyframeMetadata.__fnct;
  2833. }
  2834. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2835. }
  2836. }
  2837. endValue = nextKeyData.s || keyData.e;
  2838. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2839. if (this.propType === 'multidimensional') {
  2840. newValue[i] = keyValue;
  2841. } else {
  2842. newValue = keyValue;
  2843. }
  2844. }
  2845. }
  2846. }
  2847. caching.lastIndex = iterationIndex;
  2848. return newValue;
  2849. }
  2850. // based on @Toji's https://github.com/toji/gl-matrix/
  2851. function slerp(a, b, t) {
  2852. var out = [];
  2853. var ax = a[0];
  2854. var ay = a[1];
  2855. var az = a[2];
  2856. var aw = a[3];
  2857. var bx = b[0];
  2858. var by = b[1];
  2859. var bz = b[2];
  2860. var bw = b[3];
  2861. var omega;
  2862. var cosom;
  2863. var sinom;
  2864. var scale0;
  2865. var scale1;
  2866. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2867. if (cosom < 0.0) {
  2868. cosom = -cosom;
  2869. bx = -bx;
  2870. by = -by;
  2871. bz = -bz;
  2872. bw = -bw;
  2873. }
  2874. if ((1.0 - cosom) > 0.000001) {
  2875. omega = Math.acos(cosom);
  2876. sinom = Math.sin(omega);
  2877. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2878. scale1 = Math.sin(t * omega) / sinom;
  2879. } else {
  2880. scale0 = 1.0 - t;
  2881. scale1 = t;
  2882. }
  2883. out[0] = scale0 * ax + scale1 * bx;
  2884. out[1] = scale0 * ay + scale1 * by;
  2885. out[2] = scale0 * az + scale1 * bz;
  2886. out[3] = scale0 * aw + scale1 * bw;
  2887. return out;
  2888. }
  2889. function quaternionToEuler(out, quat) {
  2890. var qx = quat[0];
  2891. var qy = quat[1];
  2892. var qz = quat[2];
  2893. var qw = quat[3];
  2894. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2895. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2896. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2897. out[0] = heading / degToRads;
  2898. out[1] = attitude / degToRads;
  2899. out[2] = bank / degToRads;
  2900. }
  2901. function createQuaternion(values) {
  2902. var heading = values[0] * degToRads;
  2903. var attitude = values[1] * degToRads;
  2904. var bank = values[2] * degToRads;
  2905. var c1 = Math.cos(heading / 2);
  2906. var c2 = Math.cos(attitude / 2);
  2907. var c3 = Math.cos(bank / 2);
  2908. var s1 = Math.sin(heading / 2);
  2909. var s2 = Math.sin(attitude / 2);
  2910. var s3 = Math.sin(bank / 2);
  2911. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2912. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2913. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2914. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2915. return [x, y, z, w];
  2916. }
  2917. function getValueAtCurrentTime() {
  2918. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2919. var initTime = this.keyframes[0].t - this.offsetTime;
  2920. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2921. if (!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))) {
  2922. if (this._caching.lastFrame >= frameNum) {
  2923. this._caching._lastKeyframeIndex = -1;
  2924. this._caching.lastIndex = 0;
  2925. }
  2926. var renderResult = this.interpolateValue(frameNum, this._caching);
  2927. this.pv = renderResult;
  2928. }
  2929. this._caching.lastFrame = frameNum;
  2930. return this.pv;
  2931. }
  2932. function setVValue(val) {
  2933. var multipliedValue;
  2934. if (this.propType === 'unidimensional') {
  2935. multipliedValue = val * this.mult;
  2936. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  2937. this.v = multipliedValue;
  2938. this._mdf = true;
  2939. }
  2940. } else {
  2941. var i = 0;
  2942. var len = this.v.length;
  2943. while (i < len) {
  2944. multipliedValue = val[i] * this.mult;
  2945. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  2946. this.v[i] = multipliedValue;
  2947. this._mdf = true;
  2948. }
  2949. i += 1;
  2950. }
  2951. }
  2952. }
  2953. function processEffectsSequence() {
  2954. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  2955. return;
  2956. }
  2957. if (this.lock) {
  2958. this.setVValue(this.pv);
  2959. return;
  2960. }
  2961. this.lock = true;
  2962. this._mdf = this._isFirstFrame;
  2963. var i;
  2964. var len = this.effectsSequence.length;
  2965. var finalValue = this.kf ? this.pv : this.data.k;
  2966. for (i = 0; i < len; i += 1) {
  2967. finalValue = this.effectsSequence[i](finalValue);
  2968. }
  2969. this.setVValue(finalValue);
  2970. this._isFirstFrame = false;
  2971. this.lock = false;
  2972. this.frameId = this.elem.globalData.frameId;
  2973. }
  2974. function addEffect(effectFunction) {
  2975. this.effectsSequence.push(effectFunction);
  2976. this.container.addDynamicProperty(this);
  2977. }
  2978. function ValueProperty(elem, data, mult, container) {
  2979. this.propType = 'unidimensional';
  2980. this.mult = mult || 1;
  2981. this.data = data;
  2982. this.v = mult ? data.k * mult : data.k;
  2983. this.pv = data.k;
  2984. this._mdf = false;
  2985. this.elem = elem;
  2986. this.container = container;
  2987. this.comp = elem.comp;
  2988. this.k = false;
  2989. this.kf = false;
  2990. this.vel = 0;
  2991. this.effectsSequence = [];
  2992. this._isFirstFrame = true;
  2993. this.getValue = processEffectsSequence;
  2994. this.setVValue = setVValue;
  2995. this.addEffect = addEffect;
  2996. }
  2997. function MultiDimensionalProperty(elem, data, mult, container) {
  2998. this.propType = 'multidimensional';
  2999. this.mult = mult || 1;
  3000. this.data = data;
  3001. this._mdf = false;
  3002. this.elem = elem;
  3003. this.container = container;
  3004. this.comp = elem.comp;
  3005. this.k = false;
  3006. this.kf = false;
  3007. this.frameId = -1;
  3008. var i;
  3009. var len = data.k.length;
  3010. this.v = createTypedArray('float32', len);
  3011. this.pv = createTypedArray('float32', len);
  3012. this.vel = createTypedArray('float32', len);
  3013. for (i = 0; i < len; i += 1) {
  3014. this.v[i] = data.k[i] * this.mult;
  3015. this.pv[i] = data.k[i];
  3016. }
  3017. this._isFirstFrame = true;
  3018. this.effectsSequence = [];
  3019. this.getValue = processEffectsSequence;
  3020. this.setVValue = setVValue;
  3021. this.addEffect = addEffect;
  3022. }
  3023. function KeyframedValueProperty(elem, data, mult, container) {
  3024. this.propType = 'unidimensional';
  3025. this.keyframes = data.k;
  3026. this.keyframesMetadata = [];
  3027. this.offsetTime = elem.data.st;
  3028. this.frameId = -1;
  3029. this._caching = {
  3030. lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1,
  3031. };
  3032. this.k = true;
  3033. this.kf = true;
  3034. this.data = data;
  3035. this.mult = mult || 1;
  3036. this.elem = elem;
  3037. this.container = container;
  3038. this.comp = elem.comp;
  3039. this.v = initFrame;
  3040. this.pv = initFrame;
  3041. this._isFirstFrame = true;
  3042. this.getValue = processEffectsSequence;
  3043. this.setVValue = setVValue;
  3044. this.interpolateValue = interpolateValue;
  3045. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3046. this.addEffect = addEffect;
  3047. }
  3048. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3049. this.propType = 'multidimensional';
  3050. var i;
  3051. var len = data.k.length;
  3052. var s;
  3053. var e;
  3054. var to;
  3055. var ti;
  3056. for (i = 0; i < len - 1; i += 1) {
  3057. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3058. s = data.k[i].s;
  3059. e = data.k[i + 1].s;
  3060. to = data.k[i].to;
  3061. ti = data.k[i].ti;
  3062. if ((s.length === 2 && !(s[0] === e[0] && s[1] === e[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], s[0] + to[0], s[1] + to[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], e[0] + ti[0], e[1] + ti[1])) || (s.length === 3 && !(s[0] === e[0] && s[1] === e[1] && s[2] === e[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], s[0] + to[0], s[1] + to[1], s[2] + to[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], e[0] + ti[0], e[1] + ti[1], e[2] + ti[2]))) {
  3063. data.k[i].to = null;
  3064. data.k[i].ti = null;
  3065. }
  3066. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3067. if (s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) {
  3068. data.k[i].to = null;
  3069. data.k[i].ti = null;
  3070. }
  3071. }
  3072. }
  3073. }
  3074. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3075. this.data = data;
  3076. this.keyframes = data.k;
  3077. this.keyframesMetadata = [];
  3078. this.offsetTime = elem.data.st;
  3079. this.k = true;
  3080. this.kf = true;
  3081. this._isFirstFrame = true;
  3082. this.mult = mult || 1;
  3083. this.elem = elem;
  3084. this.container = container;
  3085. this.comp = elem.comp;
  3086. this.getValue = processEffectsSequence;
  3087. this.setVValue = setVValue;
  3088. this.interpolateValue = interpolateValue;
  3089. this.frameId = -1;
  3090. var arrLen = data.k[0].s.length;
  3091. this.v = createTypedArray('float32', arrLen);
  3092. this.pv = createTypedArray('float32', arrLen);
  3093. for (i = 0; i < arrLen; i += 1) {
  3094. this.v[i] = initFrame;
  3095. this.pv[i] = initFrame;
  3096. }
  3097. this._caching = { lastFrame: initFrame, lastIndex: 0, value: createTypedArray('float32', arrLen) };
  3098. this.addEffect = addEffect;
  3099. }
  3100. const PropertyFactory = (function () {
  3101. function getProp(elem, data, type, mult, container) {
  3102. if (data.sid) {
  3103. data = elem.globalData.slotManager.getProp(data);
  3104. }
  3105. var p;
  3106. if (!data.k.length) {
  3107. p = new ValueProperty(elem, data, mult, container);
  3108. } else if (typeof (data.k[0]) === 'number') {
  3109. p = new MultiDimensionalProperty(elem, data, mult, container);
  3110. } else {
  3111. switch (type) {
  3112. case 0:
  3113. p = new KeyframedValueProperty(elem, data, mult, container);
  3114. break;
  3115. case 1:
  3116. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3117. break;
  3118. default:
  3119. break;
  3120. }
  3121. }
  3122. if (p.effectsSequence.length) {
  3123. container.addDynamicProperty(p);
  3124. }
  3125. return p;
  3126. }
  3127. var ob = {
  3128. getProp: getProp,
  3129. };
  3130. return ob;
  3131. }());
  3132. function DynamicPropertyContainer() {}
  3133. DynamicPropertyContainer.prototype = {
  3134. addDynamicProperty: function (prop) {
  3135. if (this.dynamicProperties.indexOf(prop) === -1) {
  3136. this.dynamicProperties.push(prop);
  3137. this.container.addDynamicProperty(this);
  3138. this._isAnimated = true;
  3139. }
  3140. },
  3141. iterateDynamicProperties: function () {
  3142. this._mdf = false;
  3143. var i;
  3144. var len = this.dynamicProperties.length;
  3145. for (i = 0; i < len; i += 1) {
  3146. this.dynamicProperties[i].getValue();
  3147. if (this.dynamicProperties[i]._mdf) {
  3148. this._mdf = true;
  3149. }
  3150. }
  3151. },
  3152. initDynamicPropertyContainer: function (container) {
  3153. this.container = container;
  3154. this.dynamicProperties = [];
  3155. this._mdf = false;
  3156. this._isAnimated = false;
  3157. },
  3158. };
  3159. const pointPool = (function () {
  3160. function create() {
  3161. return createTypedArray('float32', 2);
  3162. }
  3163. return poolFactory(8, create);
  3164. }());
  3165. function ShapePath() {
  3166. this.c = false;
  3167. this._length = 0;
  3168. this._maxLength = 8;
  3169. this.v = createSizedArray(this._maxLength);
  3170. this.o = createSizedArray(this._maxLength);
  3171. this.i = createSizedArray(this._maxLength);
  3172. }
  3173. ShapePath.prototype.setPathData = function (closed, len) {
  3174. this.c = closed;
  3175. this.setLength(len);
  3176. var i = 0;
  3177. while (i < len) {
  3178. this.v[i] = pointPool.newElement();
  3179. this.o[i] = pointPool.newElement();
  3180. this.i[i] = pointPool.newElement();
  3181. i += 1;
  3182. }
  3183. };
  3184. ShapePath.prototype.setLength = function (len) {
  3185. while (this._maxLength < len) {
  3186. this.doubleArrayLength();
  3187. }
  3188. this._length = len;
  3189. };
  3190. ShapePath.prototype.doubleArrayLength = function () {
  3191. this.v = this.v.concat(createSizedArray(this._maxLength));
  3192. this.i = this.i.concat(createSizedArray(this._maxLength));
  3193. this.o = this.o.concat(createSizedArray(this._maxLength));
  3194. this._maxLength *= 2;
  3195. };
  3196. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3197. var arr;
  3198. this._length = Math.max(this._length, pos + 1);
  3199. if (this._length >= this._maxLength) {
  3200. this.doubleArrayLength();
  3201. }
  3202. switch (type) {
  3203. case 'v':
  3204. arr = this.v;
  3205. break;
  3206. case 'i':
  3207. arr = this.i;
  3208. break;
  3209. case 'o':
  3210. arr = this.o;
  3211. break;
  3212. default:
  3213. arr = [];
  3214. break;
  3215. }
  3216. if (!arr[pos] || (arr[pos] && !replace)) {
  3217. arr[pos] = pointPool.newElement();
  3218. }
  3219. arr[pos][0] = x;
  3220. arr[pos][1] = y;
  3221. };
  3222. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3223. this.setXYAt(vX, vY, 'v', pos, replace);
  3224. this.setXYAt(oX, oY, 'o', pos, replace);
  3225. this.setXYAt(iX, iY, 'i', pos, replace);
  3226. };
  3227. ShapePath.prototype.reverse = function () {
  3228. var newPath = new ShapePath();
  3229. newPath.setPathData(this.c, this._length);
  3230. var vertices = this.v;
  3231. var outPoints = this.o;
  3232. var inPoints = this.i;
  3233. var init = 0;
  3234. if (this.c) {
  3235. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3236. init = 1;
  3237. }
  3238. var cnt = this._length - 1;
  3239. var len = this._length;
  3240. var i;
  3241. for (i = init; i < len; i += 1) {
  3242. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3243. cnt -= 1;
  3244. }
  3245. return newPath;
  3246. };
  3247. ShapePath.prototype.length = function () {
  3248. return this._length;
  3249. };
  3250. const shapePool = (function () {
  3251. function create() {
  3252. return new ShapePath();
  3253. }
  3254. function release(shapePath) {
  3255. var len = shapePath._length;
  3256. var i;
  3257. for (i = 0; i < len; i += 1) {
  3258. pointPool.release(shapePath.v[i]);
  3259. pointPool.release(shapePath.i[i]);
  3260. pointPool.release(shapePath.o[i]);
  3261. shapePath.v[i] = null;
  3262. shapePath.i[i] = null;
  3263. shapePath.o[i] = null;
  3264. }
  3265. shapePath._length = 0;
  3266. shapePath.c = false;
  3267. }
  3268. function clone(shape) {
  3269. var cloned = factory.newElement();
  3270. var i;
  3271. var len = shape._length === undefined ? shape.v.length : shape._length;
  3272. cloned.setLength(len);
  3273. cloned.c = shape.c;
  3274. for (i = 0; i < len; i += 1) {
  3275. cloned.setTripleAt(shape.v[i][0], shape.v[i][1], shape.o[i][0], shape.o[i][1], shape.i[i][0], shape.i[i][1], i);
  3276. }
  3277. return cloned;
  3278. }
  3279. var factory = poolFactory(4, create, release);
  3280. factory.clone = clone;
  3281. return factory;
  3282. }());
  3283. function ShapeCollection() {
  3284. this._length = 0;
  3285. this._maxLength = 4;
  3286. this.shapes = createSizedArray(this._maxLength);
  3287. }
  3288. ShapeCollection.prototype.addShape = function (shapeData) {
  3289. if (this._length === this._maxLength) {
  3290. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3291. this._maxLength *= 2;
  3292. }
  3293. this.shapes[this._length] = shapeData;
  3294. this._length += 1;
  3295. };
  3296. ShapeCollection.prototype.releaseShapes = function () {
  3297. var i;
  3298. for (i = 0; i < this._length; i += 1) {
  3299. shapePool.release(this.shapes[i]);
  3300. }
  3301. this._length = 0;
  3302. };
  3303. const shapeCollectionPool = (function () {
  3304. var ob = {
  3305. newShapeCollection: newShapeCollection,
  3306. release: release,
  3307. };
  3308. var _length = 0;
  3309. var _maxLength = 4;
  3310. var pool = createSizedArray(_maxLength);
  3311. function newShapeCollection() {
  3312. var shapeCollection;
  3313. if (_length) {
  3314. _length -= 1;
  3315. shapeCollection = pool[_length];
  3316. } else {
  3317. shapeCollection = new ShapeCollection();
  3318. }
  3319. return shapeCollection;
  3320. }
  3321. function release(shapeCollection) {
  3322. var i;
  3323. var len = shapeCollection._length;
  3324. for (i = 0; i < len; i += 1) {
  3325. shapePool.release(shapeCollection.shapes[i]);
  3326. }
  3327. shapeCollection._length = 0;
  3328. if (_length === _maxLength) {
  3329. pool = pooling.double(pool);
  3330. _maxLength *= 2;
  3331. }
  3332. pool[_length] = shapeCollection;
  3333. _length += 1;
  3334. }
  3335. return ob;
  3336. }());
  3337. const ShapePropertyFactory = (function () {
  3338. var initFrame = -999999;
  3339. function interpolateShape(frameNum, previousValue, caching) {
  3340. var iterationIndex = caching.lastIndex;
  3341. var keyPropS;
  3342. var keyPropE;
  3343. var isHold;
  3344. var j;
  3345. var k;
  3346. var jLen;
  3347. var kLen;
  3348. var perc;
  3349. var vertexValue;
  3350. var kf = this.keyframes;
  3351. if (frameNum < kf[0].t - this.offsetTime) {
  3352. keyPropS = kf[0].s[0];
  3353. isHold = true;
  3354. iterationIndex = 0;
  3355. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3356. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3357. /* if(kf[kf.length - 1].s){
  3358. keyPropS = kf[kf.length - 1].s[0];
  3359. }else{
  3360. keyPropS = kf[kf.length - 2].e[0];
  3361. } */
  3362. isHold = true;
  3363. } else {
  3364. var i = iterationIndex;
  3365. var len = kf.length - 1;
  3366. var flag = true;
  3367. var keyData;
  3368. var nextKeyData;
  3369. var keyframeMetadata;
  3370. while (flag) {
  3371. keyData = kf[i];
  3372. nextKeyData = kf[i + 1];
  3373. if ((nextKeyData.t - this.offsetTime) > frameNum) {
  3374. break;
  3375. }
  3376. if (i < len - 1) {
  3377. i += 1;
  3378. } else {
  3379. flag = false;
  3380. }
  3381. }
  3382. keyframeMetadata = this.keyframesMetadata[i] || {};
  3383. isHold = keyData.h === 1;
  3384. iterationIndex = i;
  3385. if (!isHold) {
  3386. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3387. perc = 1;
  3388. } else if (frameNum < keyData.t - this.offsetTime) {
  3389. perc = 0;
  3390. } else {
  3391. var fnc;
  3392. if (keyframeMetadata.__fnct) {
  3393. fnc = keyframeMetadata.__fnct;
  3394. } else {
  3395. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3396. keyframeMetadata.__fnct = fnc;
  3397. }
  3398. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / ((nextKeyData.t - this.offsetTime) - (keyData.t - this.offsetTime)));
  3399. }
  3400. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3401. }
  3402. keyPropS = keyData.s[0];
  3403. }
  3404. jLen = previousValue._length;
  3405. kLen = keyPropS.i[0].length;
  3406. caching.lastIndex = iterationIndex;
  3407. for (j = 0; j < jLen; j += 1) {
  3408. for (k = 0; k < kLen; k += 1) {
  3409. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3410. previousValue.i[j][k] = vertexValue;
  3411. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3412. previousValue.o[j][k] = vertexValue;
  3413. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3414. previousValue.v[j][k] = vertexValue;
  3415. }
  3416. }
  3417. }
  3418. function interpolateShapeCurrentTime() {
  3419. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3420. var initTime = this.keyframes[0].t - this.offsetTime;
  3421. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3422. var lastFrame = this._caching.lastFrame;
  3423. if (!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))) {
  3424. /// /
  3425. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3426. this.interpolateShape(frameNum, this.pv, this._caching);
  3427. /// /
  3428. }
  3429. this._caching.lastFrame = frameNum;
  3430. return this.pv;
  3431. }
  3432. function resetShape() {
  3433. this.paths = this.localShapeCollection;
  3434. }
  3435. function shapesEqual(shape1, shape2) {
  3436. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3437. return false;
  3438. }
  3439. var i;
  3440. var len = shape1._length;
  3441. for (i = 0; i < len; i += 1) {
  3442. if (shape1.v[i][0] !== shape2.v[i][0]
  3443. || shape1.v[i][1] !== shape2.v[i][1]
  3444. || shape1.o[i][0] !== shape2.o[i][0]
  3445. || shape1.o[i][1] !== shape2.o[i][1]
  3446. || shape1.i[i][0] !== shape2.i[i][0]
  3447. || shape1.i[i][1] !== shape2.i[i][1]) {
  3448. return false;
  3449. }
  3450. }
  3451. return true;
  3452. }
  3453. function setVValue(newPath) {
  3454. if (!shapesEqual(this.v, newPath)) {
  3455. this.v = shapePool.clone(newPath);
  3456. this.localShapeCollection.releaseShapes();
  3457. this.localShapeCollection.addShape(this.v);
  3458. this._mdf = true;
  3459. this.paths = this.localShapeCollection;
  3460. }
  3461. }
  3462. function processEffectsSequence() {
  3463. if (this.elem.globalData.frameId === this.frameId) {
  3464. return;
  3465. } if (!this.effectsSequence.length) {
  3466. this._mdf = false;
  3467. return;
  3468. }
  3469. if (this.lock) {
  3470. this.setVValue(this.pv);
  3471. return;
  3472. }
  3473. this.lock = true;
  3474. this._mdf = false;
  3475. var finalValue;
  3476. if (this.kf) {
  3477. finalValue = this.pv;
  3478. } else if (this.data.ks) {
  3479. finalValue = this.data.ks.k;
  3480. } else {
  3481. finalValue = this.data.pt.k;
  3482. }
  3483. var i;
  3484. var len = this.effectsSequence.length;
  3485. for (i = 0; i < len; i += 1) {
  3486. finalValue = this.effectsSequence[i](finalValue);
  3487. }
  3488. this.setVValue(finalValue);
  3489. this.lock = false;
  3490. this.frameId = this.elem.globalData.frameId;
  3491. }
  3492. function ShapeProperty(elem, data, type) {
  3493. this.propType = 'shape';
  3494. this.comp = elem.comp;
  3495. this.container = elem;
  3496. this.elem = elem;
  3497. this.data = data;
  3498. this.k = false;
  3499. this.kf = false;
  3500. this._mdf = false;
  3501. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3502. this.v = shapePool.clone(pathData);
  3503. this.pv = shapePool.clone(this.v);
  3504. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3505. this.paths = this.localShapeCollection;
  3506. this.paths.addShape(this.v);
  3507. this.reset = resetShape;
  3508. this.effectsSequence = [];
  3509. }
  3510. function addEffect(effectFunction) {
  3511. this.effectsSequence.push(effectFunction);
  3512. this.container.addDynamicProperty(this);
  3513. }
  3514. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3515. ShapeProperty.prototype.getValue = processEffectsSequence;
  3516. ShapeProperty.prototype.setVValue = setVValue;
  3517. ShapeProperty.prototype.addEffect = addEffect;
  3518. function KeyframedShapeProperty(elem, data, type) {
  3519. this.propType = 'shape';
  3520. this.comp = elem.comp;
  3521. this.elem = elem;
  3522. this.container = elem;
  3523. this.offsetTime = elem.data.st;
  3524. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3525. this.keyframesMetadata = [];
  3526. this.k = true;
  3527. this.kf = true;
  3528. var len = this.keyframes[0].s[0].i.length;
  3529. this.v = shapePool.newElement();
  3530. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3531. this.pv = shapePool.clone(this.v);
  3532. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3533. this.paths = this.localShapeCollection;
  3534. this.paths.addShape(this.v);
  3535. this.lastFrame = initFrame;
  3536. this.reset = resetShape;
  3537. this._caching = { lastFrame: initFrame, lastIndex: 0 };
  3538. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3539. }
  3540. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3541. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3542. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3543. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3544. var EllShapeProperty = (function () {
  3545. var cPoint = roundCorner;
  3546. function EllShapePropertyFactory(elem, data) {
  3547. this.v = shapePool.newElement();
  3548. this.v.setPathData(true, 4);
  3549. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3550. this.paths = this.localShapeCollection;
  3551. this.localShapeCollection.addShape(this.v);
  3552. this.d = data.d;
  3553. this.elem = elem;
  3554. this.comp = elem.comp;
  3555. this.frameId = -1;
  3556. this.initDynamicPropertyContainer(elem);
  3557. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3558. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3559. if (this.dynamicProperties.length) {
  3560. this.k = true;
  3561. } else {
  3562. this.k = false;
  3563. this.convertEllToPath();
  3564. }
  3565. }
  3566. EllShapePropertyFactory.prototype = {
  3567. reset: resetShape,
  3568. getValue: function () {
  3569. if (this.elem.globalData.frameId === this.frameId) {
  3570. return;
  3571. }
  3572. this.frameId = this.elem.globalData.frameId;
  3573. this.iterateDynamicProperties();
  3574. if (this._mdf) {
  3575. this.convertEllToPath();
  3576. }
  3577. },
  3578. convertEllToPath: function () {
  3579. var p0 = this.p.v[0];
  3580. var p1 = this.p.v[1];
  3581. var s0 = this.s.v[0] / 2;
  3582. var s1 = this.s.v[1] / 2;
  3583. var _cw = this.d !== 3;
  3584. var _v = this.v;
  3585. _v.v[0][0] = p0;
  3586. _v.v[0][1] = p1 - s1;
  3587. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3588. _v.v[1][1] = p1;
  3589. _v.v[2][0] = p0;
  3590. _v.v[2][1] = p1 + s1;
  3591. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3592. _v.v[3][1] = p1;
  3593. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3594. _v.i[0][1] = p1 - s1;
  3595. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3596. _v.i[1][1] = p1 - s1 * cPoint;
  3597. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3598. _v.i[2][1] = p1 + s1;
  3599. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3600. _v.i[3][1] = p1 + s1 * cPoint;
  3601. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3602. _v.o[0][1] = p1 - s1;
  3603. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3604. _v.o[1][1] = p1 + s1 * cPoint;
  3605. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3606. _v.o[2][1] = p1 + s1;
  3607. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3608. _v.o[3][1] = p1 - s1 * cPoint;
  3609. },
  3610. };
  3611. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3612. return EllShapePropertyFactory;
  3613. }());
  3614. var StarShapeProperty = (function () {
  3615. function StarShapePropertyFactory(elem, data) {
  3616. this.v = shapePool.newElement();
  3617. this.v.setPathData(true, 0);
  3618. this.elem = elem;
  3619. this.comp = elem.comp;
  3620. this.data = data;
  3621. this.frameId = -1;
  3622. this.d = data.d;
  3623. this.initDynamicPropertyContainer(elem);
  3624. if (data.sy === 1) {
  3625. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3626. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3627. this.convertToPath = this.convertStarToPath;
  3628. } else {
  3629. this.convertToPath = this.convertPolygonToPath;
  3630. }
  3631. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3632. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3633. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3634. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3635. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3636. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3637. this.localShapeCollection.addShape(this.v);
  3638. this.paths = this.localShapeCollection;
  3639. if (this.dynamicProperties.length) {
  3640. this.k = true;
  3641. } else {
  3642. this.k = false;
  3643. this.convertToPath();
  3644. }
  3645. }
  3646. StarShapePropertyFactory.prototype = {
  3647. reset: resetShape,
  3648. getValue: function () {
  3649. if (this.elem.globalData.frameId === this.frameId) {
  3650. return;
  3651. }
  3652. this.frameId = this.elem.globalData.frameId;
  3653. this.iterateDynamicProperties();
  3654. if (this._mdf) {
  3655. this.convertToPath();
  3656. }
  3657. },
  3658. convertStarToPath: function () {
  3659. var numPts = Math.floor(this.pt.v) * 2;
  3660. var angle = (Math.PI * 2) / numPts;
  3661. /* this.v.v.length = numPts;
  3662. this.v.i.length = numPts;
  3663. this.v.o.length = numPts; */
  3664. var longFlag = true;
  3665. var longRad = this.or.v;
  3666. var shortRad = this.ir.v;
  3667. var longRound = this.os.v;
  3668. var shortRound = this.is.v;
  3669. var longPerimSegment = (2 * Math.PI * longRad) / (numPts * 2);
  3670. var shortPerimSegment = (2 * Math.PI * shortRad) / (numPts * 2);
  3671. var i;
  3672. var rad;
  3673. var roundness;
  3674. var perimSegment;
  3675. var currentAng = -Math.PI / 2;
  3676. currentAng += this.r.v;
  3677. var dir = this.data.d === 3 ? -1 : 1;
  3678. this.v._length = 0;
  3679. for (i = 0; i < numPts; i += 1) {
  3680. rad = longFlag ? longRad : shortRad;
  3681. roundness = longFlag ? longRound : shortRound;
  3682. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3683. var x = rad * Math.cos(currentAng);
  3684. var y = rad * Math.sin(currentAng);
  3685. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3686. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3687. x += +this.p.v[0];
  3688. y += +this.p.v[1];
  3689. this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
  3690. /* this.v.v[i] = [x,y];
  3691. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3692. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3693. this.v._length = numPts; */
  3694. longFlag = !longFlag;
  3695. currentAng += angle * dir;
  3696. }
  3697. },
  3698. convertPolygonToPath: function () {
  3699. var numPts = Math.floor(this.pt.v);
  3700. var angle = (Math.PI * 2) / numPts;
  3701. var rad = this.or.v;
  3702. var roundness = this.os.v;
  3703. var perimSegment = (2 * Math.PI * rad) / (numPts * 4);
  3704. var i;
  3705. var currentAng = -Math.PI * 0.5;
  3706. var dir = this.data.d === 3 ? -1 : 1;
  3707. currentAng += this.r.v;
  3708. this.v._length = 0;
  3709. for (i = 0; i < numPts; i += 1) {
  3710. var x = rad * Math.cos(currentAng);
  3711. var y = rad * Math.sin(currentAng);
  3712. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3713. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3714. x += +this.p.v[0];
  3715. y += +this.p.v[1];
  3716. this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
  3717. currentAng += angle * dir;
  3718. }
  3719. this.paths.length = 0;
  3720. this.paths[0] = this.v;
  3721. },
  3722. };
  3723. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3724. return StarShapePropertyFactory;
  3725. }());
  3726. var RectShapeProperty = (function () {
  3727. function RectShapePropertyFactory(elem, data) {
  3728. this.v = shapePool.newElement();
  3729. this.v.c = true;
  3730. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3731. this.localShapeCollection.addShape(this.v);
  3732. this.paths = this.localShapeCollection;
  3733. this.elem = elem;
  3734. this.comp = elem.comp;
  3735. this.frameId = -1;
  3736. this.d = data.d;
  3737. this.initDynamicPropertyContainer(elem);
  3738. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3739. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3740. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3741. if (this.dynamicProperties.length) {
  3742. this.k = true;
  3743. } else {
  3744. this.k = false;
  3745. this.convertRectToPath();
  3746. }
  3747. }
  3748. RectShapePropertyFactory.prototype = {
  3749. convertRectToPath: function () {
  3750. var p0 = this.p.v[0];
  3751. var p1 = this.p.v[1];
  3752. var v0 = this.s.v[0] / 2;
  3753. var v1 = this.s.v[1] / 2;
  3754. var round = bmMin(v0, v1, this.r.v);
  3755. var cPoint = round * (1 - roundCorner);
  3756. this.v._length = 0;
  3757. if (this.d === 2 || this.d === 1) {
  3758. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3759. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3760. if (round !== 0) {
  3761. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3762. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3763. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3764. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3765. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3766. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3767. } else {
  3768. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3769. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3770. }
  3771. } else {
  3772. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3773. if (round !== 0) {
  3774. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3775. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3776. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3777. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3778. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3779. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3780. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3781. } else {
  3782. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3783. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3784. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3785. }
  3786. }
  3787. },
  3788. getValue: function () {
  3789. if (this.elem.globalData.frameId === this.frameId) {
  3790. return;
  3791. }
  3792. this.frameId = this.elem.globalData.frameId;
  3793. this.iterateDynamicProperties();
  3794. if (this._mdf) {
  3795. this.convertRectToPath();
  3796. }
  3797. },
  3798. reset: resetShape,
  3799. };
  3800. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3801. return RectShapePropertyFactory;
  3802. }());
  3803. function getShapeProp(elem, data, type) {
  3804. var prop;
  3805. if (type === 3 || type === 4) {
  3806. var dataProp = type === 3 ? data.pt : data.ks;
  3807. var keys = dataProp.k;
  3808. if (keys.length) {
  3809. prop = new KeyframedShapeProperty(elem, data, type);
  3810. } else {
  3811. prop = new ShapeProperty(elem, data, type);
  3812. }
  3813. } else if (type === 5) {
  3814. prop = new RectShapeProperty(elem, data);
  3815. } else if (type === 6) {
  3816. prop = new EllShapeProperty(elem, data);
  3817. } else if (type === 7) {
  3818. prop = new StarShapeProperty(elem, data);
  3819. }
  3820. if (prop.k) {
  3821. elem.addDynamicProperty(prop);
  3822. }
  3823. return prop;
  3824. }
  3825. function getConstructorFunction() {
  3826. return ShapeProperty;
  3827. }
  3828. function getKeyframedConstructorFunction() {
  3829. return KeyframedShapeProperty;
  3830. }
  3831. var ob = {};
  3832. ob.getShapeProp = getShapeProp;
  3833. ob.getConstructorFunction = getConstructorFunction;
  3834. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3835. return ob;
  3836. }());
  3837. /*!
  3838. Transformation Matrix v2.0
  3839. (c) Epistemex 2014-2015
  3840. www.epistemex.com
  3841. By Ken Fyrstenberg
  3842. Contributions by leeoniya.
  3843. License: MIT, header required.
  3844. */
  3845. /**
  3846. * 2D transformation matrix object initialized with identity matrix.
  3847. *
  3848. * The matrix can synchronize a canvas context by supplying the context
  3849. * as an argument, or later apply current absolute transform to an
  3850. * existing context.
  3851. *
  3852. * All values are handled as floating point values.
  3853. *
  3854. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3855. * @prop {number} a - scale x
  3856. * @prop {number} b - shear y
  3857. * @prop {number} c - shear x
  3858. * @prop {number} d - scale y
  3859. * @prop {number} e - translate x
  3860. * @prop {number} f - translate y
  3861. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3862. * @constructor
  3863. */
  3864. const Matrix = (function () {
  3865. var _cos = Math.cos;
  3866. var _sin = Math.sin;
  3867. var _tan = Math.tan;
  3868. var _rnd = Math.round;
  3869. function reset() {
  3870. this.props[0] = 1;
  3871. this.props[1] = 0;
  3872. this.props[2] = 0;
  3873. this.props[3] = 0;
  3874. this.props[4] = 0;
  3875. this.props[5] = 1;
  3876. this.props[6] = 0;
  3877. this.props[7] = 0;
  3878. this.props[8] = 0;
  3879. this.props[9] = 0;
  3880. this.props[10] = 1;
  3881. this.props[11] = 0;
  3882. this.props[12] = 0;
  3883. this.props[13] = 0;
  3884. this.props[14] = 0;
  3885. this.props[15] = 1;
  3886. return this;
  3887. }
  3888. function rotate(angle) {
  3889. if (angle === 0) {
  3890. return this;
  3891. }
  3892. var mCos = _cos(angle);
  3893. var mSin = _sin(angle);
  3894. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3895. }
  3896. function rotateX(angle) {
  3897. if (angle === 0) {
  3898. return this;
  3899. }
  3900. var mCos = _cos(angle);
  3901. var mSin = _sin(angle);
  3902. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3903. }
  3904. function rotateY(angle) {
  3905. if (angle === 0) {
  3906. return this;
  3907. }
  3908. var mCos = _cos(angle);
  3909. var mSin = _sin(angle);
  3910. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3911. }
  3912. function rotateZ(angle) {
  3913. if (angle === 0) {
  3914. return this;
  3915. }
  3916. var mCos = _cos(angle);
  3917. var mSin = _sin(angle);
  3918. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3919. }
  3920. function shear(sx, sy) {
  3921. return this._t(1, sy, sx, 1, 0, 0);
  3922. }
  3923. function skew(ax, ay) {
  3924. return this.shear(_tan(ax), _tan(ay));
  3925. }
  3926. function skewFromAxis(ax, angle) {
  3927. var mCos = _cos(angle);
  3928. var mSin = _sin(angle);
  3929. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3930. ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3931. ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3932. // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  3933. }
  3934. function scale(sx, sy, sz) {
  3935. if (!sz && sz !== 0) {
  3936. sz = 1;
  3937. }
  3938. if (sx === 1 && sy === 1 && sz === 1) {
  3939. return this;
  3940. }
  3941. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  3942. }
  3943. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  3944. this.props[0] = a;
  3945. this.props[1] = b;
  3946. this.props[2] = c;
  3947. this.props[3] = d;
  3948. this.props[4] = e;
  3949. this.props[5] = f;
  3950. this.props[6] = g;
  3951. this.props[7] = h;
  3952. this.props[8] = i;
  3953. this.props[9] = j;
  3954. this.props[10] = k;
  3955. this.props[11] = l;
  3956. this.props[12] = m;
  3957. this.props[13] = n;
  3958. this.props[14] = o;
  3959. this.props[15] = p;
  3960. return this;
  3961. }
  3962. function translate(tx, ty, tz) {
  3963. tz = tz || 0;
  3964. if (tx !== 0 || ty !== 0 || tz !== 0) {
  3965. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  3966. }
  3967. return this;
  3968. }
  3969. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  3970. var _p = this.props;
  3971. if (a2 === 1 && b2 === 0 && c2 === 0 && d2 === 0 && e2 === 0 && f2 === 1 && g2 === 0 && h2 === 0 && i2 === 0 && j2 === 0 && k2 === 1 && l2 === 0) {
  3972. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  3973. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  3974. _p[12] = _p[12] * a2 + _p[15] * m2;
  3975. _p[13] = _p[13] * f2 + _p[15] * n2;
  3976. _p[14] = _p[14] * k2 + _p[15] * o2;
  3977. _p[15] *= p2;
  3978. // }
  3979. this._identityCalculated = false;
  3980. return this;
  3981. }
  3982. var a1 = _p[0];
  3983. var b1 = _p[1];
  3984. var c1 = _p[2];
  3985. var d1 = _p[3];
  3986. var e1 = _p[4];
  3987. var f1 = _p[5];
  3988. var g1 = _p[6];
  3989. var h1 = _p[7];
  3990. var i1 = _p[8];
  3991. var j1 = _p[9];
  3992. var k1 = _p[10];
  3993. var l1 = _p[11];
  3994. var m1 = _p[12];
  3995. var n1 = _p[13];
  3996. var o1 = _p[14];
  3997. var p1 = _p[15];
  3998. /* matrix order (canvas compatible):
  3999. * ace
  4000. * bdf
  4001. * 001
  4002. */
  4003. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  4004. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  4005. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  4006. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  4007. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  4008. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  4009. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  4010. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  4011. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  4012. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  4013. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  4014. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  4015. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  4016. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  4017. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  4018. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  4019. this._identityCalculated = false;
  4020. return this;
  4021. }
  4022. function multiply(matrix) {
  4023. var matrixProps = matrix.props;
  4024. return this.transform(
  4025. matrixProps[0],
  4026. matrixProps[1],
  4027. matrixProps[2],
  4028. matrixProps[3],
  4029. matrixProps[4],
  4030. matrixProps[5],
  4031. matrixProps[6],
  4032. matrixProps[7],
  4033. matrixProps[8],
  4034. matrixProps[9],
  4035. matrixProps[10],
  4036. matrixProps[11],
  4037. matrixProps[12],
  4038. matrixProps[13],
  4039. matrixProps[14],
  4040. matrixProps[15]
  4041. );
  4042. }
  4043. function isIdentity() {
  4044. if (!this._identityCalculated) {
  4045. this._identity = !(this.props[0] !== 1 || this.props[1] !== 0 || this.props[2] !== 0 || this.props[3] !== 0 || this.props[4] !== 0 || this.props[5] !== 1 || this.props[6] !== 0 || this.props[7] !== 0 || this.props[8] !== 0 || this.props[9] !== 0 || this.props[10] !== 1 || this.props[11] !== 0 || this.props[12] !== 0 || this.props[13] !== 0 || this.props[14] !== 0 || this.props[15] !== 1);
  4046. this._identityCalculated = true;
  4047. }
  4048. return this._identity;
  4049. }
  4050. function equals(matr) {
  4051. var i = 0;
  4052. while (i < 16) {
  4053. if (matr.props[i] !== this.props[i]) {
  4054. return false;
  4055. }
  4056. i += 1;
  4057. }
  4058. return true;
  4059. }
  4060. function clone(matr) {
  4061. var i;
  4062. for (i = 0; i < 16; i += 1) {
  4063. matr.props[i] = this.props[i];
  4064. }
  4065. return matr;
  4066. }
  4067. function cloneFromProps(props) {
  4068. var i;
  4069. for (i = 0; i < 16; i += 1) {
  4070. this.props[i] = props[i];
  4071. }
  4072. }
  4073. function applyToPoint(x, y, z) {
  4074. return {
  4075. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4076. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4077. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4078. };
  4079. /* return {
  4080. x: x * me.a + y * me.c + me.e,
  4081. y: x * me.b + y * me.d + me.f
  4082. }; */
  4083. }
  4084. function applyToX(x, y, z) {
  4085. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4086. }
  4087. function applyToY(x, y, z) {
  4088. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4089. }
  4090. function applyToZ(x, y, z) {
  4091. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4092. }
  4093. function getInverseMatrix() {
  4094. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4095. var a = this.props[5] / determinant;
  4096. var b = -this.props[1] / determinant;
  4097. var c = -this.props[4] / determinant;
  4098. var d = this.props[0] / determinant;
  4099. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4100. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4101. var inverseMatrix = new Matrix();
  4102. inverseMatrix.props[0] = a;
  4103. inverseMatrix.props[1] = b;
  4104. inverseMatrix.props[4] = c;
  4105. inverseMatrix.props[5] = d;
  4106. inverseMatrix.props[12] = e;
  4107. inverseMatrix.props[13] = f;
  4108. return inverseMatrix;
  4109. }
  4110. function inversePoint(pt) {
  4111. var inverseMatrix = this.getInverseMatrix();
  4112. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4113. }
  4114. function inversePoints(pts) {
  4115. var i;
  4116. var len = pts.length;
  4117. var retPts = [];
  4118. for (i = 0; i < len; i += 1) {
  4119. retPts[i] = inversePoint(pts[i]);
  4120. }
  4121. return retPts;
  4122. }
  4123. function applyToTriplePoints(pt1, pt2, pt3) {
  4124. var arr = createTypedArray('float32', 6);
  4125. if (this.isIdentity()) {
  4126. arr[0] = pt1[0];
  4127. arr[1] = pt1[1];
  4128. arr[2] = pt2[0];
  4129. arr[3] = pt2[1];
  4130. arr[4] = pt3[0];
  4131. arr[5] = pt3[1];
  4132. } else {
  4133. var p0 = this.props[0];
  4134. var p1 = this.props[1];
  4135. var p4 = this.props[4];
  4136. var p5 = this.props[5];
  4137. var p12 = this.props[12];
  4138. var p13 = this.props[13];
  4139. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4140. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4141. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4142. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4143. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4144. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4145. }
  4146. return arr;
  4147. }
  4148. function applyToPointArray(x, y, z) {
  4149. var arr;
  4150. if (this.isIdentity()) {
  4151. arr = [x, y, z];
  4152. } else {
  4153. arr = [
  4154. x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4155. x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4156. x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4157. ];
  4158. }
  4159. return arr;
  4160. }
  4161. function applyToPointStringified(x, y) {
  4162. if (this.isIdentity()) {
  4163. return x + ',' + y;
  4164. }
  4165. var _p = this.props;
  4166. return Math.round((x * _p[0] + y * _p[4] + _p[12]) * 100) / 100 + ',' + Math.round((x * _p[1] + y * _p[5] + _p[13]) * 100) / 100;
  4167. }
  4168. function toCSS() {
  4169. // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed.
  4170. /* if(this.isIdentity()) {
  4171. return '';
  4172. } */
  4173. var i = 0;
  4174. var props = this.props;
  4175. var cssValue = 'matrix3d(';
  4176. var v = 10000;
  4177. while (i < 16) {
  4178. cssValue += _rnd(props[i] * v) / v;
  4179. cssValue += i === 15 ? ')' : ',';
  4180. i += 1;
  4181. }
  4182. return cssValue;
  4183. }
  4184. function roundMatrixProperty(val) {
  4185. var v = 10000;
  4186. if ((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
  4187. return _rnd(val * v) / v;
  4188. }
  4189. return val;
  4190. }
  4191. function to2dCSS() {
  4192. // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed.
  4193. /* if(this.isIdentity()) {
  4194. return '';
  4195. } */
  4196. var props = this.props;
  4197. var _a = roundMatrixProperty(props[0]);
  4198. var _b = roundMatrixProperty(props[1]);
  4199. var _c = roundMatrixProperty(props[4]);
  4200. var _d = roundMatrixProperty(props[5]);
  4201. var _e = roundMatrixProperty(props[12]);
  4202. var _f = roundMatrixProperty(props[13]);
  4203. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4204. }
  4205. return function () {
  4206. this.reset = reset;
  4207. this.rotate = rotate;
  4208. this.rotateX = rotateX;
  4209. this.rotateY = rotateY;
  4210. this.rotateZ = rotateZ;
  4211. this.skew = skew;
  4212. this.skewFromAxis = skewFromAxis;
  4213. this.shear = shear;
  4214. this.scale = scale;
  4215. this.setTransform = setTransform;
  4216. this.translate = translate;
  4217. this.transform = transform;
  4218. this.multiply = multiply;
  4219. this.applyToPoint = applyToPoint;
  4220. this.applyToX = applyToX;
  4221. this.applyToY = applyToY;
  4222. this.applyToZ = applyToZ;
  4223. this.applyToPointArray = applyToPointArray;
  4224. this.applyToTriplePoints = applyToTriplePoints;
  4225. this.applyToPointStringified = applyToPointStringified;
  4226. this.toCSS = toCSS;
  4227. this.to2dCSS = to2dCSS;
  4228. this.clone = clone;
  4229. this.cloneFromProps = cloneFromProps;
  4230. this.equals = equals;
  4231. this.inversePoints = inversePoints;
  4232. this.inversePoint = inversePoint;
  4233. this.getInverseMatrix = getInverseMatrix;
  4234. this._t = this.transform;
  4235. this.isIdentity = isIdentity;
  4236. this._identity = true;
  4237. this._identityCalculated = false;
  4238. this.props = createTypedArray('float32', 16);
  4239. this.reset();
  4240. };
  4241. }());
  4242. const lottie = {};
  4243. var standalone = '__[STANDALONE]__';
  4244. var animationData = '__[ANIMATIONDATA]__';
  4245. var renderer = '';
  4246. function setLocation(href) {
  4247. setLocationHref(href);
  4248. }
  4249. function searchAnimations() {
  4250. if (standalone === true) {
  4251. animationManager.searchAnimations(animationData, standalone, renderer);
  4252. } else {
  4253. animationManager.searchAnimations();
  4254. }
  4255. }
  4256. function setSubframeRendering(flag) {
  4257. setSubframeEnabled(flag);
  4258. }
  4259. function setPrefix(prefix) {
  4260. setIdPrefix(prefix);
  4261. }
  4262. function loadAnimation(params) {
  4263. if (standalone === true) {
  4264. params.animationData = JSON.parse(animationData);
  4265. }
  4266. return animationManager.loadAnimation(params);
  4267. }
  4268. function setQuality(value) {
  4269. if (typeof value === 'string') {
  4270. switch (value) {
  4271. case 'high':
  4272. setDefaultCurveSegments(200);
  4273. break;
  4274. default:
  4275. case 'medium':
  4276. setDefaultCurveSegments(50);
  4277. break;
  4278. case 'low':
  4279. setDefaultCurveSegments(10);
  4280. break;
  4281. }
  4282. } else if (!isNaN(value) && value > 1) {
  4283. setDefaultCurveSegments(value);
  4284. }
  4285. if (getDefaultCurveSegments() >= 50) {
  4286. roundValues(false);
  4287. } else {
  4288. roundValues(true);
  4289. }
  4290. }
  4291. function inBrowser() {
  4292. return typeof navigator !== 'undefined';
  4293. }
  4294. function installPlugin(type, plugin) {
  4295. if (type === 'expressions') {
  4296. setExpressionsPlugin(plugin);
  4297. }
  4298. }
  4299. function getFactory(name) {
  4300. switch (name) {
  4301. case 'propertyFactory':
  4302. return PropertyFactory;
  4303. case 'shapePropertyFactory':
  4304. return ShapePropertyFactory;
  4305. case 'matrix':
  4306. return Matrix;
  4307. default:
  4308. return null;
  4309. }
  4310. }
  4311. lottie.play = animationManager.play;
  4312. lottie.pause = animationManager.pause;
  4313. lottie.setLocationHref = setLocation;
  4314. lottie.togglePause = animationManager.togglePause;
  4315. lottie.setSpeed = animationManager.setSpeed;
  4316. lottie.setDirection = animationManager.setDirection;
  4317. lottie.stop = animationManager.stop;
  4318. lottie.searchAnimations = searchAnimations;
  4319. lottie.registerAnimation = animationManager.registerAnimation;
  4320. lottie.loadAnimation = loadAnimation;
  4321. lottie.setSubframeRendering = setSubframeRendering;
  4322. lottie.resize = animationManager.resize;
  4323. // lottie.start = start;
  4324. lottie.goToAndStop = animationManager.goToAndStop;
  4325. lottie.destroy = animationManager.destroy;
  4326. lottie.setQuality = setQuality;
  4327. lottie.inBrowser = inBrowser;
  4328. lottie.installPlugin = installPlugin;
  4329. lottie.freeze = animationManager.freeze;
  4330. lottie.unfreeze = animationManager.unfreeze;
  4331. lottie.setVolume = animationManager.setVolume;
  4332. lottie.mute = animationManager.mute;
  4333. lottie.unmute = animationManager.unmute;
  4334. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4335. lottie.useWebWorker = setWebWorker;
  4336. lottie.setIDPrefix = setPrefix;
  4337. lottie.__getFactory = getFactory;
  4338. lottie.version = '[[BM_VERSION]]';
  4339. function checkReady() {
  4340. if (document.readyState === 'complete') {
  4341. clearInterval(readyStateCheckInterval);
  4342. searchAnimations();
  4343. }
  4344. }
  4345. function getQueryVariable(variable) {
  4346. var vars = queryString.split('&');
  4347. for (var i = 0; i < vars.length; i += 1) {
  4348. var pair = vars[i].split('=');
  4349. if (decodeURIComponent(pair[0]) == variable) { // eslint-disable-line eqeqeq
  4350. return decodeURIComponent(pair[1]);
  4351. }
  4352. }
  4353. return null;
  4354. }
  4355. var queryString = '';
  4356. if (standalone) {
  4357. var scripts = document.getElementsByTagName('script');
  4358. var index = scripts.length - 1;
  4359. var myScript = scripts[index] || {
  4360. src: '',
  4361. };
  4362. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4363. renderer = getQueryVariable('renderer');
  4364. }
  4365. var readyStateCheckInterval = setInterval(checkReady, 100);
  4366. // this adds bodymovin to the window object for backwards compatibility
  4367. try {
  4368. if (!(typeof exports === 'object' && typeof module !== 'undefined')
  4369. && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4370. ) {
  4371. window.bodymovin = lottie;
  4372. }
  4373. } catch (err) {
  4374. //
  4375. }
  4376. const ShapeModifiers = (function () {
  4377. var ob = {};
  4378. var modifiers = {};
  4379. ob.registerModifier = registerModifier;
  4380. ob.getModifier = getModifier;
  4381. function registerModifier(nm, factory) {
  4382. if (!modifiers[nm]) {
  4383. modifiers[nm] = factory;
  4384. }
  4385. }
  4386. function getModifier(nm, elem, data) {
  4387. return new modifiers[nm](elem, data);
  4388. }
  4389. return ob;
  4390. }());
  4391. function ShapeModifier() {}
  4392. ShapeModifier.prototype.initModifierProperties = function () {};
  4393. ShapeModifier.prototype.addShapeToModifier = function () {};
  4394. ShapeModifier.prototype.addShape = function (data) {
  4395. if (!this.closed) {
  4396. // Adding shape to dynamic properties. It covers the case where a shape has no effects applied, to reset it's _mdf state on every tick.
  4397. data.sh.container.addDynamicProperty(data.sh);
  4398. var shapeData = { shape: data.sh, data: data, localShapeCollection: shapeCollectionPool.newShapeCollection() };
  4399. this.shapes.push(shapeData);
  4400. this.addShapeToModifier(shapeData);
  4401. if (this._isAnimated) {
  4402. data.setAsAnimated();
  4403. }
  4404. }
  4405. };
  4406. ShapeModifier.prototype.init = function (elem, data) {
  4407. this.shapes = [];
  4408. this.elem = elem;
  4409. this.initDynamicPropertyContainer(elem);
  4410. this.initModifierProperties(elem, data);
  4411. this.frameId = initialDefaultFrame;
  4412. this.closed = false;
  4413. this.k = false;
  4414. if (this.dynamicProperties.length) {
  4415. this.k = true;
  4416. } else {
  4417. this.getValue(true);
  4418. }
  4419. };
  4420. ShapeModifier.prototype.processKeys = function () {
  4421. if (this.elem.globalData.frameId === this.frameId) {
  4422. return;
  4423. }
  4424. this.frameId = this.elem.globalData.frameId;
  4425. this.iterateDynamicProperties();
  4426. };
  4427. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4428. function TrimModifier() {
  4429. }
  4430. extendPrototype([ShapeModifier], TrimModifier);
  4431. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4432. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4433. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4434. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4435. this.sValue = 0;
  4436. this.eValue = 0;
  4437. this.getValue = this.processKeys;
  4438. this.m = data.m;
  4439. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4440. };
  4441. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4442. shapeData.pathsData = [];
  4443. };
  4444. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4445. var segments = [];
  4446. if (e <= 1) {
  4447. segments.push({
  4448. s: s,
  4449. e: e,
  4450. });
  4451. } else if (s >= 1) {
  4452. segments.push({
  4453. s: s - 1,
  4454. e: e - 1,
  4455. });
  4456. } else {
  4457. segments.push({
  4458. s: s,
  4459. e: 1,
  4460. });
  4461. segments.push({
  4462. s: 0,
  4463. e: e - 1,
  4464. });
  4465. }
  4466. var shapeSegments = [];
  4467. var i;
  4468. var len = segments.length;
  4469. var segmentOb;
  4470. for (i = 0; i < len; i += 1) {
  4471. segmentOb = segments[i];
  4472. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4473. var shapeS;
  4474. var shapeE;
  4475. if (segmentOb.s * totalModifierLength <= addedLength) {
  4476. shapeS = 0;
  4477. } else {
  4478. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4479. }
  4480. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4481. shapeE = 1;
  4482. } else {
  4483. shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength);
  4484. }
  4485. shapeSegments.push([shapeS, shapeE]);
  4486. }
  4487. }
  4488. if (!shapeSegments.length) {
  4489. shapeSegments.push([0, 0]);
  4490. }
  4491. return shapeSegments;
  4492. };
  4493. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4494. var i;
  4495. var len = pathsData.length;
  4496. for (i = 0; i < len; i += 1) {
  4497. segmentsLengthPool.release(pathsData[i]);
  4498. }
  4499. pathsData.length = 0;
  4500. return pathsData;
  4501. };
  4502. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4503. var s;
  4504. var e;
  4505. if (this._mdf || _isFirstFrame) {
  4506. var o = (this.o.v % 360) / 360;
  4507. if (o < 0) {
  4508. o += 1;
  4509. }
  4510. if (this.s.v > 1) {
  4511. s = 1 + o;
  4512. } else if (this.s.v < 0) {
  4513. s = 0 + o;
  4514. } else {
  4515. s = this.s.v + o;
  4516. }
  4517. if (this.e.v > 1) {
  4518. e = 1 + o;
  4519. } else if (this.e.v < 0) {
  4520. e = 0 + o;
  4521. } else {
  4522. e = this.e.v + o;
  4523. }
  4524. if (s > e) {
  4525. var _s = s;
  4526. s = e;
  4527. e = _s;
  4528. }
  4529. s = Math.round(s * 10000) * 0.0001;
  4530. e = Math.round(e * 10000) * 0.0001;
  4531. this.sValue = s;
  4532. this.eValue = e;
  4533. } else {
  4534. s = this.sValue;
  4535. e = this.eValue;
  4536. }
  4537. var shapePaths;
  4538. var i;
  4539. var len = this.shapes.length;
  4540. var j;
  4541. var jLen;
  4542. var pathsData;
  4543. var pathData;
  4544. var totalShapeLength;
  4545. var totalModifierLength = 0;
  4546. if (e === s) {
  4547. for (i = 0; i < len; i += 1) {
  4548. this.shapes[i].localShapeCollection.releaseShapes();
  4549. this.shapes[i].shape._mdf = true;
  4550. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4551. if (this._mdf) {
  4552. this.shapes[i].pathsData.length = 0;
  4553. }
  4554. }
  4555. } else if (!((e === 1 && s === 0) || (e === 0 && s === 1))) {
  4556. var segments = [];
  4557. var shapeData;
  4558. var localShapeCollection;
  4559. for (i = 0; i < len; i += 1) {
  4560. shapeData = this.shapes[i];
  4561. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4562. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4563. shapeData.shape.paths = shapeData.localShapeCollection;
  4564. } else {
  4565. shapePaths = shapeData.shape.paths;
  4566. jLen = shapePaths._length;
  4567. totalShapeLength = 0;
  4568. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4569. totalShapeLength = shapeData.totalShapeLength;
  4570. } else {
  4571. pathsData = this.releasePathsData(shapeData.pathsData);
  4572. for (j = 0; j < jLen; j += 1) {
  4573. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4574. pathsData.push(pathData);
  4575. totalShapeLength += pathData.totalLength;
  4576. }
  4577. shapeData.totalShapeLength = totalShapeLength;
  4578. shapeData.pathsData = pathsData;
  4579. }
  4580. totalModifierLength += totalShapeLength;
  4581. shapeData.shape._mdf = true;
  4582. }
  4583. }
  4584. var shapeS = s;
  4585. var shapeE = e;
  4586. var addedLength = 0;
  4587. var edges;
  4588. for (i = len - 1; i >= 0; i -= 1) {
  4589. shapeData = this.shapes[i];
  4590. if (shapeData.shape._mdf) {
  4591. localShapeCollection = shapeData.localShapeCollection;
  4592. localShapeCollection.releaseShapes();
  4593. // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4594. if (this.m === 2 && len > 1) {
  4595. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4596. addedLength += shapeData.totalShapeLength;
  4597. } else {
  4598. edges = [[shapeS, shapeE]];
  4599. }
  4600. jLen = edges.length;
  4601. for (j = 0; j < jLen; j += 1) {
  4602. shapeS = edges[j][0];
  4603. shapeE = edges[j][1];
  4604. segments.length = 0;
  4605. if (shapeE <= 1) {
  4606. segments.push({
  4607. s: shapeData.totalShapeLength * shapeS,
  4608. e: shapeData.totalShapeLength * shapeE,
  4609. });
  4610. } else if (shapeS >= 1) {
  4611. segments.push({
  4612. s: shapeData.totalShapeLength * (shapeS - 1),
  4613. e: shapeData.totalShapeLength * (shapeE - 1),
  4614. });
  4615. } else {
  4616. segments.push({
  4617. s: shapeData.totalShapeLength * shapeS,
  4618. e: shapeData.totalShapeLength,
  4619. });
  4620. segments.push({
  4621. s: 0,
  4622. e: shapeData.totalShapeLength * (shapeE - 1),
  4623. });
  4624. }
  4625. var newShapesData = this.addShapes(shapeData, segments[0]);
  4626. if (segments[0].s !== segments[0].e) {
  4627. if (segments.length > 1) {
  4628. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4629. if (lastShapeInCollection.c) {
  4630. var lastShape = newShapesData.pop();
  4631. this.addPaths(newShapesData, localShapeCollection);
  4632. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4633. } else {
  4634. this.addPaths(newShapesData, localShapeCollection);
  4635. newShapesData = this.addShapes(shapeData, segments[1]);
  4636. }
  4637. }
  4638. this.addPaths(newShapesData, localShapeCollection);
  4639. }
  4640. }
  4641. shapeData.shape.paths = localShapeCollection;
  4642. }
  4643. }
  4644. } else if (this._mdf) {
  4645. for (i = 0; i < len; i += 1) {
  4646. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4647. // Don't remove this even if it's losing cached info.
  4648. this.shapes[i].pathsData.length = 0;
  4649. this.shapes[i].shape._mdf = true;
  4650. }
  4651. }
  4652. };
  4653. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4654. var i;
  4655. var len = newPaths.length;
  4656. for (i = 0; i < len; i += 1) {
  4657. localShapeCollection.addShape(newPaths[i]);
  4658. }
  4659. };
  4660. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4661. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4662. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4663. if (newShape) {
  4664. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4665. }
  4666. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4667. };
  4668. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4669. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4670. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4671. if (newShape) {
  4672. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4673. }
  4674. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4675. };
  4676. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4677. var pathsData = shapeData.pathsData;
  4678. var shapePaths = shapeData.shape.paths.shapes;
  4679. var i;
  4680. var len = shapeData.shape.paths._length;
  4681. var j;
  4682. var jLen;
  4683. var addedLength = 0;
  4684. var currentLengthData;
  4685. var segmentCount;
  4686. var lengths;
  4687. var segment;
  4688. var shapes = [];
  4689. var initPos;
  4690. var newShape = true;
  4691. if (!shapePath) {
  4692. shapePath = shapePool.newElement();
  4693. segmentCount = 0;
  4694. initPos = 0;
  4695. } else {
  4696. segmentCount = shapePath._length;
  4697. initPos = shapePath._length;
  4698. }
  4699. shapes.push(shapePath);
  4700. for (i = 0; i < len; i += 1) {
  4701. lengths = pathsData[i].lengths;
  4702. shapePath.c = shapePaths[i].c;
  4703. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4704. for (j = 1; j < jLen; j += 1) {
  4705. currentLengthData = lengths[j - 1];
  4706. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4707. addedLength += currentLengthData.addedLength;
  4708. shapePath.c = false;
  4709. } else if (addedLength > shapeSegment.e) {
  4710. shapePath.c = false;
  4711. break;
  4712. } else {
  4713. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4714. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4715. newShape = false;
  4716. } else {
  4717. segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[j], shapePaths[i].o[j - 1], shapePaths[i].i[j], (shapeSegment.s - addedLength) / currentLengthData.addedLength, (shapeSegment.e - addedLength) / currentLengthData.addedLength, lengths[j - 1]);
  4718. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4719. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4720. newShape = false;
  4721. shapePath.c = false;
  4722. }
  4723. addedLength += currentLengthData.addedLength;
  4724. segmentCount += 1;
  4725. }
  4726. }
  4727. if (shapePaths[i].c && lengths.length) {
  4728. currentLengthData = lengths[j - 1];
  4729. if (addedLength <= shapeSegment.e) {
  4730. var segmentLength = lengths[j - 1].addedLength;
  4731. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4732. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4733. newShape = false;
  4734. } else {
  4735. segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[0], shapePaths[i].o[j - 1], shapePaths[i].i[0], (shapeSegment.s - addedLength) / segmentLength, (shapeSegment.e - addedLength) / segmentLength, lengths[j - 1]);
  4736. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4737. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4738. newShape = false;
  4739. shapePath.c = false;
  4740. }
  4741. } else {
  4742. shapePath.c = false;
  4743. }
  4744. addedLength += currentLengthData.addedLength;
  4745. segmentCount += 1;
  4746. }
  4747. if (shapePath._length) {
  4748. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4749. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4750. }
  4751. if (addedLength > shapeSegment.e) {
  4752. break;
  4753. }
  4754. if (i < len - 1) {
  4755. shapePath = shapePool.newElement();
  4756. newShape = true;
  4757. shapes.push(shapePath);
  4758. segmentCount = 0;
  4759. }
  4760. }
  4761. return shapes;
  4762. };
  4763. function PuckerAndBloatModifier() {}
  4764. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4765. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4766. this.getValue = this.processKeys;
  4767. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4768. this._isAnimated = !!this.amount.effectsSequence.length;
  4769. };
  4770. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4771. var percent = amount / 100;
  4772. var centerPoint = [0, 0];
  4773. var pathLength = path._length;
  4774. var i = 0;
  4775. for (i = 0; i < pathLength; i += 1) {
  4776. centerPoint[0] += path.v[i][0];
  4777. centerPoint[1] += path.v[i][1];
  4778. }
  4779. centerPoint[0] /= pathLength;
  4780. centerPoint[1] /= pathLength;
  4781. var clonedPath = shapePool.newElement();
  4782. clonedPath.c = path.c;
  4783. var vX;
  4784. var vY;
  4785. var oX;
  4786. var oY;
  4787. var iX;
  4788. var iY;
  4789. for (i = 0; i < pathLength; i += 1) {
  4790. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4791. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4792. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4793. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4794. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4795. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4796. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4797. }
  4798. return clonedPath;
  4799. };
  4800. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4801. var shapePaths;
  4802. var i;
  4803. var len = this.shapes.length;
  4804. var j;
  4805. var jLen;
  4806. var amount = this.amount.v;
  4807. if (amount !== 0) {
  4808. var shapeData;
  4809. var localShapeCollection;
  4810. for (i = 0; i < len; i += 1) {
  4811. shapeData = this.shapes[i];
  4812. localShapeCollection = shapeData.localShapeCollection;
  4813. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4814. localShapeCollection.releaseShapes();
  4815. shapeData.shape._mdf = true;
  4816. shapePaths = shapeData.shape.paths.shapes;
  4817. jLen = shapeData.shape.paths._length;
  4818. for (j = 0; j < jLen; j += 1) {
  4819. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4820. }
  4821. }
  4822. shapeData.shape.paths = shapeData.localShapeCollection;
  4823. }
  4824. }
  4825. if (!this.dynamicProperties.length) {
  4826. this._mdf = false;
  4827. }
  4828. };
  4829. const TransformPropertyFactory = (function () {
  4830. var defaultVector = [0, 0];
  4831. function applyToMatrix(mat) {
  4832. var _mdf = this._mdf;
  4833. this.iterateDynamicProperties();
  4834. this._mdf = this._mdf || _mdf;
  4835. if (this.a) {
  4836. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4837. }
  4838. if (this.s) {
  4839. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4840. }
  4841. if (this.sk) {
  4842. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4843. }
  4844. if (this.r) {
  4845. mat.rotate(-this.r.v);
  4846. } else {
  4847. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4848. .rotateY(this.or.v[1])
  4849. .rotateX(this.or.v[0]);
  4850. }
  4851. if (this.data.p.s) {
  4852. if (this.data.p.z) {
  4853. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4854. } else {
  4855. mat.translate(this.px.v, this.py.v, 0);
  4856. }
  4857. } else {
  4858. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4859. }
  4860. }
  4861. function processKeys(forceRender) {
  4862. if (this.elem.globalData.frameId === this.frameId) {
  4863. return;
  4864. }
  4865. if (this._isDirty) {
  4866. this.precalculateMatrix();
  4867. this._isDirty = false;
  4868. }
  4869. this.iterateDynamicProperties();
  4870. if (this._mdf || forceRender) {
  4871. var frameRate;
  4872. this.v.cloneFromProps(this.pre.props);
  4873. if (this.appliedTransformations < 1) {
  4874. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4875. }
  4876. if (this.appliedTransformations < 2) {
  4877. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4878. }
  4879. if (this.sk && this.appliedTransformations < 3) {
  4880. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4881. }
  4882. if (this.r && this.appliedTransformations < 4) {
  4883. this.v.rotate(-this.r.v);
  4884. } else if (!this.r && this.appliedTransformations < 4) {
  4885. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4886. .rotateY(this.or.v[1])
  4887. .rotateX(this.or.v[0]);
  4888. }
  4889. if (this.autoOriented) {
  4890. var v1;
  4891. var v2;
  4892. frameRate = this.elem.globalData.frameRate;
  4893. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4894. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4895. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4896. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4897. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4898. v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0);
  4899. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4900. } else {
  4901. v1 = this.p.pv;
  4902. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4903. }
  4904. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4905. v1 = [];
  4906. v2 = [];
  4907. var px = this.px;
  4908. var py = this.py;
  4909. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4910. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4911. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4912. v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate, 0);
  4913. v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate, 0);
  4914. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4915. v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate), 0);
  4916. v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate), 0);
  4917. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4918. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4919. } else {
  4920. v1 = [px.pv, py.pv];
  4921. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4922. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4923. }
  4924. } else {
  4925. v2 = defaultVector;
  4926. v1 = v2;
  4927. }
  4928. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4929. }
  4930. if (this.data.p && this.data.p.s) {
  4931. if (this.data.p.z) {
  4932. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4933. } else {
  4934. this.v.translate(this.px.v, this.py.v, 0);
  4935. }
  4936. } else {
  4937. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4938. }
  4939. }
  4940. this.frameId = this.elem.globalData.frameId;
  4941. }
  4942. function precalculateMatrix() {
  4943. this.appliedTransformations = 0;
  4944. this.pre.reset();
  4945. if (!this.a.effectsSequence.length) {
  4946. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4947. this.appliedTransformations = 1;
  4948. } else {
  4949. return;
  4950. }
  4951. if (!this.s.effectsSequence.length) {
  4952. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4953. this.appliedTransformations = 2;
  4954. } else {
  4955. return;
  4956. }
  4957. if (this.sk) {
  4958. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  4959. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  4960. this.appliedTransformations = 3;
  4961. } else {
  4962. return;
  4963. }
  4964. }
  4965. if (this.r) {
  4966. if (!this.r.effectsSequence.length) {
  4967. this.pre.rotate(-this.r.v);
  4968. this.appliedTransformations = 4;
  4969. }
  4970. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  4971. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4972. .rotateY(this.or.v[1])
  4973. .rotateX(this.or.v[0]);
  4974. this.appliedTransformations = 4;
  4975. }
  4976. }
  4977. function autoOrient() {
  4978. //
  4979. // var prevP = this.getValueAtTime();
  4980. }
  4981. function addDynamicProperty(prop) {
  4982. this._addDynamicProperty(prop);
  4983. this.elem.addDynamicProperty(prop);
  4984. this._isDirty = true;
  4985. }
  4986. function TransformProperty(elem, data, container) {
  4987. this.elem = elem;
  4988. this.frameId = -1;
  4989. this.propType = 'transform';
  4990. this.data = data;
  4991. this.v = new Matrix();
  4992. // Precalculated matrix with non animated properties
  4993. this.pre = new Matrix();
  4994. this.appliedTransformations = 0;
  4995. this.initDynamicPropertyContainer(container || elem);
  4996. if (data.p && data.p.s) {
  4997. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  4998. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  4999. if (data.p.z) {
  5000. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  5001. }
  5002. } else {
  5003. this.p = PropertyFactory.getProp(elem, data.p || { k: [0, 0, 0] }, 1, 0, this);
  5004. }
  5005. if (data.rx) {
  5006. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  5007. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  5008. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  5009. if (data.or.k[0].ti) {
  5010. var i;
  5011. var len = data.or.k.length;
  5012. for (i = 0; i < len; i += 1) {
  5013. data.or.k[i].to = null;
  5014. data.or.k[i].ti = null;
  5015. }
  5016. }
  5017. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  5018. // sh Indicates it needs to be capped between -180 and 180
  5019. this.or.sh = true;
  5020. } else {
  5021. this.r = PropertyFactory.getProp(elem, data.r || { k: 0 }, 0, degToRads, this);
  5022. }
  5023. if (data.sk) {
  5024. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  5025. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  5026. }
  5027. this.a = PropertyFactory.getProp(elem, data.a || { k: [0, 0, 0] }, 1, 0, this);
  5028. this.s = PropertyFactory.getProp(elem, data.s || { k: [100, 100, 100] }, 1, 0.01, this);
  5029. // Opacity is not part of the transform properties, that's why it won't use this.dynamicProperties. That way transforms won't get updated if opacity changes.
  5030. if (data.o) {
  5031. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  5032. } else {
  5033. this.o = { _mdf: false, v: 1 };
  5034. }
  5035. this._isDirty = true;
  5036. if (!this.dynamicProperties.length) {
  5037. this.getValue(true);
  5038. }
  5039. }
  5040. TransformProperty.prototype = {
  5041. applyToMatrix: applyToMatrix,
  5042. getValue: processKeys,
  5043. precalculateMatrix: precalculateMatrix,
  5044. autoOrient: autoOrient,
  5045. };
  5046. extendPrototype([DynamicPropertyContainer], TransformProperty);
  5047. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  5048. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  5049. function getTransformProperty(elem, data, container) {
  5050. return new TransformProperty(elem, data, container);
  5051. }
  5052. return {
  5053. getTransformProperty: getTransformProperty,
  5054. };
  5055. }());
  5056. function RepeaterModifier() {}
  5057. extendPrototype([ShapeModifier], RepeaterModifier);
  5058. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5059. this.getValue = this.processKeys;
  5060. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5061. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5062. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5063. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5064. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5065. this.data = data;
  5066. if (!this.dynamicProperties.length) {
  5067. this.getValue(true);
  5068. }
  5069. this._isAnimated = !!this.dynamicProperties.length;
  5070. this.pMatrix = new Matrix();
  5071. this.rMatrix = new Matrix();
  5072. this.sMatrix = new Matrix();
  5073. this.tMatrix = new Matrix();
  5074. this.matrix = new Matrix();
  5075. };
  5076. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5077. var dir = inv ? -1 : 1;
  5078. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5079. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5080. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5081. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5082. rMatrix.rotate(-transform.r.v * dir * perc);
  5083. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5084. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5085. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5086. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5087. };
  5088. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5089. this.elem = elem;
  5090. this.arr = arr;
  5091. this.pos = pos;
  5092. this.elemsData = elemsData;
  5093. this._currentCopies = 0;
  5094. this._elements = [];
  5095. this._groups = [];
  5096. this.frameId = -1;
  5097. this.initDynamicPropertyContainer(elem);
  5098. this.initModifierProperties(elem, arr[pos]);
  5099. while (pos > 0) {
  5100. pos -= 1;
  5101. // this._elements.unshift(arr.splice(pos,1)[0]);
  5102. this._elements.unshift(arr[pos]);
  5103. }
  5104. if (this.dynamicProperties.length) {
  5105. this.k = true;
  5106. } else {
  5107. this.getValue(true);
  5108. }
  5109. };
  5110. RepeaterModifier.prototype.resetElements = function (elements) {
  5111. var i;
  5112. var len = elements.length;
  5113. for (i = 0; i < len; i += 1) {
  5114. elements[i]._processed = false;
  5115. if (elements[i].ty === 'gr') {
  5116. this.resetElements(elements[i].it);
  5117. }
  5118. }
  5119. };
  5120. RepeaterModifier.prototype.cloneElements = function (elements) {
  5121. var newElements = JSON.parse(JSON.stringify(elements));
  5122. this.resetElements(newElements);
  5123. return newElements;
  5124. };
  5125. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5126. var i;
  5127. var len = elements.length;
  5128. for (i = 0; i < len; i += 1) {
  5129. elements[i]._render = renderFlag;
  5130. if (elements[i].ty === 'gr') {
  5131. this.changeGroupRender(elements[i].it, renderFlag);
  5132. }
  5133. }
  5134. };
  5135. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5136. var items;
  5137. var itemsTransform;
  5138. var i;
  5139. var dir;
  5140. var cont;
  5141. var hasReloaded = false;
  5142. if (this._mdf || _isFirstFrame) {
  5143. var copies = Math.ceil(this.c.v);
  5144. if (this._groups.length < copies) {
  5145. while (this._groups.length < copies) {
  5146. var group = {
  5147. it: this.cloneElements(this._elements),
  5148. ty: 'gr',
  5149. };
  5150. group.it.push({
  5151. a: { a: 0, ix: 1, k: [0, 0] }, nm: 'Transform', o: { a: 0, ix: 7, k: 100 }, p: { a: 0, ix: 2, k: [0, 0] }, r: { a: 1, ix: 6, k: [{ s: 0, e: 0, t: 0 }, { s: 0, e: 0, t: 1 }] }, s: { a: 0, ix: 3, k: [100, 100] }, sa: { a: 0, ix: 5, k: 0 }, sk: { a: 0, ix: 4, k: 0 }, ty: 'tr',
  5152. });
  5153. this.arr.splice(0, 0, group);
  5154. this._groups.splice(0, 0, group);
  5155. this._currentCopies += 1;
  5156. }
  5157. this.elem.reloadShapes();
  5158. hasReloaded = true;
  5159. }
  5160. cont = 0;
  5161. var renderFlag;
  5162. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5163. renderFlag = cont < copies;
  5164. this._groups[i]._render = renderFlag;
  5165. this.changeGroupRender(this._groups[i].it, renderFlag);
  5166. if (!renderFlag) {
  5167. var elems = this.elemsData[i].it;
  5168. var transformData = elems[elems.length - 1];
  5169. if (transformData.transform.op.v !== 0) {
  5170. transformData.transform.op._mdf = true;
  5171. transformData.transform.op.v = 0;
  5172. } else {
  5173. transformData.transform.op._mdf = false;
  5174. }
  5175. }
  5176. cont += 1;
  5177. }
  5178. this._currentCopies = copies;
  5179. /// /
  5180. var offset = this.o.v;
  5181. var offsetModulo = offset % 1;
  5182. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5183. var pProps = this.pMatrix.props;
  5184. var rProps = this.rMatrix.props;
  5185. var sProps = this.sMatrix.props;
  5186. this.pMatrix.reset();
  5187. this.rMatrix.reset();
  5188. this.sMatrix.reset();
  5189. this.tMatrix.reset();
  5190. this.matrix.reset();
  5191. var iteration = 0;
  5192. if (offset > 0) {
  5193. while (iteration < roundOffset) {
  5194. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5195. iteration += 1;
  5196. }
  5197. if (offsetModulo) {
  5198. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5199. iteration += offsetModulo;
  5200. }
  5201. } else if (offset < 0) {
  5202. while (iteration > roundOffset) {
  5203. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5204. iteration -= 1;
  5205. }
  5206. if (offsetModulo) {
  5207. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5208. iteration -= offsetModulo;
  5209. }
  5210. }
  5211. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5212. dir = this.data.m === 1 ? 1 : -1;
  5213. cont = this._currentCopies;
  5214. var j;
  5215. var jLen;
  5216. while (cont) {
  5217. items = this.elemsData[i].it;
  5218. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5219. jLen = itemsTransform.length;
  5220. items[items.length - 1].transform.mProps._mdf = true;
  5221. items[items.length - 1].transform.op._mdf = true;
  5222. items[items.length - 1].transform.op.v = this._currentCopies === 1
  5223. ? this.so.v
  5224. : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5225. if (iteration !== 0) {
  5226. if ((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)) {
  5227. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5228. }
  5229. this.matrix.transform(rProps[0], rProps[1], rProps[2], rProps[3], rProps[4], rProps[5], rProps[6], rProps[7], rProps[8], rProps[9], rProps[10], rProps[11], rProps[12], rProps[13], rProps[14], rProps[15]);
  5230. this.matrix.transform(sProps[0], sProps[1], sProps[2], sProps[3], sProps[4], sProps[5], sProps[6], sProps[7], sProps[8], sProps[9], sProps[10], sProps[11], sProps[12], sProps[13], sProps[14], sProps[15]);
  5231. this.matrix.transform(pProps[0], pProps[1], pProps[2], pProps[3], pProps[4], pProps[5], pProps[6], pProps[7], pProps[8], pProps[9], pProps[10], pProps[11], pProps[12], pProps[13], pProps[14], pProps[15]);
  5232. for (j = 0; j < jLen; j += 1) {
  5233. itemsTransform[j] = this.matrix.props[j];
  5234. }
  5235. this.matrix.reset();
  5236. } else {
  5237. this.matrix.reset();
  5238. for (j = 0; j < jLen; j += 1) {
  5239. itemsTransform[j] = this.matrix.props[j];
  5240. }
  5241. }
  5242. iteration += 1;
  5243. cont -= 1;
  5244. i += dir;
  5245. }
  5246. } else {
  5247. cont = this._currentCopies;
  5248. i = 0;
  5249. dir = 1;
  5250. while (cont) {
  5251. items = this.elemsData[i].it;
  5252. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5253. items[items.length - 1].transform.mProps._mdf = false;
  5254. items[items.length - 1].transform.op._mdf = false;
  5255. cont -= 1;
  5256. i += dir;
  5257. }
  5258. }
  5259. return hasReloaded;
  5260. };
  5261. RepeaterModifier.prototype.addShape = function () {};
  5262. function RoundCornersModifier() {}
  5263. extendPrototype([ShapeModifier], RoundCornersModifier);
  5264. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5265. this.getValue = this.processKeys;
  5266. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5267. this._isAnimated = !!this.rd.effectsSequence.length;
  5268. };
  5269. RoundCornersModifier.prototype.processPath = function (path, round) {
  5270. var clonedPath = shapePool.newElement();
  5271. clonedPath.c = path.c;
  5272. var i;
  5273. var len = path._length;
  5274. var currentV;
  5275. var currentI;
  5276. var currentO;
  5277. var closerV;
  5278. var distance;
  5279. var newPosPerc;
  5280. var index = 0;
  5281. var vX;
  5282. var vY;
  5283. var oX;
  5284. var oY;
  5285. var iX;
  5286. var iY;
  5287. for (i = 0; i < len; i += 1) {
  5288. currentV = path.v[i];
  5289. currentO = path.o[i];
  5290. currentI = path.i[i];
  5291. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5292. if ((i === 0 || i === len - 1) && !path.c) {
  5293. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5294. /* clonedPath.v[index] = currentV;
  5295. clonedPath.o[index] = currentO;
  5296. clonedPath.i[index] = currentI; */
  5297. index += 1;
  5298. } else {
  5299. if (i === 0) {
  5300. closerV = path.v[len - 1];
  5301. } else {
  5302. closerV = path.v[i - 1];
  5303. }
  5304. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5305. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5306. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5307. vX = iX;
  5308. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5309. vY = iY;
  5310. oX = vX - (vX - currentV[0]) * roundCorner;
  5311. oY = vY - (vY - currentV[1]) * roundCorner;
  5312. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5313. index += 1;
  5314. if (i === len - 1) {
  5315. closerV = path.v[0];
  5316. } else {
  5317. closerV = path.v[i + 1];
  5318. }
  5319. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5320. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5321. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5322. vX = oX;
  5323. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5324. vY = oY;
  5325. iX = vX - (vX - currentV[0]) * roundCorner;
  5326. iY = vY - (vY - currentV[1]) * roundCorner;
  5327. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5328. index += 1;
  5329. }
  5330. } else {
  5331. clonedPath.setTripleAt(path.v[i][0], path.v[i][1], path.o[i][0], path.o[i][1], path.i[i][0], path.i[i][1], index);
  5332. index += 1;
  5333. }
  5334. }
  5335. return clonedPath;
  5336. };
  5337. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5338. var shapePaths;
  5339. var i;
  5340. var len = this.shapes.length;
  5341. var j;
  5342. var jLen;
  5343. var rd = this.rd.v;
  5344. if (rd !== 0) {
  5345. var shapeData;
  5346. var localShapeCollection;
  5347. for (i = 0; i < len; i += 1) {
  5348. shapeData = this.shapes[i];
  5349. localShapeCollection = shapeData.localShapeCollection;
  5350. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5351. localShapeCollection.releaseShapes();
  5352. shapeData.shape._mdf = true;
  5353. shapePaths = shapeData.shape.paths.shapes;
  5354. jLen = shapeData.shape.paths._length;
  5355. for (j = 0; j < jLen; j += 1) {
  5356. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5357. }
  5358. }
  5359. shapeData.shape.paths = shapeData.localShapeCollection;
  5360. }
  5361. }
  5362. if (!this.dynamicProperties.length) {
  5363. this._mdf = false;
  5364. }
  5365. };
  5366. function floatEqual(a, b) {
  5367. return Math.abs(a - b) * 100000 <= Math.min(Math.abs(a), Math.abs(b));
  5368. }
  5369. function floatZero(f) {
  5370. return Math.abs(f) <= 0.00001;
  5371. }
  5372. function lerp(p0, p1, amount) {
  5373. return p0 * (1 - amount) + p1 * amount;
  5374. }
  5375. function lerpPoint(p0, p1, amount) {
  5376. return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
  5377. }
  5378. function quadRoots(a, b, c) {
  5379. // no root
  5380. if (a === 0) return [];
  5381. var s = b * b - 4 * a * c;
  5382. // Complex roots
  5383. if (s < 0) return [];
  5384. var singleRoot = -b / (2 * a);
  5385. // 1 root
  5386. if (s === 0) return [singleRoot];
  5387. var delta = Math.sqrt(s) / (2 * a);
  5388. // 2 roots
  5389. return [singleRoot - delta, singleRoot + delta];
  5390. }
  5391. function polynomialCoefficients(p0, p1, p2, p3) {
  5392. return [
  5393. -p0 + 3 * p1 - 3 * p2 + p3,
  5394. 3 * p0 - 6 * p1 + 3 * p2,
  5395. -3 * p0 + 3 * p1,
  5396. p0,
  5397. ];
  5398. }
  5399. function singlePoint(p) {
  5400. return new PolynomialBezier(p, p, p, p, false);
  5401. }
  5402. function PolynomialBezier(p0, p1, p2, p3, linearize) {
  5403. if (linearize && pointEqual(p0, p1)) {
  5404. p1 = lerpPoint(p0, p3, 1 / 3);
  5405. }
  5406. if (linearize && pointEqual(p2, p3)) {
  5407. p2 = lerpPoint(p0, p3, 2 / 3);
  5408. }
  5409. var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
  5410. var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
  5411. this.a = [coeffx[0], coeffy[0]];
  5412. this.b = [coeffx[1], coeffy[1]];
  5413. this.c = [coeffx[2], coeffy[2]];
  5414. this.d = [coeffx[3], coeffy[3]];
  5415. this.points = [p0, p1, p2, p3];
  5416. }
  5417. PolynomialBezier.prototype.point = function (t) {
  5418. return [
  5419. (((this.a[0] * t) + this.b[0]) * t + this.c[0]) * t + this.d[0],
  5420. (((this.a[1] * t) + this.b[1]) * t + this.c[1]) * t + this.d[1],
  5421. ];
  5422. };
  5423. PolynomialBezier.prototype.derivative = function (t) {
  5424. return [
  5425. (3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0],
  5426. (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1],
  5427. ];
  5428. };
  5429. PolynomialBezier.prototype.tangentAngle = function (t) {
  5430. var p = this.derivative(t);
  5431. return Math.atan2(p[1], p[0]);
  5432. };
  5433. PolynomialBezier.prototype.normalAngle = function (t) {
  5434. var p = this.derivative(t);
  5435. return Math.atan2(p[0], p[1]);
  5436. };
  5437. PolynomialBezier.prototype.inflectionPoints = function () {
  5438. var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
  5439. if (floatZero(denom)) return [];
  5440. var tcusp = (-0.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1])) / denom;
  5441. var square = tcusp * tcusp - ((1 / 3) * (this.b[1] * this.c[0] - this.b[0] * this.c[1])) / denom;
  5442. if (square < 0) return [];
  5443. var root = Math.sqrt(square);
  5444. if (floatZero(root)) {
  5445. if (root > 0 && root < 1) return [tcusp];
  5446. return [];
  5447. }
  5448. return [tcusp - root, tcusp + root].filter(function (r) { return r > 0 && r < 1; });
  5449. };
  5450. PolynomialBezier.prototype.split = function (t) {
  5451. if (t <= 0) return [singlePoint(this.points[0]), this];
  5452. if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
  5453. var p10 = lerpPoint(this.points[0], this.points[1], t);
  5454. var p11 = lerpPoint(this.points[1], this.points[2], t);
  5455. var p12 = lerpPoint(this.points[2], this.points[3], t);
  5456. var p20 = lerpPoint(p10, p11, t);
  5457. var p21 = lerpPoint(p11, p12, t);
  5458. var p3 = lerpPoint(p20, p21, t);
  5459. return [
  5460. new PolynomialBezier(this.points[0], p10, p20, p3, true),
  5461. new PolynomialBezier(p3, p21, p12, this.points[3], true),
  5462. ];
  5463. };
  5464. function extrema(bez, comp) {
  5465. var min = bez.points[0][comp];
  5466. var max = bez.points[bez.points.length - 1][comp];
  5467. if (min > max) {
  5468. var e = max;
  5469. max = min;
  5470. min = e;
  5471. }
  5472. // Derivative roots to find min/max
  5473. var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
  5474. for (var i = 0; i < f.length; i += 1) {
  5475. if (f[i] > 0 && f[i] < 1) {
  5476. var val = bez.point(f[i])[comp];
  5477. if (val < min) min = val;
  5478. else if (val > max) max = val;
  5479. }
  5480. }
  5481. return {
  5482. min: min,
  5483. max: max,
  5484. };
  5485. }
  5486. PolynomialBezier.prototype.bounds = function () {
  5487. return {
  5488. x: extrema(this, 0),
  5489. y: extrema(this, 1),
  5490. };
  5491. };
  5492. PolynomialBezier.prototype.boundingBox = function () {
  5493. var bounds = this.bounds();
  5494. return {
  5495. left: bounds.x.min,
  5496. right: bounds.x.max,
  5497. top: bounds.y.min,
  5498. bottom: bounds.y.max,
  5499. width: bounds.x.max - bounds.x.min,
  5500. height: bounds.y.max - bounds.y.min,
  5501. cx: (bounds.x.max + bounds.x.min) / 2,
  5502. cy: (bounds.y.max + bounds.y.min) / 2,
  5503. };
  5504. };
  5505. function intersectData(bez, t1, t2) {
  5506. var box = bez.boundingBox();
  5507. return {
  5508. cx: box.cx,
  5509. cy: box.cy,
  5510. width: box.width,
  5511. height: box.height,
  5512. bez: bez,
  5513. t: (t1 + t2) / 2,
  5514. t1: t1,
  5515. t2: t2,
  5516. };
  5517. }
  5518. function splitData(data) {
  5519. var split = data.bez.split(0.5);
  5520. return [
  5521. intersectData(split[0], data.t1, data.t),
  5522. intersectData(split[1], data.t, data.t2),
  5523. ];
  5524. }
  5525. function boxIntersect(b1, b2) {
  5526. return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width
  5527. && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
  5528. }
  5529. function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
  5530. if (!boxIntersect(d1, d2)) return;
  5531. if (depth >= maxRecursion || (d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance)) {
  5532. intersections.push([d1.t, d2.t]);
  5533. return;
  5534. }
  5535. var d1s = splitData(d1);
  5536. var d2s = splitData(d2);
  5537. intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5538. intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5539. intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5540. intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5541. }
  5542. PolynomialBezier.prototype.intersections = function (other, tolerance, maxRecursion) {
  5543. if (tolerance === undefined) tolerance = 2;
  5544. if (maxRecursion === undefined) maxRecursion = 7;
  5545. var intersections = [];
  5546. intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
  5547. return intersections;
  5548. };
  5549. PolynomialBezier.shapeSegment = function (shapePath, index) {
  5550. var nextIndex = (index + 1) % shapePath.length();
  5551. return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
  5552. };
  5553. PolynomialBezier.shapeSegmentInverted = function (shapePath, index) {
  5554. var nextIndex = (index + 1) % shapePath.length();
  5555. return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
  5556. };
  5557. function crossProduct(a, b) {
  5558. return [
  5559. a[1] * b[2] - a[2] * b[1],
  5560. a[2] * b[0] - a[0] * b[2],
  5561. a[0] * b[1] - a[1] * b[0],
  5562. ];
  5563. }
  5564. function lineIntersection(start1, end1, start2, end2) {
  5565. var v1 = [start1[0], start1[1], 1];
  5566. var v2 = [end1[0], end1[1], 1];
  5567. var v3 = [start2[0], start2[1], 1];
  5568. var v4 = [end2[0], end2[1], 1];
  5569. var r = crossProduct(
  5570. crossProduct(v1, v2),
  5571. crossProduct(v3, v4)
  5572. );
  5573. if (floatZero(r[2])) return null;
  5574. return [r[0] / r[2], r[1] / r[2]];
  5575. }
  5576. function polarOffset(p, angle, length) {
  5577. return [
  5578. p[0] + Math.cos(angle) * length,
  5579. p[1] - Math.sin(angle) * length,
  5580. ];
  5581. }
  5582. function pointDistance(p1, p2) {
  5583. return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
  5584. }
  5585. function pointEqual(p1, p2) {
  5586. return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
  5587. }
  5588. function ZigZagModifier() {}
  5589. extendPrototype([ShapeModifier], ZigZagModifier);
  5590. ZigZagModifier.prototype.initModifierProperties = function (elem, data) {
  5591. this.getValue = this.processKeys;
  5592. this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
  5593. this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5594. this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
  5595. this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
  5596. };
  5597. function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
  5598. var angO = angle - Math.PI / 2;
  5599. var angI = angle + Math.PI / 2;
  5600. var px = point[0] + Math.cos(angle) * direction * amplitude;
  5601. var py = point[1] - Math.sin(angle) * direction * amplitude;
  5602. outputBezier.setTripleAt(
  5603. px,
  5604. py,
  5605. px + Math.cos(angO) * outAmplitude,
  5606. py - Math.sin(angO) * outAmplitude,
  5607. px + Math.cos(angI) * inAmplitude,
  5608. py - Math.sin(angI) * inAmplitude,
  5609. outputBezier.length()
  5610. );
  5611. }
  5612. function getPerpendicularVector(pt1, pt2) {
  5613. var vector = [
  5614. pt2[0] - pt1[0],
  5615. pt2[1] - pt1[1],
  5616. ];
  5617. var rot = -Math.PI * 0.5;
  5618. var rotatedVector = [
  5619. Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1],
  5620. Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1],
  5621. ];
  5622. return rotatedVector;
  5623. }
  5624. function getProjectingAngle(path, cur) {
  5625. var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
  5626. var nextIndex = (cur + 1) % path.length();
  5627. var prevPoint = path.v[prevIndex];
  5628. var nextPoint = path.v[nextIndex];
  5629. var pVector = getPerpendicularVector(prevPoint, nextPoint);
  5630. return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
  5631. }
  5632. function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
  5633. var angle = getProjectingAngle(path, cur);
  5634. var point = path.v[cur % path._length];
  5635. var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
  5636. var nextPoint = path.v[(cur + 1) % path._length];
  5637. var prevDist = pointType === 2
  5638. ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2))
  5639. : 0;
  5640. var nextDist = pointType === 2
  5641. ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2))
  5642. : 0;
  5643. setPoint(
  5644. outputBezier,
  5645. path.v[cur % path._length],
  5646. angle,
  5647. direction,
  5648. amplitude,
  5649. nextDist / ((frequency + 1) * 2),
  5650. prevDist / ((frequency + 1) * 2),
  5651. pointType
  5652. );
  5653. }
  5654. function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
  5655. for (var i = 0; i < frequency; i += 1) {
  5656. var t = (i + 1) / (frequency + 1);
  5657. var dist = pointType === 2
  5658. ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2))
  5659. : 0;
  5660. var angle = segment.normalAngle(t);
  5661. var point = segment.point(t);
  5662. setPoint(
  5663. outputBezier,
  5664. point,
  5665. angle,
  5666. direction,
  5667. amplitude,
  5668. dist / ((frequency + 1) * 2),
  5669. dist / ((frequency + 1) * 2),
  5670. pointType
  5671. );
  5672. direction = -direction;
  5673. }
  5674. return direction;
  5675. }
  5676. ZigZagModifier.prototype.processPath = function (path, amplitude, frequency, pointType) {
  5677. var count = path._length;
  5678. var clonedPath = shapePool.newElement();
  5679. clonedPath.c = path.c;
  5680. if (!path.c) {
  5681. count -= 1;
  5682. }
  5683. if (count === 0) return clonedPath;
  5684. var direction = -1;
  5685. var segment = PolynomialBezier.shapeSegment(path, 0);
  5686. zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
  5687. for (var i = 0; i < count; i += 1) {
  5688. direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
  5689. if (i === count - 1 && !path.c) {
  5690. segment = null;
  5691. } else {
  5692. segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
  5693. }
  5694. zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
  5695. }
  5696. return clonedPath;
  5697. };
  5698. ZigZagModifier.prototype.processShapes = function (_isFirstFrame) {
  5699. var shapePaths;
  5700. var i;
  5701. var len = this.shapes.length;
  5702. var j;
  5703. var jLen;
  5704. var amplitude = this.amplitude.v;
  5705. var frequency = Math.max(0, Math.round(this.frequency.v));
  5706. var pointType = this.pointsType.v;
  5707. if (amplitude !== 0) {
  5708. var shapeData;
  5709. var localShapeCollection;
  5710. for (i = 0; i < len; i += 1) {
  5711. shapeData = this.shapes[i];
  5712. localShapeCollection = shapeData.localShapeCollection;
  5713. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5714. localShapeCollection.releaseShapes();
  5715. shapeData.shape._mdf = true;
  5716. shapePaths = shapeData.shape.paths.shapes;
  5717. jLen = shapeData.shape.paths._length;
  5718. for (j = 0; j < jLen; j += 1) {
  5719. localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
  5720. }
  5721. }
  5722. shapeData.shape.paths = shapeData.localShapeCollection;
  5723. }
  5724. }
  5725. if (!this.dynamicProperties.length) {
  5726. this._mdf = false;
  5727. }
  5728. };
  5729. function linearOffset(p1, p2, amount) {
  5730. var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
  5731. return [
  5732. polarOffset(p1, angle, amount),
  5733. polarOffset(p2, angle, amount),
  5734. ];
  5735. }
  5736. function offsetSegment(segment, amount) {
  5737. var p0; var p1a; var p1b; var p2b; var p2a; var
  5738. p3;
  5739. var e;
  5740. e = linearOffset(segment.points[0], segment.points[1], amount);
  5741. p0 = e[0];
  5742. p1a = e[1];
  5743. e = linearOffset(segment.points[1], segment.points[2], amount);
  5744. p1b = e[0];
  5745. p2b = e[1];
  5746. e = linearOffset(segment.points[2], segment.points[3], amount);
  5747. p2a = e[0];
  5748. p3 = e[1];
  5749. var p1 = lineIntersection(p0, p1a, p1b, p2b);
  5750. if (p1 === null) p1 = p1a;
  5751. var p2 = lineIntersection(p2a, p3, p1b, p2b);
  5752. if (p2 === null) p2 = p2a;
  5753. return new PolynomialBezier(p0, p1, p2, p3);
  5754. }
  5755. function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
  5756. var p0 = seg1.points[3];
  5757. var p1 = seg2.points[0];
  5758. // Bevel
  5759. if (lineJoin === 3) return p0;
  5760. // Connected, they don't need a joint
  5761. if (pointEqual(p0, p1)) return p0;
  5762. // Round
  5763. if (lineJoin === 2) {
  5764. var angleOut = -seg1.tangentAngle(1);
  5765. var angleIn = -seg2.tangentAngle(0) + Math.PI;
  5766. var center = lineIntersection(
  5767. p0,
  5768. polarOffset(p0, angleOut + Math.PI / 2, 100),
  5769. p1,
  5770. polarOffset(p1, angleOut + Math.PI / 2, 100)
  5771. );
  5772. var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
  5773. var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
  5774. outputBezier.setXYAt(tan[0], tan[1], 'o', outputBezier.length() - 1);
  5775. tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
  5776. outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
  5777. return p1;
  5778. }
  5779. // Miter
  5780. var t0 = pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2];
  5781. var t1 = pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1];
  5782. var intersection = lineIntersection(t0, p0, p1, t1);
  5783. if (intersection && pointDistance(intersection, p0) < miterLimit) {
  5784. outputBezier.setTripleAt(
  5785. intersection[0],
  5786. intersection[1],
  5787. intersection[0],
  5788. intersection[1],
  5789. intersection[0],
  5790. intersection[1],
  5791. outputBezier.length()
  5792. );
  5793. return intersection;
  5794. }
  5795. return p0;
  5796. }
  5797. function getIntersection(a, b) {
  5798. const intersect = a.intersections(b);
  5799. if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
  5800. if (intersect.length) return intersect[0];
  5801. return null;
  5802. }
  5803. function pruneSegmentIntersection(a, b) {
  5804. var outa = a.slice();
  5805. var outb = b.slice();
  5806. var intersect = getIntersection(a[a.length - 1], b[0]);
  5807. if (intersect) {
  5808. outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
  5809. outb[0] = b[0].split(intersect[1])[1];
  5810. }
  5811. if (a.length > 1 && b.length > 1) {
  5812. intersect = getIntersection(a[0], b[b.length - 1]);
  5813. if (intersect) {
  5814. return [
  5815. [a[0].split(intersect[0])[0]],
  5816. [b[b.length - 1].split(intersect[1])[1]],
  5817. ];
  5818. }
  5819. }
  5820. return [outa, outb];
  5821. }
  5822. function pruneIntersections(segments) {
  5823. var e;
  5824. for (var i = 1; i < segments.length; i += 1) {
  5825. e = pruneSegmentIntersection(segments[i - 1], segments[i]);
  5826. segments[i - 1] = e[0];
  5827. segments[i] = e[1];
  5828. }
  5829. if (segments.length > 1) {
  5830. e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
  5831. segments[segments.length - 1] = e[0];
  5832. segments[0] = e[1];
  5833. }
  5834. return segments;
  5835. }
  5836. function offsetSegmentSplit(segment, amount) {
  5837. /*
  5838. We split each bezier segment into smaller pieces based
  5839. on inflection points, this ensures the control point
  5840. polygon is convex.
  5841. (A cubic bezier can have none, one, or two inflection points)
  5842. */
  5843. var flex = segment.inflectionPoints();
  5844. var left;
  5845. var right;
  5846. var split;
  5847. var mid;
  5848. if (flex.length === 0) {
  5849. return [offsetSegment(segment, amount)];
  5850. }
  5851. if (flex.length === 1 || floatEqual(flex[1], 1)) {
  5852. split = segment.split(flex[0]);
  5853. left = split[0];
  5854. right = split[1];
  5855. return [
  5856. offsetSegment(left, amount),
  5857. offsetSegment(right, amount),
  5858. ];
  5859. }
  5860. split = segment.split(flex[0]);
  5861. left = split[0];
  5862. var t = (flex[1] - flex[0]) / (1 - flex[0]);
  5863. split = split[1].split(t);
  5864. mid = split[0];
  5865. right = split[1];
  5866. return [
  5867. offsetSegment(left, amount),
  5868. offsetSegment(mid, amount),
  5869. offsetSegment(right, amount),
  5870. ];
  5871. }
  5872. function OffsetPathModifier() {}
  5873. extendPrototype([ShapeModifier], OffsetPathModifier);
  5874. OffsetPathModifier.prototype.initModifierProperties = function (elem, data) {
  5875. this.getValue = this.processKeys;
  5876. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  5877. this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
  5878. this.lineJoin = data.lj;
  5879. this._isAnimated = this.amount.effectsSequence.length !== 0;
  5880. };
  5881. OffsetPathModifier.prototype.processPath = function (inputBezier, amount, lineJoin, miterLimit) {
  5882. var outputBezier = shapePool.newElement();
  5883. outputBezier.c = inputBezier.c;
  5884. var count = inputBezier.length();
  5885. if (!inputBezier.c) {
  5886. count -= 1;
  5887. }
  5888. var i; var j; var segment;
  5889. var multiSegments = [];
  5890. for (i = 0; i < count; i += 1) {
  5891. segment = PolynomialBezier.shapeSegment(inputBezier, i);
  5892. multiSegments.push(offsetSegmentSplit(segment, amount));
  5893. }
  5894. if (!inputBezier.c) {
  5895. for (i = count - 1; i >= 0; i -= 1) {
  5896. segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
  5897. multiSegments.push(offsetSegmentSplit(segment, amount));
  5898. }
  5899. }
  5900. multiSegments = pruneIntersections(multiSegments);
  5901. // Add bezier segments to the output and apply line joints
  5902. var lastPoint = null;
  5903. var lastSeg = null;
  5904. for (i = 0; i < multiSegments.length; i += 1) {
  5905. var multiSegment = multiSegments[i];
  5906. if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
  5907. lastSeg = multiSegment[multiSegment.length - 1];
  5908. for (j = 0; j < multiSegment.length; j += 1) {
  5909. segment = multiSegment[j];
  5910. if (lastPoint && pointEqual(segment.points[0], lastPoint)) {
  5911. outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], 'o', outputBezier.length() - 1);
  5912. } else {
  5913. outputBezier.setTripleAt(
  5914. segment.points[0][0],
  5915. segment.points[0][1],
  5916. segment.points[1][0],
  5917. segment.points[1][1],
  5918. segment.points[0][0],
  5919. segment.points[0][1],
  5920. outputBezier.length()
  5921. );
  5922. }
  5923. outputBezier.setTripleAt(
  5924. segment.points[3][0],
  5925. segment.points[3][1],
  5926. segment.points[3][0],
  5927. segment.points[3][1],
  5928. segment.points[2][0],
  5929. segment.points[2][1],
  5930. outputBezier.length()
  5931. );
  5932. lastPoint = segment.points[3];
  5933. }
  5934. }
  5935. if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
  5936. return outputBezier;
  5937. };
  5938. OffsetPathModifier.prototype.processShapes = function (_isFirstFrame) {
  5939. var shapePaths;
  5940. var i;
  5941. var len = this.shapes.length;
  5942. var j;
  5943. var jLen;
  5944. var amount = this.amount.v;
  5945. var miterLimit = this.miterLimit.v;
  5946. var lineJoin = this.lineJoin;
  5947. if (amount !== 0) {
  5948. var shapeData;
  5949. var localShapeCollection;
  5950. for (i = 0; i < len; i += 1) {
  5951. shapeData = this.shapes[i];
  5952. localShapeCollection = shapeData.localShapeCollection;
  5953. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5954. localShapeCollection.releaseShapes();
  5955. shapeData.shape._mdf = true;
  5956. shapePaths = shapeData.shape.paths.shapes;
  5957. jLen = shapeData.shape.paths._length;
  5958. for (j = 0; j < jLen; j += 1) {
  5959. localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
  5960. }
  5961. }
  5962. shapeData.shape.paths = shapeData.localShapeCollection;
  5963. }
  5964. }
  5965. if (!this.dynamicProperties.length) {
  5966. this._mdf = false;
  5967. }
  5968. };
  5969. function getFontProperties(fontData) {
  5970. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5971. var fWeight = 'normal'; var
  5972. fStyle = 'normal';
  5973. var len = styles.length;
  5974. var styleName;
  5975. for (var i = 0; i < len; i += 1) {
  5976. styleName = styles[i].toLowerCase();
  5977. switch (styleName) {
  5978. case 'italic':
  5979. fStyle = 'italic';
  5980. break;
  5981. case 'bold':
  5982. fWeight = '700';
  5983. break;
  5984. case 'black':
  5985. fWeight = '900';
  5986. break;
  5987. case 'medium':
  5988. fWeight = '500';
  5989. break;
  5990. case 'regular':
  5991. case 'normal':
  5992. fWeight = '400';
  5993. break;
  5994. case 'light':
  5995. case 'thin':
  5996. fWeight = '200';
  5997. break;
  5998. default:
  5999. break;
  6000. }
  6001. }
  6002. return {
  6003. style: fStyle,
  6004. weight: fontData.fWeight || fWeight,
  6005. };
  6006. }
  6007. const FontManager = (function () {
  6008. var maxWaitingTime = 5000;
  6009. var emptyChar = {
  6010. w: 0,
  6011. size: 0,
  6012. shapes: [],
  6013. data: {
  6014. shapes: [],
  6015. },
  6016. };
  6017. var combinedCharacters = [];
  6018. // Hindi characters
  6019. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366,
  6020. 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379,
  6021. 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  6022. var BLACK_FLAG_CODE_POINT = 127988;
  6023. var CANCEL_TAG_CODE_POINT = 917631;
  6024. var A_TAG_CODE_POINT = 917601;
  6025. var Z_TAG_CODE_POINT = 917626;
  6026. var VARIATION_SELECTOR_16_CODE_POINT = 65039;
  6027. var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
  6028. var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
  6029. var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
  6030. var surrogateModifiers = [
  6031. 'd83cdffb',
  6032. 'd83cdffc',
  6033. 'd83cdffd',
  6034. 'd83cdffe',
  6035. 'd83cdfff',
  6036. ];
  6037. function trimFontOptions(font) {
  6038. var familyArray = font.split(',');
  6039. var i;
  6040. var len = familyArray.length;
  6041. var enabledFamilies = [];
  6042. for (i = 0; i < len; i += 1) {
  6043. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  6044. enabledFamilies.push(familyArray[i]);
  6045. }
  6046. }
  6047. return enabledFamilies.join(',');
  6048. }
  6049. function setUpNode(font, family) {
  6050. var parentNode = createTag('span');
  6051. // Node is invisible to screen readers.
  6052. parentNode.setAttribute('aria-hidden', true);
  6053. parentNode.style.fontFamily = family;
  6054. var node = createTag('span');
  6055. // Characters that vary significantly among different fonts
  6056. node.innerText = 'giItT1WQy@!-/#';
  6057. // Visible - so we can measure it - but not on the screen
  6058. parentNode.style.position = 'absolute';
  6059. parentNode.style.left = '-10000px';
  6060. parentNode.style.top = '-10000px';
  6061. // Large font size makes even subtle changes obvious
  6062. parentNode.style.fontSize = '300px';
  6063. // Reset any font properties
  6064. parentNode.style.fontVariant = 'normal';
  6065. parentNode.style.fontStyle = 'normal';
  6066. parentNode.style.fontWeight = 'normal';
  6067. parentNode.style.letterSpacing = '0';
  6068. parentNode.appendChild(node);
  6069. document.body.appendChild(parentNode);
  6070. // Remember width with no applied web font
  6071. var width = node.offsetWidth;
  6072. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  6073. return { node: node, w: width, parent: parentNode };
  6074. }
  6075. function checkLoadedFonts() {
  6076. var i;
  6077. var len = this.fonts.length;
  6078. var node;
  6079. var w;
  6080. var loadedCount = len;
  6081. for (i = 0; i < len; i += 1) {
  6082. if (this.fonts[i].loaded) {
  6083. loadedCount -= 1;
  6084. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  6085. this.fonts[i].loaded = true;
  6086. } else {
  6087. node = this.fonts[i].monoCase.node;
  6088. w = this.fonts[i].monoCase.w;
  6089. if (node.offsetWidth !== w) {
  6090. loadedCount -= 1;
  6091. this.fonts[i].loaded = true;
  6092. } else {
  6093. node = this.fonts[i].sansCase.node;
  6094. w = this.fonts[i].sansCase.w;
  6095. if (node.offsetWidth !== w) {
  6096. loadedCount -= 1;
  6097. this.fonts[i].loaded = true;
  6098. }
  6099. }
  6100. if (this.fonts[i].loaded) {
  6101. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  6102. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  6103. }
  6104. }
  6105. }
  6106. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  6107. setTimeout(this.checkLoadedFontsBinded, 20);
  6108. } else {
  6109. setTimeout(this.setIsLoadedBinded, 10);
  6110. }
  6111. }
  6112. function createHelper(fontData, def) {
  6113. var engine = (document.body && def) ? 'svg' : 'canvas';
  6114. var helper;
  6115. var fontProps = getFontProperties(fontData);
  6116. if (engine === 'svg') {
  6117. var tHelper = createNS('text');
  6118. tHelper.style.fontSize = '100px';
  6119. // tHelper.style.fontFamily = fontData.fFamily;
  6120. tHelper.setAttribute('font-family', fontData.fFamily);
  6121. tHelper.setAttribute('font-style', fontProps.style);
  6122. tHelper.setAttribute('font-weight', fontProps.weight);
  6123. tHelper.textContent = '1';
  6124. if (fontData.fClass) {
  6125. tHelper.style.fontFamily = 'inherit';
  6126. tHelper.setAttribute('class', fontData.fClass);
  6127. } else {
  6128. tHelper.style.fontFamily = fontData.fFamily;
  6129. }
  6130. def.appendChild(tHelper);
  6131. helper = tHelper;
  6132. } else {
  6133. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  6134. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  6135. helper = tCanvasHelper;
  6136. }
  6137. function measure(text) {
  6138. if (engine === 'svg') {
  6139. helper.textContent = text;
  6140. return helper.getComputedTextLength();
  6141. }
  6142. return helper.measureText(text).width;
  6143. }
  6144. return {
  6145. measureText: measure,
  6146. };
  6147. }
  6148. function addFonts(fontData, defs) {
  6149. if (!fontData) {
  6150. this.isLoaded = true;
  6151. return;
  6152. }
  6153. if (this.chars) {
  6154. this.isLoaded = true;
  6155. this.fonts = fontData.list;
  6156. return;
  6157. }
  6158. if (!document.body) {
  6159. this.isLoaded = true;
  6160. fontData.list.forEach((data) => {
  6161. data.helper = createHelper(data);
  6162. data.cache = {};
  6163. });
  6164. this.fonts = fontData.list;
  6165. return;
  6166. }
  6167. var fontArr = fontData.list;
  6168. var i;
  6169. var len = fontArr.length;
  6170. var _pendingFonts = len;
  6171. for (i = 0; i < len; i += 1) {
  6172. var shouldLoadFont = true;
  6173. var loadedSelector;
  6174. var j;
  6175. fontArr[i].loaded = false;
  6176. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  6177. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  6178. if (!fontArr[i].fPath) {
  6179. fontArr[i].loaded = true;
  6180. _pendingFonts -= 1;
  6181. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  6182. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  6183. if (loadedSelector.length > 0) {
  6184. shouldLoadFont = false;
  6185. }
  6186. if (shouldLoadFont) {
  6187. var s = createTag('style');
  6188. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  6189. s.setAttribute('f-origin', fontArr[i].origin);
  6190. s.setAttribute('f-family', fontArr[i].fFamily);
  6191. s.type = 'text/css';
  6192. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  6193. defs.appendChild(s);
  6194. }
  6195. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  6196. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  6197. for (j = 0; j < loadedSelector.length; j += 1) {
  6198. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  6199. // Font is already loaded
  6200. shouldLoadFont = false;
  6201. }
  6202. }
  6203. if (shouldLoadFont) {
  6204. var l = createTag('link');
  6205. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  6206. l.setAttribute('f-origin', fontArr[i].origin);
  6207. l.type = 'text/css';
  6208. l.rel = 'stylesheet';
  6209. l.href = fontArr[i].fPath;
  6210. document.body.appendChild(l);
  6211. }
  6212. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  6213. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  6214. for (j = 0; j < loadedSelector.length; j += 1) {
  6215. if (fontArr[i].fPath === loadedSelector[j].src) {
  6216. // Font is already loaded
  6217. shouldLoadFont = false;
  6218. }
  6219. }
  6220. if (shouldLoadFont) {
  6221. var sc = createTag('link');
  6222. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  6223. sc.setAttribute('f-origin', fontArr[i].origin);
  6224. sc.setAttribute('rel', 'stylesheet');
  6225. sc.setAttribute('href', fontArr[i].fPath);
  6226. defs.appendChild(sc);
  6227. }
  6228. }
  6229. fontArr[i].helper = createHelper(fontArr[i], defs);
  6230. fontArr[i].cache = {};
  6231. this.fonts.push(fontArr[i]);
  6232. }
  6233. if (_pendingFonts === 0) {
  6234. this.isLoaded = true;
  6235. } else {
  6236. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  6237. // Adding this timeout seems to fix it
  6238. setTimeout(this.checkLoadedFonts.bind(this), 100);
  6239. }
  6240. }
  6241. function addChars(chars) {
  6242. if (!chars) {
  6243. return;
  6244. }
  6245. if (!this.chars) {
  6246. this.chars = [];
  6247. }
  6248. var i;
  6249. var len = chars.length;
  6250. var j;
  6251. var jLen = this.chars.length;
  6252. var found;
  6253. for (i = 0; i < len; i += 1) {
  6254. j = 0;
  6255. found = false;
  6256. while (j < jLen) {
  6257. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  6258. found = true;
  6259. }
  6260. j += 1;
  6261. }
  6262. if (!found) {
  6263. this.chars.push(chars[i]);
  6264. jLen += 1;
  6265. }
  6266. }
  6267. }
  6268. function getCharData(char, style, font) {
  6269. var i = 0;
  6270. var len = this.chars.length;
  6271. while (i < len) {
  6272. if (this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  6273. return this.chars[i];
  6274. }
  6275. i += 1;
  6276. }
  6277. if (((typeof char === 'string' && char.charCodeAt(0) !== 13) || !char)
  6278. && console
  6279. && console.warn // eslint-disable-line no-console
  6280. && !this._warned
  6281. ) {
  6282. this._warned = true;
  6283. console.warn('Missing character from exported characters list: ', char, style, font); // eslint-disable-line no-console
  6284. }
  6285. return emptyChar;
  6286. }
  6287. function measureText(char, fontName, size) {
  6288. var fontData = this.getFontByName(fontName);
  6289. // Using the char instead of char.charCodeAt(0)
  6290. // to avoid collisions between equal chars
  6291. var index = char;
  6292. if (!fontData.cache[index]) {
  6293. var tHelper = fontData.helper;
  6294. if (char === ' ') {
  6295. var doubleSize = tHelper.measureText('|' + char + '|');
  6296. var singleSize = tHelper.measureText('||');
  6297. fontData.cache[index] = (doubleSize - singleSize) / 100;
  6298. } else {
  6299. fontData.cache[index] = tHelper.measureText(char) / 100;
  6300. }
  6301. }
  6302. return fontData.cache[index] * size;
  6303. }
  6304. function getFontByName(name) {
  6305. var i = 0;
  6306. var len = this.fonts.length;
  6307. while (i < len) {
  6308. if (this.fonts[i].fName === name) {
  6309. return this.fonts[i];
  6310. }
  6311. i += 1;
  6312. }
  6313. return this.fonts[0];
  6314. }
  6315. function getCodePoint(string) {
  6316. var codePoint = 0;
  6317. var first = string.charCodeAt(0);
  6318. if (first >= 0xD800 && first <= 0xDBFF) {
  6319. var second = string.charCodeAt(1);
  6320. if (second >= 0xDC00 && second <= 0xDFFF) {
  6321. codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  6322. }
  6323. }
  6324. return codePoint;
  6325. }
  6326. // Skin tone modifiers
  6327. function isModifier(firstCharCode, secondCharCode) {
  6328. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  6329. return surrogateModifiers.indexOf(sum) !== -1;
  6330. }
  6331. function isZeroWidthJoiner(charCode) {
  6332. return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
  6333. }
  6334. // This codepoint may change the appearance of the preceding character.
  6335. // If that is a symbol, dingbat or emoji, U+FE0F forces it to be rendered
  6336. // as a colorful image as compared to a monochrome text variant.
  6337. function isVariationSelector(charCode) {
  6338. return charCode === VARIATION_SELECTOR_16_CODE_POINT;
  6339. }
  6340. // The regional indicator symbols are a set of 26 alphabetic Unicode
  6341. /// characters (A–Z) intended to be used to encode ISO 3166-1 alpha-2
  6342. // two-letter country codes in a way that allows optional special treatment.
  6343. function isRegionalCode(string) {
  6344. var codePoint = getCodePoint(string);
  6345. if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) {
  6346. return true;
  6347. }
  6348. return false;
  6349. }
  6350. // Some Emoji implementations represent combinations of
  6351. // two “regional indicator” letters as a single flag symbol.
  6352. function isFlagEmoji(string) {
  6353. return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
  6354. }
  6355. function isCombinedCharacter(char) {
  6356. return combinedCharacters.indexOf(char) !== -1;
  6357. }
  6358. // Regional flags start with a BLACK_FLAG_CODE_POINT
  6359. // folowed by 5 chars in the TAG range
  6360. // and end with a CANCEL_TAG_CODE_POINT
  6361. function isRegionalFlag(text, index) {
  6362. var codePoint = getCodePoint(text.substr(index, 2));
  6363. if (codePoint !== BLACK_FLAG_CODE_POINT) {
  6364. return false;
  6365. }
  6366. var count = 0;
  6367. index += 2;
  6368. while (count < 5) {
  6369. codePoint = getCodePoint(text.substr(index, 2));
  6370. if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) {
  6371. return false;
  6372. }
  6373. count += 1;
  6374. index += 2;
  6375. }
  6376. return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
  6377. }
  6378. function setIsLoaded() {
  6379. this.isLoaded = true;
  6380. }
  6381. var Font = function () {
  6382. this.fonts = [];
  6383. this.chars = null;
  6384. this.typekitLoaded = 0;
  6385. this.isLoaded = false;
  6386. this._warned = false;
  6387. this.initTime = Date.now();
  6388. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  6389. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  6390. };
  6391. Font.isModifier = isModifier;
  6392. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  6393. Font.isFlagEmoji = isFlagEmoji;
  6394. Font.isRegionalCode = isRegionalCode;
  6395. Font.isCombinedCharacter = isCombinedCharacter;
  6396. Font.isRegionalFlag = isRegionalFlag;
  6397. Font.isVariationSelector = isVariationSelector;
  6398. Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
  6399. var fontPrototype = {
  6400. addChars: addChars,
  6401. addFonts: addFonts,
  6402. getCharData: getCharData,
  6403. getFontByName: getFontByName,
  6404. measureText: measureText,
  6405. checkLoadedFonts: checkLoadedFonts,
  6406. setIsLoaded: setIsLoaded,
  6407. };
  6408. Font.prototype = fontPrototype;
  6409. return Font;
  6410. }());
  6411. function SlotManager(animationData) {
  6412. this.animationData = animationData;
  6413. }
  6414. SlotManager.prototype.getProp = function (data) {
  6415. if (this.animationData.slots
  6416. && this.animationData.slots[data.sid]
  6417. ) {
  6418. return Object.assign(data, this.animationData.slots[data.sid].p);
  6419. }
  6420. return data;
  6421. };
  6422. function slotFactory(animationData) {
  6423. return new SlotManager(animationData);
  6424. }
  6425. function RenderableElement() {
  6426. }
  6427. RenderableElement.prototype = {
  6428. initRenderable: function () {
  6429. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6430. this.isInRange = false;
  6431. // layer's display state
  6432. this.hidden = false;
  6433. // If layer's transparency equals 0, it can be hidden
  6434. this.isTransparent = false;
  6435. // list of animated components
  6436. this.renderableComponents = [];
  6437. },
  6438. addRenderableComponent: function (component) {
  6439. if (this.renderableComponents.indexOf(component) === -1) {
  6440. this.renderableComponents.push(component);
  6441. }
  6442. },
  6443. removeRenderableComponent: function (component) {
  6444. if (this.renderableComponents.indexOf(component) !== -1) {
  6445. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6446. }
  6447. },
  6448. prepareRenderableFrame: function (num) {
  6449. this.checkLayerLimits(num);
  6450. },
  6451. checkTransparency: function () {
  6452. if (this.finalTransform.mProp.o.v <= 0) {
  6453. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  6454. this.isTransparent = true;
  6455. this.hide();
  6456. }
  6457. } else if (this.isTransparent) {
  6458. this.isTransparent = false;
  6459. this.show();
  6460. }
  6461. },
  6462. /**
  6463. * @function
  6464. * Initializes frame related properties.
  6465. *
  6466. * @param {number} num
  6467. * current frame number in Layer's time
  6468. *
  6469. */
  6470. checkLayerLimits: function (num) {
  6471. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  6472. if (this.isInRange !== true) {
  6473. this.globalData._mdf = true;
  6474. this._mdf = true;
  6475. this.isInRange = true;
  6476. this.show();
  6477. }
  6478. } else if (this.isInRange !== false) {
  6479. this.globalData._mdf = true;
  6480. this.isInRange = false;
  6481. this.hide();
  6482. }
  6483. },
  6484. renderRenderable: function () {
  6485. var i;
  6486. var len = this.renderableComponents.length;
  6487. for (i = 0; i < len; i += 1) {
  6488. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6489. }
  6490. /* this.maskManager.renderFrame(this.finalTransform.mat);
  6491. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  6492. },
  6493. sourceRectAtTime: function () {
  6494. return {
  6495. top: 0,
  6496. left: 0,
  6497. width: 100,
  6498. height: 100,
  6499. };
  6500. },
  6501. getLayerSize: function () {
  6502. if (this.data.ty === 5) {
  6503. return { w: this.data.textData.width, h: this.data.textData.height };
  6504. }
  6505. return { w: this.data.width, h: this.data.height };
  6506. },
  6507. };
  6508. const getBlendMode = (function () {
  6509. var blendModeEnums = {
  6510. 0: 'source-over',
  6511. 1: 'multiply',
  6512. 2: 'screen',
  6513. 3: 'overlay',
  6514. 4: 'darken',
  6515. 5: 'lighten',
  6516. 6: 'color-dodge',
  6517. 7: 'color-burn',
  6518. 8: 'hard-light',
  6519. 9: 'soft-light',
  6520. 10: 'difference',
  6521. 11: 'exclusion',
  6522. 12: 'hue',
  6523. 13: 'saturation',
  6524. 14: 'color',
  6525. 15: 'luminosity',
  6526. };
  6527. return function (mode) {
  6528. return blendModeEnums[mode] || '';
  6529. };
  6530. }());
  6531. function SliderEffect(data, elem, container) {
  6532. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6533. }
  6534. function AngleEffect(data, elem, container) {
  6535. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6536. }
  6537. function ColorEffect(data, elem, container) {
  6538. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6539. }
  6540. function PointEffect(data, elem, container) {
  6541. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6542. }
  6543. function LayerIndexEffect(data, elem, container) {
  6544. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6545. }
  6546. function MaskIndexEffect(data, elem, container) {
  6547. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6548. }
  6549. function CheckboxEffect(data, elem, container) {
  6550. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6551. }
  6552. function NoValueEffect() {
  6553. this.p = {};
  6554. }
  6555. function EffectsManager(data, element) {
  6556. var effects = data.ef || [];
  6557. this.effectElements = [];
  6558. var i;
  6559. var len = effects.length;
  6560. var effectItem;
  6561. for (i = 0; i < len; i += 1) {
  6562. effectItem = new GroupEffect(effects[i], element);
  6563. this.effectElements.push(effectItem);
  6564. }
  6565. }
  6566. function GroupEffect(data, element) {
  6567. this.init(data, element);
  6568. }
  6569. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6570. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6571. GroupEffect.prototype.init = function (data, element) {
  6572. this.data = data;
  6573. this.effectElements = [];
  6574. this.initDynamicPropertyContainer(element);
  6575. var i;
  6576. var len = this.data.ef.length;
  6577. var eff;
  6578. var effects = this.data.ef;
  6579. for (i = 0; i < len; i += 1) {
  6580. eff = null;
  6581. switch (effects[i].ty) {
  6582. case 0:
  6583. eff = new SliderEffect(effects[i], element, this);
  6584. break;
  6585. case 1:
  6586. eff = new AngleEffect(effects[i], element, this);
  6587. break;
  6588. case 2:
  6589. eff = new ColorEffect(effects[i], element, this);
  6590. break;
  6591. case 3:
  6592. eff = new PointEffect(effects[i], element, this);
  6593. break;
  6594. case 4:
  6595. case 7:
  6596. eff = new CheckboxEffect(effects[i], element, this);
  6597. break;
  6598. case 10:
  6599. eff = new LayerIndexEffect(effects[i], element, this);
  6600. break;
  6601. case 11:
  6602. eff = new MaskIndexEffect(effects[i], element, this);
  6603. break;
  6604. case 5:
  6605. eff = new EffectsManager(effects[i], element, this);
  6606. break;
  6607. // case 6:
  6608. default:
  6609. eff = new NoValueEffect(effects[i], element, this);
  6610. break;
  6611. }
  6612. if (eff) {
  6613. this.effectElements.push(eff);
  6614. }
  6615. }
  6616. };
  6617. function BaseElement() {
  6618. }
  6619. BaseElement.prototype = {
  6620. checkMasks: function () {
  6621. if (!this.data.hasMask) {
  6622. return false;
  6623. }
  6624. var i = 0;
  6625. var len = this.data.masksProperties.length;
  6626. while (i < len) {
  6627. if ((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) {
  6628. return true;
  6629. }
  6630. i += 1;
  6631. }
  6632. return false;
  6633. },
  6634. initExpressions: function () {
  6635. const expressionsInterfaces = getExpressionInterfaces();
  6636. if (!expressionsInterfaces) {
  6637. return;
  6638. }
  6639. const LayerExpressionInterface = expressionsInterfaces('layer');
  6640. const EffectsExpressionInterface = expressionsInterfaces('effects');
  6641. const ShapeExpressionInterface = expressionsInterfaces('shape');
  6642. const TextExpressionInterface = expressionsInterfaces('text');
  6643. const CompExpressionInterface = expressionsInterfaces('comp');
  6644. this.layerInterface = LayerExpressionInterface(this);
  6645. if (this.data.hasMask && this.maskManager) {
  6646. this.layerInterface.registerMaskInterface(this.maskManager);
  6647. }
  6648. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
  6649. this.layerInterface.registerEffectsInterface(effectsInterface);
  6650. if (this.data.ty === 0 || this.data.xt) {
  6651. this.compInterface = CompExpressionInterface(this);
  6652. } else if (this.data.ty === 4) {
  6653. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
  6654. this.layerInterface.content = this.layerInterface.shapeInterface;
  6655. } else if (this.data.ty === 5) {
  6656. this.layerInterface.textInterface = TextExpressionInterface(this);
  6657. this.layerInterface.text = this.layerInterface.textInterface;
  6658. }
  6659. },
  6660. setBlendMode: function () {
  6661. var blendModeValue = getBlendMode(this.data.bm);
  6662. var elem = this.baseElement || this.layerElement;
  6663. elem.style['mix-blend-mode'] = blendModeValue;
  6664. },
  6665. initBaseData: function (data, globalData, comp) {
  6666. this.globalData = globalData;
  6667. this.comp = comp;
  6668. this.data = data;
  6669. this.layerId = createElementID();
  6670. // Stretch factor for old animations missing this property.
  6671. if (!this.data.sr) {
  6672. this.data.sr = 1;
  6673. }
  6674. // effects manager
  6675. this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
  6676. },
  6677. getType: function () {
  6678. return this.type;
  6679. },
  6680. sourceRectAtTime: function () {},
  6681. };
  6682. /**
  6683. * @file
  6684. * Handles element's layer frame update.
  6685. * Checks layer in point and out point
  6686. *
  6687. */
  6688. function FrameElement() {}
  6689. FrameElement.prototype = {
  6690. /**
  6691. * @function
  6692. * Initializes frame related properties.
  6693. *
  6694. */
  6695. initFrame: function () {
  6696. // set to true when inpoint is rendered
  6697. this._isFirstFrame = false;
  6698. // list of animated properties
  6699. this.dynamicProperties = [];
  6700. // If layer has been modified in current tick this will be true
  6701. this._mdf = false;
  6702. },
  6703. /**
  6704. * @function
  6705. * Calculates all dynamic values
  6706. *
  6707. * @param {number} num
  6708. * current frame number in Layer's time
  6709. * @param {boolean} isVisible
  6710. * if layers is currently in range
  6711. *
  6712. */
  6713. prepareProperties: function (num, isVisible) {
  6714. var i;
  6715. var len = this.dynamicProperties.length;
  6716. for (i = 0; i < len; i += 1) {
  6717. if (isVisible || (this._isParent && this.dynamicProperties[i].propType === 'transform')) {
  6718. this.dynamicProperties[i].getValue();
  6719. if (this.dynamicProperties[i]._mdf) {
  6720. this.globalData._mdf = true;
  6721. this._mdf = true;
  6722. }
  6723. }
  6724. }
  6725. },
  6726. addDynamicProperty: function (prop) {
  6727. if (this.dynamicProperties.indexOf(prop) === -1) {
  6728. this.dynamicProperties.push(prop);
  6729. }
  6730. },
  6731. };
  6732. function FootageElement(data, globalData, comp) {
  6733. this.initFrame();
  6734. this.initRenderable();
  6735. this.assetData = globalData.getAssetData(data.refId);
  6736. this.footageData = globalData.imageLoader.getAsset(this.assetData);
  6737. this.initBaseData(data, globalData, comp);
  6738. }
  6739. FootageElement.prototype.prepareFrame = function () {
  6740. };
  6741. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  6742. FootageElement.prototype.getBaseElement = function () {
  6743. return null;
  6744. };
  6745. FootageElement.prototype.renderFrame = function () {
  6746. };
  6747. FootageElement.prototype.destroy = function () {
  6748. };
  6749. FootageElement.prototype.initExpressions = function () {
  6750. const expressionsInterfaces = getExpressionInterfaces();
  6751. if (!expressionsInterfaces) {
  6752. return;
  6753. }
  6754. const FootageInterface = expressionsInterfaces('footage');
  6755. this.layerInterface = FootageInterface(this);
  6756. };
  6757. FootageElement.prototype.getFootageData = function () {
  6758. return this.footageData;
  6759. };
  6760. function AudioElement(data, globalData, comp) {
  6761. this.initFrame();
  6762. this.initRenderable();
  6763. this.assetData = globalData.getAssetData(data.refId);
  6764. this.initBaseData(data, globalData, comp);
  6765. this._isPlaying = false;
  6766. this._canPlay = false;
  6767. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6768. this.audio = this.globalData.audioController.createAudio(assetPath);
  6769. this._currentTime = 0;
  6770. this.globalData.audioController.addAudio(this);
  6771. this._volumeMultiplier = 1;
  6772. this._volume = 1;
  6773. this._previousVolume = null;
  6774. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  6775. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : { k: [100] }, 1, 0.01, this);
  6776. }
  6777. AudioElement.prototype.prepareFrame = function (num) {
  6778. this.prepareRenderableFrame(num, true);
  6779. this.prepareProperties(num, true);
  6780. if (!this.tm._placeholder) {
  6781. var timeRemapped = this.tm.v;
  6782. this._currentTime = timeRemapped;
  6783. } else {
  6784. this._currentTime = num / this.data.sr;
  6785. }
  6786. this._volume = this.lv.v[0];
  6787. var totalVolume = this._volume * this._volumeMultiplier;
  6788. if (this._previousVolume !== totalVolume) {
  6789. this._previousVolume = totalVolume;
  6790. this.audio.volume(totalVolume);
  6791. }
  6792. };
  6793. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  6794. AudioElement.prototype.renderFrame = function () {
  6795. if (this.isInRange && this._canPlay) {
  6796. if (!this._isPlaying) {
  6797. this.audio.play();
  6798. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6799. this._isPlaying = true;
  6800. } else if (!this.audio.playing()
  6801. || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1
  6802. ) {
  6803. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6804. }
  6805. }
  6806. };
  6807. AudioElement.prototype.show = function () {
  6808. // this.audio.play()
  6809. };
  6810. AudioElement.prototype.hide = function () {
  6811. this.audio.pause();
  6812. this._isPlaying = false;
  6813. };
  6814. AudioElement.prototype.pause = function () {
  6815. this.audio.pause();
  6816. this._isPlaying = false;
  6817. this._canPlay = false;
  6818. };
  6819. AudioElement.prototype.resume = function () {
  6820. this._canPlay = true;
  6821. };
  6822. AudioElement.prototype.setRate = function (rateValue) {
  6823. this.audio.rate(rateValue);
  6824. };
  6825. AudioElement.prototype.volume = function (volumeValue) {
  6826. this._volumeMultiplier = volumeValue;
  6827. this._previousVolume = volumeValue * this._volume;
  6828. this.audio.volume(this._previousVolume);
  6829. };
  6830. AudioElement.prototype.getBaseElement = function () {
  6831. return null;
  6832. };
  6833. AudioElement.prototype.destroy = function () {
  6834. };
  6835. AudioElement.prototype.sourceRectAtTime = function () {
  6836. };
  6837. AudioElement.prototype.initExpressions = function () {
  6838. };
  6839. function BaseRenderer() {}
  6840. BaseRenderer.prototype.checkLayers = function (num) {
  6841. var i;
  6842. var len = this.layers.length;
  6843. var data;
  6844. this.completeLayers = true;
  6845. for (i = len - 1; i >= 0; i -= 1) {
  6846. if (!this.elements[i]) {
  6847. data = this.layers[i];
  6848. if (data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st)) {
  6849. this.buildItem(i);
  6850. }
  6851. }
  6852. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  6853. }
  6854. this.checkPendingElements();
  6855. };
  6856. BaseRenderer.prototype.createItem = function (layer) {
  6857. switch (layer.ty) {
  6858. case 2:
  6859. return this.createImage(layer);
  6860. case 0:
  6861. return this.createComp(layer);
  6862. case 1:
  6863. return this.createSolid(layer);
  6864. case 3:
  6865. return this.createNull(layer);
  6866. case 4:
  6867. return this.createShape(layer);
  6868. case 5:
  6869. return this.createText(layer);
  6870. case 6:
  6871. return this.createAudio(layer);
  6872. case 13:
  6873. return this.createCamera(layer);
  6874. case 15:
  6875. return this.createFootage(layer);
  6876. default:
  6877. return this.createNull(layer);
  6878. }
  6879. };
  6880. BaseRenderer.prototype.createCamera = function () {
  6881. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  6882. };
  6883. BaseRenderer.prototype.createAudio = function (data) {
  6884. return new AudioElement(data, this.globalData, this);
  6885. };
  6886. BaseRenderer.prototype.createFootage = function (data) {
  6887. return new FootageElement(data, this.globalData, this);
  6888. };
  6889. BaseRenderer.prototype.buildAllItems = function () {
  6890. var i;
  6891. var len = this.layers.length;
  6892. for (i = 0; i < len; i += 1) {
  6893. this.buildItem(i);
  6894. }
  6895. this.checkPendingElements();
  6896. };
  6897. BaseRenderer.prototype.includeLayers = function (newLayers) {
  6898. this.completeLayers = false;
  6899. var i;
  6900. var len = newLayers.length;
  6901. var j;
  6902. var jLen = this.layers.length;
  6903. for (i = 0; i < len; i += 1) {
  6904. j = 0;
  6905. while (j < jLen) {
  6906. if (this.layers[j].id === newLayers[i].id) {
  6907. this.layers[j] = newLayers[i];
  6908. break;
  6909. }
  6910. j += 1;
  6911. }
  6912. }
  6913. };
  6914. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  6915. this.globalData.projectInterface = pInterface;
  6916. };
  6917. BaseRenderer.prototype.initItems = function () {
  6918. if (!this.globalData.progressiveLoad) {
  6919. this.buildAllItems();
  6920. }
  6921. };
  6922. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  6923. var elements = this.elements;
  6924. var layers = this.layers;
  6925. var i = 0;
  6926. var len = layers.length;
  6927. while (i < len) {
  6928. if (layers[i].ind == parentName) { // eslint-disable-line eqeqeq
  6929. if (!elements[i] || elements[i] === true) {
  6930. this.buildItem(i);
  6931. this.addPendingElement(element);
  6932. } else {
  6933. hierarchy.push(elements[i]);
  6934. elements[i].setAsParent();
  6935. if (layers[i].parent !== undefined) {
  6936. this.buildElementParenting(element, layers[i].parent, hierarchy);
  6937. } else {
  6938. element.setHierarchy(hierarchy);
  6939. }
  6940. }
  6941. }
  6942. i += 1;
  6943. }
  6944. };
  6945. BaseRenderer.prototype.addPendingElement = function (element) {
  6946. this.pendingElements.push(element);
  6947. };
  6948. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  6949. var i;
  6950. var len = assets.length;
  6951. for (i = 0; i < len; i += 1) {
  6952. if (assets[i].xt) {
  6953. var comp = this.createComp(assets[i]);
  6954. comp.initExpressions();
  6955. this.globalData.projectInterface.registerComposition(comp);
  6956. }
  6957. }
  6958. };
  6959. BaseRenderer.prototype.getElementById = function (ind) {
  6960. var i;
  6961. var len = this.elements.length;
  6962. for (i = 0; i < len; i += 1) {
  6963. if (this.elements[i].data.ind === ind) {
  6964. return this.elements[i];
  6965. }
  6966. }
  6967. return null;
  6968. };
  6969. BaseRenderer.prototype.getElementByPath = function (path) {
  6970. var pathValue = path.shift();
  6971. var element;
  6972. if (typeof pathValue === 'number') {
  6973. element = this.elements[pathValue];
  6974. } else {
  6975. var i;
  6976. var len = this.elements.length;
  6977. for (i = 0; i < len; i += 1) {
  6978. if (this.elements[i].data.nm === pathValue) {
  6979. element = this.elements[i];
  6980. break;
  6981. }
  6982. }
  6983. }
  6984. if (path.length === 0) {
  6985. return element;
  6986. }
  6987. return element.getElementByPath(path);
  6988. };
  6989. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  6990. this.globalData.fontManager = new FontManager();
  6991. this.globalData.slotManager = slotFactory(animData);
  6992. this.globalData.fontManager.addChars(animData.chars);
  6993. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  6994. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  6995. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  6996. this.globalData.imageLoader = this.animationItem.imagePreloader;
  6997. this.globalData.audioController = this.animationItem.audioController;
  6998. this.globalData.frameId = 0;
  6999. this.globalData.frameRate = animData.fr;
  7000. this.globalData.nm = animData.nm;
  7001. this.globalData.compSize = {
  7002. w: animData.w,
  7003. h: animData.h,
  7004. };
  7005. };
  7006. var effectTypes = {
  7007. TRANSFORM_EFFECT: 'transformEFfect',
  7008. };
  7009. function TransformElement() {}
  7010. TransformElement.prototype = {
  7011. initTransform: function () {
  7012. var mat = new Matrix();
  7013. this.finalTransform = {
  7014. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : { o: 0 },
  7015. _matMdf: false,
  7016. _localMatMdf: false,
  7017. _opMdf: false,
  7018. mat: mat,
  7019. localMat: mat,
  7020. localOpacity: 1,
  7021. };
  7022. if (this.data.ao) {
  7023. this.finalTransform.mProp.autoOriented = true;
  7024. }
  7025. // TODO: check TYPE 11: Guided elements
  7026. if (this.data.ty !== 11) {
  7027. // this.createElements();
  7028. }
  7029. },
  7030. renderTransform: function () {
  7031. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  7032. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  7033. if (this.hierarchy) {
  7034. var mat;
  7035. var finalMat = this.finalTransform.mat;
  7036. var i = 0;
  7037. var len = this.hierarchy.length;
  7038. // Checking if any of the transformation matrices in the hierarchy chain has changed.
  7039. if (!this.finalTransform._matMdf) {
  7040. while (i < len) {
  7041. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  7042. this.finalTransform._matMdf = true;
  7043. break;
  7044. }
  7045. i += 1;
  7046. }
  7047. }
  7048. if (this.finalTransform._matMdf) {
  7049. mat = this.finalTransform.mProp.v.props;
  7050. finalMat.cloneFromProps(mat);
  7051. for (i = 0; i < len; i += 1) {
  7052. finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
  7053. }
  7054. }
  7055. }
  7056. if (!this.localTransforms || this.finalTransform._matMdf) {
  7057. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7058. }
  7059. if (this.finalTransform._opMdf) {
  7060. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7061. }
  7062. },
  7063. renderLocalTransform: function () {
  7064. if (this.localTransforms) {
  7065. var i = 0;
  7066. var len = this.localTransforms.length;
  7067. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7068. if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) {
  7069. while (i < len) {
  7070. if (this.localTransforms[i]._mdf) {
  7071. this.finalTransform._localMatMdf = true;
  7072. }
  7073. if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
  7074. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7075. this.finalTransform._opMdf = true;
  7076. }
  7077. i += 1;
  7078. }
  7079. }
  7080. if (this.finalTransform._localMatMdf) {
  7081. var localMat = this.finalTransform.localMat;
  7082. this.localTransforms[0].matrix.clone(localMat);
  7083. for (i = 1; i < len; i += 1) {
  7084. var lmat = this.localTransforms[i].matrix;
  7085. localMat.multiply(lmat);
  7086. }
  7087. localMat.multiply(this.finalTransform.mat);
  7088. }
  7089. if (this.finalTransform._opMdf) {
  7090. var localOp = this.finalTransform.localOpacity;
  7091. for (i = 0; i < len; i += 1) {
  7092. localOp *= this.localTransforms[i].opacity * 0.01;
  7093. }
  7094. this.finalTransform.localOpacity = localOp;
  7095. }
  7096. }
  7097. },
  7098. searchEffectTransforms: function () {
  7099. if (this.renderableEffectsManager) {
  7100. var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  7101. if (transformEffects.length) {
  7102. this.localTransforms = [];
  7103. this.finalTransform.localMat = new Matrix();
  7104. var i = 0;
  7105. var len = transformEffects.length;
  7106. for (i = 0; i < len; i += 1) {
  7107. this.localTransforms.push(transformEffects[i]);
  7108. }
  7109. }
  7110. }
  7111. },
  7112. globalToLocal: function (pt) {
  7113. var transforms = [];
  7114. transforms.push(this.finalTransform);
  7115. var flag = true;
  7116. var comp = this.comp;
  7117. while (flag) {
  7118. if (comp.finalTransform) {
  7119. if (comp.data.hasMask) {
  7120. transforms.splice(0, 0, comp.finalTransform);
  7121. }
  7122. comp = comp.comp;
  7123. } else {
  7124. flag = false;
  7125. }
  7126. }
  7127. var i;
  7128. var len = transforms.length;
  7129. var ptNew;
  7130. for (i = 0; i < len; i += 1) {
  7131. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  7132. // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7133. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7134. }
  7135. return pt;
  7136. },
  7137. mHelper: new Matrix(),
  7138. };
  7139. function MaskElement(data, element, globalData) {
  7140. this.data = data;
  7141. this.element = element;
  7142. this.globalData = globalData;
  7143. this.storedData = [];
  7144. this.masksProperties = this.data.masksProperties || [];
  7145. this.maskElement = null;
  7146. var defs = this.globalData.defs;
  7147. var i;
  7148. var len = this.masksProperties ? this.masksProperties.length : 0;
  7149. this.viewData = createSizedArray(len);
  7150. this.solidPath = '';
  7151. var path;
  7152. var properties = this.masksProperties;
  7153. var count = 0;
  7154. var currentMasks = [];
  7155. var j;
  7156. var jLen;
  7157. var layerId = createElementID();
  7158. var rect;
  7159. var expansor;
  7160. var feMorph;
  7161. var x;
  7162. var maskType = 'clipPath';
  7163. var maskRef = 'clip-path';
  7164. for (i = 0; i < len; i += 1) {
  7165. if ((properties[i].mode !== 'a' && properties[i].mode !== 'n') || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7166. maskType = 'mask';
  7167. maskRef = 'mask';
  7168. }
  7169. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7170. rect = createNS('rect');
  7171. rect.setAttribute('fill', '#ffffff');
  7172. rect.setAttribute('width', this.element.comp.data.w || 0);
  7173. rect.setAttribute('height', this.element.comp.data.h || 0);
  7174. currentMasks.push(rect);
  7175. } else {
  7176. rect = null;
  7177. }
  7178. path = createNS('path');
  7179. if (properties[i].mode === 'n') {
  7180. // TODO move this to a factory or to a constructor
  7181. this.viewData[i] = {
  7182. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7183. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7184. elem: path,
  7185. lastPath: '',
  7186. };
  7187. defs.appendChild(path);
  7188. } else {
  7189. count += 1;
  7190. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7191. path.setAttribute('clip-rule', 'nonzero');
  7192. var filterID;
  7193. if (properties[i].x.k !== 0) {
  7194. maskType = 'mask';
  7195. maskRef = 'mask';
  7196. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7197. filterID = createElementID();
  7198. expansor = createNS('filter');
  7199. expansor.setAttribute('id', filterID);
  7200. feMorph = createNS('feMorphology');
  7201. feMorph.setAttribute('operator', 'erode');
  7202. feMorph.setAttribute('in', 'SourceGraphic');
  7203. feMorph.setAttribute('radius', '0');
  7204. expansor.appendChild(feMorph);
  7205. defs.appendChild(expansor);
  7206. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7207. } else {
  7208. feMorph = null;
  7209. x = null;
  7210. }
  7211. // TODO move this to a factory or to a constructor
  7212. this.storedData[i] = {
  7213. elem: path,
  7214. x: x,
  7215. expan: feMorph,
  7216. lastPath: '',
  7217. lastOperator: '',
  7218. filterId: filterID,
  7219. lastRadius: 0,
  7220. };
  7221. if (properties[i].mode === 'i') {
  7222. jLen = currentMasks.length;
  7223. var g = createNS('g');
  7224. for (j = 0; j < jLen; j += 1) {
  7225. g.appendChild(currentMasks[j]);
  7226. }
  7227. var mask = createNS('mask');
  7228. mask.setAttribute('mask-type', 'alpha');
  7229. mask.setAttribute('id', layerId + '_' + count);
  7230. mask.appendChild(path);
  7231. defs.appendChild(mask);
  7232. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7233. currentMasks.length = 0;
  7234. currentMasks.push(g);
  7235. } else {
  7236. currentMasks.push(path);
  7237. }
  7238. if (properties[i].inv && !this.solidPath) {
  7239. this.solidPath = this.createLayerSolidPath();
  7240. }
  7241. // TODO move this to a factory or to a constructor
  7242. this.viewData[i] = {
  7243. elem: path,
  7244. lastPath: '',
  7245. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7246. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7247. invRect: rect,
  7248. };
  7249. if (!this.viewData[i].prop.k) {
  7250. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7251. }
  7252. }
  7253. }
  7254. this.maskElement = createNS(maskType);
  7255. len = currentMasks.length;
  7256. for (i = 0; i < len; i += 1) {
  7257. this.maskElement.appendChild(currentMasks[i]);
  7258. }
  7259. if (count > 0) {
  7260. this.maskElement.setAttribute('id', layerId);
  7261. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7262. defs.appendChild(this.maskElement);
  7263. }
  7264. if (this.viewData.length) {
  7265. this.element.addRenderableComponent(this);
  7266. }
  7267. }
  7268. MaskElement.prototype.getMaskProperty = function (pos) {
  7269. return this.viewData[pos].prop;
  7270. };
  7271. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7272. var finalMat = this.element.finalTransform.mat;
  7273. var i;
  7274. var len = this.masksProperties.length;
  7275. for (i = 0; i < len; i += 1) {
  7276. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7277. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7278. }
  7279. if (this.viewData[i].op._mdf || isFirstFrame) {
  7280. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7281. }
  7282. if (this.masksProperties[i].mode !== 'n') {
  7283. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7284. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7285. }
  7286. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7287. var feMorph = this.storedData[i].expan;
  7288. if (this.storedData[i].x.v < 0) {
  7289. if (this.storedData[i].lastOperator !== 'erode') {
  7290. this.storedData[i].lastOperator = 'erode';
  7291. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7292. }
  7293. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7294. } else {
  7295. if (this.storedData[i].lastOperator !== 'dilate') {
  7296. this.storedData[i].lastOperator = 'dilate';
  7297. this.storedData[i].elem.setAttribute('filter', null);
  7298. }
  7299. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7300. }
  7301. }
  7302. }
  7303. }
  7304. };
  7305. MaskElement.prototype.getMaskelement = function () {
  7306. return this.maskElement;
  7307. };
  7308. MaskElement.prototype.createLayerSolidPath = function () {
  7309. var path = 'M0,0 ';
  7310. path += ' h' + this.globalData.compSize.w;
  7311. path += ' v' + this.globalData.compSize.h;
  7312. path += ' h-' + this.globalData.compSize.w;
  7313. path += ' v-' + this.globalData.compSize.h + ' ';
  7314. return path;
  7315. };
  7316. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7317. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7318. var i;
  7319. var len;
  7320. len = pathNodes._length;
  7321. for (i = 1; i < len; i += 1) {
  7322. // pathString += " C"+pathNodes.o[i-1][0]+','+pathNodes.o[i-1][1] + " "+pathNodes.i[i][0]+','+pathNodes.i[i][1] + " "+pathNodes.v[i][0]+','+pathNodes.v[i][1];
  7323. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[i][0] + ',' + pathNodes.i[i][1] + ' ' + pathNodes.v[i][0] + ',' + pathNodes.v[i][1];
  7324. }
  7325. // pathString += " C"+pathNodes.o[i-1][0]+','+pathNodes.o[i-1][1] + " "+pathNodes.i[0][0]+','+pathNodes.i[0][1] + " "+pathNodes.v[0][0]+','+pathNodes.v[0][1];
  7326. if (pathNodes.c && len > 1) {
  7327. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[0][0] + ',' + pathNodes.i[0][1] + ' ' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7328. }
  7329. // pathNodes.__renderedString = pathString;
  7330. if (viewData.lastPath !== pathString) {
  7331. var pathShapeValue = '';
  7332. if (viewData.elem) {
  7333. if (pathNodes.c) {
  7334. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7335. }
  7336. viewData.elem.setAttribute('d', pathShapeValue);
  7337. }
  7338. viewData.lastPath = pathString;
  7339. }
  7340. };
  7341. MaskElement.prototype.destroy = function () {
  7342. this.element = null;
  7343. this.globalData = null;
  7344. this.maskElement = null;
  7345. this.data = null;
  7346. this.masksProperties = null;
  7347. };
  7348. const filtersFactory = (function () {
  7349. var ob = {};
  7350. ob.createFilter = createFilter;
  7351. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7352. function createFilter(filId, skipCoordinates) {
  7353. var fil = createNS('filter');
  7354. fil.setAttribute('id', filId);
  7355. if (skipCoordinates !== true) {
  7356. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7357. fil.setAttribute('x', '0%');
  7358. fil.setAttribute('y', '0%');
  7359. fil.setAttribute('width', '100%');
  7360. fil.setAttribute('height', '100%');
  7361. }
  7362. return fil;
  7363. }
  7364. function createAlphaToLuminanceFilter() {
  7365. var feColorMatrix = createNS('feColorMatrix');
  7366. feColorMatrix.setAttribute('type', 'matrix');
  7367. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7368. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7369. return feColorMatrix;
  7370. }
  7371. return ob;
  7372. }());
  7373. const featureSupport = (function () {
  7374. var ob = {
  7375. maskType: true,
  7376. svgLumaHidden: true,
  7377. offscreenCanvas: typeof OffscreenCanvas !== 'undefined',
  7378. };
  7379. if (/MSIE 10/i.test(navigator.userAgent) || /MSIE 9/i.test(navigator.userAgent) || /rv:11.0/i.test(navigator.userAgent) || /Edge\/\d./i.test(navigator.userAgent)) {
  7380. ob.maskType = false;
  7381. }
  7382. if (/firefox/i.test(navigator.userAgent)) {
  7383. ob.svgLumaHidden = false;
  7384. }
  7385. return ob;
  7386. }());
  7387. var registeredEffects$1 = {};
  7388. var idPrefix = 'filter_result_';
  7389. function SVGEffects(elem) {
  7390. var i;
  7391. var source = 'SourceGraphic';
  7392. var len = elem.data.ef ? elem.data.ef.length : 0;
  7393. var filId = createElementID();
  7394. var fil = filtersFactory.createFilter(filId, true);
  7395. var count = 0;
  7396. this.filters = [];
  7397. var filterManager;
  7398. for (i = 0; i < len; i += 1) {
  7399. filterManager = null;
  7400. var type = elem.data.ef[i].ty;
  7401. if (registeredEffects$1[type]) {
  7402. var Effect = registeredEffects$1[type].effect;
  7403. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7404. source = idPrefix + count;
  7405. if (registeredEffects$1[type].countsAsEffect) {
  7406. count += 1;
  7407. }
  7408. }
  7409. if (filterManager) {
  7410. this.filters.push(filterManager);
  7411. }
  7412. }
  7413. if (count) {
  7414. elem.globalData.defs.appendChild(fil);
  7415. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7416. }
  7417. if (this.filters.length) {
  7418. elem.addRenderableComponent(this);
  7419. }
  7420. }
  7421. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7422. var i;
  7423. var len = this.filters.length;
  7424. for (i = 0; i < len; i += 1) {
  7425. this.filters[i].renderFrame(_isFirstFrame);
  7426. }
  7427. };
  7428. SVGEffects.prototype.getEffects = function (type) {
  7429. var i;
  7430. var len = this.filters.length;
  7431. var effects = [];
  7432. for (i = 0; i < len; i += 1) {
  7433. if (this.filters[i].type === type) {
  7434. effects.push(this.filters[i]);
  7435. }
  7436. }
  7437. return effects;
  7438. };
  7439. function registerEffect$1(id, effect, countsAsEffect) {
  7440. registeredEffects$1[id] = {
  7441. effect,
  7442. countsAsEffect,
  7443. };
  7444. }
  7445. function SVGBaseElement() {
  7446. }
  7447. SVGBaseElement.prototype = {
  7448. initRendererElement: function () {
  7449. this.layerElement = createNS('g');
  7450. },
  7451. createContainerElements: function () {
  7452. this.matteElement = createNS('g');
  7453. this.transformedElement = this.layerElement;
  7454. this.maskedElement = this.layerElement;
  7455. this._sizeChanged = false;
  7456. var layerElementParent = null;
  7457. // If this layer acts as a mask for the following layer
  7458. if (this.data.td) {
  7459. this.matteMasks = {};
  7460. var gg = createNS('g');
  7461. gg.setAttribute('id', this.layerId);
  7462. gg.appendChild(this.layerElement);
  7463. layerElementParent = gg;
  7464. this.globalData.defs.appendChild(gg);
  7465. } else if (this.data.tt) {
  7466. this.matteElement.appendChild(this.layerElement);
  7467. layerElementParent = this.matteElement;
  7468. this.baseElement = this.matteElement;
  7469. } else {
  7470. this.baseElement = this.layerElement;
  7471. }
  7472. if (this.data.ln) {
  7473. this.layerElement.setAttribute('id', this.data.ln);
  7474. }
  7475. if (this.data.cl) {
  7476. this.layerElement.setAttribute('class', this.data.cl);
  7477. }
  7478. // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7479. if (this.data.ty === 0 && !this.data.hd) {
  7480. var cp = createNS('clipPath');
  7481. var pt = createNS('path');
  7482. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7483. var clipId = createElementID();
  7484. cp.setAttribute('id', clipId);
  7485. cp.appendChild(pt);
  7486. this.globalData.defs.appendChild(cp);
  7487. if (this.checkMasks()) {
  7488. var cpGroup = createNS('g');
  7489. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7490. cpGroup.appendChild(this.layerElement);
  7491. this.transformedElement = cpGroup;
  7492. if (layerElementParent) {
  7493. layerElementParent.appendChild(this.transformedElement);
  7494. } else {
  7495. this.baseElement = this.transformedElement;
  7496. }
  7497. } else {
  7498. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7499. }
  7500. }
  7501. if (this.data.bm !== 0) {
  7502. this.setBlendMode();
  7503. }
  7504. },
  7505. renderElement: function () {
  7506. if (this.finalTransform._localMatMdf) {
  7507. this.transformedElement.setAttribute('transform', this.finalTransform.localMat.to2dCSS());
  7508. }
  7509. if (this.finalTransform._opMdf) {
  7510. this.transformedElement.setAttribute('opacity', this.finalTransform.localOpacity);
  7511. }
  7512. },
  7513. destroyBaseElement: function () {
  7514. this.layerElement = null;
  7515. this.matteElement = null;
  7516. this.maskManager.destroy();
  7517. },
  7518. getBaseElement: function () {
  7519. if (this.data.hd) {
  7520. return null;
  7521. }
  7522. return this.baseElement;
  7523. },
  7524. createRenderableComponents: function () {
  7525. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7526. this.renderableEffectsManager = new SVGEffects(this);
  7527. this.searchEffectTransforms();
  7528. },
  7529. getMatte: function (matteType) {
  7530. // This should not be a common case. But for backward compatibility, we'll create the matte object.
  7531. // It solves animations that have two consecutive layers marked as matte masks.
  7532. // Which is an undefined behavior in AE.
  7533. if (!this.matteMasks) {
  7534. this.matteMasks = {};
  7535. }
  7536. if (!this.matteMasks[matteType]) {
  7537. var id = this.layerId + '_' + matteType;
  7538. var filId;
  7539. var fil;
  7540. var useElement;
  7541. var gg;
  7542. if (matteType === 1 || matteType === 3) {
  7543. var masker = createNS('mask');
  7544. masker.setAttribute('id', id);
  7545. masker.setAttribute('mask-type', matteType === 3 ? 'luminance' : 'alpha');
  7546. useElement = createNS('use');
  7547. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7548. masker.appendChild(useElement);
  7549. this.globalData.defs.appendChild(masker);
  7550. if (!featureSupport.maskType && matteType === 1) {
  7551. masker.setAttribute('mask-type', 'luminance');
  7552. filId = createElementID();
  7553. fil = filtersFactory.createFilter(filId);
  7554. this.globalData.defs.appendChild(fil);
  7555. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7556. gg = createNS('g');
  7557. gg.appendChild(useElement);
  7558. masker.appendChild(gg);
  7559. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7560. }
  7561. } else if (matteType === 2) {
  7562. var maskGroup = createNS('mask');
  7563. maskGroup.setAttribute('id', id);
  7564. maskGroup.setAttribute('mask-type', 'alpha');
  7565. var maskGrouper = createNS('g');
  7566. maskGroup.appendChild(maskGrouper);
  7567. filId = createElementID();
  7568. fil = filtersFactory.createFilter(filId);
  7569. /// /
  7570. var feCTr = createNS('feComponentTransfer');
  7571. feCTr.setAttribute('in', 'SourceGraphic');
  7572. fil.appendChild(feCTr);
  7573. var feFunc = createNS('feFuncA');
  7574. feFunc.setAttribute('type', 'table');
  7575. feFunc.setAttribute('tableValues', '1.0 0.0');
  7576. feCTr.appendChild(feFunc);
  7577. /// /
  7578. this.globalData.defs.appendChild(fil);
  7579. var alphaRect = createNS('rect');
  7580. alphaRect.setAttribute('width', this.comp.data.w);
  7581. alphaRect.setAttribute('height', this.comp.data.h);
  7582. alphaRect.setAttribute('x', '0');
  7583. alphaRect.setAttribute('y', '0');
  7584. alphaRect.setAttribute('fill', '#ffffff');
  7585. alphaRect.setAttribute('opacity', '0');
  7586. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7587. maskGrouper.appendChild(alphaRect);
  7588. useElement = createNS('use');
  7589. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7590. maskGrouper.appendChild(useElement);
  7591. if (!featureSupport.maskType) {
  7592. maskGroup.setAttribute('mask-type', 'luminance');
  7593. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7594. gg = createNS('g');
  7595. maskGrouper.appendChild(alphaRect);
  7596. gg.appendChild(this.layerElement);
  7597. maskGrouper.appendChild(gg);
  7598. }
  7599. this.globalData.defs.appendChild(maskGroup);
  7600. }
  7601. this.matteMasks[matteType] = id;
  7602. }
  7603. return this.matteMasks[matteType];
  7604. },
  7605. setMatte: function (id) {
  7606. if (!this.matteElement) {
  7607. return;
  7608. }
  7609. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7610. },
  7611. };
  7612. /**
  7613. * @file
  7614. * Handles AE's layer parenting property.
  7615. *
  7616. */
  7617. function HierarchyElement() {}
  7618. HierarchyElement.prototype = {
  7619. /**
  7620. * @function
  7621. * Initializes hierarchy properties
  7622. *
  7623. */
  7624. initHierarchy: function () {
  7625. // element's parent list
  7626. this.hierarchy = [];
  7627. // if element is parent of another layer _isParent will be true
  7628. this._isParent = false;
  7629. this.checkParenting();
  7630. },
  7631. /**
  7632. * @function
  7633. * Sets layer's hierarchy.
  7634. * @param {array} hierarch
  7635. * layer's parent list
  7636. *
  7637. */
  7638. setHierarchy: function (hierarchy) {
  7639. this.hierarchy = hierarchy;
  7640. },
  7641. /**
  7642. * @function
  7643. * Sets layer as parent.
  7644. *
  7645. */
  7646. setAsParent: function () {
  7647. this._isParent = true;
  7648. },
  7649. /**
  7650. * @function
  7651. * Searches layer's parenting chain
  7652. *
  7653. */
  7654. checkParenting: function () {
  7655. if (this.data.parent !== undefined) {
  7656. this.comp.buildElementParenting(this, this.data.parent, []);
  7657. }
  7658. },
  7659. };
  7660. function RenderableDOMElement() {}
  7661. (function () {
  7662. var _prototype = {
  7663. initElement: function (data, globalData, comp) {
  7664. this.initFrame();
  7665. this.initBaseData(data, globalData, comp);
  7666. this.initTransform(data, globalData, comp);
  7667. this.initHierarchy();
  7668. this.initRenderable();
  7669. this.initRendererElement();
  7670. this.createContainerElements();
  7671. this.createRenderableComponents();
  7672. this.createContent();
  7673. this.hide();
  7674. },
  7675. hide: function () {
  7676. // console.log('HIDE', this);
  7677. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7678. var elem = this.baseElement || this.layerElement;
  7679. elem.style.display = 'none';
  7680. this.hidden = true;
  7681. }
  7682. },
  7683. show: function () {
  7684. // console.log('SHOW', this);
  7685. if (this.isInRange && !this.isTransparent) {
  7686. if (!this.data.hd) {
  7687. var elem = this.baseElement || this.layerElement;
  7688. elem.style.display = 'block';
  7689. }
  7690. this.hidden = false;
  7691. this._isFirstFrame = true;
  7692. }
  7693. },
  7694. renderFrame: function () {
  7695. // If it is exported as hidden (data.hd === true) no need to render
  7696. // If it is not visible no need to render
  7697. if (this.data.hd || this.hidden) {
  7698. return;
  7699. }
  7700. this.renderTransform();
  7701. this.renderRenderable();
  7702. this.renderLocalTransform();
  7703. this.renderElement();
  7704. this.renderInnerContent();
  7705. if (this._isFirstFrame) {
  7706. this._isFirstFrame = false;
  7707. }
  7708. },
  7709. renderInnerContent: function () {},
  7710. prepareFrame: function (num) {
  7711. this._mdf = false;
  7712. this.prepareRenderableFrame(num);
  7713. this.prepareProperties(num, this.isInRange);
  7714. this.checkTransparency();
  7715. },
  7716. destroy: function () {
  7717. this.innerElem = null;
  7718. this.destroyBaseElement();
  7719. },
  7720. };
  7721. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  7722. }());
  7723. function IImageElement(data, globalData, comp) {
  7724. this.assetData = globalData.getAssetData(data.refId);
  7725. if (this.assetData && this.assetData.sid) {
  7726. this.assetData = globalData.slotManager.getProp(this.assetData);
  7727. }
  7728. this.initElement(data, globalData, comp);
  7729. this.sourceRect = {
  7730. top: 0, left: 0, width: this.assetData.w, height: this.assetData.h,
  7731. };
  7732. }
  7733. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  7734. IImageElement.prototype.createContent = function () {
  7735. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7736. this.innerElem = createNS('image');
  7737. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  7738. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  7739. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7740. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  7741. this.layerElement.appendChild(this.innerElem);
  7742. };
  7743. IImageElement.prototype.sourceRectAtTime = function () {
  7744. return this.sourceRect;
  7745. };
  7746. function ProcessedElement(element, position) {
  7747. this.elem = element;
  7748. this.pos = position;
  7749. }
  7750. function IShapeElement() {
  7751. }
  7752. IShapeElement.prototype = {
  7753. addShapeToModifiers: function (data) {
  7754. var i;
  7755. var len = this.shapeModifiers.length;
  7756. for (i = 0; i < len; i += 1) {
  7757. this.shapeModifiers[i].addShape(data);
  7758. }
  7759. },
  7760. isShapeInAnimatedModifiers: function (data) {
  7761. var i = 0;
  7762. var len = this.shapeModifiers.length;
  7763. while (i < len) {
  7764. if (this.shapeModifiers[i].isAnimatedWithShape(data)) {
  7765. return true;
  7766. }
  7767. }
  7768. return false;
  7769. },
  7770. renderModifiers: function () {
  7771. if (!this.shapeModifiers.length) {
  7772. return;
  7773. }
  7774. var i;
  7775. var len = this.shapes.length;
  7776. for (i = 0; i < len; i += 1) {
  7777. this.shapes[i].sh.reset();
  7778. }
  7779. len = this.shapeModifiers.length;
  7780. var shouldBreakProcess;
  7781. for (i = len - 1; i >= 0; i -= 1) {
  7782. shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame);
  7783. // workaround to fix cases where a repeater resets the shape so the following processes get called twice
  7784. // TODO: find a better solution for this
  7785. if (shouldBreakProcess) {
  7786. break;
  7787. }
  7788. }
  7789. },
  7790. searchProcessedElement: function (elem) {
  7791. var elements = this.processedElements;
  7792. var i = 0;
  7793. var len = elements.length;
  7794. while (i < len) {
  7795. if (elements[i].elem === elem) {
  7796. return elements[i].pos;
  7797. }
  7798. i += 1;
  7799. }
  7800. return 0;
  7801. },
  7802. addProcessedElement: function (elem, pos) {
  7803. var elements = this.processedElements;
  7804. var i = elements.length;
  7805. while (i) {
  7806. i -= 1;
  7807. if (elements[i].elem === elem) {
  7808. elements[i].pos = pos;
  7809. return;
  7810. }
  7811. }
  7812. elements.push(new ProcessedElement(elem, pos));
  7813. },
  7814. prepareFrame: function (num) {
  7815. this.prepareRenderableFrame(num);
  7816. this.prepareProperties(num, this.isInRange);
  7817. },
  7818. };
  7819. const lineCapEnum = {
  7820. 1: 'butt',
  7821. 2: 'round',
  7822. 3: 'square',
  7823. };
  7824. const lineJoinEnum = {
  7825. 1: 'miter',
  7826. 2: 'round',
  7827. 3: 'bevel',
  7828. };
  7829. function SVGShapeData(transformers, level, shape) {
  7830. this.caches = [];
  7831. this.styles = [];
  7832. this.transformers = transformers;
  7833. this.lStr = '';
  7834. this.sh = shape;
  7835. this.lvl = level;
  7836. // TODO find if there are some cases where _isAnimated can be false.
  7837. // For now, since shapes add up with other shapes. They have to be calculated every time.
  7838. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  7839. this._isAnimated = !!shape.k;
  7840. // TODO: commenting this for now since all shapes are animated
  7841. var i = 0;
  7842. var len = transformers.length;
  7843. while (i < len) {
  7844. if (transformers[i].mProps.dynamicProperties.length) {
  7845. this._isAnimated = true;
  7846. break;
  7847. }
  7848. i += 1;
  7849. }
  7850. }
  7851. SVGShapeData.prototype.setAsAnimated = function () {
  7852. this._isAnimated = true;
  7853. };
  7854. function SVGStyleData(data, level) {
  7855. this.data = data;
  7856. this.type = data.ty;
  7857. this.d = '';
  7858. this.lvl = level;
  7859. this._mdf = false;
  7860. this.closed = data.hd === true;
  7861. this.pElem = createNS('path');
  7862. this.msElem = null;
  7863. }
  7864. SVGStyleData.prototype.reset = function () {
  7865. this.d = '';
  7866. this._mdf = false;
  7867. };
  7868. function DashProperty(elem, data, renderer, container) {
  7869. this.elem = elem;
  7870. this.frameId = -1;
  7871. this.dataProps = createSizedArray(data.length);
  7872. this.renderer = renderer;
  7873. this.k = false;
  7874. this.dashStr = '';
  7875. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  7876. this.dashoffset = createTypedArray('float32', 1);
  7877. this.initDynamicPropertyContainer(container);
  7878. var i;
  7879. var len = data.length || 0;
  7880. var prop;
  7881. for (i = 0; i < len; i += 1) {
  7882. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  7883. this.k = prop.k || this.k;
  7884. this.dataProps[i] = { n: data[i].n, p: prop };
  7885. }
  7886. if (!this.k) {
  7887. this.getValue(true);
  7888. }
  7889. this._isAnimated = this.k;
  7890. }
  7891. DashProperty.prototype.getValue = function (forceRender) {
  7892. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  7893. return;
  7894. }
  7895. this.frameId = this.elem.globalData.frameId;
  7896. this.iterateDynamicProperties();
  7897. this._mdf = this._mdf || forceRender;
  7898. if (this._mdf) {
  7899. var i = 0;
  7900. var len = this.dataProps.length;
  7901. if (this.renderer === 'svg') {
  7902. this.dashStr = '';
  7903. }
  7904. for (i = 0; i < len; i += 1) {
  7905. if (this.dataProps[i].n !== 'o') {
  7906. if (this.renderer === 'svg') {
  7907. this.dashStr += ' ' + this.dataProps[i].p.v;
  7908. } else {
  7909. this.dashArray[i] = this.dataProps[i].p.v;
  7910. }
  7911. } else {
  7912. this.dashoffset[0] = this.dataProps[i].p.v;
  7913. }
  7914. }
  7915. }
  7916. };
  7917. extendPrototype([DynamicPropertyContainer], DashProperty);
  7918. function SVGStrokeStyleData(elem, data, styleOb) {
  7919. this.initDynamicPropertyContainer(elem);
  7920. this.getValue = this.iterateDynamicProperties;
  7921. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7922. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  7923. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  7924. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7925. this.style = styleOb;
  7926. this._isAnimated = !!this._isAnimated;
  7927. }
  7928. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  7929. function SVGFillStyleData(elem, data, styleOb) {
  7930. this.initDynamicPropertyContainer(elem);
  7931. this.getValue = this.iterateDynamicProperties;
  7932. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7933. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7934. this.style = styleOb;
  7935. }
  7936. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  7937. function SVGNoStyleData(elem, data, styleOb) {
  7938. this.initDynamicPropertyContainer(elem);
  7939. this.getValue = this.iterateDynamicProperties;
  7940. this.style = styleOb;
  7941. }
  7942. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  7943. function GradientProperty(elem, data, container) {
  7944. this.data = data;
  7945. this.c = createTypedArray('uint8c', data.p * 4);
  7946. var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p * 4) : data.k.k.length - data.p * 4;
  7947. this.o = createTypedArray('float32', cLength);
  7948. this._cmdf = false;
  7949. this._omdf = false;
  7950. this._collapsable = this.checkCollapsable();
  7951. this._hasOpacity = cLength;
  7952. this.initDynamicPropertyContainer(container);
  7953. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  7954. this.k = this.prop.k;
  7955. this.getValue(true);
  7956. }
  7957. GradientProperty.prototype.comparePoints = function (values, points) {
  7958. var i = 0;
  7959. var len = this.o.length / 2;
  7960. var diff;
  7961. while (i < len) {
  7962. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  7963. if (diff > 0.01) {
  7964. return false;
  7965. }
  7966. i += 1;
  7967. }
  7968. return true;
  7969. };
  7970. GradientProperty.prototype.checkCollapsable = function () {
  7971. if (this.o.length / 2 !== this.c.length / 4) {
  7972. return false;
  7973. }
  7974. if (this.data.k.k[0].s) {
  7975. var i = 0;
  7976. var len = this.data.k.k.length;
  7977. while (i < len) {
  7978. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  7979. return false;
  7980. }
  7981. i += 1;
  7982. }
  7983. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  7984. return false;
  7985. }
  7986. return true;
  7987. };
  7988. GradientProperty.prototype.getValue = function (forceRender) {
  7989. this.prop.getValue();
  7990. this._mdf = false;
  7991. this._cmdf = false;
  7992. this._omdf = false;
  7993. if (this.prop._mdf || forceRender) {
  7994. var i;
  7995. var len = this.data.p * 4;
  7996. var mult;
  7997. var val;
  7998. for (i = 0; i < len; i += 1) {
  7999. mult = i % 4 === 0 ? 100 : 255;
  8000. val = Math.round(this.prop.v[i] * mult);
  8001. if (this.c[i] !== val) {
  8002. this.c[i] = val;
  8003. this._cmdf = !forceRender;
  8004. }
  8005. }
  8006. if (this.o.length) {
  8007. len = this.prop.v.length;
  8008. for (i = this.data.p * 4; i < len; i += 1) {
  8009. mult = i % 2 === 0 ? 100 : 1;
  8010. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  8011. if (this.o[i - this.data.p * 4] !== val) {
  8012. this.o[i - this.data.p * 4] = val;
  8013. this._omdf = !forceRender;
  8014. }
  8015. }
  8016. }
  8017. this._mdf = !forceRender;
  8018. }
  8019. };
  8020. extendPrototype([DynamicPropertyContainer], GradientProperty);
  8021. function SVGGradientFillStyleData(elem, data, styleOb) {
  8022. this.initDynamicPropertyContainer(elem);
  8023. this.getValue = this.iterateDynamicProperties;
  8024. this.initGradientData(elem, data, styleOb);
  8025. }
  8026. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  8027. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8028. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  8029. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  8030. this.h = PropertyFactory.getProp(elem, data.h || { k: 0 }, 0, 0.01, this);
  8031. this.a = PropertyFactory.getProp(elem, data.a || { k: 0 }, 0, degToRads, this);
  8032. this.g = new GradientProperty(elem, data.g, this);
  8033. this.style = styleOb;
  8034. this.stops = [];
  8035. this.setGradientData(styleOb.pElem, data);
  8036. this.setGradientOpacity(data, styleOb);
  8037. this._isAnimated = !!this._isAnimated;
  8038. };
  8039. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  8040. var gradientId = createElementID();
  8041. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8042. gfill.setAttribute('id', gradientId);
  8043. gfill.setAttribute('spreadMethod', 'pad');
  8044. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8045. var stops = [];
  8046. var stop;
  8047. var j;
  8048. var jLen;
  8049. jLen = data.g.p * 4;
  8050. for (j = 0; j < jLen; j += 4) {
  8051. stop = createNS('stop');
  8052. gfill.appendChild(stop);
  8053. stops.push(stop);
  8054. }
  8055. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  8056. this.gf = gfill;
  8057. this.cst = stops;
  8058. };
  8059. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  8060. if (this.g._hasOpacity && !this.g._collapsable) {
  8061. var stop;
  8062. var j;
  8063. var jLen;
  8064. var mask = createNS('mask');
  8065. var maskElement = createNS('path');
  8066. mask.appendChild(maskElement);
  8067. var opacityId = createElementID();
  8068. var maskId = createElementID();
  8069. mask.setAttribute('id', maskId);
  8070. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8071. opFill.setAttribute('id', opacityId);
  8072. opFill.setAttribute('spreadMethod', 'pad');
  8073. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8074. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8075. var stops = this.stops;
  8076. for (j = data.g.p * 4; j < jLen; j += 2) {
  8077. stop = createNS('stop');
  8078. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8079. opFill.appendChild(stop);
  8080. stops.push(stop);
  8081. }
  8082. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8083. if (data.ty === 'gs') {
  8084. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8085. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8086. if (data.lj === 1) {
  8087. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8088. }
  8089. }
  8090. this.of = opFill;
  8091. this.ms = mask;
  8092. this.ost = stops;
  8093. this.maskId = maskId;
  8094. styleOb.msElem = maskElement;
  8095. }
  8096. };
  8097. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8098. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8099. this.initDynamicPropertyContainer(elem);
  8100. this.getValue = this.iterateDynamicProperties;
  8101. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8102. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8103. this.initGradientData(elem, data, styleOb);
  8104. this._isAnimated = !!this._isAnimated;
  8105. }
  8106. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8107. function ShapeGroupData() {
  8108. this.it = [];
  8109. this.prevViewData = [];
  8110. this.gr = createNS('g');
  8111. }
  8112. function SVGTransformData(mProps, op, container) {
  8113. this.transform = {
  8114. mProps: mProps,
  8115. op: op,
  8116. container: container,
  8117. };
  8118. this.elements = [];
  8119. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8120. }
  8121. const buildShapeString = function (pathNodes, length, closed, mat) {
  8122. if (length === 0) {
  8123. return '';
  8124. }
  8125. var _o = pathNodes.o;
  8126. var _i = pathNodes.i;
  8127. var _v = pathNodes.v;
  8128. var i;
  8129. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8130. for (i = 1; i < length; i += 1) {
  8131. shapeString += ' C' + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + ' ' + mat.applyToPointStringified(_i[i][0], _i[i][1]) + ' ' + mat.applyToPointStringified(_v[i][0], _v[i][1]);
  8132. }
  8133. if (closed && length) {
  8134. shapeString += ' C' + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + ' ' + mat.applyToPointStringified(_i[0][0], _i[0][1]) + ' ' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8135. shapeString += 'z';
  8136. }
  8137. return shapeString;
  8138. };
  8139. const SVGElementsRenderer = (function () {
  8140. var _identityMatrix = new Matrix();
  8141. var _matrixHelper = new Matrix();
  8142. var ob = {
  8143. createRenderFunction: createRenderFunction,
  8144. };
  8145. function createRenderFunction(data) {
  8146. switch (data.ty) {
  8147. case 'fl':
  8148. return renderFill;
  8149. case 'gf':
  8150. return renderGradient;
  8151. case 'gs':
  8152. return renderGradientStroke;
  8153. case 'st':
  8154. return renderStroke;
  8155. case 'sh':
  8156. case 'el':
  8157. case 'rc':
  8158. case 'sr':
  8159. return renderPath;
  8160. case 'tr':
  8161. return renderContentTransform;
  8162. case 'no':
  8163. return renderNoop;
  8164. default:
  8165. return null;
  8166. }
  8167. }
  8168. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8169. if (isFirstFrame || itemData.transform.op._mdf) {
  8170. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8171. }
  8172. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8173. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8174. }
  8175. }
  8176. function renderNoop() {
  8177. }
  8178. function renderPath(styleData, itemData, isFirstFrame) {
  8179. var j;
  8180. var jLen;
  8181. var pathStringTransformed;
  8182. var redraw;
  8183. var pathNodes;
  8184. var l;
  8185. var lLen = itemData.styles.length;
  8186. var lvl = itemData.lvl;
  8187. var paths;
  8188. var mat;
  8189. var iterations;
  8190. var k;
  8191. for (l = 0; l < lLen; l += 1) {
  8192. redraw = itemData.sh._mdf || isFirstFrame;
  8193. if (itemData.styles[l].lvl < lvl) {
  8194. mat = _matrixHelper.reset();
  8195. iterations = lvl - itemData.styles[l].lvl;
  8196. k = itemData.transformers.length - 1;
  8197. while (!redraw && iterations > 0) {
  8198. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8199. iterations -= 1;
  8200. k -= 1;
  8201. }
  8202. if (redraw) {
  8203. iterations = lvl - itemData.styles[l].lvl;
  8204. k = itemData.transformers.length - 1;
  8205. while (iterations > 0) {
  8206. mat.multiply(itemData.transformers[k].mProps.v);
  8207. iterations -= 1;
  8208. k -= 1;
  8209. }
  8210. }
  8211. } else {
  8212. mat = _identityMatrix;
  8213. }
  8214. paths = itemData.sh.paths;
  8215. jLen = paths._length;
  8216. if (redraw) {
  8217. pathStringTransformed = '';
  8218. for (j = 0; j < jLen; j += 1) {
  8219. pathNodes = paths.shapes[j];
  8220. if (pathNodes && pathNodes._length) {
  8221. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8222. }
  8223. }
  8224. itemData.caches[l] = pathStringTransformed;
  8225. } else {
  8226. pathStringTransformed = itemData.caches[l];
  8227. }
  8228. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8229. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8230. }
  8231. }
  8232. function renderFill(styleData, itemData, isFirstFrame) {
  8233. var styleElem = itemData.style;
  8234. if (itemData.c._mdf || isFirstFrame) {
  8235. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8236. }
  8237. if (itemData.o._mdf || isFirstFrame) {
  8238. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8239. }
  8240. }
  8241. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8242. renderGradient(styleData, itemData, isFirstFrame);
  8243. renderStroke(styleData, itemData, isFirstFrame);
  8244. }
  8245. function renderGradient(styleData, itemData, isFirstFrame) {
  8246. var gfill = itemData.gf;
  8247. var hasOpacity = itemData.g._hasOpacity;
  8248. var pt1 = itemData.s.v;
  8249. var pt2 = itemData.e.v;
  8250. if (itemData.o._mdf || isFirstFrame) {
  8251. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8252. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8253. }
  8254. if (itemData.s._mdf || isFirstFrame) {
  8255. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8256. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8257. gfill.setAttribute(attr1, pt1[0]);
  8258. gfill.setAttribute(attr2, pt1[1]);
  8259. if (hasOpacity && !itemData.g._collapsable) {
  8260. itemData.of.setAttribute(attr1, pt1[0]);
  8261. itemData.of.setAttribute(attr2, pt1[1]);
  8262. }
  8263. }
  8264. var stops;
  8265. var i;
  8266. var len;
  8267. var stop;
  8268. if (itemData.g._cmdf || isFirstFrame) {
  8269. stops = itemData.cst;
  8270. var cValues = itemData.g.c;
  8271. len = stops.length;
  8272. for (i = 0; i < len; i += 1) {
  8273. stop = stops[i];
  8274. stop.setAttribute('offset', cValues[i * 4] + '%');
  8275. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8276. }
  8277. }
  8278. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8279. var oValues = itemData.g.o;
  8280. if (itemData.g._collapsable) {
  8281. stops = itemData.cst;
  8282. } else {
  8283. stops = itemData.ost;
  8284. }
  8285. len = stops.length;
  8286. for (i = 0; i < len; i += 1) {
  8287. stop = stops[i];
  8288. if (!itemData.g._collapsable) {
  8289. stop.setAttribute('offset', oValues[i * 2] + '%');
  8290. }
  8291. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8292. }
  8293. }
  8294. if (styleData.t === 1) {
  8295. if (itemData.e._mdf || isFirstFrame) {
  8296. gfill.setAttribute('x2', pt2[0]);
  8297. gfill.setAttribute('y2', pt2[1]);
  8298. if (hasOpacity && !itemData.g._collapsable) {
  8299. itemData.of.setAttribute('x2', pt2[0]);
  8300. itemData.of.setAttribute('y2', pt2[1]);
  8301. }
  8302. }
  8303. } else {
  8304. var rad;
  8305. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8306. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8307. gfill.setAttribute('r', rad);
  8308. if (hasOpacity && !itemData.g._collapsable) {
  8309. itemData.of.setAttribute('r', rad);
  8310. }
  8311. }
  8312. if (itemData.s._mdf || itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8313. if (!rad) {
  8314. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8315. }
  8316. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8317. var percent = itemData.h.v;
  8318. if (percent >= 1) {
  8319. percent = 0.99;
  8320. } else if (percent <= -1) {
  8321. percent = -0.99;
  8322. }
  8323. var dist = rad * percent;
  8324. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8325. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8326. gfill.setAttribute('fx', x);
  8327. gfill.setAttribute('fy', y);
  8328. if (hasOpacity && !itemData.g._collapsable) {
  8329. itemData.of.setAttribute('fx', x);
  8330. itemData.of.setAttribute('fy', y);
  8331. }
  8332. }
  8333. // gfill.setAttribute('fy','200');
  8334. }
  8335. }
  8336. function renderStroke(styleData, itemData, isFirstFrame) {
  8337. var styleElem = itemData.style;
  8338. var d = itemData.d;
  8339. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8340. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8341. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8342. }
  8343. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8344. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8345. }
  8346. if (itemData.o._mdf || isFirstFrame) {
  8347. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8348. }
  8349. if (itemData.w._mdf || isFirstFrame) {
  8350. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8351. if (styleElem.msElem) {
  8352. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8353. }
  8354. }
  8355. }
  8356. return ob;
  8357. }());
  8358. function SVGShapeElement(data, globalData, comp) {
  8359. // List of drawable elements
  8360. this.shapes = [];
  8361. // Full shape data
  8362. this.shapesData = data.shapes;
  8363. // List of styles that will be applied to shapes
  8364. this.stylesList = [];
  8365. // List of modifiers that will be applied to shapes
  8366. this.shapeModifiers = [];
  8367. // List of items in shape tree
  8368. this.itemsData = [];
  8369. // List of items in previous shape tree
  8370. this.processedElements = [];
  8371. // List of animated components
  8372. this.animatedContents = [];
  8373. this.initElement(data, globalData, comp);
  8374. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8375. // List of elements that have been created
  8376. this.prevViewData = [];
  8377. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8378. }
  8379. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8380. SVGShapeElement.prototype.initSecondaryElement = function () {
  8381. };
  8382. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8383. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8384. SVGShapeElement.prototype.createContent = function () {
  8385. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8386. this.filterUniqueShapes();
  8387. };
  8388. /*
  8389. This method searches for multiple shapes that affect a single element and one of them is animated
  8390. */
  8391. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8392. var i;
  8393. var len = this.shapes.length;
  8394. var shape;
  8395. var j;
  8396. var jLen = this.stylesList.length;
  8397. var style;
  8398. var tempShapes = [];
  8399. var areAnimated = false;
  8400. for (j = 0; j < jLen; j += 1) {
  8401. style = this.stylesList[j];
  8402. areAnimated = false;
  8403. tempShapes.length = 0;
  8404. for (i = 0; i < len; i += 1) {
  8405. shape = this.shapes[i];
  8406. if (shape.styles.indexOf(style) !== -1) {
  8407. tempShapes.push(shape);
  8408. areAnimated = shape._isAnimated || areAnimated;
  8409. }
  8410. }
  8411. if (tempShapes.length > 1 && areAnimated) {
  8412. this.setShapesAsAnimated(tempShapes);
  8413. }
  8414. }
  8415. };
  8416. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8417. var i;
  8418. var len = shapes.length;
  8419. for (i = 0; i < len; i += 1) {
  8420. shapes[i].setAsAnimated();
  8421. }
  8422. };
  8423. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8424. // TODO: prevent drawing of hidden styles
  8425. var elementData;
  8426. var styleOb = new SVGStyleData(data, level);
  8427. var pathElement = styleOb.pElem;
  8428. if (data.ty === 'st') {
  8429. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8430. } else if (data.ty === 'fl') {
  8431. elementData = new SVGFillStyleData(this, data, styleOb);
  8432. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8433. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8434. elementData = new GradientConstructor(this, data, styleOb);
  8435. this.globalData.defs.appendChild(elementData.gf);
  8436. if (elementData.maskId) {
  8437. this.globalData.defs.appendChild(elementData.ms);
  8438. this.globalData.defs.appendChild(elementData.of);
  8439. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8440. }
  8441. } else if (data.ty === 'no') {
  8442. elementData = new SVGNoStyleData(this, data, styleOb);
  8443. }
  8444. if (data.ty === 'st' || data.ty === 'gs') {
  8445. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8446. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8447. pathElement.setAttribute('fill-opacity', '0');
  8448. if (data.lj === 1) {
  8449. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8450. }
  8451. }
  8452. if (data.r === 2) {
  8453. pathElement.setAttribute('fill-rule', 'evenodd');
  8454. }
  8455. if (data.ln) {
  8456. pathElement.setAttribute('id', data.ln);
  8457. }
  8458. if (data.cl) {
  8459. pathElement.setAttribute('class', data.cl);
  8460. }
  8461. if (data.bm) {
  8462. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8463. }
  8464. this.stylesList.push(styleOb);
  8465. this.addToAnimatedContents(data, elementData);
  8466. return elementData;
  8467. };
  8468. SVGShapeElement.prototype.createGroupElement = function (data) {
  8469. var elementData = new ShapeGroupData();
  8470. if (data.ln) {
  8471. elementData.gr.setAttribute('id', data.ln);
  8472. }
  8473. if (data.cl) {
  8474. elementData.gr.setAttribute('class', data.cl);
  8475. }
  8476. if (data.bm) {
  8477. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8478. }
  8479. return elementData;
  8480. };
  8481. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8482. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8483. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8484. this.addToAnimatedContents(data, elementData);
  8485. return elementData;
  8486. };
  8487. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8488. var ty = 4;
  8489. if (data.ty === 'rc') {
  8490. ty = 5;
  8491. } else if (data.ty === 'el') {
  8492. ty = 6;
  8493. } else if (data.ty === 'sr') {
  8494. ty = 7;
  8495. }
  8496. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8497. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8498. this.shapes.push(elementData);
  8499. this.addShapeToModifiers(elementData);
  8500. this.addToAnimatedContents(data, elementData);
  8501. return elementData;
  8502. };
  8503. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8504. var i = 0;
  8505. var len = this.animatedContents.length;
  8506. while (i < len) {
  8507. if (this.animatedContents[i].element === element) {
  8508. return;
  8509. }
  8510. i += 1;
  8511. }
  8512. this.animatedContents.push({
  8513. fn: SVGElementsRenderer.createRenderFunction(data),
  8514. element: element,
  8515. data: data,
  8516. });
  8517. };
  8518. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8519. var arr = elementData.styles;
  8520. var j;
  8521. var jLen = this.stylesList.length;
  8522. for (j = 0; j < jLen; j += 1) {
  8523. if (arr.indexOf(this.stylesList[j]) === -1 && !this.stylesList[j].closed) {
  8524. arr.push(this.stylesList[j]);
  8525. }
  8526. }
  8527. };
  8528. SVGShapeElement.prototype.reloadShapes = function () {
  8529. this._isFirstFrame = true;
  8530. var i;
  8531. var len = this.itemsData.length;
  8532. for (i = 0; i < len; i += 1) {
  8533. this.prevViewData[i] = this.itemsData[i];
  8534. }
  8535. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8536. this.filterUniqueShapes();
  8537. len = this.dynamicProperties.length;
  8538. for (i = 0; i < len; i += 1) {
  8539. this.dynamicProperties[i].getValue();
  8540. }
  8541. this.renderModifiers();
  8542. };
  8543. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8544. var ownTransformers = [].concat(transformers);
  8545. var i;
  8546. var len = arr.length - 1;
  8547. var j;
  8548. var jLen;
  8549. var ownStyles = [];
  8550. var ownModifiers = [];
  8551. var currentTransform;
  8552. var modifier;
  8553. var processedPos;
  8554. for (i = len; i >= 0; i -= 1) {
  8555. processedPos = this.searchProcessedElement(arr[i]);
  8556. if (!processedPos) {
  8557. arr[i]._render = render;
  8558. } else {
  8559. itemsData[i] = prevViewData[processedPos - 1];
  8560. }
  8561. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8562. if (!processedPos) {
  8563. itemsData[i] = this.createStyleElement(arr[i], level);
  8564. } else {
  8565. itemsData[i].style.closed = arr[i].hd;
  8566. }
  8567. if (arr[i]._render) {
  8568. if (itemsData[i].style.pElem.parentNode !== container) {
  8569. container.appendChild(itemsData[i].style.pElem);
  8570. }
  8571. }
  8572. ownStyles.push(itemsData[i].style);
  8573. } else if (arr[i].ty === 'gr') {
  8574. if (!processedPos) {
  8575. itemsData[i] = this.createGroupElement(arr[i]);
  8576. } else {
  8577. jLen = itemsData[i].it.length;
  8578. for (j = 0; j < jLen; j += 1) {
  8579. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8580. }
  8581. }
  8582. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8583. if (arr[i]._render) {
  8584. if (itemsData[i].gr.parentNode !== container) {
  8585. container.appendChild(itemsData[i].gr);
  8586. }
  8587. }
  8588. } else if (arr[i].ty === 'tr') {
  8589. if (!processedPos) {
  8590. itemsData[i] = this.createTransformElement(arr[i], container);
  8591. }
  8592. currentTransform = itemsData[i].transform;
  8593. ownTransformers.push(currentTransform);
  8594. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8595. if (!processedPos) {
  8596. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8597. }
  8598. this.setElementStyles(itemsData[i]);
  8599. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'ms' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  8600. if (!processedPos) {
  8601. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8602. modifier.init(this, arr[i]);
  8603. itemsData[i] = modifier;
  8604. this.shapeModifiers.push(modifier);
  8605. } else {
  8606. modifier = itemsData[i];
  8607. modifier.closed = false;
  8608. }
  8609. ownModifiers.push(modifier);
  8610. } else if (arr[i].ty === 'rp') {
  8611. if (!processedPos) {
  8612. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8613. itemsData[i] = modifier;
  8614. modifier.init(this, arr, i, itemsData);
  8615. this.shapeModifiers.push(modifier);
  8616. render = false;
  8617. } else {
  8618. modifier = itemsData[i];
  8619. modifier.closed = true;
  8620. }
  8621. ownModifiers.push(modifier);
  8622. }
  8623. this.addProcessedElement(arr[i], i + 1);
  8624. }
  8625. len = ownStyles.length;
  8626. for (i = 0; i < len; i += 1) {
  8627. ownStyles[i].closed = true;
  8628. }
  8629. len = ownModifiers.length;
  8630. for (i = 0; i < len; i += 1) {
  8631. ownModifiers[i].closed = true;
  8632. }
  8633. };
  8634. SVGShapeElement.prototype.renderInnerContent = function () {
  8635. this.renderModifiers();
  8636. var i;
  8637. var len = this.stylesList.length;
  8638. for (i = 0; i < len; i += 1) {
  8639. this.stylesList[i].reset();
  8640. }
  8641. this.renderShape();
  8642. for (i = 0; i < len; i += 1) {
  8643. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8644. if (this.stylesList[i].msElem) {
  8645. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  8646. // Adding M0 0 fixes same mask bug on all browsers
  8647. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8648. }
  8649. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8650. }
  8651. }
  8652. };
  8653. SVGShapeElement.prototype.renderShape = function () {
  8654. var i;
  8655. var len = this.animatedContents.length;
  8656. var animatedContent;
  8657. for (i = 0; i < len; i += 1) {
  8658. animatedContent = this.animatedContents[i];
  8659. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8660. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8661. }
  8662. }
  8663. };
  8664. SVGShapeElement.prototype.destroy = function () {
  8665. this.destroyBaseElement();
  8666. this.shapesData = null;
  8667. this.itemsData = null;
  8668. };
  8669. function LetterProps(o, sw, sc, fc, m, p) {
  8670. this.o = o;
  8671. this.sw = sw;
  8672. this.sc = sc;
  8673. this.fc = fc;
  8674. this.m = m;
  8675. this.p = p;
  8676. this._mdf = {
  8677. o: true,
  8678. sw: !!sw,
  8679. sc: !!sc,
  8680. fc: !!fc,
  8681. m: true,
  8682. p: true,
  8683. };
  8684. }
  8685. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  8686. this._mdf.o = false;
  8687. this._mdf.sw = false;
  8688. this._mdf.sc = false;
  8689. this._mdf.fc = false;
  8690. this._mdf.m = false;
  8691. this._mdf.p = false;
  8692. var updated = false;
  8693. if (this.o !== o) {
  8694. this.o = o;
  8695. this._mdf.o = true;
  8696. updated = true;
  8697. }
  8698. if (this.sw !== sw) {
  8699. this.sw = sw;
  8700. this._mdf.sw = true;
  8701. updated = true;
  8702. }
  8703. if (this.sc !== sc) {
  8704. this.sc = sc;
  8705. this._mdf.sc = true;
  8706. updated = true;
  8707. }
  8708. if (this.fc !== fc) {
  8709. this.fc = fc;
  8710. this._mdf.fc = true;
  8711. updated = true;
  8712. }
  8713. if (this.m !== m) {
  8714. this.m = m;
  8715. this._mdf.m = true;
  8716. updated = true;
  8717. }
  8718. if (p.length && (this.p[0] !== p[0] || this.p[1] !== p[1] || this.p[4] !== p[4] || this.p[5] !== p[5] || this.p[12] !== p[12] || this.p[13] !== p[13])) {
  8719. this.p = p;
  8720. this._mdf.p = true;
  8721. updated = true;
  8722. }
  8723. return updated;
  8724. };
  8725. function TextProperty(elem, data) {
  8726. this._frameId = initialDefaultFrame;
  8727. this.pv = '';
  8728. this.v = '';
  8729. this.kf = false;
  8730. this._isFirstFrame = true;
  8731. this._mdf = false;
  8732. if (data.d && data.d.sid) {
  8733. data.d = elem.globalData.slotManager.getProp(data.d);
  8734. }
  8735. this.data = data;
  8736. this.elem = elem;
  8737. this.comp = this.elem.comp;
  8738. this.keysIndex = 0;
  8739. this.canResize = false;
  8740. this.minimumFontSize = 1;
  8741. this.effectsSequence = [];
  8742. this.currentData = {
  8743. ascent: 0,
  8744. boxWidth: this.defaultBoxWidth,
  8745. f: '',
  8746. fStyle: '',
  8747. fWeight: '',
  8748. fc: '',
  8749. j: '',
  8750. justifyOffset: '',
  8751. l: [],
  8752. lh: 0,
  8753. lineWidths: [],
  8754. ls: '',
  8755. of: '',
  8756. s: '',
  8757. sc: '',
  8758. sw: 0,
  8759. t: 0,
  8760. tr: 0,
  8761. sz: 0,
  8762. ps: null,
  8763. fillColorAnim: false,
  8764. strokeColorAnim: false,
  8765. strokeWidthAnim: false,
  8766. yOffset: 0,
  8767. finalSize: 0,
  8768. finalText: [],
  8769. finalLineHeight: 0,
  8770. __complete: false,
  8771. };
  8772. this.copyData(this.currentData, this.data.d.k[0].s);
  8773. if (!this.searchProperty()) {
  8774. this.completeTextData(this.currentData);
  8775. }
  8776. }
  8777. TextProperty.prototype.defaultBoxWidth = [0, 0];
  8778. TextProperty.prototype.copyData = function (obj, data) {
  8779. for (var s in data) {
  8780. if (Object.prototype.hasOwnProperty.call(data, s)) {
  8781. obj[s] = data[s];
  8782. }
  8783. }
  8784. return obj;
  8785. };
  8786. TextProperty.prototype.setCurrentData = function (data) {
  8787. if (!data.__complete) {
  8788. this.completeTextData(data);
  8789. }
  8790. this.currentData = data;
  8791. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  8792. this._mdf = true;
  8793. };
  8794. TextProperty.prototype.searchProperty = function () {
  8795. return this.searchKeyframes();
  8796. };
  8797. TextProperty.prototype.searchKeyframes = function () {
  8798. this.kf = this.data.d.k.length > 1;
  8799. if (this.kf) {
  8800. this.addEffect(this.getKeyframeValue.bind(this));
  8801. }
  8802. return this.kf;
  8803. };
  8804. TextProperty.prototype.addEffect = function (effectFunction) {
  8805. this.effectsSequence.push(effectFunction);
  8806. this.elem.addDynamicProperty(this);
  8807. };
  8808. TextProperty.prototype.getValue = function (_finalValue) {
  8809. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  8810. return;
  8811. }
  8812. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  8813. var currentValue = this.currentData;
  8814. var currentIndex = this.keysIndex;
  8815. if (this.lock) {
  8816. this.setCurrentData(this.currentData);
  8817. return;
  8818. }
  8819. this.lock = true;
  8820. this._mdf = false;
  8821. var i; var
  8822. len = this.effectsSequence.length;
  8823. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  8824. for (i = 0; i < len; i += 1) {
  8825. // Checking if index changed to prevent creating a new object every time the expression updates.
  8826. if (currentIndex !== this.keysIndex) {
  8827. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  8828. } else {
  8829. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  8830. }
  8831. }
  8832. if (currentValue !== finalValue) {
  8833. this.setCurrentData(finalValue);
  8834. }
  8835. this.v = this.currentData;
  8836. this.pv = this.v;
  8837. this.lock = false;
  8838. this.frameId = this.elem.globalData.frameId;
  8839. };
  8840. TextProperty.prototype.getKeyframeValue = function () {
  8841. var textKeys = this.data.d.k;
  8842. var frameNum = this.elem.comp.renderedFrame;
  8843. var i = 0; var
  8844. len = textKeys.length;
  8845. while (i <= len - 1) {
  8846. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  8847. break;
  8848. }
  8849. i += 1;
  8850. }
  8851. if (this.keysIndex !== i) {
  8852. this.keysIndex = i;
  8853. }
  8854. return this.data.d.k[this.keysIndex].s;
  8855. };
  8856. TextProperty.prototype.buildFinalText = function (text) {
  8857. var charactersArray = [];
  8858. var i = 0;
  8859. var len = text.length;
  8860. var charCode;
  8861. var secondCharCode;
  8862. var shouldCombine = false;
  8863. var shouldCombineNext = false;
  8864. var currentChars = '';
  8865. while (i < len) {
  8866. shouldCombine = shouldCombineNext;
  8867. shouldCombineNext = false;
  8868. charCode = text.charCodeAt(i);
  8869. currentChars = text.charAt(i);
  8870. if (FontManager.isCombinedCharacter(charCode)) {
  8871. shouldCombine = true;
  8872. // It's a potential surrogate pair (this is the High surrogate)
  8873. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  8874. if (FontManager.isRegionalFlag(text, i)) {
  8875. currentChars = text.substr(i, 14);
  8876. } else {
  8877. secondCharCode = text.charCodeAt(i + 1);
  8878. // It's a surrogate pair (this is the Low surrogate)
  8879. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  8880. if (FontManager.isModifier(charCode, secondCharCode)) {
  8881. currentChars = text.substr(i, 2);
  8882. shouldCombine = true;
  8883. } else if (FontManager.isFlagEmoji(text.substr(i, 4))) {
  8884. currentChars = text.substr(i, 4);
  8885. } else {
  8886. currentChars = text.substr(i, 2);
  8887. }
  8888. }
  8889. }
  8890. } else if (charCode > 0xDBFF) {
  8891. secondCharCode = text.charCodeAt(i + 1);
  8892. if (FontManager.isVariationSelector(charCode)) {
  8893. shouldCombine = true;
  8894. }
  8895. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  8896. shouldCombine = true;
  8897. shouldCombineNext = true;
  8898. }
  8899. if (shouldCombine) {
  8900. charactersArray[charactersArray.length - 1] += currentChars;
  8901. shouldCombine = false;
  8902. } else {
  8903. charactersArray.push(currentChars);
  8904. }
  8905. i += currentChars.length;
  8906. }
  8907. return charactersArray;
  8908. };
  8909. TextProperty.prototype.completeTextData = function (documentData) {
  8910. documentData.__complete = true;
  8911. var fontManager = this.elem.globalData.fontManager;
  8912. var data = this.data;
  8913. var letters = [];
  8914. var i; var
  8915. len;
  8916. var newLineFlag; var index = 0; var
  8917. val;
  8918. var anchorGrouping = data.m.g;
  8919. var currentSize = 0; var currentPos = 0; var currentLine = 0; var
  8920. lineWidths = [];
  8921. var lineWidth = 0;
  8922. var maxLineWidth = 0;
  8923. var j; var
  8924. jLen;
  8925. var fontData = fontManager.getFontByName(documentData.f);
  8926. var charData; var
  8927. cLength = 0;
  8928. var fontProps = getFontProperties(fontData);
  8929. documentData.fWeight = fontProps.weight;
  8930. documentData.fStyle = fontProps.style;
  8931. documentData.finalSize = documentData.s;
  8932. documentData.finalText = this.buildFinalText(documentData.t);
  8933. len = documentData.finalText.length;
  8934. documentData.finalLineHeight = documentData.lh;
  8935. var trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8936. var charCode;
  8937. if (documentData.sz) {
  8938. var flag = true;
  8939. var boxWidth = documentData.sz[0];
  8940. var boxHeight = documentData.sz[1];
  8941. var currentHeight; var
  8942. finalText;
  8943. while (flag) {
  8944. finalText = this.buildFinalText(documentData.t);
  8945. currentHeight = 0;
  8946. lineWidth = 0;
  8947. len = finalText.length;
  8948. trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8949. var lastSpaceIndex = -1;
  8950. for (i = 0; i < len; i += 1) {
  8951. charCode = finalText[i].charCodeAt(0);
  8952. newLineFlag = false;
  8953. if (finalText[i] === ' ') {
  8954. lastSpaceIndex = i;
  8955. } else if (charCode === 13 || charCode === 3) {
  8956. lineWidth = 0;
  8957. newLineFlag = true;
  8958. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8959. }
  8960. if (fontManager.chars) {
  8961. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  8962. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  8963. } else {
  8964. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  8965. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  8966. }
  8967. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  8968. if (lastSpaceIndex === -1) {
  8969. len += 1;
  8970. } else {
  8971. i = lastSpaceIndex;
  8972. }
  8973. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8974. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r');
  8975. // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  8976. lastSpaceIndex = -1;
  8977. lineWidth = 0;
  8978. } else {
  8979. lineWidth += cLength;
  8980. lineWidth += trackingOffset;
  8981. }
  8982. }
  8983. currentHeight += (fontData.ascent * documentData.finalSize) / 100;
  8984. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  8985. documentData.finalSize -= 1;
  8986. documentData.finalLineHeight = (documentData.finalSize * documentData.lh) / documentData.s;
  8987. } else {
  8988. documentData.finalText = finalText;
  8989. len = documentData.finalText.length;
  8990. flag = false;
  8991. }
  8992. }
  8993. }
  8994. lineWidth = -trackingOffset;
  8995. cLength = 0;
  8996. var uncollapsedSpaces = 0;
  8997. var currentChar;
  8998. for (i = 0; i < len; i += 1) {
  8999. newLineFlag = false;
  9000. currentChar = documentData.finalText[i];
  9001. charCode = currentChar.charCodeAt(0);
  9002. if (charCode === 13 || charCode === 3) {
  9003. uncollapsedSpaces = 0;
  9004. lineWidths.push(lineWidth);
  9005. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9006. lineWidth = -2 * trackingOffset;
  9007. val = '';
  9008. newLineFlag = true;
  9009. currentLine += 1;
  9010. } else {
  9011. val = currentChar;
  9012. }
  9013. if (fontManager.chars) {
  9014. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  9015. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  9016. } else {
  9017. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9018. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  9019. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9020. }
  9021. //
  9022. if (currentChar === ' ') {
  9023. uncollapsedSpaces += cLength + trackingOffset;
  9024. } else {
  9025. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  9026. uncollapsedSpaces = 0;
  9027. }
  9028. letters.push({
  9029. l: cLength, an: cLength, add: currentSize, n: newLineFlag, anIndexes: [], val: val, line: currentLine, animatorJustifyOffset: 0,
  9030. });
  9031. if (anchorGrouping == 2) { // eslint-disable-line eqeqeq
  9032. currentSize += cLength;
  9033. if (val === '' || val === ' ' || i === len - 1) {
  9034. if (val === '' || val === ' ') {
  9035. currentSize -= cLength;
  9036. }
  9037. while (currentPos <= i) {
  9038. letters[currentPos].an = currentSize;
  9039. letters[currentPos].ind = index;
  9040. letters[currentPos].extra = cLength;
  9041. currentPos += 1;
  9042. }
  9043. index += 1;
  9044. currentSize = 0;
  9045. }
  9046. } else if (anchorGrouping == 3) { // eslint-disable-line eqeqeq
  9047. currentSize += cLength;
  9048. if (val === '' || i === len - 1) {
  9049. if (val === '') {
  9050. currentSize -= cLength;
  9051. }
  9052. while (currentPos <= i) {
  9053. letters[currentPos].an = currentSize;
  9054. letters[currentPos].ind = index;
  9055. letters[currentPos].extra = cLength;
  9056. currentPos += 1;
  9057. }
  9058. currentSize = 0;
  9059. index += 1;
  9060. }
  9061. } else {
  9062. letters[index].ind = index;
  9063. letters[index].extra = 0;
  9064. index += 1;
  9065. }
  9066. }
  9067. documentData.l = letters;
  9068. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9069. lineWidths.push(lineWidth);
  9070. if (documentData.sz) {
  9071. documentData.boxWidth = documentData.sz[0];
  9072. documentData.justifyOffset = 0;
  9073. } else {
  9074. documentData.boxWidth = maxLineWidth;
  9075. switch (documentData.j) {
  9076. case 1:
  9077. documentData.justifyOffset = -documentData.boxWidth;
  9078. break;
  9079. case 2:
  9080. documentData.justifyOffset = -documentData.boxWidth / 2;
  9081. break;
  9082. default:
  9083. documentData.justifyOffset = 0;
  9084. }
  9085. }
  9086. documentData.lineWidths = lineWidths;
  9087. var animators = data.a; var animatorData; var
  9088. letterData;
  9089. jLen = animators.length;
  9090. var based; var ind; var
  9091. indexes = [];
  9092. for (j = 0; j < jLen; j += 1) {
  9093. animatorData = animators[j];
  9094. if (animatorData.a.sc) {
  9095. documentData.strokeColorAnim = true;
  9096. }
  9097. if (animatorData.a.sw) {
  9098. documentData.strokeWidthAnim = true;
  9099. }
  9100. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9101. documentData.fillColorAnim = true;
  9102. }
  9103. ind = 0;
  9104. based = animatorData.s.b;
  9105. for (i = 0; i < len; i += 1) {
  9106. letterData = letters[i];
  9107. letterData.anIndexes[j] = ind;
  9108. if ((based == 1 && letterData.val !== '') || (based == 2 && letterData.val !== '' && letterData.val !== ' ') || (based == 3 && (letterData.n || letterData.val == ' ' || i == len - 1)) || (based == 4 && (letterData.n || i == len - 1))) { // eslint-disable-line eqeqeq
  9109. if (animatorData.s.rn === 1) {
  9110. indexes.push(ind);
  9111. }
  9112. ind += 1;
  9113. }
  9114. }
  9115. data.a[j].s.totalChars = ind;
  9116. var currentInd = -1; var
  9117. newInd;
  9118. if (animatorData.s.rn === 1) {
  9119. for (i = 0; i < len; i += 1) {
  9120. letterData = letters[i];
  9121. if (currentInd != letterData.anIndexes[j]) { // eslint-disable-line eqeqeq
  9122. currentInd = letterData.anIndexes[j];
  9123. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9124. }
  9125. letterData.anIndexes[j] = newInd;
  9126. }
  9127. }
  9128. }
  9129. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9130. documentData.ls = documentData.ls || 0;
  9131. documentData.ascent = (fontData.ascent * documentData.finalSize) / 100;
  9132. };
  9133. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9134. index = index === undefined ? this.keysIndex : index;
  9135. var dData = this.copyData({}, this.data.d.k[index].s);
  9136. dData = this.copyData(dData, newData);
  9137. this.data.d.k[index].s = dData;
  9138. this.recalculate(index);
  9139. this.setCurrentData(dData);
  9140. this.elem.addDynamicProperty(this);
  9141. };
  9142. TextProperty.prototype.recalculate = function (index) {
  9143. var dData = this.data.d.k[index].s;
  9144. dData.__complete = false;
  9145. this.keysIndex = 0;
  9146. this._isFirstFrame = true;
  9147. this.getValue(dData);
  9148. };
  9149. TextProperty.prototype.canResizeFont = function (_canResize) {
  9150. this.canResize = _canResize;
  9151. this.recalculate(this.keysIndex);
  9152. this.elem.addDynamicProperty(this);
  9153. };
  9154. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9155. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9156. this.recalculate(this.keysIndex);
  9157. this.elem.addDynamicProperty(this);
  9158. };
  9159. const TextSelectorProp = (function () {
  9160. var max = Math.max;
  9161. var min = Math.min;
  9162. var floor = Math.floor;
  9163. function TextSelectorPropFactory(elem, data) {
  9164. this._currentTextLength = -1;
  9165. this.k = false;
  9166. this.data = data;
  9167. this.elem = elem;
  9168. this.comp = elem.comp;
  9169. this.finalS = 0;
  9170. this.finalE = 0;
  9171. this.initDynamicPropertyContainer(elem);
  9172. this.s = PropertyFactory.getProp(elem, data.s || { k: 0 }, 0, 0, this);
  9173. if ('e' in data) {
  9174. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9175. } else {
  9176. this.e = { v: 100 };
  9177. }
  9178. this.o = PropertyFactory.getProp(elem, data.o || { k: 0 }, 0, 0, this);
  9179. this.xe = PropertyFactory.getProp(elem, data.xe || { k: 0 }, 0, 0, this);
  9180. this.ne = PropertyFactory.getProp(elem, data.ne || { k: 0 }, 0, 0, this);
  9181. this.sm = PropertyFactory.getProp(elem, data.sm || { k: 100 }, 0, 0, this);
  9182. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9183. if (!this.dynamicProperties.length) {
  9184. this.getValue();
  9185. }
  9186. }
  9187. TextSelectorPropFactory.prototype = {
  9188. getMult: function (ind) {
  9189. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9190. this.getValue();
  9191. }
  9192. var x1 = 0;
  9193. var y1 = 0;
  9194. var x2 = 1;
  9195. var y2 = 1;
  9196. if (this.ne.v > 0) {
  9197. x1 = this.ne.v / 100.0;
  9198. } else {
  9199. y1 = -this.ne.v / 100.0;
  9200. }
  9201. if (this.xe.v > 0) {
  9202. x2 = 1.0 - this.xe.v / 100.0;
  9203. } else {
  9204. y2 = 1.0 + this.xe.v / 100.0;
  9205. }
  9206. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9207. var mult = 0;
  9208. var s = this.finalS;
  9209. var e = this.finalE;
  9210. var type = this.data.sh;
  9211. if (type === 2) {
  9212. if (e === s) {
  9213. mult = ind >= e ? 1 : 0;
  9214. } else {
  9215. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9216. }
  9217. mult = easer(mult);
  9218. } else if (type === 3) {
  9219. if (e === s) {
  9220. mult = ind >= e ? 0 : 1;
  9221. } else {
  9222. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9223. }
  9224. mult = easer(mult);
  9225. } else if (type === 4) {
  9226. if (e === s) {
  9227. mult = 0;
  9228. } else {
  9229. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9230. if (mult < 0.5) {
  9231. mult *= 2;
  9232. } else {
  9233. mult = 1 - 2 * (mult - 0.5);
  9234. }
  9235. }
  9236. mult = easer(mult);
  9237. } else if (type === 5) {
  9238. if (e === s) {
  9239. mult = 0;
  9240. } else {
  9241. var tot = e - s;
  9242. /* ind += 0.5;
  9243. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9244. ind = min(max(0, ind + 0.5 - s), e - s);
  9245. var x = -tot / 2 + ind;
  9246. var a = tot / 2;
  9247. mult = Math.sqrt(1 - (x * x) / (a * a));
  9248. }
  9249. mult = easer(mult);
  9250. } else if (type === 6) {
  9251. if (e === s) {
  9252. mult = 0;
  9253. } else {
  9254. ind = min(max(0, ind + 0.5 - s), e - s);
  9255. mult = (1 + (Math.cos((Math.PI + Math.PI * 2 * (ind) / (e - s))))) / 2; // eslint-disable-line
  9256. }
  9257. mult = easer(mult);
  9258. } else {
  9259. if (ind >= floor(s)) {
  9260. if (ind - s < 0) {
  9261. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9262. } else {
  9263. mult = max(0, min(e - ind, 1));
  9264. }
  9265. }
  9266. mult = easer(mult);
  9267. }
  9268. // Smoothness implementation.
  9269. // The smoothness represents a reduced range of the original [0; 1] range.
  9270. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9271. // Steps are:
  9272. // - find the lower value of the new range (threshold)
  9273. // - if multiplier is smaller than that value, floor it to 0
  9274. // - if it is larger,
  9275. // - subtract the threshold
  9276. // - divide it by the smoothness (this will return the range to [0; 1])
  9277. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9278. if (this.sm.v !== 100) {
  9279. var smoothness = this.sm.v * 0.01;
  9280. if (smoothness === 0) {
  9281. smoothness = 0.00000001;
  9282. }
  9283. var threshold = 0.5 - smoothness * 0.5;
  9284. if (mult < threshold) {
  9285. mult = 0;
  9286. } else {
  9287. mult = (mult - threshold) / smoothness;
  9288. if (mult > 1) {
  9289. mult = 1;
  9290. }
  9291. }
  9292. }
  9293. return mult * this.a.v;
  9294. },
  9295. getValue: function (newCharsFlag) {
  9296. this.iterateDynamicProperties();
  9297. this._mdf = newCharsFlag || this._mdf;
  9298. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9299. if (newCharsFlag && this.data.r === 2) {
  9300. this.e.v = this._currentTextLength;
  9301. }
  9302. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9303. var o = this.o.v / divisor;
  9304. var s = this.s.v / divisor + o;
  9305. var e = (this.e.v / divisor) + o;
  9306. if (s > e) {
  9307. var _s = s;
  9308. s = e;
  9309. e = _s;
  9310. }
  9311. this.finalS = s;
  9312. this.finalE = e;
  9313. },
  9314. };
  9315. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9316. function getTextSelectorProp(elem, data, arr) {
  9317. return new TextSelectorPropFactory(elem, data, arr);
  9318. }
  9319. return {
  9320. getTextSelectorProp: getTextSelectorProp,
  9321. };
  9322. }());
  9323. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9324. var defaultData = { propType: false };
  9325. var getProp = PropertyFactory.getProp;
  9326. var textAnimatorAnimatables = animatorProps.a;
  9327. this.a = {
  9328. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9329. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9330. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9331. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9332. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9333. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9334. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9335. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9336. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9337. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9338. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9339. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9340. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9341. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9342. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9343. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData,
  9344. };
  9345. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9346. this.s.t = animatorProps.s.t;
  9347. }
  9348. function TextAnimatorProperty(textData, renderType, elem) {
  9349. this._isFirstFrame = true;
  9350. this._hasMaskedPath = false;
  9351. this._frameId = -1;
  9352. this._textData = textData;
  9353. this._renderType = renderType;
  9354. this._elem = elem;
  9355. this._animatorsData = createSizedArray(this._textData.a.length);
  9356. this._pathData = {};
  9357. this._moreOptions = {
  9358. alignment: {},
  9359. };
  9360. this.renderedLetters = [];
  9361. this.lettersChangedFlag = false;
  9362. this.initDynamicPropertyContainer(elem);
  9363. }
  9364. TextAnimatorProperty.prototype.searchProperties = function () {
  9365. var i;
  9366. var len = this._textData.a.length;
  9367. var animatorProps;
  9368. var getProp = PropertyFactory.getProp;
  9369. for (i = 0; i < len; i += 1) {
  9370. animatorProps = this._textData.a[i];
  9371. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9372. }
  9373. if (this._textData.p && 'm' in this._textData.p) {
  9374. this._pathData = {
  9375. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9376. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9377. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9378. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9379. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9380. m: this._elem.maskManager.getMaskProperty(this._textData.p.m),
  9381. };
  9382. this._hasMaskedPath = true;
  9383. } else {
  9384. this._hasMaskedPath = false;
  9385. }
  9386. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9387. };
  9388. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9389. this.lettersChangedFlag = lettersChangedFlag;
  9390. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9391. return;
  9392. }
  9393. this._isFirstFrame = false;
  9394. var alignment = this._moreOptions.alignment.v;
  9395. var animators = this._animatorsData;
  9396. var textData = this._textData;
  9397. var matrixHelper = this.mHelper;
  9398. var renderType = this._renderType;
  9399. var renderedLettersCount = this.renderedLetters.length;
  9400. var xPos;
  9401. var yPos;
  9402. var i;
  9403. var len;
  9404. var letters = documentData.l;
  9405. var pathInfo;
  9406. var currentLength;
  9407. var currentPoint;
  9408. var segmentLength;
  9409. var flag;
  9410. var pointInd;
  9411. var segmentInd;
  9412. var prevPoint;
  9413. var points;
  9414. var segments;
  9415. var partialLength;
  9416. var totalLength;
  9417. var perc;
  9418. var tanAngle;
  9419. var mask;
  9420. if (this._hasMaskedPath) {
  9421. mask = this._pathData.m;
  9422. if (!this._pathData.n || this._pathData._mdf) {
  9423. var paths = mask.v;
  9424. if (this._pathData.r.v) {
  9425. paths = paths.reverse();
  9426. }
  9427. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9428. pathInfo = {
  9429. tLength: 0,
  9430. segments: [],
  9431. };
  9432. len = paths._length - 1;
  9433. var bezierData;
  9434. totalLength = 0;
  9435. for (i = 0; i < len; i += 1) {
  9436. bezierData = bez.buildBezierData(paths.v[i],
  9437. paths.v[i + 1],
  9438. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9439. [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9440. pathInfo.tLength += bezierData.segmentLength;
  9441. pathInfo.segments.push(bezierData);
  9442. totalLength += bezierData.segmentLength;
  9443. }
  9444. i = len;
  9445. if (mask.v.c) {
  9446. bezierData = bez.buildBezierData(paths.v[i],
  9447. paths.v[0],
  9448. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9449. [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9450. pathInfo.tLength += bezierData.segmentLength;
  9451. pathInfo.segments.push(bezierData);
  9452. totalLength += bezierData.segmentLength;
  9453. }
  9454. this._pathData.pi = pathInfo;
  9455. }
  9456. pathInfo = this._pathData.pi;
  9457. currentLength = this._pathData.f.v;
  9458. segmentInd = 0;
  9459. pointInd = 1;
  9460. segmentLength = 0;
  9461. flag = true;
  9462. segments = pathInfo.segments;
  9463. if (currentLength < 0 && mask.v.c) {
  9464. if (pathInfo.tLength < Math.abs(currentLength)) {
  9465. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9466. }
  9467. segmentInd = segments.length - 1;
  9468. points = segments[segmentInd].points;
  9469. pointInd = points.length - 1;
  9470. while (currentLength < 0) {
  9471. currentLength += points[pointInd].partialLength;
  9472. pointInd -= 1;
  9473. if (pointInd < 0) {
  9474. segmentInd -= 1;
  9475. points = segments[segmentInd].points;
  9476. pointInd = points.length - 1;
  9477. }
  9478. }
  9479. }
  9480. points = segments[segmentInd].points;
  9481. prevPoint = points[pointInd - 1];
  9482. currentPoint = points[pointInd];
  9483. partialLength = currentPoint.partialLength;
  9484. }
  9485. len = letters.length;
  9486. xPos = 0;
  9487. yPos = 0;
  9488. var yOff = documentData.finalSize * 1.2 * 0.714;
  9489. var firstLine = true;
  9490. var animatorProps;
  9491. var animatorSelector;
  9492. var j;
  9493. var jLen;
  9494. var letterValue;
  9495. jLen = animators.length;
  9496. var mult;
  9497. var ind = -1;
  9498. var offf;
  9499. var xPathPos;
  9500. var yPathPos;
  9501. var initPathPos = currentLength;
  9502. var initSegmentInd = segmentInd;
  9503. var initPointInd = pointInd;
  9504. var currentLine = -1;
  9505. var elemOpacity;
  9506. var sc;
  9507. var sw;
  9508. var fc;
  9509. var k;
  9510. var letterSw;
  9511. var letterSc;
  9512. var letterFc;
  9513. var letterM = '';
  9514. var letterP = this.defaultPropsArray;
  9515. var letterO;
  9516. //
  9517. if (documentData.j === 2 || documentData.j === 1) {
  9518. var animatorJustifyOffset = 0;
  9519. var animatorFirstCharOffset = 0;
  9520. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9521. var lastIndex = 0;
  9522. var isNewLine = true;
  9523. for (i = 0; i < len; i += 1) {
  9524. if (letters[i].n) {
  9525. if (animatorJustifyOffset) {
  9526. animatorJustifyOffset += animatorFirstCharOffset;
  9527. }
  9528. while (lastIndex < i) {
  9529. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9530. lastIndex += 1;
  9531. }
  9532. animatorJustifyOffset = 0;
  9533. isNewLine = true;
  9534. } else {
  9535. for (j = 0; j < jLen; j += 1) {
  9536. animatorProps = animators[j].a;
  9537. if (animatorProps.t.propType) {
  9538. if (isNewLine && documentData.j === 2) {
  9539. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9540. }
  9541. animatorSelector = animators[j].s;
  9542. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9543. if (mult.length) {
  9544. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9545. } else {
  9546. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9547. }
  9548. }
  9549. }
  9550. isNewLine = false;
  9551. }
  9552. }
  9553. if (animatorJustifyOffset) {
  9554. animatorJustifyOffset += animatorFirstCharOffset;
  9555. }
  9556. while (lastIndex < i) {
  9557. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9558. lastIndex += 1;
  9559. }
  9560. }
  9561. //
  9562. for (i = 0; i < len; i += 1) {
  9563. matrixHelper.reset();
  9564. elemOpacity = 1;
  9565. if (letters[i].n) {
  9566. xPos = 0;
  9567. yPos += documentData.yOffset;
  9568. yPos += firstLine ? 1 : 0;
  9569. currentLength = initPathPos;
  9570. firstLine = false;
  9571. if (this._hasMaskedPath) {
  9572. segmentInd = initSegmentInd;
  9573. pointInd = initPointInd;
  9574. points = segments[segmentInd].points;
  9575. prevPoint = points[pointInd - 1];
  9576. currentPoint = points[pointInd];
  9577. partialLength = currentPoint.partialLength;
  9578. segmentLength = 0;
  9579. }
  9580. letterM = '';
  9581. letterFc = '';
  9582. letterSw = '';
  9583. letterO = '';
  9584. letterP = this.defaultPropsArray;
  9585. } else {
  9586. if (this._hasMaskedPath) {
  9587. if (currentLine !== letters[i].line) {
  9588. switch (documentData.j) {
  9589. case 1:
  9590. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9591. break;
  9592. case 2:
  9593. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9594. break;
  9595. default:
  9596. break;
  9597. }
  9598. currentLine = letters[i].line;
  9599. }
  9600. if (ind !== letters[i].ind) {
  9601. if (letters[ind]) {
  9602. currentLength += letters[ind].extra;
  9603. }
  9604. currentLength += letters[i].an / 2;
  9605. ind = letters[i].ind;
  9606. }
  9607. currentLength += (alignment[0] * letters[i].an) * 0.005;
  9608. var animatorOffset = 0;
  9609. for (j = 0; j < jLen; j += 1) {
  9610. animatorProps = animators[j].a;
  9611. if (animatorProps.p.propType) {
  9612. animatorSelector = animators[j].s;
  9613. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9614. if (mult.length) {
  9615. animatorOffset += animatorProps.p.v[0] * mult[0];
  9616. } else {
  9617. animatorOffset += animatorProps.p.v[0] * mult;
  9618. }
  9619. }
  9620. if (animatorProps.a.propType) {
  9621. animatorSelector = animators[j].s;
  9622. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9623. if (mult.length) {
  9624. animatorOffset += animatorProps.a.v[0] * mult[0];
  9625. } else {
  9626. animatorOffset += animatorProps.a.v[0] * mult;
  9627. }
  9628. }
  9629. }
  9630. flag = true;
  9631. // Force alignment only works with a single line for now
  9632. if (this._pathData.a.v) {
  9633. currentLength = letters[0].an * 0.5 + ((totalLength - this._pathData.f.v - letters[0].an * 0.5 - letters[letters.length - 1].an * 0.5) * ind) / (len - 1);
  9634. currentLength += this._pathData.f.v;
  9635. }
  9636. while (flag) {
  9637. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9638. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9639. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9640. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9641. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, -(alignment[1] * yOff) * 0.01);
  9642. flag = false;
  9643. } else if (points) {
  9644. segmentLength += currentPoint.partialLength;
  9645. pointInd += 1;
  9646. if (pointInd >= points.length) {
  9647. pointInd = 0;
  9648. segmentInd += 1;
  9649. if (!segments[segmentInd]) {
  9650. if (mask.v.c) {
  9651. pointInd = 0;
  9652. segmentInd = 0;
  9653. points = segments[segmentInd].points;
  9654. } else {
  9655. segmentLength -= currentPoint.partialLength;
  9656. points = null;
  9657. }
  9658. } else {
  9659. points = segments[segmentInd].points;
  9660. }
  9661. }
  9662. if (points) {
  9663. prevPoint = currentPoint;
  9664. currentPoint = points[pointInd];
  9665. partialLength = currentPoint.partialLength;
  9666. }
  9667. }
  9668. }
  9669. offf = letters[i].an / 2 - letters[i].add;
  9670. matrixHelper.translate(-offf, 0, 0);
  9671. } else {
  9672. offf = letters[i].an / 2 - letters[i].add;
  9673. matrixHelper.translate(-offf, 0, 0);
  9674. // Grouping alignment
  9675. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, (-alignment[1] * yOff) * 0.01, 0);
  9676. }
  9677. for (j = 0; j < jLen; j += 1) {
  9678. animatorProps = animators[j].a;
  9679. if (animatorProps.t.propType) {
  9680. animatorSelector = animators[j].s;
  9681. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9682. // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9683. if (xPos !== 0 || documentData.j !== 0) {
  9684. if (this._hasMaskedPath) {
  9685. if (mult.length) {
  9686. currentLength += animatorProps.t.v * mult[0];
  9687. } else {
  9688. currentLength += animatorProps.t.v * mult;
  9689. }
  9690. } else if (mult.length) {
  9691. xPos += animatorProps.t.v * mult[0];
  9692. } else {
  9693. xPos += animatorProps.t.v * mult;
  9694. }
  9695. }
  9696. }
  9697. }
  9698. if (documentData.strokeWidthAnim) {
  9699. sw = documentData.sw || 0;
  9700. }
  9701. if (documentData.strokeColorAnim) {
  9702. if (documentData.sc) {
  9703. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  9704. } else {
  9705. sc = [0, 0, 0];
  9706. }
  9707. }
  9708. if (documentData.fillColorAnim && documentData.fc) {
  9709. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  9710. }
  9711. for (j = 0; j < jLen; j += 1) {
  9712. animatorProps = animators[j].a;
  9713. if (animatorProps.a.propType) {
  9714. animatorSelector = animators[j].s;
  9715. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9716. if (mult.length) {
  9717. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  9718. } else {
  9719. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  9720. }
  9721. }
  9722. }
  9723. for (j = 0; j < jLen; j += 1) {
  9724. animatorProps = animators[j].a;
  9725. if (animatorProps.s.propType) {
  9726. animatorSelector = animators[j].s;
  9727. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9728. if (mult.length) {
  9729. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult[0]), 1 + ((animatorProps.s.v[1] - 1) * mult[1]), 1);
  9730. } else {
  9731. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult), 1 + ((animatorProps.s.v[1] - 1) * mult), 1);
  9732. }
  9733. }
  9734. }
  9735. for (j = 0; j < jLen; j += 1) {
  9736. animatorProps = animators[j].a;
  9737. animatorSelector = animators[j].s;
  9738. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9739. if (animatorProps.sk.propType) {
  9740. if (mult.length) {
  9741. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  9742. } else {
  9743. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  9744. }
  9745. }
  9746. if (animatorProps.r.propType) {
  9747. if (mult.length) {
  9748. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  9749. } else {
  9750. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  9751. }
  9752. }
  9753. if (animatorProps.ry.propType) {
  9754. if (mult.length) {
  9755. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  9756. } else {
  9757. matrixHelper.rotateY(animatorProps.ry.v * mult);
  9758. }
  9759. }
  9760. if (animatorProps.rx.propType) {
  9761. if (mult.length) {
  9762. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  9763. } else {
  9764. matrixHelper.rotateX(animatorProps.rx.v * mult);
  9765. }
  9766. }
  9767. if (animatorProps.o.propType) {
  9768. if (mult.length) {
  9769. elemOpacity += ((animatorProps.o.v) * mult[0] - elemOpacity) * mult[0];
  9770. } else {
  9771. elemOpacity += ((animatorProps.o.v) * mult - elemOpacity) * mult;
  9772. }
  9773. }
  9774. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  9775. if (mult.length) {
  9776. sw += animatorProps.sw.v * mult[0];
  9777. } else {
  9778. sw += animatorProps.sw.v * mult;
  9779. }
  9780. }
  9781. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  9782. for (k = 0; k < 3; k += 1) {
  9783. if (mult.length) {
  9784. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  9785. } else {
  9786. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  9787. }
  9788. }
  9789. }
  9790. if (documentData.fillColorAnim && documentData.fc) {
  9791. if (animatorProps.fc.propType) {
  9792. for (k = 0; k < 3; k += 1) {
  9793. if (mult.length) {
  9794. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  9795. } else {
  9796. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  9797. }
  9798. }
  9799. }
  9800. if (animatorProps.fh.propType) {
  9801. if (mult.length) {
  9802. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  9803. } else {
  9804. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  9805. }
  9806. }
  9807. if (animatorProps.fs.propType) {
  9808. if (mult.length) {
  9809. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  9810. } else {
  9811. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  9812. }
  9813. }
  9814. if (animatorProps.fb.propType) {
  9815. if (mult.length) {
  9816. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  9817. } else {
  9818. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  9819. }
  9820. }
  9821. }
  9822. }
  9823. for (j = 0; j < jLen; j += 1) {
  9824. animatorProps = animators[j].a;
  9825. if (animatorProps.p.propType) {
  9826. animatorSelector = animators[j].s;
  9827. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9828. if (this._hasMaskedPath) {
  9829. if (mult.length) {
  9830. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  9831. } else {
  9832. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9833. }
  9834. } else if (mult.length) {
  9835. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  9836. } else {
  9837. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9838. }
  9839. }
  9840. }
  9841. if (documentData.strokeWidthAnim) {
  9842. letterSw = sw < 0 ? 0 : sw;
  9843. }
  9844. if (documentData.strokeColorAnim) {
  9845. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  9846. }
  9847. if (documentData.fillColorAnim && documentData.fc) {
  9848. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  9849. }
  9850. if (this._hasMaskedPath) {
  9851. matrixHelper.translate(0, -documentData.ls);
  9852. matrixHelper.translate(0, (alignment[1] * yOff) * 0.01 + yPos, 0);
  9853. if (this._pathData.p.v) {
  9854. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  9855. var rot = (Math.atan(tanAngle) * 180) / Math.PI;
  9856. if (currentPoint.point[0] < prevPoint.point[0]) {
  9857. rot += 180;
  9858. }
  9859. matrixHelper.rotate((-rot * Math.PI) / 180);
  9860. }
  9861. matrixHelper.translate(xPathPos, yPathPos, 0);
  9862. currentLength -= (alignment[0] * letters[i].an) * 0.005;
  9863. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  9864. currentLength += letters[i].an / 2;
  9865. currentLength += (documentData.tr * 0.001) * documentData.finalSize;
  9866. }
  9867. } else {
  9868. matrixHelper.translate(xPos, yPos, 0);
  9869. if (documentData.ps) {
  9870. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  9871. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9872. }
  9873. switch (documentData.j) {
  9874. case 1:
  9875. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  9876. break;
  9877. case 2:
  9878. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  9879. break;
  9880. default:
  9881. break;
  9882. }
  9883. matrixHelper.translate(0, -documentData.ls);
  9884. matrixHelper.translate(offf, 0, 0);
  9885. matrixHelper.translate((alignment[0] * letters[i].an) * 0.005, (alignment[1] * yOff) * 0.01, 0);
  9886. xPos += letters[i].l + (documentData.tr * 0.001) * documentData.finalSize;
  9887. }
  9888. if (renderType === 'html') {
  9889. letterM = matrixHelper.toCSS();
  9890. } else if (renderType === 'svg') {
  9891. letterM = matrixHelper.to2dCSS();
  9892. } else {
  9893. letterP = [matrixHelper.props[0], matrixHelper.props[1], matrixHelper.props[2], matrixHelper.props[3], matrixHelper.props[4], matrixHelper.props[5], matrixHelper.props[6], matrixHelper.props[7], matrixHelper.props[8], matrixHelper.props[9], matrixHelper.props[10], matrixHelper.props[11], matrixHelper.props[12], matrixHelper.props[13], matrixHelper.props[14], matrixHelper.props[15]];
  9894. }
  9895. letterO = elemOpacity;
  9896. }
  9897. if (renderedLettersCount <= i) {
  9898. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  9899. this.renderedLetters.push(letterValue);
  9900. renderedLettersCount += 1;
  9901. this.lettersChangedFlag = true;
  9902. } else {
  9903. letterValue = this.renderedLetters[i];
  9904. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  9905. }
  9906. }
  9907. };
  9908. TextAnimatorProperty.prototype.getValue = function () {
  9909. if (this._elem.globalData.frameId === this._frameId) {
  9910. return;
  9911. }
  9912. this._frameId = this._elem.globalData.frameId;
  9913. this.iterateDynamicProperties();
  9914. };
  9915. TextAnimatorProperty.prototype.mHelper = new Matrix();
  9916. TextAnimatorProperty.prototype.defaultPropsArray = [];
  9917. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  9918. function ITextElement() {
  9919. }
  9920. ITextElement.prototype.initElement = function (data, globalData, comp) {
  9921. this.lettersChangedFlag = true;
  9922. this.initFrame();
  9923. this.initBaseData(data, globalData, comp);
  9924. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  9925. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  9926. this.initTransform(data, globalData, comp);
  9927. this.initHierarchy();
  9928. this.initRenderable();
  9929. this.initRendererElement();
  9930. this.createContainerElements();
  9931. this.createRenderableComponents();
  9932. this.createContent();
  9933. this.hide();
  9934. this.textAnimator.searchProperties(this.dynamicProperties);
  9935. };
  9936. ITextElement.prototype.prepareFrame = function (num) {
  9937. this._mdf = false;
  9938. this.prepareRenderableFrame(num);
  9939. this.prepareProperties(num, this.isInRange);
  9940. };
  9941. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  9942. var j;
  9943. var jLen = shapes.length;
  9944. var pathNodes;
  9945. var shapeStr = '';
  9946. for (j = 0; j < jLen; j += 1) {
  9947. if (shapes[j].ty === 'sh') {
  9948. pathNodes = shapes[j].ks.k;
  9949. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  9950. }
  9951. }
  9952. return shapeStr;
  9953. };
  9954. ITextElement.prototype.updateDocumentData = function (newData, index) {
  9955. this.textProperty.updateDocumentData(newData, index);
  9956. };
  9957. ITextElement.prototype.canResizeFont = function (_canResize) {
  9958. this.textProperty.canResizeFont(_canResize);
  9959. };
  9960. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  9961. this.textProperty.setMinimumFontSize(_fontSize);
  9962. };
  9963. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  9964. if (documentData.ps) {
  9965. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9966. }
  9967. matrixHelper.translate(0, -documentData.ls, 0);
  9968. switch (documentData.j) {
  9969. case 1:
  9970. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  9971. break;
  9972. case 2:
  9973. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  9974. break;
  9975. default:
  9976. break;
  9977. }
  9978. matrixHelper.translate(xPos, yPos, 0);
  9979. };
  9980. ITextElement.prototype.buildColor = function (colorData) {
  9981. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  9982. };
  9983. ITextElement.prototype.emptyProp = new LetterProps();
  9984. ITextElement.prototype.destroy = function () {
  9985. };
  9986. ITextElement.prototype.validateText = function () {
  9987. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  9988. this.buildNewText();
  9989. this.textProperty._isFirstFrame = false;
  9990. this.textProperty._mdf = false;
  9991. }
  9992. };
  9993. var emptyShapeData = {
  9994. shapes: [],
  9995. };
  9996. function SVGTextLottieElement(data, globalData, comp) {
  9997. this.textSpans = [];
  9998. this.renderType = 'svg';
  9999. this.initElement(data, globalData, comp);
  10000. }
  10001. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  10002. SVGTextLottieElement.prototype.createContent = function () {
  10003. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  10004. this.textContainer = createNS('text');
  10005. }
  10006. };
  10007. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  10008. var i = 0;
  10009. var len = textArray.length;
  10010. var textContents = [];
  10011. var currentTextContent = '';
  10012. while (i < len) {
  10013. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  10014. textContents.push(currentTextContent);
  10015. currentTextContent = '';
  10016. } else {
  10017. currentTextContent += textArray[i];
  10018. }
  10019. i += 1;
  10020. }
  10021. textContents.push(currentTextContent);
  10022. return textContents;
  10023. };
  10024. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  10025. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  10026. // but since text internal content gets only rendered once and then it's never rerendered,
  10027. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  10028. // Avoiding cloning is preferred since cloning each character shape data is expensive
  10029. if (data.shapes && data.shapes.length) {
  10030. var shape = data.shapes[0];
  10031. if (shape.it) {
  10032. var shapeItem = shape.it[shape.it.length - 1];
  10033. if (shapeItem.s) {
  10034. shapeItem.s.k[0] = scale;
  10035. shapeItem.s.k[1] = scale;
  10036. }
  10037. }
  10038. }
  10039. return data;
  10040. };
  10041. SVGTextLottieElement.prototype.buildNewText = function () {
  10042. this.addDynamicProperty(this);
  10043. var i;
  10044. var len;
  10045. var documentData = this.textProperty.currentData;
  10046. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  10047. if (documentData.fc) {
  10048. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  10049. } else {
  10050. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  10051. }
  10052. if (documentData.sc) {
  10053. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  10054. this.layerElement.setAttribute('stroke-width', documentData.sw);
  10055. }
  10056. this.layerElement.setAttribute('font-size', documentData.finalSize);
  10057. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10058. if (fontData.fClass) {
  10059. this.layerElement.setAttribute('class', fontData.fClass);
  10060. } else {
  10061. this.layerElement.setAttribute('font-family', fontData.fFamily);
  10062. var fWeight = documentData.fWeight;
  10063. var fStyle = documentData.fStyle;
  10064. this.layerElement.setAttribute('font-style', fStyle);
  10065. this.layerElement.setAttribute('font-weight', fWeight);
  10066. }
  10067. this.layerElement.setAttribute('aria-label', documentData.t);
  10068. var letters = documentData.l || [];
  10069. var usesGlyphs = !!this.globalData.fontManager.chars;
  10070. len = letters.length;
  10071. var tSpan;
  10072. var matrixHelper = this.mHelper;
  10073. var shapeStr = '';
  10074. var singleShape = this.data.singleShape;
  10075. var xPos = 0;
  10076. var yPos = 0;
  10077. var firstLine = true;
  10078. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10079. if (singleShape && !usesGlyphs && !documentData.sz) {
  10080. var tElement = this.textContainer;
  10081. var justify = 'start';
  10082. switch (documentData.j) {
  10083. case 1:
  10084. justify = 'end';
  10085. break;
  10086. case 2:
  10087. justify = 'middle';
  10088. break;
  10089. default:
  10090. justify = 'start';
  10091. break;
  10092. }
  10093. tElement.setAttribute('text-anchor', justify);
  10094. tElement.setAttribute('letter-spacing', trackingOffset);
  10095. var textContent = this.buildTextContents(documentData.finalText);
  10096. len = textContent.length;
  10097. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10098. for (i = 0; i < len; i += 1) {
  10099. tSpan = this.textSpans[i].span || createNS('tspan');
  10100. tSpan.textContent = textContent[i];
  10101. tSpan.setAttribute('x', 0);
  10102. tSpan.setAttribute('y', yPos);
  10103. tSpan.style.display = 'inherit';
  10104. tElement.appendChild(tSpan);
  10105. if (!this.textSpans[i]) {
  10106. this.textSpans[i] = {
  10107. span: null,
  10108. glyph: null,
  10109. };
  10110. }
  10111. this.textSpans[i].span = tSpan;
  10112. yPos += documentData.finalLineHeight;
  10113. }
  10114. this.layerElement.appendChild(tElement);
  10115. } else {
  10116. var cachedSpansLength = this.textSpans.length;
  10117. var charData;
  10118. for (i = 0; i < len; i += 1) {
  10119. if (!this.textSpans[i]) {
  10120. this.textSpans[i] = {
  10121. span: null,
  10122. childSpan: null,
  10123. glyph: null,
  10124. };
  10125. }
  10126. if (!usesGlyphs || !singleShape || i === 0) {
  10127. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10128. if (cachedSpansLength <= i) {
  10129. tSpan.setAttribute('stroke-linecap', 'butt');
  10130. tSpan.setAttribute('stroke-linejoin', 'round');
  10131. tSpan.setAttribute('stroke-miterlimit', '4');
  10132. this.textSpans[i].span = tSpan;
  10133. if (usesGlyphs) {
  10134. var childSpan = createNS('g');
  10135. tSpan.appendChild(childSpan);
  10136. this.textSpans[i].childSpan = childSpan;
  10137. }
  10138. this.textSpans[i].span = tSpan;
  10139. this.layerElement.appendChild(tSpan);
  10140. }
  10141. tSpan.style.display = 'inherit';
  10142. }
  10143. matrixHelper.reset();
  10144. if (singleShape) {
  10145. if (letters[i].n) {
  10146. xPos = -trackingOffset;
  10147. yPos += documentData.yOffset;
  10148. yPos += firstLine ? 1 : 0;
  10149. firstLine = false;
  10150. }
  10151. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10152. xPos += letters[i].l || 0;
  10153. // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10154. xPos += trackingOffset;
  10155. }
  10156. if (usesGlyphs) {
  10157. charData = this.globalData.fontManager.getCharData(
  10158. documentData.finalText[i],
  10159. fontData.fStyle,
  10160. this.globalData.fontManager.getFontByName(documentData.f).fFamily
  10161. );
  10162. var glyphElement;
  10163. // t === 1 means the character has been replaced with an animated shaped
  10164. if (charData.t === 1) {
  10165. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10166. } else {
  10167. var data = emptyShapeData;
  10168. if (charData.data && charData.data.shapes) {
  10169. data = this.buildShapeData(charData.data, documentData.finalSize);
  10170. }
  10171. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10172. }
  10173. if (this.textSpans[i].glyph) {
  10174. var glyph = this.textSpans[i].glyph;
  10175. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10176. glyph.destroy();
  10177. }
  10178. this.textSpans[i].glyph = glyphElement;
  10179. glyphElement._debug = true;
  10180. glyphElement.prepareFrame(0);
  10181. glyphElement.renderFrame();
  10182. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
  10183. // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10184. // this might have issues with strokes and might need a different solution
  10185. if (charData.t === 1) {
  10186. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10187. }
  10188. } else {
  10189. if (singleShape) {
  10190. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10191. }
  10192. tSpan.textContent = letters[i].val;
  10193. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10194. }
  10195. //
  10196. }
  10197. if (singleShape && tSpan) {
  10198. tSpan.setAttribute('d', shapeStr);
  10199. }
  10200. }
  10201. while (i < this.textSpans.length) {
  10202. this.textSpans[i].span.style.display = 'none';
  10203. i += 1;
  10204. }
  10205. this._sizeChanged = true;
  10206. };
  10207. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10208. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10209. this.renderInnerContent();
  10210. if (this._sizeChanged) {
  10211. this._sizeChanged = false;
  10212. var textBox = this.layerElement.getBBox();
  10213. this.bbox = {
  10214. top: textBox.y,
  10215. left: textBox.x,
  10216. width: textBox.width,
  10217. height: textBox.height,
  10218. };
  10219. }
  10220. return this.bbox;
  10221. };
  10222. SVGTextLottieElement.prototype.getValue = function () {
  10223. var i;
  10224. var len = this.textSpans.length;
  10225. var glyphElement;
  10226. this.renderedFrame = this.comp.renderedFrame;
  10227. for (i = 0; i < len; i += 1) {
  10228. glyphElement = this.textSpans[i].glyph;
  10229. if (glyphElement) {
  10230. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10231. if (glyphElement._mdf) {
  10232. this._mdf = true;
  10233. }
  10234. }
  10235. }
  10236. };
  10237. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10238. this.validateText();
  10239. if (!this.data.singleShape || this._mdf) {
  10240. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10241. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10242. this._sizeChanged = true;
  10243. var i;
  10244. var len;
  10245. var renderedLetters = this.textAnimator.renderedLetters;
  10246. var letters = this.textProperty.currentData.l;
  10247. len = letters.length;
  10248. var renderedLetter;
  10249. var textSpan;
  10250. var glyphElement;
  10251. for (i = 0; i < len; i += 1) {
  10252. if (!letters[i].n) {
  10253. renderedLetter = renderedLetters[i];
  10254. textSpan = this.textSpans[i].span;
  10255. glyphElement = this.textSpans[i].glyph;
  10256. if (glyphElement) {
  10257. glyphElement.renderFrame();
  10258. }
  10259. if (renderedLetter._mdf.m) {
  10260. textSpan.setAttribute('transform', renderedLetter.m);
  10261. }
  10262. if (renderedLetter._mdf.o) {
  10263. textSpan.setAttribute('opacity', renderedLetter.o);
  10264. }
  10265. if (renderedLetter._mdf.sw) {
  10266. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10267. }
  10268. if (renderedLetter._mdf.sc) {
  10269. textSpan.setAttribute('stroke', renderedLetter.sc);
  10270. }
  10271. if (renderedLetter._mdf.fc) {
  10272. textSpan.setAttribute('fill', renderedLetter.fc);
  10273. }
  10274. }
  10275. }
  10276. }
  10277. }
  10278. };
  10279. function ISolidElement(data, globalData, comp) {
  10280. this.initElement(data, globalData, comp);
  10281. }
  10282. extendPrototype([IImageElement], ISolidElement);
  10283. ISolidElement.prototype.createContent = function () {
  10284. var rect = createNS('rect');
  10285. /// /rect.style.width = this.data.sw;
  10286. /// /rect.style.height = this.data.sh;
  10287. /// /rect.style.fill = this.data.sc;
  10288. rect.setAttribute('width', this.data.sw);
  10289. rect.setAttribute('height', this.data.sh);
  10290. rect.setAttribute('fill', this.data.sc);
  10291. this.layerElement.appendChild(rect);
  10292. };
  10293. function NullElement(data, globalData, comp) {
  10294. this.initFrame();
  10295. this.initBaseData(data, globalData, comp);
  10296. this.initFrame();
  10297. this.initTransform(data, globalData, comp);
  10298. this.initHierarchy();
  10299. }
  10300. NullElement.prototype.prepareFrame = function (num) {
  10301. this.prepareProperties(num, true);
  10302. };
  10303. NullElement.prototype.renderFrame = function () {
  10304. };
  10305. NullElement.prototype.getBaseElement = function () {
  10306. return null;
  10307. };
  10308. NullElement.prototype.destroy = function () {
  10309. };
  10310. NullElement.prototype.sourceRectAtTime = function () {
  10311. };
  10312. NullElement.prototype.hide = function () {
  10313. };
  10314. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10315. function SVGRendererBase() {
  10316. }
  10317. extendPrototype([BaseRenderer], SVGRendererBase);
  10318. SVGRendererBase.prototype.createNull = function (data) {
  10319. return new NullElement(data, this.globalData, this);
  10320. };
  10321. SVGRendererBase.prototype.createShape = function (data) {
  10322. return new SVGShapeElement(data, this.globalData, this);
  10323. };
  10324. SVGRendererBase.prototype.createText = function (data) {
  10325. return new SVGTextLottieElement(data, this.globalData, this);
  10326. };
  10327. SVGRendererBase.prototype.createImage = function (data) {
  10328. return new IImageElement(data, this.globalData, this);
  10329. };
  10330. SVGRendererBase.prototype.createSolid = function (data) {
  10331. return new ISolidElement(data, this.globalData, this);
  10332. };
  10333. SVGRendererBase.prototype.configAnimation = function (animData) {
  10334. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10335. this.svgElement.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  10336. if (this.renderConfig.viewBoxSize) {
  10337. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10338. } else {
  10339. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10340. }
  10341. if (!this.renderConfig.viewBoxOnly) {
  10342. this.svgElement.setAttribute('width', animData.w);
  10343. this.svgElement.setAttribute('height', animData.h);
  10344. this.svgElement.style.width = '100%';
  10345. this.svgElement.style.height = '100%';
  10346. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10347. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10348. }
  10349. if (this.renderConfig.width) {
  10350. this.svgElement.setAttribute('width', this.renderConfig.width);
  10351. }
  10352. if (this.renderConfig.height) {
  10353. this.svgElement.setAttribute('height', this.renderConfig.height);
  10354. }
  10355. if (this.renderConfig.className) {
  10356. this.svgElement.setAttribute('class', this.renderConfig.className);
  10357. }
  10358. if (this.renderConfig.id) {
  10359. this.svgElement.setAttribute('id', this.renderConfig.id);
  10360. }
  10361. if (this.renderConfig.focusable !== undefined) {
  10362. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10363. }
  10364. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio);
  10365. // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10366. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10367. this.animationItem.wrapper.appendChild(this.svgElement);
  10368. // Mask animation
  10369. var defs = this.globalData.defs;
  10370. this.setupGlobalData(animData, defs);
  10371. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10372. this.data = animData;
  10373. var maskElement = createNS('clipPath');
  10374. var rect = createNS('rect');
  10375. rect.setAttribute('width', animData.w);
  10376. rect.setAttribute('height', animData.h);
  10377. rect.setAttribute('x', 0);
  10378. rect.setAttribute('y', 0);
  10379. var maskId = createElementID();
  10380. maskElement.setAttribute('id', maskId);
  10381. maskElement.appendChild(rect);
  10382. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10383. defs.appendChild(maskElement);
  10384. this.layers = animData.layers;
  10385. this.elements = createSizedArray(animData.layers.length);
  10386. };
  10387. SVGRendererBase.prototype.destroy = function () {
  10388. if (this.animationItem.wrapper) {
  10389. this.animationItem.wrapper.innerText = '';
  10390. }
  10391. this.layerElement = null;
  10392. this.globalData.defs = null;
  10393. var i;
  10394. var len = this.layers ? this.layers.length : 0;
  10395. for (i = 0; i < len; i += 1) {
  10396. if (this.elements[i] && this.elements[i].destroy) {
  10397. this.elements[i].destroy();
  10398. }
  10399. }
  10400. this.elements.length = 0;
  10401. this.destroyed = true;
  10402. this.animationItem = null;
  10403. };
  10404. SVGRendererBase.prototype.updateContainerSize = function () {
  10405. };
  10406. SVGRendererBase.prototype.findIndexByInd = function (ind) {
  10407. var i = 0;
  10408. var len = this.layers.length;
  10409. for (i = 0; i < len; i += 1) {
  10410. if (this.layers[i].ind === ind) {
  10411. return i;
  10412. }
  10413. }
  10414. return -1;
  10415. };
  10416. SVGRendererBase.prototype.buildItem = function (pos) {
  10417. var elements = this.elements;
  10418. if (elements[pos] || this.layers[pos].ty === 99) {
  10419. return;
  10420. }
  10421. elements[pos] = true;
  10422. var element = this.createItem(this.layers[pos]);
  10423. elements[pos] = element;
  10424. if (getExpressionsPlugin()) {
  10425. if (this.layers[pos].ty === 0) {
  10426. this.globalData.projectInterface.registerComposition(element);
  10427. }
  10428. element.initExpressions();
  10429. }
  10430. this.appendElementInPos(element, pos);
  10431. if (this.layers[pos].tt) {
  10432. var elementIndex = ('tp' in this.layers[pos])
  10433. ? this.findIndexByInd(this.layers[pos].tp)
  10434. : pos - 1;
  10435. if (elementIndex === -1) {
  10436. return;
  10437. }
  10438. if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
  10439. this.buildItem(elementIndex);
  10440. this.addPendingElement(element);
  10441. } else {
  10442. var matteElement = elements[elementIndex];
  10443. var matteMask = matteElement.getMatte(this.layers[pos].tt);
  10444. element.setMatte(matteMask);
  10445. }
  10446. }
  10447. };
  10448. SVGRendererBase.prototype.checkPendingElements = function () {
  10449. while (this.pendingElements.length) {
  10450. var element = this.pendingElements.pop();
  10451. element.checkParenting();
  10452. if (element.data.tt) {
  10453. var i = 0;
  10454. var len = this.elements.length;
  10455. while (i < len) {
  10456. if (this.elements[i] === element) {
  10457. var elementIndex = 'tp' in element.data
  10458. ? this.findIndexByInd(element.data.tp)
  10459. : i - 1;
  10460. var matteElement = this.elements[elementIndex];
  10461. var matteMask = matteElement.getMatte(this.layers[i].tt);
  10462. element.setMatte(matteMask);
  10463. break;
  10464. }
  10465. i += 1;
  10466. }
  10467. }
  10468. }
  10469. };
  10470. SVGRendererBase.prototype.renderFrame = function (num) {
  10471. if (this.renderedFrame === num || this.destroyed) {
  10472. return;
  10473. }
  10474. if (num === null) {
  10475. num = this.renderedFrame;
  10476. } else {
  10477. this.renderedFrame = num;
  10478. }
  10479. // console.log('-------');
  10480. // console.log('FRAME ',num);
  10481. this.globalData.frameNum = num;
  10482. this.globalData.frameId += 1;
  10483. this.globalData.projectInterface.currentFrame = num;
  10484. this.globalData._mdf = false;
  10485. var i;
  10486. var len = this.layers.length;
  10487. if (!this.completeLayers) {
  10488. this.checkLayers(num);
  10489. }
  10490. for (i = len - 1; i >= 0; i -= 1) {
  10491. if (this.completeLayers || this.elements[i]) {
  10492. this.elements[i].prepareFrame(num - this.layers[i].st);
  10493. }
  10494. }
  10495. if (this.globalData._mdf) {
  10496. for (i = 0; i < len; i += 1) {
  10497. if (this.completeLayers || this.elements[i]) {
  10498. this.elements[i].renderFrame();
  10499. }
  10500. }
  10501. }
  10502. };
  10503. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10504. var newElement = element.getBaseElement();
  10505. if (!newElement) {
  10506. return;
  10507. }
  10508. var i = 0;
  10509. var nextElement;
  10510. while (i < pos) {
  10511. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10512. nextElement = this.elements[i].getBaseElement();
  10513. }
  10514. i += 1;
  10515. }
  10516. if (nextElement) {
  10517. this.layerElement.insertBefore(newElement, nextElement);
  10518. } else {
  10519. this.layerElement.appendChild(newElement);
  10520. }
  10521. };
  10522. SVGRendererBase.prototype.hide = function () {
  10523. this.layerElement.style.display = 'none';
  10524. };
  10525. SVGRendererBase.prototype.show = function () {
  10526. this.layerElement.style.display = 'block';
  10527. };
  10528. function ICompElement() {}
  10529. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10530. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10531. this.initFrame();
  10532. this.initBaseData(data, globalData, comp);
  10533. this.initTransform(data, globalData, comp);
  10534. this.initRenderable();
  10535. this.initHierarchy();
  10536. this.initRendererElement();
  10537. this.createContainerElements();
  10538. this.createRenderableComponents();
  10539. if (this.data.xt || !globalData.progressiveLoad) {
  10540. this.buildAllItems();
  10541. }
  10542. this.hide();
  10543. };
  10544. /* ICompElement.prototype.hide = function(){
  10545. if(!this.hidden){
  10546. this.hideElement();
  10547. var i,len = this.elements.length;
  10548. for( i = 0; i < len; i+=1 ){
  10549. if(this.elements[i]){
  10550. this.elements[i].hide();
  10551. }
  10552. }
  10553. }
  10554. }; */
  10555. ICompElement.prototype.prepareFrame = function (num) {
  10556. this._mdf = false;
  10557. this.prepareRenderableFrame(num);
  10558. this.prepareProperties(num, this.isInRange);
  10559. if (!this.isInRange && !this.data.xt) {
  10560. return;
  10561. }
  10562. if (!this.tm._placeholder) {
  10563. var timeRemapped = this.tm.v;
  10564. if (timeRemapped === this.data.op) {
  10565. timeRemapped = this.data.op - 1;
  10566. }
  10567. this.renderedFrame = timeRemapped;
  10568. } else {
  10569. this.renderedFrame = num / this.data.sr;
  10570. }
  10571. var i;
  10572. var len = this.elements.length;
  10573. if (!this.completeLayers) {
  10574. this.checkLayers(this.renderedFrame);
  10575. }
  10576. // This iteration needs to be backwards because of how expressions connect between each other
  10577. for (i = len - 1; i >= 0; i -= 1) {
  10578. if (this.completeLayers || this.elements[i]) {
  10579. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10580. if (this.elements[i]._mdf) {
  10581. this._mdf = true;
  10582. }
  10583. }
  10584. }
  10585. };
  10586. ICompElement.prototype.renderInnerContent = function () {
  10587. var i;
  10588. var len = this.layers.length;
  10589. for (i = 0; i < len; i += 1) {
  10590. if (this.completeLayers || this.elements[i]) {
  10591. this.elements[i].renderFrame();
  10592. }
  10593. }
  10594. };
  10595. ICompElement.prototype.setElements = function (elems) {
  10596. this.elements = elems;
  10597. };
  10598. ICompElement.prototype.getElements = function () {
  10599. return this.elements;
  10600. };
  10601. ICompElement.prototype.destroyElements = function () {
  10602. var i;
  10603. var len = this.layers.length;
  10604. for (i = 0; i < len; i += 1) {
  10605. if (this.elements[i]) {
  10606. this.elements[i].destroy();
  10607. }
  10608. }
  10609. };
  10610. ICompElement.prototype.destroy = function () {
  10611. this.destroyElements();
  10612. this.destroyBaseElement();
  10613. };
  10614. function SVGCompElement(data, globalData, comp) {
  10615. this.layers = data.layers;
  10616. this.supports3d = true;
  10617. this.completeLayers = false;
  10618. this.pendingElements = [];
  10619. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10620. this.initElement(data, globalData, comp);
  10621. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  10622. }
  10623. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10624. SVGCompElement.prototype.createComp = function (data) {
  10625. return new SVGCompElement(data, this.globalData, this);
  10626. };
  10627. function SVGRenderer(animationItem, config) {
  10628. this.animationItem = animationItem;
  10629. this.layers = null;
  10630. this.renderedFrame = -1;
  10631. this.svgElement = createNS('svg');
  10632. var ariaLabel = '';
  10633. if (config && config.title) {
  10634. var titleElement = createNS('title');
  10635. var titleId = createElementID();
  10636. titleElement.setAttribute('id', titleId);
  10637. titleElement.textContent = config.title;
  10638. this.svgElement.appendChild(titleElement);
  10639. ariaLabel += titleId;
  10640. }
  10641. if (config && config.description) {
  10642. var descElement = createNS('desc');
  10643. var descId = createElementID();
  10644. descElement.setAttribute('id', descId);
  10645. descElement.textContent = config.description;
  10646. this.svgElement.appendChild(descElement);
  10647. ariaLabel += ' ' + descId;
  10648. }
  10649. if (ariaLabel) {
  10650. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10651. }
  10652. var defs = createNS('defs');
  10653. this.svgElement.appendChild(defs);
  10654. var maskElement = createNS('g');
  10655. this.svgElement.appendChild(maskElement);
  10656. this.layerElement = maskElement;
  10657. this.renderConfig = {
  10658. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  10659. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  10660. contentVisibility: (config && config.contentVisibility) || 'visible',
  10661. progressiveLoad: (config && config.progressiveLoad) || false,
  10662. hideOnTransparent: !((config && config.hideOnTransparent === false)),
  10663. viewBoxOnly: (config && config.viewBoxOnly) || false,
  10664. viewBoxSize: (config && config.viewBoxSize) || false,
  10665. className: (config && config.className) || '',
  10666. id: (config && config.id) || '',
  10667. focusable: config && config.focusable,
  10668. filterSize: {
  10669. width: (config && config.filterSize && config.filterSize.width) || '100%',
  10670. height: (config && config.filterSize && config.filterSize.height) || '100%',
  10671. x: (config && config.filterSize && config.filterSize.x) || '0%',
  10672. y: (config && config.filterSize && config.filterSize.y) || '0%',
  10673. },
  10674. width: (config && config.width),
  10675. height: (config && config.height),
  10676. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  10677. };
  10678. this.globalData = {
  10679. _mdf: false,
  10680. frameNum: -1,
  10681. defs: defs,
  10682. renderConfig: this.renderConfig,
  10683. };
  10684. this.elements = [];
  10685. this.pendingElements = [];
  10686. this.destroyed = false;
  10687. this.rendererType = 'svg';
  10688. }
  10689. extendPrototype([SVGRendererBase], SVGRenderer);
  10690. SVGRenderer.prototype.createComp = function (data) {
  10691. return new SVGCompElement(data, this.globalData, this);
  10692. };
  10693. function ShapeTransformManager() {
  10694. this.sequences = {};
  10695. this.sequenceList = [];
  10696. this.transform_key_count = 0;
  10697. }
  10698. ShapeTransformManager.prototype = {
  10699. addTransformSequence: function (transforms) {
  10700. var i;
  10701. var len = transforms.length;
  10702. var key = '_';
  10703. for (i = 0; i < len; i += 1) {
  10704. key += transforms[i].transform.key + '_';
  10705. }
  10706. var sequence = this.sequences[key];
  10707. if (!sequence) {
  10708. sequence = {
  10709. transforms: [].concat(transforms),
  10710. finalTransform: new Matrix(),
  10711. _mdf: false,
  10712. };
  10713. this.sequences[key] = sequence;
  10714. this.sequenceList.push(sequence);
  10715. }
  10716. return sequence;
  10717. },
  10718. processSequence: function (sequence, isFirstFrame) {
  10719. var i = 0;
  10720. var len = sequence.transforms.length;
  10721. var _mdf = isFirstFrame;
  10722. while (i < len && !isFirstFrame) {
  10723. if (sequence.transforms[i].transform.mProps._mdf) {
  10724. _mdf = true;
  10725. break;
  10726. }
  10727. i += 1;
  10728. }
  10729. if (_mdf) {
  10730. sequence.finalTransform.reset();
  10731. for (i = len - 1; i >= 0; i -= 1) {
  10732. sequence.finalTransform.multiply(sequence.transforms[i].transform.mProps.v);
  10733. }
  10734. }
  10735. sequence._mdf = _mdf;
  10736. },
  10737. processSequences: function (isFirstFrame) {
  10738. var i;
  10739. var len = this.sequenceList.length;
  10740. for (i = 0; i < len; i += 1) {
  10741. this.processSequence(this.sequenceList[i], isFirstFrame);
  10742. }
  10743. },
  10744. getNewKey: function () {
  10745. this.transform_key_count += 1;
  10746. return '_' + this.transform_key_count;
  10747. },
  10748. };
  10749. var lumaLoader = (function () {
  10750. var id = '__lottie_element_luma_buffer';
  10751. var lumaBuffer = null;
  10752. var lumaBufferCtx = null;
  10753. var svg = null;
  10754. // This alternate solution has a slight delay before the filter is applied, resulting in a flicker on the first frame.
  10755. // Keeping this here for reference, and in the future, if offscreen canvas supports url filters, this can be used.
  10756. // For now, neither of them work for offscreen canvas, so canvas workers can't support the luma track matte mask.
  10757. // Naming it solution 2 to mark the extra comment lines.
  10758. /*
  10759. var svgString = [
  10760. '<svg xmlns="http://www.w3.org/2000/svg">',
  10761. '<filter id="' + id + '">',
  10762. '<feColorMatrix type="matrix" color-interpolation-filters="sRGB" values="',
  10763. '0.3, 0.3, 0.3, 0, 0, ',
  10764. '0.3, 0.3, 0.3, 0, 0, ',
  10765. '0.3, 0.3, 0.3, 0, 0, ',
  10766. '0.3, 0.3, 0.3, 0, 0',
  10767. '"/>',
  10768. '</filter>',
  10769. '</svg>',
  10770. ].join('');
  10771. var blob = new Blob([svgString], { type: 'image/svg+xml' });
  10772. var url = URL.createObjectURL(blob);
  10773. */
  10774. function createLumaSvgFilter() {
  10775. var _svg = createNS('svg');
  10776. var fil = createNS('filter');
  10777. var matrix = createNS('feColorMatrix');
  10778. fil.setAttribute('id', id);
  10779. matrix.setAttribute('type', 'matrix');
  10780. matrix.setAttribute('color-interpolation-filters', 'sRGB');
  10781. matrix.setAttribute('values', '0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0');
  10782. fil.appendChild(matrix);
  10783. _svg.appendChild(fil);
  10784. _svg.setAttribute('id', id + '_svg');
  10785. if (featureSupport.svgLumaHidden) {
  10786. _svg.style.display = 'none';
  10787. }
  10788. return _svg;
  10789. }
  10790. function loadLuma() {
  10791. if (!lumaBuffer) {
  10792. svg = createLumaSvgFilter();
  10793. document.body.appendChild(svg);
  10794. lumaBuffer = createTag('canvas');
  10795. lumaBufferCtx = lumaBuffer.getContext('2d');
  10796. // lumaBufferCtx.filter = `url('${url}#__lottie_element_luma_buffer')`; // part of solution 2
  10797. lumaBufferCtx.filter = 'url(#' + id + ')';
  10798. lumaBufferCtx.fillStyle = 'rgba(0,0,0,0)';
  10799. lumaBufferCtx.fillRect(0, 0, 1, 1);
  10800. }
  10801. }
  10802. function getLuma(canvas) {
  10803. if (!lumaBuffer) {
  10804. loadLuma();
  10805. }
  10806. lumaBuffer.width = canvas.width;
  10807. lumaBuffer.height = canvas.height;
  10808. // lumaBufferCtx.filter = `url('${url}#__lottie_element_luma_buffer')`; // part of solution 2
  10809. lumaBufferCtx.filter = 'url(#' + id + ')';
  10810. return lumaBuffer;
  10811. }
  10812. return {
  10813. load: loadLuma,
  10814. get: getLuma,
  10815. };
  10816. });
  10817. function createCanvas(width, height) {
  10818. if (featureSupport.offscreenCanvas) {
  10819. return new OffscreenCanvas(width, height);
  10820. }
  10821. var canvas = createTag('canvas');
  10822. canvas.width = width;
  10823. canvas.height = height;
  10824. return canvas;
  10825. }
  10826. const assetLoader = (function () {
  10827. return {
  10828. loadLumaCanvas: lumaLoader.load,
  10829. getLumaCanvas: lumaLoader.get,
  10830. createCanvas: createCanvas,
  10831. };
  10832. }());
  10833. var registeredEffects = {};
  10834. function CVEffects(elem) {
  10835. var i;
  10836. var len = elem.data.ef ? elem.data.ef.length : 0;
  10837. this.filters = [];
  10838. var filterManager;
  10839. for (i = 0; i < len; i += 1) {
  10840. filterManager = null;
  10841. var type = elem.data.ef[i].ty;
  10842. if (registeredEffects[type]) {
  10843. var Effect = registeredEffects[type].effect;
  10844. filterManager = new Effect(elem.effectsManager.effectElements[i], elem);
  10845. }
  10846. if (filterManager) {
  10847. this.filters.push(filterManager);
  10848. }
  10849. }
  10850. if (this.filters.length) {
  10851. elem.addRenderableComponent(this);
  10852. }
  10853. }
  10854. CVEffects.prototype.renderFrame = function (_isFirstFrame) {
  10855. var i;
  10856. var len = this.filters.length;
  10857. for (i = 0; i < len; i += 1) {
  10858. this.filters[i].renderFrame(_isFirstFrame);
  10859. }
  10860. };
  10861. CVEffects.prototype.getEffects = function (type) {
  10862. var i;
  10863. var len = this.filters.length;
  10864. var effects = [];
  10865. for (i = 0; i < len; i += 1) {
  10866. if (this.filters[i].type === type) {
  10867. effects.push(this.filters[i]);
  10868. }
  10869. }
  10870. return effects;
  10871. };
  10872. function registerEffect(id, effect) {
  10873. registeredEffects[id] = {
  10874. effect,
  10875. };
  10876. }
  10877. function CVMaskElement(data, element) {
  10878. this.data = data;
  10879. this.element = element;
  10880. this.masksProperties = this.data.masksProperties || [];
  10881. this.viewData = createSizedArray(this.masksProperties.length);
  10882. var i;
  10883. var len = this.masksProperties.length;
  10884. var hasMasks = false;
  10885. for (i = 0; i < len; i += 1) {
  10886. if (this.masksProperties[i].mode !== 'n') {
  10887. hasMasks = true;
  10888. }
  10889. this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element, this.masksProperties[i], 3);
  10890. }
  10891. this.hasMasks = hasMasks;
  10892. if (hasMasks) {
  10893. this.element.addRenderableComponent(this);
  10894. }
  10895. }
  10896. CVMaskElement.prototype.renderFrame = function () {
  10897. if (!this.hasMasks) {
  10898. return;
  10899. }
  10900. var transform = this.element.finalTransform.mat;
  10901. var ctx = this.element.canvasContext;
  10902. var i;
  10903. var len = this.masksProperties.length;
  10904. var pt;
  10905. var pts;
  10906. var data;
  10907. ctx.beginPath();
  10908. for (i = 0; i < len; i += 1) {
  10909. if (this.masksProperties[i].mode !== 'n') {
  10910. if (this.masksProperties[i].inv) {
  10911. ctx.moveTo(0, 0);
  10912. ctx.lineTo(this.element.globalData.compSize.w, 0);
  10913. ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h);
  10914. ctx.lineTo(0, this.element.globalData.compSize.h);
  10915. ctx.lineTo(0, 0);
  10916. }
  10917. data = this.viewData[i].v;
  10918. pt = transform.applyToPointArray(data.v[0][0], data.v[0][1], 0);
  10919. ctx.moveTo(pt[0], pt[1]);
  10920. var j;
  10921. var jLen = data._length;
  10922. for (j = 1; j < jLen; j += 1) {
  10923. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]);
  10924. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  10925. }
  10926. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]);
  10927. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  10928. }
  10929. }
  10930. this.element.globalData.renderer.save(true);
  10931. ctx.clip();
  10932. };
  10933. CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty;
  10934. CVMaskElement.prototype.destroy = function () {
  10935. this.element = null;
  10936. };
  10937. function CVBaseElement() {
  10938. }
  10939. var operationsMap = {
  10940. 1: 'source-in',
  10941. 2: 'source-out',
  10942. 3: 'source-in',
  10943. 4: 'source-out',
  10944. };
  10945. CVBaseElement.prototype = {
  10946. createElements: function () {},
  10947. initRendererElement: function () {},
  10948. createContainerElements: function () {
  10949. // If the layer is masked we will use two buffers to store each different states of the drawing
  10950. // This solution is not ideal for several reason. But unfortunately, because of the recursive
  10951. // nature of the render tree, it's the only simple way to make sure one inner mask doesn't override an outer mask.
  10952. // TODO: try to reduce the size of these buffers to the size of the composition contaning the layer
  10953. // It might be challenging because the layer most likely is transformed in some way
  10954. if (this.data.tt >= 1) {
  10955. this.buffers = [];
  10956. var canvasContext = this.globalData.canvasContext;
  10957. var bufferCanvas = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
  10958. this.buffers.push(bufferCanvas);
  10959. var bufferCanvas2 = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
  10960. this.buffers.push(bufferCanvas2);
  10961. if (this.data.tt >= 3 && !document._isProxy) {
  10962. assetLoader.loadLumaCanvas();
  10963. }
  10964. }
  10965. this.canvasContext = this.globalData.canvasContext;
  10966. this.transformCanvas = this.globalData.transformCanvas;
  10967. this.renderableEffectsManager = new CVEffects(this);
  10968. this.searchEffectTransforms();
  10969. },
  10970. createContent: function () {},
  10971. setBlendMode: function () {
  10972. var globalData = this.globalData;
  10973. if (globalData.blendMode !== this.data.bm) {
  10974. globalData.blendMode = this.data.bm;
  10975. var blendModeValue = getBlendMode(this.data.bm);
  10976. globalData.canvasContext.globalCompositeOperation = blendModeValue;
  10977. }
  10978. },
  10979. createRenderableComponents: function () {
  10980. this.maskManager = new CVMaskElement(this.data, this);
  10981. this.transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  10982. },
  10983. hideElement: function () {
  10984. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  10985. this.hidden = true;
  10986. }
  10987. },
  10988. showElement: function () {
  10989. if (this.isInRange && !this.isTransparent) {
  10990. this.hidden = false;
  10991. this._isFirstFrame = true;
  10992. this.maskManager._isFirstFrame = true;
  10993. }
  10994. },
  10995. clearCanvas: function (canvasContext) {
  10996. canvasContext.clearRect(
  10997. this.transformCanvas.tx,
  10998. this.transformCanvas.ty,
  10999. this.transformCanvas.w * this.transformCanvas.sx,
  11000. this.transformCanvas.h * this.transformCanvas.sy
  11001. );
  11002. },
  11003. prepareLayer: function () {
  11004. if (this.data.tt >= 1) {
  11005. var buffer = this.buffers[0];
  11006. var bufferCtx = buffer.getContext('2d');
  11007. this.clearCanvas(bufferCtx);
  11008. // on the first buffer we store the current state of the global drawing
  11009. bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11010. // The next four lines are to clear the canvas
  11011. // TODO: Check if there is a way to clear the canvas without resetting the transform
  11012. this.currentTransform = this.canvasContext.getTransform();
  11013. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11014. this.clearCanvas(this.canvasContext);
  11015. this.canvasContext.setTransform(this.currentTransform);
  11016. }
  11017. },
  11018. exitLayer: function () {
  11019. if (this.data.tt >= 1) {
  11020. var buffer = this.buffers[1];
  11021. // On the second buffer we store the current state of the global drawing
  11022. // that only contains the content of this layer
  11023. // (if it is a composition, it also includes the nested layers)
  11024. var bufferCtx = buffer.getContext('2d');
  11025. this.clearCanvas(bufferCtx);
  11026. bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11027. // We clear the canvas again
  11028. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11029. this.clearCanvas(this.canvasContext);
  11030. this.canvasContext.setTransform(this.currentTransform);
  11031. // We draw the mask
  11032. const mask = this.comp.getElementById('tp' in this.data ? this.data.tp : this.data.ind - 1);
  11033. mask.renderFrame(true);
  11034. // We draw the second buffer (that contains the content of this layer)
  11035. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11036. // If the mask is a Luma matte, we need to do two extra painting operations
  11037. // the _isProxy check is to avoid drawing a fake canvas in workers that will throw an error
  11038. if (this.data.tt >= 3 && !document._isProxy) {
  11039. // We copy the painted mask to a buffer that has a color matrix filter applied to it
  11040. // that applies the rgb values to the alpha channel
  11041. var lumaBuffer = assetLoader.getLumaCanvas(this.canvasContext.canvas);
  11042. var lumaBufferCtx = lumaBuffer.getContext('2d');
  11043. lumaBufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11044. this.clearCanvas(this.canvasContext);
  11045. // we repaint the context with the mask applied to it
  11046. this.canvasContext.drawImage(lumaBuffer, 0, 0);
  11047. }
  11048. this.canvasContext.globalCompositeOperation = operationsMap[this.data.tt];
  11049. this.canvasContext.drawImage(buffer, 0, 0);
  11050. // We finally draw the first buffer (that contains the content of the global drawing)
  11051. // We use destination-over to draw the global drawing below the current layer
  11052. this.canvasContext.globalCompositeOperation = 'destination-over';
  11053. this.canvasContext.drawImage(this.buffers[0], 0, 0);
  11054. this.canvasContext.setTransform(this.currentTransform);
  11055. // We reset the globalCompositeOperation to source-over, the standard type of operation
  11056. this.canvasContext.globalCompositeOperation = 'source-over';
  11057. }
  11058. },
  11059. renderFrame: function (forceRender) {
  11060. if (this.hidden || this.data.hd) {
  11061. return;
  11062. }
  11063. if (this.data.td === 1 && !forceRender) {
  11064. return;
  11065. }
  11066. this.renderTransform();
  11067. this.renderRenderable();
  11068. this.renderLocalTransform();
  11069. this.setBlendMode();
  11070. var forceRealStack = this.data.ty === 0;
  11071. this.prepareLayer();
  11072. this.globalData.renderer.save(forceRealStack);
  11073. this.globalData.renderer.ctxTransform(this.finalTransform.localMat.props);
  11074. this.globalData.renderer.ctxOpacity(this.finalTransform.localOpacity);
  11075. this.renderInnerContent();
  11076. this.globalData.renderer.restore(forceRealStack);
  11077. this.exitLayer();
  11078. if (this.maskManager.hasMasks) {
  11079. this.globalData.renderer.restore(true);
  11080. }
  11081. if (this._isFirstFrame) {
  11082. this._isFirstFrame = false;
  11083. }
  11084. },
  11085. destroy: function () {
  11086. this.canvasContext = null;
  11087. this.data = null;
  11088. this.globalData = null;
  11089. this.maskManager.destroy();
  11090. },
  11091. mHelper: new Matrix(),
  11092. };
  11093. CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement;
  11094. CVBaseElement.prototype.show = CVBaseElement.prototype.showElement;
  11095. function CVShapeData(element, data, styles, transformsManager) {
  11096. this.styledShapes = [];
  11097. this.tr = [0, 0, 0, 0, 0, 0];
  11098. var ty = 4;
  11099. if (data.ty === 'rc') {
  11100. ty = 5;
  11101. } else if (data.ty === 'el') {
  11102. ty = 6;
  11103. } else if (data.ty === 'sr') {
  11104. ty = 7;
  11105. }
  11106. this.sh = ShapePropertyFactory.getShapeProp(element, data, ty, element);
  11107. var i;
  11108. var len = styles.length;
  11109. var styledShape;
  11110. for (i = 0; i < len; i += 1) {
  11111. if (!styles[i].closed) {
  11112. styledShape = {
  11113. transforms: transformsManager.addTransformSequence(styles[i].transforms),
  11114. trNodes: [],
  11115. };
  11116. this.styledShapes.push(styledShape);
  11117. styles[i].elements.push(styledShape);
  11118. }
  11119. }
  11120. }
  11121. CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated;
  11122. function CVShapeElement(data, globalData, comp) {
  11123. this.shapes = [];
  11124. this.shapesData = data.shapes;
  11125. this.stylesList = [];
  11126. this.itemsData = [];
  11127. this.prevViewData = [];
  11128. this.shapeModifiers = [];
  11129. this.processedElements = [];
  11130. this.transformsManager = new ShapeTransformManager();
  11131. this.initElement(data, globalData, comp);
  11132. }
  11133. extendPrototype([BaseElement, TransformElement, CVBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableElement], CVShapeElement);
  11134. CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement;
  11135. CVShapeElement.prototype.transformHelper = { opacity: 1, _opMdf: false };
  11136. CVShapeElement.prototype.dashResetter = [];
  11137. CVShapeElement.prototype.createContent = function () {
  11138. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11139. };
  11140. CVShapeElement.prototype.createStyleElement = function (data, transforms) {
  11141. var styleElem = {
  11142. data: data,
  11143. type: data.ty,
  11144. preTransforms: this.transformsManager.addTransformSequence(transforms),
  11145. transforms: [],
  11146. elements: [],
  11147. closed: data.hd === true,
  11148. };
  11149. var elementData = {};
  11150. if (data.ty === 'fl' || data.ty === 'st') {
  11151. elementData.c = PropertyFactory.getProp(this, data.c, 1, 255, this);
  11152. if (!elementData.c.k) {
  11153. styleElem.co = 'rgb(' + bmFloor(elementData.c.v[0]) + ',' + bmFloor(elementData.c.v[1]) + ',' + bmFloor(elementData.c.v[2]) + ')';
  11154. }
  11155. } else if (data.ty === 'gf' || data.ty === 'gs') {
  11156. elementData.s = PropertyFactory.getProp(this, data.s, 1, null, this);
  11157. elementData.e = PropertyFactory.getProp(this, data.e, 1, null, this);
  11158. elementData.h = PropertyFactory.getProp(this, data.h || { k: 0 }, 0, 0.01, this);
  11159. elementData.a = PropertyFactory.getProp(this, data.a || { k: 0 }, 0, degToRads, this);
  11160. elementData.g = new GradientProperty(this, data.g, this);
  11161. }
  11162. elementData.o = PropertyFactory.getProp(this, data.o, 0, 0.01, this);
  11163. if (data.ty === 'st' || data.ty === 'gs') {
  11164. styleElem.lc = lineCapEnum[data.lc || 2];
  11165. styleElem.lj = lineJoinEnum[data.lj || 2];
  11166. if (data.lj == 1) { // eslint-disable-line eqeqeq
  11167. styleElem.ml = data.ml;
  11168. }
  11169. elementData.w = PropertyFactory.getProp(this, data.w, 0, null, this);
  11170. if (!elementData.w.k) {
  11171. styleElem.wi = elementData.w.v;
  11172. }
  11173. if (data.d) {
  11174. var d = new DashProperty(this, data.d, 'canvas', this);
  11175. elementData.d = d;
  11176. if (!elementData.d.k) {
  11177. styleElem.da = elementData.d.dashArray;
  11178. styleElem.do = elementData.d.dashoffset[0];
  11179. }
  11180. }
  11181. } else {
  11182. styleElem.r = data.r === 2 ? 'evenodd' : 'nonzero';
  11183. }
  11184. this.stylesList.push(styleElem);
  11185. elementData.style = styleElem;
  11186. return elementData;
  11187. };
  11188. CVShapeElement.prototype.createGroupElement = function () {
  11189. var elementData = {
  11190. it: [],
  11191. prevViewData: [],
  11192. };
  11193. return elementData;
  11194. };
  11195. CVShapeElement.prototype.createTransformElement = function (data) {
  11196. var elementData = {
  11197. transform: {
  11198. opacity: 1,
  11199. _opMdf: false,
  11200. key: this.transformsManager.getNewKey(),
  11201. op: PropertyFactory.getProp(this, data.o, 0, 0.01, this),
  11202. mProps: TransformPropertyFactory.getTransformProperty(this, data, this),
  11203. },
  11204. };
  11205. return elementData;
  11206. };
  11207. CVShapeElement.prototype.createShapeElement = function (data) {
  11208. var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager);
  11209. this.shapes.push(elementData);
  11210. this.addShapeToModifiers(elementData);
  11211. return elementData;
  11212. };
  11213. CVShapeElement.prototype.reloadShapes = function () {
  11214. this._isFirstFrame = true;
  11215. var i;
  11216. var len = this.itemsData.length;
  11217. for (i = 0; i < len; i += 1) {
  11218. this.prevViewData[i] = this.itemsData[i];
  11219. }
  11220. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11221. len = this.dynamicProperties.length;
  11222. for (i = 0; i < len; i += 1) {
  11223. this.dynamicProperties[i].getValue();
  11224. }
  11225. this.renderModifiers();
  11226. this.transformsManager.processSequences(this._isFirstFrame);
  11227. };
  11228. CVShapeElement.prototype.addTransformToStyleList = function (transform) {
  11229. var i;
  11230. var len = this.stylesList.length;
  11231. for (i = 0; i < len; i += 1) {
  11232. if (!this.stylesList[i].closed) {
  11233. this.stylesList[i].transforms.push(transform);
  11234. }
  11235. }
  11236. };
  11237. CVShapeElement.prototype.removeTransformFromStyleList = function () {
  11238. var i;
  11239. var len = this.stylesList.length;
  11240. for (i = 0; i < len; i += 1) {
  11241. if (!this.stylesList[i].closed) {
  11242. this.stylesList[i].transforms.pop();
  11243. }
  11244. }
  11245. };
  11246. CVShapeElement.prototype.closeStyles = function (styles) {
  11247. var i;
  11248. var len = styles.length;
  11249. for (i = 0; i < len; i += 1) {
  11250. styles[i].closed = true;
  11251. }
  11252. };
  11253. CVShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, shouldRender, transforms) {
  11254. var i;
  11255. var len = arr.length - 1;
  11256. var j;
  11257. var jLen;
  11258. var ownStyles = [];
  11259. var ownModifiers = [];
  11260. var processedPos;
  11261. var modifier;
  11262. var currentTransform;
  11263. var ownTransforms = [].concat(transforms);
  11264. for (i = len; i >= 0; i -= 1) {
  11265. processedPos = this.searchProcessedElement(arr[i]);
  11266. if (!processedPos) {
  11267. arr[i]._shouldRender = shouldRender;
  11268. } else {
  11269. itemsData[i] = prevViewData[processedPos - 1];
  11270. }
  11271. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs') {
  11272. if (!processedPos) {
  11273. itemsData[i] = this.createStyleElement(arr[i], ownTransforms);
  11274. } else {
  11275. itemsData[i].style.closed = false;
  11276. }
  11277. ownStyles.push(itemsData[i].style);
  11278. } else if (arr[i].ty === 'gr') {
  11279. if (!processedPos) {
  11280. itemsData[i] = this.createGroupElement(arr[i]);
  11281. } else {
  11282. jLen = itemsData[i].it.length;
  11283. for (j = 0; j < jLen; j += 1) {
  11284. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  11285. }
  11286. }
  11287. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, shouldRender, ownTransforms);
  11288. } else if (arr[i].ty === 'tr') {
  11289. if (!processedPos) {
  11290. currentTransform = this.createTransformElement(arr[i]);
  11291. itemsData[i] = currentTransform;
  11292. }
  11293. ownTransforms.push(itemsData[i]);
  11294. this.addTransformToStyleList(itemsData[i]);
  11295. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  11296. if (!processedPos) {
  11297. itemsData[i] = this.createShapeElement(arr[i]);
  11298. }
  11299. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  11300. if (!processedPos) {
  11301. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11302. modifier.init(this, arr[i]);
  11303. itemsData[i] = modifier;
  11304. this.shapeModifiers.push(modifier);
  11305. } else {
  11306. modifier = itemsData[i];
  11307. modifier.closed = false;
  11308. }
  11309. ownModifiers.push(modifier);
  11310. } else if (arr[i].ty === 'rp') {
  11311. if (!processedPos) {
  11312. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11313. itemsData[i] = modifier;
  11314. modifier.init(this, arr, i, itemsData);
  11315. this.shapeModifiers.push(modifier);
  11316. shouldRender = false;
  11317. } else {
  11318. modifier = itemsData[i];
  11319. modifier.closed = true;
  11320. }
  11321. ownModifiers.push(modifier);
  11322. }
  11323. this.addProcessedElement(arr[i], i + 1);
  11324. }
  11325. this.removeTransformFromStyleList();
  11326. this.closeStyles(ownStyles);
  11327. len = ownModifiers.length;
  11328. for (i = 0; i < len; i += 1) {
  11329. ownModifiers[i].closed = true;
  11330. }
  11331. };
  11332. CVShapeElement.prototype.renderInnerContent = function () {
  11333. this.transformHelper.opacity = 1;
  11334. this.transformHelper._opMdf = false;
  11335. this.renderModifiers();
  11336. this.transformsManager.processSequences(this._isFirstFrame);
  11337. this.renderShape(this.transformHelper, this.shapesData, this.itemsData, true);
  11338. };
  11339. CVShapeElement.prototype.renderShapeTransform = function (parentTransform, groupTransform) {
  11340. if (parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) {
  11341. groupTransform.opacity = parentTransform.opacity;
  11342. groupTransform.opacity *= groupTransform.op.v;
  11343. groupTransform._opMdf = true;
  11344. }
  11345. };
  11346. CVShapeElement.prototype.drawLayer = function () {
  11347. var i;
  11348. var len = this.stylesList.length;
  11349. var j;
  11350. var jLen;
  11351. var k;
  11352. var kLen;
  11353. var elems;
  11354. var nodes;
  11355. var renderer = this.globalData.renderer;
  11356. var ctx = this.globalData.canvasContext;
  11357. var type;
  11358. var currentStyle;
  11359. for (i = 0; i < len; i += 1) {
  11360. currentStyle = this.stylesList[i];
  11361. type = currentStyle.type;
  11362. // Skipping style when
  11363. // Stroke width equals 0
  11364. // style should not be rendered (extra unused repeaters)
  11365. // current opacity equals 0
  11366. // global opacity equals 0
  11367. if (!(((type === 'st' || type === 'gs') && currentStyle.wi === 0) || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0)) {
  11368. renderer.save();
  11369. elems = currentStyle.elements;
  11370. if (type === 'st' || type === 'gs') {
  11371. renderer.ctxStrokeStyle(type === 'st' ? currentStyle.co : currentStyle.grd);
  11372. // ctx.strokeStyle = type === 'st' ? currentStyle.co : currentStyle.grd;
  11373. renderer.ctxLineWidth(currentStyle.wi);
  11374. // ctx.lineWidth = currentStyle.wi;
  11375. renderer.ctxLineCap(currentStyle.lc);
  11376. // ctx.lineCap = currentStyle.lc;
  11377. renderer.ctxLineJoin(currentStyle.lj);
  11378. // ctx.lineJoin = currentStyle.lj;
  11379. renderer.ctxMiterLimit(currentStyle.ml || 0);
  11380. // ctx.miterLimit = currentStyle.ml || 0;
  11381. } else {
  11382. renderer.ctxFillStyle(type === 'fl' ? currentStyle.co : currentStyle.grd);
  11383. // ctx.fillStyle = type === 'fl' ? currentStyle.co : currentStyle.grd;
  11384. }
  11385. renderer.ctxOpacity(currentStyle.coOp);
  11386. if (type !== 'st' && type !== 'gs') {
  11387. ctx.beginPath();
  11388. }
  11389. renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props);
  11390. jLen = elems.length;
  11391. for (j = 0; j < jLen; j += 1) {
  11392. if (type === 'st' || type === 'gs') {
  11393. ctx.beginPath();
  11394. if (currentStyle.da) {
  11395. ctx.setLineDash(currentStyle.da);
  11396. ctx.lineDashOffset = currentStyle.do;
  11397. }
  11398. }
  11399. nodes = elems[j].trNodes;
  11400. kLen = nodes.length;
  11401. for (k = 0; k < kLen; k += 1) {
  11402. if (nodes[k].t === 'm') {
  11403. ctx.moveTo(nodes[k].p[0], nodes[k].p[1]);
  11404. } else if (nodes[k].t === 'c') {
  11405. ctx.bezierCurveTo(nodes[k].pts[0], nodes[k].pts[1], nodes[k].pts[2], nodes[k].pts[3], nodes[k].pts[4], nodes[k].pts[5]);
  11406. } else {
  11407. ctx.closePath();
  11408. }
  11409. }
  11410. if (type === 'st' || type === 'gs') {
  11411. // ctx.stroke();
  11412. renderer.ctxStroke();
  11413. if (currentStyle.da) {
  11414. ctx.setLineDash(this.dashResetter);
  11415. }
  11416. }
  11417. }
  11418. if (type !== 'st' && type !== 'gs') {
  11419. // ctx.fill(currentStyle.r);
  11420. this.globalData.renderer.ctxFill(currentStyle.r);
  11421. }
  11422. renderer.restore();
  11423. }
  11424. }
  11425. };
  11426. CVShapeElement.prototype.renderShape = function (parentTransform, items, data, isMain) {
  11427. var i;
  11428. var len = items.length - 1;
  11429. var groupTransform;
  11430. groupTransform = parentTransform;
  11431. for (i = len; i >= 0; i -= 1) {
  11432. if (items[i].ty === 'tr') {
  11433. groupTransform = data[i].transform;
  11434. this.renderShapeTransform(parentTransform, groupTransform);
  11435. } else if (items[i].ty === 'sh' || items[i].ty === 'el' || items[i].ty === 'rc' || items[i].ty === 'sr') {
  11436. this.renderPath(items[i], data[i]);
  11437. } else if (items[i].ty === 'fl') {
  11438. this.renderFill(items[i], data[i], groupTransform);
  11439. } else if (items[i].ty === 'st') {
  11440. this.renderStroke(items[i], data[i], groupTransform);
  11441. } else if (items[i].ty === 'gf' || items[i].ty === 'gs') {
  11442. this.renderGradientFill(items[i], data[i], groupTransform);
  11443. } else if (items[i].ty === 'gr') {
  11444. this.renderShape(groupTransform, items[i].it, data[i].it);
  11445. } else if (items[i].ty === 'tm') {
  11446. //
  11447. }
  11448. }
  11449. if (isMain) {
  11450. this.drawLayer();
  11451. }
  11452. };
  11453. CVShapeElement.prototype.renderStyledShape = function (styledShape, shape) {
  11454. if (this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) {
  11455. var shapeNodes = styledShape.trNodes;
  11456. var paths = shape.paths;
  11457. var i;
  11458. var len;
  11459. var j;
  11460. var jLen = paths._length;
  11461. shapeNodes.length = 0;
  11462. var groupTransformMat = styledShape.transforms.finalTransform;
  11463. for (j = 0; j < jLen; j += 1) {
  11464. var pathNodes = paths.shapes[j];
  11465. if (pathNodes && pathNodes.v) {
  11466. len = pathNodes._length;
  11467. for (i = 1; i < len; i += 1) {
  11468. if (i === 1) {
  11469. shapeNodes.push({
  11470. t: 'm',
  11471. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0),
  11472. });
  11473. }
  11474. shapeNodes.push({
  11475. t: 'c',
  11476. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i]),
  11477. });
  11478. }
  11479. if (len === 1) {
  11480. shapeNodes.push({
  11481. t: 'm',
  11482. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0),
  11483. });
  11484. }
  11485. if (pathNodes.c && len) {
  11486. shapeNodes.push({
  11487. t: 'c',
  11488. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0]),
  11489. });
  11490. shapeNodes.push({
  11491. t: 'z',
  11492. });
  11493. }
  11494. }
  11495. }
  11496. styledShape.trNodes = shapeNodes;
  11497. }
  11498. };
  11499. CVShapeElement.prototype.renderPath = function (pathData, itemData) {
  11500. if (pathData.hd !== true && pathData._shouldRender) {
  11501. var i;
  11502. var len = itemData.styledShapes.length;
  11503. for (i = 0; i < len; i += 1) {
  11504. this.renderStyledShape(itemData.styledShapes[i], itemData.sh);
  11505. }
  11506. }
  11507. };
  11508. CVShapeElement.prototype.renderFill = function (styleData, itemData, groupTransform) {
  11509. var styleElem = itemData.style;
  11510. if (itemData.c._mdf || this._isFirstFrame) {
  11511. styleElem.co = 'rgb('
  11512. + bmFloor(itemData.c.v[0]) + ','
  11513. + bmFloor(itemData.c.v[1]) + ','
  11514. + bmFloor(itemData.c.v[2]) + ')';
  11515. }
  11516. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11517. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11518. }
  11519. };
  11520. CVShapeElement.prototype.renderGradientFill = function (styleData, itemData, groupTransform) {
  11521. var styleElem = itemData.style;
  11522. var grd;
  11523. if (!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || (styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf))) {
  11524. var ctx = this.globalData.canvasContext;
  11525. var pt1 = itemData.s.v;
  11526. var pt2 = itemData.e.v;
  11527. if (styleData.t === 1) {
  11528. grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]);
  11529. } else {
  11530. var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  11531. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  11532. var percent = itemData.h.v;
  11533. if (percent >= 1) {
  11534. percent = 0.99;
  11535. } else if (percent <= -1) {
  11536. percent = -0.99;
  11537. }
  11538. var dist = rad * percent;
  11539. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  11540. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  11541. grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad);
  11542. }
  11543. var i;
  11544. var len = styleData.g.p;
  11545. var cValues = itemData.g.c;
  11546. var opacity = 1;
  11547. for (i = 0; i < len; i += 1) {
  11548. if (itemData.g._hasOpacity && itemData.g._collapsable) {
  11549. opacity = itemData.g.o[i * 2 + 1];
  11550. }
  11551. grd.addColorStop(cValues[i * 4] / 100, 'rgba(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ',' + opacity + ')');
  11552. }
  11553. styleElem.grd = grd;
  11554. }
  11555. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11556. };
  11557. CVShapeElement.prototype.renderStroke = function (styleData, itemData, groupTransform) {
  11558. var styleElem = itemData.style;
  11559. var d = itemData.d;
  11560. if (d && (d._mdf || this._isFirstFrame)) {
  11561. styleElem.da = d.dashArray;
  11562. styleElem.do = d.dashoffset[0];
  11563. }
  11564. if (itemData.c._mdf || this._isFirstFrame) {
  11565. styleElem.co = 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')';
  11566. }
  11567. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11568. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11569. }
  11570. if (itemData.w._mdf || this._isFirstFrame) {
  11571. styleElem.wi = itemData.w.v;
  11572. }
  11573. };
  11574. CVShapeElement.prototype.destroy = function () {
  11575. this.shapesData = null;
  11576. this.globalData = null;
  11577. this.canvasContext = null;
  11578. this.stylesList.length = 0;
  11579. this.itemsData.length = 0;
  11580. };
  11581. function CVTextElement(data, globalData, comp) {
  11582. this.textSpans = [];
  11583. this.yOffset = 0;
  11584. this.fillColorAnim = false;
  11585. this.strokeColorAnim = false;
  11586. this.strokeWidthAnim = false;
  11587. this.stroke = false;
  11588. this.fill = false;
  11589. this.justifyOffset = 0;
  11590. this.currentRender = null;
  11591. this.renderType = 'canvas';
  11592. this.values = {
  11593. fill: 'rgba(0,0,0,0)',
  11594. stroke: 'rgba(0,0,0,0)',
  11595. sWidth: 0,
  11596. fValue: '',
  11597. };
  11598. this.initElement(data, globalData, comp);
  11599. }
  11600. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement, ITextElement], CVTextElement);
  11601. CVTextElement.prototype.tHelper = createTag('canvas').getContext('2d');
  11602. CVTextElement.prototype.buildNewText = function () {
  11603. var documentData = this.textProperty.currentData;
  11604. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  11605. var hasFill = false;
  11606. if (documentData.fc) {
  11607. hasFill = true;
  11608. this.values.fill = this.buildColor(documentData.fc);
  11609. } else {
  11610. this.values.fill = 'rgba(0,0,0,0)';
  11611. }
  11612. this.fill = hasFill;
  11613. var hasStroke = false;
  11614. if (documentData.sc) {
  11615. hasStroke = true;
  11616. this.values.stroke = this.buildColor(documentData.sc);
  11617. this.values.sWidth = documentData.sw;
  11618. }
  11619. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  11620. var i;
  11621. var len;
  11622. var letters = documentData.l;
  11623. var matrixHelper = this.mHelper;
  11624. this.stroke = hasStroke;
  11625. this.values.fValue = documentData.finalSize + 'px ' + this.globalData.fontManager.getFontByName(documentData.f).fFamily;
  11626. len = documentData.finalText.length;
  11627. // this.tHelper.font = this.values.fValue;
  11628. var charData;
  11629. var shapeData;
  11630. var k;
  11631. var kLen;
  11632. var shapes;
  11633. var j;
  11634. var jLen;
  11635. var pathNodes;
  11636. var commands;
  11637. var pathArr;
  11638. var singleShape = this.data.singleShape;
  11639. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  11640. var xPos = 0;
  11641. var yPos = 0;
  11642. var firstLine = true;
  11643. var cnt = 0;
  11644. for (i = 0; i < len; i += 1) {
  11645. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  11646. shapeData = (charData && charData.data) || {};
  11647. matrixHelper.reset();
  11648. if (singleShape && letters[i].n) {
  11649. xPos = -trackingOffset;
  11650. yPos += documentData.yOffset;
  11651. yPos += firstLine ? 1 : 0;
  11652. firstLine = false;
  11653. }
  11654. shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
  11655. jLen = shapes.length;
  11656. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  11657. if (singleShape) {
  11658. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  11659. }
  11660. commands = createSizedArray(jLen - 1);
  11661. var commandsCounter = 0;
  11662. for (j = 0; j < jLen; j += 1) {
  11663. if (shapes[j].ty === 'sh') {
  11664. kLen = shapes[j].ks.k.i.length;
  11665. pathNodes = shapes[j].ks.k;
  11666. pathArr = [];
  11667. for (k = 1; k < kLen; k += 1) {
  11668. if (k === 1) {
  11669. pathArr.push(matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
  11670. }
  11671. pathArr.push(matrixHelper.applyToX(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToY(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToX(pathNodes.i[k][0], pathNodes.i[k][1], 0), matrixHelper.applyToY(pathNodes.i[k][0], pathNodes.i[k][1], 0), matrixHelper.applyToX(pathNodes.v[k][0], pathNodes.v[k][1], 0), matrixHelper.applyToY(pathNodes.v[k][0], pathNodes.v[k][1], 0));
  11672. }
  11673. pathArr.push(matrixHelper.applyToX(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToY(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToX(pathNodes.i[0][0], pathNodes.i[0][1], 0), matrixHelper.applyToY(pathNodes.i[0][0], pathNodes.i[0][1], 0), matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
  11674. commands[commandsCounter] = pathArr;
  11675. commandsCounter += 1;
  11676. }
  11677. }
  11678. if (singleShape) {
  11679. xPos += letters[i].l;
  11680. xPos += trackingOffset;
  11681. }
  11682. if (this.textSpans[cnt]) {
  11683. this.textSpans[cnt].elem = commands;
  11684. } else {
  11685. this.textSpans[cnt] = { elem: commands };
  11686. }
  11687. cnt += 1;
  11688. }
  11689. };
  11690. CVTextElement.prototype.renderInnerContent = function () {
  11691. this.validateText();
  11692. var ctx = this.canvasContext;
  11693. ctx.font = this.values.fValue;
  11694. this.globalData.renderer.ctxLineCap('butt');
  11695. // ctx.lineCap = 'butt';
  11696. this.globalData.renderer.ctxLineJoin('miter');
  11697. // ctx.lineJoin = 'miter';
  11698. this.globalData.renderer.ctxMiterLimit(4);
  11699. // ctx.miterLimit = 4;
  11700. if (!this.data.singleShape) {
  11701. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  11702. }
  11703. var i;
  11704. var len;
  11705. var j;
  11706. var jLen;
  11707. var k;
  11708. var kLen;
  11709. var renderedLetters = this.textAnimator.renderedLetters;
  11710. var letters = this.textProperty.currentData.l;
  11711. len = letters.length;
  11712. var renderedLetter;
  11713. var lastFill = null;
  11714. var lastStroke = null;
  11715. var lastStrokeW = null;
  11716. var commands;
  11717. var pathArr;
  11718. var renderer = this.globalData.renderer;
  11719. for (i = 0; i < len; i += 1) {
  11720. if (!letters[i].n) {
  11721. renderedLetter = renderedLetters[i];
  11722. if (renderedLetter) {
  11723. renderer.save();
  11724. renderer.ctxTransform(renderedLetter.p);
  11725. renderer.ctxOpacity(renderedLetter.o);
  11726. }
  11727. if (this.fill) {
  11728. if (renderedLetter && renderedLetter.fc) {
  11729. if (lastFill !== renderedLetter.fc) {
  11730. renderer.ctxFillStyle(renderedLetter.fc);
  11731. lastFill = renderedLetter.fc;
  11732. // ctx.fillStyle = renderedLetter.fc;
  11733. }
  11734. } else if (lastFill !== this.values.fill) {
  11735. lastFill = this.values.fill;
  11736. renderer.ctxFillStyle(this.values.fill);
  11737. // ctx.fillStyle = this.values.fill;
  11738. }
  11739. commands = this.textSpans[i].elem;
  11740. jLen = commands.length;
  11741. this.globalData.canvasContext.beginPath();
  11742. for (j = 0; j < jLen; j += 1) {
  11743. pathArr = commands[j];
  11744. kLen = pathArr.length;
  11745. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11746. for (k = 2; k < kLen; k += 6) {
  11747. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11748. }
  11749. }
  11750. this.globalData.canvasContext.closePath();
  11751. renderer.ctxFill();
  11752. // this.globalData.canvasContext.fill();
  11753. /// ctx.fillText(this.textSpans[i].val,0,0);
  11754. }
  11755. if (this.stroke) {
  11756. if (renderedLetter && renderedLetter.sw) {
  11757. if (lastStrokeW !== renderedLetter.sw) {
  11758. lastStrokeW = renderedLetter.sw;
  11759. renderer.ctxLineWidth(renderedLetter.sw);
  11760. // ctx.lineWidth = renderedLetter.sw;
  11761. }
  11762. } else if (lastStrokeW !== this.values.sWidth) {
  11763. lastStrokeW = this.values.sWidth;
  11764. renderer.ctxLineWidth(this.values.sWidth);
  11765. // ctx.lineWidth = this.values.sWidth;
  11766. }
  11767. if (renderedLetter && renderedLetter.sc) {
  11768. if (lastStroke !== renderedLetter.sc) {
  11769. lastStroke = renderedLetter.sc;
  11770. renderer.ctxStrokeStyle(renderedLetter.sc);
  11771. // ctx.strokeStyle = renderedLetter.sc;
  11772. }
  11773. } else if (lastStroke !== this.values.stroke) {
  11774. lastStroke = this.values.stroke;
  11775. renderer.ctxStrokeStyle(this.values.stroke);
  11776. // ctx.strokeStyle = this.values.stroke;
  11777. }
  11778. commands = this.textSpans[i].elem;
  11779. jLen = commands.length;
  11780. this.globalData.canvasContext.beginPath();
  11781. for (j = 0; j < jLen; j += 1) {
  11782. pathArr = commands[j];
  11783. kLen = pathArr.length;
  11784. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11785. for (k = 2; k < kLen; k += 6) {
  11786. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11787. }
  11788. }
  11789. this.globalData.canvasContext.closePath();
  11790. renderer.ctxStroke();
  11791. // this.globalData.canvasContext.stroke();
  11792. /// ctx.strokeText(letters[i].val,0,0);
  11793. }
  11794. if (renderedLetter) {
  11795. this.globalData.renderer.restore();
  11796. }
  11797. }
  11798. }
  11799. };
  11800. function CVImageElement(data, globalData, comp) {
  11801. this.assetData = globalData.getAssetData(data.refId);
  11802. this.img = globalData.imageLoader.getAsset(this.assetData);
  11803. this.initElement(data, globalData, comp);
  11804. }
  11805. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVImageElement);
  11806. CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11807. CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11808. CVImageElement.prototype.createContent = function () {
  11809. if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) {
  11810. var canvas = createTag('canvas');
  11811. canvas.width = this.assetData.w;
  11812. canvas.height = this.assetData.h;
  11813. var ctx = canvas.getContext('2d');
  11814. var imgW = this.img.width;
  11815. var imgH = this.img.height;
  11816. var imgRel = imgW / imgH;
  11817. var canvasRel = this.assetData.w / this.assetData.h;
  11818. var widthCrop;
  11819. var heightCrop;
  11820. var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio;
  11821. if ((imgRel > canvasRel && par === 'xMidYMid slice') || (imgRel < canvasRel && par !== 'xMidYMid slice')) {
  11822. heightCrop = imgH;
  11823. widthCrop = heightCrop * canvasRel;
  11824. } else {
  11825. widthCrop = imgW;
  11826. heightCrop = widthCrop / canvasRel;
  11827. }
  11828. ctx.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h);
  11829. this.img = canvas;
  11830. }
  11831. };
  11832. CVImageElement.prototype.renderInnerContent = function () {
  11833. this.canvasContext.drawImage(this.img, 0, 0);
  11834. };
  11835. CVImageElement.prototype.destroy = function () {
  11836. this.img = null;
  11837. };
  11838. function CVSolidElement(data, globalData, comp) {
  11839. this.initElement(data, globalData, comp);
  11840. }
  11841. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVSolidElement);
  11842. CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11843. CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11844. CVSolidElement.prototype.renderInnerContent = function () {
  11845. // var ctx = this.canvasContext;
  11846. this.globalData.renderer.ctxFillStyle(this.data.sc);
  11847. // ctx.fillStyle = this.data.sc;
  11848. this.globalData.renderer.ctxFillRect(0, 0, this.data.sw, this.data.sh);
  11849. // ctx.fillRect(0, 0, this.data.sw, this.data.sh);
  11850. //
  11851. };
  11852. function CanvasRendererBase() {
  11853. }
  11854. extendPrototype([BaseRenderer], CanvasRendererBase);
  11855. CanvasRendererBase.prototype.createShape = function (data) {
  11856. return new CVShapeElement(data, this.globalData, this);
  11857. };
  11858. CanvasRendererBase.prototype.createText = function (data) {
  11859. return new CVTextElement(data, this.globalData, this);
  11860. };
  11861. CanvasRendererBase.prototype.createImage = function (data) {
  11862. return new CVImageElement(data, this.globalData, this);
  11863. };
  11864. CanvasRendererBase.prototype.createSolid = function (data) {
  11865. return new CVSolidElement(data, this.globalData, this);
  11866. };
  11867. CanvasRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  11868. CanvasRendererBase.prototype.ctxTransform = function (props) {
  11869. if (props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0) {
  11870. return;
  11871. }
  11872. this.canvasContext.transform(props[0], props[1], props[4], props[5], props[12], props[13]);
  11873. };
  11874. CanvasRendererBase.prototype.ctxOpacity = function (op) {
  11875. this.canvasContext.globalAlpha *= op < 0 ? 0 : op;
  11876. };
  11877. CanvasRendererBase.prototype.ctxFillStyle = function (value) {
  11878. this.canvasContext.fillStyle = value;
  11879. };
  11880. CanvasRendererBase.prototype.ctxStrokeStyle = function (value) {
  11881. this.canvasContext.strokeStyle = value;
  11882. };
  11883. CanvasRendererBase.prototype.ctxLineWidth = function (value) {
  11884. this.canvasContext.lineWidth = value;
  11885. };
  11886. CanvasRendererBase.prototype.ctxLineCap = function (value) {
  11887. this.canvasContext.lineCap = value;
  11888. };
  11889. CanvasRendererBase.prototype.ctxLineJoin = function (value) {
  11890. this.canvasContext.lineJoin = value;
  11891. };
  11892. CanvasRendererBase.prototype.ctxMiterLimit = function (value) {
  11893. this.canvasContext.miterLimit = value;
  11894. };
  11895. CanvasRendererBase.prototype.ctxFill = function (rule) {
  11896. this.canvasContext.fill(rule);
  11897. };
  11898. CanvasRendererBase.prototype.ctxFillRect = function (x, y, w, h) {
  11899. this.canvasContext.fillRect(x, y, w, h);
  11900. };
  11901. CanvasRendererBase.prototype.ctxStroke = function () {
  11902. this.canvasContext.stroke();
  11903. };
  11904. CanvasRendererBase.prototype.reset = function () {
  11905. if (!this.renderConfig.clearCanvas) {
  11906. this.canvasContext.restore();
  11907. return;
  11908. }
  11909. this.contextData.reset();
  11910. };
  11911. CanvasRendererBase.prototype.save = function () {
  11912. this.canvasContext.save();
  11913. };
  11914. CanvasRendererBase.prototype.restore = function (actionFlag) {
  11915. if (!this.renderConfig.clearCanvas) {
  11916. this.canvasContext.restore();
  11917. return;
  11918. }
  11919. if (actionFlag) {
  11920. this.globalData.blendMode = 'source-over';
  11921. }
  11922. this.contextData.restore(actionFlag);
  11923. };
  11924. CanvasRendererBase.prototype.configAnimation = function (animData) {
  11925. if (this.animationItem.wrapper) {
  11926. this.animationItem.container = createTag('canvas');
  11927. var containerStyle = this.animationItem.container.style;
  11928. containerStyle.width = '100%';
  11929. containerStyle.height = '100%';
  11930. var origin = '0px 0px 0px';
  11931. containerStyle.transformOrigin = origin;
  11932. containerStyle.mozTransformOrigin = origin;
  11933. containerStyle.webkitTransformOrigin = origin;
  11934. containerStyle['-webkit-transform'] = origin;
  11935. containerStyle.contentVisibility = this.renderConfig.contentVisibility;
  11936. this.animationItem.wrapper.appendChild(this.animationItem.container);
  11937. this.canvasContext = this.animationItem.container.getContext('2d');
  11938. if (this.renderConfig.className) {
  11939. this.animationItem.container.setAttribute('class', this.renderConfig.className);
  11940. }
  11941. if (this.renderConfig.id) {
  11942. this.animationItem.container.setAttribute('id', this.renderConfig.id);
  11943. }
  11944. } else {
  11945. this.canvasContext = this.renderConfig.context;
  11946. }
  11947. this.contextData.setContext(this.canvasContext);
  11948. this.data = animData;
  11949. this.layers = animData.layers;
  11950. this.transformCanvas = {
  11951. w: animData.w,
  11952. h: animData.h,
  11953. sx: 0,
  11954. sy: 0,
  11955. tx: 0,
  11956. ty: 0,
  11957. };
  11958. this.setupGlobalData(animData, document.body);
  11959. this.globalData.canvasContext = this.canvasContext;
  11960. this.globalData.renderer = this;
  11961. this.globalData.isDashed = false;
  11962. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  11963. this.globalData.transformCanvas = this.transformCanvas;
  11964. this.elements = createSizedArray(animData.layers.length);
  11965. this.updateContainerSize();
  11966. };
  11967. CanvasRendererBase.prototype.updateContainerSize = function (width, height) {
  11968. this.reset();
  11969. var elementWidth;
  11970. var elementHeight;
  11971. if (width) {
  11972. elementWidth = width;
  11973. elementHeight = height;
  11974. this.canvasContext.canvas.width = elementWidth;
  11975. this.canvasContext.canvas.height = elementHeight;
  11976. } else {
  11977. if (this.animationItem.wrapper && this.animationItem.container) {
  11978. elementWidth = this.animationItem.wrapper.offsetWidth;
  11979. elementHeight = this.animationItem.wrapper.offsetHeight;
  11980. } else {
  11981. elementWidth = this.canvasContext.canvas.width;
  11982. elementHeight = this.canvasContext.canvas.height;
  11983. }
  11984. this.canvasContext.canvas.width = elementWidth * this.renderConfig.dpr;
  11985. this.canvasContext.canvas.height = elementHeight * this.renderConfig.dpr;
  11986. }
  11987. var elementRel;
  11988. var animationRel;
  11989. if (this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1) {
  11990. var par = this.renderConfig.preserveAspectRatio.split(' ');
  11991. var fillType = par[1] || 'meet';
  11992. var pos = par[0] || 'xMidYMid';
  11993. var xPos = pos.substr(0, 4);
  11994. var yPos = pos.substr(4);
  11995. elementRel = elementWidth / elementHeight;
  11996. animationRel = this.transformCanvas.w / this.transformCanvas.h;
  11997. if ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice')) {
  11998. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  11999. this.transformCanvas.sy = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12000. } else {
  12001. this.transformCanvas.sx = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12002. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12003. }
  12004. if (xPos === 'xMid' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
  12005. this.transformCanvas.tx = ((elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) / 2) * this.renderConfig.dpr;
  12006. } else if (xPos === 'xMax' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
  12007. this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) * this.renderConfig.dpr;
  12008. } else {
  12009. this.transformCanvas.tx = 0;
  12010. }
  12011. if (yPos === 'YMid' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
  12012. this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) / 2) * this.renderConfig.dpr;
  12013. } else if (yPos === 'YMax' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
  12014. this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w))) * this.renderConfig.dpr;
  12015. } else {
  12016. this.transformCanvas.ty = 0;
  12017. }
  12018. } else if (this.renderConfig.preserveAspectRatio === 'none') {
  12019. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12020. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12021. this.transformCanvas.tx = 0;
  12022. this.transformCanvas.ty = 0;
  12023. } else {
  12024. this.transformCanvas.sx = this.renderConfig.dpr;
  12025. this.transformCanvas.sy = this.renderConfig.dpr;
  12026. this.transformCanvas.tx = 0;
  12027. this.transformCanvas.ty = 0;
  12028. }
  12029. this.transformCanvas.props = [this.transformCanvas.sx, 0, 0, 0, 0, this.transformCanvas.sy, 0, 0, 0, 0, 1, 0, this.transformCanvas.tx, this.transformCanvas.ty, 0, 1];
  12030. /* var i, len = this.elements.length;
  12031. for(i=0;i<len;i+=1){
  12032. if(this.elements[i] && this.elements[i].data.ty === 0){
  12033. this.elements[i].resize(this.globalData.transformCanvas);
  12034. }
  12035. } */
  12036. this.ctxTransform(this.transformCanvas.props);
  12037. this.canvasContext.beginPath();
  12038. this.canvasContext.rect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12039. this.canvasContext.closePath();
  12040. this.canvasContext.clip();
  12041. this.renderFrame(this.renderedFrame, true);
  12042. };
  12043. CanvasRendererBase.prototype.destroy = function () {
  12044. if (this.renderConfig.clearCanvas && this.animationItem.wrapper) {
  12045. this.animationItem.wrapper.innerText = '';
  12046. }
  12047. var i;
  12048. var len = this.layers ? this.layers.length : 0;
  12049. for (i = len - 1; i >= 0; i -= 1) {
  12050. if (this.elements[i] && this.elements[i].destroy) {
  12051. this.elements[i].destroy();
  12052. }
  12053. }
  12054. this.elements.length = 0;
  12055. this.globalData.canvasContext = null;
  12056. this.animationItem.container = null;
  12057. this.destroyed = true;
  12058. };
  12059. CanvasRendererBase.prototype.renderFrame = function (num, forceRender) {
  12060. if ((this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender) || this.destroyed || num === -1) {
  12061. return;
  12062. }
  12063. this.renderedFrame = num;
  12064. this.globalData.frameNum = num - this.animationItem._isFirstFrame;
  12065. this.globalData.frameId += 1;
  12066. this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender;
  12067. this.globalData.projectInterface.currentFrame = num;
  12068. // console.log('--------');
  12069. // console.log('NEW: ',num);
  12070. var i;
  12071. var len = this.layers.length;
  12072. if (!this.completeLayers) {
  12073. this.checkLayers(num);
  12074. }
  12075. for (i = len - 1; i >= 0; i -= 1) {
  12076. if (this.completeLayers || this.elements[i]) {
  12077. this.elements[i].prepareFrame(num - this.layers[i].st);
  12078. }
  12079. }
  12080. if (this.globalData._mdf) {
  12081. if (this.renderConfig.clearCanvas === true) {
  12082. this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12083. } else {
  12084. this.save();
  12085. }
  12086. for (i = len - 1; i >= 0; i -= 1) {
  12087. if (this.completeLayers || this.elements[i]) {
  12088. this.elements[i].renderFrame();
  12089. }
  12090. }
  12091. if (this.renderConfig.clearCanvas !== true) {
  12092. this.restore();
  12093. }
  12094. }
  12095. };
  12096. CanvasRendererBase.prototype.buildItem = function (pos) {
  12097. var elements = this.elements;
  12098. if (elements[pos] || this.layers[pos].ty === 99) {
  12099. return;
  12100. }
  12101. var element = this.createItem(this.layers[pos], this, this.globalData);
  12102. elements[pos] = element;
  12103. element.initExpressions();
  12104. /* if(this.layers[pos].ty === 0){
  12105. element.resize(this.globalData.transformCanvas);
  12106. } */
  12107. };
  12108. CanvasRendererBase.prototype.checkPendingElements = function () {
  12109. while (this.pendingElements.length) {
  12110. var element = this.pendingElements.pop();
  12111. element.checkParenting();
  12112. }
  12113. };
  12114. CanvasRendererBase.prototype.hide = function () {
  12115. this.animationItem.container.style.display = 'none';
  12116. };
  12117. CanvasRendererBase.prototype.show = function () {
  12118. this.animationItem.container.style.display = 'block';
  12119. };
  12120. function CanvasContext() {
  12121. this.opacity = -1;
  12122. this.transform = createTypedArray('float32', 16);
  12123. this.fillStyle = '';
  12124. this.strokeStyle = '';
  12125. this.lineWidth = '';
  12126. this.lineCap = '';
  12127. this.lineJoin = '';
  12128. this.miterLimit = '';
  12129. this.id = Math.random();
  12130. }
  12131. function CVContextData() {
  12132. this.stack = [];
  12133. this.cArrPos = 0;
  12134. this.cTr = new Matrix();
  12135. var i;
  12136. var len = 15;
  12137. for (i = 0; i < len; i += 1) {
  12138. var canvasContext = new CanvasContext();
  12139. this.stack[i] = canvasContext;
  12140. }
  12141. this._length = len;
  12142. this.nativeContext = null;
  12143. this.transformMat = new Matrix();
  12144. this.currentOpacity = 1;
  12145. //
  12146. this.currentFillStyle = '';
  12147. this.appliedFillStyle = '';
  12148. //
  12149. this.currentStrokeStyle = '';
  12150. this.appliedStrokeStyle = '';
  12151. //
  12152. this.currentLineWidth = '';
  12153. this.appliedLineWidth = '';
  12154. //
  12155. this.currentLineCap = '';
  12156. this.appliedLineCap = '';
  12157. //
  12158. this.currentLineJoin = '';
  12159. this.appliedLineJoin = '';
  12160. //
  12161. this.appliedMiterLimit = '';
  12162. this.currentMiterLimit = '';
  12163. }
  12164. CVContextData.prototype.duplicate = function () {
  12165. var newLength = this._length * 2;
  12166. var i = 0;
  12167. for (i = this._length; i < newLength; i += 1) {
  12168. this.stack[i] = new CanvasContext();
  12169. }
  12170. this._length = newLength;
  12171. };
  12172. CVContextData.prototype.reset = function () {
  12173. this.cArrPos = 0;
  12174. this.cTr.reset();
  12175. this.stack[this.cArrPos].opacity = 1;
  12176. };
  12177. CVContextData.prototype.restore = function (forceRestore) {
  12178. this.cArrPos -= 1;
  12179. var currentContext = this.stack[this.cArrPos];
  12180. var transform = currentContext.transform;
  12181. var i;
  12182. var arr = this.cTr.props;
  12183. for (i = 0; i < 16; i += 1) {
  12184. arr[i] = transform[i];
  12185. }
  12186. if (forceRestore) {
  12187. this.nativeContext.restore();
  12188. var prevStack = this.stack[this.cArrPos + 1];
  12189. this.appliedFillStyle = prevStack.fillStyle;
  12190. this.appliedStrokeStyle = prevStack.strokeStyle;
  12191. this.appliedLineWidth = prevStack.lineWidth;
  12192. this.appliedLineCap = prevStack.lineCap;
  12193. this.appliedLineJoin = prevStack.lineJoin;
  12194. this.appliedMiterLimit = prevStack.miterLimit;
  12195. }
  12196. this.nativeContext.setTransform(transform[0], transform[1], transform[4], transform[5], transform[12], transform[13]);
  12197. if (forceRestore || (currentContext.opacity !== -1 && this.currentOpacity !== currentContext.opacity)) {
  12198. this.nativeContext.globalAlpha = currentContext.opacity;
  12199. this.currentOpacity = currentContext.opacity;
  12200. }
  12201. this.currentFillStyle = currentContext.fillStyle;
  12202. this.currentStrokeStyle = currentContext.strokeStyle;
  12203. this.currentLineWidth = currentContext.lineWidth;
  12204. this.currentLineCap = currentContext.lineCap;
  12205. this.currentLineJoin = currentContext.lineJoin;
  12206. this.currentMiterLimit = currentContext.miterLimit;
  12207. };
  12208. CVContextData.prototype.save = function (saveOnNativeFlag) {
  12209. if (saveOnNativeFlag) {
  12210. this.nativeContext.save();
  12211. }
  12212. var props = this.cTr.props;
  12213. if (this._length <= this.cArrPos) {
  12214. this.duplicate();
  12215. }
  12216. var currentStack = this.stack[this.cArrPos];
  12217. var i;
  12218. for (i = 0; i < 16; i += 1) {
  12219. currentStack.transform[i] = props[i];
  12220. }
  12221. this.cArrPos += 1;
  12222. var newStack = this.stack[this.cArrPos];
  12223. newStack.opacity = currentStack.opacity;
  12224. newStack.fillStyle = currentStack.fillStyle;
  12225. newStack.strokeStyle = currentStack.strokeStyle;
  12226. newStack.lineWidth = currentStack.lineWidth;
  12227. newStack.lineCap = currentStack.lineCap;
  12228. newStack.lineJoin = currentStack.lineJoin;
  12229. newStack.miterLimit = currentStack.miterLimit;
  12230. };
  12231. CVContextData.prototype.setOpacity = function (value) {
  12232. this.stack[this.cArrPos].opacity = value;
  12233. };
  12234. CVContextData.prototype.setContext = function (value) {
  12235. this.nativeContext = value;
  12236. };
  12237. CVContextData.prototype.fillStyle = function (value) {
  12238. if (this.stack[this.cArrPos].fillStyle !== value) {
  12239. this.currentFillStyle = value;
  12240. this.stack[this.cArrPos].fillStyle = value;
  12241. }
  12242. };
  12243. CVContextData.prototype.strokeStyle = function (value) {
  12244. if (this.stack[this.cArrPos].strokeStyle !== value) {
  12245. this.currentStrokeStyle = value;
  12246. this.stack[this.cArrPos].strokeStyle = value;
  12247. }
  12248. };
  12249. CVContextData.prototype.lineWidth = function (value) {
  12250. if (this.stack[this.cArrPos].lineWidth !== value) {
  12251. this.currentLineWidth = value;
  12252. this.stack[this.cArrPos].lineWidth = value;
  12253. }
  12254. };
  12255. CVContextData.prototype.lineCap = function (value) {
  12256. if (this.stack[this.cArrPos].lineCap !== value) {
  12257. this.currentLineCap = value;
  12258. this.stack[this.cArrPos].lineCap = value;
  12259. }
  12260. };
  12261. CVContextData.prototype.lineJoin = function (value) {
  12262. if (this.stack[this.cArrPos].lineJoin !== value) {
  12263. this.currentLineJoin = value;
  12264. this.stack[this.cArrPos].lineJoin = value;
  12265. }
  12266. };
  12267. CVContextData.prototype.miterLimit = function (value) {
  12268. if (this.stack[this.cArrPos].miterLimit !== value) {
  12269. this.currentMiterLimit = value;
  12270. this.stack[this.cArrPos].miterLimit = value;
  12271. }
  12272. };
  12273. CVContextData.prototype.transform = function (props) {
  12274. this.transformMat.cloneFromProps(props);
  12275. // Taking the last transform value from the stored stack of transforms
  12276. var currentTransform = this.cTr;
  12277. // Applying the last transform value after the new transform to respect the order of transformations
  12278. this.transformMat.multiply(currentTransform);
  12279. // Storing the new transformed value in the stored transform
  12280. currentTransform.cloneFromProps(this.transformMat.props);
  12281. var trProps = currentTransform.props;
  12282. // Applying the new transform to the canvas
  12283. this.nativeContext.setTransform(trProps[0], trProps[1], trProps[4], trProps[5], trProps[12], trProps[13]);
  12284. };
  12285. CVContextData.prototype.opacity = function (op) {
  12286. var currentOpacity = this.stack[this.cArrPos].opacity;
  12287. currentOpacity *= op < 0 ? 0 : op;
  12288. if (this.stack[this.cArrPos].opacity !== currentOpacity) {
  12289. if (this.currentOpacity !== op) {
  12290. this.nativeContext.globalAlpha = op;
  12291. this.currentOpacity = op;
  12292. }
  12293. this.stack[this.cArrPos].opacity = currentOpacity;
  12294. }
  12295. };
  12296. CVContextData.prototype.fill = function (rule) {
  12297. if (this.appliedFillStyle !== this.currentFillStyle) {
  12298. this.appliedFillStyle = this.currentFillStyle;
  12299. this.nativeContext.fillStyle = this.appliedFillStyle;
  12300. }
  12301. this.nativeContext.fill(rule);
  12302. };
  12303. CVContextData.prototype.fillRect = function (x, y, w, h) {
  12304. if (this.appliedFillStyle !== this.currentFillStyle) {
  12305. this.appliedFillStyle = this.currentFillStyle;
  12306. this.nativeContext.fillStyle = this.appliedFillStyle;
  12307. }
  12308. this.nativeContext.fillRect(x, y, w, h);
  12309. };
  12310. CVContextData.prototype.stroke = function () {
  12311. if (this.appliedStrokeStyle !== this.currentStrokeStyle) {
  12312. this.appliedStrokeStyle = this.currentStrokeStyle;
  12313. this.nativeContext.strokeStyle = this.appliedStrokeStyle;
  12314. }
  12315. if (this.appliedLineWidth !== this.currentLineWidth) {
  12316. this.appliedLineWidth = this.currentLineWidth;
  12317. this.nativeContext.lineWidth = this.appliedLineWidth;
  12318. }
  12319. if (this.appliedLineCap !== this.currentLineCap) {
  12320. this.appliedLineCap = this.currentLineCap;
  12321. this.nativeContext.lineCap = this.appliedLineCap;
  12322. }
  12323. if (this.appliedLineJoin !== this.currentLineJoin) {
  12324. this.appliedLineJoin = this.currentLineJoin;
  12325. this.nativeContext.lineJoin = this.appliedLineJoin;
  12326. }
  12327. if (this.appliedMiterLimit !== this.currentMiterLimit) {
  12328. this.appliedMiterLimit = this.currentMiterLimit;
  12329. this.nativeContext.miterLimit = this.appliedMiterLimit;
  12330. }
  12331. this.nativeContext.stroke();
  12332. };
  12333. function CVCompElement(data, globalData, comp) {
  12334. this.completeLayers = false;
  12335. this.layers = data.layers;
  12336. this.pendingElements = [];
  12337. this.elements = createSizedArray(this.layers.length);
  12338. this.initElement(data, globalData, comp);
  12339. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  12340. }
  12341. extendPrototype([CanvasRendererBase, ICompElement, CVBaseElement], CVCompElement);
  12342. CVCompElement.prototype.renderInnerContent = function () {
  12343. var ctx = this.canvasContext;
  12344. ctx.beginPath();
  12345. ctx.moveTo(0, 0);
  12346. ctx.lineTo(this.data.w, 0);
  12347. ctx.lineTo(this.data.w, this.data.h);
  12348. ctx.lineTo(0, this.data.h);
  12349. ctx.lineTo(0, 0);
  12350. ctx.clip();
  12351. var i;
  12352. var len = this.layers.length;
  12353. for (i = len - 1; i >= 0; i -= 1) {
  12354. if (this.completeLayers || this.elements[i]) {
  12355. this.elements[i].renderFrame();
  12356. }
  12357. }
  12358. };
  12359. CVCompElement.prototype.destroy = function () {
  12360. var i;
  12361. var len = this.layers.length;
  12362. for (i = len - 1; i >= 0; i -= 1) {
  12363. if (this.elements[i]) {
  12364. this.elements[i].destroy();
  12365. }
  12366. }
  12367. this.layers = null;
  12368. this.elements = null;
  12369. };
  12370. CVCompElement.prototype.createComp = function (data) {
  12371. return new CVCompElement(data, this.globalData, this);
  12372. };
  12373. function CanvasRenderer(animationItem, config) {
  12374. this.animationItem = animationItem;
  12375. this.renderConfig = {
  12376. clearCanvas: (config && config.clearCanvas !== undefined) ? config.clearCanvas : true,
  12377. context: (config && config.context) || null,
  12378. progressiveLoad: (config && config.progressiveLoad) || false,
  12379. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  12380. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  12381. contentVisibility: (config && config.contentVisibility) || 'visible',
  12382. className: (config && config.className) || '',
  12383. id: (config && config.id) || '',
  12384. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  12385. };
  12386. this.renderConfig.dpr = (config && config.dpr) || 1;
  12387. if (this.animationItem.wrapper) {
  12388. this.renderConfig.dpr = (config && config.dpr) || window.devicePixelRatio || 1;
  12389. }
  12390. this.renderedFrame = -1;
  12391. this.globalData = {
  12392. frameNum: -1,
  12393. _mdf: false,
  12394. renderConfig: this.renderConfig,
  12395. currentGlobalAlpha: -1,
  12396. };
  12397. this.contextData = new CVContextData();
  12398. this.elements = [];
  12399. this.pendingElements = [];
  12400. this.transformMat = new Matrix();
  12401. this.completeLayers = false;
  12402. this.rendererType = 'canvas';
  12403. if (this.renderConfig.clearCanvas) {
  12404. this.ctxTransform = this.contextData.transform.bind(this.contextData);
  12405. this.ctxOpacity = this.contextData.opacity.bind(this.contextData);
  12406. this.ctxFillStyle = this.contextData.fillStyle.bind(this.contextData);
  12407. this.ctxStrokeStyle = this.contextData.strokeStyle.bind(this.contextData);
  12408. this.ctxLineWidth = this.contextData.lineWidth.bind(this.contextData);
  12409. this.ctxLineCap = this.contextData.lineCap.bind(this.contextData);
  12410. this.ctxLineJoin = this.contextData.lineJoin.bind(this.contextData);
  12411. this.ctxMiterLimit = this.contextData.miterLimit.bind(this.contextData);
  12412. this.ctxFill = this.contextData.fill.bind(this.contextData);
  12413. this.ctxFillRect = this.contextData.fillRect.bind(this.contextData);
  12414. this.ctxStroke = this.contextData.stroke.bind(this.contextData);
  12415. this.save = this.contextData.save.bind(this.contextData);
  12416. }
  12417. }
  12418. extendPrototype([CanvasRendererBase], CanvasRenderer);
  12419. CanvasRenderer.prototype.createComp = function (data) {
  12420. return new CVCompElement(data, this.globalData, this);
  12421. };
  12422. // Registering renderers
  12423. registerRenderer('canvas', CanvasRenderer);
  12424. // Registering shape modifiers
  12425. ShapeModifiers.registerModifier('tm', TrimModifier);
  12426. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  12427. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  12428. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  12429. ShapeModifiers.registerModifier('zz', ZigZagModifier);
  12430. ShapeModifiers.registerModifier('op', OffsetPathModifier);
  12431. const CompExpressionInterface = (function () {
  12432. return function (comp) {
  12433. function _thisLayerFunction(name) {
  12434. var i = 0;
  12435. var len = comp.layers.length;
  12436. while (i < len) {
  12437. if (comp.layers[i].nm === name || comp.layers[i].ind === name) {
  12438. return comp.elements[i].layerInterface;
  12439. }
  12440. i += 1;
  12441. }
  12442. return null;
  12443. // return {active:false};
  12444. }
  12445. Object.defineProperty(_thisLayerFunction, '_name', { value: comp.data.nm });
  12446. _thisLayerFunction.layer = _thisLayerFunction;
  12447. _thisLayerFunction.pixelAspect = 1;
  12448. _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h;
  12449. _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w;
  12450. _thisLayerFunction.pixelAspect = 1;
  12451. _thisLayerFunction.frameDuration = 1 / comp.globalData.frameRate;
  12452. _thisLayerFunction.displayStartTime = 0;
  12453. _thisLayerFunction.numLayers = comp.layers.length;
  12454. return _thisLayerFunction;
  12455. };
  12456. }());
  12457. /* eslint-disable */
  12458. /*
  12459. Copyright 2014 David Bau.
  12460. Permission is hereby granted, free of charge, to any person obtaining
  12461. a copy of this software and associated documentation files (the
  12462. "Software"), to deal in the Software without restriction, including
  12463. without limitation the rights to use, copy, modify, merge, publish,
  12464. distribute, sublicense, and/or sell copies of the Software, and to
  12465. permit persons to whom the Software is furnished to do so, subject to
  12466. the following conditions:
  12467. The above copyright notice and this permission notice shall be
  12468. included in all copies or substantial portions of the Software.
  12469. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  12470. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12471. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  12472. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  12473. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  12474. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  12475. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12476. */
  12477. function seedRandom(pool, math) {
  12478. //
  12479. // The following constants are related to IEEE 754 limits.
  12480. //
  12481. var global = this,
  12482. width = 256, // each RC4 output is 0 <= x < 256
  12483. chunks = 6, // at least six RC4 outputs for each double
  12484. digits = 52, // there are 52 significant digits in a double
  12485. rngname = 'random', // rngname: name for Math.random and Math.seedrandom
  12486. startdenom = math.pow(width, chunks),
  12487. significance = math.pow(2, digits),
  12488. overflow = significance * 2,
  12489. mask = width - 1,
  12490. nodecrypto; // node.js crypto module, initialized at the bottom.
  12491. //
  12492. // seedrandom()
  12493. // This is the seedrandom function described above.
  12494. //
  12495. function seedrandom(seed, options, callback) {
  12496. var key = [];
  12497. options = (options === true) ? { entropy: true } : (options || {});
  12498. // Flatten the seed string or build one from local entropy if needed.
  12499. var shortseed = mixkey(flatten(
  12500. options.entropy ? [seed, tostring(pool)] :
  12501. (seed === null) ? autoseed() : seed, 3), key);
  12502. // Use the seed to initialize an ARC4 generator.
  12503. var arc4 = new ARC4(key);
  12504. // This function returns a random double in [0, 1) that contains
  12505. // randomness in every bit of the mantissa of the IEEE 754 value.
  12506. var prng = function() {
  12507. var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
  12508. d = startdenom, // and denominator d = 2 ^ 48.
  12509. x = 0; // and no 'extra last byte'.
  12510. while (n < significance) { // Fill up all significant digits by
  12511. n = (n + x) * width; // shifting numerator and
  12512. d *= width; // denominator and generating a
  12513. x = arc4.g(1); // new least-significant-byte.
  12514. }
  12515. while (n >= overflow) { // To avoid rounding up, before adding
  12516. n /= 2; // last byte, shift everything
  12517. d /= 2; // right using integer math until
  12518. x >>>= 1; // we have exactly the desired bits.
  12519. }
  12520. return (n + x) / d; // Form the number within [0, 1).
  12521. };
  12522. prng.int32 = function() { return arc4.g(4) | 0; };
  12523. prng.quick = function() { return arc4.g(4) / 0x100000000; };
  12524. prng.double = prng;
  12525. // Mix the randomness into accumulated entropy.
  12526. mixkey(tostring(arc4.S), pool);
  12527. // Calling convention: what to return as a function of prng, seed, is_math.
  12528. return (options.pass || callback ||
  12529. function(prng, seed, is_math_call, state) {
  12530. if (state) {
  12531. // Load the arc4 state from the given state if it has an S array.
  12532. if (state.S) { copy(state, arc4); }
  12533. // Only provide the .state method if requested via options.state.
  12534. prng.state = function() { return copy(arc4, {}); };
  12535. }
  12536. // If called as a method of Math (Math.seedrandom()), mutate
  12537. // Math.random because that is how seedrandom.js has worked since v1.0.
  12538. if (is_math_call) { math[rngname] = prng; return seed; }
  12539. // Otherwise, it is a newer calling convention, so return the
  12540. // prng directly.
  12541. else return prng;
  12542. })(
  12543. prng,
  12544. shortseed,
  12545. 'global' in options ? options.global : (this == math),
  12546. options.state);
  12547. }
  12548. math['seed' + rngname] = seedrandom;
  12549. //
  12550. // ARC4
  12551. //
  12552. // An ARC4 implementation. The constructor takes a key in the form of
  12553. // an array of at most (width) integers that should be 0 <= x < (width).
  12554. //
  12555. // The g(count) method returns a pseudorandom integer that concatenates
  12556. // the next (count) outputs from ARC4. Its return value is a number x
  12557. // that is in the range 0 <= x < (width ^ count).
  12558. //
  12559. function ARC4(key) {
  12560. var t, keylen = key.length,
  12561. me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
  12562. // The empty key [] is treated as [0].
  12563. if (!keylen) { key = [keylen++]; }
  12564. // Set up S using the standard key scheduling algorithm.
  12565. while (i < width) {
  12566. s[i] = i++;
  12567. }
  12568. for (i = 0; i < width; i++) {
  12569. s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
  12570. s[j] = t;
  12571. }
  12572. // The "g" method returns the next (count) outputs as one number.
  12573. me.g = function(count) {
  12574. // Using instance members instead of closure state nearly doubles speed.
  12575. var t, r = 0,
  12576. i = me.i, j = me.j, s = me.S;
  12577. while (count--) {
  12578. t = s[i = mask & (i + 1)];
  12579. r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
  12580. }
  12581. me.i = i; me.j = j;
  12582. return r;
  12583. // For robust unpredictability, the function call below automatically
  12584. // discards an initial batch of values. This is called RC4-drop[256].
  12585. // See http://google.com/search?q=rsa+fluhrer+response&btnI
  12586. };
  12587. }
  12588. //
  12589. // copy()
  12590. // Copies internal state of ARC4 to or from a plain object.
  12591. //
  12592. function copy(f, t) {
  12593. t.i = f.i;
  12594. t.j = f.j;
  12595. t.S = f.S.slice();
  12596. return t;
  12597. }
  12598. //
  12599. // flatten()
  12600. // Converts an object tree to nested arrays of strings.
  12601. //
  12602. function flatten(obj, depth) {
  12603. var result = [], typ = (typeof obj), prop;
  12604. if (depth && typ == 'object') {
  12605. for (prop in obj) {
  12606. try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
  12607. }
  12608. }
  12609. return (result.length ? result : typ == 'string' ? obj : obj + '\0');
  12610. }
  12611. //
  12612. // mixkey()
  12613. // Mixes a string seed into a key that is an array of integers, and
  12614. // returns a shortened string seed that is equivalent to the result key.
  12615. //
  12616. function mixkey(seed, key) {
  12617. var stringseed = seed + '', smear, j = 0;
  12618. while (j < stringseed.length) {
  12619. key[mask & j] =
  12620. mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
  12621. }
  12622. return tostring(key);
  12623. }
  12624. //
  12625. // autoseed()
  12626. // Returns an object for autoseeding, using window.crypto and Node crypto
  12627. // module if available.
  12628. //
  12629. function autoseed() {
  12630. try {
  12631. if (nodecrypto) { return tostring(nodecrypto.randomBytes(width)); }
  12632. var out = new Uint8Array(width);
  12633. (global.crypto || global.msCrypto).getRandomValues(out);
  12634. return tostring(out);
  12635. } catch (e) {
  12636. var browser = global.navigator,
  12637. plugins = browser && browser.plugins;
  12638. return [+new Date(), global, plugins, global.screen, tostring(pool)];
  12639. }
  12640. }
  12641. //
  12642. // tostring()
  12643. // Converts an array of charcodes to a string
  12644. //
  12645. function tostring(a) {
  12646. return String.fromCharCode.apply(0, a);
  12647. }
  12648. //
  12649. // When seedrandom.js is loaded, we immediately mix a few bits
  12650. // from the built-in RNG into the entropy pool. Because we do
  12651. // not want to interfere with deterministic PRNG state later,
  12652. // seedrandom will not call math.random on its own again after
  12653. // initialization.
  12654. //
  12655. mixkey(math.random(), pool);
  12656. //
  12657. // Nodejs and AMD support: export the implementation as a module using
  12658. // either convention.
  12659. //
  12660. // End anonymous scope, and pass initial values.
  12661. };
  12662. function initialize$2(BMMath) {
  12663. seedRandom([], BMMath);
  12664. }
  12665. var propTypes = {
  12666. SHAPE: 'shape',
  12667. };
  12668. /* eslint-disable camelcase */
  12669. const ExpressionManager = (function () {
  12670. 'use strict';
  12671. var ob = {};
  12672. var Math = BMMath;
  12673. var window = null;
  12674. var document = null;
  12675. var XMLHttpRequest = null;
  12676. var fetch = null;
  12677. var frames = null;
  12678. var _lottieGlobal = {};
  12679. initialize$2(BMMath);
  12680. function resetFrame() {
  12681. _lottieGlobal = {};
  12682. }
  12683. function $bm_isInstanceOfArray(arr) {
  12684. return arr.constructor === Array || arr.constructor === Float32Array;
  12685. }
  12686. function isNumerable(tOfV, v) {
  12687. return tOfV === 'number' || v instanceof Number || tOfV === 'boolean' || tOfV === 'string';
  12688. }
  12689. function $bm_neg(a) {
  12690. var tOfA = typeof a;
  12691. if (tOfA === 'number' || a instanceof Number || tOfA === 'boolean') {
  12692. return -a;
  12693. }
  12694. if ($bm_isInstanceOfArray(a)) {
  12695. var i;
  12696. var lenA = a.length;
  12697. var retArr = [];
  12698. for (i = 0; i < lenA; i += 1) {
  12699. retArr[i] = -a[i];
  12700. }
  12701. return retArr;
  12702. }
  12703. if (a.propType) {
  12704. return a.v;
  12705. }
  12706. return -a;
  12707. }
  12708. var easeInBez = BezierFactory.getBezierEasing(0.333, 0, 0.833, 0.833, 'easeIn').get;
  12709. var easeOutBez = BezierFactory.getBezierEasing(0.167, 0.167, 0.667, 1, 'easeOut').get;
  12710. var easeInOutBez = BezierFactory.getBezierEasing(0.33, 0, 0.667, 1, 'easeInOut').get;
  12711. function sum(a, b) {
  12712. var tOfA = typeof a;
  12713. var tOfB = typeof b;
  12714. if ((isNumerable(tOfA, a) && isNumerable(tOfB, b)) || tOfA === 'string' || tOfB === 'string') {
  12715. return a + b;
  12716. }
  12717. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12718. a = a.slice(0);
  12719. a[0] += b;
  12720. return a;
  12721. }
  12722. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12723. b = b.slice(0);
  12724. b[0] = a + b[0];
  12725. return b;
  12726. }
  12727. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  12728. var i = 0;
  12729. var lenA = a.length;
  12730. var lenB = b.length;
  12731. var retArr = [];
  12732. while (i < lenA || i < lenB) {
  12733. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  12734. retArr[i] = a[i] + b[i];
  12735. } else {
  12736. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  12737. }
  12738. i += 1;
  12739. }
  12740. return retArr;
  12741. }
  12742. return 0;
  12743. }
  12744. var add = sum;
  12745. function sub(a, b) {
  12746. var tOfA = typeof a;
  12747. var tOfB = typeof b;
  12748. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12749. if (tOfA === 'string') {
  12750. a = parseInt(a, 10);
  12751. }
  12752. if (tOfB === 'string') {
  12753. b = parseInt(b, 10);
  12754. }
  12755. return a - b;
  12756. }
  12757. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12758. a = a.slice(0);
  12759. a[0] -= b;
  12760. return a;
  12761. }
  12762. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12763. b = b.slice(0);
  12764. b[0] = a - b[0];
  12765. return b;
  12766. }
  12767. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  12768. var i = 0;
  12769. var lenA = a.length;
  12770. var lenB = b.length;
  12771. var retArr = [];
  12772. while (i < lenA || i < lenB) {
  12773. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  12774. retArr[i] = a[i] - b[i];
  12775. } else {
  12776. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  12777. }
  12778. i += 1;
  12779. }
  12780. return retArr;
  12781. }
  12782. return 0;
  12783. }
  12784. function mul(a, b) {
  12785. var tOfA = typeof a;
  12786. var tOfB = typeof b;
  12787. var arr;
  12788. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12789. return a * b;
  12790. }
  12791. var i;
  12792. var len;
  12793. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12794. len = a.length;
  12795. arr = createTypedArray('float32', len);
  12796. for (i = 0; i < len; i += 1) {
  12797. arr[i] = a[i] * b;
  12798. }
  12799. return arr;
  12800. }
  12801. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12802. len = b.length;
  12803. arr = createTypedArray('float32', len);
  12804. for (i = 0; i < len; i += 1) {
  12805. arr[i] = a * b[i];
  12806. }
  12807. return arr;
  12808. }
  12809. return 0;
  12810. }
  12811. function div(a, b) {
  12812. var tOfA = typeof a;
  12813. var tOfB = typeof b;
  12814. var arr;
  12815. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12816. return a / b;
  12817. }
  12818. var i;
  12819. var len;
  12820. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12821. len = a.length;
  12822. arr = createTypedArray('float32', len);
  12823. for (i = 0; i < len; i += 1) {
  12824. arr[i] = a[i] / b;
  12825. }
  12826. return arr;
  12827. }
  12828. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12829. len = b.length;
  12830. arr = createTypedArray('float32', len);
  12831. for (i = 0; i < len; i += 1) {
  12832. arr[i] = a / b[i];
  12833. }
  12834. return arr;
  12835. }
  12836. return 0;
  12837. }
  12838. function mod(a, b) {
  12839. if (typeof a === 'string') {
  12840. a = parseInt(a, 10);
  12841. }
  12842. if (typeof b === 'string') {
  12843. b = parseInt(b, 10);
  12844. }
  12845. return a % b;
  12846. }
  12847. var $bm_sum = sum;
  12848. var $bm_sub = sub;
  12849. var $bm_mul = mul;
  12850. var $bm_div = div;
  12851. var $bm_mod = mod;
  12852. function clamp(num, min, max) {
  12853. if (min > max) {
  12854. var mm = max;
  12855. max = min;
  12856. min = mm;
  12857. }
  12858. return Math.min(Math.max(num, min), max);
  12859. }
  12860. function radiansToDegrees(val) {
  12861. return val / degToRads;
  12862. }
  12863. var radians_to_degrees = radiansToDegrees;
  12864. function degreesToRadians(val) {
  12865. return val * degToRads;
  12866. }
  12867. var degrees_to_radians = radiansToDegrees;
  12868. var helperLengthArray = [0, 0, 0, 0, 0, 0];
  12869. function length(arr1, arr2) {
  12870. if (typeof arr1 === 'number' || arr1 instanceof Number) {
  12871. arr2 = arr2 || 0;
  12872. return Math.abs(arr1 - arr2);
  12873. }
  12874. if (!arr2) {
  12875. arr2 = helperLengthArray;
  12876. }
  12877. var i;
  12878. var len = Math.min(arr1.length, arr2.length);
  12879. var addedLength = 0;
  12880. for (i = 0; i < len; i += 1) {
  12881. addedLength += Math.pow(arr2[i] - arr1[i], 2);
  12882. }
  12883. return Math.sqrt(addedLength);
  12884. }
  12885. function normalize(vec) {
  12886. return div(vec, length(vec));
  12887. }
  12888. function rgbToHsl(val) {
  12889. var r = val[0]; var g = val[1]; var b = val[2];
  12890. var max = Math.max(r, g, b);
  12891. var min = Math.min(r, g, b);
  12892. var h;
  12893. var s;
  12894. var l = (max + min) / 2;
  12895. if (max === min) {
  12896. h = 0; // achromatic
  12897. s = 0; // achromatic
  12898. } else {
  12899. var d = max - min;
  12900. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  12901. switch (max) {
  12902. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  12903. case g: h = (b - r) / d + 2; break;
  12904. case b: h = (r - g) / d + 4; break;
  12905. default: break;
  12906. }
  12907. h /= 6;
  12908. }
  12909. return [h, s, l, val[3]];
  12910. }
  12911. function hue2rgb(p, q, t) {
  12912. if (t < 0) t += 1;
  12913. if (t > 1) t -= 1;
  12914. if (t < 1 / 6) return p + (q - p) * 6 * t;
  12915. if (t < 1 / 2) return q;
  12916. if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
  12917. return p;
  12918. }
  12919. function hslToRgb(val) {
  12920. var h = val[0];
  12921. var s = val[1];
  12922. var l = val[2];
  12923. var r;
  12924. var g;
  12925. var b;
  12926. if (s === 0) {
  12927. r = l; // achromatic
  12928. b = l; // achromatic
  12929. g = l; // achromatic
  12930. } else {
  12931. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  12932. var p = 2 * l - q;
  12933. r = hue2rgb(p, q, h + 1 / 3);
  12934. g = hue2rgb(p, q, h);
  12935. b = hue2rgb(p, q, h - 1 / 3);
  12936. }
  12937. return [r, g, b, val[3]];
  12938. }
  12939. function linear(t, tMin, tMax, value1, value2) {
  12940. if (value1 === undefined || value2 === undefined) {
  12941. value1 = tMin;
  12942. value2 = tMax;
  12943. tMin = 0;
  12944. tMax = 1;
  12945. }
  12946. if (tMax < tMin) {
  12947. var _tMin = tMax;
  12948. tMax = tMin;
  12949. tMin = _tMin;
  12950. }
  12951. if (t <= tMin) {
  12952. return value1;
  12953. } if (t >= tMax) {
  12954. return value2;
  12955. }
  12956. var perc = tMax === tMin ? 0 : (t - tMin) / (tMax - tMin);
  12957. if (!value1.length) {
  12958. return value1 + (value2 - value1) * perc;
  12959. }
  12960. var i;
  12961. var len = value1.length;
  12962. var arr = createTypedArray('float32', len);
  12963. for (i = 0; i < len; i += 1) {
  12964. arr[i] = value1[i] + (value2[i] - value1[i]) * perc;
  12965. }
  12966. return arr;
  12967. }
  12968. function random(min, max) {
  12969. if (max === undefined) {
  12970. if (min === undefined) {
  12971. min = 0;
  12972. max = 1;
  12973. } else {
  12974. max = min;
  12975. min = undefined;
  12976. }
  12977. }
  12978. if (max.length) {
  12979. var i;
  12980. var len = max.length;
  12981. if (!min) {
  12982. min = createTypedArray('float32', len);
  12983. }
  12984. var arr = createTypedArray('float32', len);
  12985. var rnd = BMMath.random();
  12986. for (i = 0; i < len; i += 1) {
  12987. arr[i] = min[i] + rnd * (max[i] - min[i]);
  12988. }
  12989. return arr;
  12990. }
  12991. if (min === undefined) {
  12992. min = 0;
  12993. }
  12994. var rndm = BMMath.random();
  12995. return min + rndm * (max - min);
  12996. }
  12997. function createPath(points, inTangents, outTangents, closed) {
  12998. var i;
  12999. var len = points.length;
  13000. var path = shapePool.newElement();
  13001. path.setPathData(!!closed, len);
  13002. var arrPlaceholder = [0, 0];
  13003. var inVertexPoint;
  13004. var outVertexPoint;
  13005. for (i = 0; i < len; i += 1) {
  13006. inVertexPoint = (inTangents && inTangents[i]) ? inTangents[i] : arrPlaceholder;
  13007. outVertexPoint = (outTangents && outTangents[i]) ? outTangents[i] : arrPlaceholder;
  13008. 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);
  13009. }
  13010. return path;
  13011. }
  13012. function initiateExpression(elem, data, property) {
  13013. // Bail out if we don't want expressions
  13014. function noOp(_value) {
  13015. return _value;
  13016. }
  13017. if (!elem.globalData.renderConfig.runExpressions) {
  13018. return noOp;
  13019. }
  13020. var val = data.x;
  13021. var needsVelocity = /velocity(?![\w\d])/.test(val);
  13022. var _needsRandom = val.indexOf('random') !== -1;
  13023. var elemType = elem.data.ty;
  13024. var transform;
  13025. var $bm_transform;
  13026. var content;
  13027. var effect;
  13028. var thisProperty = property;
  13029. thisProperty._name = elem.data.nm;
  13030. thisProperty.valueAtTime = thisProperty.getValueAtTime;
  13031. Object.defineProperty(thisProperty, 'value', {
  13032. get: function () {
  13033. return thisProperty.v;
  13034. },
  13035. });
  13036. elem.comp.frameDuration = 1 / elem.comp.globalData.frameRate;
  13037. elem.comp.displayStartTime = 0;
  13038. var inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  13039. var outPoint = elem.data.op / elem.comp.globalData.frameRate;
  13040. var width = elem.data.sw ? elem.data.sw : 0;
  13041. var height = elem.data.sh ? elem.data.sh : 0;
  13042. var name = elem.data.nm;
  13043. var loopIn;
  13044. var loop_in;
  13045. var loopOut;
  13046. var loop_out;
  13047. var smooth;
  13048. var toWorld;
  13049. var fromWorld;
  13050. var fromComp;
  13051. var toComp;
  13052. var fromCompToSurface;
  13053. var position;
  13054. var rotation;
  13055. var anchorPoint;
  13056. var scale;
  13057. var thisLayer;
  13058. var thisComp;
  13059. var mask;
  13060. var valueAtTime;
  13061. var velocityAtTime;
  13062. var scoped_bm_rt;
  13063. // val = val.replace(/(\\?"|')((http)(s)?(:\/))?\/.*?(\\?"|')/g, "\"\""); // deter potential network calls
  13064. var expression_function = eval('[function _expression_function(){' + val + ';scoped_bm_rt=$bm_rt}]')[0]; // eslint-disable-line no-eval
  13065. var numKeys = property.kf ? data.k.length : 0;
  13066. var active = !this.data || this.data.hd !== true;
  13067. var wiggle = function wiggle(freq, amp) {
  13068. var iWiggle;
  13069. var j;
  13070. var lenWiggle = this.pv.length ? this.pv.length : 1;
  13071. var addedAmps = createTypedArray('float32', lenWiggle);
  13072. freq = 5;
  13073. var iterations = Math.floor(time * freq);
  13074. iWiggle = 0;
  13075. j = 0;
  13076. while (iWiggle < iterations) {
  13077. // var rnd = BMMath.random();
  13078. for (j = 0; j < lenWiggle; j += 1) {
  13079. addedAmps[j] += -amp + amp * 2 * BMMath.random();
  13080. // addedAmps[j] += -amp + amp*2*rnd;
  13081. }
  13082. iWiggle += 1;
  13083. }
  13084. // var rnd2 = BMMath.random();
  13085. var periods = time * freq;
  13086. var perc = periods - Math.floor(periods);
  13087. var arr = createTypedArray('float32', lenWiggle);
  13088. if (lenWiggle > 1) {
  13089. for (j = 0; j < lenWiggle; j += 1) {
  13090. arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc;
  13091. // arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc;
  13092. // arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc);
  13093. }
  13094. return arr;
  13095. }
  13096. return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc;
  13097. }.bind(this);
  13098. if (thisProperty.loopIn) {
  13099. loopIn = thisProperty.loopIn.bind(thisProperty);
  13100. loop_in = loopIn;
  13101. }
  13102. if (thisProperty.loopOut) {
  13103. loopOut = thisProperty.loopOut.bind(thisProperty);
  13104. loop_out = loopOut;
  13105. }
  13106. if (thisProperty.smooth) {
  13107. smooth = thisProperty.smooth.bind(thisProperty);
  13108. }
  13109. function loopInDuration(type, duration) {
  13110. return loopIn(type, duration, true);
  13111. }
  13112. function loopOutDuration(type, duration) {
  13113. return loopOut(type, duration, true);
  13114. }
  13115. if (this.getValueAtTime) {
  13116. valueAtTime = this.getValueAtTime.bind(this);
  13117. }
  13118. if (this.getVelocityAtTime) {
  13119. velocityAtTime = this.getVelocityAtTime.bind(this);
  13120. }
  13121. var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface);
  13122. function lookAt(elem1, elem2) {
  13123. var fVec = [elem2[0] - elem1[0], elem2[1] - elem1[1], elem2[2] - elem1[2]];
  13124. var pitch = Math.atan2(fVec[0], Math.sqrt(fVec[1] * fVec[1] + fVec[2] * fVec[2])) / degToRads;
  13125. var yaw = -Math.atan2(fVec[1], fVec[2]) / degToRads;
  13126. return [yaw, pitch, 0];
  13127. }
  13128. function easeOut(t, tMin, tMax, val1, val2) {
  13129. return applyEase(easeOutBez, t, tMin, tMax, val1, val2);
  13130. }
  13131. function easeIn(t, tMin, tMax, val1, val2) {
  13132. return applyEase(easeInBez, t, tMin, tMax, val1, val2);
  13133. }
  13134. function ease(t, tMin, tMax, val1, val2) {
  13135. return applyEase(easeInOutBez, t, tMin, tMax, val1, val2);
  13136. }
  13137. function applyEase(fn, t, tMin, tMax, val1, val2) {
  13138. if (val1 === undefined) {
  13139. val1 = tMin;
  13140. val2 = tMax;
  13141. } else {
  13142. t = (t - tMin) / (tMax - tMin);
  13143. }
  13144. if (t > 1) {
  13145. t = 1;
  13146. } else if (t < 0) {
  13147. t = 0;
  13148. }
  13149. var mult = fn(t);
  13150. if ($bm_isInstanceOfArray(val1)) {
  13151. var iKey;
  13152. var lenKey = val1.length;
  13153. var arr = createTypedArray('float32', lenKey);
  13154. for (iKey = 0; iKey < lenKey; iKey += 1) {
  13155. arr[iKey] = (val2[iKey] - val1[iKey]) * mult + val1[iKey];
  13156. }
  13157. return arr;
  13158. }
  13159. return (val2 - val1) * mult + val1;
  13160. }
  13161. function nearestKey(time) {
  13162. var iKey;
  13163. var lenKey = data.k.length;
  13164. var index;
  13165. var keyTime;
  13166. if (!data.k.length || typeof (data.k[0]) === 'number') {
  13167. index = 0;
  13168. keyTime = 0;
  13169. } else {
  13170. index = -1;
  13171. time *= elem.comp.globalData.frameRate;
  13172. if (time < data.k[0].t) {
  13173. index = 1;
  13174. keyTime = data.k[0].t;
  13175. } else {
  13176. for (iKey = 0; iKey < lenKey - 1; iKey += 1) {
  13177. if (time === data.k[iKey].t) {
  13178. index = iKey + 1;
  13179. keyTime = data.k[iKey].t;
  13180. break;
  13181. } else if (time > data.k[iKey].t && time < data.k[iKey + 1].t) {
  13182. if (time - data.k[iKey].t > data.k[iKey + 1].t - time) {
  13183. index = iKey + 2;
  13184. keyTime = data.k[iKey + 1].t;
  13185. } else {
  13186. index = iKey + 1;
  13187. keyTime = data.k[iKey].t;
  13188. }
  13189. break;
  13190. }
  13191. }
  13192. if (index === -1) {
  13193. index = iKey + 1;
  13194. keyTime = data.k[iKey].t;
  13195. }
  13196. }
  13197. }
  13198. var obKey = {};
  13199. obKey.index = index;
  13200. obKey.time = keyTime / elem.comp.globalData.frameRate;
  13201. return obKey;
  13202. }
  13203. function key(ind) {
  13204. var obKey;
  13205. var iKey;
  13206. var lenKey;
  13207. if (!data.k.length || typeof (data.k[0]) === 'number') {
  13208. throw new Error('The property has no keyframe at index ' + ind);
  13209. }
  13210. ind -= 1;
  13211. obKey = {
  13212. time: data.k[ind].t / elem.comp.globalData.frameRate,
  13213. value: [],
  13214. };
  13215. var arr = Object.prototype.hasOwnProperty.call(data.k[ind], 's') ? data.k[ind].s : data.k[ind - 1].e;
  13216. lenKey = arr.length;
  13217. for (iKey = 0; iKey < lenKey; iKey += 1) {
  13218. obKey[iKey] = arr[iKey];
  13219. obKey.value[iKey] = arr[iKey];
  13220. }
  13221. return obKey;
  13222. }
  13223. function framesToTime(fr, fps) {
  13224. if (!fps) {
  13225. fps = elem.comp.globalData.frameRate;
  13226. }
  13227. return fr / fps;
  13228. }
  13229. function timeToFrames(t, fps) {
  13230. if (!t && t !== 0) {
  13231. t = time;
  13232. }
  13233. if (!fps) {
  13234. fps = elem.comp.globalData.frameRate;
  13235. }
  13236. return t * fps;
  13237. }
  13238. function seedRandom(seed) {
  13239. BMMath.seedrandom(randSeed + seed);
  13240. }
  13241. function sourceRectAtTime() {
  13242. return elem.sourceRectAtTime();
  13243. }
  13244. function substring(init, end) {
  13245. if (typeof value === 'string') {
  13246. if (end === undefined) {
  13247. return value.substring(init);
  13248. }
  13249. return value.substring(init, end);
  13250. }
  13251. return '';
  13252. }
  13253. function substr(init, end) {
  13254. if (typeof value === 'string') {
  13255. if (end === undefined) {
  13256. return value.substr(init);
  13257. }
  13258. return value.substr(init, end);
  13259. }
  13260. return '';
  13261. }
  13262. function posterizeTime(framesPerSecond) {
  13263. time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond;
  13264. value = valueAtTime(time);
  13265. }
  13266. var time;
  13267. var velocity;
  13268. var value;
  13269. var text;
  13270. var textIndex;
  13271. var textTotal;
  13272. var selectorValue;
  13273. var index = elem.data.ind;
  13274. var hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  13275. var parent;
  13276. var randSeed = Math.floor(Math.random() * 1000000);
  13277. var globalData = elem.globalData;
  13278. function executeExpression(_value) {
  13279. // globalData.pushExpression();
  13280. value = _value;
  13281. if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') {
  13282. return value;
  13283. }
  13284. if (this.propType === 'textSelector') {
  13285. textIndex = this.textIndex;
  13286. textTotal = this.textTotal;
  13287. selectorValue = this.selectorValue;
  13288. }
  13289. if (!thisLayer) {
  13290. text = elem.layerInterface.text;
  13291. thisLayer = elem.layerInterface;
  13292. thisComp = elem.comp.compInterface;
  13293. toWorld = thisLayer.toWorld.bind(thisLayer);
  13294. fromWorld = thisLayer.fromWorld.bind(thisLayer);
  13295. fromComp = thisLayer.fromComp.bind(thisLayer);
  13296. toComp = thisLayer.toComp.bind(thisLayer);
  13297. mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null;
  13298. fromCompToSurface = fromComp;
  13299. }
  13300. if (!transform) {
  13301. transform = elem.layerInterface('ADBE Transform Group');
  13302. $bm_transform = transform;
  13303. if (transform) {
  13304. anchorPoint = transform.anchorPoint;
  13305. /* position = transform.position;
  13306. rotation = transform.rotation;
  13307. scale = transform.scale; */
  13308. }
  13309. }
  13310. if (elemType === 4 && !content) {
  13311. content = thisLayer('ADBE Root Vectors Group');
  13312. }
  13313. if (!effect) {
  13314. effect = thisLayer(4);
  13315. }
  13316. hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  13317. if (hasParent && !parent) {
  13318. parent = elem.hierarchy[0].layerInterface;
  13319. }
  13320. time = this.comp.renderedFrame / this.comp.globalData.frameRate;
  13321. if (_needsRandom) {
  13322. seedRandom(randSeed + time);
  13323. }
  13324. if (needsVelocity) {
  13325. velocity = velocityAtTime(time);
  13326. }
  13327. expression_function();
  13328. this.frameExpressionId = elem.globalData.frameId;
  13329. // TODO: Check if it's possible to return on ShapeInterface the .v value
  13330. // Changed this to a ternary operation because Rollup failed compiling it correctly
  13331. scoped_bm_rt = scoped_bm_rt.propType === propTypes.SHAPE
  13332. ? scoped_bm_rt.v
  13333. : scoped_bm_rt;
  13334. return scoped_bm_rt;
  13335. }
  13336. // Bundlers will see these as dead code and unless we reference them
  13337. 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];
  13338. return executeExpression;
  13339. }
  13340. ob.initiateExpression = initiateExpression;
  13341. 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];
  13342. ob.resetFrame = resetFrame;
  13343. return ob;
  13344. }());
  13345. const Expressions = (function () {
  13346. var ob = {};
  13347. ob.initExpressions = initExpressions;
  13348. ob.resetFrame = ExpressionManager.resetFrame;
  13349. function initExpressions(animation) {
  13350. var stackCount = 0;
  13351. var registers = [];
  13352. function pushExpression() {
  13353. stackCount += 1;
  13354. }
  13355. function popExpression() {
  13356. stackCount -= 1;
  13357. if (stackCount === 0) {
  13358. releaseInstances();
  13359. }
  13360. }
  13361. function registerExpressionProperty(expression) {
  13362. if (registers.indexOf(expression) === -1) {
  13363. registers.push(expression);
  13364. }
  13365. }
  13366. function releaseInstances() {
  13367. var i;
  13368. var len = registers.length;
  13369. for (i = 0; i < len; i += 1) {
  13370. registers[i].release();
  13371. }
  13372. registers.length = 0;
  13373. }
  13374. animation.renderer.compInterface = CompExpressionInterface(animation.renderer);
  13375. animation.renderer.globalData.projectInterface.registerComposition(animation.renderer);
  13376. animation.renderer.globalData.pushExpression = pushExpression;
  13377. animation.renderer.globalData.popExpression = popExpression;
  13378. animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty;
  13379. }
  13380. return ob;
  13381. }());
  13382. const MaskManagerInterface = (function () {
  13383. function MaskInterface(mask, data) {
  13384. this._mask = mask;
  13385. this._data = data;
  13386. }
  13387. Object.defineProperty(MaskInterface.prototype, 'maskPath', {
  13388. get: function () {
  13389. if (this._mask.prop.k) {
  13390. this._mask.prop.getValue();
  13391. }
  13392. return this._mask.prop;
  13393. },
  13394. });
  13395. Object.defineProperty(MaskInterface.prototype, 'maskOpacity', {
  13396. get: function () {
  13397. if (this._mask.op.k) {
  13398. this._mask.op.getValue();
  13399. }
  13400. return this._mask.op.v * 100;
  13401. },
  13402. });
  13403. var MaskManager = function (maskManager) {
  13404. var _masksInterfaces = createSizedArray(maskManager.viewData.length);
  13405. var i;
  13406. var len = maskManager.viewData.length;
  13407. for (i = 0; i < len; i += 1) {
  13408. _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]);
  13409. }
  13410. var maskFunction = function (name) {
  13411. i = 0;
  13412. while (i < len) {
  13413. if (maskManager.masksProperties[i].nm === name) {
  13414. return _masksInterfaces[i];
  13415. }
  13416. i += 1;
  13417. }
  13418. return null;
  13419. };
  13420. return maskFunction;
  13421. };
  13422. return MaskManager;
  13423. }());
  13424. const ExpressionPropertyInterface = (function () {
  13425. var defaultUnidimensionalValue = { pv: 0, v: 0, mult: 1 };
  13426. var defaultMultidimensionalValue = { pv: [0, 0, 0], v: [0, 0, 0], mult: 1 };
  13427. function completeProperty(expressionValue, property, type) {
  13428. Object.defineProperty(expressionValue, 'velocity', {
  13429. get: function () {
  13430. return property.getVelocityAtTime(property.comp.currentFrame);
  13431. },
  13432. });
  13433. expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0;
  13434. expressionValue.key = function (pos) {
  13435. if (!expressionValue.numKeys) {
  13436. return 0;
  13437. }
  13438. var value = '';
  13439. if ('s' in property.keyframes[pos - 1]) {
  13440. value = property.keyframes[pos - 1].s;
  13441. } else if ('e' in property.keyframes[pos - 2]) {
  13442. value = property.keyframes[pos - 2].e;
  13443. } else {
  13444. value = property.keyframes[pos - 2].s;
  13445. }
  13446. var valueProp = type === 'unidimensional' ? new Number(value) : Object.assign({}, value); // eslint-disable-line no-new-wrappers
  13447. valueProp.time = property.keyframes[pos - 1].t / property.elem.comp.globalData.frameRate;
  13448. valueProp.value = type === 'unidimensional' ? value[0] : value;
  13449. return valueProp;
  13450. };
  13451. expressionValue.valueAtTime = property.getValueAtTime;
  13452. expressionValue.speedAtTime = property.getSpeedAtTime;
  13453. expressionValue.velocityAtTime = property.getVelocityAtTime;
  13454. expressionValue.propertyGroup = property.propertyGroup;
  13455. }
  13456. function UnidimensionalPropertyInterface(property) {
  13457. if (!property || !('pv' in property)) {
  13458. property = defaultUnidimensionalValue;
  13459. }
  13460. var mult = 1 / property.mult;
  13461. var val = property.pv * mult;
  13462. var expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  13463. expressionValue.value = val;
  13464. completeProperty(expressionValue, property, 'unidimensional');
  13465. return function () {
  13466. if (property.k) {
  13467. property.getValue();
  13468. }
  13469. val = property.v * mult;
  13470. if (expressionValue.value !== val) {
  13471. expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  13472. expressionValue.value = val;
  13473. expressionValue[0] = val;
  13474. completeProperty(expressionValue, property, 'unidimensional');
  13475. }
  13476. return expressionValue;
  13477. };
  13478. }
  13479. function MultidimensionalPropertyInterface(property) {
  13480. if (!property || !('pv' in property)) {
  13481. property = defaultMultidimensionalValue;
  13482. }
  13483. var mult = 1 / property.mult;
  13484. var len = (property.data && property.data.l) || property.pv.length;
  13485. var expressionValue = createTypedArray('float32', len);
  13486. var arrValue = createTypedArray('float32', len);
  13487. expressionValue.value = arrValue;
  13488. completeProperty(expressionValue, property, 'multidimensional');
  13489. return function () {
  13490. if (property.k) {
  13491. property.getValue();
  13492. }
  13493. for (var i = 0; i < len; i += 1) {
  13494. arrValue[i] = property.v[i] * mult;
  13495. expressionValue[i] = arrValue[i];
  13496. }
  13497. return expressionValue;
  13498. };
  13499. }
  13500. // TODO: try to avoid using this getter
  13501. function defaultGetter() {
  13502. return defaultUnidimensionalValue;
  13503. }
  13504. return function (property) {
  13505. if (!property) {
  13506. return defaultGetter;
  13507. } if (property.propType === 'unidimensional') {
  13508. return UnidimensionalPropertyInterface(property);
  13509. }
  13510. return MultidimensionalPropertyInterface(property);
  13511. };
  13512. }());
  13513. const TransformExpressionInterface = (function () {
  13514. return function (transform) {
  13515. function _thisFunction(name) {
  13516. switch (name) {
  13517. case 'scale':
  13518. case 'Scale':
  13519. case 'ADBE Scale':
  13520. case 6:
  13521. return _thisFunction.scale;
  13522. case 'rotation':
  13523. case 'Rotation':
  13524. case 'ADBE Rotation':
  13525. case 'ADBE Rotate Z':
  13526. case 10:
  13527. return _thisFunction.rotation;
  13528. case 'ADBE Rotate X':
  13529. return _thisFunction.xRotation;
  13530. case 'ADBE Rotate Y':
  13531. return _thisFunction.yRotation;
  13532. case 'position':
  13533. case 'Position':
  13534. case 'ADBE Position':
  13535. case 2:
  13536. return _thisFunction.position;
  13537. case 'ADBE Position_0':
  13538. return _thisFunction.xPosition;
  13539. case 'ADBE Position_1':
  13540. return _thisFunction.yPosition;
  13541. case 'ADBE Position_2':
  13542. return _thisFunction.zPosition;
  13543. case 'anchorPoint':
  13544. case 'AnchorPoint':
  13545. case 'Anchor Point':
  13546. case 'ADBE AnchorPoint':
  13547. case 1:
  13548. return _thisFunction.anchorPoint;
  13549. case 'opacity':
  13550. case 'Opacity':
  13551. case 11:
  13552. return _thisFunction.opacity;
  13553. default:
  13554. return null;
  13555. }
  13556. }
  13557. Object.defineProperty(_thisFunction, 'rotation', {
  13558. get: ExpressionPropertyInterface(transform.r || transform.rz),
  13559. });
  13560. Object.defineProperty(_thisFunction, 'zRotation', {
  13561. get: ExpressionPropertyInterface(transform.rz || transform.r),
  13562. });
  13563. Object.defineProperty(_thisFunction, 'xRotation', {
  13564. get: ExpressionPropertyInterface(transform.rx),
  13565. });
  13566. Object.defineProperty(_thisFunction, 'yRotation', {
  13567. get: ExpressionPropertyInterface(transform.ry),
  13568. });
  13569. Object.defineProperty(_thisFunction, 'scale', {
  13570. get: ExpressionPropertyInterface(transform.s),
  13571. });
  13572. var _px;
  13573. var _py;
  13574. var _pz;
  13575. var _transformFactory;
  13576. if (transform.p) {
  13577. _transformFactory = ExpressionPropertyInterface(transform.p);
  13578. } else {
  13579. _px = ExpressionPropertyInterface(transform.px);
  13580. _py = ExpressionPropertyInterface(transform.py);
  13581. if (transform.pz) {
  13582. _pz = ExpressionPropertyInterface(transform.pz);
  13583. }
  13584. }
  13585. Object.defineProperty(_thisFunction, 'position', {
  13586. get: function () {
  13587. if (transform.p) {
  13588. return _transformFactory();
  13589. }
  13590. return [
  13591. _px(),
  13592. _py(),
  13593. _pz ? _pz() : 0];
  13594. },
  13595. });
  13596. Object.defineProperty(_thisFunction, 'xPosition', {
  13597. get: ExpressionPropertyInterface(transform.px),
  13598. });
  13599. Object.defineProperty(_thisFunction, 'yPosition', {
  13600. get: ExpressionPropertyInterface(transform.py),
  13601. });
  13602. Object.defineProperty(_thisFunction, 'zPosition', {
  13603. get: ExpressionPropertyInterface(transform.pz),
  13604. });
  13605. Object.defineProperty(_thisFunction, 'anchorPoint', {
  13606. get: ExpressionPropertyInterface(transform.a),
  13607. });
  13608. Object.defineProperty(_thisFunction, 'opacity', {
  13609. get: ExpressionPropertyInterface(transform.o),
  13610. });
  13611. Object.defineProperty(_thisFunction, 'skew', {
  13612. get: ExpressionPropertyInterface(transform.sk),
  13613. });
  13614. Object.defineProperty(_thisFunction, 'skewAxis', {
  13615. get: ExpressionPropertyInterface(transform.sa),
  13616. });
  13617. Object.defineProperty(_thisFunction, 'orientation', {
  13618. get: ExpressionPropertyInterface(transform.or),
  13619. });
  13620. return _thisFunction;
  13621. };
  13622. }());
  13623. const LayerExpressionInterface = (function () {
  13624. function getMatrix(time) {
  13625. var toWorldMat = new Matrix();
  13626. if (time !== undefined) {
  13627. var propMatrix = this._elem.finalTransform.mProp.getValueAtTime(time);
  13628. propMatrix.clone(toWorldMat);
  13629. } else {
  13630. var transformMat = this._elem.finalTransform.mProp;
  13631. transformMat.applyToMatrix(toWorldMat);
  13632. }
  13633. return toWorldMat;
  13634. }
  13635. function toWorldVec(arr, time) {
  13636. var toWorldMat = this.getMatrix(time);
  13637. toWorldMat.props[12] = 0;
  13638. toWorldMat.props[13] = 0;
  13639. toWorldMat.props[14] = 0;
  13640. return this.applyPoint(toWorldMat, arr);
  13641. }
  13642. function toWorld(arr, time) {
  13643. var toWorldMat = this.getMatrix(time);
  13644. return this.applyPoint(toWorldMat, arr);
  13645. }
  13646. function fromWorldVec(arr, time) {
  13647. var toWorldMat = this.getMatrix(time);
  13648. toWorldMat.props[12] = 0;
  13649. toWorldMat.props[13] = 0;
  13650. toWorldMat.props[14] = 0;
  13651. return this.invertPoint(toWorldMat, arr);
  13652. }
  13653. function fromWorld(arr, time) {
  13654. var toWorldMat = this.getMatrix(time);
  13655. return this.invertPoint(toWorldMat, arr);
  13656. }
  13657. function applyPoint(matrix, arr) {
  13658. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  13659. var i;
  13660. var len = this._elem.hierarchy.length;
  13661. for (i = 0; i < len; i += 1) {
  13662. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  13663. }
  13664. }
  13665. return matrix.applyToPointArray(arr[0], arr[1], arr[2] || 0);
  13666. }
  13667. function invertPoint(matrix, arr) {
  13668. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  13669. var i;
  13670. var len = this._elem.hierarchy.length;
  13671. for (i = 0; i < len; i += 1) {
  13672. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  13673. }
  13674. }
  13675. return matrix.inversePoint(arr);
  13676. }
  13677. function fromComp(arr) {
  13678. var toWorldMat = new Matrix();
  13679. toWorldMat.reset();
  13680. this._elem.finalTransform.mProp.applyToMatrix(toWorldMat);
  13681. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  13682. var i;
  13683. var len = this._elem.hierarchy.length;
  13684. for (i = 0; i < len; i += 1) {
  13685. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  13686. }
  13687. return toWorldMat.inversePoint(arr);
  13688. }
  13689. return toWorldMat.inversePoint(arr);
  13690. }
  13691. function sampleImage() {
  13692. return [1, 1, 1, 1];
  13693. }
  13694. return function (elem) {
  13695. var transformInterface;
  13696. function _registerMaskInterface(maskManager) {
  13697. _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem);
  13698. }
  13699. function _registerEffectsInterface(effects) {
  13700. _thisLayerFunction.effect = effects;
  13701. }
  13702. function _thisLayerFunction(name) {
  13703. switch (name) {
  13704. case 'ADBE Root Vectors Group':
  13705. case 'Contents':
  13706. case 2:
  13707. return _thisLayerFunction.shapeInterface;
  13708. case 1:
  13709. case 6:
  13710. case 'Transform':
  13711. case 'transform':
  13712. case 'ADBE Transform Group':
  13713. return transformInterface;
  13714. case 4:
  13715. case 'ADBE Effect Parade':
  13716. case 'effects':
  13717. case 'Effects':
  13718. return _thisLayerFunction.effect;
  13719. case 'ADBE Text Properties':
  13720. return _thisLayerFunction.textInterface;
  13721. default:
  13722. return null;
  13723. }
  13724. }
  13725. _thisLayerFunction.getMatrix = getMatrix;
  13726. _thisLayerFunction.invertPoint = invertPoint;
  13727. _thisLayerFunction.applyPoint = applyPoint;
  13728. _thisLayerFunction.toWorld = toWorld;
  13729. _thisLayerFunction.toWorldVec = toWorldVec;
  13730. _thisLayerFunction.fromWorld = fromWorld;
  13731. _thisLayerFunction.fromWorldVec = fromWorldVec;
  13732. _thisLayerFunction.toComp = toWorld;
  13733. _thisLayerFunction.fromComp = fromComp;
  13734. _thisLayerFunction.sampleImage = sampleImage;
  13735. _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem);
  13736. _thisLayerFunction._elem = elem;
  13737. transformInterface = TransformExpressionInterface(elem.finalTransform.mProp);
  13738. var anchorPointDescriptor = getDescriptor(transformInterface, 'anchorPoint');
  13739. Object.defineProperties(_thisLayerFunction, {
  13740. hasParent: {
  13741. get: function () {
  13742. return elem.hierarchy.length;
  13743. },
  13744. },
  13745. parent: {
  13746. get: function () {
  13747. return elem.hierarchy[0].layerInterface;
  13748. },
  13749. },
  13750. rotation: getDescriptor(transformInterface, 'rotation'),
  13751. scale: getDescriptor(transformInterface, 'scale'),
  13752. position: getDescriptor(transformInterface, 'position'),
  13753. opacity: getDescriptor(transformInterface, 'opacity'),
  13754. anchorPoint: anchorPointDescriptor,
  13755. anchor_point: anchorPointDescriptor,
  13756. transform: {
  13757. get: function () {
  13758. return transformInterface;
  13759. },
  13760. },
  13761. active: {
  13762. get: function () {
  13763. return elem.isInRange;
  13764. },
  13765. },
  13766. });
  13767. _thisLayerFunction.startTime = elem.data.st;
  13768. _thisLayerFunction.index = elem.data.ind;
  13769. _thisLayerFunction.source = elem.data.refId;
  13770. _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100;
  13771. _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100;
  13772. _thisLayerFunction.inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  13773. _thisLayerFunction.outPoint = elem.data.op / elem.comp.globalData.frameRate;
  13774. _thisLayerFunction._name = elem.data.nm;
  13775. _thisLayerFunction.registerMaskInterface = _registerMaskInterface;
  13776. _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface;
  13777. return _thisLayerFunction;
  13778. };
  13779. }());
  13780. const propertyGroupFactory = (function () {
  13781. return function (interfaceFunction, parentPropertyGroup) {
  13782. return function (val) {
  13783. val = val === undefined ? 1 : val;
  13784. if (val <= 0) {
  13785. return interfaceFunction;
  13786. }
  13787. return parentPropertyGroup(val - 1);
  13788. };
  13789. };
  13790. }());
  13791. const PropertyInterface = (function () {
  13792. return function (propertyName, propertyGroup) {
  13793. var interfaceFunction = {
  13794. _name: propertyName,
  13795. };
  13796. function _propertyGroup(val) {
  13797. val = val === undefined ? 1 : val;
  13798. if (val <= 0) {
  13799. return interfaceFunction;
  13800. }
  13801. return propertyGroup(val - 1);
  13802. }
  13803. return _propertyGroup;
  13804. };
  13805. }());
  13806. const EffectsExpressionInterface = (function () {
  13807. var ob = {
  13808. createEffectsInterface: createEffectsInterface,
  13809. };
  13810. function createEffectsInterface(elem, propertyGroup) {
  13811. if (elem.effectsManager) {
  13812. var effectElements = [];
  13813. var effectsData = elem.data.ef;
  13814. var i;
  13815. var len = elem.effectsManager.effectElements.length;
  13816. for (i = 0; i < len; i += 1) {
  13817. effectElements.push(createGroupInterface(effectsData[i], elem.effectsManager.effectElements[i], propertyGroup, elem));
  13818. }
  13819. var effects = elem.data.ef || [];
  13820. var groupInterface = function (name) {
  13821. i = 0;
  13822. len = effects.length;
  13823. while (i < len) {
  13824. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  13825. return effectElements[i];
  13826. }
  13827. i += 1;
  13828. }
  13829. return null;
  13830. };
  13831. Object.defineProperty(groupInterface, 'numProperties', {
  13832. get: function () {
  13833. return effects.length;
  13834. },
  13835. });
  13836. return groupInterface;
  13837. }
  13838. return null;
  13839. }
  13840. function createGroupInterface(data, elements, propertyGroup, elem) {
  13841. function groupInterface(name) {
  13842. var effects = data.ef;
  13843. var i = 0;
  13844. var len = effects.length;
  13845. while (i < len) {
  13846. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  13847. if (effects[i].ty === 5) {
  13848. return effectElements[i];
  13849. }
  13850. return effectElements[i]();
  13851. }
  13852. i += 1;
  13853. }
  13854. throw new Error();
  13855. }
  13856. var _propertyGroup = propertyGroupFactory(groupInterface, propertyGroup);
  13857. var effectElements = [];
  13858. var i;
  13859. var len = data.ef.length;
  13860. for (i = 0; i < len; i += 1) {
  13861. if (data.ef[i].ty === 5) {
  13862. effectElements.push(createGroupInterface(data.ef[i], elements.effectElements[i], elements.effectElements[i].propertyGroup, elem));
  13863. } else {
  13864. effectElements.push(createValueInterface(elements.effectElements[i], data.ef[i].ty, elem, _propertyGroup));
  13865. }
  13866. }
  13867. if (data.mn === 'ADBE Color Control') {
  13868. Object.defineProperty(groupInterface, 'color', {
  13869. get: function () {
  13870. return effectElements[0]();
  13871. },
  13872. });
  13873. }
  13874. Object.defineProperties(groupInterface, {
  13875. numProperties: {
  13876. get: function () {
  13877. return data.np;
  13878. },
  13879. },
  13880. _name: { value: data.nm },
  13881. propertyGroup: { value: _propertyGroup },
  13882. });
  13883. groupInterface.enabled = data.en !== 0;
  13884. groupInterface.active = groupInterface.enabled;
  13885. return groupInterface;
  13886. }
  13887. function createValueInterface(element, type, elem, propertyGroup) {
  13888. var expressionProperty = ExpressionPropertyInterface(element.p);
  13889. function interfaceFunction() {
  13890. if (type === 10) {
  13891. return elem.comp.compInterface(element.p.v);
  13892. }
  13893. return expressionProperty();
  13894. }
  13895. if (element.p.setGroupProperty) {
  13896. element.p.setGroupProperty(PropertyInterface('', propertyGroup));
  13897. }
  13898. return interfaceFunction;
  13899. }
  13900. return ob;
  13901. }());
  13902. const ShapePathInterface = (
  13903. function () {
  13904. return function pathInterfaceFactory(shape, view, propertyGroup) {
  13905. var prop = view.sh;
  13906. function interfaceFunction(val) {
  13907. if (val === 'Shape' || val === 'shape' || val === 'Path' || val === 'path' || val === 'ADBE Vector Shape' || val === 2) {
  13908. return interfaceFunction.path;
  13909. }
  13910. return null;
  13911. }
  13912. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13913. prop.setGroupProperty(PropertyInterface('Path', _propertyGroup));
  13914. Object.defineProperties(interfaceFunction, {
  13915. path: {
  13916. get: function () {
  13917. if (prop.k) {
  13918. prop.getValue();
  13919. }
  13920. return prop;
  13921. },
  13922. },
  13923. shape: {
  13924. get: function () {
  13925. if (prop.k) {
  13926. prop.getValue();
  13927. }
  13928. return prop;
  13929. },
  13930. },
  13931. _name: { value: shape.nm },
  13932. ix: { value: shape.ix },
  13933. propertyIndex: { value: shape.ix },
  13934. mn: { value: shape.mn },
  13935. propertyGroup: { value: propertyGroup },
  13936. });
  13937. return interfaceFunction;
  13938. };
  13939. }()
  13940. );
  13941. const ShapeExpressionInterface = (function () {
  13942. function iterateElements(shapes, view, propertyGroup) {
  13943. var arr = [];
  13944. var i;
  13945. var len = shapes ? shapes.length : 0;
  13946. for (i = 0; i < len; i += 1) {
  13947. if (shapes[i].ty === 'gr') {
  13948. arr.push(groupInterfaceFactory(shapes[i], view[i], propertyGroup));
  13949. } else if (shapes[i].ty === 'fl') {
  13950. arr.push(fillInterfaceFactory(shapes[i], view[i], propertyGroup));
  13951. } else if (shapes[i].ty === 'st') {
  13952. arr.push(strokeInterfaceFactory(shapes[i], view[i], propertyGroup));
  13953. } else if (shapes[i].ty === 'tm') {
  13954. arr.push(trimInterfaceFactory(shapes[i], view[i], propertyGroup));
  13955. } else if (shapes[i].ty === 'tr') {
  13956. // arr.push(transformInterfaceFactory(shapes[i],view[i],propertyGroup));
  13957. } else if (shapes[i].ty === 'el') {
  13958. arr.push(ellipseInterfaceFactory(shapes[i], view[i], propertyGroup));
  13959. } else if (shapes[i].ty === 'sr') {
  13960. arr.push(starInterfaceFactory(shapes[i], view[i], propertyGroup));
  13961. } else if (shapes[i].ty === 'sh') {
  13962. arr.push(ShapePathInterface(shapes[i], view[i], propertyGroup));
  13963. } else if (shapes[i].ty === 'rc') {
  13964. arr.push(rectInterfaceFactory(shapes[i], view[i], propertyGroup));
  13965. } else if (shapes[i].ty === 'rd') {
  13966. arr.push(roundedInterfaceFactory(shapes[i], view[i], propertyGroup));
  13967. } else if (shapes[i].ty === 'rp') {
  13968. arr.push(repeaterInterfaceFactory(shapes[i], view[i], propertyGroup));
  13969. } else if (shapes[i].ty === 'gf') {
  13970. arr.push(gradientFillInterfaceFactory(shapes[i], view[i], propertyGroup));
  13971. } else {
  13972. arr.push(defaultInterfaceFactory(shapes[i], view[i], propertyGroup));
  13973. }
  13974. }
  13975. return arr;
  13976. }
  13977. function contentsInterfaceFactory(shape, view, propertyGroup) {
  13978. var interfaces;
  13979. var interfaceFunction = function _interfaceFunction(value) {
  13980. var i = 0;
  13981. var len = interfaces.length;
  13982. while (i < len) {
  13983. if (interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value) {
  13984. return interfaces[i];
  13985. }
  13986. i += 1;
  13987. }
  13988. if (typeof value === 'number') {
  13989. return interfaces[value - 1];
  13990. }
  13991. return null;
  13992. };
  13993. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13994. interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup);
  13995. interfaceFunction.numProperties = interfaces.length;
  13996. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  13997. interfaceFunction.transform = transformInterface;
  13998. interfaceFunction.propertyIndex = shape.cix;
  13999. interfaceFunction._name = shape.nm;
  14000. return interfaceFunction;
  14001. }
  14002. function groupInterfaceFactory(shape, view, propertyGroup) {
  14003. var interfaceFunction = function _interfaceFunction(value) {
  14004. switch (value) {
  14005. case 'ADBE Vectors Group':
  14006. case 'Contents':
  14007. case 2:
  14008. return interfaceFunction.content;
  14009. // Not necessary for now. Keeping them here in case a new case appears
  14010. // case 'ADBE Vector Transform Group':
  14011. // case 3:
  14012. default:
  14013. return interfaceFunction.transform;
  14014. }
  14015. };
  14016. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  14017. var content = contentsInterfaceFactory(shape, view, interfaceFunction.propertyGroup);
  14018. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  14019. interfaceFunction.content = content;
  14020. interfaceFunction.transform = transformInterface;
  14021. Object.defineProperty(interfaceFunction, '_name', {
  14022. get: function () {
  14023. return shape.nm;
  14024. },
  14025. });
  14026. // interfaceFunction.content = interfaceFunction;
  14027. interfaceFunction.numProperties = shape.np;
  14028. interfaceFunction.propertyIndex = shape.ix;
  14029. interfaceFunction.nm = shape.nm;
  14030. interfaceFunction.mn = shape.mn;
  14031. return interfaceFunction;
  14032. }
  14033. function fillInterfaceFactory(shape, view, propertyGroup) {
  14034. function interfaceFunction(val) {
  14035. if (val === 'Color' || val === 'color') {
  14036. return interfaceFunction.color;
  14037. } if (val === 'Opacity' || val === 'opacity') {
  14038. return interfaceFunction.opacity;
  14039. }
  14040. return null;
  14041. }
  14042. Object.defineProperties(interfaceFunction, {
  14043. color: {
  14044. get: ExpressionPropertyInterface(view.c),
  14045. },
  14046. opacity: {
  14047. get: ExpressionPropertyInterface(view.o),
  14048. },
  14049. _name: { value: shape.nm },
  14050. mn: { value: shape.mn },
  14051. });
  14052. view.c.setGroupProperty(PropertyInterface('Color', propertyGroup));
  14053. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  14054. return interfaceFunction;
  14055. }
  14056. function gradientFillInterfaceFactory(shape, view, propertyGroup) {
  14057. function interfaceFunction(val) {
  14058. if (val === 'Start Point' || val === 'start point') {
  14059. return interfaceFunction.startPoint;
  14060. }
  14061. if (val === 'End Point' || val === 'end point') {
  14062. return interfaceFunction.endPoint;
  14063. }
  14064. if (val === 'Opacity' || val === 'opacity') {
  14065. return interfaceFunction.opacity;
  14066. }
  14067. return null;
  14068. }
  14069. Object.defineProperties(interfaceFunction, {
  14070. startPoint: {
  14071. get: ExpressionPropertyInterface(view.s),
  14072. },
  14073. endPoint: {
  14074. get: ExpressionPropertyInterface(view.e),
  14075. },
  14076. opacity: {
  14077. get: ExpressionPropertyInterface(view.o),
  14078. },
  14079. type: {
  14080. get: function () {
  14081. return 'a';
  14082. },
  14083. },
  14084. _name: { value: shape.nm },
  14085. mn: { value: shape.mn },
  14086. });
  14087. view.s.setGroupProperty(PropertyInterface('Start Point', propertyGroup));
  14088. view.e.setGroupProperty(PropertyInterface('End Point', propertyGroup));
  14089. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  14090. return interfaceFunction;
  14091. }
  14092. function defaultInterfaceFactory() {
  14093. function interfaceFunction() {
  14094. return null;
  14095. }
  14096. return interfaceFunction;
  14097. }
  14098. function strokeInterfaceFactory(shape, view, propertyGroup) {
  14099. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  14100. var _dashPropertyGroup = propertyGroupFactory(dashOb, _propertyGroup);
  14101. function addPropertyToDashOb(i) {
  14102. Object.defineProperty(dashOb, shape.d[i].nm, {
  14103. get: ExpressionPropertyInterface(view.d.dataProps[i].p),
  14104. });
  14105. }
  14106. var i;
  14107. var len = shape.d ? shape.d.length : 0;
  14108. var dashOb = {};
  14109. for (i = 0; i < len; i += 1) {
  14110. addPropertyToDashOb(i);
  14111. view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup);
  14112. }
  14113. function interfaceFunction(val) {
  14114. if (val === 'Color' || val === 'color') {
  14115. return interfaceFunction.color;
  14116. } if (val === 'Opacity' || val === 'opacity') {
  14117. return interfaceFunction.opacity;
  14118. } if (val === 'Stroke Width' || val === 'stroke width') {
  14119. return interfaceFunction.strokeWidth;
  14120. }
  14121. return null;
  14122. }
  14123. Object.defineProperties(interfaceFunction, {
  14124. color: {
  14125. get: ExpressionPropertyInterface(view.c),
  14126. },
  14127. opacity: {
  14128. get: ExpressionPropertyInterface(view.o),
  14129. },
  14130. strokeWidth: {
  14131. get: ExpressionPropertyInterface(view.w),
  14132. },
  14133. dash: {
  14134. get: function () {
  14135. return dashOb;
  14136. },
  14137. },
  14138. _name: { value: shape.nm },
  14139. mn: { value: shape.mn },
  14140. });
  14141. view.c.setGroupProperty(PropertyInterface('Color', _propertyGroup));
  14142. view.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  14143. view.w.setGroupProperty(PropertyInterface('Stroke Width', _propertyGroup));
  14144. return interfaceFunction;
  14145. }
  14146. function trimInterfaceFactory(shape, view, propertyGroup) {
  14147. function interfaceFunction(val) {
  14148. if (val === shape.e.ix || val === 'End' || val === 'end') {
  14149. return interfaceFunction.end;
  14150. }
  14151. if (val === shape.s.ix) {
  14152. return interfaceFunction.start;
  14153. }
  14154. if (val === shape.o.ix) {
  14155. return interfaceFunction.offset;
  14156. }
  14157. return null;
  14158. }
  14159. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  14160. interfaceFunction.propertyIndex = shape.ix;
  14161. view.s.setGroupProperty(PropertyInterface('Start', _propertyGroup));
  14162. view.e.setGroupProperty(PropertyInterface('End', _propertyGroup));
  14163. view.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  14164. interfaceFunction.propertyIndex = shape.ix;
  14165. interfaceFunction.propertyGroup = propertyGroup;
  14166. Object.defineProperties(interfaceFunction, {
  14167. start: {
  14168. get: ExpressionPropertyInterface(view.s),
  14169. },
  14170. end: {
  14171. get: ExpressionPropertyInterface(view.e),
  14172. },
  14173. offset: {
  14174. get: ExpressionPropertyInterface(view.o),
  14175. },
  14176. _name: { value: shape.nm },
  14177. });
  14178. interfaceFunction.mn = shape.mn;
  14179. return interfaceFunction;
  14180. }
  14181. function transformInterfaceFactory(shape, view, propertyGroup) {
  14182. function interfaceFunction(value) {
  14183. if (shape.a.ix === value || value === 'Anchor Point') {
  14184. return interfaceFunction.anchorPoint;
  14185. }
  14186. if (shape.o.ix === value || value === 'Opacity') {
  14187. return interfaceFunction.opacity;
  14188. }
  14189. if (shape.p.ix === value || value === 'Position') {
  14190. return interfaceFunction.position;
  14191. }
  14192. if (shape.r.ix === value || value === 'Rotation' || value === 'ADBE Vector Rotation') {
  14193. return interfaceFunction.rotation;
  14194. }
  14195. if (shape.s.ix === value || value === 'Scale') {
  14196. return interfaceFunction.scale;
  14197. }
  14198. if ((shape.sk && shape.sk.ix === value) || value === 'Skew') {
  14199. return interfaceFunction.skew;
  14200. }
  14201. if ((shape.sa && shape.sa.ix === value) || value === 'Skew Axis') {
  14202. return interfaceFunction.skewAxis;
  14203. }
  14204. return null;
  14205. }
  14206. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  14207. view.transform.mProps.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  14208. view.transform.mProps.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  14209. view.transform.mProps.a.setGroupProperty(PropertyInterface('Anchor Point', _propertyGroup));
  14210. view.transform.mProps.s.setGroupProperty(PropertyInterface('Scale', _propertyGroup));
  14211. view.transform.mProps.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  14212. if (view.transform.mProps.sk) {
  14213. view.transform.mProps.sk.setGroupProperty(PropertyInterface('Skew', _propertyGroup));
  14214. view.transform.mProps.sa.setGroupProperty(PropertyInterface('Skew Angle', _propertyGroup));
  14215. }
  14216. view.transform.op.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  14217. Object.defineProperties(interfaceFunction, {
  14218. opacity: {
  14219. get: ExpressionPropertyInterface(view.transform.mProps.o),
  14220. },
  14221. position: {
  14222. get: ExpressionPropertyInterface(view.transform.mProps.p),
  14223. },
  14224. anchorPoint: {
  14225. get: ExpressionPropertyInterface(view.transform.mProps.a),
  14226. },
  14227. scale: {
  14228. get: ExpressionPropertyInterface(view.transform.mProps.s),
  14229. },
  14230. rotation: {
  14231. get: ExpressionPropertyInterface(view.transform.mProps.r),
  14232. },
  14233. skew: {
  14234. get: ExpressionPropertyInterface(view.transform.mProps.sk),
  14235. },
  14236. skewAxis: {
  14237. get: ExpressionPropertyInterface(view.transform.mProps.sa),
  14238. },
  14239. _name: { value: shape.nm },
  14240. });
  14241. interfaceFunction.ty = 'tr';
  14242. interfaceFunction.mn = shape.mn;
  14243. interfaceFunction.propertyGroup = propertyGroup;
  14244. return interfaceFunction;
  14245. }
  14246. function ellipseInterfaceFactory(shape, view, propertyGroup) {
  14247. function interfaceFunction(value) {
  14248. if (shape.p.ix === value) {
  14249. return interfaceFunction.position;
  14250. }
  14251. if (shape.s.ix === value) {
  14252. return interfaceFunction.size;
  14253. }
  14254. return null;
  14255. }
  14256. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  14257. interfaceFunction.propertyIndex = shape.ix;
  14258. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  14259. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  14260. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  14261. Object.defineProperties(interfaceFunction, {
  14262. size: {
  14263. get: ExpressionPropertyInterface(prop.s),
  14264. },
  14265. position: {
  14266. get: ExpressionPropertyInterface(prop.p),
  14267. },
  14268. _name: { value: shape.nm },
  14269. });
  14270. interfaceFunction.mn = shape.mn;
  14271. return interfaceFunction;
  14272. }
  14273. function starInterfaceFactory(shape, view, propertyGroup) {
  14274. function interfaceFunction(value) {
  14275. if (shape.p.ix === value) {
  14276. return interfaceFunction.position;
  14277. }
  14278. if (shape.r.ix === value) {
  14279. return interfaceFunction.rotation;
  14280. }
  14281. if (shape.pt.ix === value) {
  14282. return interfaceFunction.points;
  14283. }
  14284. if (shape.or.ix === value || value === 'ADBE Vector Star Outer Radius') {
  14285. return interfaceFunction.outerRadius;
  14286. }
  14287. if (shape.os.ix === value) {
  14288. return interfaceFunction.outerRoundness;
  14289. }
  14290. if (shape.ir && (shape.ir.ix === value || value === 'ADBE Vector Star Inner Radius')) {
  14291. return interfaceFunction.innerRadius;
  14292. }
  14293. if (shape.is && shape.is.ix === value) {
  14294. return interfaceFunction.innerRoundness;
  14295. }
  14296. return null;
  14297. }
  14298. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  14299. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  14300. interfaceFunction.propertyIndex = shape.ix;
  14301. prop.or.setGroupProperty(PropertyInterface('Outer Radius', _propertyGroup));
  14302. prop.os.setGroupProperty(PropertyInterface('Outer Roundness', _propertyGroup));
  14303. prop.pt.setGroupProperty(PropertyInterface('Points', _propertyGroup));
  14304. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  14305. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  14306. if (shape.ir) {
  14307. prop.ir.setGroupProperty(PropertyInterface('Inner Radius', _propertyGroup));
  14308. prop.is.setGroupProperty(PropertyInterface('Inner Roundness', _propertyGroup));
  14309. }
  14310. Object.defineProperties(interfaceFunction, {
  14311. position: {
  14312. get: ExpressionPropertyInterface(prop.p),
  14313. },
  14314. rotation: {
  14315. get: ExpressionPropertyInterface(prop.r),
  14316. },
  14317. points: {
  14318. get: ExpressionPropertyInterface(prop.pt),
  14319. },
  14320. outerRadius: {
  14321. get: ExpressionPropertyInterface(prop.or),
  14322. },
  14323. outerRoundness: {
  14324. get: ExpressionPropertyInterface(prop.os),
  14325. },
  14326. innerRadius: {
  14327. get: ExpressionPropertyInterface(prop.ir),
  14328. },
  14329. innerRoundness: {
  14330. get: ExpressionPropertyInterface(prop.is),
  14331. },
  14332. _name: { value: shape.nm },
  14333. });
  14334. interfaceFunction.mn = shape.mn;
  14335. return interfaceFunction;
  14336. }
  14337. function rectInterfaceFactory(shape, view, propertyGroup) {
  14338. function interfaceFunction(value) {
  14339. if (shape.p.ix === value) {
  14340. return interfaceFunction.position;
  14341. }
  14342. if (shape.r.ix === value) {
  14343. return interfaceFunction.roundness;
  14344. }
  14345. if (shape.s.ix === value || value === 'Size' || value === 'ADBE Vector Rect Size') {
  14346. return interfaceFunction.size;
  14347. }
  14348. return null;
  14349. }
  14350. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  14351. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  14352. interfaceFunction.propertyIndex = shape.ix;
  14353. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  14354. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  14355. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  14356. Object.defineProperties(interfaceFunction, {
  14357. position: {
  14358. get: ExpressionPropertyInterface(prop.p),
  14359. },
  14360. roundness: {
  14361. get: ExpressionPropertyInterface(prop.r),
  14362. },
  14363. size: {
  14364. get: ExpressionPropertyInterface(prop.s),
  14365. },
  14366. _name: { value: shape.nm },
  14367. });
  14368. interfaceFunction.mn = shape.mn;
  14369. return interfaceFunction;
  14370. }
  14371. function roundedInterfaceFactory(shape, view, propertyGroup) {
  14372. function interfaceFunction(value) {
  14373. if (shape.r.ix === value || value === 'Round Corners 1') {
  14374. return interfaceFunction.radius;
  14375. }
  14376. return null;
  14377. }
  14378. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  14379. var prop = view;
  14380. interfaceFunction.propertyIndex = shape.ix;
  14381. prop.rd.setGroupProperty(PropertyInterface('Radius', _propertyGroup));
  14382. Object.defineProperties(interfaceFunction, {
  14383. radius: {
  14384. get: ExpressionPropertyInterface(prop.rd),
  14385. },
  14386. _name: { value: shape.nm },
  14387. });
  14388. interfaceFunction.mn = shape.mn;
  14389. return interfaceFunction;
  14390. }
  14391. function repeaterInterfaceFactory(shape, view, propertyGroup) {
  14392. function interfaceFunction(value) {
  14393. if (shape.c.ix === value || value === 'Copies') {
  14394. return interfaceFunction.copies;
  14395. } if (shape.o.ix === value || value === 'Offset') {
  14396. return interfaceFunction.offset;
  14397. }
  14398. return null;
  14399. }
  14400. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  14401. var prop = view;
  14402. interfaceFunction.propertyIndex = shape.ix;
  14403. prop.c.setGroupProperty(PropertyInterface('Copies', _propertyGroup));
  14404. prop.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  14405. Object.defineProperties(interfaceFunction, {
  14406. copies: {
  14407. get: ExpressionPropertyInterface(prop.c),
  14408. },
  14409. offset: {
  14410. get: ExpressionPropertyInterface(prop.o),
  14411. },
  14412. _name: { value: shape.nm },
  14413. });
  14414. interfaceFunction.mn = shape.mn;
  14415. return interfaceFunction;
  14416. }
  14417. return function (shapes, view, propertyGroup) {
  14418. var interfaces;
  14419. function _interfaceFunction(value) {
  14420. if (typeof value === 'number') {
  14421. value = value === undefined ? 1 : value;
  14422. if (value === 0) {
  14423. return propertyGroup;
  14424. }
  14425. return interfaces[value - 1];
  14426. }
  14427. var i = 0;
  14428. var len = interfaces.length;
  14429. while (i < len) {
  14430. if (interfaces[i]._name === value) {
  14431. return interfaces[i];
  14432. }
  14433. i += 1;
  14434. }
  14435. return null;
  14436. }
  14437. function parentGroupWrapper() {
  14438. return propertyGroup;
  14439. }
  14440. _interfaceFunction.propertyGroup = propertyGroupFactory(_interfaceFunction, parentGroupWrapper);
  14441. interfaces = iterateElements(shapes, view, _interfaceFunction.propertyGroup);
  14442. _interfaceFunction.numProperties = interfaces.length;
  14443. _interfaceFunction._name = 'Contents';
  14444. return _interfaceFunction;
  14445. };
  14446. }());
  14447. const TextExpressionInterface = (function () {
  14448. return function (elem) {
  14449. var _sourceText;
  14450. function _thisLayerFunction(name) {
  14451. switch (name) {
  14452. case 'ADBE Text Document':
  14453. return _thisLayerFunction.sourceText;
  14454. default:
  14455. return null;
  14456. }
  14457. }
  14458. Object.defineProperty(_thisLayerFunction, 'sourceText', {
  14459. get: function () {
  14460. elem.textProperty.getValue();
  14461. var stringValue = elem.textProperty.currentData.t;
  14462. if (!_sourceText || stringValue !== _sourceText.value) {
  14463. _sourceText = new String(stringValue); // eslint-disable-line no-new-wrappers
  14464. // If stringValue is an empty string, eval returns undefined, so it has to be returned as a String primitive
  14465. _sourceText.value = stringValue || new String(stringValue); // eslint-disable-line no-new-wrappers
  14466. Object.defineProperty(_sourceText, 'style', {
  14467. get: function () {
  14468. return {
  14469. fillColor: elem.textProperty.currentData.fc,
  14470. };
  14471. },
  14472. });
  14473. }
  14474. return _sourceText;
  14475. },
  14476. });
  14477. return _thisLayerFunction;
  14478. };
  14479. }());
  14480. const FootageInterface = (function () {
  14481. var outlineInterfaceFactory = (function (elem) {
  14482. var currentPropertyName = '';
  14483. var currentProperty = elem.getFootageData();
  14484. function init() {
  14485. currentPropertyName = '';
  14486. currentProperty = elem.getFootageData();
  14487. return searchProperty;
  14488. }
  14489. function searchProperty(value) {
  14490. if (currentProperty[value]) {
  14491. currentPropertyName = value;
  14492. currentProperty = currentProperty[value];
  14493. if (typeof currentProperty === 'object') {
  14494. return searchProperty;
  14495. }
  14496. return currentProperty;
  14497. }
  14498. var propertyNameIndex = value.indexOf(currentPropertyName);
  14499. if (propertyNameIndex !== -1) {
  14500. var index = parseInt(value.substr(propertyNameIndex + currentPropertyName.length), 10);
  14501. currentProperty = currentProperty[index];
  14502. if (typeof currentProperty === 'object') {
  14503. return searchProperty;
  14504. }
  14505. return currentProperty;
  14506. }
  14507. return '';
  14508. }
  14509. return init;
  14510. });
  14511. var dataInterfaceFactory = function (elem) {
  14512. function interfaceFunction(value) {
  14513. if (value === 'Outline') {
  14514. return interfaceFunction.outlineInterface();
  14515. }
  14516. return null;
  14517. }
  14518. interfaceFunction._name = 'Outline';
  14519. interfaceFunction.outlineInterface = outlineInterfaceFactory(elem);
  14520. return interfaceFunction;
  14521. };
  14522. return function (elem) {
  14523. function _interfaceFunction(value) {
  14524. if (value === 'Data') {
  14525. return _interfaceFunction.dataInterface;
  14526. }
  14527. return null;
  14528. }
  14529. _interfaceFunction._name = 'Data';
  14530. _interfaceFunction.dataInterface = dataInterfaceFactory(elem);
  14531. return _interfaceFunction;
  14532. };
  14533. }());
  14534. var interfaces = {
  14535. layer: LayerExpressionInterface,
  14536. effects: EffectsExpressionInterface,
  14537. comp: CompExpressionInterface,
  14538. shape: ShapeExpressionInterface,
  14539. text: TextExpressionInterface,
  14540. footage: FootageInterface,
  14541. };
  14542. function getInterface(type) {
  14543. return interfaces[type] || null;
  14544. }
  14545. const expressionHelpers = (function () {
  14546. function searchExpressions(elem, data, prop) {
  14547. if (data.x) {
  14548. prop.k = true;
  14549. prop.x = true;
  14550. prop.initiateExpression = ExpressionManager.initiateExpression;
  14551. prop.effectsSequence.push(prop.initiateExpression(elem, data, prop).bind(prop));
  14552. }
  14553. }
  14554. function getValueAtTime(frameNum) {
  14555. frameNum *= this.elem.globalData.frameRate;
  14556. frameNum -= this.offsetTime;
  14557. if (frameNum !== this._cachingAtTime.lastFrame) {
  14558. this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
  14559. this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
  14560. this._cachingAtTime.lastFrame = frameNum;
  14561. }
  14562. return this._cachingAtTime.value;
  14563. }
  14564. function getSpeedAtTime(frameNum) {
  14565. var delta = -0.01;
  14566. var v1 = this.getValueAtTime(frameNum);
  14567. var v2 = this.getValueAtTime(frameNum + delta);
  14568. var speed = 0;
  14569. if (v1.length) {
  14570. var i;
  14571. for (i = 0; i < v1.length; i += 1) {
  14572. speed += Math.pow(v2[i] - v1[i], 2);
  14573. }
  14574. speed = Math.sqrt(speed) * 100;
  14575. } else {
  14576. speed = 0;
  14577. }
  14578. return speed;
  14579. }
  14580. function getVelocityAtTime(frameNum) {
  14581. if (this.vel !== undefined) {
  14582. return this.vel;
  14583. }
  14584. var delta = -0.001;
  14585. // frameNum += this.elem.data.st;
  14586. var v1 = this.getValueAtTime(frameNum);
  14587. var v2 = this.getValueAtTime(frameNum + delta);
  14588. var velocity;
  14589. if (v1.length) {
  14590. velocity = createTypedArray('float32', v1.length);
  14591. var i;
  14592. for (i = 0; i < v1.length; i += 1) {
  14593. // removing frameRate
  14594. // if needed, don't add it here
  14595. // velocity[i] = this.elem.globalData.frameRate*((v2[i] - v1[i])/delta);
  14596. velocity[i] = (v2[i] - v1[i]) / delta;
  14597. }
  14598. } else {
  14599. velocity = (v2 - v1) / delta;
  14600. }
  14601. return velocity;
  14602. }
  14603. function getStaticValueAtTime() {
  14604. return this.pv;
  14605. }
  14606. function setGroupProperty(propertyGroup) {
  14607. this.propertyGroup = propertyGroup;
  14608. }
  14609. return {
  14610. searchExpressions: searchExpressions,
  14611. getSpeedAtTime: getSpeedAtTime,
  14612. getVelocityAtTime: getVelocityAtTime,
  14613. getValueAtTime: getValueAtTime,
  14614. getStaticValueAtTime: getStaticValueAtTime,
  14615. setGroupProperty: setGroupProperty,
  14616. };
  14617. }());
  14618. function addPropertyDecorator() {
  14619. function loopOut(type, duration, durationFlag) {
  14620. if (!this.k || !this.keyframes) {
  14621. return this.pv;
  14622. }
  14623. type = type ? type.toLowerCase() : '';
  14624. var currentFrame = this.comp.renderedFrame;
  14625. var keyframes = this.keyframes;
  14626. var lastKeyFrame = keyframes[keyframes.length - 1].t;
  14627. if (currentFrame <= lastKeyFrame) {
  14628. return this.pv;
  14629. }
  14630. var cycleDuration;
  14631. var firstKeyFrame;
  14632. if (!durationFlag) {
  14633. if (!duration || duration > keyframes.length - 1) {
  14634. duration = keyframes.length - 1;
  14635. }
  14636. firstKeyFrame = keyframes[keyframes.length - 1 - duration].t;
  14637. cycleDuration = lastKeyFrame - firstKeyFrame;
  14638. } else {
  14639. if (!duration) {
  14640. cycleDuration = Math.max(0, lastKeyFrame - this.elem.data.ip);
  14641. } else {
  14642. cycleDuration = Math.abs(lastKeyFrame - this.elem.comp.globalData.frameRate * duration);
  14643. }
  14644. firstKeyFrame = lastKeyFrame - cycleDuration;
  14645. }
  14646. var i;
  14647. var len;
  14648. var ret;
  14649. if (type === 'pingpong') {
  14650. var iterations = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  14651. if (iterations % 2 !== 0) {
  14652. return this.getValueAtTime(((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14653. }
  14654. } else if (type === 'offset') {
  14655. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  14656. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  14657. var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14658. var repeats = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  14659. if (this.pv.length) {
  14660. ret = new Array(initV.length);
  14661. len = ret.length;
  14662. for (i = 0; i < len; i += 1) {
  14663. ret[i] = (endV[i] - initV[i]) * repeats + current[i];
  14664. }
  14665. return ret;
  14666. }
  14667. return (endV - initV) * repeats + current;
  14668. } else if (type === 'continue') {
  14669. var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  14670. var nextLastValue = this.getValueAtTime((lastKeyFrame - 0.001) / this.comp.globalData.frameRate, 0);
  14671. if (this.pv.length) {
  14672. ret = new Array(lastValue.length);
  14673. len = ret.length;
  14674. for (i = 0; i < len; i += 1) {
  14675. ret[i] = lastValue[i] + (lastValue[i] - nextLastValue[i]) * ((currentFrame - lastKeyFrame) / this.comp.globalData.frameRate) / 0.0005; // eslint-disable-line
  14676. }
  14677. return ret;
  14678. }
  14679. return lastValue + (lastValue - nextLastValue) * (((currentFrame - lastKeyFrame)) / 0.001);
  14680. }
  14681. return this.getValueAtTime((((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14682. }
  14683. function loopIn(type, duration, durationFlag) {
  14684. if (!this.k) {
  14685. return this.pv;
  14686. }
  14687. type = type ? type.toLowerCase() : '';
  14688. var currentFrame = this.comp.renderedFrame;
  14689. var keyframes = this.keyframes;
  14690. var firstKeyFrame = keyframes[0].t;
  14691. if (currentFrame >= firstKeyFrame) {
  14692. return this.pv;
  14693. }
  14694. var cycleDuration;
  14695. var lastKeyFrame;
  14696. if (!durationFlag) {
  14697. if (!duration || duration > keyframes.length - 1) {
  14698. duration = keyframes.length - 1;
  14699. }
  14700. lastKeyFrame = keyframes[duration].t;
  14701. cycleDuration = lastKeyFrame - firstKeyFrame;
  14702. } else {
  14703. if (!duration) {
  14704. cycleDuration = Math.max(0, this.elem.data.op - firstKeyFrame);
  14705. } else {
  14706. cycleDuration = Math.abs(this.elem.comp.globalData.frameRate * duration);
  14707. }
  14708. lastKeyFrame = firstKeyFrame + cycleDuration;
  14709. }
  14710. var i;
  14711. var len;
  14712. var ret;
  14713. if (type === 'pingpong') {
  14714. var iterations = Math.floor((firstKeyFrame - currentFrame) / cycleDuration);
  14715. if (iterations % 2 === 0) {
  14716. return this.getValueAtTime((((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14717. }
  14718. } else if (type === 'offset') {
  14719. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  14720. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  14721. var current = this.getValueAtTime((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration) + firstKeyFrame) / this.comp.globalData.frameRate, 0);
  14722. var repeats = Math.floor((firstKeyFrame - currentFrame) / cycleDuration) + 1;
  14723. if (this.pv.length) {
  14724. ret = new Array(initV.length);
  14725. len = ret.length;
  14726. for (i = 0; i < len; i += 1) {
  14727. ret[i] = current[i] - (endV[i] - initV[i]) * repeats;
  14728. }
  14729. return ret;
  14730. }
  14731. return current - (endV - initV) * repeats;
  14732. } else if (type === 'continue') {
  14733. var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  14734. var nextFirstValue = this.getValueAtTime((firstKeyFrame + 0.001) / this.comp.globalData.frameRate, 0);
  14735. if (this.pv.length) {
  14736. ret = new Array(firstValue.length);
  14737. len = ret.length;
  14738. for (i = 0; i < len; i += 1) {
  14739. ret[i] = firstValue[i] + ((firstValue[i] - nextFirstValue[i]) * (firstKeyFrame - currentFrame)) / 0.001;
  14740. }
  14741. return ret;
  14742. }
  14743. return firstValue + ((firstValue - nextFirstValue) * (firstKeyFrame - currentFrame)) / 0.001;
  14744. }
  14745. return this.getValueAtTime(((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame))) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14746. }
  14747. function smooth(width, samples) {
  14748. if (!this.k) {
  14749. return this.pv;
  14750. }
  14751. width = (width || 0.4) * 0.5;
  14752. samples = Math.floor(samples || 5);
  14753. if (samples <= 1) {
  14754. return this.pv;
  14755. }
  14756. var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate;
  14757. var initFrame = currentTime - width;
  14758. var endFrame = currentTime + width;
  14759. var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1;
  14760. var i = 0;
  14761. var j = 0;
  14762. var value;
  14763. if (this.pv.length) {
  14764. value = createTypedArray('float32', this.pv.length);
  14765. } else {
  14766. value = 0;
  14767. }
  14768. var sampleValue;
  14769. while (i < samples) {
  14770. sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency);
  14771. if (this.pv.length) {
  14772. for (j = 0; j < this.pv.length; j += 1) {
  14773. value[j] += sampleValue[j];
  14774. }
  14775. } else {
  14776. value += sampleValue;
  14777. }
  14778. i += 1;
  14779. }
  14780. if (this.pv.length) {
  14781. for (j = 0; j < this.pv.length; j += 1) {
  14782. value[j] /= samples;
  14783. }
  14784. } else {
  14785. value /= samples;
  14786. }
  14787. return value;
  14788. }
  14789. function getTransformValueAtTime(time) {
  14790. if (!this._transformCachingAtTime) {
  14791. this._transformCachingAtTime = {
  14792. v: new Matrix(),
  14793. };
  14794. }
  14795. /// /
  14796. var matrix = this._transformCachingAtTime.v;
  14797. matrix.cloneFromProps(this.pre.props);
  14798. if (this.appliedTransformations < 1) {
  14799. var anchor = this.a.getValueAtTime(time);
  14800. matrix.translate(
  14801. -anchor[0] * this.a.mult,
  14802. -anchor[1] * this.a.mult,
  14803. anchor[2] * this.a.mult
  14804. );
  14805. }
  14806. if (this.appliedTransformations < 2) {
  14807. var scale = this.s.getValueAtTime(time);
  14808. matrix.scale(
  14809. scale[0] * this.s.mult,
  14810. scale[1] * this.s.mult,
  14811. scale[2] * this.s.mult
  14812. );
  14813. }
  14814. if (this.sk && this.appliedTransformations < 3) {
  14815. var skew = this.sk.getValueAtTime(time);
  14816. var skewAxis = this.sa.getValueAtTime(time);
  14817. matrix.skewFromAxis(-skew * this.sk.mult, skewAxis * this.sa.mult);
  14818. }
  14819. if (this.r && this.appliedTransformations < 4) {
  14820. var rotation = this.r.getValueAtTime(time);
  14821. matrix.rotate(-rotation * this.r.mult);
  14822. } else if (!this.r && this.appliedTransformations < 4) {
  14823. var rotationZ = this.rz.getValueAtTime(time);
  14824. var rotationY = this.ry.getValueAtTime(time);
  14825. var rotationX = this.rx.getValueAtTime(time);
  14826. var orientation = this.or.getValueAtTime(time);
  14827. matrix.rotateZ(-rotationZ * this.rz.mult)
  14828. .rotateY(rotationY * this.ry.mult)
  14829. .rotateX(rotationX * this.rx.mult)
  14830. .rotateZ(-orientation[2] * this.or.mult)
  14831. .rotateY(orientation[1] * this.or.mult)
  14832. .rotateX(orientation[0] * this.or.mult);
  14833. }
  14834. if (this.data.p && this.data.p.s) {
  14835. var positionX = this.px.getValueAtTime(time);
  14836. var positionY = this.py.getValueAtTime(time);
  14837. if (this.data.p.z) {
  14838. var positionZ = this.pz.getValueAtTime(time);
  14839. matrix.translate(
  14840. positionX * this.px.mult,
  14841. positionY * this.py.mult,
  14842. -positionZ * this.pz.mult
  14843. );
  14844. } else {
  14845. matrix.translate(positionX * this.px.mult, positionY * this.py.mult, 0);
  14846. }
  14847. } else {
  14848. var position = this.p.getValueAtTime(time);
  14849. matrix.translate(
  14850. position[0] * this.p.mult,
  14851. position[1] * this.p.mult,
  14852. -position[2] * this.p.mult
  14853. );
  14854. }
  14855. return matrix;
  14856. /// /
  14857. }
  14858. function getTransformStaticValueAtTime() {
  14859. return this.v.clone(new Matrix());
  14860. }
  14861. var getTransformProperty = TransformPropertyFactory.getTransformProperty;
  14862. TransformPropertyFactory.getTransformProperty = function (elem, data, container) {
  14863. var prop = getTransformProperty(elem, data, container);
  14864. if (prop.dynamicProperties.length) {
  14865. prop.getValueAtTime = getTransformValueAtTime.bind(prop);
  14866. } else {
  14867. prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop);
  14868. }
  14869. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  14870. return prop;
  14871. };
  14872. var propertyGetProp = PropertyFactory.getProp;
  14873. PropertyFactory.getProp = function (elem, data, type, mult, container) {
  14874. var prop = propertyGetProp(elem, data, type, mult, container);
  14875. // prop.getVelocityAtTime = getVelocityAtTime;
  14876. // prop.loopOut = loopOut;
  14877. // prop.loopIn = loopIn;
  14878. if (prop.kf) {
  14879. prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop);
  14880. } else {
  14881. prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop);
  14882. }
  14883. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  14884. prop.loopOut = loopOut;
  14885. prop.loopIn = loopIn;
  14886. prop.smooth = smooth;
  14887. prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop);
  14888. prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop);
  14889. prop.numKeys = data.a === 1 ? data.k.length : 0;
  14890. prop.propertyIndex = data.ix;
  14891. var value = 0;
  14892. if (type !== 0) {
  14893. value = createTypedArray('float32', data.a === 1 ? data.k[0].s.length : data.k.length);
  14894. }
  14895. prop._cachingAtTime = {
  14896. lastFrame: initialDefaultFrame,
  14897. lastIndex: 0,
  14898. value: value,
  14899. };
  14900. expressionHelpers.searchExpressions(elem, data, prop);
  14901. if (prop.k) {
  14902. container.addDynamicProperty(prop);
  14903. }
  14904. return prop;
  14905. };
  14906. function getShapeValueAtTime(frameNum) {
  14907. // For now this caching object is created only when needed instead of creating it when the shape is initialized.
  14908. if (!this._cachingAtTime) {
  14909. this._cachingAtTime = {
  14910. shapeValue: shapePool.clone(this.pv),
  14911. lastIndex: 0,
  14912. lastTime: initialDefaultFrame,
  14913. };
  14914. }
  14915. frameNum *= this.elem.globalData.frameRate;
  14916. frameNum -= this.offsetTime;
  14917. if (frameNum !== this._cachingAtTime.lastTime) {
  14918. this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0;
  14919. this._cachingAtTime.lastTime = frameNum;
  14920. this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime);
  14921. }
  14922. return this._cachingAtTime.shapeValue;
  14923. }
  14924. var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction();
  14925. var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction();
  14926. function ShapeExpressions() {}
  14927. ShapeExpressions.prototype = {
  14928. vertices: function (prop, time) {
  14929. if (this.k) {
  14930. this.getValue();
  14931. }
  14932. var shapePath = this.v;
  14933. if (time !== undefined) {
  14934. shapePath = this.getValueAtTime(time, 0);
  14935. }
  14936. var i;
  14937. var len = shapePath._length;
  14938. var vertices = shapePath[prop];
  14939. var points = shapePath.v;
  14940. var arr = createSizedArray(len);
  14941. for (i = 0; i < len; i += 1) {
  14942. if (prop === 'i' || prop === 'o') {
  14943. arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]];
  14944. } else {
  14945. arr[i] = [vertices[i][0], vertices[i][1]];
  14946. }
  14947. }
  14948. return arr;
  14949. },
  14950. points: function (time) {
  14951. return this.vertices('v', time);
  14952. },
  14953. inTangents: function (time) {
  14954. return this.vertices('i', time);
  14955. },
  14956. outTangents: function (time) {
  14957. return this.vertices('o', time);
  14958. },
  14959. isClosed: function () {
  14960. return this.v.c;
  14961. },
  14962. pointOnPath: function (perc, time) {
  14963. var shapePath = this.v;
  14964. if (time !== undefined) {
  14965. shapePath = this.getValueAtTime(time, 0);
  14966. }
  14967. if (!this._segmentsLength) {
  14968. this._segmentsLength = bez.getSegmentsLength(shapePath);
  14969. }
  14970. var segmentsLength = this._segmentsLength;
  14971. var lengths = segmentsLength.lengths;
  14972. var lengthPos = segmentsLength.totalLength * perc;
  14973. var i = 0;
  14974. var len = lengths.length;
  14975. var accumulatedLength = 0;
  14976. var pt;
  14977. while (i < len) {
  14978. if (accumulatedLength + lengths[i].addedLength > lengthPos) {
  14979. var initIndex = i;
  14980. var endIndex = (shapePath.c && i === len - 1) ? 0 : i + 1;
  14981. var segmentPerc = (lengthPos - accumulatedLength) / lengths[i].addedLength;
  14982. pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]);
  14983. break;
  14984. } else {
  14985. accumulatedLength += lengths[i].addedLength;
  14986. }
  14987. i += 1;
  14988. }
  14989. if (!pt) {
  14990. pt = shapePath.c ? [shapePath.v[0][0], shapePath.v[0][1]] : [shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1]];
  14991. }
  14992. return pt;
  14993. },
  14994. vectorOnPath: function (perc, time, vectorType) {
  14995. // perc doesn't use triple equality because it can be a Number object as well as a primitive.
  14996. if (perc == 1) { // eslint-disable-line eqeqeq
  14997. perc = this.v.c;
  14998. } else if (perc == 0) { // eslint-disable-line eqeqeq
  14999. perc = 0.999;
  15000. }
  15001. var pt1 = this.pointOnPath(perc, time);
  15002. var pt2 = this.pointOnPath(perc + 0.001, time);
  15003. var xLength = pt2[0] - pt1[0];
  15004. var yLength = pt2[1] - pt1[1];
  15005. var magnitude = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2));
  15006. if (magnitude === 0) {
  15007. return [0, 0];
  15008. }
  15009. var unitVector = vectorType === 'tangent' ? [xLength / magnitude, yLength / magnitude] : [-yLength / magnitude, xLength / magnitude];
  15010. return unitVector;
  15011. },
  15012. tangentOnPath: function (perc, time) {
  15013. return this.vectorOnPath(perc, time, 'tangent');
  15014. },
  15015. normalOnPath: function (perc, time) {
  15016. return this.vectorOnPath(perc, time, 'normal');
  15017. },
  15018. setGroupProperty: expressionHelpers.setGroupProperty,
  15019. getValueAtTime: expressionHelpers.getStaticValueAtTime,
  15020. };
  15021. extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction);
  15022. extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction);
  15023. KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime;
  15024. KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression;
  15025. var propertyGetShapeProp = ShapePropertyFactory.getShapeProp;
  15026. ShapePropertyFactory.getShapeProp = function (elem, data, type, arr, trims) {
  15027. var prop = propertyGetShapeProp(elem, data, type, arr, trims);
  15028. prop.propertyIndex = data.ix;
  15029. prop.lock = false;
  15030. if (type === 3) {
  15031. expressionHelpers.searchExpressions(elem, data.pt, prop);
  15032. } else if (type === 4) {
  15033. expressionHelpers.searchExpressions(elem, data.ks, prop);
  15034. }
  15035. if (prop.k) {
  15036. elem.addDynamicProperty(prop);
  15037. }
  15038. return prop;
  15039. };
  15040. }
  15041. function initialize$1() {
  15042. addPropertyDecorator();
  15043. }
  15044. function addDecorator() {
  15045. function searchExpressions() {
  15046. if (this.data.d.x) {
  15047. this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem, this.data.d, this);
  15048. this.addEffect(this.getExpressionValue.bind(this));
  15049. return true;
  15050. }
  15051. return null;
  15052. }
  15053. TextProperty.prototype.getExpressionValue = function (currentValue, text) {
  15054. var newValue = this.calculateExpression(text);
  15055. if (currentValue.t !== newValue) {
  15056. var newData = {};
  15057. this.copyData(newData, currentValue);
  15058. newData.t = newValue.toString();
  15059. newData.__complete = false;
  15060. return newData;
  15061. }
  15062. return currentValue;
  15063. };
  15064. TextProperty.prototype.searchProperty = function () {
  15065. var isKeyframed = this.searchKeyframes();
  15066. var hasExpressions = this.searchExpressions();
  15067. this.kf = isKeyframed || hasExpressions;
  15068. return this.kf;
  15069. };
  15070. TextProperty.prototype.searchExpressions = searchExpressions;
  15071. }
  15072. function initialize() {
  15073. addDecorator();
  15074. }
  15075. function TransformEffect() {
  15076. }
  15077. TransformEffect.prototype.init = function (effectsManager) {
  15078. this.effectsManager = effectsManager;
  15079. this.type = effectTypes.TRANSFORM_EFFECT;
  15080. this.matrix = new Matrix();
  15081. this.opacity = -1;
  15082. this._mdf = false;
  15083. this._opMdf = false;
  15084. };
  15085. TransformEffect.prototype.renderFrame = function (forceFrame) {
  15086. this._opMdf = false;
  15087. this._mdf = false;
  15088. if (forceFrame || this.effectsManager._mdf) {
  15089. var effectElements = this.effectsManager.effectElements;
  15090. var anchor = effectElements[0].p.v;
  15091. var position = effectElements[1].p.v;
  15092. var isUniformScale = effectElements[2].p.v === 1;
  15093. var scaleHeight = effectElements[3].p.v;
  15094. var scaleWidth = isUniformScale ? scaleHeight : effectElements[4].p.v;
  15095. var skew = effectElements[5].p.v;
  15096. var skewAxis = effectElements[6].p.v;
  15097. var rotation = effectElements[7].p.v;
  15098. this.matrix.reset();
  15099. this.matrix.translate(-anchor[0], -anchor[1], anchor[2]);
  15100. this.matrix.scale(scaleWidth * 0.01, scaleHeight * 0.01, 1);
  15101. this.matrix.rotate(-rotation * degToRads);
  15102. this.matrix.skewFromAxis(-skew * degToRads, (skewAxis + 90) * degToRads);
  15103. this.matrix.translate(position[0], position[1], 0);
  15104. this._mdf = true;
  15105. if (this.opacity !== effectElements[8].p.v) {
  15106. this.opacity = effectElements[8].p.v;
  15107. this._opMdf = true;
  15108. }
  15109. }
  15110. };
  15111. function CVTransformEffect(effectsManager) {
  15112. this.init(effectsManager);
  15113. }
  15114. extendPrototype([TransformEffect], CVTransformEffect);
  15115. // Registering expression plugin
  15116. setExpressionsPlugin(Expressions);
  15117. setExpressionInterfaces(getInterface);
  15118. initialize$1();
  15119. initialize();
  15120. registerEffect(35, CVTransformEffect);
  15121. export { lottie as default };