lottie_worker.js 425 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121
  1. var lottiejs = (function(window) {
  2. "use strict";
  3. var svgNS = "http://www.w3.org/2000/svg";
  4. var locationHref = '';
  5. var initialDefaultFrame = -999999;
  6. var subframeEnabled = true;
  7. var expressionsPlugin;
  8. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  9. var cachedColors = {};
  10. var bm_rounder = Math.round;
  11. var bm_rnd;
  12. var bm_pow = Math.pow;
  13. var bm_sqrt = Math.sqrt;
  14. var bm_abs = Math.abs;
  15. var bm_floor = Math.floor;
  16. var bm_max = Math.max;
  17. var bm_min = Math.min;
  18. var blitter = 10;
  19. var BMMath = {};
  20. (function(){
  21. 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"];
  22. var i, len = propertyNames.length;
  23. for(i=0;i<len;i+=1){
  24. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  25. }
  26. }());
  27. function ProjectInterface(){return {};}
  28. BMMath.random = Math.random;
  29. BMMath.abs = function(val){
  30. var tOfVal = typeof val;
  31. if(tOfVal === 'object' && val.length){
  32. var absArr = createSizedArray(val.length);
  33. var i, len = val.length;
  34. for(i=0;i<len;i+=1){
  35. absArr[i] = Math.abs(val[i]);
  36. }
  37. return absArr;
  38. }
  39. return Math.abs(val);
  40. };
  41. var defaultCurveSegments = 150;
  42. var degToRads = Math.PI/180;
  43. var roundCorner = 0.5519;
  44. function roundValues(flag){
  45. if(flag){
  46. bm_rnd = Math.round;
  47. }else{
  48. bm_rnd = function(val){
  49. return val;
  50. };
  51. }
  52. }
  53. roundValues(false);
  54. function styleDiv(element){
  55. element.style.position = 'absolute';
  56. element.style.top = 0;
  57. element.style.left = 0;
  58. element.style.display = 'block';
  59. element.style.transformOrigin = element.style.webkitTransformOrigin = '0 0';
  60. element.style.backfaceVisibility = element.style.webkitBackfaceVisibility = 'visible';
  61. element.style.transformStyle = element.style.webkitTransformStyle = element.style.mozTransformStyle = "preserve-3d";
  62. }
  63. function BMEnterFrameEvent(n,c,t,d){
  64. this.type = n;
  65. this.currentTime = c;
  66. this.totalTime = t;
  67. this.direction = d < 0 ? -1:1;
  68. }
  69. function BMCompleteEvent(n,d){
  70. this.type = n;
  71. this.direction = d < 0 ? -1:1;
  72. }
  73. function BMCompleteLoopEvent(n,c,t,d){
  74. this.type = n;
  75. this.currentLoop = t;
  76. this.totalLoops = c;
  77. this.direction = d < 0 ? -1:1;
  78. }
  79. function BMSegmentStartEvent(n,f,t){
  80. this.type = n;
  81. this.firstFrame = f;
  82. this.totalFrames = t;
  83. }
  84. function BMDestroyEvent(n,t){
  85. this.type = n;
  86. this.target = t;
  87. }
  88. var createElementID = (function(){
  89. var _count = 0;
  90. return function createID() {
  91. return '__lottie_element_' + ++_count
  92. }
  93. }())
  94. function HSVtoRGB(h, s, v) {
  95. var r, g, b, i, f, p, q, t;
  96. i = Math.floor(h * 6);
  97. f = h * 6 - i;
  98. p = v * (1 - s);
  99. q = v * (1 - f * s);
  100. t = v * (1 - (1 - f) * s);
  101. switch (i % 6) {
  102. case 0: r = v; g = t; b = p; break;
  103. case 1: r = q; g = v; b = p; break;
  104. case 2: r = p; g = v; b = t; break;
  105. case 3: r = p; g = q; b = v; break;
  106. case 4: r = t; g = p; b = v; break;
  107. case 5: r = v; g = p; b = q; break;
  108. }
  109. return [ r,
  110. g,
  111. b ];
  112. }
  113. function RGBtoHSV(r, g, b) {
  114. var max = Math.max(r, g, b), min = Math.min(r, g, b),
  115. d = max - min,
  116. h,
  117. s = (max === 0 ? 0 : d / max),
  118. v = max / 255;
  119. switch (max) {
  120. case min: h = 0; break;
  121. case r: h = (g - b) + d * (g < b ? 6: 0); h /= 6 * d; break;
  122. case g: h = (b - r) + d * 2; h /= 6 * d; break;
  123. case b: h = (r - g) + d * 4; h /= 6 * d; break;
  124. }
  125. return [
  126. h,
  127. s,
  128. v
  129. ];
  130. }
  131. function addSaturationToRGB(color,offset){
  132. var hsv = RGBtoHSV(color[0]*255,color[1]*255,color[2]*255);
  133. hsv[1] += offset;
  134. if (hsv[1] > 1) {
  135. hsv[1] = 1;
  136. }
  137. else if (hsv[1] <= 0) {
  138. hsv[1] = 0;
  139. }
  140. return HSVtoRGB(hsv[0],hsv[1],hsv[2]);
  141. }
  142. function addBrightnessToRGB(color,offset){
  143. var hsv = RGBtoHSV(color[0]*255,color[1]*255,color[2]*255);
  144. hsv[2] += offset;
  145. if (hsv[2] > 1) {
  146. hsv[2] = 1;
  147. }
  148. else if (hsv[2] < 0) {
  149. hsv[2] = 0;
  150. }
  151. return HSVtoRGB(hsv[0],hsv[1],hsv[2]);
  152. }
  153. function addHueToRGB(color,offset) {
  154. var hsv = RGBtoHSV(color[0]*255,color[1]*255,color[2]*255);
  155. hsv[0] += offset/360;
  156. if (hsv[0] > 1) {
  157. hsv[0] -= 1;
  158. }
  159. else if (hsv[0] < 0) {
  160. hsv[0] += 1;
  161. }
  162. return HSVtoRGB(hsv[0],hsv[1],hsv[2]);
  163. }
  164. var rgbToHex = (function(){
  165. var colorMap = [];
  166. var i;
  167. var hex;
  168. for(i=0;i<256;i+=1){
  169. hex = i.toString(16);
  170. colorMap[i] = hex.length == 1 ? '0' + hex : hex;
  171. }
  172. return function(r, g, b) {
  173. if(r<0){
  174. r = 0;
  175. }
  176. if(g<0){
  177. g = 0;
  178. }
  179. if(b<0){
  180. b = 0;
  181. }
  182. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  183. };
  184. }());
  185. function BaseEvent(){}
  186. BaseEvent.prototype = {
  187. triggerEvent: function (eventName, args) {
  188. if (this._cbs[eventName]) {
  189. var len = this._cbs[eventName].length;
  190. for (var i = 0; i < len; i++){
  191. this._cbs[eventName][i](args);
  192. }
  193. }
  194. },
  195. addEventListener: function (eventName, callback) {
  196. if (!this._cbs[eventName]){
  197. this._cbs[eventName] = [];
  198. }
  199. this._cbs[eventName].push(callback);
  200. return function() {
  201. this.removeEventListener(eventName, callback);
  202. }.bind(this);
  203. },
  204. removeEventListener: function (eventName,callback){
  205. if (!callback){
  206. this._cbs[eventName] = null;
  207. }else if(this._cbs[eventName]){
  208. var i = 0, len = this._cbs[eventName].length;
  209. while(i<len){
  210. if(this._cbs[eventName][i] === callback){
  211. this._cbs[eventName].splice(i,1);
  212. i -=1;
  213. len -= 1;
  214. }
  215. i += 1;
  216. }
  217. if(!this._cbs[eventName].length){
  218. this._cbs[eventName] = null;
  219. }
  220. }
  221. }
  222. };
  223. var createTypedArray = (function(){
  224. function createRegularArray(type, len){
  225. var i = 0, arr = [], value;
  226. switch(type) {
  227. case 'int16':
  228. case 'uint8c':
  229. value = 1;
  230. break;
  231. default:
  232. value = 1.1;
  233. break;
  234. }
  235. for(i = 0; i < len; i += 1) {
  236. arr.push(value);
  237. }
  238. return arr;
  239. }
  240. function createTypedArray(type, len){
  241. if(type === 'float32') {
  242. return new Float32Array(len);
  243. } else if(type === 'int16') {
  244. return new Int16Array(len);
  245. } else if(type === 'uint8c') {
  246. return new Uint8ClampedArray(len);
  247. }
  248. }
  249. if(typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  250. return createTypedArray;
  251. } else {
  252. return createRegularArray;
  253. }
  254. }());
  255. function createSizedArray(len) {
  256. return Array.apply(null,{length:len});
  257. }
  258. function createTag(type) {
  259. //return {appendChild:function(){},setAttribute:function(){},style:{}}
  260. return document.createElement(type);
  261. }
  262. function DynamicPropertyContainer(){};
  263. DynamicPropertyContainer.prototype = {
  264. addDynamicProperty: function(prop) {
  265. if(this.dynamicProperties.indexOf(prop) === -1) {
  266. this.dynamicProperties.push(prop);
  267. this.container.addDynamicProperty(this);
  268. this._isAnimated = true;
  269. }
  270. },
  271. iterateDynamicProperties: function(){
  272. this._mdf = false;
  273. var i, len = this.dynamicProperties.length;
  274. for(i=0;i<len;i+=1){
  275. this.dynamicProperties[i].getValue();
  276. if(this.dynamicProperties[i]._mdf) {
  277. this._mdf = true;
  278. }
  279. }
  280. },
  281. initDynamicPropertyContainer: function(container){
  282. this.container = container;
  283. this.dynamicProperties = [];
  284. this._mdf = false;
  285. this._isAnimated = false;
  286. }
  287. }
  288. var getBlendMode = (function() {
  289. var blendModeEnums = {
  290. 0:'source-over',
  291. 1:'multiply',
  292. 2:'screen',
  293. 3:'overlay',
  294. 4:'darken',
  295. 5:'lighten',
  296. 6:'color-dodge',
  297. 7:'color-burn',
  298. 8:'hard-light',
  299. 9:'soft-light',
  300. 10:'difference',
  301. 11:'exclusion',
  302. 12:'hue',
  303. 13:'saturation',
  304. 14:'color',
  305. 15:'luminosity'
  306. }
  307. return function(mode) {
  308. return blendModeEnums[mode] || '';
  309. }
  310. }())
  311. /**
  312. * 2D transformation matrix object initialized with identity matrix.
  313. *
  314. * The matrix can synchronize a canvas context by supplying the context
  315. * as an argument, or later apply current absolute transform to an
  316. * existing context.
  317. *
  318. * All values are handled as floating point values.
  319. *
  320. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  321. * @prop {number} a - scale x
  322. * @prop {number} b - shear y
  323. * @prop {number} c - shear x
  324. * @prop {number} d - scale y
  325. * @prop {number} e - translate x
  326. * @prop {number} f - translate y
  327. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  328. * @constructor
  329. */
  330. var Matrix = (function(){
  331. var _cos = Math.cos;
  332. var _sin = Math.sin;
  333. var _tan = Math.tan;
  334. var _rnd = Math.round;
  335. function reset(){
  336. this.props[0] = 1;
  337. this.props[1] = 0;
  338. this.props[2] = 0;
  339. this.props[3] = 0;
  340. this.props[4] = 0;
  341. this.props[5] = 1;
  342. this.props[6] = 0;
  343. this.props[7] = 0;
  344. this.props[8] = 0;
  345. this.props[9] = 0;
  346. this.props[10] = 1;
  347. this.props[11] = 0;
  348. this.props[12] = 0;
  349. this.props[13] = 0;
  350. this.props[14] = 0;
  351. this.props[15] = 1;
  352. return this;
  353. }
  354. function rotate(angle) {
  355. if(angle === 0){
  356. return this;
  357. }
  358. var mCos = _cos(angle);
  359. var mSin = _sin(angle);
  360. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  361. }
  362. function rotateX(angle){
  363. if(angle === 0){
  364. return this;
  365. }
  366. var mCos = _cos(angle);
  367. var mSin = _sin(angle);
  368. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  369. }
  370. function rotateY(angle){
  371. if(angle === 0){
  372. return this;
  373. }
  374. var mCos = _cos(angle);
  375. var mSin = _sin(angle);
  376. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  377. }
  378. function rotateZ(angle){
  379. if(angle === 0){
  380. return this;
  381. }
  382. var mCos = _cos(angle);
  383. var mSin = _sin(angle);
  384. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  385. }
  386. function shear(sx,sy){
  387. return this._t(1, sy, sx, 1, 0, 0);
  388. }
  389. function skew(ax, ay){
  390. return this.shear(_tan(ax), _tan(ay));
  391. }
  392. function skewFromAxis(ax, angle){
  393. var mCos = _cos(angle);
  394. var mSin = _sin(angle);
  395. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  396. ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  397. ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  398. //return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  399. }
  400. function scale(sx, sy, sz) {
  401. if(!sz && sz !== 0) {
  402. sz = 1;
  403. }
  404. if(sx === 1 && sy === 1 && sz === 1){
  405. return this;
  406. }
  407. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  408. }
  409. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  410. this.props[0] = a;
  411. this.props[1] = b;
  412. this.props[2] = c;
  413. this.props[3] = d;
  414. this.props[4] = e;
  415. this.props[5] = f;
  416. this.props[6] = g;
  417. this.props[7] = h;
  418. this.props[8] = i;
  419. this.props[9] = j;
  420. this.props[10] = k;
  421. this.props[11] = l;
  422. this.props[12] = m;
  423. this.props[13] = n;
  424. this.props[14] = o;
  425. this.props[15] = p;
  426. return this;
  427. }
  428. function translate(tx, ty, tz) {
  429. tz = tz || 0;
  430. if(tx !== 0 || ty !== 0 || tz !== 0){
  431. return this._t(1,0,0,0,0,1,0,0,0,0,1,0,tx,ty,tz,1);
  432. }
  433. return this;
  434. }
  435. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  436. var _p = this.props;
  437. 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){
  438. //NOTE: commenting this condition because TurboFan deoptimizes code when present
  439. //if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  440. _p[12] = _p[12] * a2 + _p[15] * m2;
  441. _p[13] = _p[13] * f2 + _p[15] * n2;
  442. _p[14] = _p[14] * k2 + _p[15] * o2;
  443. _p[15] = _p[15] * p2;
  444. //}
  445. this._identityCalculated = false;
  446. return this;
  447. }
  448. var a1 = _p[0];
  449. var b1 = _p[1];
  450. var c1 = _p[2];
  451. var d1 = _p[3];
  452. var e1 = _p[4];
  453. var f1 = _p[5];
  454. var g1 = _p[6];
  455. var h1 = _p[7];
  456. var i1 = _p[8];
  457. var j1 = _p[9];
  458. var k1 = _p[10];
  459. var l1 = _p[11];
  460. var m1 = _p[12];
  461. var n1 = _p[13];
  462. var o1 = _p[14];
  463. var p1 = _p[15];
  464. /* matrix order (canvas compatible):
  465. * ace
  466. * bdf
  467. * 001
  468. */
  469. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  470. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2 ;
  471. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2 ;
  472. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2 ;
  473. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2 ;
  474. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2 ;
  475. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2 ;
  476. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2 ;
  477. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2 ;
  478. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2 ;
  479. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2 ;
  480. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2 ;
  481. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2 ;
  482. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2 ;
  483. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2 ;
  484. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2 ;
  485. this._identityCalculated = false;
  486. return this;
  487. }
  488. function isIdentity() {
  489. if(!this._identityCalculated){
  490. 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);
  491. this._identityCalculated = true;
  492. }
  493. return this._identity;
  494. }
  495. function equals(matr){
  496. var i = 0;
  497. while (i < 16) {
  498. if(matr.props[i] !== this.props[i]) {
  499. return false;
  500. }
  501. i+=1;
  502. }
  503. return true;
  504. }
  505. function clone(matr){
  506. var i;
  507. for(i=0;i<16;i+=1){
  508. matr.props[i] = this.props[i];
  509. }
  510. }
  511. function cloneFromProps(props){
  512. var i;
  513. for(i=0;i<16;i+=1){
  514. this.props[i] = props[i];
  515. }
  516. }
  517. function applyToPoint(x, y, z) {
  518. return {
  519. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  520. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  521. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]
  522. };
  523. /*return {
  524. x: x * me.a + y * me.c + me.e,
  525. y: x * me.b + y * me.d + me.f
  526. };*/
  527. }
  528. function applyToX(x, y, z) {
  529. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  530. }
  531. function applyToY(x, y, z) {
  532. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  533. }
  534. function applyToZ(x, y, z) {
  535. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  536. }
  537. function inversePoint(pt) {
  538. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  539. var a = this.props[5]/determinant;
  540. var b = - this.props[1]/determinant;
  541. var c = - this.props[4]/determinant;
  542. var d = this.props[0]/determinant;
  543. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12])/determinant;
  544. var f = - (this.props[0] * this.props[13] - this.props[1] * this.props[12])/determinant;
  545. return [pt[0] * a + pt[1] * c + e, pt[0] * b + pt[1] * d + f, 0];
  546. }
  547. function inversePoints(pts){
  548. var i, len = pts.length, retPts = [];
  549. for(i=0;i<len;i+=1){
  550. retPts[i] = inversePoint(pts[i]);
  551. }
  552. return retPts;
  553. }
  554. function applyToTriplePoints(pt1, pt2, pt3) {
  555. var arr = createTypedArray('float32', 6);
  556. if(this.isIdentity()) {
  557. arr[0] = pt1[0];
  558. arr[1] = pt1[1];
  559. arr[2] = pt2[0];
  560. arr[3] = pt2[1];
  561. arr[4] = pt3[0];
  562. arr[5] = pt3[1];
  563. } else {
  564. var p0 = this.props[0], p1 = this.props[1], p4 = this.props[4], p5 = this.props[5], p12 = this.props[12], p13 = this.props[13];
  565. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  566. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  567. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  568. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  569. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  570. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  571. }
  572. return arr;
  573. }
  574. function applyToPointArray(x,y,z){
  575. var arr;
  576. if(this.isIdentity()) {
  577. arr = [x,y,z];
  578. } else {
  579. arr = [x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]];
  580. }
  581. return arr;
  582. }
  583. function applyToPointStringified(x, y) {
  584. if(this.isIdentity()) {
  585. return x + ',' + y;
  586. }
  587. var _p = this.props;
  588. 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;
  589. }
  590. function toCSS() {
  591. //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.
  592. /*if(this.isIdentity()) {
  593. return '';
  594. }*/
  595. var i = 0;
  596. var props = this.props;
  597. var cssValue = 'matrix3d(';
  598. var v = 10000;
  599. while(i<16){
  600. cssValue += _rnd(props[i]*v)/v;
  601. cssValue += i === 15 ? ')':',';
  602. i += 1;
  603. }
  604. return cssValue;
  605. }
  606. function roundMatrixProperty(val) {
  607. var v = 10000;
  608. if((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
  609. return _rnd(val * v) / v;
  610. }
  611. return val;
  612. }
  613. function to2dCSS() {
  614. //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.
  615. /*if(this.isIdentity()) {
  616. return '';
  617. }*/
  618. var props = this.props;
  619. var _a = roundMatrixProperty(props[0]);
  620. var _b = roundMatrixProperty(props[1]);
  621. var _c = roundMatrixProperty(props[4]);
  622. var _d = roundMatrixProperty(props[5]);
  623. var _e = roundMatrixProperty(props[12]);
  624. var _f = roundMatrixProperty(props[13]);
  625. return "matrix(" + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ")";
  626. }
  627. return function(){
  628. this.reset = reset;
  629. this.rotate = rotate;
  630. this.rotateX = rotateX;
  631. this.rotateY = rotateY;
  632. this.rotateZ = rotateZ;
  633. this.skew = skew;
  634. this.skewFromAxis = skewFromAxis;
  635. this.shear = shear;
  636. this.scale = scale;
  637. this.setTransform = setTransform;
  638. this.translate = translate;
  639. this.transform = transform;
  640. this.applyToPoint = applyToPoint;
  641. this.applyToX = applyToX;
  642. this.applyToY = applyToY;
  643. this.applyToZ = applyToZ;
  644. this.applyToPointArray = applyToPointArray;
  645. this.applyToTriplePoints = applyToTriplePoints;
  646. this.applyToPointStringified = applyToPointStringified;
  647. this.toCSS = toCSS;
  648. this.to2dCSS = to2dCSS;
  649. this.clone = clone;
  650. this.cloneFromProps = cloneFromProps;
  651. this.equals = equals;
  652. this.inversePoints = inversePoints;
  653. this.inversePoint = inversePoint;
  654. this._t = this.transform;
  655. this.isIdentity = isIdentity;
  656. this._identity = true;
  657. this._identityCalculated = false;
  658. this.props = createTypedArray('float32', 16);
  659. this.reset();
  660. };
  661. }());
  662. (function (pool, math) {
  663. //
  664. // The following constants are related to IEEE 754 limits.
  665. //
  666. var global = this,
  667. width = 256, // each RC4 output is 0 <= x < 256
  668. chunks = 6, // at least six RC4 outputs for each double
  669. digits = 52, // there are 52 significant digits in a double
  670. rngname = 'random', // rngname: name for Math.random and Math.seedrandom
  671. startdenom = math.pow(width, chunks),
  672. significance = math.pow(2, digits),
  673. overflow = significance * 2,
  674. mask = width - 1,
  675. nodecrypto; // node.js crypto module, initialized at the bottom.
  676. //
  677. // seedrandom()
  678. // This is the seedrandom function described above.
  679. //
  680. function seedrandom(seed, options, callback) {
  681. var key = [];
  682. options = (options === true) ? { entropy: true } : (options || {});
  683. // Flatten the seed string or build one from local entropy if needed.
  684. var shortseed = mixkey(flatten(
  685. options.entropy ? [seed, tostring(pool)] :
  686. (seed === null) ? autoseed() : seed, 3), key);
  687. // Use the seed to initialize an ARC4 generator.
  688. var arc4 = new ARC4(key);
  689. // This function returns a random double in [0, 1) that contains
  690. // randomness in every bit of the mantissa of the IEEE 754 value.
  691. var prng = function() {
  692. var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
  693. d = startdenom, // and denominator d = 2 ^ 48.
  694. x = 0; // and no 'extra last byte'.
  695. while (n < significance) { // Fill up all significant digits by
  696. n = (n + x) * width; // shifting numerator and
  697. d *= width; // denominator and generating a
  698. x = arc4.g(1); // new least-significant-byte.
  699. }
  700. while (n >= overflow) { // To avoid rounding up, before adding
  701. n /= 2; // last byte, shift everything
  702. d /= 2; // right using integer math until
  703. x >>>= 1; // we have exactly the desired bits.
  704. }
  705. return (n + x) / d; // Form the number within [0, 1).
  706. };
  707. prng.int32 = function() { return arc4.g(4) | 0; };
  708. prng.quick = function() { return arc4.g(4) / 0x100000000; };
  709. prng.double = prng;
  710. // Mix the randomness into accumulated entropy.
  711. mixkey(tostring(arc4.S), pool);
  712. // Calling convention: what to return as a function of prng, seed, is_math.
  713. return (options.pass || callback ||
  714. function(prng, seed, is_math_call, state) {
  715. if (state) {
  716. // Load the arc4 state from the given state if it has an S array.
  717. if (state.S) { copy(state, arc4); }
  718. // Only provide the .state method if requested via options.state.
  719. prng.state = function() { return copy(arc4, {}); };
  720. }
  721. // If called as a method of Math (Math.seedrandom()), mutate
  722. // Math.random because that is how seedrandom.js has worked since v1.0.
  723. if (is_math_call) { math[rngname] = prng; return seed; }
  724. // Otherwise, it is a newer calling convention, so return the
  725. // prng directly.
  726. else return prng;
  727. })(
  728. prng,
  729. shortseed,
  730. 'global' in options ? options.global : (this == math),
  731. options.state);
  732. }
  733. math['seed' + rngname] = seedrandom;
  734. //
  735. // ARC4
  736. //
  737. // An ARC4 implementation. The constructor takes a key in the form of
  738. // an array of at most (width) integers that should be 0 <= x < (width).
  739. //
  740. // The g(count) method returns a pseudorandom integer that concatenates
  741. // the next (count) outputs from ARC4. Its return value is a number x
  742. // that is in the range 0 <= x < (width ^ count).
  743. //
  744. function ARC4(key) {
  745. var t, keylen = key.length,
  746. me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
  747. // The empty key [] is treated as [0].
  748. if (!keylen) { key = [keylen++]; }
  749. // Set up S using the standard key scheduling algorithm.
  750. while (i < width) {
  751. s[i] = i++;
  752. }
  753. for (i = 0; i < width; i++) {
  754. s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
  755. s[j] = t;
  756. }
  757. // The "g" method returns the next (count) outputs as one number.
  758. me.g = function(count) {
  759. // Using instance members instead of closure state nearly doubles speed.
  760. var t, r = 0,
  761. i = me.i, j = me.j, s = me.S;
  762. while (count--) {
  763. t = s[i = mask & (i + 1)];
  764. r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
  765. }
  766. me.i = i; me.j = j;
  767. return r;
  768. // For robust unpredictability, the function call below automatically
  769. // discards an initial batch of values. This is called RC4-drop[256].
  770. // See http://google.com/search?q=rsa+fluhrer+response&btnI
  771. };
  772. }
  773. //
  774. // copy()
  775. // Copies internal state of ARC4 to or from a plain object.
  776. //
  777. function copy(f, t) {
  778. t.i = f.i;
  779. t.j = f.j;
  780. t.S = f.S.slice();
  781. return t;
  782. }
  783. //
  784. // flatten()
  785. // Converts an object tree to nested arrays of strings.
  786. //
  787. function flatten(obj, depth) {
  788. var result = [], typ = (typeof obj), prop;
  789. if (depth && typ == 'object') {
  790. for (prop in obj) {
  791. try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
  792. }
  793. }
  794. return (result.length ? result : typ == 'string' ? obj : obj + '\0');
  795. }
  796. //
  797. // mixkey()
  798. // Mixes a string seed into a key that is an array of integers, and
  799. // returns a shortened string seed that is equivalent to the result key.
  800. //
  801. function mixkey(seed, key) {
  802. var stringseed = seed + '', smear, j = 0;
  803. while (j < stringseed.length) {
  804. key[mask & j] =
  805. mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
  806. }
  807. return tostring(key);
  808. }
  809. //
  810. // autoseed()
  811. // Returns an object for autoseeding, using window.crypto and Node crypto
  812. // module if available.
  813. //
  814. function autoseed() {
  815. try {
  816. if (nodecrypto) { return tostring(nodecrypto.randomBytes(width)); }
  817. var out = new Uint8Array(width);
  818. (global.crypto || global.msCrypto).getRandomValues(out);
  819. return tostring(out);
  820. } catch (e) {
  821. var browser = global.navigator,
  822. plugins = browser && browser.plugins;
  823. return [+new Date(), global, plugins, global.screen, tostring(pool)];
  824. }
  825. }
  826. //
  827. // tostring()
  828. // Converts an array of charcodes to a string
  829. //
  830. function tostring(a) {
  831. return String.fromCharCode.apply(0, a);
  832. }
  833. //
  834. // When seedrandom.js is loaded, we immediately mix a few bits
  835. // from the built-in RNG into the entropy pool. Because we do
  836. // not want to interfere with deterministic PRNG state later,
  837. // seedrandom will not call math.random on its own again after
  838. // initialization.
  839. //
  840. mixkey(math.random(), pool);
  841. //
  842. // Nodejs and AMD support: export the implementation as a module using
  843. // either convention.
  844. //
  845. // End anonymous scope, and pass initial values.
  846. })(
  847. [], // pool: entropy pool starts empty
  848. BMMath // math: package containing random, pow, and seedrandom
  849. );
  850. var BezierFactory = (function(){
  851. var ob = {};
  852. ob.getBezierEasing = getBezierEasing;
  853. var beziers = {};
  854. function getBezierEasing(a,b,c,d,nm){
  855. var str = nm || ('bez_' + a+'_'+b+'_'+c+'_'+d).replace(/\./g, 'p');
  856. if(beziers[str]){
  857. return beziers[str];
  858. }
  859. var bezEasing = new BezierEasing([a,b,c,d]);
  860. beziers[str] = bezEasing;
  861. return bezEasing;
  862. }
  863. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  864. var NEWTON_ITERATIONS = 4;
  865. var NEWTON_MIN_SLOPE = 0.001;
  866. var SUBDIVISION_PRECISION = 0.0000001;
  867. var SUBDIVISION_MAX_ITERATIONS = 10;
  868. var kSplineTableSize = 11;
  869. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  870. var float32ArraySupported = typeof Float32Array === "function";
  871. function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
  872. function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
  873. function C (aA1) { return 3.0 * aA1; }
  874. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  875. function calcBezier (aT, aA1, aA2) {
  876. return ((A(aA1, aA2)*aT + B(aA1, aA2))*aT + C(aA1))*aT;
  877. }
  878. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  879. function getSlope (aT, aA1, aA2) {
  880. return 3.0 * A(aA1, aA2)*aT*aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  881. }
  882. function binarySubdivide (aX, aA, aB, mX1, mX2) {
  883. var currentX, currentT, i = 0;
  884. do {
  885. currentT = aA + (aB - aA) / 2.0;
  886. currentX = calcBezier(currentT, mX1, mX2) - aX;
  887. if (currentX > 0.0) {
  888. aB = currentT;
  889. } else {
  890. aA = currentT;
  891. }
  892. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  893. return currentT;
  894. }
  895. function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) {
  896. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  897. var currentSlope = getSlope(aGuessT, mX1, mX2);
  898. if (currentSlope === 0.0) return aGuessT;
  899. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  900. aGuessT -= currentX / currentSlope;
  901. }
  902. return aGuessT;
  903. }
  904. /**
  905. * points is an array of [ mX1, mY1, mX2, mY2 ]
  906. */
  907. function BezierEasing (points) {
  908. this._p = points;
  909. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  910. this._precomputed = false;
  911. this.get = this.get.bind(this);
  912. }
  913. BezierEasing.prototype = {
  914. get: function (x) {
  915. var mX1 = this._p[0],
  916. mY1 = this._p[1],
  917. mX2 = this._p[2],
  918. mY2 = this._p[3];
  919. if (!this._precomputed) this._precompute();
  920. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  921. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  922. if (x === 0) return 0;
  923. if (x === 1) return 1;
  924. return calcBezier(this._getTForX(x), mY1, mY2);
  925. },
  926. // Private part
  927. _precompute: function () {
  928. var mX1 = this._p[0],
  929. mY1 = this._p[1],
  930. mX2 = this._p[2],
  931. mY2 = this._p[3];
  932. this._precomputed = true;
  933. if (mX1 !== mY1 || mX2 !== mY2)
  934. this._calcSampleValues();
  935. },
  936. _calcSampleValues: function () {
  937. var mX1 = this._p[0],
  938. mX2 = this._p[2];
  939. for (var i = 0; i < kSplineTableSize; ++i) {
  940. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  941. }
  942. },
  943. /**
  944. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  945. */
  946. _getTForX: function (aX) {
  947. var mX1 = this._p[0],
  948. mX2 = this._p[2],
  949. mSampleValues = this._mSampleValues;
  950. var intervalStart = 0.0;
  951. var currentSample = 1;
  952. var lastSample = kSplineTableSize - 1;
  953. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  954. intervalStart += kSampleStepSize;
  955. }
  956. --currentSample;
  957. // Interpolate to provide an initial guess for t
  958. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample+1] - mSampleValues[currentSample]);
  959. var guessForT = intervalStart + dist * kSampleStepSize;
  960. var initialSlope = getSlope(guessForT, mX1, mX2);
  961. if (initialSlope >= NEWTON_MIN_SLOPE) {
  962. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  963. } else if (initialSlope === 0.0) {
  964. return guessForT;
  965. } else {
  966. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  967. }
  968. }
  969. };
  970. return ob;
  971. }());
  972. (function () {
  973. var lastTime = 0;
  974. var vendors = ['ms', 'moz', 'webkit', 'o'];
  975. for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
  976. window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
  977. window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
  978. }
  979. if(!window.requestAnimationFrame)
  980. window.requestAnimationFrame = function (callback, element) {
  981. var currTime = new Date().getTime();
  982. var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  983. var id = setTimeout(function () {
  984. callback(currTime + timeToCall);
  985. },
  986. timeToCall);
  987. lastTime = currTime + timeToCall;
  988. return id;
  989. };
  990. if(!window.cancelAnimationFrame)
  991. window.cancelAnimationFrame = function (id) {
  992. clearTimeout(id);
  993. };
  994. }());
  995. function extendPrototype(sources,destination){
  996. var i, len = sources.length, sourcePrototype;
  997. for (i = 0;i < len;i += 1) {
  998. sourcePrototype = sources[i].prototype;
  999. for (var attr in sourcePrototype) {
  1000. if (sourcePrototype.hasOwnProperty(attr)) destination.prototype[attr] = sourcePrototype[attr];
  1001. }
  1002. }
  1003. }
  1004. function getDescriptor(object, prop) {
  1005. return Object.getOwnPropertyDescriptor(object, prop);
  1006. }
  1007. function createProxyFunction(prototype) {
  1008. function ProxyFunction(){}
  1009. ProxyFunction.prototype = prototype;
  1010. return ProxyFunction;
  1011. }
  1012. function bezFunction(){
  1013. var easingFunctions = [];
  1014. var math = Math;
  1015. function pointOnLine2D(x1,y1, x2,y2, x3,y3){
  1016. var det1 = (x1*y2) + (y1*x3) + (x2*y3) - (x3*y2) - (y3*x1) - (x2*y1);
  1017. return det1 > -0.001 && det1 < 0.001;
  1018. }
  1019. function pointOnLine3D(x1,y1,z1, x2,y2,z2, x3,y3,z3){
  1020. if(z1 === 0 && z2 === 0 && z3 === 0) {
  1021. return pointOnLine2D(x1,y1, x2,y2, x3,y3);
  1022. }
  1023. var dist1 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) + Math.pow(z2 - z1, 2));
  1024. var dist2 = Math.sqrt(Math.pow(x3 - x1, 2) + Math.pow(y3 - y1, 2) + Math.pow(z3 - z1, 2));
  1025. var dist3 = Math.sqrt(Math.pow(x3 - x2, 2) + Math.pow(y3 - y2, 2) + Math.pow(z3 - z2, 2));
  1026. var diffDist;
  1027. if(dist1 > dist2){
  1028. if(dist1 > dist3){
  1029. diffDist = dist1 - dist2 - dist3;
  1030. } else {
  1031. diffDist = dist3 - dist2 - dist1;
  1032. }
  1033. } else if(dist3 > dist2){
  1034. diffDist = dist3 - dist2 - dist1;
  1035. } else {
  1036. diffDist = dist2 - dist1 - dist3;
  1037. }
  1038. return diffDist > -0.0001 && diffDist < 0.0001;
  1039. }
  1040. var getBezierLength = (function(){
  1041. return function(pt1,pt2,pt3,pt4){
  1042. var curveSegments = defaultCurveSegments;
  1043. var k;
  1044. var i, len;
  1045. var ptCoord,perc,addedLength = 0;
  1046. var ptDistance;
  1047. var point = [],lastPoint = [];
  1048. var lengthData = bezier_length_pool.newElement();
  1049. len = pt3.length;
  1050. for(k=0;k<curveSegments;k+=1){
  1051. perc = k/(curveSegments-1);
  1052. ptDistance = 0;
  1053. for(i=0;i<len;i+=1){
  1054. ptCoord = bm_pow(1-perc,3)*pt1[i]+3*bm_pow(1-perc,2)*perc*pt3[i]+3*(1-perc)*bm_pow(perc,2)*pt4[i]+bm_pow(perc,3)*pt2[i];
  1055. point[i] = ptCoord;
  1056. if(lastPoint[i] !== null){
  1057. ptDistance += bm_pow(point[i] - lastPoint[i],2);
  1058. }
  1059. lastPoint[i] = point[i];
  1060. }
  1061. if(ptDistance){
  1062. ptDistance = bm_sqrt(ptDistance);
  1063. addedLength += ptDistance;
  1064. }
  1065. lengthData.percents[k] = perc;
  1066. lengthData.lengths[k] = addedLength;
  1067. }
  1068. lengthData.addedLength = addedLength;
  1069. return lengthData;
  1070. };
  1071. }());
  1072. function getSegmentsLength(shapeData) {
  1073. var segmentsLength = segments_length_pool.newElement();
  1074. var closed = shapeData.c;
  1075. var pathV = shapeData.v;
  1076. var pathO = shapeData.o;
  1077. var pathI = shapeData.i;
  1078. var i, len = shapeData._length;
  1079. var lengths = segmentsLength.lengths;
  1080. var totalLength = 0;
  1081. for(i=0;i<len-1;i+=1){
  1082. lengths[i] = getBezierLength(pathV[i],pathV[i+1],pathO[i],pathI[i+1]);
  1083. totalLength += lengths[i].addedLength;
  1084. }
  1085. if(closed && len){
  1086. lengths[i] = getBezierLength(pathV[i],pathV[0],pathO[i],pathI[0]);
  1087. totalLength += lengths[i].addedLength;
  1088. }
  1089. segmentsLength.totalLength = totalLength;
  1090. return segmentsLength;
  1091. }
  1092. function BezierData(length){
  1093. this.segmentLength = 0;
  1094. this.points = new Array(length);
  1095. }
  1096. function PointData(partial,point){
  1097. this.partialLength = partial;
  1098. this.point = point;
  1099. }
  1100. var buildBezierData = (function(){
  1101. var storedData = {};
  1102. return function (pt1, pt2, pt3, pt4){
  1103. var bezierName = (pt1[0]+'_'+pt1[1]+'_'+pt2[0]+'_'+pt2[1]+'_'+pt3[0]+'_'+pt3[1]+'_'+pt4[0]+'_'+pt4[1]).replace(/\./g, 'p');
  1104. if(!storedData[bezierName]){
  1105. var curveSegments = defaultCurveSegments;
  1106. var k, i, len;
  1107. var ptCoord,perc,addedLength = 0;
  1108. var ptDistance;
  1109. var point,lastPoint = null;
  1110. 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])){
  1111. curveSegments = 2;
  1112. }
  1113. var bezierData = new BezierData(curveSegments);
  1114. len = pt3.length;
  1115. for (k = 0; k < curveSegments; k += 1) {
  1116. point = createSizedArray(len);
  1117. perc = k / (curveSegments - 1);
  1118. ptDistance = 0;
  1119. for (i = 0; i < len; i += 1){
  1120. ptCoord = bm_pow(1-perc,3)*pt1[i]+3*bm_pow(1-perc,2)*perc*(pt1[i] + pt3[i])+3*(1-perc)*bm_pow(perc,2)*(pt2[i] + pt4[i])+bm_pow(perc,3)*pt2[i];
  1121. point[i] = ptCoord;
  1122. if(lastPoint !== null){
  1123. ptDistance += bm_pow(point[i] - lastPoint[i],2);
  1124. }
  1125. }
  1126. ptDistance = bm_sqrt(ptDistance);
  1127. addedLength += ptDistance;
  1128. bezierData.points[k] = new PointData(ptDistance, point);
  1129. lastPoint = point;
  1130. }
  1131. bezierData.segmentLength = addedLength;
  1132. storedData[bezierName] = bezierData;
  1133. }
  1134. return storedData[bezierName];
  1135. };
  1136. }());
  1137. function getDistancePerc(perc,bezierData){
  1138. var percents = bezierData.percents;
  1139. var lengths = bezierData.lengths;
  1140. var len = percents.length;
  1141. var initPos = bm_floor((len-1)*perc);
  1142. var lengthPos = perc*bezierData.addedLength;
  1143. var lPerc = 0;
  1144. if(initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]){
  1145. return percents[initPos];
  1146. }else{
  1147. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  1148. var flag = true;
  1149. while(flag){
  1150. if(lengths[initPos] <= lengthPos && lengths[initPos+1] > lengthPos){
  1151. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos+1] - lengths[initPos]);
  1152. flag = false;
  1153. }else{
  1154. initPos += dir;
  1155. }
  1156. if(initPos < 0 || initPos >= len - 1){
  1157. //FIX for TypedArrays that don't store floating point values with enough accuracy
  1158. if(initPos === len - 1) {
  1159. return percents[initPos];
  1160. }
  1161. flag = false;
  1162. }
  1163. }
  1164. return percents[initPos] + (percents[initPos+1] - percents[initPos])*lPerc;
  1165. }
  1166. }
  1167. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  1168. var t1 = getDistancePerc(percent,bezierData);
  1169. var u0 = 1;
  1170. var u1 = 1 - t1;
  1171. 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;
  1172. 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;
  1173. return [ptX, ptY];
  1174. }
  1175. function getSegmentArray() {
  1176. }
  1177. var bezier_segment_points = createTypedArray('float32', 8);
  1178. function getNewSegment(pt1,pt2,pt3,pt4,startPerc,endPerc, bezierData){
  1179. startPerc = startPerc < 0 ? 0 : startPerc > 1 ? 1 : startPerc;
  1180. var t0 = getDistancePerc(startPerc,bezierData);
  1181. endPerc = endPerc > 1 ? 1 : endPerc;
  1182. var t1 = getDistancePerc(endPerc,bezierData);
  1183. var i, len = pt1.length;
  1184. var u0 = 1 - t0;
  1185. var u1 = 1 - t1;
  1186. var u0u0u0 = u0*u0*u0;
  1187. var t0u0u0_3 = t0*u0*u0*3;
  1188. var t0t0u0_3 = t0*t0*u0*3;
  1189. var t0t0t0 = t0*t0*t0;
  1190. //
  1191. var u0u0u1 = u0*u0*u1;
  1192. var t0u0u1_3 = t0*u0*u1 + u0*t0*u1 + u0*u0*t1;
  1193. var t0t0u1_3 = t0*t0*u1 + u0*t0*t1 + t0*u0*t1;
  1194. var t0t0t1 = t0*t0*t1;
  1195. //
  1196. var u0u1u1 = u0*u1*u1;
  1197. var t0u1u1_3 = t0*u1*u1 + u0*t1*u1 + u0*u1*t1;
  1198. var t0t1u1_3 = t0*t1*u1 + u0*t1*t1 + t0*u1*t1;
  1199. var t0t1t1 = t0*t1*t1;
  1200. //
  1201. var u1u1u1 = u1*u1*u1;
  1202. var t1u1u1_3 = t1*u1*u1 + u1*t1*u1 + u1*u1*t1;
  1203. var t1t1u1_3 = t1*t1*u1 + u1*t1*t1 + t1*u1*t1;
  1204. var t1t1t1 = t1*t1*t1;
  1205. for(i=0;i<len;i+=1){
  1206. bezier_segment_points[i * 4] = Math.round((u0u0u0 * pt1[i] + t0u0u0_3 * pt3[i] + t0t0u0_3 * pt4[i] + t0t0t0 * pt2[i]) * 1000) / 1000;
  1207. bezier_segment_points[i * 4 + 1] = Math.round((u0u0u1 * pt1[i] + t0u0u1_3 * pt3[i] + t0t0u1_3 * pt4[i] + t0t0t1 * pt2[i]) * 1000) / 1000;
  1208. bezier_segment_points[i * 4 + 2] = Math.round((u0u1u1 * pt1[i] + t0u1u1_3 * pt3[i] + t0t1u1_3 * pt4[i] + t0t1t1 * pt2[i]) * 1000) / 1000;
  1209. bezier_segment_points[i * 4 + 3] = Math.round((u1u1u1 * pt1[i] + t1u1u1_3 * pt3[i] + t1t1u1_3 * pt4[i] + t1t1t1 * pt2[i]) * 1000) / 1000;
  1210. }
  1211. return bezier_segment_points;
  1212. }
  1213. return {
  1214. getSegmentsLength : getSegmentsLength,
  1215. getNewSegment : getNewSegment,
  1216. getPointInSegment : getPointInSegment,
  1217. buildBezierData : buildBezierData,
  1218. pointOnLine2D : pointOnLine2D,
  1219. pointOnLine3D : pointOnLine3D
  1220. };
  1221. }
  1222. var bez = bezFunction();
  1223. function dataFunctionManager(){
  1224. //var tCanvasHelper = createTag('canvas').getContext('2d');
  1225. function completeLayers(layers, comps, fontManager){
  1226. var layerData;
  1227. var animArray, lastFrame;
  1228. var i, len = layers.length;
  1229. var j, jLen, k, kLen;
  1230. for(i=0;i<len;i+=1){
  1231. layerData = layers[i];
  1232. if(!('ks' in layerData) || layerData.completed){
  1233. continue;
  1234. }
  1235. layerData.completed = true;
  1236. if(layerData.tt){
  1237. layers[i-1].td = layerData.tt;
  1238. }
  1239. animArray = [];
  1240. lastFrame = -1;
  1241. if(layerData.hasMask){
  1242. var maskProps = layerData.masksProperties;
  1243. jLen = maskProps.length;
  1244. for(j=0;j<jLen;j+=1){
  1245. if(maskProps[j].pt.k.i){
  1246. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  1247. }else{
  1248. kLen = maskProps[j].pt.k.length;
  1249. for(k=0;k<kLen;k+=1){
  1250. if(maskProps[j].pt.k[k].s){
  1251. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  1252. }
  1253. if(maskProps[j].pt.k[k].e){
  1254. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. if(layerData.ty===0){
  1261. layerData.layers = findCompLayers(layerData.refId, comps);
  1262. completeLayers(layerData.layers,comps, fontManager);
  1263. }else if(layerData.ty === 4){
  1264. completeShapes(layerData.shapes);
  1265. }else if(layerData.ty == 5){
  1266. completeText(layerData, fontManager);
  1267. }
  1268. }
  1269. }
  1270. function findCompLayers(id,comps){
  1271. var i = 0, len = comps.length;
  1272. while(i<len){
  1273. if(comps[i].id === id){
  1274. if(!comps[i].layers.__used) {
  1275. comps[i].layers.__used = true;
  1276. return comps[i].layers;
  1277. }
  1278. return JSON.parse(JSON.stringify(comps[i].layers));
  1279. }
  1280. i += 1;
  1281. }
  1282. }
  1283. function completeShapes(arr){
  1284. var i, len = arr.length;
  1285. var j, jLen;
  1286. var hasPaths = false;
  1287. for(i=len-1;i>=0;i-=1){
  1288. if(arr[i].ty == 'sh'){
  1289. if(arr[i].ks.k.i){
  1290. convertPathsToAbsoluteValues(arr[i].ks.k);
  1291. }else{
  1292. jLen = arr[i].ks.k.length;
  1293. for(j=0;j<jLen;j+=1){
  1294. if(arr[i].ks.k[j].s){
  1295. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  1296. }
  1297. if(arr[i].ks.k[j].e){
  1298. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  1299. }
  1300. }
  1301. }
  1302. hasPaths = true;
  1303. }else if(arr[i].ty == 'gr'){
  1304. completeShapes(arr[i].it);
  1305. }
  1306. }
  1307. /*if(hasPaths){
  1308. //mx: distance
  1309. //ss: sensitivity
  1310. //dc: decay
  1311. arr.splice(arr.length-1,0,{
  1312. "ty": "ms",
  1313. "mx":20,
  1314. "ss":10,
  1315. "dc":0.001,
  1316. "maxDist":200
  1317. });
  1318. }*/
  1319. }
  1320. function convertPathsToAbsoluteValues(path){
  1321. var i, len = path.i.length;
  1322. for(i=0;i<len;i+=1){
  1323. path.i[i][0] += path.v[i][0];
  1324. path.i[i][1] += path.v[i][1];
  1325. path.o[i][0] += path.v[i][0];
  1326. path.o[i][1] += path.v[i][1];
  1327. }
  1328. }
  1329. function checkVersion(minimum,animVersionString){
  1330. var animVersion = animVersionString ? animVersionString.split('.') : [100,100,100];
  1331. if(minimum[0]>animVersion[0]){
  1332. return true;
  1333. } else if(animVersion[0] > minimum[0]){
  1334. return false;
  1335. }
  1336. if(minimum[1]>animVersion[1]){
  1337. return true;
  1338. } else if(animVersion[1] > minimum[1]){
  1339. return false;
  1340. }
  1341. if(minimum[2]>animVersion[2]){
  1342. return true;
  1343. } else if(animVersion[2] > minimum[2]){
  1344. return false;
  1345. }
  1346. }
  1347. var checkText = (function(){
  1348. var minimumVersion = [4,4,14];
  1349. function updateTextLayer(textLayer){
  1350. var documentData = textLayer.t.d;
  1351. textLayer.t.d = {
  1352. k: [
  1353. {
  1354. s:documentData,
  1355. t:0
  1356. }
  1357. ]
  1358. };
  1359. }
  1360. function iterateLayers(layers){
  1361. var i, len = layers.length;
  1362. for(i=0;i<len;i+=1){
  1363. if(layers[i].ty === 5){
  1364. updateTextLayer(layers[i]);
  1365. }
  1366. }
  1367. }
  1368. return function (animationData){
  1369. if(checkVersion(minimumVersion,animationData.v)){
  1370. iterateLayers(animationData.layers);
  1371. if(animationData.assets){
  1372. var i, len = animationData.assets.length;
  1373. for(i=0;i<len;i+=1){
  1374. if(animationData.assets[i].layers){
  1375. iterateLayers(animationData.assets[i].layers);
  1376. }
  1377. }
  1378. }
  1379. }
  1380. };
  1381. }());
  1382. var checkChars = (function() {
  1383. var minimumVersion = [4,7,99];
  1384. return function (animationData){
  1385. if(animationData.chars && !checkVersion(minimumVersion,animationData.v)){
  1386. var i, len = animationData.chars.length, j, jLen, k, kLen;
  1387. var pathData, paths;
  1388. for(i = 0; i < len; i += 1) {
  1389. if(animationData.chars[i].data && animationData.chars[i].data.shapes) {
  1390. paths = animationData.chars[i].data.shapes[0].it;
  1391. jLen = paths.length;
  1392. for(j = 0; j < jLen; j += 1) {
  1393. pathData = paths[j].ks.k;
  1394. if(!pathData.__converted) {
  1395. convertPathsToAbsoluteValues(paths[j].ks.k);
  1396. pathData.__converted = true;
  1397. }
  1398. }
  1399. }
  1400. }
  1401. }
  1402. };
  1403. }());
  1404. var checkColors = (function(){
  1405. var minimumVersion = [4,1,9];
  1406. function iterateShapes(shapes){
  1407. var i, len = shapes.length;
  1408. var j, jLen;
  1409. for(i=0;i<len;i+=1){
  1410. if(shapes[i].ty === 'gr'){
  1411. iterateShapes(shapes[i].it);
  1412. }else if(shapes[i].ty === 'fl' || shapes[i].ty === 'st'){
  1413. if(shapes[i].c.k && shapes[i].c.k[0].i){
  1414. jLen = shapes[i].c.k.length;
  1415. for(j=0;j<jLen;j+=1){
  1416. if(shapes[i].c.k[j].s){
  1417. shapes[i].c.k[j].s[0] /= 255;
  1418. shapes[i].c.k[j].s[1] /= 255;
  1419. shapes[i].c.k[j].s[2] /= 255;
  1420. shapes[i].c.k[j].s[3] /= 255;
  1421. }
  1422. if(shapes[i].c.k[j].e){
  1423. shapes[i].c.k[j].e[0] /= 255;
  1424. shapes[i].c.k[j].e[1] /= 255;
  1425. shapes[i].c.k[j].e[2] /= 255;
  1426. shapes[i].c.k[j].e[3] /= 255;
  1427. }
  1428. }
  1429. } else {
  1430. shapes[i].c.k[0] /= 255;
  1431. shapes[i].c.k[1] /= 255;
  1432. shapes[i].c.k[2] /= 255;
  1433. shapes[i].c.k[3] /= 255;
  1434. }
  1435. }
  1436. }
  1437. }
  1438. function iterateLayers(layers){
  1439. var i, len = layers.length;
  1440. for(i=0;i<len;i+=1){
  1441. if(layers[i].ty === 4){
  1442. iterateShapes(layers[i].shapes);
  1443. }
  1444. }
  1445. }
  1446. return function (animationData){
  1447. if(checkVersion(minimumVersion,animationData.v)){
  1448. iterateLayers(animationData.layers);
  1449. if(animationData.assets){
  1450. var i, len = animationData.assets.length;
  1451. for(i=0;i<len;i+=1){
  1452. if(animationData.assets[i].layers){
  1453. iterateLayers(animationData.assets[i].layers);
  1454. }
  1455. }
  1456. }
  1457. }
  1458. };
  1459. }());
  1460. var checkShapes = (function(){
  1461. var minimumVersion = [4,4,18];
  1462. function completeShapes(arr){
  1463. var i, len = arr.length;
  1464. var j, jLen;
  1465. var hasPaths = false;
  1466. for(i=len-1;i>=0;i-=1){
  1467. if(arr[i].ty == 'sh'){
  1468. if(arr[i].ks.k.i){
  1469. arr[i].ks.k.c = arr[i].closed;
  1470. }else{
  1471. jLen = arr[i].ks.k.length;
  1472. for(j=0;j<jLen;j+=1){
  1473. if(arr[i].ks.k[j].s){
  1474. arr[i].ks.k[j].s[0].c = arr[i].closed;
  1475. }
  1476. if(arr[i].ks.k[j].e){
  1477. arr[i].ks.k[j].e[0].c = arr[i].closed;
  1478. }
  1479. }
  1480. }
  1481. hasPaths = true;
  1482. }else if(arr[i].ty == 'gr'){
  1483. completeShapes(arr[i].it);
  1484. }
  1485. }
  1486. }
  1487. function iterateLayers(layers){
  1488. var layerData;
  1489. var i, len = layers.length;
  1490. var j, jLen, k, kLen;
  1491. for(i=0;i<len;i+=1){
  1492. layerData = layers[i];
  1493. if(layerData.hasMask){
  1494. var maskProps = layerData.masksProperties;
  1495. jLen = maskProps.length;
  1496. for(j=0;j<jLen;j+=1){
  1497. if(maskProps[j].pt.k.i){
  1498. maskProps[j].pt.k.c = maskProps[j].cl;
  1499. }else{
  1500. kLen = maskProps[j].pt.k.length;
  1501. for(k=0;k<kLen;k+=1){
  1502. if(maskProps[j].pt.k[k].s){
  1503. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  1504. }
  1505. if(maskProps[j].pt.k[k].e){
  1506. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  1507. }
  1508. }
  1509. }
  1510. }
  1511. }
  1512. if(layerData.ty === 4){
  1513. completeShapes(layerData.shapes);
  1514. }
  1515. }
  1516. }
  1517. return function (animationData){
  1518. if(checkVersion(minimumVersion,animationData.v)){
  1519. iterateLayers(animationData.layers);
  1520. if(animationData.assets){
  1521. var i, len = animationData.assets.length;
  1522. for(i=0;i<len;i+=1){
  1523. if(animationData.assets[i].layers){
  1524. iterateLayers(animationData.assets[i].layers);
  1525. }
  1526. }
  1527. }
  1528. }
  1529. };
  1530. }());
  1531. function completeData(animationData, fontManager){
  1532. if(animationData.__complete){
  1533. return;
  1534. }
  1535. checkColors(animationData);
  1536. checkText(animationData);
  1537. checkChars(animationData);
  1538. checkShapes(animationData);
  1539. completeLayers(animationData.layers, animationData.assets, fontManager);
  1540. animationData.__complete = true;
  1541. //blitAnimation(animationData, animationData.assets, fontManager);
  1542. }
  1543. function completeText(data, fontManager){
  1544. if(data.t.a.length === 0 && !('m' in data.t.p)){
  1545. data.singleShape = true;
  1546. }
  1547. }
  1548. var moduleOb = {};
  1549. moduleOb.completeData = completeData;
  1550. moduleOb.checkColors = checkColors;
  1551. moduleOb.checkChars = checkChars;
  1552. moduleOb.checkShapes = checkShapes;
  1553. moduleOb.completeLayers = completeLayers;
  1554. return moduleOb;
  1555. }
  1556. var dataManager = dataFunctionManager();
  1557. dataManager.completeData = function(animationData, fontManager) {
  1558. if(animationData.__complete){
  1559. return;
  1560. }
  1561. this.checkColors(animationData);
  1562. this.checkChars(animationData);
  1563. this.checkShapes(animationData);
  1564. this.completeLayers(animationData.layers, animationData.assets, fontManager);
  1565. animationData.__complete = true;
  1566. }
  1567. var FontManager = (function(){
  1568. var maxWaitingTime = 5000;
  1569. var emptyChar = {
  1570. w: 0,
  1571. size:0,
  1572. shapes:[]
  1573. };
  1574. var combinedCharacters = [];
  1575. //Hindi characters
  1576. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366
  1577. , 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379
  1578. , 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  1579. function setUpNode(font, family){
  1580. var parentNode = createTag('span');
  1581. parentNode.style.fontFamily = family;
  1582. var node = createTag('span');
  1583. // Characters that vary significantly among different fonts
  1584. node.innerHTML = 'giItT1WQy@!-/#';
  1585. // Visible - so we can measure it - but not on the screen
  1586. parentNode.style.position = 'absolute';
  1587. parentNode.style.left = '-10000px';
  1588. parentNode.style.top = '-10000px';
  1589. // Large font size makes even subtle changes obvious
  1590. parentNode.style.fontSize = '300px';
  1591. // Reset any font properties
  1592. parentNode.style.fontVariant = 'normal';
  1593. parentNode.style.fontStyle = 'normal';
  1594. parentNode.style.fontWeight = 'normal';
  1595. parentNode.style.letterSpacing = '0';
  1596. parentNode.appendChild(node);
  1597. document.body.appendChild(parentNode);
  1598. // Remember width with no applied web font
  1599. var width = node.offsetWidth;
  1600. node.style.fontFamily = font + ', '+family;
  1601. return {node:node, w:width, parent:parentNode};
  1602. }
  1603. function checkLoadedFonts() {
  1604. var i, len = this.fonts.length;
  1605. var node, w;
  1606. var loadedCount = len;
  1607. for(i=0;i<len; i+= 1){
  1608. if(this.fonts[i].loaded){
  1609. loadedCount -= 1;
  1610. continue;
  1611. }
  1612. if(this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0){
  1613. this.fonts[i].loaded = true;
  1614. } else{
  1615. node = this.fonts[i].monoCase.node;
  1616. w = this.fonts[i].monoCase.w;
  1617. if(node.offsetWidth !== w){
  1618. loadedCount -= 1;
  1619. this.fonts[i].loaded = true;
  1620. }else{
  1621. node = this.fonts[i].sansCase.node;
  1622. w = this.fonts[i].sansCase.w;
  1623. if(node.offsetWidth !== w){
  1624. loadedCount -= 1;
  1625. this.fonts[i].loaded = true;
  1626. }
  1627. }
  1628. if(this.fonts[i].loaded){
  1629. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  1630. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  1631. }
  1632. }
  1633. }
  1634. if(loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime){
  1635. setTimeout(this.checkLoadedFonts.bind(this),20);
  1636. }else{
  1637. setTimeout(function(){this.isLoaded = true;}.bind(this),0);
  1638. }
  1639. }
  1640. function createHelper(def, fontData){
  1641. var tHelper = createNS('text');
  1642. tHelper.style.fontSize = '100px';
  1643. //tHelper.style.fontFamily = fontData.fFamily;
  1644. tHelper.setAttribute('font-family', fontData.fFamily);
  1645. tHelper.setAttribute('font-style', fontData.fStyle);
  1646. tHelper.setAttribute('font-weight', fontData.fWeight);
  1647. tHelper.textContent = '1';
  1648. if(fontData.fClass){
  1649. tHelper.style.fontFamily = 'inherit';
  1650. tHelper.setAttribute('class', fontData.fClass);
  1651. } else {
  1652. tHelper.style.fontFamily = fontData.fFamily;
  1653. }
  1654. def.appendChild(tHelper);
  1655. var tCanvasHelper = createTag('canvas').getContext('2d');
  1656. tCanvasHelper.font = fontData.fWeight + ' ' + fontData.fStyle + ' 100px '+ fontData.fFamily;
  1657. //tCanvasHelper.font = ' 100px '+ fontData.fFamily;
  1658. return tHelper;
  1659. }
  1660. function addFonts(fontData, defs){
  1661. if(!fontData){
  1662. this.isLoaded = true;
  1663. return;
  1664. }
  1665. if(this.chars){
  1666. this.isLoaded = true;
  1667. this.fonts = fontData.list;
  1668. return;
  1669. }
  1670. var fontArr = fontData.list;
  1671. var i, len = fontArr.length;
  1672. var _pendingFonts = len;
  1673. for(i=0; i<len; i+= 1){
  1674. var shouldLoadFont = true;
  1675. var loadedSelector;
  1676. var j;
  1677. fontArr[i].loaded = false;
  1678. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily,'monospace');
  1679. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily,'sans-serif');
  1680. if(!fontArr[i].fPath) {
  1681. fontArr[i].loaded = true;
  1682. _pendingFonts -= 1;
  1683. }else if(fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3){
  1684. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="'+ fontArr[i].fFamily +'"], style[f-origin="3"][f-family="'+ fontArr[i].fFamily +'"]');
  1685. if (loadedSelector.length > 0) {
  1686. shouldLoadFont = false;
  1687. }
  1688. if (shouldLoadFont) {
  1689. var s = createTag('style');
  1690. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  1691. s.setAttribute('f-origin', fontArr[i].origin);
  1692. s.setAttribute('f-family', fontArr[i].fFamily);
  1693. s.type = "text/css";
  1694. s.innerHTML = "@font-face {" + "font-family: "+fontArr[i].fFamily+"; font-style: normal; src: url('"+fontArr[i].fPath+"');}";
  1695. defs.appendChild(s);
  1696. }
  1697. } else if(fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1){
  1698. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  1699. for (j = 0; j < loadedSelector.length; j++) {
  1700. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  1701. // Font is already loaded
  1702. shouldLoadFont = false;
  1703. }
  1704. }
  1705. if (shouldLoadFont) {
  1706. var l = createTag('link');
  1707. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  1708. l.setAttribute('f-origin', fontArr[i].origin);
  1709. l.type = "text/css";
  1710. l.rel = "stylesheet";
  1711. l.href = fontArr[i].fPath;
  1712. document.body.appendChild(l);
  1713. }
  1714. } else if(fontArr[i].fOrigin === 't' || fontArr[i].origin === 2){
  1715. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  1716. for (j = 0; j < loadedSelector.length; j++) {
  1717. if (fontArr[i].fPath === loadedSelector[j].src) {
  1718. // Font is already loaded
  1719. shouldLoadFont = false;
  1720. }
  1721. }
  1722. if (shouldLoadFont) {
  1723. var sc = createTag('link');
  1724. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  1725. sc.setAttribute('f-origin', fontArr[i].origin);
  1726. sc.setAttribute('rel','stylesheet');
  1727. sc.setAttribute('href',fontArr[i].fPath);
  1728. defs.appendChild(sc);
  1729. }
  1730. }
  1731. fontArr[i].helper = createHelper(defs,fontArr[i]);
  1732. fontArr[i].cache = {};
  1733. this.fonts.push(fontArr[i]);
  1734. }
  1735. if (_pendingFonts === 0) {
  1736. this.isLoaded = true;
  1737. } else {
  1738. //On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  1739. //Adding this timeout seems to fix it
  1740. setTimeout(this.checkLoadedFonts.bind(this), 100);
  1741. }
  1742. }
  1743. function addChars(chars){
  1744. if(!chars){
  1745. return;
  1746. }
  1747. if(!this.chars){
  1748. this.chars = [];
  1749. }
  1750. var i, len = chars.length;
  1751. var j, jLen = this.chars.length, found;
  1752. for(i=0;i<len;i+=1){
  1753. j = 0;
  1754. found = false;
  1755. while(j<jLen){
  1756. if(this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch){
  1757. found = true;
  1758. }
  1759. j += 1;
  1760. }
  1761. if(!found){
  1762. this.chars.push(chars[i]);
  1763. jLen += 1;
  1764. }
  1765. }
  1766. }
  1767. function getCharData(char, style, font){
  1768. var i = 0, len = this.chars.length;
  1769. while( i < len) {
  1770. if(this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font){
  1771. return this.chars[i];
  1772. }
  1773. i+= 1;
  1774. }
  1775. if(console && console.warn) {
  1776. console.warn('Missing character from exported characters list: ', char, style, font);
  1777. }
  1778. return emptyChar;
  1779. }
  1780. function measureText(char, fontName, size) {
  1781. var fontData = this.getFontByName(fontName);
  1782. var index = char.charCodeAt(0);
  1783. if(!fontData.cache[index + 1]) {
  1784. var tHelper = fontData.helper;
  1785. //Canvas version
  1786. //fontData.cache[index] = tHelper.measureText(char).width / 100;
  1787. //SVG version
  1788. //console.log(tHelper.getBBox().width)
  1789. if (char === ' ') {
  1790. tHelper.textContent = '|' + char + '|';
  1791. var doubleSize = tHelper.getComputedTextLength();
  1792. tHelper.textContent = '||';
  1793. var singleSize = tHelper.getComputedTextLength();
  1794. fontData.cache[index + 1] = (doubleSize - singleSize)/100;
  1795. } else {
  1796. tHelper.textContent = char;
  1797. fontData.cache[index + 1] = (tHelper.getComputedTextLength())/100;
  1798. }
  1799. }
  1800. return fontData.cache[index + 1] * size;
  1801. }
  1802. function getFontByName(name){
  1803. var i = 0, len = this.fonts.length;
  1804. while(i<len){
  1805. if(this.fonts[i].fName === name) {
  1806. return this.fonts[i];
  1807. }
  1808. i += 1;
  1809. }
  1810. return this.fonts[0];
  1811. }
  1812. function getCombinedCharacterCodes() {
  1813. return combinedCharacters;
  1814. }
  1815. function loaded() {
  1816. return this.isLoaded;
  1817. }
  1818. var Font = function(){
  1819. this.fonts = [];
  1820. this.chars = null;
  1821. this.typekitLoaded = 0;
  1822. this.isLoaded = false;
  1823. this.initTime = Date.now();
  1824. };
  1825. //TODO: for now I'm adding these methods to the Class and not the prototype. Think of a better way to implement it.
  1826. Font.getCombinedCharacterCodes = getCombinedCharacterCodes;
  1827. Font.prototype.addChars = addChars;
  1828. Font.prototype.addFonts = addFonts;
  1829. Font.prototype.getCharData = getCharData;
  1830. Font.prototype.getFontByName = getFontByName;
  1831. Font.prototype.measureText = measureText;
  1832. Font.prototype.checkLoadedFonts = checkLoadedFonts;
  1833. Font.prototype.loaded = loaded;
  1834. return Font;
  1835. }());
  1836. FontManager = (function(){
  1837. var Font = function(){
  1838. this.fonts = [];
  1839. this.chars = null;
  1840. this.typekitLoaded = 0;
  1841. this.isLoaded = false;
  1842. this.initTime = Date.now();
  1843. };
  1844. return Font;
  1845. }());
  1846. var PropertyFactory = (function(){
  1847. var initFrame = initialDefaultFrame;
  1848. var math_abs = Math.abs;
  1849. function interpolateValue(frameNum, caching) {
  1850. var offsetTime = this.offsetTime;
  1851. var newValue;
  1852. if (this.propType === 'multidimensional') {
  1853. newValue = createTypedArray('float32', this.pv.length);
  1854. }
  1855. var iterationIndex = caching.lastIndex;
  1856. var i = iterationIndex;
  1857. var len = this.keyframes.length - 1, flag = true;
  1858. var keyData, nextKeyData;
  1859. while (flag) {
  1860. keyData = this.keyframes[i];
  1861. nextKeyData = this.keyframes[i + 1];
  1862. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime){
  1863. if(keyData.h){
  1864. keyData = nextKeyData;
  1865. }
  1866. iterationIndex = 0;
  1867. break;
  1868. }
  1869. if ((nextKeyData.t - offsetTime) > frameNum){
  1870. iterationIndex = i;
  1871. break;
  1872. }
  1873. if (i < len - 1){
  1874. i += 1;
  1875. } else {
  1876. iterationIndex = 0;
  1877. flag = false;
  1878. }
  1879. }
  1880. var k, kLen, perc, jLen, j, fnc;
  1881. var nextKeyTime = nextKeyData.t - offsetTime;
  1882. var keyTime = keyData.t - offsetTime;
  1883. var endValue;
  1884. if (keyData.to) {
  1885. if (!keyData.bezierData) {
  1886. keyData.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  1887. }
  1888. var bezierData = keyData.bezierData;
  1889. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  1890. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  1891. kLen = bezierData.points[ind].point.length;
  1892. for (k = 0; k < kLen; k += 1) {
  1893. newValue[k] = bezierData.points[ind].point[k];
  1894. }
  1895. // caching._lastKeyframeIndex = -1;
  1896. } else {
  1897. if (keyData.__fnct) {
  1898. fnc = keyData.__fnct;
  1899. } else {
  1900. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  1901. keyData.__fnct = fnc;
  1902. }
  1903. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  1904. var distanceInLine = bezierData.segmentLength*perc;
  1905. var segmentPerc;
  1906. var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0;
  1907. j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0;
  1908. flag = true;
  1909. jLen = bezierData.points.length;
  1910. while (flag) {
  1911. addedLength += bezierData.points[j].partialLength;
  1912. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  1913. kLen = bezierData.points[j].point.length;
  1914. for (k = 0; k < kLen; k += 1) {
  1915. newValue[k] = bezierData.points[j].point[k];
  1916. }
  1917. break;
  1918. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  1919. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  1920. kLen = bezierData.points[j].point.length;
  1921. for (k = 0; k < kLen; k += 1) {
  1922. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  1923. }
  1924. break;
  1925. }
  1926. if (j < jLen - 1){
  1927. j += 1;
  1928. } else {
  1929. flag = false;
  1930. }
  1931. }
  1932. caching._lastPoint = j;
  1933. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  1934. caching._lastKeyframeIndex = i;
  1935. }
  1936. } else {
  1937. var outX, outY, inX, inY, keyValue;
  1938. len = keyData.s.length;
  1939. endValue = nextKeyData.s || keyData.e;
  1940. if (this.sh && keyData.h !== 1) {
  1941. if (frameNum >= nextKeyTime) {
  1942. newValue[0] = endValue[0];
  1943. newValue[1] = endValue[1];
  1944. newValue[2] = endValue[2];
  1945. } else if (frameNum <= keyTime) {
  1946. newValue[0] = keyData.s[0];
  1947. newValue[1] = keyData.s[1];
  1948. newValue[2] = keyData.s[2];
  1949. } else {
  1950. var quatStart = createQuaternion(keyData.s);
  1951. var quatEnd = createQuaternion(endValue);
  1952. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  1953. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  1954. }
  1955. } else {
  1956. for(i = 0; i < len; i += 1) {
  1957. if (keyData.h !== 1) {
  1958. if (frameNum >= nextKeyTime) {
  1959. perc = 1;
  1960. } else if(frameNum < keyTime) {
  1961. perc = 0;
  1962. } else {
  1963. if(keyData.o.x.constructor === Array) {
  1964. if (!keyData.__fnct) {
  1965. keyData.__fnct = [];
  1966. }
  1967. if (!keyData.__fnct[i]) {
  1968. outX = (typeof keyData.o.x[i] === 'undefined') ? keyData.o.x[0] : keyData.o.x[i];
  1969. outY = (typeof keyData.o.y[i] === 'undefined') ? keyData.o.y[0] : keyData.o.y[i];
  1970. inX = (typeof keyData.i.x[i] === 'undefined') ? keyData.i.x[0] : keyData.i.x[i];
  1971. inY = (typeof keyData.i.y[i] === 'undefined') ? keyData.i.y[0] : keyData.i.y[i];
  1972. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  1973. keyData.__fnct[i] = fnc;
  1974. } else {
  1975. fnc = keyData.__fnct[i];
  1976. }
  1977. } else {
  1978. if (!keyData.__fnct) {
  1979. outX = keyData.o.x;
  1980. outY = keyData.o.y;
  1981. inX = keyData.i.x;
  1982. inY = keyData.i.y;
  1983. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  1984. keyData.__fnct = fnc;
  1985. } else {
  1986. fnc = keyData.__fnct;
  1987. }
  1988. }
  1989. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime ));
  1990. }
  1991. }
  1992. endValue = nextKeyData.s || keyData.e;
  1993. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  1994. if (len === 1) {
  1995. newValue = keyValue;
  1996. } else {
  1997. newValue[i] = keyValue;
  1998. }
  1999. }
  2000. }
  2001. }
  2002. caching.lastIndex = iterationIndex;
  2003. return newValue;
  2004. }
  2005. //based on @Toji's https://github.com/toji/gl-matrix/
  2006. function slerp(a, b, t) {
  2007. var out = [];
  2008. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  2009. bx = b[0], by = b[1], bz = b[2], bw = b[3]
  2010. var omega, cosom, sinom, scale0, scale1;
  2011. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2012. if (cosom < 0.0) {
  2013. cosom = -cosom;
  2014. bx = -bx;
  2015. by = -by;
  2016. bz = -bz;
  2017. bw = -bw;
  2018. }
  2019. if ((1.0 - cosom) > 0.000001) {
  2020. omega = Math.acos(cosom);
  2021. sinom = Math.sin(omega);
  2022. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2023. scale1 = Math.sin(t * omega) / sinom;
  2024. } else {
  2025. scale0 = 1.0 - t;
  2026. scale1 = t;
  2027. }
  2028. out[0] = scale0 * ax + scale1 * bx;
  2029. out[1] = scale0 * ay + scale1 * by;
  2030. out[2] = scale0 * az + scale1 * bz;
  2031. out[3] = scale0 * aw + scale1 * bw;
  2032. return out;
  2033. }
  2034. function quaternionToEuler(out, quat) {
  2035. var qx = quat[0];
  2036. var qy = quat[1];
  2037. var qz = quat[2];
  2038. var qw = quat[3];
  2039. var heading = Math.atan2(2*qy*qw-2*qx*qz , 1 - 2*qy*qy - 2*qz*qz)
  2040. var attitude = Math.asin(2*qx*qy + 2*qz*qw)
  2041. var bank = Math.atan2(2*qx*qw-2*qy*qz , 1 - 2*qx*qx - 2*qz*qz);
  2042. out[0] = heading/degToRads;
  2043. out[1] = attitude/degToRads;
  2044. out[2] = bank/degToRads;
  2045. }
  2046. function createQuaternion(values) {
  2047. var heading = values[0] * degToRads;
  2048. var attitude = values[1] * degToRads;
  2049. var bank = values[2] * degToRads;
  2050. var c1 = Math.cos(heading / 2);
  2051. var c2 = Math.cos(attitude / 2);
  2052. var c3 = Math.cos(bank / 2);
  2053. var s1 = Math.sin(heading / 2);
  2054. var s2 = Math.sin(attitude / 2);
  2055. var s3 = Math.sin(bank / 2);
  2056. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2057. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2058. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2059. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2060. return [x,y,z,w];
  2061. }
  2062. function getValueAtCurrentTime(){
  2063. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2064. var initTime = this.keyframes[0].t - this.offsetTime;
  2065. var endTime = this.keyframes[this.keyframes.length- 1].t-this.offsetTime;
  2066. if(!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))){
  2067. if(this._caching.lastFrame >= frameNum) {
  2068. this._caching._lastKeyframeIndex = -1;
  2069. this._caching.lastIndex = 0;
  2070. }
  2071. var renderResult = this.interpolateValue(frameNum, this._caching);
  2072. this.pv = renderResult;
  2073. }
  2074. this._caching.lastFrame = frameNum;
  2075. return this.pv;
  2076. }
  2077. function setVValue(val) {
  2078. var multipliedValue;
  2079. if(this.propType === 'unidimensional') {
  2080. multipliedValue = val * this.mult;
  2081. if(math_abs(this.v - multipliedValue) > 0.00001) {
  2082. this.v = multipliedValue;
  2083. this._mdf = true;
  2084. }
  2085. } else {
  2086. var i = 0, len = this.v.length;
  2087. while (i < len) {
  2088. multipliedValue = val[i] * this.mult;
  2089. if (math_abs(this.v[i] - multipliedValue) > 0.00001) {
  2090. this.v[i] = multipliedValue;
  2091. this._mdf = true;
  2092. }
  2093. i += 1;
  2094. }
  2095. }
  2096. }
  2097. function processEffectsSequence() {
  2098. if(this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  2099. return;
  2100. }
  2101. if(this.lock) {
  2102. this.setVValue(this.pv);
  2103. return;
  2104. }
  2105. this.lock = true;
  2106. this._mdf = this._isFirstFrame;
  2107. var multipliedValue;
  2108. var i, len = this.effectsSequence.length;
  2109. var finalValue = this.kf ? this.pv : this.data.k;
  2110. for(i = 0; i < len; i += 1) {
  2111. finalValue = this.effectsSequence[i](finalValue);
  2112. }
  2113. this.setVValue(finalValue);
  2114. this._isFirstFrame = false;
  2115. this.lock = false;
  2116. this.frameId = this.elem.globalData.frameId;
  2117. }
  2118. function addEffect(effectFunction) {
  2119. this.effectsSequence.push(effectFunction);
  2120. this.container.addDynamicProperty(this);
  2121. }
  2122. function ValueProperty(elem, data, mult, container){
  2123. this.propType = 'unidimensional';
  2124. this.mult = mult || 1;
  2125. this.data = data;
  2126. this.v = mult ? data.k * mult : data.k;
  2127. this.pv = data.k;
  2128. this._mdf = false;
  2129. this.elem = elem;
  2130. this.container = container;
  2131. this.comp = elem.comp;
  2132. this.k = false;
  2133. this.kf = false;
  2134. this.vel = 0;
  2135. this.effectsSequence = [];
  2136. this._isFirstFrame = true;
  2137. this.getValue = processEffectsSequence;
  2138. this.setVValue = setVValue;
  2139. this.addEffect = addEffect;
  2140. }
  2141. function MultiDimensionalProperty(elem, data, mult, container) {
  2142. this.propType = 'multidimensional';
  2143. this.mult = mult || 1;
  2144. this.data = data;
  2145. this._mdf = false;
  2146. this.elem = elem;
  2147. this.container = container;
  2148. this.comp = elem.comp;
  2149. this.k = false;
  2150. this.kf = false;
  2151. this.frameId = -1;
  2152. var i, len = data.k.length;
  2153. this.v = createTypedArray('float32', len);
  2154. this.pv = createTypedArray('float32', len);
  2155. var arr = createTypedArray('float32', len);
  2156. this.vel = createTypedArray('float32', len);
  2157. for (i = 0; i < len; i += 1) {
  2158. this.v[i] = data.k[i] * this.mult;
  2159. this.pv[i] = data.k[i];
  2160. }
  2161. this._isFirstFrame = true;
  2162. this.effectsSequence = [];
  2163. this.getValue = processEffectsSequence;
  2164. this.setVValue = setVValue;
  2165. this.addEffect = addEffect;
  2166. }
  2167. function KeyframedValueProperty(elem, data, mult, container) {
  2168. this.propType = 'unidimensional';
  2169. this.keyframes = data.k;
  2170. this.offsetTime = elem.data.st;
  2171. this.frameId = -1;
  2172. this._caching = {lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1};
  2173. this.k = true;
  2174. this.kf = true;
  2175. this.data = data;
  2176. this.mult = mult || 1;
  2177. this.elem = elem;
  2178. this.container = container;
  2179. this.comp = elem.comp;
  2180. this.v = initFrame;
  2181. this.pv = initFrame;
  2182. this._isFirstFrame = true;
  2183. this.getValue = processEffectsSequence;
  2184. this.setVValue = setVValue;
  2185. this.interpolateValue = interpolateValue;
  2186. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  2187. this.addEffect = addEffect;
  2188. }
  2189. function KeyframedMultidimensionalProperty(elem, data, mult, container){
  2190. this.propType = 'multidimensional';
  2191. var i, len = data.k.length;
  2192. var s, e,to,ti;
  2193. for (i = 0; i < len - 1; i += 1) {
  2194. if (data.k[i].to && data.k[i].s && data.k[i].e) {
  2195. s = data.k[i].s;
  2196. e = data.k[i].e;
  2197. to = data.k[i].to;
  2198. ti = data.k[i].ti;
  2199. 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]))){
  2200. data.k[i].to = null;
  2201. data.k[i].ti = null;
  2202. }
  2203. if(s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  2204. if(s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) {
  2205. data.k[i].to = null;
  2206. data.k[i].ti = null;
  2207. }
  2208. }
  2209. }
  2210. }
  2211. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  2212. this.keyframes = data.k;
  2213. this.offsetTime = elem.data.st;
  2214. this.k = true;
  2215. this.kf = true;
  2216. this._isFirstFrame = true;
  2217. this.mult = mult || 1;
  2218. this.elem = elem;
  2219. this.container = container;
  2220. this.comp = elem.comp;
  2221. this.getValue = processEffectsSequence;
  2222. this.setVValue = setVValue;
  2223. this.interpolateValue = interpolateValue;
  2224. this.frameId = -1;
  2225. var arrLen = data.k[0].s.length;
  2226. this.v = createTypedArray('float32', arrLen);
  2227. this.pv = createTypedArray('float32', arrLen);
  2228. for (i = 0; i < arrLen; i += 1) {
  2229. this.v[i] = initFrame;
  2230. this.pv[i] = initFrame;
  2231. }
  2232. this._caching={lastFrame:initFrame,lastIndex:0,value:createTypedArray('float32', arrLen)};
  2233. this.addEffect = addEffect;
  2234. }
  2235. function getProp(elem,data,type, mult, container) {
  2236. var p;
  2237. if(!data.k.length){
  2238. p = new ValueProperty(elem,data, mult, container);
  2239. }else if(typeof(data.k[0]) === 'number'){
  2240. p = new MultiDimensionalProperty(elem,data, mult, container);
  2241. }else{
  2242. switch(type){
  2243. case 0:
  2244. p = new KeyframedValueProperty(elem,data,mult, container);
  2245. break;
  2246. case 1:
  2247. p = new KeyframedMultidimensionalProperty(elem,data,mult, container);
  2248. break;
  2249. }
  2250. }
  2251. if(p.effectsSequence.length){
  2252. container.addDynamicProperty(p);
  2253. }
  2254. return p;
  2255. }
  2256. var ob = {
  2257. getProp: getProp
  2258. };
  2259. return ob;
  2260. }());
  2261. var TransformPropertyFactory = (function() {
  2262. function applyToMatrix(mat) {
  2263. var _mdf = this._mdf;
  2264. this.iterateDynamicProperties();
  2265. this._mdf = this._mdf || _mdf;
  2266. if (this.a) {
  2267. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  2268. }
  2269. if (this.s) {
  2270. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  2271. }
  2272. if (this.sk) {
  2273. mat.skewFromAxis(-this.sk.v, this.sa.v);
  2274. }
  2275. if (this.r) {
  2276. mat.rotate(-this.r.v);
  2277. } else {
  2278. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  2279. }
  2280. if (this.data.p.s) {
  2281. if (this.data.p.z) {
  2282. mat.translate(this.px.v, this.py.v, -this.pz.v);
  2283. } else {
  2284. mat.translate(this.px.v, this.py.v, 0);
  2285. }
  2286. } else {
  2287. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  2288. }
  2289. }
  2290. function processKeys(forceRender){
  2291. if (this.elem.globalData.frameId === this.frameId) {
  2292. return;
  2293. }
  2294. if(this._isDirty) {
  2295. this.precalculateMatrix();
  2296. this._isDirty = false;
  2297. }
  2298. this.iterateDynamicProperties();
  2299. if (this._mdf || forceRender) {
  2300. this.v.cloneFromProps(this.pre.props);
  2301. if (this.appliedTransformations < 1) {
  2302. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  2303. }
  2304. if(this.appliedTransformations < 2) {
  2305. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  2306. }
  2307. if (this.sk && this.appliedTransformations < 3) {
  2308. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  2309. }
  2310. if (this.r && this.appliedTransformations < 4) {
  2311. this.v.rotate(-this.r.v);
  2312. } else if (!this.r && this.appliedTransformations < 4){
  2313. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  2314. }
  2315. if (this.autoOriented) {
  2316. var v1,v2, frameRate = this.elem.globalData.frameRate;
  2317. if(this.p && this.p.keyframes && this.p.getValueAtTime) {
  2318. if (this.p._caching.lastFrame+this.p.offsetTime <= this.p.keyframes[0].t) {
  2319. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate,0);
  2320. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  2321. } else if(this.p._caching.lastFrame+this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  2322. v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0);
  2323. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.01) / frameRate, 0);
  2324. } else {
  2325. v1 = this.p.pv;
  2326. v2 = this.p.getValueAtTime((this.p._caching.lastFrame+this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  2327. }
  2328. } else if(this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  2329. v1 = [];
  2330. v2 = [];
  2331. var px = this.px, py = this.py, frameRate;
  2332. if (px._caching.lastFrame+px.offsetTime <= px.keyframes[0].t) {
  2333. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate,0);
  2334. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate,0);
  2335. v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate,0);
  2336. v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate,0);
  2337. } else if(px._caching.lastFrame+px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  2338. v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate),0);
  2339. v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate),0);
  2340. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate,0);
  2341. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate,0);
  2342. } else {
  2343. v1 = [px.pv, py.pv];
  2344. v2[0] = px.getValueAtTime((px._caching.lastFrame+px.offsetTime - 0.01) / frameRate,px.offsetTime);
  2345. v2[1] = py.getValueAtTime((py._caching.lastFrame+py.offsetTime - 0.01) / frameRate,py.offsetTime);
  2346. }
  2347. }
  2348. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  2349. }
  2350. if(this.data.p && this.data.p.s){
  2351. if(this.data.p.z) {
  2352. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  2353. } else {
  2354. this.v.translate(this.px.v, this.py.v, 0);
  2355. }
  2356. }else{
  2357. this.v.translate(this.p.v[0],this.p.v[1],-this.p.v[2]);
  2358. }
  2359. }
  2360. this.frameId = this.elem.globalData.frameId;
  2361. }
  2362. function precalculateMatrix() {
  2363. if(!this.a.k) {
  2364. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  2365. this.appliedTransformations = 1;
  2366. } else {
  2367. return;
  2368. }
  2369. if(!this.s.effectsSequence.length) {
  2370. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  2371. this.appliedTransformations = 2;
  2372. } else {
  2373. return;
  2374. }
  2375. if(this.sk) {
  2376. if(!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  2377. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  2378. this.appliedTransformations = 3;
  2379. } else {
  2380. return;
  2381. }
  2382. }
  2383. if (this.r) {
  2384. if(!this.r.effectsSequence.length) {
  2385. this.pre.rotate(-this.r.v);
  2386. this.appliedTransformations = 4;
  2387. } else {
  2388. return;
  2389. }
  2390. } else if(!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  2391. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]).rotateY(this.or.v[1]).rotateX(this.or.v[0]);
  2392. this.appliedTransformations = 4;
  2393. }
  2394. }
  2395. function autoOrient(){
  2396. //
  2397. //var prevP = this.getValueAtTime();
  2398. }
  2399. function addDynamicProperty(prop) {
  2400. this._addDynamicProperty(prop);
  2401. this.elem.addDynamicProperty(prop);
  2402. this._isDirty = true;
  2403. }
  2404. function TransformProperty(elem,data,container){
  2405. this.elem = elem;
  2406. this.frameId = -1;
  2407. this.propType = 'transform';
  2408. this.data = data;
  2409. this.v = new Matrix();
  2410. //Precalculated matrix with non animated properties
  2411. this.pre = new Matrix();
  2412. this.appliedTransformations = 0;
  2413. this.initDynamicPropertyContainer(container || elem);
  2414. if(data.p && data.p.s){
  2415. this.px = PropertyFactory.getProp(elem,data.p.x,0,0,this);
  2416. this.py = PropertyFactory.getProp(elem,data.p.y,0,0,this);
  2417. if(data.p.z){
  2418. this.pz = PropertyFactory.getProp(elem,data.p.z,0,0,this);
  2419. }
  2420. }else{
  2421. this.p = PropertyFactory.getProp(elem,data.p || {k:[0,0,0]},1,0,this);
  2422. }
  2423. if(data.rx) {
  2424. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  2425. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  2426. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  2427. if(data.or.k[0].ti) {
  2428. var i, len = data.or.k.length;
  2429. for(i=0;i<len;i+=1) {
  2430. data.or.k[i].to = data.or.k[i].ti = null;
  2431. }
  2432. }
  2433. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  2434. //sh Indicates it needs to be capped between -180 and 180
  2435. this.or.sh = true;
  2436. } else {
  2437. this.r = PropertyFactory.getProp(elem, data.r || {k: 0}, 0, degToRads, this);
  2438. }
  2439. if(data.sk){
  2440. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  2441. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  2442. }
  2443. this.a = PropertyFactory.getProp(elem,data.a || {k:[0,0,0]},1,0,this);
  2444. this.s = PropertyFactory.getProp(elem,data.s || {k:[100,100,100]},1,0.01,this);
  2445. // 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.
  2446. if(data.o){
  2447. this.o = PropertyFactory.getProp(elem,data.o,0,0.01,elem);
  2448. } else {
  2449. this.o = {_mdf:false,v:1};
  2450. }
  2451. this._isDirty = true;
  2452. if(!this.dynamicProperties.length){
  2453. this.getValue(true);
  2454. }
  2455. }
  2456. TransformProperty.prototype = {
  2457. applyToMatrix: applyToMatrix,
  2458. getValue: processKeys,
  2459. precalculateMatrix: precalculateMatrix,
  2460. autoOrient: autoOrient
  2461. }
  2462. extendPrototype([DynamicPropertyContainer], TransformProperty);
  2463. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  2464. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  2465. function getTransformProperty(elem,data,container){
  2466. return new TransformProperty(elem,data,container);
  2467. }
  2468. return {
  2469. getTransformProperty: getTransformProperty
  2470. };
  2471. }());
  2472. function ShapePath(){
  2473. this.c = false;
  2474. this._length = 0;
  2475. this._maxLength = 8;
  2476. this.v = createSizedArray(this._maxLength);
  2477. this.o = createSizedArray(this._maxLength);
  2478. this.i = createSizedArray(this._maxLength);
  2479. }
  2480. ShapePath.prototype.setPathData = function(closed, len) {
  2481. this.c = closed;
  2482. this.setLength(len);
  2483. var i = 0;
  2484. while(i < len){
  2485. this.v[i] = point_pool.newElement();
  2486. this.o[i] = point_pool.newElement();
  2487. this.i[i] = point_pool.newElement();
  2488. i += 1;
  2489. }
  2490. };
  2491. ShapePath.prototype.setLength = function(len) {
  2492. while(this._maxLength < len) {
  2493. this.doubleArrayLength();
  2494. }
  2495. this._length = len;
  2496. };
  2497. ShapePath.prototype.doubleArrayLength = function() {
  2498. this.v = this.v.concat(createSizedArray(this._maxLength));
  2499. this.i = this.i.concat(createSizedArray(this._maxLength));
  2500. this.o = this.o.concat(createSizedArray(this._maxLength));
  2501. this._maxLength *= 2;
  2502. };
  2503. ShapePath.prototype.setXYAt = function(x, y, type, pos, replace) {
  2504. var arr;
  2505. this._length = Math.max(this._length, pos + 1);
  2506. if(this._length >= this._maxLength) {
  2507. this.doubleArrayLength();
  2508. }
  2509. switch(type){
  2510. case 'v':
  2511. arr = this.v;
  2512. break;
  2513. case 'i':
  2514. arr = this.i;
  2515. break;
  2516. case 'o':
  2517. arr = this.o;
  2518. break;
  2519. }
  2520. if(!arr[pos] || (arr[pos] && !replace)){
  2521. arr[pos] = point_pool.newElement();
  2522. }
  2523. arr[pos][0] = x;
  2524. arr[pos][1] = y;
  2525. };
  2526. ShapePath.prototype.setTripleAt = function(vX,vY,oX,oY,iX,iY,pos, replace) {
  2527. this.setXYAt(vX,vY,'v',pos, replace);
  2528. this.setXYAt(oX,oY,'o',pos, replace);
  2529. this.setXYAt(iX,iY,'i',pos, replace);
  2530. };
  2531. ShapePath.prototype.reverse = function() {
  2532. var newPath = new ShapePath();
  2533. newPath.setPathData(this.c, this._length);
  2534. var vertices = this.v, outPoints = this.o, inPoints = this.i;
  2535. var init = 0;
  2536. if (this.c) {
  2537. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  2538. init = 1;
  2539. }
  2540. var cnt = this._length - 1;
  2541. var len = this._length;
  2542. var i;
  2543. for (i = init; i < len; i += 1) {
  2544. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  2545. cnt -= 1;
  2546. }
  2547. return newPath;
  2548. };
  2549. var ShapePropertyFactory = (function(){
  2550. var initFrame = -999999;
  2551. function interpolateShape(frameNum, previousValue, caching) {
  2552. var iterationIndex = caching.lastIndex;
  2553. var keyPropS,keyPropE,isHold, j, k, jLen, kLen, perc, vertexValue;
  2554. var kf = this.keyframes;
  2555. if(frameNum < kf[0].t-this.offsetTime){
  2556. keyPropS = kf[0].s[0];
  2557. isHold = true;
  2558. iterationIndex = 0;
  2559. }else if(frameNum >= kf[kf.length - 1].t-this.offsetTime){
  2560. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  2561. /*if(kf[kf.length - 1].s){
  2562. keyPropS = kf[kf.length - 1].s[0];
  2563. }else{
  2564. keyPropS = kf[kf.length - 2].e[0];
  2565. }*/
  2566. isHold = true;
  2567. }else{
  2568. var i = iterationIndex;
  2569. var len = kf.length- 1,flag = true,keyData,nextKeyData;
  2570. while(flag){
  2571. keyData = kf[i];
  2572. nextKeyData = kf[i+1];
  2573. if((nextKeyData.t - this.offsetTime) > frameNum){
  2574. break;
  2575. }
  2576. if(i < len - 1){
  2577. i += 1;
  2578. }else{
  2579. flag = false;
  2580. }
  2581. }
  2582. isHold = keyData.h === 1;
  2583. iterationIndex = i;
  2584. if(!isHold){
  2585. if(frameNum >= nextKeyData.t-this.offsetTime){
  2586. perc = 1;
  2587. }else if(frameNum < keyData.t-this.offsetTime){
  2588. perc = 0;
  2589. }else{
  2590. var fnc;
  2591. if(keyData.__fnct){
  2592. fnc = keyData.__fnct;
  2593. }else{
  2594. fnc = BezierFactory.getBezierEasing(keyData.o.x,keyData.o.y,keyData.i.x,keyData.i.y).get;
  2595. keyData.__fnct = fnc;
  2596. }
  2597. perc = fnc((frameNum-(keyData.t-this.offsetTime))/((nextKeyData.t-this.offsetTime)-(keyData.t-this.offsetTime)));
  2598. }
  2599. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  2600. }
  2601. keyPropS = keyData.s[0];
  2602. }
  2603. jLen = previousValue._length;
  2604. kLen = keyPropS.i[0].length;
  2605. caching.lastIndex = iterationIndex;
  2606. for(j=0;j<jLen;j+=1){
  2607. for(k=0;k<kLen;k+=1){
  2608. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k]+(keyPropE.i[j][k]-keyPropS.i[j][k])*perc;
  2609. previousValue.i[j][k] = vertexValue;
  2610. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k]+(keyPropE.o[j][k]-keyPropS.o[j][k])*perc;
  2611. previousValue.o[j][k] = vertexValue;
  2612. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k]+(keyPropE.v[j][k]-keyPropS.v[j][k])*perc;
  2613. previousValue.v[j][k] = vertexValue;
  2614. }
  2615. }
  2616. }
  2617. function interpolateShapeCurrentTime(){
  2618. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2619. var initTime = this.keyframes[0].t - this.offsetTime;
  2620. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2621. var lastFrame = this._caching.lastFrame;
  2622. if(!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))){
  2623. ////
  2624. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  2625. this.interpolateShape(frameNum, this.pv, this._caching);
  2626. ////
  2627. }
  2628. this._caching.lastFrame = frameNum;
  2629. return this.pv;
  2630. }
  2631. function resetShape(){
  2632. this.paths = this.localShapeCollection;
  2633. }
  2634. function shapesEqual(shape1, shape2) {
  2635. if(shape1._length !== shape2._length || shape1.c !== shape2.c){
  2636. return false;
  2637. }
  2638. var i, len = shape1._length;
  2639. for(i = 0; i < len; i += 1) {
  2640. if(shape1.v[i][0] !== shape2.v[i][0]
  2641. || shape1.v[i][1] !== shape2.v[i][1]
  2642. || shape1.o[i][0] !== shape2.o[i][0]
  2643. || shape1.o[i][1] !== shape2.o[i][1]
  2644. || shape1.i[i][0] !== shape2.i[i][0]
  2645. || shape1.i[i][1] !== shape2.i[i][1]) {
  2646. return false;
  2647. }
  2648. }
  2649. return true;
  2650. }
  2651. function setVValue(newPath) {
  2652. if(!shapesEqual(this.v, newPath)) {
  2653. this.v = shape_pool.clone(newPath);
  2654. this.localShapeCollection.releaseShapes();
  2655. this.localShapeCollection.addShape(this.v);
  2656. this._mdf = true;
  2657. this.paths = this.localShapeCollection;
  2658. }
  2659. }
  2660. function processEffectsSequence() {
  2661. if(this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  2662. return;
  2663. }
  2664. if(this.lock) {
  2665. this.setVValue(this.pv);
  2666. return;
  2667. }
  2668. this.lock = true;
  2669. this._mdf = false;
  2670. var finalValue = this.kf ? this.pv : this.data.ks ? this.data.ks.k : this.data.pt.k;
  2671. var i, len = this.effectsSequence.length;
  2672. for(i = 0; i < len; i += 1) {
  2673. finalValue = this.effectsSequence[i](finalValue);
  2674. }
  2675. this.setVValue(finalValue);
  2676. this.lock = false;
  2677. this.frameId = this.elem.globalData.frameId;
  2678. };
  2679. function ShapeProperty(elem, data, type){
  2680. this.propType = 'shape';
  2681. this.comp = elem.comp;
  2682. this.container = elem;
  2683. this.elem = elem;
  2684. this.data = data;
  2685. this.k = false;
  2686. this.kf = false;
  2687. this._mdf = false;
  2688. var pathData = type === 3 ? data.pt.k : data.ks.k;
  2689. this.v = shape_pool.clone(pathData);
  2690. this.pv = shape_pool.clone(this.v);
  2691. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2692. this.paths = this.localShapeCollection;
  2693. this.paths.addShape(this.v);
  2694. this.reset = resetShape;
  2695. this.effectsSequence = [];
  2696. }
  2697. function addEffect(effectFunction) {
  2698. this.effectsSequence.push(effectFunction);
  2699. this.container.addDynamicProperty(this);
  2700. }
  2701. ShapeProperty.prototype.interpolateShape = interpolateShape;
  2702. ShapeProperty.prototype.getValue = processEffectsSequence;
  2703. ShapeProperty.prototype.setVValue = setVValue;
  2704. ShapeProperty.prototype.addEffect = addEffect;
  2705. function KeyframedShapeProperty(elem,data,type){
  2706. this.propType = 'shape';
  2707. this.comp = elem.comp;
  2708. this.elem = elem;
  2709. this.container = elem;
  2710. this.offsetTime = elem.data.st;
  2711. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  2712. this.k = true;
  2713. this.kf = true;
  2714. var i, len = this.keyframes[0].s[0].i.length;
  2715. var jLen = this.keyframes[0].s[0].i[0].length;
  2716. this.v = shape_pool.newElement();
  2717. this.v.setPathData(this.keyframes[0].s[0].c, len);
  2718. this.pv = shape_pool.clone(this.v);
  2719. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2720. this.paths = this.localShapeCollection;
  2721. this.paths.addShape(this.v);
  2722. this.lastFrame = initFrame;
  2723. this.reset = resetShape;
  2724. this._caching = {lastFrame: initFrame, lastIndex: 0};
  2725. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  2726. }
  2727. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  2728. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  2729. KeyframedShapeProperty.prototype.setVValue = setVValue;
  2730. KeyframedShapeProperty.prototype.addEffect = addEffect;
  2731. var EllShapeProperty = (function(){
  2732. var cPoint = roundCorner;
  2733. function EllShapeProperty(elem,data) {
  2734. /*this.v = {
  2735. v: createSizedArray(4),
  2736. i: createSizedArray(4),
  2737. o: createSizedArray(4),
  2738. c: true
  2739. };*/
  2740. this.v = shape_pool.newElement();
  2741. this.v.setPathData(true, 4);
  2742. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2743. this.paths = this.localShapeCollection;
  2744. this.localShapeCollection.addShape(this.v);
  2745. this.d = data.d;
  2746. this.elem = elem;
  2747. this.comp = elem.comp;
  2748. this.frameId = -1;
  2749. this.initDynamicPropertyContainer(elem);
  2750. this.p = PropertyFactory.getProp(elem,data.p,1,0,this);
  2751. this.s = PropertyFactory.getProp(elem,data.s,1,0,this);
  2752. if(this.dynamicProperties.length){
  2753. this.k = true;
  2754. }else{
  2755. this.k = false;
  2756. this.convertEllToPath();
  2757. }
  2758. };
  2759. EllShapeProperty.prototype = {
  2760. reset: resetShape,
  2761. getValue: function (){
  2762. if(this.elem.globalData.frameId === this.frameId){
  2763. return;
  2764. }
  2765. this.frameId = this.elem.globalData.frameId;
  2766. this.iterateDynamicProperties();
  2767. if(this._mdf){
  2768. this.convertEllToPath();
  2769. }
  2770. },
  2771. convertEllToPath: function() {
  2772. var p0 = this.p.v[0], p1 = this.p.v[1], s0 = this.s.v[0]/2, s1 = this.s.v[1]/2;
  2773. var _cw = this.d !== 3;
  2774. var _v = this.v;
  2775. _v.v[0][0] = p0;
  2776. _v.v[0][1] = p1 - s1;
  2777. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  2778. _v.v[1][1] = p1;
  2779. _v.v[2][0] = p0;
  2780. _v.v[2][1] = p1 + s1;
  2781. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  2782. _v.v[3][1] = p1;
  2783. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  2784. _v.i[0][1] = p1 - s1;
  2785. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  2786. _v.i[1][1] = p1 - s1 * cPoint;
  2787. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  2788. _v.i[2][1] = p1 + s1;
  2789. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  2790. _v.i[3][1] = p1 + s1 * cPoint;
  2791. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  2792. _v.o[0][1] = p1 - s1;
  2793. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  2794. _v.o[1][1] = p1 + s1 * cPoint;
  2795. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  2796. _v.o[2][1] = p1 + s1;
  2797. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  2798. _v.o[3][1] = p1 - s1 * cPoint;
  2799. }
  2800. }
  2801. extendPrototype([DynamicPropertyContainer], EllShapeProperty);
  2802. return EllShapeProperty;
  2803. }());
  2804. var StarShapeProperty = (function() {
  2805. function StarShapeProperty(elem,data) {
  2806. this.v = shape_pool.newElement();
  2807. this.v.setPathData(true, 0);
  2808. this.elem = elem;
  2809. this.comp = elem.comp;
  2810. this.data = data;
  2811. this.frameId = -1;
  2812. this.d = data.d;
  2813. this.initDynamicPropertyContainer(elem);
  2814. if(data.sy === 1){
  2815. this.ir = PropertyFactory.getProp(elem,data.ir,0,0,this);
  2816. this.is = PropertyFactory.getProp(elem,data.is,0,0.01,this);
  2817. this.convertToPath = this.convertStarToPath;
  2818. } else {
  2819. this.convertToPath = this.convertPolygonToPath;
  2820. }
  2821. this.pt = PropertyFactory.getProp(elem,data.pt,0,0,this);
  2822. this.p = PropertyFactory.getProp(elem,data.p,1,0,this);
  2823. this.r = PropertyFactory.getProp(elem,data.r,0,degToRads,this);
  2824. this.or = PropertyFactory.getProp(elem,data.or,0,0,this);
  2825. this.os = PropertyFactory.getProp(elem,data.os,0,0.01,this);
  2826. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2827. this.localShapeCollection.addShape(this.v);
  2828. this.paths = this.localShapeCollection;
  2829. if(this.dynamicProperties.length){
  2830. this.k = true;
  2831. }else{
  2832. this.k = false;
  2833. this.convertToPath();
  2834. }
  2835. };
  2836. StarShapeProperty.prototype = {
  2837. reset: resetShape,
  2838. getValue: function() {
  2839. if(this.elem.globalData.frameId === this.frameId){
  2840. return;
  2841. }
  2842. this.frameId = this.elem.globalData.frameId;
  2843. this.iterateDynamicProperties();
  2844. if(this._mdf){
  2845. this.convertToPath();
  2846. }
  2847. },
  2848. convertStarToPath: function() {
  2849. var numPts = Math.floor(this.pt.v)*2;
  2850. var angle = Math.PI*2/numPts;
  2851. /*this.v.v.length = numPts;
  2852. this.v.i.length = numPts;
  2853. this.v.o.length = numPts;*/
  2854. var longFlag = true;
  2855. var longRad = this.or.v;
  2856. var shortRad = this.ir.v;
  2857. var longRound = this.os.v;
  2858. var shortRound = this.is.v;
  2859. var longPerimSegment = 2*Math.PI*longRad/(numPts*2);
  2860. var shortPerimSegment = 2*Math.PI*shortRad/(numPts*2);
  2861. var i, rad,roundness,perimSegment, currentAng = -Math.PI/ 2;
  2862. currentAng += this.r.v;
  2863. var dir = this.data.d === 3 ? -1 : 1;
  2864. this.v._length = 0;
  2865. for(i=0;i<numPts;i+=1){
  2866. rad = longFlag ? longRad : shortRad;
  2867. roundness = longFlag ? longRound : shortRound;
  2868. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  2869. var x = rad * Math.cos(currentAng);
  2870. var y = rad * Math.sin(currentAng);
  2871. var ox = x === 0 && y === 0 ? 0 : y/Math.sqrt(x*x + y*y);
  2872. var oy = x === 0 && y === 0 ? 0 : -x/Math.sqrt(x*x + y*y);
  2873. x += + this.p.v[0];
  2874. y += + this.p.v[1];
  2875. 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);
  2876. /*this.v.v[i] = [x,y];
  2877. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  2878. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  2879. this.v._length = numPts;*/
  2880. longFlag = !longFlag;
  2881. currentAng += angle*dir;
  2882. }
  2883. },
  2884. convertPolygonToPath: function() {
  2885. var numPts = Math.floor(this.pt.v);
  2886. var angle = Math.PI*2/numPts;
  2887. var rad = this.or.v;
  2888. var roundness = this.os.v;
  2889. var perimSegment = 2*Math.PI*rad/(numPts*4);
  2890. var i, currentAng = -Math.PI/ 2;
  2891. var dir = this.data.d === 3 ? -1 : 1;
  2892. currentAng += this.r.v;
  2893. this.v._length = 0;
  2894. for(i=0;i<numPts;i+=1){
  2895. var x = rad * Math.cos(currentAng);
  2896. var y = rad * Math.sin(currentAng);
  2897. var ox = x === 0 && y === 0 ? 0 : y/Math.sqrt(x*x + y*y);
  2898. var oy = x === 0 && y === 0 ? 0 : -x/Math.sqrt(x*x + y*y);
  2899. x += + this.p.v[0];
  2900. y += + this.p.v[1];
  2901. 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);
  2902. currentAng += angle*dir;
  2903. }
  2904. this.paths.length = 0;
  2905. this.paths[0] = this.v;
  2906. }
  2907. }
  2908. extendPrototype([DynamicPropertyContainer], StarShapeProperty);
  2909. return StarShapeProperty;
  2910. }());
  2911. var RectShapeProperty = (function() {
  2912. function RectShapeProperty(elem,data) {
  2913. this.v = shape_pool.newElement();
  2914. this.v.c = true;
  2915. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2916. this.localShapeCollection.addShape(this.v);
  2917. this.paths = this.localShapeCollection;
  2918. this.elem = elem;
  2919. this.comp = elem.comp;
  2920. this.frameId = -1;
  2921. this.d = data.d;
  2922. this.initDynamicPropertyContainer(elem);
  2923. this.p = PropertyFactory.getProp(elem,data.p,1,0,this);
  2924. this.s = PropertyFactory.getProp(elem,data.s,1,0,this);
  2925. this.r = PropertyFactory.getProp(elem,data.r,0,0,this);
  2926. if(this.dynamicProperties.length){
  2927. this.k = true;
  2928. }else{
  2929. this.k = false;
  2930. this.convertRectToPath();
  2931. }
  2932. };
  2933. RectShapeProperty.prototype = {
  2934. convertRectToPath: function (){
  2935. var p0 = this.p.v[0], p1 = this.p.v[1], v0 = this.s.v[0]/2, v1 = this.s.v[1]/2;
  2936. var round = bm_min(v0,v1,this.r.v);
  2937. var cPoint = round*(1-roundCorner);
  2938. this.v._length = 0;
  2939. if(this.d === 2 || this.d === 1) {
  2940. this.v.setTripleAt(p0+v0, p1-v1+round,p0+v0, p1-v1+round,p0+v0,p1-v1+cPoint,0, true);
  2941. this.v.setTripleAt(p0+v0, p1+v1-round,p0+v0, p1+v1-cPoint,p0+v0, p1+v1-round,1, true);
  2942. if(round!== 0){
  2943. this.v.setTripleAt(p0+v0-round, p1+v1,p0+v0-round,p1+v1,p0+v0-cPoint,p1+v1,2, true);
  2944. this.v.setTripleAt(p0-v0+round,p1+v1,p0-v0+cPoint,p1+v1,p0-v0+round,p1+v1,3, true);
  2945. this.v.setTripleAt(p0-v0,p1+v1-round,p0-v0,p1+v1-round,p0-v0,p1+v1-cPoint,4, true);
  2946. this.v.setTripleAt(p0-v0,p1-v1+round,p0-v0,p1-v1+cPoint,p0-v0,p1-v1+round,5, true);
  2947. this.v.setTripleAt(p0-v0+round,p1-v1,p0-v0+round,p1-v1,p0-v0+cPoint,p1-v1,6, true);
  2948. this.v.setTripleAt(p0+v0-round,p1-v1,p0+v0-cPoint,p1-v1,p0+v0-round,p1-v1,7, true);
  2949. } else {
  2950. this.v.setTripleAt(p0-v0,p1+v1,p0-v0+cPoint,p1+v1,p0-v0,p1+v1,2);
  2951. this.v.setTripleAt(p0-v0,p1-v1,p0-v0,p1-v1+cPoint,p0-v0,p1-v1,3);
  2952. }
  2953. }else{
  2954. this.v.setTripleAt(p0+v0,p1-v1+round,p0+v0,p1-v1+cPoint,p0+v0,p1-v1+round,0, true);
  2955. if(round!== 0){
  2956. this.v.setTripleAt(p0+v0-round,p1-v1,p0+v0-round,p1-v1,p0+v0-cPoint,p1-v1,1, true);
  2957. this.v.setTripleAt(p0-v0+round,p1-v1,p0-v0+cPoint,p1-v1,p0-v0+round,p1-v1,2, true);
  2958. this.v.setTripleAt(p0-v0,p1-v1+round,p0-v0,p1-v1+round,p0-v0,p1-v1+cPoint,3, true);
  2959. this.v.setTripleAt(p0-v0,p1+v1-round,p0-v0,p1+v1-cPoint,p0-v0,p1+v1-round,4, true);
  2960. this.v.setTripleAt(p0-v0+round,p1+v1,p0-v0+round,p1+v1,p0-v0+cPoint,p1+v1,5, true);
  2961. this.v.setTripleAt(p0+v0-round,p1+v1,p0+v0-cPoint,p1+v1,p0+v0-round,p1+v1,6, true);
  2962. this.v.setTripleAt(p0+v0,p1+v1-round,p0+v0,p1+v1-round,p0+v0,p1+v1-cPoint,7, true);
  2963. } else {
  2964. this.v.setTripleAt(p0-v0,p1-v1,p0-v0+cPoint,p1-v1,p0-v0,p1-v1,1, true);
  2965. this.v.setTripleAt(p0-v0,p1+v1,p0-v0,p1+v1-cPoint,p0-v0,p1+v1,2, true);
  2966. this.v.setTripleAt(p0+v0,p1+v1,p0+v0-cPoint,p1+v1,p0+v0,p1+v1,3, true);
  2967. }
  2968. }
  2969. },
  2970. getValue: function(frameNum){
  2971. if(this.elem.globalData.frameId === this.frameId){
  2972. return;
  2973. }
  2974. this.frameId = this.elem.globalData.frameId;
  2975. this.iterateDynamicProperties();
  2976. if(this._mdf){
  2977. this.convertRectToPath();
  2978. }
  2979. },
  2980. reset: resetShape
  2981. }
  2982. extendPrototype([DynamicPropertyContainer], RectShapeProperty);
  2983. return RectShapeProperty;
  2984. }());
  2985. function getShapeProp(elem,data,type){
  2986. var prop;
  2987. if(type === 3 || type === 4){
  2988. var dataProp = type === 3 ? data.pt : data.ks;
  2989. var keys = dataProp.k;
  2990. if(keys.length){
  2991. prop = new KeyframedShapeProperty(elem, data, type);
  2992. }else{
  2993. prop = new ShapeProperty(elem, data, type);
  2994. }
  2995. }else if(type === 5){
  2996. prop = new RectShapeProperty(elem, data);
  2997. }else if(type === 6){
  2998. prop = new EllShapeProperty(elem, data);
  2999. }else if(type === 7){
  3000. prop = new StarShapeProperty(elem, data);
  3001. }
  3002. if(prop.k){
  3003. elem.addDynamicProperty(prop);
  3004. }
  3005. return prop;
  3006. }
  3007. function getConstructorFunction() {
  3008. return ShapeProperty;
  3009. }
  3010. function getKeyframedConstructorFunction() {
  3011. return KeyframedShapeProperty;
  3012. }
  3013. var ob = {};
  3014. ob.getShapeProp = getShapeProp;
  3015. ob.getConstructorFunction = getConstructorFunction;
  3016. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3017. return ob;
  3018. }());
  3019. var ShapeModifiers = (function(){
  3020. var ob = {};
  3021. var modifiers = {};
  3022. ob.registerModifier = registerModifier;
  3023. ob.getModifier = getModifier;
  3024. function registerModifier(nm,factory){
  3025. if(!modifiers[nm]){
  3026. modifiers[nm] = factory;
  3027. }
  3028. }
  3029. function getModifier(nm,elem, data){
  3030. return new modifiers[nm](elem, data);
  3031. }
  3032. return ob;
  3033. }());
  3034. function ShapeModifier(){}
  3035. ShapeModifier.prototype.initModifierProperties = function(){};
  3036. ShapeModifier.prototype.addShapeToModifier = function(){};
  3037. ShapeModifier.prototype.addShape = function(data){
  3038. if(!this.closed){
  3039. var shapeData = {shape:data.sh, data: data, localShapeCollection:shapeCollection_pool.newShapeCollection()};
  3040. this.shapes.push(shapeData);
  3041. this.addShapeToModifier(shapeData);
  3042. if(this._isAnimated) {
  3043. data.setAsAnimated();
  3044. }
  3045. }
  3046. };
  3047. ShapeModifier.prototype.init = function(elem,data){
  3048. this.shapes = [];
  3049. this.elem = elem;
  3050. this.initDynamicPropertyContainer(elem);
  3051. this.initModifierProperties(elem,data);
  3052. this.frameId = initialDefaultFrame;
  3053. this.closed = false;
  3054. this.k = false;
  3055. if(this.dynamicProperties.length){
  3056. this.k = true;
  3057. }else{
  3058. this.getValue(true);
  3059. }
  3060. };
  3061. ShapeModifier.prototype.processKeys = function(){
  3062. if(this.elem.globalData.frameId === this.frameId){
  3063. return;
  3064. }
  3065. this.frameId = this.elem.globalData.frameId;
  3066. this.iterateDynamicProperties();
  3067. };
  3068. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  3069. function TrimModifier(){
  3070. }
  3071. extendPrototype([ShapeModifier], TrimModifier);
  3072. TrimModifier.prototype.initModifierProperties = function(elem, data) {
  3073. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  3074. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  3075. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  3076. this.sValue = 0;
  3077. this.eValue = 0;
  3078. this.getValue = this.processKeys;
  3079. this.m = data.m;
  3080. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  3081. };
  3082. TrimModifier.prototype.addShapeToModifier = function(shapeData){
  3083. shapeData.pathsData = [];
  3084. };
  3085. TrimModifier.prototype.calculateShapeEdges = function(s, e, shapeLength, addedLength, totalModifierLength) {
  3086. var segments = [];
  3087. if (e <= 1) {
  3088. segments.push({
  3089. s: s,
  3090. e: e
  3091. });
  3092. } else if (s >= 1) {
  3093. segments.push({
  3094. s: s - 1,
  3095. e: e - 1
  3096. });
  3097. } else {
  3098. segments.push({
  3099. s: s,
  3100. e: 1
  3101. });
  3102. segments.push({
  3103. s: 0,
  3104. e: e - 1
  3105. });
  3106. }
  3107. var shapeSegments = [];
  3108. var i, len = segments.length, segmentOb;
  3109. for (i = 0; i < len; i += 1) {
  3110. segmentOb = segments[i];
  3111. if (segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength) {
  3112. } else {
  3113. var shapeS, shapeE;
  3114. if (segmentOb.s * totalModifierLength <= addedLength) {
  3115. shapeS = 0;
  3116. } else {
  3117. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  3118. }
  3119. if(segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  3120. shapeE = 1;
  3121. } else {
  3122. shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength);
  3123. }
  3124. shapeSegments.push([shapeS, shapeE]);
  3125. }
  3126. }
  3127. if (!shapeSegments.length) {
  3128. shapeSegments.push([0, 0]);
  3129. }
  3130. return shapeSegments;
  3131. };
  3132. TrimModifier.prototype.releasePathsData = function(pathsData) {
  3133. var i, len = pathsData.length;
  3134. for (i = 0; i < len; i += 1) {
  3135. segments_length_pool.release(pathsData[i]);
  3136. }
  3137. pathsData.length = 0;
  3138. return pathsData;
  3139. };
  3140. TrimModifier.prototype.processShapes = function(_isFirstFrame) {
  3141. var s, e;
  3142. if (this._mdf || _isFirstFrame) {
  3143. var o = (this.o.v % 360) / 360;
  3144. if (o < 0) {
  3145. o += 1;
  3146. }
  3147. s = (this.s.v > 1 ? 1 : this.s.v < 0 ? 0 : this.s.v) + o;
  3148. e = (this.e.v > 1 ? 1 : this.e.v < 0 ? 0 : this.e.v) + o;
  3149. if (s === e) {
  3150. }
  3151. if (s > e) {
  3152. var _s = s;
  3153. s = e;
  3154. e = _s;
  3155. }
  3156. s = Math.round(s * 10000) * 0.0001;
  3157. e = Math.round(e * 10000) * 0.0001;
  3158. this.sValue = s;
  3159. this.eValue = e;
  3160. } else {
  3161. s = this.sValue;
  3162. e = this.eValue;
  3163. }
  3164. var shapePaths;
  3165. var i, len = this.shapes.length, j, jLen;
  3166. var pathsData, pathData, totalShapeLength, totalModifierLength = 0;
  3167. if (e === s) {
  3168. for (i = 0; i < len; i += 1) {
  3169. this.shapes[i].localShapeCollection.releaseShapes();
  3170. this.shapes[i].shape._mdf = true;
  3171. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  3172. }
  3173. } else if (!((e === 1 && s === 0) || (e===0 && s === 1))){
  3174. var segments = [], shapeData, localShapeCollection;
  3175. for (i = 0; i < len; i += 1) {
  3176. shapeData = this.shapes[i];
  3177. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  3178. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  3179. shapeData.shape.paths = shapeData.localShapeCollection;
  3180. } else {
  3181. shapePaths = shapeData.shape.paths;
  3182. jLen = shapePaths._length;
  3183. totalShapeLength = 0;
  3184. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  3185. totalShapeLength = shapeData.totalShapeLength;
  3186. } else {
  3187. pathsData = this.releasePathsData(shapeData.pathsData);
  3188. for (j = 0; j < jLen; j += 1) {
  3189. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  3190. pathsData.push(pathData);
  3191. totalShapeLength += pathData.totalLength;
  3192. }
  3193. shapeData.totalShapeLength = totalShapeLength;
  3194. shapeData.pathsData = pathsData;
  3195. }
  3196. totalModifierLength += totalShapeLength;
  3197. shapeData.shape._mdf = true;
  3198. }
  3199. }
  3200. var shapeS = s, shapeE = e, addedLength = 0, edges;
  3201. for (i = len - 1; i >= 0; i -= 1) {
  3202. shapeData = this.shapes[i];
  3203. if (shapeData.shape._mdf) {
  3204. localShapeCollection = shapeData.localShapeCollection;
  3205. localShapeCollection.releaseShapes();
  3206. //if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  3207. if (this.m === 2 && len > 1) {
  3208. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  3209. addedLength += shapeData.totalShapeLength;
  3210. } else {
  3211. edges = [[shapeS, shapeE]];
  3212. }
  3213. jLen = edges.length;
  3214. for (j = 0; j < jLen; j += 1) {
  3215. shapeS = edges[j][0];
  3216. shapeE = edges[j][1];
  3217. segments.length = 0;
  3218. if (shapeE <= 1) {
  3219. segments.push({
  3220. s:shapeData.totalShapeLength * shapeS,
  3221. e:shapeData.totalShapeLength * shapeE
  3222. });
  3223. } else if (shapeS >= 1) {
  3224. segments.push({
  3225. s:shapeData.totalShapeLength * (shapeS - 1),
  3226. e:shapeData.totalShapeLength * (shapeE - 1)
  3227. });
  3228. } else {
  3229. segments.push({
  3230. s:shapeData.totalShapeLength * shapeS,
  3231. e:shapeData.totalShapeLength
  3232. });
  3233. segments.push({
  3234. s:0,
  3235. e:shapeData.totalShapeLength * (shapeE - 1)
  3236. });
  3237. }
  3238. var newShapesData = this.addShapes(shapeData,segments[0]);
  3239. if (segments[0].s !== segments[0].e) {
  3240. if (segments.length > 1) {
  3241. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  3242. if (lastShapeInCollection.c) {
  3243. var lastShape = newShapesData.pop();
  3244. this.addPaths(newShapesData, localShapeCollection);
  3245. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  3246. } else {
  3247. this.addPaths(newShapesData, localShapeCollection);
  3248. newShapesData = this.addShapes(shapeData, segments[1]);
  3249. }
  3250. }
  3251. this.addPaths(newShapesData, localShapeCollection);
  3252. }
  3253. }
  3254. shapeData.shape.paths = localShapeCollection;
  3255. }
  3256. }
  3257. } else if (this._mdf) {
  3258. for (i = 0; i < len; i += 1) {
  3259. //Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  3260. //Don't remove this even if it's losing cached info.
  3261. this.shapes[i].pathsData.length = 0;
  3262. this.shapes[i].shape._mdf = true;
  3263. }
  3264. }
  3265. };
  3266. TrimModifier.prototype.addPaths = function(newPaths, localShapeCollection) {
  3267. var i, len = newPaths.length;
  3268. for (i = 0; i < len; i += 1) {
  3269. localShapeCollection.addShape(newPaths[i]);
  3270. }
  3271. };
  3272. TrimModifier.prototype.addSegment = function(pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  3273. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  3274. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  3275. if(newShape){
  3276. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  3277. }
  3278. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  3279. };
  3280. TrimModifier.prototype.addSegmentFromArray = function(points, shapePath, pos, newShape) {
  3281. shapePath.setXYAt(points[1], points[5], 'o', pos);
  3282. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  3283. if(newShape){
  3284. shapePath.setXYAt(points[0], points[4], 'v', pos);
  3285. }
  3286. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  3287. };
  3288. TrimModifier.prototype.addShapes = function(shapeData, shapeSegment, shapePath) {
  3289. var pathsData = shapeData.pathsData;
  3290. var shapePaths = shapeData.shape.paths.shapes;
  3291. var i, len = shapeData.shape.paths._length, j, jLen;
  3292. var addedLength = 0;
  3293. var currentLengthData,segmentCount;
  3294. var lengths;
  3295. var segment;
  3296. var shapes = [];
  3297. var initPos;
  3298. var newShape = true;
  3299. if (!shapePath) {
  3300. shapePath = shape_pool.newElement();
  3301. segmentCount = 0;
  3302. initPos = 0;
  3303. } else {
  3304. segmentCount = shapePath._length;
  3305. initPos = shapePath._length;
  3306. }
  3307. shapes.push(shapePath);
  3308. for (i = 0; i < len; i += 1) {
  3309. lengths = pathsData[i].lengths;
  3310. shapePath.c = shapePaths[i].c;
  3311. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  3312. for (j = 1; j < jLen; j +=1) {
  3313. currentLengthData = lengths[j-1];
  3314. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  3315. addedLength += currentLengthData.addedLength;
  3316. shapePath.c = false;
  3317. } else if(addedLength > shapeSegment.e) {
  3318. shapePath.c = false;
  3319. break;
  3320. } else {
  3321. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  3322. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  3323. newShape = false;
  3324. } else {
  3325. 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]);
  3326. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  3327. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  3328. newShape = false;
  3329. shapePath.c = false;
  3330. }
  3331. addedLength += currentLengthData.addedLength;
  3332. segmentCount += 1;
  3333. }
  3334. }
  3335. if (shapePaths[i].c && lengths.length) {
  3336. currentLengthData = lengths[j - 1];
  3337. if (addedLength <= shapeSegment.e) {
  3338. var segmentLength = lengths[j - 1].addedLength;
  3339. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  3340. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  3341. newShape = false;
  3342. } else {
  3343. 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]);
  3344. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  3345. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  3346. newShape = false;
  3347. shapePath.c = false;
  3348. }
  3349. } else {
  3350. shapePath.c = false;
  3351. }
  3352. addedLength += currentLengthData.addedLength;
  3353. segmentCount += 1;
  3354. }
  3355. if (shapePath._length) {
  3356. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  3357. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1],'o', shapePath._length - 1);
  3358. }
  3359. if (addedLength > shapeSegment.e) {
  3360. break;
  3361. }
  3362. if (i < len - 1) {
  3363. shapePath = shape_pool.newElement();
  3364. newShape = true;
  3365. shapes.push(shapePath);
  3366. segmentCount = 0;
  3367. }
  3368. }
  3369. return shapes;
  3370. };
  3371. ShapeModifiers.registerModifier('tm', TrimModifier);
  3372. function RoundCornersModifier(){}
  3373. extendPrototype([ShapeModifier],RoundCornersModifier);
  3374. RoundCornersModifier.prototype.initModifierProperties = function(elem,data){
  3375. this.getValue = this.processKeys;
  3376. this.rd = PropertyFactory.getProp(elem,data.r,0,null,this);
  3377. this._isAnimated = !!this.rd.effectsSequence.length;
  3378. };
  3379. RoundCornersModifier.prototype.processPath = function(path, round){
  3380. var cloned_path = shape_pool.newElement();
  3381. cloned_path.c = path.c;
  3382. var i, len = path._length;
  3383. var currentV,currentI,currentO,closerV, newV,newO,newI,distance,newPosPerc,index = 0;
  3384. var vX,vY,oX,oY,iX,iY;
  3385. for(i=0;i<len;i+=1){
  3386. currentV = path.v[i];
  3387. currentO = path.o[i];
  3388. currentI = path.i[i];
  3389. if(currentV[0]===currentO[0] && currentV[1]===currentO[1] && currentV[0]===currentI[0] && currentV[1]===currentI[1]){
  3390. if((i===0 || i === len - 1) && !path.c){
  3391. cloned_path.setTripleAt(currentV[0],currentV[1],currentO[0],currentO[1],currentI[0],currentI[1],index);
  3392. /*cloned_path.v[index] = currentV;
  3393. cloned_path.o[index] = currentO;
  3394. cloned_path.i[index] = currentI;*/
  3395. index += 1;
  3396. } else {
  3397. if(i===0){
  3398. closerV = path.v[len-1];
  3399. } else {
  3400. closerV = path.v[i-1];
  3401. }
  3402. distance = Math.sqrt(Math.pow(currentV[0]-closerV[0],2)+Math.pow(currentV[1]-closerV[1],2));
  3403. newPosPerc = distance ? Math.min(distance/2,round)/distance : 0;
  3404. vX = iX = currentV[0]+(closerV[0]-currentV[0])*newPosPerc;
  3405. vY = iY = currentV[1]-(currentV[1]-closerV[1])*newPosPerc;
  3406. oX = vX-(vX-currentV[0])*roundCorner;
  3407. oY = vY-(vY-currentV[1])*roundCorner;
  3408. cloned_path.setTripleAt(vX,vY,oX,oY,iX,iY,index);
  3409. index += 1;
  3410. if(i === len - 1){
  3411. closerV = path.v[0];
  3412. } else {
  3413. closerV = path.v[i+1];
  3414. }
  3415. distance = Math.sqrt(Math.pow(currentV[0]-closerV[0],2)+Math.pow(currentV[1]-closerV[1],2));
  3416. newPosPerc = distance ? Math.min(distance/2,round)/distance : 0;
  3417. vX = oX = currentV[0]+(closerV[0]-currentV[0])*newPosPerc;
  3418. vY = oY = currentV[1]+(closerV[1]-currentV[1])*newPosPerc;
  3419. iX = vX-(vX-currentV[0])*roundCorner;
  3420. iY = vY-(vY-currentV[1])*roundCorner;
  3421. cloned_path.setTripleAt(vX,vY,oX,oY,iX,iY,index);
  3422. index += 1;
  3423. }
  3424. } else {
  3425. cloned_path.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);
  3426. index += 1;
  3427. }
  3428. }
  3429. return cloned_path;
  3430. };
  3431. RoundCornersModifier.prototype.processShapes = function(_isFirstFrame){
  3432. var shapePaths;
  3433. var i, len = this.shapes.length;
  3434. var j, jLen;
  3435. var rd = this.rd.v;
  3436. if(rd !== 0){
  3437. var shapeData, newPaths, localShapeCollection;
  3438. for(i=0;i<len;i+=1){
  3439. shapeData = this.shapes[i];
  3440. newPaths = shapeData.shape.paths;
  3441. localShapeCollection = shapeData.localShapeCollection;
  3442. if(!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)){
  3443. localShapeCollection.releaseShapes();
  3444. shapeData.shape._mdf = true;
  3445. shapePaths = shapeData.shape.paths.shapes;
  3446. jLen = shapeData.shape.paths._length;
  3447. for(j=0;j<jLen;j+=1){
  3448. localShapeCollection.addShape(this.processPath(shapePaths[j],rd));
  3449. }
  3450. }
  3451. shapeData.shape.paths = shapeData.localShapeCollection;
  3452. }
  3453. }
  3454. if(!this.dynamicProperties.length){
  3455. this._mdf = false;
  3456. }
  3457. };
  3458. ShapeModifiers.registerModifier('rd',RoundCornersModifier);
  3459. function RepeaterModifier(){}
  3460. extendPrototype([ShapeModifier], RepeaterModifier);
  3461. RepeaterModifier.prototype.initModifierProperties = function(elem,data){
  3462. this.getValue = this.processKeys;
  3463. this.c = PropertyFactory.getProp(elem,data.c,0,null,this);
  3464. this.o = PropertyFactory.getProp(elem,data.o,0,null,this);
  3465. this.tr = TransformPropertyFactory.getTransformProperty(elem,data.tr,this);
  3466. this.so = PropertyFactory.getProp(elem,data.tr.so,0,0.01,this);
  3467. this.eo = PropertyFactory.getProp(elem,data.tr.eo,0,0.01,this);
  3468. this.data = data;
  3469. if(!this.dynamicProperties.length){
  3470. this.getValue(true);
  3471. }
  3472. this._isAnimated = !!this.dynamicProperties.length;
  3473. this.pMatrix = new Matrix();
  3474. this.rMatrix = new Matrix();
  3475. this.sMatrix = new Matrix();
  3476. this.tMatrix = new Matrix();
  3477. this.matrix = new Matrix();
  3478. };
  3479. RepeaterModifier.prototype.applyTransforms = function(pMatrix, rMatrix, sMatrix, transform, perc, inv){
  3480. var dir = inv ? -1 : 1;
  3481. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  3482. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  3483. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  3484. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  3485. rMatrix.rotate(-transform.r.v * dir * perc);
  3486. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  3487. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  3488. sMatrix.scale(inv ? 1/scaleX : scaleX, inv ? 1/scaleY : scaleY);
  3489. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  3490. };
  3491. RepeaterModifier.prototype.init = function(elem, arr, pos, elemsData) {
  3492. this.elem = elem;
  3493. this.arr = arr;
  3494. this.pos = pos;
  3495. this.elemsData = elemsData;
  3496. this._currentCopies = 0;
  3497. this._elements = [];
  3498. this._groups = [];
  3499. this.frameId = -1;
  3500. this.initDynamicPropertyContainer(elem);
  3501. this.initModifierProperties(elem,arr[pos]);
  3502. var cont = 0;
  3503. while(pos>0){
  3504. pos -= 1;
  3505. //this._elements.unshift(arr.splice(pos,1)[0]);
  3506. this._elements.unshift(arr[pos]);
  3507. cont += 1;
  3508. }
  3509. if(this.dynamicProperties.length){
  3510. this.k = true;
  3511. }else{
  3512. this.getValue(true);
  3513. }
  3514. };
  3515. RepeaterModifier.prototype.resetElements = function(elements){
  3516. var i, len = elements.length;
  3517. for(i = 0; i < len; i += 1) {
  3518. elements[i]._processed = false;
  3519. if(elements[i].ty === 'gr'){
  3520. this.resetElements(elements[i].it);
  3521. }
  3522. }
  3523. };
  3524. RepeaterModifier.prototype.cloneElements = function(elements){
  3525. var i, len = elements.length;
  3526. var newElements = JSON.parse(JSON.stringify(elements));
  3527. this.resetElements(newElements);
  3528. return newElements;
  3529. };
  3530. RepeaterModifier.prototype.changeGroupRender = function(elements, renderFlag) {
  3531. var i, len = elements.length;
  3532. for(i = 0; i < len; i += 1) {
  3533. elements[i]._render = renderFlag;
  3534. if(elements[i].ty === 'gr') {
  3535. this.changeGroupRender(elements[i].it, renderFlag);
  3536. }
  3537. }
  3538. };
  3539. RepeaterModifier.prototype.processShapes = function(_isFirstFrame) {
  3540. var items, itemsTransform, i, dir, cont;
  3541. if(this._mdf || _isFirstFrame){
  3542. var copies = Math.ceil(this.c.v);
  3543. if(this._groups.length < copies){
  3544. while(this._groups.length < copies){
  3545. var group = {
  3546. it:this.cloneElements(this._elements),
  3547. ty:'gr'
  3548. };
  3549. group.it.push({"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"});
  3550. this.arr.splice(0,0,group);
  3551. this._groups.splice(0,0,group);
  3552. this._currentCopies += 1;
  3553. }
  3554. this.elem.reloadShapes();
  3555. }
  3556. cont = 0;
  3557. var renderFlag;
  3558. for(i = 0; i <= this._groups.length - 1; i += 1){
  3559. renderFlag = cont < copies;
  3560. this._groups[i]._render = renderFlag;
  3561. this.changeGroupRender(this._groups[i].it, renderFlag);
  3562. cont += 1;
  3563. }
  3564. this._currentCopies = copies;
  3565. ////
  3566. var offset = this.o.v;
  3567. var offsetModulo = offset%1;
  3568. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  3569. var k;
  3570. var tMat = this.tr.v.props;
  3571. var pProps = this.pMatrix.props;
  3572. var rProps = this.rMatrix.props;
  3573. var sProps = this.sMatrix.props;
  3574. this.pMatrix.reset();
  3575. this.rMatrix.reset();
  3576. this.sMatrix.reset();
  3577. this.tMatrix.reset();
  3578. this.matrix.reset();
  3579. var iteration = 0;
  3580. if(offset > 0) {
  3581. while(iteration<roundOffset){
  3582. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  3583. iteration += 1;
  3584. }
  3585. if(offsetModulo){
  3586. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  3587. iteration += offsetModulo;
  3588. }
  3589. } else if(offset < 0) {
  3590. while(iteration>roundOffset){
  3591. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  3592. iteration -= 1;
  3593. }
  3594. if(offsetModulo){
  3595. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, - offsetModulo, true);
  3596. iteration -= offsetModulo;
  3597. }
  3598. }
  3599. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  3600. dir = this.data.m === 1 ? 1 : -1;
  3601. cont = this._currentCopies;
  3602. var j, jLen;
  3603. while(cont){
  3604. items = this.elemsData[i].it;
  3605. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  3606. jLen = itemsTransform.length;
  3607. items[items.length - 1].transform.mProps._mdf = true;
  3608. items[items.length - 1].transform.op._mdf = true;
  3609. items[items.length - 1].transform.op.v = this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  3610. if(iteration !== 0){
  3611. if((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)){
  3612. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  3613. }
  3614. 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]);
  3615. 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]);
  3616. 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]);
  3617. for(j=0;j<jLen;j+=1) {
  3618. itemsTransform[j] = this.matrix.props[j];
  3619. }
  3620. this.matrix.reset();
  3621. } else {
  3622. this.matrix.reset();
  3623. for(j=0;j<jLen;j+=1) {
  3624. itemsTransform[j] = this.matrix.props[j];
  3625. }
  3626. }
  3627. iteration += 1;
  3628. cont -= 1;
  3629. i += dir;
  3630. }
  3631. } else {
  3632. cont = this._currentCopies;
  3633. i = 0;
  3634. dir = 1;
  3635. while(cont){
  3636. items = this.elemsData[i].it;
  3637. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  3638. items[items.length - 1].transform.mProps._mdf = false;
  3639. items[items.length - 1].transform.op._mdf = false;
  3640. cont -= 1;
  3641. i += dir;
  3642. }
  3643. }
  3644. };
  3645. RepeaterModifier.prototype.addShape = function(){};
  3646. ShapeModifiers.registerModifier('rp',RepeaterModifier);
  3647. function ShapeCollection(){
  3648. this._length = 0;
  3649. this._maxLength = 4;
  3650. this.shapes = createSizedArray(this._maxLength);
  3651. }
  3652. ShapeCollection.prototype.addShape = function(shapeData){
  3653. if(this._length === this._maxLength){
  3654. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3655. this._maxLength *= 2;
  3656. }
  3657. this.shapes[this._length] = shapeData;
  3658. this._length += 1;
  3659. };
  3660. ShapeCollection.prototype.releaseShapes = function(){
  3661. var i;
  3662. for(i = 0; i < this._length; i += 1) {
  3663. shape_pool.release(this.shapes[i]);
  3664. }
  3665. this._length = 0;
  3666. };
  3667. function DashProperty(elem, data, renderer, container) {
  3668. this.elem = elem;
  3669. this.frameId = -1;
  3670. this.dataProps = createSizedArray(data.length);
  3671. this.renderer = renderer;
  3672. this.k = false;
  3673. this.dashStr = '';
  3674. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  3675. this.dashoffset = createTypedArray('float32', 1);
  3676. this.initDynamicPropertyContainer(container);
  3677. var i, len = data.length || 0, prop;
  3678. for(i = 0; i < len; i += 1) {
  3679. prop = PropertyFactory.getProp(elem,data[i].v,0, 0, this);
  3680. this.k = prop.k || this.k;
  3681. this.dataProps[i] = {n:data[i].n,p:prop};
  3682. }
  3683. if(!this.k){
  3684. this.getValue(true);
  3685. }
  3686. this._isAnimated = this.k;
  3687. }
  3688. DashProperty.prototype.getValue = function(forceRender) {
  3689. if(this.elem.globalData.frameId === this.frameId && !forceRender){
  3690. return;
  3691. }
  3692. this.frameId = this.elem.globalData.frameId;
  3693. this.iterateDynamicProperties();
  3694. this._mdf = this._mdf || forceRender;
  3695. if (this._mdf) {
  3696. var i = 0, len = this.dataProps.length;
  3697. if(this.renderer === 'svg') {
  3698. this.dashStr = '';
  3699. }
  3700. for(i=0;i<len;i+=1){
  3701. if(this.dataProps[i].n != 'o'){
  3702. if(this.renderer === 'svg') {
  3703. this.dashStr += ' ' + this.dataProps[i].p.v;
  3704. }else{
  3705. this.dashArray[i] = this.dataProps[i].p.v;
  3706. }
  3707. }else{
  3708. this.dashoffset[0] = this.dataProps[i].p.v;
  3709. }
  3710. }
  3711. }
  3712. };
  3713. extendPrototype([DynamicPropertyContainer], DashProperty);
  3714. function GradientProperty(elem,data,container){
  3715. this.data = data;
  3716. this.c = createTypedArray('uint8c', data.p*4);
  3717. var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p*4) : data.k.k.length - data.p*4;
  3718. this.o = createTypedArray('float32', cLength);
  3719. this._cmdf = false;
  3720. this._omdf = false;
  3721. this._collapsable = this.checkCollapsable();
  3722. this._hasOpacity = cLength;
  3723. this.initDynamicPropertyContainer(container);
  3724. this.prop = PropertyFactory.getProp(elem,data.k,1,null,this);
  3725. this.k = this.prop.k;
  3726. this.getValue(true);
  3727. }
  3728. GradientProperty.prototype.comparePoints = function(values, points) {
  3729. var i = 0, len = this.o.length/2, diff;
  3730. while(i < len) {
  3731. diff = Math.abs(values[i*4] - values[points*4 + i*2]);
  3732. if(diff > 0.01){
  3733. return false;
  3734. }
  3735. i += 1;
  3736. }
  3737. return true;
  3738. };
  3739. GradientProperty.prototype.checkCollapsable = function() {
  3740. if (this.o.length/2 !== this.c.length/4) {
  3741. return false;
  3742. }
  3743. if (this.data.k.k[0].s) {
  3744. var i = 0, len = this.data.k.k.length;
  3745. while (i < len) {
  3746. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  3747. return false;
  3748. }
  3749. i += 1;
  3750. }
  3751. } else if(!this.comparePoints(this.data.k.k, this.data.p)) {
  3752. return false;
  3753. }
  3754. return true;
  3755. };
  3756. GradientProperty.prototype.getValue = function(forceRender){
  3757. this.prop.getValue();
  3758. this._mdf = false;
  3759. this._cmdf = false;
  3760. this._omdf = false;
  3761. if(this.prop._mdf || forceRender){
  3762. var i, len = this.data.p*4;
  3763. var mult, val;
  3764. for(i=0;i<len;i+=1){
  3765. mult = i%4 === 0 ? 100 : 255;
  3766. val = Math.round(this.prop.v[i]*mult);
  3767. if(this.c[i] !== val){
  3768. this.c[i] = val;
  3769. this._cmdf = !forceRender;
  3770. }
  3771. }
  3772. if(this.o.length){
  3773. len = this.prop.v.length;
  3774. for(i=this.data.p*4;i<len;i+=1){
  3775. mult = i%2 === 0 ? 100 : 1;
  3776. val = i%2 === 0 ? Math.round(this.prop.v[i]*100):this.prop.v[i];
  3777. if(this.o[i-this.data.p*4] !== val){
  3778. this.o[i-this.data.p*4] = val;
  3779. this._omdf = !forceRender;
  3780. }
  3781. }
  3782. }
  3783. this._mdf = !forceRender;
  3784. }
  3785. };
  3786. extendPrototype([DynamicPropertyContainer], GradientProperty);
  3787. var buildShapeString = function(pathNodes, length, closed, mat) {
  3788. if(length === 0) {
  3789. return '';
  3790. }
  3791. var _o = pathNodes.o;
  3792. var _i = pathNodes.i;
  3793. var _v = pathNodes.v;
  3794. var i, shapeString = " M" + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  3795. for(i = 1; i < length; i += 1) {
  3796. 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]);
  3797. }
  3798. if (closed && length) {
  3799. 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]);
  3800. shapeString += 'z';
  3801. }
  3802. return shapeString;
  3803. }
  3804. var ImagePreloader = function() {};
  3805. var featureSupport = (function(){
  3806. var ob = {
  3807. maskType: true
  3808. };
  3809. 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)) {
  3810. ob.maskType = false;
  3811. }
  3812. return ob;
  3813. }());
  3814. var filtersFactory = (function(){
  3815. var ob = {};
  3816. ob.createFilter = createFilter;
  3817. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  3818. function createFilter(filId){
  3819. var fil = createNS('filter');
  3820. fil.setAttribute('id',filId);
  3821. fil.setAttribute('filterUnits','objectBoundingBox');
  3822. fil.setAttribute('x','0%');
  3823. fil.setAttribute('y','0%');
  3824. fil.setAttribute('width','100%');
  3825. fil.setAttribute('height','100%');
  3826. return fil;
  3827. }
  3828. function createAlphaToLuminanceFilter(){
  3829. var feColorMatrix = createNS('feColorMatrix');
  3830. feColorMatrix.setAttribute('type','matrix');
  3831. feColorMatrix.setAttribute('color-interpolation-filters','sRGB');
  3832. feColorMatrix.setAttribute('values','0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  3833. return feColorMatrix;
  3834. }
  3835. return ob;
  3836. }());
  3837. var assetLoader = (function(){
  3838. function formatResponse(xhr) {
  3839. if(xhr.response && typeof xhr.response === 'object') {
  3840. return xhr.response;
  3841. } else if(xhr.response && typeof xhr.response === 'string') {
  3842. return JSON.parse(xhr.response);
  3843. } else if(xhr.responseText) {
  3844. return JSON.parse(xhr.responseText);
  3845. }
  3846. }
  3847. function loadAsset(path, callback, errorCallback) {
  3848. var response;
  3849. var xhr = new XMLHttpRequest();
  3850. xhr.open('GET', path, true);
  3851. // set responseType after calling open or IE will break.
  3852. try {
  3853. // This crashes on Android WebView prior to KitKat
  3854. xhr.responseType = "json";
  3855. } catch (err) {}
  3856. xhr.send();
  3857. xhr.onreadystatechange = function () {
  3858. if (xhr.readyState == 4) {
  3859. if(xhr.status == 200){
  3860. response = formatResponse(xhr);
  3861. callback(response);
  3862. }else{
  3863. try{
  3864. response = formatResponse(xhr);
  3865. callback(response);
  3866. }catch(err){
  3867. if(errorCallback) {
  3868. errorCallback(err);
  3869. }
  3870. }
  3871. }
  3872. }
  3873. };
  3874. }
  3875. return {
  3876. load: loadAsset
  3877. }
  3878. }())
  3879. var assetLoader = null;
  3880. function TextAnimatorProperty(textData, renderType, elem){
  3881. this._isFirstFrame = true;
  3882. this._hasMaskedPath = false;
  3883. this._frameId = -1;
  3884. this._textData = textData;
  3885. this._renderType = renderType;
  3886. this._elem = elem;
  3887. this._animatorsData = createSizedArray(this._textData.a.length);
  3888. this._pathData = {};
  3889. this._moreOptions = {
  3890. alignment: {}
  3891. };
  3892. this.renderedLetters = [];
  3893. this.lettersChangedFlag = false;
  3894. this.initDynamicPropertyContainer(elem);
  3895. }
  3896. TextAnimatorProperty.prototype.searchProperties = function(){
  3897. var i, len = this._textData.a.length, animatorProps;
  3898. var getProp = PropertyFactory.getProp;
  3899. for(i=0;i<len;i+=1){
  3900. animatorProps = this._textData.a[i];
  3901. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  3902. }
  3903. if(this._textData.p && 'm' in this._textData.p){
  3904. this._pathData = {
  3905. f: getProp(this._elem,this._textData.p.f,0,0,this),
  3906. l: getProp(this._elem,this._textData.p.l,0,0,this),
  3907. r: this._textData.p.r,
  3908. m: this._elem.maskManager.getMaskProperty(this._textData.p.m)
  3909. };
  3910. this._hasMaskedPath = true;
  3911. } else {
  3912. this._hasMaskedPath = false;
  3913. }
  3914. this._moreOptions.alignment = getProp(this._elem,this._textData.m.a,1,0,this);
  3915. };
  3916. TextAnimatorProperty.prototype.getMeasures = function(documentData, lettersChangedFlag){
  3917. this.lettersChangedFlag = lettersChangedFlag;
  3918. if(!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  3919. return;
  3920. }
  3921. this._isFirstFrame = false;
  3922. var alignment = this._moreOptions.alignment.v;
  3923. var animators = this._animatorsData;
  3924. var textData = this._textData;
  3925. var matrixHelper = this.mHelper;
  3926. var renderType = this._renderType;
  3927. var renderedLettersCount = this.renderedLetters.length;
  3928. var data = this.data;
  3929. var xPos,yPos;
  3930. var i, len;
  3931. var letters = documentData.l, pathInfo, currentLength, currentPoint, segmentLength, flag, pointInd, segmentInd, prevPoint, points, segments, partialLength, totalLength, perc, tanAngle, mask;
  3932. if(this._hasMaskedPath) {
  3933. mask = this._pathData.m;
  3934. if(!this._pathData.n || this._pathData._mdf){
  3935. var paths = mask.v;
  3936. if(this._pathData.r){
  3937. paths = paths.reverse();
  3938. }
  3939. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  3940. pathInfo = {
  3941. tLength: 0,
  3942. segments: []
  3943. };
  3944. len = paths._length - 1;
  3945. var bezierData;
  3946. totalLength = 0;
  3947. for (i = 0; i < len; i += 1) {
  3948. bezierData = bez.buildBezierData(paths.v[i]
  3949. , paths.v[i + 1]
  3950. , [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]]
  3951. , [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  3952. pathInfo.tLength += bezierData.segmentLength;
  3953. pathInfo.segments.push(bezierData);
  3954. totalLength += bezierData.segmentLength;
  3955. }
  3956. i = len;
  3957. if (mask.v.c) {
  3958. bezierData = bez.buildBezierData(paths.v[i]
  3959. , paths.v[0]
  3960. , [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]]
  3961. , [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  3962. pathInfo.tLength += bezierData.segmentLength;
  3963. pathInfo.segments.push(bezierData);
  3964. totalLength += bezierData.segmentLength;
  3965. }
  3966. this._pathData.pi = pathInfo;
  3967. }
  3968. pathInfo = this._pathData.pi;
  3969. currentLength = this._pathData.f.v;
  3970. segmentInd = 0;
  3971. pointInd = 1;
  3972. segmentLength = 0;
  3973. flag = true;
  3974. segments = pathInfo.segments;
  3975. if (currentLength < 0 && mask.v.c) {
  3976. if (pathInfo.tLength < Math.abs(currentLength)) {
  3977. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  3978. }
  3979. segmentInd = segments.length - 1;
  3980. points = segments[segmentInd].points;
  3981. pointInd = points.length - 1;
  3982. while (currentLength < 0) {
  3983. currentLength += points[pointInd].partialLength;
  3984. pointInd -= 1;
  3985. if (pointInd < 0) {
  3986. segmentInd -= 1;
  3987. points = segments[segmentInd].points;
  3988. pointInd = points.length - 1;
  3989. }
  3990. }
  3991. }
  3992. points = segments[segmentInd].points;
  3993. prevPoint = points[pointInd - 1];
  3994. currentPoint = points[pointInd];
  3995. partialLength = currentPoint.partialLength;
  3996. }
  3997. len = letters.length;
  3998. xPos = 0;
  3999. yPos = 0;
  4000. var yOff = documentData.finalSize * 1.2 * 0.714;
  4001. var firstLine = true;
  4002. var animatorProps, animatorSelector;
  4003. var j, jLen;
  4004. var letterValue;
  4005. jLen = animators.length;
  4006. var lastLetter;
  4007. var mult, ind = -1, offf, xPathPos, yPathPos;
  4008. var initPathPos = currentLength,initSegmentInd = segmentInd, initPointInd = pointInd, currentLine = -1;
  4009. var elemOpacity;
  4010. var sc,sw,fc,k;
  4011. var lineLength = 0;
  4012. var letterSw, letterSc, letterFc, letterM = '', letterP = this.defaultPropsArray, letterO;
  4013. //
  4014. if(documentData.j === 2 || documentData.j === 1) {
  4015. var animatorJustifyOffset = 0;
  4016. var animatorFirstCharOffset = 0;
  4017. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  4018. var lastIndex = 0;
  4019. var isNewLine = true;
  4020. for (i = 0; i < len; i += 1) {
  4021. if (letters[i].n) {
  4022. if(animatorJustifyOffset) {
  4023. animatorJustifyOffset += animatorFirstCharOffset;
  4024. }
  4025. while (lastIndex < i) {
  4026. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  4027. lastIndex += 1;
  4028. }
  4029. animatorJustifyOffset = 0;
  4030. isNewLine = true;
  4031. } else {
  4032. for (j = 0; j < jLen; j += 1) {
  4033. animatorProps = animators[j].a;
  4034. if (animatorProps.t.propType) {
  4035. if (isNewLine && documentData.j === 2) {
  4036. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  4037. }
  4038. animatorSelector = animators[j].s;
  4039. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  4040. if (mult.length) {
  4041. animatorJustifyOffset += animatorProps.t.v*mult[0] * justifyOffsetMult;
  4042. } else {
  4043. animatorJustifyOffset += animatorProps.t.v*mult * justifyOffsetMult;
  4044. }
  4045. }
  4046. }
  4047. isNewLine = false;
  4048. }
  4049. }
  4050. if(animatorJustifyOffset) {
  4051. animatorJustifyOffset += animatorFirstCharOffset;
  4052. }
  4053. while(lastIndex < i) {
  4054. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  4055. lastIndex += 1;
  4056. }
  4057. }
  4058. //
  4059. for( i = 0; i < len; i += 1) {
  4060. matrixHelper.reset();
  4061. elemOpacity = 1;
  4062. if(letters[i].n) {
  4063. xPos = 0;
  4064. yPos += documentData.yOffset;
  4065. yPos += firstLine ? 1 : 0;
  4066. currentLength = initPathPos ;
  4067. firstLine = false;
  4068. lineLength = 0;
  4069. if(this._hasMaskedPath) {
  4070. segmentInd = initSegmentInd;
  4071. pointInd = initPointInd;
  4072. points = segments[segmentInd].points;
  4073. prevPoint = points[pointInd - 1];
  4074. currentPoint = points[pointInd];
  4075. partialLength = currentPoint.partialLength;
  4076. segmentLength = 0;
  4077. }
  4078. letterO = letterSw = letterFc = letterM = '';
  4079. letterP = this.defaultPropsArray;
  4080. }else{
  4081. if(this._hasMaskedPath) {
  4082. if(currentLine !== letters[i].line){
  4083. switch(documentData.j){
  4084. case 1:
  4085. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  4086. break;
  4087. case 2:
  4088. currentLength += (totalLength - documentData.lineWidths[letters[i].line])/2;
  4089. break;
  4090. }
  4091. currentLine = letters[i].line;
  4092. }
  4093. if (ind !== letters[i].ind) {
  4094. if (letters[ind]) {
  4095. currentLength += letters[ind].extra;
  4096. }
  4097. currentLength += letters[i].an / 2;
  4098. ind = letters[i].ind;
  4099. }
  4100. currentLength += alignment[0] * letters[i].an / 200;
  4101. var animatorOffset = 0;
  4102. for (j = 0; j < jLen; j += 1) {
  4103. animatorProps = animators[j].a;
  4104. if (animatorProps.p.propType) {
  4105. animatorSelector = animators[j].s;
  4106. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4107. if(mult.length){
  4108. animatorOffset += animatorProps.p.v[0] * mult[0];
  4109. } else{
  4110. animatorOffset += animatorProps.p.v[0] * mult;
  4111. }
  4112. }
  4113. if (animatorProps.a.propType) {
  4114. animatorSelector = animators[j].s;
  4115. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4116. if(mult.length){
  4117. animatorOffset += animatorProps.a.v[0] * mult[0];
  4118. } else{
  4119. animatorOffset += animatorProps.a.v[0] * mult;
  4120. }
  4121. }
  4122. }
  4123. flag = true;
  4124. while (flag) {
  4125. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  4126. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  4127. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  4128. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  4129. matrixHelper.translate(-alignment[0]*letters[i].an/200, -(alignment[1] * yOff / 100));
  4130. flag = false;
  4131. } else if (points) {
  4132. segmentLength += currentPoint.partialLength;
  4133. pointInd += 1;
  4134. if (pointInd >= points.length) {
  4135. pointInd = 0;
  4136. segmentInd += 1;
  4137. if (!segments[segmentInd]) {
  4138. if (mask.v.c) {
  4139. pointInd = 0;
  4140. segmentInd = 0;
  4141. points = segments[segmentInd].points;
  4142. } else {
  4143. segmentLength -= currentPoint.partialLength;
  4144. points = null;
  4145. }
  4146. } else {
  4147. points = segments[segmentInd].points;
  4148. }
  4149. }
  4150. if (points) {
  4151. prevPoint = currentPoint;
  4152. currentPoint = points[pointInd];
  4153. partialLength = currentPoint.partialLength;
  4154. }
  4155. }
  4156. }
  4157. offf = letters[i].an / 2 - letters[i].add;
  4158. matrixHelper.translate(-offf, 0, 0);
  4159. } else {
  4160. offf = letters[i].an/2 - letters[i].add;
  4161. matrixHelper.translate(-offf,0,0);
  4162. // Grouping alignment
  4163. matrixHelper.translate(-alignment[0]*letters[i].an/200, -alignment[1]*yOff/100, 0);
  4164. }
  4165. lineLength += letters[i].l/2;
  4166. for(j=0;j<jLen;j+=1){
  4167. animatorProps = animators[j].a;
  4168. if (animatorProps.t.propType) {
  4169. animatorSelector = animators[j].s;
  4170. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4171. //This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  4172. if(xPos !== 0 || documentData.j !== 0) {
  4173. if(this._hasMaskedPath) {
  4174. if(mult.length) {
  4175. currentLength += animatorProps.t.v*mult[0];
  4176. } else {
  4177. currentLength += animatorProps.t.v*mult;
  4178. }
  4179. }else{
  4180. if(mult.length) {
  4181. xPos += animatorProps.t.v*mult[0];
  4182. } else {
  4183. xPos += animatorProps.t.v*mult;
  4184. }
  4185. }
  4186. }
  4187. }
  4188. }
  4189. lineLength += letters[i].l/2;
  4190. if(documentData.strokeWidthAnim) {
  4191. sw = documentData.sw || 0;
  4192. }
  4193. if(documentData.strokeColorAnim) {
  4194. if(documentData.sc){
  4195. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  4196. }else{
  4197. sc = [0,0,0];
  4198. }
  4199. }
  4200. if(documentData.fillColorAnim && documentData.fc) {
  4201. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  4202. }
  4203. for(j=0;j<jLen;j+=1){
  4204. animatorProps = animators[j].a;
  4205. if (animatorProps.a.propType) {
  4206. animatorSelector = animators[j].s;
  4207. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4208. if(mult.length){
  4209. matrixHelper.translate(-animatorProps.a.v[0]*mult[0], -animatorProps.a.v[1]*mult[1], animatorProps.a.v[2]*mult[2]);
  4210. } else {
  4211. matrixHelper.translate(-animatorProps.a.v[0]*mult, -animatorProps.a.v[1]*mult, animatorProps.a.v[2]*mult);
  4212. }
  4213. }
  4214. }
  4215. for(j=0;j<jLen;j+=1){
  4216. animatorProps = animators[j].a;
  4217. if (animatorProps.s.propType) {
  4218. animatorSelector = animators[j].s;
  4219. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4220. if(mult.length){
  4221. matrixHelper.scale(1+((animatorProps.s.v[0]-1)*mult[0]),1+((animatorProps.s.v[1]-1)*mult[1]),1);
  4222. } else {
  4223. matrixHelper.scale(1+((animatorProps.s.v[0]-1)*mult),1+((animatorProps.s.v[1]-1)*mult),1);
  4224. }
  4225. }
  4226. }
  4227. for(j=0;j<jLen;j+=1) {
  4228. animatorProps = animators[j].a;
  4229. animatorSelector = animators[j].s;
  4230. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4231. if (animatorProps.sk.propType) {
  4232. if(mult.length) {
  4233. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  4234. } else {
  4235. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  4236. }
  4237. }
  4238. if (animatorProps.r.propType) {
  4239. if(mult.length) {
  4240. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  4241. } else {
  4242. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  4243. }
  4244. }
  4245. if (animatorProps.ry.propType) {
  4246. if(mult.length) {
  4247. matrixHelper.rotateY(animatorProps.ry.v*mult[1]);
  4248. }else{
  4249. matrixHelper.rotateY(animatorProps.ry.v*mult);
  4250. }
  4251. }
  4252. if (animatorProps.rx.propType) {
  4253. if(mult.length) {
  4254. matrixHelper.rotateX(animatorProps.rx.v*mult[0]);
  4255. } else {
  4256. matrixHelper.rotateX(animatorProps.rx.v*mult);
  4257. }
  4258. }
  4259. if (animatorProps.o.propType) {
  4260. if(mult.length) {
  4261. elemOpacity += ((animatorProps.o.v)*mult[0] - elemOpacity)*mult[0];
  4262. } else {
  4263. elemOpacity += ((animatorProps.o.v)*mult - elemOpacity)*mult;
  4264. }
  4265. }
  4266. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  4267. if(mult.length) {
  4268. sw += animatorProps.sw.v*mult[0];
  4269. } else {
  4270. sw += animatorProps.sw.v*mult;
  4271. }
  4272. }
  4273. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  4274. for(k=0;k<3;k+=1){
  4275. if(mult.length) {
  4276. sc[k] = sc[k] + (animatorProps.sc.v[k] - sc[k])*mult[0];
  4277. } else {
  4278. sc[k] = sc[k] + (animatorProps.sc.v[k] - sc[k])*mult;
  4279. }
  4280. }
  4281. }
  4282. if (documentData.fillColorAnim && documentData.fc) {
  4283. if(animatorProps.fc.propType){
  4284. for(k=0;k<3;k+=1){
  4285. if(mult.length) {
  4286. fc[k] = fc[k] + (animatorProps.fc.v[k] - fc[k])*mult[0];
  4287. } else {
  4288. fc[k] = fc[k] + (animatorProps.fc.v[k] - fc[k])*mult;
  4289. }
  4290. }
  4291. }
  4292. if(animatorProps.fh.propType){
  4293. if(mult.length) {
  4294. fc = addHueToRGB(fc,animatorProps.fh.v*mult[0]);
  4295. } else {
  4296. fc = addHueToRGB(fc,animatorProps.fh.v*mult);
  4297. }
  4298. }
  4299. if(animatorProps.fs.propType){
  4300. if(mult.length) {
  4301. fc = addSaturationToRGB(fc,animatorProps.fs.v*mult[0]);
  4302. } else {
  4303. fc = addSaturationToRGB(fc,animatorProps.fs.v*mult);
  4304. }
  4305. }
  4306. if(animatorProps.fb.propType){
  4307. if(mult.length) {
  4308. fc = addBrightnessToRGB(fc,animatorProps.fb.v*mult[0]);
  4309. } else {
  4310. fc = addBrightnessToRGB(fc,animatorProps.fb.v*mult);
  4311. }
  4312. }
  4313. }
  4314. }
  4315. for(j=0;j<jLen;j+=1){
  4316. animatorProps = animators[j].a;
  4317. if (animatorProps.p.propType) {
  4318. animatorSelector = animators[j].s;
  4319. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4320. if(this._hasMaskedPath) {
  4321. if(mult.length) {
  4322. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  4323. } else {
  4324. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  4325. }
  4326. }else{
  4327. if(mult.length) {
  4328. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  4329. } else {
  4330. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  4331. }
  4332. }
  4333. }
  4334. }
  4335. if(documentData.strokeWidthAnim){
  4336. letterSw = sw < 0 ? 0 : sw;
  4337. }
  4338. if(documentData.strokeColorAnim){
  4339. letterSc = 'rgb('+Math.round(sc[0]*255)+','+Math.round(sc[1]*255)+','+Math.round(sc[2]*255)+')';
  4340. }
  4341. if(documentData.fillColorAnim && documentData.fc){
  4342. letterFc = 'rgb('+Math.round(fc[0]*255)+','+Math.round(fc[1]*255)+','+Math.round(fc[2]*255)+')';
  4343. }
  4344. if(this._hasMaskedPath) {
  4345. matrixHelper.translate(0,-documentData.ls);
  4346. matrixHelper.translate(0, alignment[1]*yOff/100 + yPos,0);
  4347. if (textData.p.p) {
  4348. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  4349. var rot = Math.atan(tanAngle) * 180 / Math.PI;
  4350. if (currentPoint.point[0] < prevPoint.point[0]) {
  4351. rot += 180;
  4352. }
  4353. matrixHelper.rotate(-rot * Math.PI / 180);
  4354. }
  4355. matrixHelper.translate(xPathPos, yPathPos, 0);
  4356. currentLength -= alignment[0]*letters[i].an/200;
  4357. if(letters[i+1] && ind !== letters[i+1].ind){
  4358. currentLength += letters[i].an / 2;
  4359. currentLength += documentData.tr/1000*documentData.finalSize;
  4360. }
  4361. }else{
  4362. matrixHelper.translate(xPos,yPos,0);
  4363. if(documentData.ps){
  4364. //matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  4365. matrixHelper.translate(documentData.ps[0],documentData.ps[1] + documentData.ascent,0);
  4366. }
  4367. switch(documentData.j){
  4368. case 1:
  4369. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]),0,0);
  4370. break;
  4371. case 2:
  4372. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line])/2,0,0);
  4373. break;
  4374. }
  4375. matrixHelper.translate(0,-documentData.ls);
  4376. matrixHelper.translate(offf,0,0);
  4377. matrixHelper.translate(alignment[0]*letters[i].an/200,alignment[1]*yOff/100,0);
  4378. xPos += letters[i].l + documentData.tr/1000*documentData.finalSize;
  4379. }
  4380. if(renderType === 'html'){
  4381. letterM = matrixHelper.toCSS();
  4382. }else if(renderType === 'svg'){
  4383. letterM = matrixHelper.to2dCSS();
  4384. }else{
  4385. 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]];
  4386. }
  4387. letterO = elemOpacity;
  4388. }
  4389. if(renderedLettersCount <= i) {
  4390. letterValue = new LetterProps(letterO,letterSw,letterSc,letterFc,letterM,letterP);
  4391. this.renderedLetters.push(letterValue);
  4392. renderedLettersCount += 1;
  4393. this.lettersChangedFlag = true;
  4394. } else {
  4395. letterValue = this.renderedLetters[i];
  4396. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  4397. }
  4398. }
  4399. };
  4400. TextAnimatorProperty.prototype.getValue = function(){
  4401. if(this._elem.globalData.frameId === this._frameId){
  4402. return;
  4403. }
  4404. this._frameId = this._elem.globalData.frameId;
  4405. this.iterateDynamicProperties();
  4406. };
  4407. TextAnimatorProperty.prototype.mHelper = new Matrix();
  4408. TextAnimatorProperty.prototype.defaultPropsArray = [];
  4409. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  4410. function TextAnimatorDataProperty(elem, animatorProps, container) {
  4411. var defaultData = {propType:false};
  4412. var getProp = PropertyFactory.getProp;
  4413. var textAnimator_animatables = animatorProps.a;
  4414. this.a = {
  4415. r: textAnimator_animatables.r ? getProp(elem, textAnimator_animatables.r, 0, degToRads, container) : defaultData,
  4416. rx: textAnimator_animatables.rx ? getProp(elem, textAnimator_animatables.rx, 0, degToRads, container) : defaultData,
  4417. ry: textAnimator_animatables.ry ? getProp(elem, textAnimator_animatables.ry, 0, degToRads, container) : defaultData,
  4418. sk: textAnimator_animatables.sk ? getProp(elem, textAnimator_animatables.sk, 0, degToRads, container) : defaultData,
  4419. sa: textAnimator_animatables.sa ? getProp(elem, textAnimator_animatables.sa, 0, degToRads, container) : defaultData,
  4420. s: textAnimator_animatables.s ? getProp(elem, textAnimator_animatables.s, 1, 0.01, container) : defaultData,
  4421. a: textAnimator_animatables.a ? getProp(elem, textAnimator_animatables.a, 1, 0, container) : defaultData,
  4422. o: textAnimator_animatables.o ? getProp(elem, textAnimator_animatables.o, 0, 0.01, container) : defaultData,
  4423. p: textAnimator_animatables.p ? getProp(elem,textAnimator_animatables.p, 1, 0, container) : defaultData,
  4424. sw: textAnimator_animatables.sw ? getProp(elem, textAnimator_animatables.sw, 0, 0, container) : defaultData,
  4425. sc: textAnimator_animatables.sc ? getProp(elem, textAnimator_animatables.sc, 1, 0, container) : defaultData,
  4426. fc: textAnimator_animatables.fc ? getProp(elem, textAnimator_animatables.fc, 1, 0, container) : defaultData,
  4427. fh: textAnimator_animatables.fh ? getProp(elem, textAnimator_animatables.fh, 0, 0, container) : defaultData,
  4428. fs: textAnimator_animatables.fs ? getProp(elem, textAnimator_animatables.fs, 0, 0.01, container) : defaultData,
  4429. fb: textAnimator_animatables.fb ? getProp(elem, textAnimator_animatables.fb, 0, 0.01, container) : defaultData,
  4430. t: textAnimator_animatables.t ? getProp(elem, textAnimator_animatables.t, 0, 0, container) : defaultData
  4431. };
  4432. this.s = TextSelectorProp.getTextSelectorProp(elem,animatorProps.s, container);
  4433. this.s.t = animatorProps.s.t;
  4434. }
  4435. function LetterProps(o, sw, sc, fc, m, p){
  4436. this.o = o;
  4437. this.sw = sw;
  4438. this.sc = sc;
  4439. this.fc = fc;
  4440. this.m = m;
  4441. this.p = p;
  4442. this._mdf = {
  4443. o: true,
  4444. sw: !!sw,
  4445. sc: !!sc,
  4446. fc: !!fc,
  4447. m: true,
  4448. p: true
  4449. };
  4450. }
  4451. LetterProps.prototype.update = function(o, sw, sc, fc, m, p) {
  4452. this._mdf.o = false;
  4453. this._mdf.sw = false;
  4454. this._mdf.sc = false;
  4455. this._mdf.fc = false;
  4456. this._mdf.m = false;
  4457. this._mdf.p = false;
  4458. var updated = false;
  4459. if(this.o !== o) {
  4460. this.o = o;
  4461. this._mdf.o = true;
  4462. updated = true;
  4463. }
  4464. if(this.sw !== sw) {
  4465. this.sw = sw;
  4466. this._mdf.sw = true;
  4467. updated = true;
  4468. }
  4469. if(this.sc !== sc) {
  4470. this.sc = sc;
  4471. this._mdf.sc = true;
  4472. updated = true;
  4473. }
  4474. if(this.fc !== fc) {
  4475. this.fc = fc;
  4476. this._mdf.fc = true;
  4477. updated = true;
  4478. }
  4479. if(this.m !== m) {
  4480. this.m = m;
  4481. this._mdf.m = true;
  4482. updated = true;
  4483. }
  4484. 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])) {
  4485. this.p = p;
  4486. this._mdf.p = true;
  4487. updated = true;
  4488. }
  4489. return updated;
  4490. };
  4491. function TextProperty(elem, data){
  4492. this._frameId = initialDefaultFrame;
  4493. this.pv = '';
  4494. this.v = '';
  4495. this.kf = false;
  4496. this._isFirstFrame = true;
  4497. this._mdf = false;
  4498. this.data = data;
  4499. this.elem = elem;
  4500. this.comp = this.elem.comp;
  4501. this.keysIndex = 0;
  4502. this.canResize = false;
  4503. this.minimumFontSize = 1;
  4504. this.effectsSequence = [];
  4505. this.currentData = {
  4506. ascent: 0,
  4507. boxWidth: this.defaultBoxWidth,
  4508. f: '',
  4509. fStyle: '',
  4510. fWeight: '',
  4511. fc: '',
  4512. j: '',
  4513. justifyOffset: '',
  4514. l: [],
  4515. lh: 0,
  4516. lineWidths: [],
  4517. ls: '',
  4518. of: '',
  4519. s: '',
  4520. sc: '',
  4521. sw: 0,
  4522. t: 0,
  4523. tr: 0,
  4524. sz:0,
  4525. ps:null,
  4526. fillColorAnim: false,
  4527. strokeColorAnim: false,
  4528. strokeWidthAnim: false,
  4529. yOffset: 0,
  4530. finalSize:0,
  4531. finalText:[],
  4532. finalLineHeight: 0,
  4533. __complete: false
  4534. };
  4535. this.copyData(this.currentData, this.data.d.k[0].s);
  4536. if(!this.searchProperty()) {
  4537. this.completeTextData(this.currentData);
  4538. }
  4539. }
  4540. TextProperty.prototype.defaultBoxWidth = [0,0];
  4541. TextProperty.prototype.copyData = function(obj, data) {
  4542. for(var s in data) {
  4543. if(data.hasOwnProperty(s)) {
  4544. obj[s] = data[s];
  4545. }
  4546. }
  4547. return obj;
  4548. }
  4549. TextProperty.prototype.setCurrentData = function(data){
  4550. if(!data.__complete) {
  4551. this.completeTextData(data);
  4552. }
  4553. this.currentData = data;
  4554. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  4555. this._mdf = true;
  4556. };
  4557. TextProperty.prototype.searchProperty = function() {
  4558. return this.searchKeyframes();
  4559. };
  4560. TextProperty.prototype.searchKeyframes = function() {
  4561. this.kf = this.data.d.k.length > 1;
  4562. if(this.kf) {
  4563. this.addEffect(this.getKeyframeValue.bind(this));
  4564. }
  4565. return this.kf;
  4566. }
  4567. TextProperty.prototype.addEffect = function(effectFunction) {
  4568. this.effectsSequence.push(effectFunction);
  4569. this.elem.addDynamicProperty(this);
  4570. };
  4571. TextProperty.prototype.getValue = function(_finalValue) {
  4572. if((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  4573. return;
  4574. }
  4575. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  4576. var currentValue = this.currentData;
  4577. var currentIndex = this.keysIndex;
  4578. if(this.lock) {
  4579. this.setCurrentData(this.currentData);
  4580. return;
  4581. }
  4582. this.lock = true;
  4583. this._mdf = false;
  4584. var multipliedValue;
  4585. var i, len = this.effectsSequence.length;
  4586. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  4587. for(i = 0; i < len; i += 1) {
  4588. //Checking if index changed to prevent creating a new object every time the expression updates.
  4589. if(currentIndex !== this.keysIndex) {
  4590. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  4591. } else {
  4592. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  4593. }
  4594. }
  4595. if(currentValue !== finalValue) {
  4596. this.setCurrentData(finalValue);
  4597. }
  4598. this.pv = this.v = this.currentData;
  4599. this.lock = false;
  4600. this.frameId = this.elem.globalData.frameId;
  4601. }
  4602. TextProperty.prototype.getKeyframeValue = function() {
  4603. var textKeys = this.data.d.k, textDocumentData;
  4604. var frameNum = this.elem.comp.renderedFrame;
  4605. var i = 0, len = textKeys.length;
  4606. while(i <= len - 1) {
  4607. textDocumentData = textKeys[i].s;
  4608. if(i === len - 1 || textKeys[i+1].t > frameNum){
  4609. break;
  4610. }
  4611. i += 1;
  4612. }
  4613. if(this.keysIndex !== i) {
  4614. this.keysIndex = i;
  4615. }
  4616. return this.data.d.k[this.keysIndex].s;
  4617. };
  4618. TextProperty.prototype.buildFinalText = function(text) {
  4619. var combinedCharacters = FontManager.getCombinedCharacterCodes();
  4620. var charactersArray = [];
  4621. var i = 0, len = text.length;
  4622. while (i < len) {
  4623. if (combinedCharacters.indexOf(text.charCodeAt(i)) !== -1) {
  4624. charactersArray[charactersArray.length - 1] += text.charAt(i);
  4625. } else {
  4626. charactersArray.push(text.charAt(i));
  4627. }
  4628. i += 1;
  4629. }
  4630. return charactersArray;
  4631. }
  4632. TextProperty.prototype.completeTextData = function(documentData) {
  4633. documentData.__complete = true;
  4634. var fontManager = this.elem.globalData.fontManager;
  4635. var data = this.data;
  4636. var letters = [];
  4637. var i, len;
  4638. var newLineFlag, index = 0, val;
  4639. var anchorGrouping = data.m.g;
  4640. var currentSize = 0, currentPos = 0, currentLine = 0, lineWidths = [];
  4641. var lineWidth = 0;
  4642. var maxLineWidth = 0;
  4643. var j, jLen;
  4644. var fontData = fontManager.getFontByName(documentData.f);
  4645. var charData, cLength = 0;
  4646. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  4647. var fWeight = 'normal', fStyle = 'normal';
  4648. len = styles.length;
  4649. var styleName;
  4650. for(i=0;i<len;i+=1){
  4651. styleName = styles[i].toLowerCase();
  4652. switch(styleName) {
  4653. case 'italic':
  4654. fStyle = 'italic';
  4655. break;
  4656. case 'bold':
  4657. fWeight = '700';
  4658. break;
  4659. case 'black':
  4660. fWeight = '900';
  4661. break;
  4662. case 'medium':
  4663. fWeight = '500';
  4664. break;
  4665. case 'regular':
  4666. case 'normal':
  4667. fWeight = '400';
  4668. break;
  4669. case 'light':
  4670. case 'thin':
  4671. fWeight = '200';
  4672. break;
  4673. }
  4674. }
  4675. documentData.fWeight = fontData.fWeight || fWeight;
  4676. documentData.fStyle = fStyle;
  4677. len = documentData.t.length;
  4678. documentData.finalSize = documentData.s;
  4679. documentData.finalText = this.buildFinalText(documentData.t);
  4680. documentData.finalLineHeight = documentData.lh;
  4681. var trackingOffset = documentData.tr/1000*documentData.finalSize;
  4682. var charCode;
  4683. if(documentData.sz){
  4684. var flag = true;
  4685. var boxWidth = documentData.sz[0];
  4686. var boxHeight = documentData.sz[1];
  4687. var currentHeight, finalText;
  4688. while(flag) {
  4689. finalText = this.buildFinalText(documentData.t);
  4690. currentHeight = 0;
  4691. lineWidth = 0;
  4692. len = finalText.length;
  4693. trackingOffset = documentData.tr/1000*documentData.finalSize;
  4694. var lastSpaceIndex = -1;
  4695. for(i=0;i<len;i+=1){
  4696. charCode = finalText[i].charCodeAt(0);
  4697. newLineFlag = false;
  4698. if(finalText[i] === ' '){
  4699. lastSpaceIndex = i;
  4700. }else if(charCode === 13 || charCode === 3){
  4701. lineWidth = 0;
  4702. newLineFlag = true;
  4703. currentHeight += documentData.finalLineHeight || documentData.finalSize*1.2;
  4704. }
  4705. if(fontManager.chars){
  4706. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  4707. cLength = newLineFlag ? 0 : charData.w*documentData.finalSize/100;
  4708. }else{
  4709. //tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  4710. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  4711. }
  4712. if(lineWidth + cLength > boxWidth && finalText[i] !== ' '){
  4713. if(lastSpaceIndex === -1){
  4714. len += 1;
  4715. } else {
  4716. i = lastSpaceIndex;
  4717. }
  4718. currentHeight += documentData.finalLineHeight || documentData.finalSize*1.2;
  4719. finalText.splice(i, lastSpaceIndex === i ? 1 : 0,"\r");
  4720. //finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  4721. lastSpaceIndex = -1;
  4722. lineWidth = 0;
  4723. }else {
  4724. lineWidth += cLength;
  4725. lineWidth += trackingOffset;
  4726. }
  4727. }
  4728. currentHeight += fontData.ascent*documentData.finalSize/100;
  4729. if(this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  4730. documentData.finalSize -= 1;
  4731. documentData.finalLineHeight = documentData.finalSize * documentData.lh / documentData.s;
  4732. } else {
  4733. documentData.finalText = finalText;
  4734. len = documentData.finalText.length;
  4735. flag = false;
  4736. }
  4737. }
  4738. }
  4739. lineWidth = - trackingOffset;
  4740. cLength = 0;
  4741. var uncollapsedSpaces = 0;
  4742. var currentChar;
  4743. for (i = 0;i < len ;i += 1) {
  4744. newLineFlag = false;
  4745. currentChar = documentData.finalText[i];
  4746. charCode = currentChar.charCodeAt(0);
  4747. if (currentChar === ' '){
  4748. val = '\u00A0';
  4749. } else if (charCode === 13 || charCode === 3) {
  4750. uncollapsedSpaces = 0;
  4751. lineWidths.push(lineWidth);
  4752. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  4753. lineWidth = - 2 * trackingOffset;
  4754. val = '';
  4755. newLineFlag = true;
  4756. currentLine += 1;
  4757. }else{
  4758. val = documentData.finalText[i];
  4759. }
  4760. if(fontManager.chars){
  4761. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  4762. cLength = newLineFlag ? 0 : charData.w*documentData.finalSize/100;
  4763. }else{
  4764. //var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  4765. //tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  4766. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  4767. }
  4768. //
  4769. if(currentChar === ' '){
  4770. uncollapsedSpaces += cLength + trackingOffset;
  4771. } else {
  4772. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  4773. uncollapsedSpaces = 0;
  4774. }
  4775. letters.push({l:cLength,an:cLength,add:currentSize,n:newLineFlag, anIndexes:[], val: val, line: currentLine, animatorJustifyOffset: 0});
  4776. if(anchorGrouping == 2){
  4777. currentSize += cLength;
  4778. if(val === '' || val === '\u00A0' || i === len - 1){
  4779. if(val === '' || val === '\u00A0'){
  4780. currentSize -= cLength;
  4781. }
  4782. while(currentPos<=i){
  4783. letters[currentPos].an = currentSize;
  4784. letters[currentPos].ind = index;
  4785. letters[currentPos].extra = cLength;
  4786. currentPos += 1;
  4787. }
  4788. index += 1;
  4789. currentSize = 0;
  4790. }
  4791. }else if(anchorGrouping == 3){
  4792. currentSize += cLength;
  4793. if(val === '' || i === len - 1){
  4794. if(val === ''){
  4795. currentSize -= cLength;
  4796. }
  4797. while(currentPos<=i){
  4798. letters[currentPos].an = currentSize;
  4799. letters[currentPos].ind = index;
  4800. letters[currentPos].extra = cLength;
  4801. currentPos += 1;
  4802. }
  4803. currentSize = 0;
  4804. index += 1;
  4805. }
  4806. }else{
  4807. letters[index].ind = index;
  4808. letters[index].extra = 0;
  4809. index += 1;
  4810. }
  4811. }
  4812. documentData.l = letters;
  4813. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  4814. lineWidths.push(lineWidth);
  4815. if(documentData.sz){
  4816. documentData.boxWidth = documentData.sz[0];
  4817. documentData.justifyOffset = 0;
  4818. }else{
  4819. documentData.boxWidth = maxLineWidth;
  4820. switch(documentData.j){
  4821. case 1:
  4822. documentData.justifyOffset = - documentData.boxWidth;
  4823. break;
  4824. case 2:
  4825. documentData.justifyOffset = - documentData.boxWidth/2;
  4826. break;
  4827. default:
  4828. documentData.justifyOffset = 0;
  4829. }
  4830. }
  4831. documentData.lineWidths = lineWidths;
  4832. var animators = data.a, animatorData, letterData;
  4833. jLen = animators.length;
  4834. var based, ind, indexes = [];
  4835. for(j=0;j<jLen;j+=1){
  4836. animatorData = animators[j];
  4837. if(animatorData.a.sc){
  4838. documentData.strokeColorAnim = true;
  4839. }
  4840. if(animatorData.a.sw){
  4841. documentData.strokeWidthAnim = true;
  4842. }
  4843. if(animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb){
  4844. documentData.fillColorAnim = true;
  4845. }
  4846. ind = 0;
  4847. based = animatorData.s.b;
  4848. for(i=0;i<len;i+=1){
  4849. letterData = letters[i];
  4850. letterData.anIndexes[j] = ind;
  4851. if((based == 1 && letterData.val !== '') || (based == 2 && letterData.val !== '' && letterData.val !== '\u00A0') || (based == 3 && (letterData.n || letterData.val == '\u00A0' || i == len - 1)) || (based == 4 && (letterData.n || i == len - 1))){
  4852. if(animatorData.s.rn === 1){
  4853. indexes.push(ind);
  4854. }
  4855. ind += 1;
  4856. }
  4857. }
  4858. data.a[j].s.totalChars = ind;
  4859. var currentInd = -1, newInd;
  4860. if(animatorData.s.rn === 1){
  4861. for(i = 0; i < len; i += 1){
  4862. letterData = letters[i];
  4863. if(currentInd != letterData.anIndexes[j]){
  4864. currentInd = letterData.anIndexes[j];
  4865. newInd = indexes.splice(Math.floor(Math.random()*indexes.length),1)[0];
  4866. }
  4867. letterData.anIndexes[j] = newInd;
  4868. }
  4869. }
  4870. }
  4871. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize*1.2;
  4872. documentData.ls = documentData.ls || 0;
  4873. documentData.ascent = fontData.ascent*documentData.finalSize/100;
  4874. };
  4875. TextProperty.prototype.updateDocumentData = function(newData, index) {
  4876. index = index === undefined ? this.keysIndex : index;
  4877. var dData = this.copyData({}, this.data.d.k[index].s);
  4878. dData = this.copyData(dData, newData);
  4879. this.data.d.k[index].s = dData;
  4880. this.recalculate(index);
  4881. this.elem.addDynamicProperty(this);
  4882. };
  4883. TextProperty.prototype.recalculate = function(index) {
  4884. var dData = this.data.d.k[index].s;
  4885. dData.__complete = false;
  4886. this.keysIndex = 0;
  4887. this._isFirstFrame = true;
  4888. this.getValue(dData);
  4889. }
  4890. TextProperty.prototype.canResizeFont = function(_canResize) {
  4891. this.canResize = _canResize;
  4892. this.recalculate(this.keysIndex);
  4893. this.elem.addDynamicProperty(this);
  4894. };
  4895. TextProperty.prototype.setMinimumFontSize = function(_fontValue) {
  4896. this.minimumFontSize = Math.floor(_fontValue) || 1;
  4897. this.recalculate(this.keysIndex);
  4898. this.elem.addDynamicProperty(this);
  4899. };
  4900. var TextSelectorProp = (function(){
  4901. var max = Math.max;
  4902. var min = Math.min;
  4903. var floor = Math.floor;
  4904. function TextSelectorProp(elem,data){
  4905. this._currentTextLength = -1;
  4906. this.k = false;
  4907. this.data = data;
  4908. this.elem = elem;
  4909. this.comp = elem.comp;
  4910. this.finalS = 0;
  4911. this.finalE = 0;
  4912. this.initDynamicPropertyContainer(elem);
  4913. this.s = PropertyFactory.getProp(elem,data.s || {k:0},0,0,this);
  4914. if('e' in data){
  4915. this.e = PropertyFactory.getProp(elem,data.e,0,0,this);
  4916. }else{
  4917. this.e = {v:100};
  4918. }
  4919. this.o = PropertyFactory.getProp(elem,data.o || {k:0},0,0,this);
  4920. this.xe = PropertyFactory.getProp(elem,data.xe || {k:0},0,0,this);
  4921. this.ne = PropertyFactory.getProp(elem,data.ne || {k:0},0,0,this);
  4922. this.a = PropertyFactory.getProp(elem,data.a,0,0.01,this);
  4923. if(!this.dynamicProperties.length){
  4924. this.getValue();
  4925. }
  4926. }
  4927. TextSelectorProp.prototype = {
  4928. getMult: function(ind) {
  4929. if(this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  4930. this.getValue();
  4931. }
  4932. //var easer = bez.getEasingCurve(this.ne.v/100,0,1-this.xe.v/100,1);
  4933. var easer = BezierFactory.getBezierEasing(this.ne.v/100,0,1-this.xe.v/100,1).get;
  4934. var mult = 0;
  4935. var s = this.finalS;
  4936. var e = this.finalE;
  4937. var type = this.data.sh;
  4938. if(type == 2){
  4939. if(e === s){
  4940. mult = ind >= e ? 1 : 0;
  4941. }else{
  4942. mult = max(0,min(0.5/(e-s) + (ind-s)/(e-s),1));
  4943. }
  4944. mult = easer(mult);
  4945. }else if(type == 3){
  4946. if(e === s){
  4947. mult = ind >= e ? 0 : 1;
  4948. }else{
  4949. mult = 1 - max(0,min(0.5/(e-s) + (ind-s)/(e-s),1));
  4950. }
  4951. mult = easer(mult);
  4952. }else if(type == 4){
  4953. if(e === s){
  4954. mult = 0;
  4955. }else{
  4956. mult = max(0,min(0.5/(e-s) + (ind-s)/(e-s),1));
  4957. if(mult<0.5){
  4958. mult *= 2;
  4959. }else{
  4960. mult = 1 - 2*(mult-0.5);
  4961. }
  4962. }
  4963. mult = easer(mult);
  4964. }else if(type == 5){
  4965. if(e === s){
  4966. mult = 0;
  4967. }else{
  4968. var tot = e - s;
  4969. /*ind += 0.5;
  4970. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind;*/
  4971. ind = min(max(0,ind+0.5-s),e-s);
  4972. var x = -tot/2+ind;
  4973. var a = tot/2;
  4974. mult = Math.sqrt(1 - (x*x)/(a*a));
  4975. }
  4976. mult = easer(mult);
  4977. }else if(type == 6){
  4978. if(e === s){
  4979. mult = 0;
  4980. }else{
  4981. ind = min(max(0,ind+0.5-s),e-s);
  4982. mult = (1+(Math.cos((Math.PI+Math.PI*2*(ind)/(e-s)))))/2;
  4983. /*
  4984. ind = Math.min(Math.max(s,ind),e-1);
  4985. mult = (1+(Math.cos((Math.PI+Math.PI*2*(ind-s)/(e-1-s)))))/2;
  4986. mult = Math.max(mult,(1/(e-1-s))/(e-1-s));*/
  4987. }
  4988. mult = easer(mult);
  4989. }else {
  4990. if(ind >= floor(s)){
  4991. if(ind-s < 0){
  4992. mult = 1 - (s - ind);
  4993. }else{
  4994. mult = max(0,min(e-ind,1));
  4995. }
  4996. }
  4997. mult = easer(mult);
  4998. }
  4999. return mult*this.a.v;
  5000. },
  5001. getValue: function(newCharsFlag) {
  5002. this.iterateDynamicProperties();
  5003. this._mdf = newCharsFlag || this._mdf;
  5004. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  5005. if(newCharsFlag && this.data.r === 2) {
  5006. this.e.v = this._currentTextLength;
  5007. }
  5008. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  5009. var o = this.o.v/divisor;
  5010. var s = this.s.v/divisor + o;
  5011. var e = (this.e.v/divisor) + o;
  5012. if(s>e){
  5013. var _s = s;
  5014. s = e;
  5015. e = _s;
  5016. }
  5017. this.finalS = s;
  5018. this.finalE = e;
  5019. }
  5020. }
  5021. extendPrototype([DynamicPropertyContainer], TextSelectorProp);
  5022. function getTextSelectorProp(elem, data,arr) {
  5023. return new TextSelectorProp(elem, data, arr);
  5024. }
  5025. return {
  5026. getTextSelectorProp: getTextSelectorProp
  5027. };
  5028. }());
  5029. var pool_factory = (function() {
  5030. return function(initialLength, _create, _release, _clone) {
  5031. var _length = 0;
  5032. var _maxLength = initialLength;
  5033. var pool = createSizedArray(_maxLength);
  5034. var ob = {
  5035. newElement: newElement,
  5036. release: release
  5037. };
  5038. function newElement(){
  5039. var element;
  5040. if(_length){
  5041. _length -= 1;
  5042. element = pool[_length];
  5043. } else {
  5044. element = _create();
  5045. }
  5046. return element;
  5047. }
  5048. function release(element) {
  5049. if(_length === _maxLength) {
  5050. pool = pooling.double(pool);
  5051. _maxLength = _maxLength*2;
  5052. }
  5053. if (_release) {
  5054. _release(element);
  5055. }
  5056. pool[_length] = element;
  5057. _length += 1;
  5058. }
  5059. function clone() {
  5060. var clonedElement = newElement();
  5061. return _clone(clonedElement);
  5062. }
  5063. return ob;
  5064. };
  5065. }());
  5066. var pooling = (function(){
  5067. function double(arr){
  5068. return arr.concat(createSizedArray(arr.length));
  5069. }
  5070. return {
  5071. double: double
  5072. };
  5073. }());
  5074. var point_pool = (function(){
  5075. function create() {
  5076. return createTypedArray('float32', 2);
  5077. }
  5078. return pool_factory(8, create);
  5079. }());
  5080. var shape_pool = (function(){
  5081. function create() {
  5082. return new ShapePath();
  5083. }
  5084. function release(shapePath) {
  5085. var len = shapePath._length, i;
  5086. for(i = 0; i < len; i += 1) {
  5087. point_pool.release(shapePath.v[i]);
  5088. point_pool.release(shapePath.i[i]);
  5089. point_pool.release(shapePath.o[i]);
  5090. shapePath.v[i] = null;
  5091. shapePath.i[i] = null;
  5092. shapePath.o[i] = null;
  5093. }
  5094. shapePath._length = 0;
  5095. shapePath.c = false;
  5096. }
  5097. function clone(shape) {
  5098. var cloned = factory.newElement();
  5099. var i, len = shape._length === undefined ? shape.v.length : shape._length;
  5100. cloned.setLength(len);
  5101. cloned.c = shape.c;
  5102. var pt;
  5103. for(i = 0; i < len; i += 1) {
  5104. 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);
  5105. }
  5106. return cloned;
  5107. }
  5108. var factory = pool_factory(4, create, release);
  5109. factory.clone = clone;
  5110. return factory;
  5111. }());
  5112. var shapeCollection_pool = (function(){
  5113. var ob = {
  5114. newShapeCollection: newShapeCollection,
  5115. release: release
  5116. };
  5117. var _length = 0;
  5118. var _maxLength = 4;
  5119. var pool = createSizedArray(_maxLength);
  5120. function newShapeCollection(){
  5121. var shapeCollection;
  5122. if(_length){
  5123. _length -= 1;
  5124. shapeCollection = pool[_length];
  5125. } else {
  5126. shapeCollection = new ShapeCollection();
  5127. }
  5128. return shapeCollection;
  5129. }
  5130. function release(shapeCollection) {
  5131. var i, len = shapeCollection._length;
  5132. for(i = 0; i < len; i += 1) {
  5133. shape_pool.release(shapeCollection.shapes[i]);
  5134. }
  5135. shapeCollection._length = 0;
  5136. if(_length === _maxLength) {
  5137. pool = pooling.double(pool);
  5138. _maxLength = _maxLength*2;
  5139. }
  5140. pool[_length] = shapeCollection;
  5141. _length += 1;
  5142. }
  5143. return ob;
  5144. }());
  5145. var segments_length_pool = (function(){
  5146. function create() {
  5147. return {
  5148. lengths: [],
  5149. totalLength: 0
  5150. };
  5151. }
  5152. function release(element) {
  5153. var i, len = element.lengths.length;
  5154. for(i=0;i<len;i+=1) {
  5155. bezier_length_pool.release(element.lengths[i]);
  5156. }
  5157. element.lengths.length = 0;
  5158. }
  5159. return pool_factory(8, create, release);
  5160. }());
  5161. var bezier_length_pool = (function(){
  5162. function create() {
  5163. return {
  5164. addedLength: 0,
  5165. percents: createTypedArray('float32', defaultCurveSegments),
  5166. lengths: createTypedArray('float32', defaultCurveSegments),
  5167. };
  5168. }
  5169. return pool_factory(8, create);
  5170. }());
  5171. function BaseRenderer(){}
  5172. BaseRenderer.prototype.checkLayers = function(num){
  5173. var i, len = this.layers.length, data;
  5174. this.completeLayers = true;
  5175. for (i = len - 1; i >= 0; i--) {
  5176. if (!this.elements[i]) {
  5177. data = this.layers[i];
  5178. if(data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st))
  5179. {
  5180. this.buildItem(i);
  5181. }
  5182. }
  5183. this.completeLayers = this.elements[i] ? this.completeLayers:false;
  5184. }
  5185. this.checkPendingElements();
  5186. };
  5187. BaseRenderer.prototype.createItem = function(layer){
  5188. switch(layer.ty){
  5189. case 2:
  5190. return this.createImage(layer);
  5191. case 0:
  5192. return this.createComp(layer);
  5193. case 1:
  5194. return this.createSolid(layer);
  5195. case 3:
  5196. return this.createNull(layer);
  5197. case 4:
  5198. return this.createShape(layer);
  5199. case 5:
  5200. return this.createText(layer);
  5201. case 13:
  5202. return this.createCamera(layer);
  5203. }
  5204. return this.createNull(layer);
  5205. };
  5206. BaseRenderer.prototype.createCamera = function(){
  5207. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  5208. };
  5209. BaseRenderer.prototype.buildAllItems = function(){
  5210. var i, len = this.layers.length;
  5211. for(i=0;i<len;i+=1){
  5212. this.buildItem(i);
  5213. }
  5214. this.checkPendingElements();
  5215. };
  5216. BaseRenderer.prototype.includeLayers = function(newLayers){
  5217. this.completeLayers = false;
  5218. var i, len = newLayers.length;
  5219. var j, jLen = this.layers.length;
  5220. for(i=0;i<len;i+=1){
  5221. j = 0;
  5222. while(j<jLen){
  5223. if(this.layers[j].id == newLayers[i].id){
  5224. this.layers[j] = newLayers[i];
  5225. break;
  5226. }
  5227. j += 1;
  5228. }
  5229. }
  5230. };
  5231. BaseRenderer.prototype.setProjectInterface = function(pInterface){
  5232. this.globalData.projectInterface = pInterface;
  5233. };
  5234. BaseRenderer.prototype.initItems = function(){
  5235. if(!this.globalData.progressiveLoad){
  5236. this.buildAllItems();
  5237. }
  5238. };
  5239. BaseRenderer.prototype.buildElementParenting = function(element, parentName, hierarchy) {
  5240. var elements = this.elements;
  5241. var layers = this.layers;
  5242. var i=0, len = layers.length;
  5243. while (i < len) {
  5244. if (layers[i].ind == parentName) {
  5245. if (!elements[i] || elements[i] === true) {
  5246. this.buildItem(i);
  5247. this.addPendingElement(element);
  5248. } else {
  5249. hierarchy.push(elements[i]);
  5250. elements[i].setAsParent();
  5251. if(layers[i].parent !== undefined) {
  5252. this.buildElementParenting(element, layers[i].parent, hierarchy);
  5253. } else {
  5254. element.setHierarchy(hierarchy);
  5255. }
  5256. }
  5257. }
  5258. i += 1;
  5259. }
  5260. };
  5261. BaseRenderer.prototype.addPendingElement = function(element){
  5262. this.pendingElements.push(element);
  5263. };
  5264. BaseRenderer.prototype.searchExtraCompositions = function(assets){
  5265. var i, len = assets.length;
  5266. for(i=0;i<len;i+=1){
  5267. if(assets[i].xt){
  5268. var comp = this.createComp(assets[i]);
  5269. comp.initExpressions();
  5270. this.globalData.projectInterface.registerComposition(comp);
  5271. }
  5272. }
  5273. };
  5274. BaseRenderer.prototype.setupGlobalData = function(animData, fontsContainer) {
  5275. this.globalData.fontManager = new FontManager();
  5276. this.globalData.fontManager.addChars(animData.chars);
  5277. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  5278. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  5279. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  5280. this.globalData.imageLoader = this.animationItem.imagePreloader;
  5281. this.globalData.frameId = 0;
  5282. this.globalData.frameRate = animData.fr;
  5283. this.globalData.nm = animData.nm;
  5284. this.globalData.compSize = {
  5285. w: animData.w,
  5286. h: animData.h
  5287. }
  5288. }
  5289. function SVGRenderer(animationItem, config){
  5290. this.animationItem = animationItem;
  5291. this.layers = null;
  5292. this.renderedFrame = -1;
  5293. this.svgElement = createNS('svg');
  5294. var ariaLabel = '';
  5295. if (config && config.title) {
  5296. var titleElement = createNS('title');
  5297. var titleId = createElementID();
  5298. titleElement.setAttribute('id', titleId);
  5299. titleElement.textContent = config.title;
  5300. this.svgElement.appendChild(titleElement);
  5301. ariaLabel += titleId;
  5302. }
  5303. if (config && config.description) {
  5304. var descElement = createNS('desc');
  5305. var descId = createElementID();
  5306. descElement.setAttribute('id', descId);
  5307. descElement.textContent = config.description;
  5308. this.svgElement.appendChild(descElement);
  5309. ariaLabel += ' ' + descId;
  5310. }
  5311. if (ariaLabel) {
  5312. this.svgElement.setAttribute('aria-labelledby', ariaLabel)
  5313. }
  5314. var defs = createNS( 'defs');
  5315. this.svgElement.appendChild(defs);
  5316. var maskElement = createNS('g');
  5317. this.svgElement.appendChild(maskElement);
  5318. this.layerElement = maskElement;
  5319. this.renderConfig = {
  5320. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  5321. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  5322. progressiveLoad: (config && config.progressiveLoad) || false,
  5323. hideOnTransparent: (config && config.hideOnTransparent === false) ? false : true,
  5324. viewBoxOnly: (config && config.viewBoxOnly) || false,
  5325. viewBoxSize: (config && config.viewBoxSize) || false,
  5326. className: (config && config.className) || ''
  5327. };
  5328. this.globalData = {
  5329. _mdf: false,
  5330. frameNum: -1,
  5331. defs: defs,
  5332. renderConfig: this.renderConfig
  5333. };
  5334. this.elements = [];
  5335. this.pendingElements = [];
  5336. this.destroyed = false;
  5337. this.rendererType = 'svg';
  5338. }
  5339. extendPrototype([BaseRenderer],SVGRenderer);
  5340. SVGRenderer.prototype.createNull = function (data) {
  5341. return new NullElement(data,this.globalData,this);
  5342. };
  5343. SVGRenderer.prototype.createShape = function (data) {
  5344. return new SVGShapeElement(data,this.globalData,this);
  5345. };
  5346. SVGRenderer.prototype.createText = function (data) {
  5347. return new SVGTextElement(data,this.globalData,this);
  5348. };
  5349. SVGRenderer.prototype.createImage = function (data) {
  5350. return new IImageElement(data,this.globalData,this);
  5351. };
  5352. SVGRenderer.prototype.createComp = function (data) {
  5353. return new SVGCompElement(data,this.globalData,this);
  5354. };
  5355. SVGRenderer.prototype.createSolid = function (data) {
  5356. return new ISolidElement(data,this.globalData,this);
  5357. };
  5358. SVGRenderer.prototype.configAnimation = function(animData){
  5359. this.svgElement.setAttribute('xmlns','http://www.w3.org/2000/svg');
  5360. if(this.renderConfig.viewBoxSize) {
  5361. this.svgElement.setAttribute('viewBox',this.renderConfig.viewBoxSize);
  5362. } else {
  5363. this.svgElement.setAttribute('viewBox','0 0 '+animData.w+' '+animData.h);
  5364. }
  5365. if(!this.renderConfig.viewBoxOnly) {
  5366. this.svgElement.setAttribute('width',animData.w);
  5367. this.svgElement.setAttribute('height',animData.h);
  5368. this.svgElement.style.width = '100%';
  5369. this.svgElement.style.height = '100%';
  5370. this.svgElement.style.transform = 'translate3d(0,0,0)';
  5371. }
  5372. if(this.renderConfig.className) {
  5373. this.svgElement.setAttribute('class', this.renderConfig.className);
  5374. }
  5375. this.svgElement.setAttribute('preserveAspectRatio',this.renderConfig.preserveAspectRatio);
  5376. //this.layerElement.style.transform = 'translate3d(0,0,0)';
  5377. //this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  5378. this.animationItem.wrapper.appendChild(this.svgElement);
  5379. //Mask animation
  5380. var defs = this.globalData.defs;
  5381. this.setupGlobalData(animData, defs);
  5382. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  5383. this.data = animData;
  5384. var maskElement = createNS( 'clipPath');
  5385. var rect = createNS('rect');
  5386. rect.setAttribute('width',animData.w);
  5387. rect.setAttribute('height',animData.h);
  5388. rect.setAttribute('x',0);
  5389. rect.setAttribute('y',0);
  5390. var maskId = createElementID();
  5391. maskElement.setAttribute('id', maskId);
  5392. maskElement.appendChild(rect);
  5393. this.layerElement.setAttribute("clip-path", "url(" + locationHref + "#"+maskId+")");
  5394. defs.appendChild(maskElement);
  5395. this.layers = animData.layers;
  5396. this.elements = createSizedArray(animData.layers.length);
  5397. };
  5398. SVGRenderer.prototype.destroy = function () {
  5399. this.animationItem.wrapper.innerHTML = '';
  5400. this.layerElement = null;
  5401. this.globalData.defs = null;
  5402. var i, len = this.layers ? this.layers.length : 0;
  5403. for (i = 0; i < len; i++) {
  5404. if(this.elements[i]){
  5405. this.elements[i].destroy();
  5406. }
  5407. }
  5408. this.elements.length = 0;
  5409. this.destroyed = true;
  5410. this.animationItem = null;
  5411. };
  5412. SVGRenderer.prototype.updateContainerSize = function () {
  5413. };
  5414. SVGRenderer.prototype.buildItem = function(pos){
  5415. var elements = this.elements;
  5416. if(elements[pos] || this.layers[pos].ty == 99){
  5417. return;
  5418. }
  5419. elements[pos] = true;
  5420. var element = this.createItem(this.layers[pos]);
  5421. elements[pos] = element;
  5422. if(expressionsPlugin){
  5423. if(this.layers[pos].ty === 0){
  5424. this.globalData.projectInterface.registerComposition(element);
  5425. }
  5426. element.initExpressions();
  5427. }
  5428. this.appendElementInPos(element,pos);
  5429. if(this.layers[pos].tt){
  5430. if(!this.elements[pos - 1] || this.elements[pos - 1] === true){
  5431. this.buildItem(pos - 1);
  5432. this.addPendingElement(element);
  5433. } else {
  5434. element.setMatte(elements[pos - 1].layerId);
  5435. }
  5436. }
  5437. };
  5438. SVGRenderer.prototype.checkPendingElements = function(){
  5439. while(this.pendingElements.length){
  5440. var element = this.pendingElements.pop();
  5441. element.checkParenting();
  5442. if(element.data.tt){
  5443. var i = 0, len = this.elements.length;
  5444. while(i<len){
  5445. if(this.elements[i] === element){
  5446. element.setMatte(this.elements[i - 1].layerId);
  5447. break;
  5448. }
  5449. i += 1;
  5450. }
  5451. }
  5452. }
  5453. };
  5454. SVGRenderer.prototype.renderFrame = function(num){
  5455. if(this.renderedFrame === num || this.destroyed){
  5456. return;
  5457. }
  5458. if(num === null){
  5459. num = this.renderedFrame;
  5460. }else{
  5461. this.renderedFrame = num;
  5462. }
  5463. // console.log('-------');
  5464. // console.log('FRAME ',num);
  5465. this.globalData.frameNum = num;
  5466. this.globalData.frameId += 1;
  5467. this.globalData.projectInterface.currentFrame = num;
  5468. this.globalData._mdf = false;
  5469. var i, len = this.layers.length;
  5470. if(!this.completeLayers){
  5471. this.checkLayers(num);
  5472. }
  5473. for (i = len - 1; i >= 0; i--) {
  5474. if(this.completeLayers || this.elements[i]){
  5475. this.elements[i].prepareFrame(num - this.layers[i].st);
  5476. }
  5477. }
  5478. if(this.globalData._mdf) {
  5479. for (i = 0; i < len; i += 1) {
  5480. if(this.completeLayers || this.elements[i]){
  5481. this.elements[i].renderFrame();
  5482. }
  5483. }
  5484. }
  5485. };
  5486. SVGRenderer.prototype.appendElementInPos = function(element, pos){
  5487. var newElement = element.getBaseElement();
  5488. if(!newElement){
  5489. return;
  5490. }
  5491. var i = 0;
  5492. var nextElement;
  5493. while(i<pos){
  5494. if(this.elements[i] && this.elements[i]!== true && this.elements[i].getBaseElement()){
  5495. nextElement = this.elements[i].getBaseElement();
  5496. }
  5497. i += 1;
  5498. }
  5499. if(nextElement){
  5500. this.layerElement.insertBefore(newElement, nextElement);
  5501. } else {
  5502. this.layerElement.appendChild(newElement);
  5503. }
  5504. };
  5505. SVGRenderer.prototype.hide = function(){
  5506. this.layerElement.style.display = 'none';
  5507. };
  5508. SVGRenderer.prototype.show = function(){
  5509. this.layerElement.style.display = 'block';
  5510. };
  5511. function CanvasRenderer(animationItem, config){
  5512. this.animationItem = animationItem;
  5513. this.renderConfig = {
  5514. clearCanvas: (config && config.clearCanvas !== undefined) ? config.clearCanvas : true,
  5515. context: (config && config.context) || null,
  5516. progressiveLoad: (config && config.progressiveLoad) || false,
  5517. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  5518. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  5519. className: (config && config.className) || ''
  5520. };
  5521. this.renderConfig.dpr = (config && config.dpr) || 1;
  5522. if (this.animationItem.wrapper) {
  5523. this.renderConfig.dpr = (config && config.dpr) || window.devicePixelRatio || 1;
  5524. }
  5525. this.renderedFrame = -1;
  5526. this.globalData = {
  5527. frameNum: -1,
  5528. _mdf: false,
  5529. renderConfig: this.renderConfig,
  5530. currentGlobalAlpha: -1
  5531. };
  5532. this.contextData = new CVContextData();
  5533. this.elements = [];
  5534. this.pendingElements = [];
  5535. this.transformMat = new Matrix();
  5536. this.completeLayers = false;
  5537. this.rendererType = 'canvas';
  5538. }
  5539. extendPrototype([BaseRenderer],CanvasRenderer);
  5540. CanvasRenderer.prototype.createShape = function (data) {
  5541. return new CVShapeElement(data, this.globalData, this);
  5542. };
  5543. CanvasRenderer.prototype.createText = function (data) {
  5544. return new CVTextElement(data, this.globalData, this);
  5545. };
  5546. CanvasRenderer.prototype.createImage = function (data) {
  5547. return new CVImageElement(data, this.globalData, this);
  5548. };
  5549. CanvasRenderer.prototype.createComp = function (data) {
  5550. return new CVCompElement(data, this.globalData, this);
  5551. };
  5552. CanvasRenderer.prototype.createSolid = function (data) {
  5553. return new CVSolidElement(data, this.globalData, this);
  5554. };
  5555. CanvasRenderer.prototype.createNull = SVGRenderer.prototype.createNull;
  5556. CanvasRenderer.prototype.ctxTransform = function(props){
  5557. if(props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0){
  5558. return;
  5559. }
  5560. if(!this.renderConfig.clearCanvas){
  5561. this.canvasContext.transform(props[0],props[1],props[4],props[5],props[12],props[13]);
  5562. return;
  5563. }
  5564. this.transformMat.cloneFromProps(props);
  5565. var cProps = this.contextData.cTr.props;
  5566. this.transformMat.transform(cProps[0],cProps[1],cProps[2],cProps[3],cProps[4],cProps[5],cProps[6],cProps[7],cProps[8],cProps[9],cProps[10],cProps[11],cProps[12],cProps[13],cProps[14],cProps[15]);
  5567. //this.contextData.cTr.transform(props[0],props[1],props[2],props[3],props[4],props[5],props[6],props[7],props[8],props[9],props[10],props[11],props[12],props[13],props[14],props[15]);
  5568. this.contextData.cTr.cloneFromProps(this.transformMat.props);
  5569. var trProps = this.contextData.cTr.props;
  5570. this.canvasContext.setTransform(trProps[0],trProps[1],trProps[4],trProps[5],trProps[12],trProps[13]);
  5571. };
  5572. CanvasRenderer.prototype.ctxOpacity = function(op){
  5573. /*if(op === 1){
  5574. return;
  5575. }*/
  5576. if(!this.renderConfig.clearCanvas){
  5577. this.canvasContext.globalAlpha *= op < 0 ? 0 : op;
  5578. this.globalData.currentGlobalAlpha = this.contextData.cO;
  5579. return;
  5580. }
  5581. this.contextData.cO *= op < 0 ? 0 : op;
  5582. if(this.globalData.currentGlobalAlpha !== this.contextData.cO) {
  5583. this.canvasContext.globalAlpha = this.contextData.cO;
  5584. this.globalData.currentGlobalAlpha = this.contextData.cO;
  5585. }
  5586. };
  5587. CanvasRenderer.prototype.reset = function(){
  5588. if(!this.renderConfig.clearCanvas){
  5589. this.canvasContext.restore();
  5590. return;
  5591. }
  5592. this.contextData.reset();
  5593. };
  5594. CanvasRenderer.prototype.save = function(actionFlag){
  5595. if(!this.renderConfig.clearCanvas){
  5596. this.canvasContext.save();
  5597. return;
  5598. }
  5599. if(actionFlag){
  5600. this.canvasContext.save();
  5601. }
  5602. var props = this.contextData.cTr.props;
  5603. if(this.contextData._length <= this.contextData.cArrPos) {
  5604. this.contextData.duplicate();
  5605. }
  5606. var i, arr = this.contextData.saved[this.contextData.cArrPos];
  5607. for (i = 0; i < 16; i += 1) {
  5608. arr[i] = props[i];
  5609. }
  5610. this.contextData.savedOp[this.contextData.cArrPos] = this.contextData.cO;
  5611. this.contextData.cArrPos += 1;
  5612. };
  5613. CanvasRenderer.prototype.restore = function(actionFlag){
  5614. if(!this.renderConfig.clearCanvas){
  5615. this.canvasContext.restore();
  5616. return;
  5617. }
  5618. if(actionFlag){
  5619. this.canvasContext.restore();
  5620. this.globalData.blendMode = 'source-over';
  5621. }
  5622. this.contextData.cArrPos -= 1;
  5623. var popped = this.contextData.saved[this.contextData.cArrPos];
  5624. var i,arr = this.contextData.cTr.props;
  5625. for(i=0;i<16;i+=1){
  5626. arr[i] = popped[i];
  5627. }
  5628. this.canvasContext.setTransform(popped[0],popped[1],popped[4],popped[5],popped[12],popped[13]);
  5629. popped = this.contextData.savedOp[this.contextData.cArrPos];
  5630. this.contextData.cO = popped;
  5631. if(this.globalData.currentGlobalAlpha !== popped) {
  5632. this.canvasContext.globalAlpha = popped;
  5633. this.globalData.currentGlobalAlpha = popped;
  5634. }
  5635. };
  5636. CanvasRenderer.prototype.configAnimation = function(animData){
  5637. if(this.animationItem.wrapper){
  5638. this.animationItem.container = createTag('canvas');
  5639. this.animationItem.container.style.width = '100%';
  5640. this.animationItem.container.style.height = '100%';
  5641. //this.animationItem.container.style.transform = 'translate3d(0,0,0)';
  5642. //this.animationItem.container.style.webkitTransform = 'translate3d(0,0,0)';
  5643. this.animationItem.container.style.transformOrigin = this.animationItem.container.style.mozTransformOrigin = this.animationItem.container.style.webkitTransformOrigin = this.animationItem.container.style['-webkit-transform'] = "0px 0px 0px";
  5644. this.animationItem.wrapper.appendChild(this.animationItem.container);
  5645. this.canvasContext = this.animationItem.container.getContext('2d');
  5646. if(this.renderConfig.className) {
  5647. this.animationItem.container.setAttribute('class', this.renderConfig.className);
  5648. }
  5649. }else{
  5650. this.canvasContext = this.renderConfig.context;
  5651. }
  5652. this.data = animData;
  5653. this.layers = animData.layers;
  5654. this.transformCanvas = {
  5655. w: animData.w,
  5656. h:animData.h,
  5657. sx:0,
  5658. sy:0,
  5659. tx:0,
  5660. ty:0
  5661. };
  5662. this.setupGlobalData(animData, document.body);
  5663. this.globalData.canvasContext = this.canvasContext;
  5664. this.globalData.renderer = this;
  5665. this.globalData.isDashed = false;
  5666. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  5667. this.globalData.transformCanvas = this.transformCanvas;
  5668. this.elements = createSizedArray(animData.layers.length);
  5669. this.updateContainerSize();
  5670. };
  5671. CanvasRenderer.prototype.updateContainerSize = function () {
  5672. this.reset();
  5673. var elementWidth,elementHeight;
  5674. if(this.animationItem.wrapper && this.animationItem.container){
  5675. elementWidth = this.animationItem.wrapper.offsetWidth;
  5676. elementHeight = this.animationItem.wrapper.offsetHeight;
  5677. this.animationItem.container.setAttribute('width',elementWidth * this.renderConfig.dpr );
  5678. this.animationItem.container.setAttribute('height',elementHeight * this.renderConfig.dpr);
  5679. }else{
  5680. elementWidth = this.canvasContext.canvas.width * this.renderConfig.dpr;
  5681. elementHeight = this.canvasContext.canvas.height * this.renderConfig.dpr;
  5682. }
  5683. var elementRel,animationRel;
  5684. if(this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1){
  5685. var par = this.renderConfig.preserveAspectRatio.split(' ');
  5686. var fillType = par[1] || 'meet';
  5687. var pos = par[0] || 'xMidYMid';
  5688. var xPos = pos.substr(0,4);
  5689. var yPos = pos.substr(4);
  5690. elementRel = elementWidth/elementHeight;
  5691. animationRel = this.transformCanvas.w/this.transformCanvas.h;
  5692. if(animationRel>elementRel && fillType === 'meet' || animationRel<elementRel && fillType === 'slice'){
  5693. this.transformCanvas.sx = elementWidth/(this.transformCanvas.w/this.renderConfig.dpr);
  5694. this.transformCanvas.sy = elementWidth/(this.transformCanvas.w/this.renderConfig.dpr);
  5695. }else{
  5696. this.transformCanvas.sx = elementHeight/(this.transformCanvas.h / this.renderConfig.dpr);
  5697. this.transformCanvas.sy = elementHeight/(this.transformCanvas.h / this.renderConfig.dpr);
  5698. }
  5699. if(xPos === 'xMid' && ((animationRel<elementRel && fillType==='meet') || (animationRel>elementRel && fillType === 'slice'))){
  5700. this.transformCanvas.tx = (elementWidth-this.transformCanvas.w*(elementHeight/this.transformCanvas.h))/2*this.renderConfig.dpr;
  5701. } else if(xPos === 'xMax' && ((animationRel<elementRel && fillType==='meet') || (animationRel>elementRel && fillType === 'slice'))){
  5702. this.transformCanvas.tx = (elementWidth-this.transformCanvas.w*(elementHeight/this.transformCanvas.h))*this.renderConfig.dpr;
  5703. } else {
  5704. this.transformCanvas.tx = 0;
  5705. }
  5706. if(yPos === 'YMid' && ((animationRel>elementRel && fillType==='meet') || (animationRel<elementRel && fillType === 'slice'))){
  5707. this.transformCanvas.ty = ((elementHeight-this.transformCanvas.h*(elementWidth/this.transformCanvas.w))/2)*this.renderConfig.dpr;
  5708. } else if(yPos === 'YMax' && ((animationRel>elementRel && fillType==='meet') || (animationRel<elementRel && fillType === 'slice'))){
  5709. this.transformCanvas.ty = ((elementHeight-this.transformCanvas.h*(elementWidth/this.transformCanvas.w)))*this.renderConfig.dpr;
  5710. } else {
  5711. this.transformCanvas.ty = 0;
  5712. }
  5713. }else if(this.renderConfig.preserveAspectRatio == 'none'){
  5714. this.transformCanvas.sx = elementWidth/(this.transformCanvas.w/this.renderConfig.dpr);
  5715. this.transformCanvas.sy = elementHeight/(this.transformCanvas.h/this.renderConfig.dpr);
  5716. this.transformCanvas.tx = 0;
  5717. this.transformCanvas.ty = 0;
  5718. }else{
  5719. this.transformCanvas.sx = this.renderConfig.dpr;
  5720. this.transformCanvas.sy = this.renderConfig.dpr;
  5721. this.transformCanvas.tx = 0;
  5722. this.transformCanvas.ty = 0;
  5723. }
  5724. 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];
  5725. /*var i, len = this.elements.length;
  5726. for(i=0;i<len;i+=1){
  5727. if(this.elements[i] && this.elements[i].data.ty === 0){
  5728. this.elements[i].resize(this.globalData.transformCanvas);
  5729. }
  5730. }*/
  5731. this.ctxTransform(this.transformCanvas.props);
  5732. this.canvasContext.beginPath();
  5733. this.canvasContext.rect(0,0,this.transformCanvas.w,this.transformCanvas.h);
  5734. this.canvasContext.closePath();
  5735. this.canvasContext.clip();
  5736. this.renderFrame(this.renderedFrame, true);
  5737. };
  5738. CanvasRenderer.prototype.destroy = function () {
  5739. if(this.renderConfig.clearCanvas) {
  5740. this.animationItem.wrapper.innerHTML = '';
  5741. }
  5742. var i, len = this.layers ? this.layers.length : 0;
  5743. for (i = len - 1; i >= 0; i-=1) {
  5744. if(this.elements[i]) {
  5745. this.elements[i].destroy();
  5746. }
  5747. }
  5748. this.elements.length = 0;
  5749. this.globalData.canvasContext = null;
  5750. this.animationItem.container = null;
  5751. this.destroyed = true;
  5752. };
  5753. CanvasRenderer.prototype.renderFrame = function(num, forceRender){
  5754. if((this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender) || this.destroyed || num === -1){
  5755. return;
  5756. }
  5757. this.renderedFrame = num;
  5758. this.globalData.frameNum = num - this.animationItem._isFirstFrame;
  5759. this.globalData.frameId += 1;
  5760. this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender;
  5761. this.globalData.projectInterface.currentFrame = num;
  5762. // console.log('--------');
  5763. // console.log('NEW: ',num);
  5764. var i, len = this.layers.length;
  5765. if(!this.completeLayers){
  5766. this.checkLayers(num);
  5767. }
  5768. for (i = 0; i < len; i++) {
  5769. if(this.completeLayers || this.elements[i]){
  5770. this.elements[i].prepareFrame(num - this.layers[i].st);
  5771. }
  5772. }
  5773. if(this.globalData._mdf) {
  5774. if(this.renderConfig.clearCanvas === true){
  5775. this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  5776. }else{
  5777. this.save();
  5778. }
  5779. for (i = len - 1; i >= 0; i-=1) {
  5780. if(this.completeLayers || this.elements[i]){
  5781. this.elements[i].renderFrame();
  5782. }
  5783. }
  5784. if(this.renderConfig.clearCanvas !== true){
  5785. this.restore();
  5786. }
  5787. }
  5788. };
  5789. CanvasRenderer.prototype.buildItem = function(pos){
  5790. var elements = this.elements;
  5791. if(elements[pos] || this.layers[pos].ty == 99){
  5792. return;
  5793. }
  5794. var element = this.createItem(this.layers[pos], this,this.globalData);
  5795. elements[pos] = element;
  5796. element.initExpressions();
  5797. /*if(this.layers[pos].ty === 0){
  5798. element.resize(this.globalData.transformCanvas);
  5799. }*/
  5800. };
  5801. CanvasRenderer.prototype.checkPendingElements = function(){
  5802. while(this.pendingElements.length){
  5803. var element = this.pendingElements.pop();
  5804. element.checkParenting();
  5805. }
  5806. };
  5807. CanvasRenderer.prototype.hide = function(){
  5808. this.animationItem.container.style.display = 'none';
  5809. };
  5810. CanvasRenderer.prototype.show = function(){
  5811. this.animationItem.container.style.display = 'block';
  5812. };
  5813. CanvasRenderer.prototype.configAnimation = function(animData){
  5814. if(this.animationItem.wrapper){
  5815. this.animationItem.container = createTag('canvas');
  5816. this.animationItem.container.style.width = '100%';
  5817. this.animationItem.container.style.height = '100%';
  5818. //this.animationItem.container.style.transform = 'translate3d(0,0,0)';
  5819. //this.animationItem.container.style.webkitTransform = 'translate3d(0,0,0)';
  5820. this.animationItem.container.style.transformOrigin = this.animationItem.container.style.mozTransformOrigin = this.animationItem.container.style.webkitTransformOrigin = this.animationItem.container.style['-webkit-transform'] = "0px 0px 0px";
  5821. this.animationItem.wrapper.appendChild(this.animationItem.container);
  5822. this.canvasContext = this.animationItem.container.getContext('2d');
  5823. if(this.renderConfig.className) {
  5824. this.animationItem.container.setAttribute('class', this.renderConfig.className);
  5825. }
  5826. }else{
  5827. this.canvasContext = this.renderConfig.context;
  5828. }
  5829. this.data = animData;
  5830. this.layers = animData.layers;
  5831. this.transformCanvas = {
  5832. w: animData.w,
  5833. h:animData.h,
  5834. sx:0,
  5835. sy:0,
  5836. tx:0,
  5837. ty:0
  5838. };
  5839. this.globalData.frameId = 0;
  5840. this.globalData.frameRate = animData.fr;
  5841. this.globalData.nm = animData.nm;
  5842. this.globalData.compSize = {
  5843. w: animData.w,
  5844. h: animData.h
  5845. }
  5846. this.globalData.canvasContext = this.canvasContext;
  5847. this.globalData.renderer = this;
  5848. this.globalData.isDashed = false;
  5849. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  5850. this.globalData.transformCanvas = this.transformCanvas;
  5851. this.elements = createSizedArray(animData.layers.length);
  5852. this.updateContainerSize();
  5853. };
  5854. function MaskElement(data,element,globalData) {
  5855. this.data = data;
  5856. this.element = element;
  5857. this.globalData = globalData;
  5858. this.storedData = [];
  5859. this.masksProperties = this.data.masksProperties || [];
  5860. this.maskElement = null;
  5861. var defs = this.globalData.defs;
  5862. var i, len = this.masksProperties ? this.masksProperties.length : 0;
  5863. this.viewData = createSizedArray(len);
  5864. this.solidPath = '';
  5865. var path, properties = this.masksProperties;
  5866. var count = 0;
  5867. var currentMasks = [];
  5868. var j, jLen;
  5869. var layerId = createElementID();
  5870. var rect, expansor, feMorph,x;
  5871. var maskType = 'clipPath', maskRef = 'clip-path';
  5872. for (i = 0; i < len; i++) {
  5873. if((properties[i].mode !== 'a' && properties[i].mode !== 'n')|| properties[i].inv || properties[i].o.k !== 100){
  5874. maskType = 'mask';
  5875. maskRef = 'mask';
  5876. }
  5877. if((properties[i].mode == 's' || properties[i].mode == 'i') && count === 0){
  5878. rect = createNS( 'rect');
  5879. rect.setAttribute('fill', '#ffffff');
  5880. rect.setAttribute('width', this.element.comp.data.w || 0);
  5881. rect.setAttribute('height', this.element.comp.data.h || 0);
  5882. currentMasks.push(rect);
  5883. } else {
  5884. rect = null;
  5885. }
  5886. path = createNS( 'path');
  5887. if(properties[i].mode == 'n') {
  5888. // TODO move this to a factory or to a constructor
  5889. this.viewData[i] = {
  5890. op: PropertyFactory.getProp(this.element,properties[i].o,0,0.01,this.element),
  5891. prop: ShapePropertyFactory.getShapeProp(this.element,properties[i],3),
  5892. elem: path,
  5893. lastPath: ''
  5894. };
  5895. defs.appendChild(path);
  5896. continue;
  5897. }
  5898. count += 1;
  5899. path.setAttribute('fill', properties[i].mode === 's' ? '#000000':'#ffffff');
  5900. path.setAttribute('clip-rule','nonzero');
  5901. var filterID;
  5902. if (properties[i].x.k !== 0) {
  5903. maskType = 'mask';
  5904. maskRef = 'mask';
  5905. x = PropertyFactory.getProp(this.element,properties[i].x,0,null,this.element);
  5906. filterID = createElementID();
  5907. expansor = createNS('filter');
  5908. expansor.setAttribute('id',filterID);
  5909. feMorph = createNS('feMorphology');
  5910. feMorph.setAttribute('operator','erode');
  5911. feMorph.setAttribute('in','SourceGraphic');
  5912. feMorph.setAttribute('radius','0');
  5913. expansor.appendChild(feMorph);
  5914. defs.appendChild(expansor);
  5915. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000':'#ffffff');
  5916. } else {
  5917. feMorph = null;
  5918. x = null;
  5919. }
  5920. // TODO move this to a factory or to a constructor
  5921. this.storedData[i] = {
  5922. elem: path,
  5923. x: x,
  5924. expan: feMorph,
  5925. lastPath: '',
  5926. lastOperator:'',
  5927. filterId:filterID,
  5928. lastRadius:0
  5929. };
  5930. if(properties[i].mode == 'i'){
  5931. jLen = currentMasks.length;
  5932. var g = createNS('g');
  5933. for(j=0;j<jLen;j+=1){
  5934. g.appendChild(currentMasks[j]);
  5935. }
  5936. var mask = createNS('mask');
  5937. mask.setAttribute('mask-type','alpha');
  5938. mask.setAttribute('id',layerId+'_'+count);
  5939. mask.appendChild(path);
  5940. defs.appendChild(mask);
  5941. g.setAttribute('mask','url(' + locationHref + '#'+layerId+'_'+count+')');
  5942. currentMasks.length = 0;
  5943. currentMasks.push(g);
  5944. }else{
  5945. currentMasks.push(path);
  5946. }
  5947. if(properties[i].inv && !this.solidPath){
  5948. this.solidPath = this.createLayerSolidPath();
  5949. }
  5950. // TODO move this to a factory or to a constructor
  5951. this.viewData[i] = {
  5952. elem: path,
  5953. lastPath: '',
  5954. op: PropertyFactory.getProp(this.element,properties[i].o,0,0.01,this.element),
  5955. prop:ShapePropertyFactory.getShapeProp(this.element,properties[i],3),
  5956. invRect: rect
  5957. };
  5958. if(!this.viewData[i].prop.k){
  5959. this.drawPath(properties[i],this.viewData[i].prop.v,this.viewData[i]);
  5960. }
  5961. }
  5962. this.maskElement = createNS( maskType);
  5963. len = currentMasks.length;
  5964. for(i=0;i<len;i+=1){
  5965. this.maskElement.appendChild(currentMasks[i]);
  5966. }
  5967. if(count > 0){
  5968. this.maskElement.setAttribute('id', layerId);
  5969. this.element.maskedElement.setAttribute(maskRef, "url(" + locationHref + "#" + layerId + ")");
  5970. defs.appendChild(this.maskElement);
  5971. }
  5972. if (this.viewData.length) {
  5973. this.element.addRenderableComponent(this);
  5974. }
  5975. }
  5976. MaskElement.prototype.getMaskProperty = function(pos){
  5977. return this.viewData[pos].prop;
  5978. };
  5979. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  5980. var finalMat = this.element.finalTransform.mat;
  5981. var i, len = this.masksProperties.length;
  5982. for (i = 0; i < len; i++) {
  5983. if(this.viewData[i].prop._mdf || isFirstFrame){
  5984. this.drawPath(this.masksProperties[i],this.viewData[i].prop.v,this.viewData[i]);
  5985. }
  5986. if(this.viewData[i].op._mdf || isFirstFrame){
  5987. this.viewData[i].elem.setAttribute('fill-opacity',this.viewData[i].op.v);
  5988. }
  5989. if(this.masksProperties[i].mode !== 'n'){
  5990. if(this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)){
  5991. this.viewData[i].invRect.setAttribute('x', -finalMat.props[12]);
  5992. this.viewData[i].invRect.setAttribute('y', -finalMat.props[13]);
  5993. }
  5994. if(this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)){
  5995. var feMorph = this.storedData[i].expan;
  5996. if(this.storedData[i].x.v < 0){
  5997. if(this.storedData[i].lastOperator !== 'erode'){
  5998. this.storedData[i].lastOperator = 'erode';
  5999. this.storedData[i].elem.setAttribute('filter','url(' + locationHref + '#'+this.storedData[i].filterId+')');
  6000. }
  6001. feMorph.setAttribute('radius',-this.storedData[i].x.v);
  6002. }else{
  6003. if(this.storedData[i].lastOperator !== 'dilate'){
  6004. this.storedData[i].lastOperator = 'dilate';
  6005. this.storedData[i].elem.setAttribute('filter',null);
  6006. }
  6007. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v*2);
  6008. }
  6009. }
  6010. }
  6011. }
  6012. };
  6013. MaskElement.prototype.getMaskelement = function () {
  6014. return this.maskElement;
  6015. };
  6016. MaskElement.prototype.createLayerSolidPath = function(){
  6017. var path = 'M0,0 ';
  6018. path += ' h' + this.globalData.compSize.w ;
  6019. path += ' v' + this.globalData.compSize.h ;
  6020. path += ' h-' + this.globalData.compSize.w ;
  6021. path += ' v-' + this.globalData.compSize.h + ' ';
  6022. return path;
  6023. };
  6024. MaskElement.prototype.drawPath = function(pathData,pathNodes,viewData){
  6025. var pathString = " M"+pathNodes.v[0][0]+','+pathNodes.v[0][1];
  6026. var i, len;
  6027. len = pathNodes._length;
  6028. for(i=1;i<len;i+=1){
  6029. //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];
  6030. 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];
  6031. }
  6032. //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];
  6033. if(pathNodes.c && len > 1){
  6034. 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];
  6035. }
  6036. //pathNodes.__renderedString = pathString;
  6037. if(viewData.lastPath !== pathString){
  6038. var pathShapeValue = '';
  6039. if(viewData.elem){
  6040. if(pathNodes.c){
  6041. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  6042. }
  6043. viewData.elem.setAttribute('d',pathShapeValue);
  6044. }
  6045. viewData.lastPath = pathString;
  6046. }
  6047. };
  6048. MaskElement.prototype.destroy = function(){
  6049. this.element = null;
  6050. this.globalData = null;
  6051. this.maskElement = null;
  6052. this.data = null;
  6053. this.masksProperties = null;
  6054. };
  6055. /**
  6056. * @file
  6057. * Handles AE's layer parenting property.
  6058. *
  6059. */
  6060. function HierarchyElement(){}
  6061. HierarchyElement.prototype = {
  6062. /**
  6063. * @function
  6064. * Initializes hierarchy properties
  6065. *
  6066. */
  6067. initHierarchy: function() {
  6068. //element's parent list
  6069. this.hierarchy = [];
  6070. //if element is parent of another layer _isParent will be true
  6071. this._isParent = false;
  6072. this.checkParenting();
  6073. },
  6074. /**
  6075. * @function
  6076. * Sets layer's hierarchy.
  6077. * @param {array} hierarch
  6078. * layer's parent list
  6079. *
  6080. */
  6081. setHierarchy: function(hierarchy){
  6082. this.hierarchy = hierarchy;
  6083. },
  6084. /**
  6085. * @function
  6086. * Sets layer as parent.
  6087. *
  6088. */
  6089. setAsParent: function() {
  6090. this._isParent = true;
  6091. },
  6092. /**
  6093. * @function
  6094. * Searches layer's parenting chain
  6095. *
  6096. */
  6097. checkParenting: function(){
  6098. if (this.data.parent !== undefined){
  6099. this.comp.buildElementParenting(this, this.data.parent, []);
  6100. }
  6101. }
  6102. };
  6103. /**
  6104. * @file
  6105. * Handles element's layer frame update.
  6106. * Checks layer in point and out point
  6107. *
  6108. */
  6109. function FrameElement(){}
  6110. FrameElement.prototype = {
  6111. /**
  6112. * @function
  6113. * Initializes frame related properties.
  6114. *
  6115. */
  6116. initFrame: function(){
  6117. //set to true when inpoint is rendered
  6118. this._isFirstFrame = false;
  6119. //list of animated properties
  6120. this.dynamicProperties = [];
  6121. // If layer has been modified in current tick this will be true
  6122. this._mdf = false;
  6123. },
  6124. /**
  6125. * @function
  6126. * Calculates all dynamic values
  6127. *
  6128. * @param {number} num
  6129. * current frame number in Layer's time
  6130. * @param {boolean} isVisible
  6131. * if layers is currently in range
  6132. *
  6133. */
  6134. prepareProperties: function(num, isVisible) {
  6135. var i, len = this.dynamicProperties.length;
  6136. for (i = 0;i < len; i += 1) {
  6137. if (isVisible || (this._isParent && this.dynamicProperties[i].propType === 'transform')) {
  6138. this.dynamicProperties[i].getValue();
  6139. if (this.dynamicProperties[i]._mdf) {
  6140. this.globalData._mdf = true;
  6141. this._mdf = true;
  6142. }
  6143. }
  6144. }
  6145. },
  6146. addDynamicProperty: function(prop) {
  6147. if(this.dynamicProperties.indexOf(prop) === -1) {
  6148. this.dynamicProperties.push(prop);
  6149. }
  6150. }
  6151. };
  6152. function TransformElement(){}
  6153. TransformElement.prototype = {
  6154. initTransform: function() {
  6155. this.finalTransform = {
  6156. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : {o:0},
  6157. _matMdf: false,
  6158. _opMdf: false,
  6159. mat: new Matrix()
  6160. };
  6161. if (this.data.ao) {
  6162. this.finalTransform.mProp.autoOriented = true;
  6163. }
  6164. //TODO: check TYPE 11: Guided elements
  6165. if (this.data.ty !== 11) {
  6166. //this.createElements();
  6167. }
  6168. },
  6169. renderTransform: function() {
  6170. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  6171. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  6172. if (this.hierarchy) {
  6173. var mat;
  6174. var finalMat = this.finalTransform.mat;
  6175. var i = 0, len = this.hierarchy.length;
  6176. //Checking if any of the transformation matrices in the hierarchy chain has changed.
  6177. if (!this.finalTransform._matMdf) {
  6178. while (i < len) {
  6179. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  6180. this.finalTransform._matMdf = true;
  6181. break;
  6182. }
  6183. i += 1;
  6184. }
  6185. }
  6186. if (this.finalTransform._matMdf) {
  6187. mat = this.finalTransform.mProp.v.props;
  6188. finalMat.cloneFromProps(mat);
  6189. for (i = 0; i < len; i += 1) {
  6190. mat = this.hierarchy[i].finalTransform.mProp.v.props;
  6191. finalMat.transform(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5], mat[6], mat[7], mat[8], mat[9], mat[10], mat[11], mat[12], mat[13], mat[14], mat[15]);
  6192. }
  6193. }
  6194. }
  6195. },
  6196. globalToLocal: function(pt) {
  6197. var transforms = [];
  6198. transforms.push(this.finalTransform);
  6199. var flag = true;
  6200. var comp = this.comp;
  6201. while (flag) {
  6202. if (comp.finalTransform) {
  6203. if (comp.data.hasMask) {
  6204. transforms.splice(0, 0, comp.finalTransform);
  6205. }
  6206. comp = comp.comp;
  6207. } else {
  6208. flag = false;
  6209. }
  6210. }
  6211. var i, len = transforms.length,ptNew;
  6212. for (i = 0; i < len; i += 1) {
  6213. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  6214. //ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  6215. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  6216. }
  6217. return pt;
  6218. },
  6219. mHelper: new Matrix()
  6220. };
  6221. function RenderableElement(){
  6222. }
  6223. RenderableElement.prototype = {
  6224. initRenderable: function() {
  6225. //layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6226. this.isInRange = false;
  6227. //layer's display state
  6228. this.hidden = false;
  6229. // If layer's transparency equals 0, it can be hidden
  6230. this.isTransparent = false;
  6231. //list of animated components
  6232. this.renderableComponents = [];
  6233. },
  6234. addRenderableComponent: function(component) {
  6235. if(this.renderableComponents.indexOf(component) === -1) {
  6236. this.renderableComponents.push(component);
  6237. }
  6238. },
  6239. removeRenderableComponent: function(component) {
  6240. if(this.renderableComponents.indexOf(component) !== -1) {
  6241. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6242. }
  6243. },
  6244. prepareRenderableFrame: function(num) {
  6245. this.checkLayerLimits(num);
  6246. },
  6247. checkTransparency: function(){
  6248. if(this.finalTransform.mProp.o.v <= 0) {
  6249. if(!this.isTransparent && this.globalData.renderConfig.hideOnTransparent){
  6250. this.isTransparent = true;
  6251. this.hide();
  6252. }
  6253. } else if(this.isTransparent) {
  6254. this.isTransparent = false;
  6255. this.show();
  6256. }
  6257. },
  6258. /**
  6259. * @function
  6260. * Initializes frame related properties.
  6261. *
  6262. * @param {number} num
  6263. * current frame number in Layer's time
  6264. *
  6265. */
  6266. checkLayerLimits: function(num) {
  6267. if(this.data.ip - this.data.st <= num && this.data.op - this.data.st > num)
  6268. {
  6269. if(this.isInRange !== true){
  6270. this.globalData._mdf = true;
  6271. this._mdf = true;
  6272. this.isInRange = true;
  6273. this.show();
  6274. }
  6275. } else {
  6276. if(this.isInRange !== false){
  6277. this.globalData._mdf = true;
  6278. this.isInRange = false;
  6279. this.hide();
  6280. }
  6281. }
  6282. },
  6283. renderRenderable: function() {
  6284. var i, len = this.renderableComponents.length;
  6285. for(i = 0; i < len; i += 1) {
  6286. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6287. }
  6288. /*this.maskManager.renderFrame(this.finalTransform.mat);
  6289. this.renderableEffectsManager.renderFrame(this._isFirstFrame);*/
  6290. },
  6291. sourceRectAtTime: function(){
  6292. return {
  6293. top:0,
  6294. left:0,
  6295. width:100,
  6296. height:100
  6297. };
  6298. },
  6299. getLayerSize: function(){
  6300. if(this.data.ty === 5){
  6301. return {w:this.data.textData.width,h:this.data.textData.height};
  6302. }else{
  6303. return {w:this.data.width,h:this.data.height};
  6304. }
  6305. }
  6306. };
  6307. function RenderableDOMElement() {}
  6308. (function(){
  6309. var _prototype = {
  6310. initElement: function(data,globalData,comp) {
  6311. this.initFrame();
  6312. this.initBaseData(data, globalData, comp);
  6313. this.initTransform(data, globalData, comp);
  6314. this.initHierarchy();
  6315. this.initRenderable();
  6316. this.initRendererElement();
  6317. this.createContainerElements();
  6318. this.createRenderableComponents();
  6319. this.createContent();
  6320. this.hide();
  6321. },
  6322. hide: function(){
  6323. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  6324. var elem = this.baseElement || this.layerElement;
  6325. elem.style.display = 'none';
  6326. this.hidden = true;
  6327. }
  6328. },
  6329. show: function(){
  6330. if (this.isInRange && !this.isTransparent){
  6331. if (!this.data.hd) {
  6332. var elem = this.baseElement || this.layerElement;
  6333. elem.style.display = 'block';
  6334. }
  6335. this.hidden = false;
  6336. this._isFirstFrame = true;
  6337. }
  6338. },
  6339. renderFrame: function() {
  6340. //If it is exported as hidden (data.hd === true) no need to render
  6341. //If it is not visible no need to render
  6342. if (this.data.hd || this.hidden) {
  6343. return;
  6344. }
  6345. this.renderTransform();
  6346. this.renderRenderable();
  6347. this.renderElement();
  6348. this.renderInnerContent();
  6349. if (this._isFirstFrame) {
  6350. this._isFirstFrame = false;
  6351. }
  6352. },
  6353. renderInnerContent: function() {},
  6354. prepareFrame: function(num) {
  6355. this._mdf = false;
  6356. this.prepareRenderableFrame(num);
  6357. this.prepareProperties(num, this.isInRange);
  6358. this.checkTransparency();
  6359. },
  6360. destroy: function(){
  6361. this.innerElem = null;
  6362. this.destroyBaseElement();
  6363. }
  6364. };
  6365. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  6366. }());
  6367. function ProcessedElement(element, position) {
  6368. this.elem = element;
  6369. this.pos = position;
  6370. }
  6371. function SVGShapeData(transformers, level, shape) {
  6372. this.caches = [];
  6373. this.styles = [];
  6374. this.transformers = transformers;
  6375. this.lStr = '';
  6376. this.sh = shape;
  6377. this.lvl = level;
  6378. //TODO find if there are some cases where _isAnimated can be false.
  6379. // For now, since shapes add up with other shapes. They have to be calculated every time.
  6380. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  6381. this._isAnimated = !!shape.k;
  6382. // TODO: commenting this for now since all shapes are animated
  6383. var i = 0, len = transformers.length;
  6384. while(i < len) {
  6385. if(transformers[i].mProps.dynamicProperties.length) {
  6386. this._isAnimated = true;
  6387. break;
  6388. }
  6389. i += 1;
  6390. }
  6391. }
  6392. SVGShapeData.prototype.setAsAnimated = function() {
  6393. this._isAnimated = true;
  6394. }
  6395. function ShapeGroupData() {
  6396. this.it = [];
  6397. this.prevViewData = [];
  6398. this.gr = createNS('g');
  6399. }
  6400. function ShapeTransformManager() {
  6401. this.sequences = {};
  6402. this.sequenceList = [];
  6403. this.transform_key_count = 0;
  6404. }
  6405. ShapeTransformManager.prototype = {
  6406. addTransformSequence: function(transforms) {
  6407. var i, len = transforms.length;
  6408. var key = '_';
  6409. for(i = 0; i < len; i += 1) {
  6410. key += transforms[i].transform.key + '_';
  6411. }
  6412. var sequence = this.sequences[key];
  6413. if(!sequence) {
  6414. sequence = {
  6415. transforms: [].concat(transforms),
  6416. finalTransform: new Matrix(),
  6417. _mdf: false
  6418. };
  6419. this.sequences[key] = sequence;
  6420. this.sequenceList.push(sequence);
  6421. }
  6422. return sequence;
  6423. },
  6424. processSequence: function(sequence, isFirstFrame) {
  6425. var i = 0, len = sequence.transforms.length, _mdf = isFirstFrame;
  6426. while (i < len && !isFirstFrame) {
  6427. if (sequence.transforms[i].transform.mProps._mdf) {
  6428. _mdf = true;
  6429. break;
  6430. }
  6431. i += 1
  6432. }
  6433. if (_mdf) {
  6434. var props;
  6435. sequence.finalTransform.reset();
  6436. for (i = len - 1; i >= 0; i -= 1) {
  6437. props = sequence.transforms[i].transform.mProps.v.props;
  6438. sequence.finalTransform.transform(props[0],props[1],props[2],props[3],props[4],props[5],props[6],props[7],props[8],props[9],props[10],props[11],props[12],props[13],props[14],props[15]);
  6439. }
  6440. }
  6441. sequence._mdf = _mdf;
  6442. },
  6443. processSequences: function(isFirstFrame) {
  6444. var i, len = this.sequenceList.length;
  6445. for (i = 0; i < len; i += 1) {
  6446. this.processSequence(this.sequenceList[i], isFirstFrame);
  6447. }
  6448. },
  6449. getNewKey: function() {
  6450. return '_' + this.transform_key_count++;
  6451. }
  6452. }
  6453. function CVShapeData(element, data, styles, transformsManager) {
  6454. this.styledShapes = [];
  6455. this.tr = [0,0,0,0,0,0];
  6456. var ty = 4;
  6457. if(data.ty == 'rc'){
  6458. ty = 5;
  6459. }else if(data.ty == 'el'){
  6460. ty = 6;
  6461. }else if(data.ty == 'sr'){
  6462. ty = 7;
  6463. }
  6464. this.sh = ShapePropertyFactory.getShapeProp(element,data,ty,element);
  6465. var i , len = styles.length,styledShape;
  6466. for (i = 0; i < len; i += 1) {
  6467. if (!styles[i].closed) {
  6468. styledShape = {
  6469. transforms: transformsManager.addTransformSequence(styles[i].transforms),
  6470. trNodes: []
  6471. }
  6472. this.styledShapes.push(styledShape);
  6473. styles[i].elements.push(styledShape);
  6474. }
  6475. }
  6476. }
  6477. CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated;
  6478. function BaseElement(){
  6479. }
  6480. BaseElement.prototype = {
  6481. checkMasks: function(){
  6482. if(!this.data.hasMask){
  6483. return false;
  6484. }
  6485. var i = 0, len = this.data.masksProperties.length;
  6486. while(i<len) {
  6487. if((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) {
  6488. return true;
  6489. }
  6490. i += 1;
  6491. }
  6492. return false;
  6493. },
  6494. initExpressions: function(){
  6495. this.layerInterface = LayerExpressionInterface(this);
  6496. if(this.data.hasMask && this.maskManager) {
  6497. this.layerInterface.registerMaskInterface(this.maskManager);
  6498. }
  6499. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this,this.layerInterface);
  6500. this.layerInterface.registerEffectsInterface(effectsInterface);
  6501. if(this.data.ty === 0 || this.data.xt){
  6502. this.compInterface = CompExpressionInterface(this);
  6503. } else if(this.data.ty === 4){
  6504. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData,this.itemsData,this.layerInterface);
  6505. this.layerInterface.content = this.layerInterface.shapeInterface;
  6506. } else if(this.data.ty === 5){
  6507. this.layerInterface.textInterface = TextExpressionInterface(this);
  6508. this.layerInterface.text = this.layerInterface.textInterface;
  6509. }
  6510. },
  6511. setBlendMode: function(){
  6512. var blendModeValue = getBlendMode(this.data.bm);
  6513. var elem = this.baseElement || this.layerElement;
  6514. elem.style['mix-blend-mode'] = blendModeValue;
  6515. },
  6516. initBaseData: function(data, globalData, comp){
  6517. this.globalData = globalData;
  6518. this.comp = comp;
  6519. this.data = data;
  6520. this.layerId = createElementID();
  6521. //Stretch factor for old animations missing this property.
  6522. if(!this.data.sr){
  6523. this.data.sr = 1;
  6524. }
  6525. // effects manager
  6526. this.effectsManager = new EffectsManager(this.data,this,this.dynamicProperties);
  6527. },
  6528. getType: function(){
  6529. return this.type;
  6530. }
  6531. ,sourceRectAtTime: function(){}
  6532. }
  6533. function NullElement(data,globalData,comp){
  6534. this.initFrame();
  6535. this.initBaseData(data, globalData, comp);
  6536. this.initFrame();
  6537. this.initTransform(data, globalData, comp);
  6538. this.initHierarchy();
  6539. }
  6540. NullElement.prototype.prepareFrame = function(num) {
  6541. this.prepareProperties(num, true);
  6542. };
  6543. NullElement.prototype.renderFrame = function() {
  6544. };
  6545. NullElement.prototype.getBaseElement = function() {
  6546. return null;
  6547. };
  6548. NullElement.prototype.destroy = function() {
  6549. };
  6550. NullElement.prototype.sourceRectAtTime = function() {
  6551. };
  6552. NullElement.prototype.hide = function() {
  6553. };
  6554. extendPrototype([BaseElement,TransformElement,HierarchyElement,FrameElement], NullElement);
  6555. function SVGBaseElement(){
  6556. }
  6557. SVGBaseElement.prototype = {
  6558. initRendererElement: function() {
  6559. this.layerElement = createNS('g');
  6560. },
  6561. createContainerElements: function(){
  6562. this.matteElement = createNS('g');
  6563. this.transformedElement = this.layerElement;
  6564. this.maskedElement = this.layerElement;
  6565. this._sizeChanged = false;
  6566. var layerElementParent = null;
  6567. //If this layer acts as a mask for the following layer
  6568. var filId, fil, gg;
  6569. if (this.data.td) {
  6570. if (this.data.td == 3 || this.data.td == 1) {
  6571. var masker = createNS('mask');
  6572. masker.setAttribute('id', this.layerId);
  6573. masker.setAttribute('mask-type', this.data.td == 3 ? 'luminance' : 'alpha');
  6574. masker.appendChild(this.layerElement);
  6575. layerElementParent = masker;
  6576. this.globalData.defs.appendChild(masker);
  6577. // This is only for IE and Edge when mask if of type alpha
  6578. if (!featureSupport.maskType && this.data.td == 1) {
  6579. masker.setAttribute('mask-type', 'luminance');
  6580. filId = createElementID();
  6581. fil = filtersFactory.createFilter(filId);
  6582. this.globalData.defs.appendChild(fil);
  6583. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  6584. gg = createNS('g');
  6585. gg.appendChild(this.layerElement);
  6586. layerElementParent = gg;
  6587. masker.appendChild(gg);
  6588. gg.setAttribute('filter','url(' + locationHref + '#' + filId + ')');
  6589. }
  6590. } else if(this.data.td == 2) {
  6591. var maskGroup = createNS('mask');
  6592. maskGroup.setAttribute('id', this.layerId);
  6593. maskGroup.setAttribute('mask-type','alpha');
  6594. var maskGrouper = createNS('g');
  6595. maskGroup.appendChild(maskGrouper);
  6596. filId = createElementID();
  6597. fil = filtersFactory.createFilter(filId);
  6598. ////
  6599. // This solution doesn't work on Android when meta tag with viewport attribute is set
  6600. /*var feColorMatrix = createNS('feColorMatrix');
  6601. feColorMatrix.setAttribute('type', 'matrix');
  6602. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  6603. feColorMatrix.setAttribute('values','1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 -1 1');
  6604. fil.appendChild(feColorMatrix);*/
  6605. ////
  6606. var feCTr = createNS('feComponentTransfer');
  6607. feCTr.setAttribute('in','SourceGraphic');
  6608. fil.appendChild(feCTr);
  6609. var feFunc = createNS('feFuncA');
  6610. feFunc.setAttribute('type','table');
  6611. feFunc.setAttribute('tableValues','1.0 0.0');
  6612. feCTr.appendChild(feFunc);
  6613. ////
  6614. this.globalData.defs.appendChild(fil);
  6615. var alphaRect = createNS('rect');
  6616. alphaRect.setAttribute('width', this.comp.data.w);
  6617. alphaRect.setAttribute('height', this.comp.data.h);
  6618. alphaRect.setAttribute('x','0');
  6619. alphaRect.setAttribute('y','0');
  6620. alphaRect.setAttribute('fill','#ffffff');
  6621. alphaRect.setAttribute('opacity','0');
  6622. maskGrouper.setAttribute('filter', 'url(' + locationHref + '#'+filId+')');
  6623. maskGrouper.appendChild(alphaRect);
  6624. maskGrouper.appendChild(this.layerElement);
  6625. layerElementParent = maskGrouper;
  6626. if (!featureSupport.maskType) {
  6627. maskGroup.setAttribute('mask-type', 'luminance');
  6628. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  6629. gg = createNS('g');
  6630. maskGrouper.appendChild(alphaRect);
  6631. gg.appendChild(this.layerElement);
  6632. layerElementParent = gg;
  6633. maskGrouper.appendChild(gg);
  6634. }
  6635. this.globalData.defs.appendChild(maskGroup);
  6636. }
  6637. } else if (this.data.tt) {
  6638. this.matteElement.appendChild(this.layerElement);
  6639. layerElementParent = this.matteElement;
  6640. this.baseElement = this.matteElement;
  6641. } else {
  6642. this.baseElement = this.layerElement;
  6643. }
  6644. if (this.data.ln) {
  6645. this.layerElement.setAttribute('id', this.data.ln);
  6646. }
  6647. if (this.data.cl) {
  6648. this.layerElement.setAttribute('class', this.data.cl);
  6649. }
  6650. //Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  6651. if (this.data.ty === 0 && !this.data.hd) {
  6652. var cp = createNS( 'clipPath');
  6653. var pt = createNS('path');
  6654. pt.setAttribute('d','M0,0 L' + this.data.w + ',0' + ' L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  6655. var clipId = createElementID();
  6656. cp.setAttribute('id',clipId);
  6657. cp.appendChild(pt);
  6658. this.globalData.defs.appendChild(cp);
  6659. if (this.checkMasks()) {
  6660. var cpGroup = createNS('g');
  6661. cpGroup.setAttribute('clip-path','url(' + locationHref + '#'+clipId + ')');
  6662. cpGroup.appendChild(this.layerElement);
  6663. this.transformedElement = cpGroup;
  6664. if (layerElementParent) {
  6665. layerElementParent.appendChild(this.transformedElement);
  6666. } else {
  6667. this.baseElement = this.transformedElement;
  6668. }
  6669. } else {
  6670. this.layerElement.setAttribute('clip-path','url(' + locationHref + '#'+clipId+')');
  6671. }
  6672. }
  6673. if (this.data.bm !== 0) {
  6674. this.setBlendMode();
  6675. }
  6676. },
  6677. renderElement: function() {
  6678. if (this.finalTransform._matMdf) {
  6679. this.transformedElement.setAttribute('transform', this.finalTransform.mat.to2dCSS());
  6680. }
  6681. if (this.finalTransform._opMdf) {
  6682. this.transformedElement.setAttribute('opacity', this.finalTransform.mProp.o.v);
  6683. }
  6684. },
  6685. destroyBaseElement: function() {
  6686. this.layerElement = null;
  6687. this.matteElement = null;
  6688. this.maskManager.destroy();
  6689. },
  6690. getBaseElement: function() {
  6691. if (this.data.hd) {
  6692. return null;
  6693. }
  6694. return this.baseElement;
  6695. },
  6696. createRenderableComponents: function() {
  6697. this.maskManager = new MaskElement(this.data, this, this.globalData);
  6698. this.renderableEffectsManager = new SVGEffects(this);
  6699. },
  6700. setMatte: function(id) {
  6701. if (!this.matteElement) {
  6702. return;
  6703. }
  6704. this.matteElement.setAttribute("mask", "url(" + locationHref + "#" + id + ")");
  6705. }
  6706. };
  6707. function IShapeElement(){
  6708. }
  6709. IShapeElement.prototype = {
  6710. addShapeToModifiers: function(data) {
  6711. var i, len = this.shapeModifiers.length;
  6712. for(i=0;i<len;i+=1){
  6713. this.shapeModifiers[i].addShape(data);
  6714. }
  6715. },
  6716. isShapeInAnimatedModifiers: function(data) {
  6717. var i = 0, len = this.shapeModifiers.length;
  6718. while(i < len) {
  6719. if(this.shapeModifiers[i].isAnimatedWithShape(data)) {
  6720. return true;
  6721. }
  6722. }
  6723. return false;
  6724. },
  6725. renderModifiers: function() {
  6726. if(!this.shapeModifiers.length){
  6727. return;
  6728. }
  6729. var i, len = this.shapes.length;
  6730. for(i=0;i<len;i+=1){
  6731. this.shapes[i].sh.reset();
  6732. }
  6733. len = this.shapeModifiers.length;
  6734. for(i=len-1;i>=0;i-=1){
  6735. this.shapeModifiers[i].processShapes(this._isFirstFrame);
  6736. }
  6737. },
  6738. lcEnum: {
  6739. '1': 'butt',
  6740. '2': 'round',
  6741. '3': 'square'
  6742. },
  6743. ljEnum: {
  6744. '1': 'miter',
  6745. '2': 'round',
  6746. '3': 'bevel'
  6747. },
  6748. searchProcessedElement: function(elem){
  6749. var elements = this.processedElements;
  6750. var i = 0, len = elements.length;
  6751. while (i < len) {
  6752. if (elements[i].elem === elem) {
  6753. return elements[i].pos;
  6754. }
  6755. i += 1;
  6756. }
  6757. return 0;
  6758. },
  6759. addProcessedElement: function(elem, pos){
  6760. var elements = this.processedElements;
  6761. var i = elements.length;
  6762. while(i) {
  6763. i -= 1;
  6764. if (elements[i].elem === elem) {
  6765. elements[i].pos = pos;
  6766. return;
  6767. }
  6768. }
  6769. elements.push(new ProcessedElement(elem, pos));
  6770. },
  6771. prepareFrame: function(num) {
  6772. this.prepareRenderableFrame(num);
  6773. this.prepareProperties(num, this.isInRange);
  6774. }
  6775. };
  6776. function ITextElement(){
  6777. }
  6778. ITextElement.prototype.initElement = function(data,globalData,comp){
  6779. this.lettersChangedFlag = true;
  6780. this.initFrame();
  6781. this.initBaseData(data, globalData, comp);
  6782. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  6783. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  6784. this.initTransform(data, globalData, comp);
  6785. this.initHierarchy();
  6786. this.initRenderable();
  6787. this.initRendererElement();
  6788. this.createContainerElements();
  6789. this.createRenderableComponents();
  6790. this.createContent();
  6791. this.hide();
  6792. this.textAnimator.searchProperties(this.dynamicProperties);
  6793. };
  6794. ITextElement.prototype.prepareFrame = function(num) {
  6795. this._mdf = false;
  6796. this.prepareRenderableFrame(num);
  6797. this.prepareProperties(num, this.isInRange);
  6798. if(this.textProperty._mdf || this.textProperty._isFirstFrame) {
  6799. this.buildNewText();
  6800. this.textProperty._isFirstFrame = false;
  6801. this.textProperty._mdf = false;
  6802. }
  6803. };
  6804. ITextElement.prototype.createPathShape = function(matrixHelper, shapes) {
  6805. var j,jLen = shapes.length;
  6806. var k, kLen, pathNodes;
  6807. var shapeStr = '';
  6808. for(j=0;j<jLen;j+=1){
  6809. pathNodes = shapes[j].ks.k;
  6810. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  6811. }
  6812. return shapeStr;
  6813. };
  6814. ITextElement.prototype.updateDocumentData = function(newData, index) {
  6815. this.textProperty.updateDocumentData(newData, index);
  6816. };
  6817. ITextElement.prototype.canResizeFont = function(_canResize) {
  6818. this.textProperty.canResizeFont(_canResize);
  6819. };
  6820. ITextElement.prototype.setMinimumFontSize = function(_fontSize) {
  6821. this.textProperty.setMinimumFontSize(_fontSize);
  6822. };
  6823. ITextElement.prototype.applyTextPropertiesToMatrix = function(documentData, matrixHelper, lineNumber, xPos, yPos) {
  6824. if(documentData.ps){
  6825. matrixHelper.translate(documentData.ps[0],documentData.ps[1] + documentData.ascent,0);
  6826. }
  6827. matrixHelper.translate(0,-documentData.ls,0);
  6828. switch(documentData.j){
  6829. case 1:
  6830. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]),0,0);
  6831. break;
  6832. case 2:
  6833. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber] )/2,0,0);
  6834. break;
  6835. }
  6836. matrixHelper.translate(xPos, yPos, 0);
  6837. };
  6838. ITextElement.prototype.buildColor = function(colorData) {
  6839. return 'rgb(' + Math.round(colorData[0]*255) + ',' + Math.round(colorData[1]*255) + ',' + Math.round(colorData[2]*255) + ')';
  6840. };
  6841. ITextElement.prototype.emptyProp = new LetterProps();
  6842. ITextElement.prototype.destroy = function(){
  6843. };
  6844. function ICompElement(){}
  6845. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  6846. ICompElement.prototype.initElement = function(data,globalData,comp) {
  6847. this.initFrame();
  6848. this.initBaseData(data, globalData, comp);
  6849. this.initTransform(data, globalData, comp);
  6850. this.initRenderable();
  6851. this.initHierarchy();
  6852. this.initRendererElement();
  6853. this.createContainerElements();
  6854. this.createRenderableComponents();
  6855. if(this.data.xt || !globalData.progressiveLoad){
  6856. this.buildAllItems();
  6857. }
  6858. this.hide();
  6859. };
  6860. /*ICompElement.prototype.hide = function(){
  6861. if(!this.hidden){
  6862. this.hideElement();
  6863. var i,len = this.elements.length;
  6864. for( i = 0; i < len; i+=1 ){
  6865. if(this.elements[i]){
  6866. this.elements[i].hide();
  6867. }
  6868. }
  6869. }
  6870. };*/
  6871. ICompElement.prototype.prepareFrame = function(num){
  6872. this._mdf = false;
  6873. this.prepareRenderableFrame(num);
  6874. this.prepareProperties(num, this.isInRange);
  6875. if(!this.isInRange && !this.data.xt){
  6876. return;
  6877. }
  6878. if (!this.tm._placeholder) {
  6879. var timeRemapped = this.tm.v;
  6880. if(timeRemapped === this.data.op){
  6881. timeRemapped = this.data.op - 1;
  6882. }
  6883. this.renderedFrame = timeRemapped;
  6884. } else {
  6885. this.renderedFrame = num/this.data.sr;
  6886. }
  6887. var i,len = this.elements.length;
  6888. if(!this.completeLayers){
  6889. this.checkLayers(this.renderedFrame);
  6890. }
  6891. //This iteration needs to be backwards because of how expressions connect between each other
  6892. for( i = len - 1; i >= 0; i -= 1 ){
  6893. if(this.completeLayers || this.elements[i]){
  6894. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  6895. if(this.elements[i]._mdf) {
  6896. this._mdf = true;
  6897. }
  6898. }
  6899. }
  6900. };
  6901. ICompElement.prototype.renderInnerContent = function() {
  6902. var i,len = this.layers.length;
  6903. for( i = 0; i < len; i += 1 ){
  6904. if(this.completeLayers || this.elements[i]){
  6905. this.elements[i].renderFrame();
  6906. }
  6907. }
  6908. };
  6909. ICompElement.prototype.setElements = function(elems){
  6910. this.elements = elems;
  6911. };
  6912. ICompElement.prototype.getElements = function(){
  6913. return this.elements;
  6914. };
  6915. ICompElement.prototype.destroyElements = function(){
  6916. var i,len = this.layers.length;
  6917. for( i = 0; i < len; i+=1 ){
  6918. if(this.elements[i]){
  6919. this.elements[i].destroy();
  6920. }
  6921. }
  6922. };
  6923. ICompElement.prototype.destroy = function(){
  6924. this.destroyElements();
  6925. this.destroyBaseElement();
  6926. };
  6927. function IImageElement(data,globalData,comp){
  6928. this.assetData = globalData.getAssetData(data.refId);
  6929. this.initElement(data,globalData,comp);
  6930. this.sourceRect = {top:0,left:0,width:this.assetData.w,height:this.assetData.h};
  6931. }
  6932. extendPrototype([BaseElement,TransformElement,SVGBaseElement,HierarchyElement,FrameElement,RenderableDOMElement], IImageElement);
  6933. IImageElement.prototype.createContent = function(){
  6934. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6935. this.innerElem = createNS('image');
  6936. this.innerElem.setAttribute('width',this.assetData.w+"px");
  6937. this.innerElem.setAttribute('height',this.assetData.h+"px");
  6938. this.innerElem.setAttribute('preserveAspectRatio',this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  6939. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink','href',assetPath);
  6940. this.layerElement.appendChild(this.innerElem);
  6941. };
  6942. IImageElement.prototype.sourceRectAtTime = function() {
  6943. return this.sourceRect;
  6944. }
  6945. function ISolidElement(data,globalData,comp){
  6946. this.initElement(data,globalData,comp);
  6947. }
  6948. extendPrototype([IImageElement], ISolidElement);
  6949. ISolidElement.prototype.createContent = function(){
  6950. var rect = createNS('rect');
  6951. ////rect.style.width = this.data.sw;
  6952. ////rect.style.height = this.data.sh;
  6953. ////rect.style.fill = this.data.sc;
  6954. rect.setAttribute('width',this.data.sw);
  6955. rect.setAttribute('height',this.data.sh);
  6956. rect.setAttribute('fill',this.data.sc);
  6957. this.layerElement.appendChild(rect);
  6958. };
  6959. function SVGShapeElement(data,globalData,comp){
  6960. //List of drawable elements
  6961. this.shapes = [];
  6962. // Full shape data
  6963. this.shapesData = data.shapes;
  6964. //List of styles that will be applied to shapes
  6965. this.stylesList = [];
  6966. //List of modifiers that will be applied to shapes
  6967. this.shapeModifiers = [];
  6968. //List of items in shape tree
  6969. this.itemsData = [];
  6970. //List of items in previous shape tree
  6971. this.processedElements = [];
  6972. // List of animated components
  6973. this.animatedContents = [];
  6974. this.initElement(data,globalData,comp);
  6975. //Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  6976. // List of elements that have been created
  6977. this.prevViewData = [];
  6978. //Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  6979. }
  6980. extendPrototype([BaseElement,TransformElement,SVGBaseElement,IShapeElement,HierarchyElement,FrameElement,RenderableDOMElement], SVGShapeElement);
  6981. SVGShapeElement.prototype.initSecondaryElement = function() {
  6982. };
  6983. SVGShapeElement.prototype.identityMatrix = new Matrix();
  6984. SVGShapeElement.prototype.buildExpressionInterface = function(){};
  6985. SVGShapeElement.prototype.createContent = function(){
  6986. this.searchShapes(this.shapesData,this.itemsData,this.prevViewData,this.layerElement, 0, [], true);
  6987. this.filterUniqueShapes();
  6988. };
  6989. /*
  6990. This method searches for multiple shapes that affect a single element and one of them is animated
  6991. */
  6992. SVGShapeElement.prototype.filterUniqueShapes = function(){
  6993. var i, len = this.shapes.length, shape;
  6994. var j, jLen = this.stylesList.length;
  6995. var style, count = 0;
  6996. var tempShapes = [];
  6997. var areAnimated = false;
  6998. for(j = 0; j < jLen; j += 1) {
  6999. style = this.stylesList[j];
  7000. areAnimated = false;
  7001. tempShapes.length = 0;
  7002. for(i = 0; i < len; i += 1) {
  7003. shape = this.shapes[i];
  7004. if(shape.styles.indexOf(style) !== -1) {
  7005. tempShapes.push(shape);
  7006. areAnimated = shape._isAnimated || areAnimated;
  7007. }
  7008. }
  7009. if(tempShapes.length > 1 && areAnimated) {
  7010. this.setShapesAsAnimated(tempShapes);
  7011. }
  7012. }
  7013. }
  7014. SVGShapeElement.prototype.setShapesAsAnimated = function(shapes){
  7015. var i, len = shapes.length;
  7016. for(i = 0; i < len; i += 1) {
  7017. shapes[i].setAsAnimated();
  7018. }
  7019. }
  7020. SVGShapeElement.prototype.createStyleElement = function(data, level){
  7021. //TODO: prevent drawing of hidden styles
  7022. var elementData;
  7023. var styleOb = new SVGStyleData(data, level);
  7024. var pathElement = styleOb.pElem;
  7025. if(data.ty === 'st') {
  7026. elementData = new SVGStrokeStyleData(this, data, styleOb);
  7027. } else if(data.ty === 'fl') {
  7028. elementData = new SVGFillStyleData(this, data, styleOb);
  7029. } else if(data.ty === 'gf' || data.ty === 'gs') {
  7030. var gradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  7031. elementData = new gradientConstructor(this, data, styleOb);
  7032. this.globalData.defs.appendChild(elementData.gf);
  7033. if (elementData.maskId) {
  7034. this.globalData.defs.appendChild(elementData.ms);
  7035. this.globalData.defs.appendChild(elementData.of);
  7036. pathElement.setAttribute('mask','url(' + locationHref + '#' + elementData.maskId + ')');
  7037. }
  7038. }
  7039. if(data.ty === 'st' || data.ty === 'gs') {
  7040. pathElement.setAttribute('stroke-linecap', this.lcEnum[data.lc] || 'round');
  7041. pathElement.setAttribute('stroke-linejoin',this.ljEnum[data.lj] || 'round');
  7042. pathElement.setAttribute('fill-opacity','0');
  7043. if(data.lj === 1) {
  7044. pathElement.setAttribute('stroke-miterlimit',data.ml);
  7045. }
  7046. }
  7047. if(data.r === 2) {
  7048. pathElement.setAttribute('fill-rule', 'evenodd');
  7049. }
  7050. if(data.ln){
  7051. pathElement.setAttribute('id',data.ln);
  7052. }
  7053. if(data.cl){
  7054. pathElement.setAttribute('class',data.cl);
  7055. }
  7056. if(data.bm){
  7057. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  7058. }
  7059. this.stylesList.push(styleOb);
  7060. this.addToAnimatedContents(data, elementData);
  7061. return elementData;
  7062. };
  7063. SVGShapeElement.prototype.createGroupElement = function(data) {
  7064. var elementData = new ShapeGroupData();
  7065. if(data.ln){
  7066. elementData.gr.setAttribute('id',data.ln);
  7067. }
  7068. if(data.cl){
  7069. elementData.gr.setAttribute('class',data.cl);
  7070. }
  7071. if(data.bm){
  7072. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  7073. }
  7074. return elementData;
  7075. };
  7076. SVGShapeElement.prototype.createTransformElement = function(data, container) {
  7077. var transformProperty = TransformPropertyFactory.getTransformProperty(this,data,this);
  7078. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  7079. this.addToAnimatedContents(data, elementData);
  7080. return elementData;
  7081. };
  7082. SVGShapeElement.prototype.createShapeElement = function(data, ownTransformers, level) {
  7083. var ty = 4;
  7084. if(data.ty === 'rc'){
  7085. ty = 5;
  7086. }else if(data.ty === 'el'){
  7087. ty = 6;
  7088. }else if(data.ty === 'sr'){
  7089. ty = 7;
  7090. }
  7091. var shapeProperty = ShapePropertyFactory.getShapeProp(this,data,ty,this);
  7092. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  7093. this.shapes.push(elementData);
  7094. this.addShapeToModifiers(elementData);
  7095. this.addToAnimatedContents(data, elementData);
  7096. return elementData;
  7097. };
  7098. SVGShapeElement.prototype.addToAnimatedContents = function(data, element) {
  7099. var i = 0, len = this.animatedContents.length;
  7100. while(i < len) {
  7101. if(this.animatedContents[i].element === element) {
  7102. return;
  7103. }
  7104. i += 1;
  7105. }
  7106. this.animatedContents.push({
  7107. fn: SVGElementsRenderer.createRenderFunction(data),
  7108. element: element,
  7109. data: data
  7110. });
  7111. };
  7112. SVGShapeElement.prototype.setElementStyles = function(elementData){
  7113. var arr = elementData.styles;
  7114. var j, jLen = this.stylesList.length;
  7115. for (j = 0; j < jLen; j += 1) {
  7116. if (!this.stylesList[j].closed) {
  7117. arr.push(this.stylesList[j]);
  7118. }
  7119. }
  7120. };
  7121. SVGShapeElement.prototype.reloadShapes = function(){
  7122. this._isFirstFrame = true;
  7123. var i, len = this.itemsData.length;
  7124. for( i = 0; i < len; i += 1) {
  7125. this.prevViewData[i] = this.itemsData[i];
  7126. }
  7127. this.searchShapes(this.shapesData,this.itemsData,this.prevViewData,this.layerElement, 0, [], true);
  7128. this.filterUniqueShapes();
  7129. len = this.dynamicProperties.length;
  7130. for(i = 0; i < len; i += 1) {
  7131. this.dynamicProperties[i].getValue();
  7132. }
  7133. this.renderModifiers();
  7134. };
  7135. SVGShapeElement.prototype.searchShapes = function(arr,itemsData,prevViewData,container, level, transformers, render){
  7136. var ownTransformers = [].concat(transformers);
  7137. var i, len = arr.length - 1;
  7138. var j, jLen;
  7139. var ownStyles = [], ownModifiers = [], styleOb, currentTransform, modifier, processedPos;
  7140. for(i=len;i>=0;i-=1){
  7141. processedPos = this.searchProcessedElement(arr[i]);
  7142. if(!processedPos){
  7143. arr[i]._render = render;
  7144. } else {
  7145. itemsData[i] = prevViewData[processedPos - 1];
  7146. }
  7147. if(arr[i].ty == 'fl' || arr[i].ty == 'st' || arr[i].ty == 'gf' || arr[i].ty == 'gs'){
  7148. if(!processedPos){
  7149. itemsData[i] = this.createStyleElement(arr[i], level);
  7150. } else {
  7151. itemsData[i].style.closed = false;
  7152. }
  7153. if(arr[i]._render){
  7154. container.appendChild(itemsData[i].style.pElem);
  7155. }
  7156. ownStyles.push(itemsData[i].style);
  7157. }else if(arr[i].ty == 'gr'){
  7158. if(!processedPos){
  7159. itemsData[i] = this.createGroupElement(arr[i]);
  7160. } else {
  7161. jLen = itemsData[i].it.length;
  7162. for(j=0;j<jLen;j+=1){
  7163. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  7164. }
  7165. }
  7166. this.searchShapes(arr[i].it,itemsData[i].it,itemsData[i].prevViewData,itemsData[i].gr, level + 1, ownTransformers, render);
  7167. if(arr[i]._render){
  7168. container.appendChild(itemsData[i].gr);
  7169. }
  7170. }else if(arr[i].ty == 'tr'){
  7171. if(!processedPos){
  7172. itemsData[i] = this.createTransformElement(arr[i], container);
  7173. }
  7174. currentTransform = itemsData[i].transform;
  7175. ownTransformers.push(currentTransform);
  7176. }else if(arr[i].ty == 'sh' || arr[i].ty == 'rc' || arr[i].ty == 'el' || arr[i].ty == 'sr'){
  7177. if(!processedPos){
  7178. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  7179. }
  7180. this.setElementStyles(itemsData[i]);
  7181. }else if(arr[i].ty == 'tm' || arr[i].ty == 'rd' || arr[i].ty == 'ms'){
  7182. if(!processedPos){
  7183. modifier = ShapeModifiers.getModifier(arr[i].ty);
  7184. modifier.init(this,arr[i]);
  7185. itemsData[i] = modifier;
  7186. this.shapeModifiers.push(modifier);
  7187. } else {
  7188. modifier = itemsData[i];
  7189. modifier.closed = false;
  7190. }
  7191. ownModifiers.push(modifier);
  7192. }else if(arr[i].ty == 'rp'){
  7193. if(!processedPos){
  7194. modifier = ShapeModifiers.getModifier(arr[i].ty);
  7195. itemsData[i] = modifier;
  7196. modifier.init(this,arr,i,itemsData);
  7197. this.shapeModifiers.push(modifier);
  7198. render = false;
  7199. }else{
  7200. modifier = itemsData[i];
  7201. modifier.closed = true;
  7202. }
  7203. ownModifiers.push(modifier);
  7204. }
  7205. this.addProcessedElement(arr[i], i + 1);
  7206. }
  7207. len = ownStyles.length;
  7208. for(i=0;i<len;i+=1){
  7209. ownStyles[i].closed = true;
  7210. }
  7211. len = ownModifiers.length;
  7212. for(i=0;i<len;i+=1){
  7213. ownModifiers[i].closed = true;
  7214. }
  7215. };
  7216. SVGShapeElement.prototype.renderInnerContent = function() {
  7217. this.renderModifiers();
  7218. var i, len = this.stylesList.length;
  7219. for(i=0;i<len;i+=1){
  7220. this.stylesList[i].reset();
  7221. }
  7222. this.renderShape();
  7223. for (i = 0; i < len; i += 1) {
  7224. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  7225. if(this.stylesList[i].msElem){
  7226. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  7227. //Adding M0 0 fixes same mask bug on all browsers
  7228. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  7229. }
  7230. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  7231. }
  7232. }
  7233. };
  7234. SVGShapeElement.prototype.renderShape = function() {
  7235. var i, len = this.animatedContents.length;
  7236. var animatedContent;
  7237. for(i = 0; i < len; i += 1) {
  7238. animatedContent = this.animatedContents[i];
  7239. if((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  7240. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  7241. }
  7242. }
  7243. }
  7244. SVGShapeElement.prototype.destroy = function(){
  7245. this.destroyBaseElement();
  7246. this.shapesData = null;
  7247. this.itemsData = null;
  7248. };
  7249. function CVContextData() {
  7250. this.saved = [];
  7251. this.cArrPos = 0;
  7252. this.cTr = new Matrix();
  7253. this.cO = 1;
  7254. var i, len = 15;
  7255. this.savedOp = createTypedArray('float32', len);
  7256. for(i=0;i<len;i+=1){
  7257. this.saved[i] = createTypedArray('float32', 16);
  7258. }
  7259. this._length = len;
  7260. }
  7261. CVContextData.prototype.duplicate = function() {
  7262. var newLength = this._length * 2;
  7263. var currentSavedOp = this.savedOp;
  7264. this.savedOp = createTypedArray('float32', newLength);
  7265. this.savedOp.set(currentSavedOp);
  7266. var i = 0;
  7267. for(i = this._length; i < newLength; i += 1) {
  7268. this.saved[i] = createTypedArray('float32', 16);
  7269. }
  7270. this._length = newLength;
  7271. };
  7272. CVContextData.prototype.reset = function() {
  7273. this.cArrPos = 0;
  7274. this.cTr.reset();
  7275. this.cO = 1;
  7276. };
  7277. function CVBaseElement(){
  7278. }
  7279. CVBaseElement.prototype = {
  7280. createElements: function(){},
  7281. initRendererElement: function(){},
  7282. createContainerElements: function(){
  7283. this.canvasContext = this.globalData.canvasContext;
  7284. this.renderableEffectsManager = new CVEffects(this);
  7285. },
  7286. createContent: function(){},
  7287. setBlendMode: function(){
  7288. var globalData = this.globalData;
  7289. if(globalData.blendMode !== this.data.bm) {
  7290. globalData.blendMode = this.data.bm;
  7291. var blendModeValue = getBlendMode(this.data.bm);
  7292. globalData.canvasContext.globalCompositeOperation = blendModeValue;
  7293. }
  7294. },
  7295. createRenderableComponents: function(){
  7296. this.maskManager = new CVMaskElement(this.data, this);
  7297. },
  7298. hideElement: function(){
  7299. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7300. this.hidden = true;
  7301. }
  7302. },
  7303. showElement: function(){
  7304. if (this.isInRange && !this.isTransparent){
  7305. this.hidden = false;
  7306. this._isFirstFrame = true;
  7307. this.maskManager._isFirstFrame = true;
  7308. }
  7309. },
  7310. renderFrame: function() {
  7311. if (this.hidden || this.data.hd) {
  7312. return;
  7313. }
  7314. this.renderTransform();
  7315. this.renderRenderable();
  7316. this.setBlendMode();
  7317. this.globalData.renderer.save();
  7318. this.globalData.renderer.ctxTransform(this.finalTransform.mat.props);
  7319. this.globalData.renderer.ctxOpacity(this.finalTransform.mProp.o.v);
  7320. this.renderInnerContent();
  7321. this.globalData.renderer.restore();
  7322. if(this.maskManager.hasMasks) {
  7323. this.globalData.renderer.restore(true);
  7324. }
  7325. if (this._isFirstFrame) {
  7326. this._isFirstFrame = false;
  7327. }
  7328. },
  7329. destroy: function(){
  7330. this.canvasContext = null;
  7331. this.data = null;
  7332. this.globalData = null;
  7333. this.maskManager.destroy();
  7334. },
  7335. mHelper: new Matrix()
  7336. };
  7337. CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement;
  7338. CVBaseElement.prototype.show = CVBaseElement.prototype.showElement;
  7339. function CVCompElement(data, globalData, comp) {
  7340. this.completeLayers = false;
  7341. this.layers = data.layers;
  7342. this.pendingElements = [];
  7343. this.elements = createSizedArray(this.layers.length);
  7344. this.initElement(data, globalData, comp);
  7345. this.tm = data.tm ? PropertyFactory.getProp(this,data.tm,0,globalData.frameRate, this) : {_placeholder:true};
  7346. }
  7347. extendPrototype([CanvasRenderer, ICompElement, CVBaseElement], CVCompElement);
  7348. CVCompElement.prototype.renderInnerContent = function() {
  7349. var i,len = this.layers.length;
  7350. for( i = len - 1; i >= 0; i -= 1 ){
  7351. if(this.completeLayers || this.elements[i]){
  7352. this.elements[i].renderFrame();
  7353. }
  7354. }
  7355. };
  7356. CVCompElement.prototype.destroy = function(){
  7357. var i,len = this.layers.length;
  7358. for( i = len - 1; i >= 0; i -= 1 ){
  7359. if(this.elements[i]) {
  7360. this.elements[i].destroy();
  7361. }
  7362. }
  7363. this.layers = null;
  7364. this.elements = null;
  7365. };
  7366. function CVMaskElement(data,element){
  7367. this.data = data;
  7368. this.element = element;
  7369. this.masksProperties = this.data.masksProperties || [];
  7370. this.viewData = createSizedArray(this.masksProperties.length);
  7371. var i, len = this.masksProperties.length, hasMasks = false;
  7372. for (i = 0; i < len; i++) {
  7373. if(this.masksProperties[i].mode !== 'n'){
  7374. hasMasks = true;
  7375. }
  7376. this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element,this.masksProperties[i],3);
  7377. }
  7378. this.hasMasks = hasMasks;
  7379. if(hasMasks) {
  7380. this.element.addRenderableComponent(this);
  7381. }
  7382. }
  7383. CVMaskElement.prototype.renderFrame = function () {
  7384. if(!this.hasMasks){
  7385. return;
  7386. }
  7387. var transform = this.element.finalTransform.mat;
  7388. var ctx = this.element.canvasContext;
  7389. var i, len = this.masksProperties.length;
  7390. var pt,pts,data;
  7391. ctx.beginPath();
  7392. for (i = 0; i < len; i++) {
  7393. if(this.masksProperties[i].mode !== 'n'){
  7394. if (this.masksProperties[i].inv) {
  7395. ctx.moveTo(0, 0);
  7396. ctx.lineTo(this.element.globalData.compSize.w, 0);
  7397. ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h);
  7398. ctx.lineTo(0, this.element.globalData.compSize.h);
  7399. ctx.lineTo(0, 0);
  7400. }
  7401. data = this.viewData[i].v;
  7402. pt = transform.applyToPointArray(data.v[0][0],data.v[0][1],0);
  7403. ctx.moveTo(pt[0], pt[1]);
  7404. var j, jLen = data._length;
  7405. for (j = 1; j < jLen; j++) {
  7406. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]);
  7407. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  7408. }
  7409. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]);
  7410. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  7411. }
  7412. }
  7413. this.element.globalData.renderer.save(true);
  7414. ctx.clip();
  7415. };
  7416. CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty;
  7417. CVMaskElement.prototype.destroy = function(){
  7418. this.element = null;
  7419. };
  7420. function CVShapeElement(data, globalData, comp) {
  7421. this.shapes = [];
  7422. this.shapesData = data.shapes;
  7423. this.stylesList = [];
  7424. this.itemsData = [];
  7425. this.prevViewData = [];
  7426. this.shapeModifiers = [];
  7427. this.processedElements = [];
  7428. this.transformsManager = new ShapeTransformManager();
  7429. this.initElement(data, globalData, comp);
  7430. }
  7431. extendPrototype([BaseElement,TransformElement,CVBaseElement,IShapeElement,HierarchyElement,FrameElement,RenderableElement], CVShapeElement);
  7432. CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement;
  7433. CVShapeElement.prototype.transformHelper = {opacity:1,_opMdf:false};
  7434. CVShapeElement.prototype.dashResetter = [];
  7435. CVShapeElement.prototype.createContent = function(){
  7436. this.searchShapes(this.shapesData,this.itemsData,this.prevViewData, true, []);
  7437. };
  7438. CVShapeElement.prototype.createStyleElement = function(data, transforms) {
  7439. var styleElem = {
  7440. data: data,
  7441. type: data.ty,
  7442. preTransforms: this.transformsManager.addTransformSequence(transforms),
  7443. transforms: [],
  7444. elements: [],
  7445. closed: data.hd === true
  7446. };
  7447. var elementData = {};
  7448. if(data.ty == 'fl' || data.ty == 'st'){
  7449. elementData.c = PropertyFactory.getProp(this,data.c,1,255,this);
  7450. if(!elementData.c.k){
  7451. styleElem.co = 'rgb('+bm_floor(elementData.c.v[0])+','+bm_floor(elementData.c.v[1])+','+bm_floor(elementData.c.v[2])+')';
  7452. }
  7453. } else if (data.ty === 'gf' || data.ty === 'gs') {
  7454. elementData.s = PropertyFactory.getProp(this,data.s,1,null,this);
  7455. elementData.e = PropertyFactory.getProp(this,data.e,1,null,this);
  7456. elementData.h = PropertyFactory.getProp(this,data.h||{k:0},0,0.01,this);
  7457. elementData.a = PropertyFactory.getProp(this,data.a||{k:0},0,degToRads,this);
  7458. elementData.g = new GradientProperty(this,data.g,this);
  7459. }
  7460. elementData.o = PropertyFactory.getProp(this,data.o,0,0.01,this);
  7461. if(data.ty == 'st' || data.ty == 'gs') {
  7462. styleElem.lc = this.lcEnum[data.lc] || 'round';
  7463. styleElem.lj = this.ljEnum[data.lj] || 'round';
  7464. if(data.lj == 1) {
  7465. styleElem.ml = data.ml;
  7466. }
  7467. elementData.w = PropertyFactory.getProp(this,data.w,0,null,this);
  7468. if(!elementData.w.k){
  7469. styleElem.wi = elementData.w.v;
  7470. }
  7471. if(data.d){
  7472. var d = new DashProperty(this,data.d,'canvas', this);
  7473. elementData.d = d;
  7474. if(!elementData.d.k){
  7475. styleElem.da = elementData.d.dashArray;
  7476. styleElem.do = elementData.d.dashoffset[0];
  7477. }
  7478. }
  7479. } else {
  7480. styleElem.r = data.r === 2 ? 'evenodd' : 'nonzero';
  7481. }
  7482. this.stylesList.push(styleElem);
  7483. elementData.style = styleElem;
  7484. return elementData;
  7485. };
  7486. CVShapeElement.prototype.createGroupElement = function(data) {
  7487. var elementData = {
  7488. it: [],
  7489. prevViewData: []
  7490. };
  7491. return elementData;
  7492. };
  7493. CVShapeElement.prototype.createTransformElement = function(data) {
  7494. var elementData = {
  7495. transform : {
  7496. opacity: 1,
  7497. _opMdf:false,
  7498. key: this.transformsManager.getNewKey(),
  7499. op: PropertyFactory.getProp(this,data.o,0,0.01,this),
  7500. mProps: TransformPropertyFactory.getTransformProperty(this,data,this)
  7501. }
  7502. };
  7503. return elementData;
  7504. };
  7505. CVShapeElement.prototype.createShapeElement = function(data) {
  7506. var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager);
  7507. this.shapes.push(elementData);
  7508. this.addShapeToModifiers(elementData);
  7509. return elementData;
  7510. };
  7511. CVShapeElement.prototype.reloadShapes = function() {
  7512. this._isFirstFrame = true;
  7513. var i, len = this.itemsData.length;
  7514. for (i = 0; i < len; i += 1) {
  7515. this.prevViewData[i] = this.itemsData[i];
  7516. }
  7517. this.searchShapes(this.shapesData,this.itemsData,this.prevViewData, true, []);
  7518. len = this.dynamicProperties.length;
  7519. for (i = 0; i < len; i += 1) {
  7520. this.dynamicProperties[i].getValue();
  7521. }
  7522. this.renderModifiers();
  7523. this.transformsManager.processSequences(this._isFirstFrame);
  7524. };
  7525. CVShapeElement.prototype.addTransformToStyleList = function(transform) {
  7526. var i, len = this.stylesList.length;
  7527. for (i = 0; i < len; i += 1) {
  7528. if(!this.stylesList[i].closed) {
  7529. this.stylesList[i].transforms.push(transform);
  7530. }
  7531. }
  7532. }
  7533. CVShapeElement.prototype.removeTransformFromStyleList = function() {
  7534. var i, len = this.stylesList.length;
  7535. for (i = 0; i < len; i += 1) {
  7536. if(!this.stylesList[i].closed) {
  7537. this.stylesList[i].transforms.pop();
  7538. }
  7539. }
  7540. }
  7541. CVShapeElement.prototype.closeStyles = function(styles) {
  7542. var i, len = styles.length, j, jLen;
  7543. for (i = 0; i < len; i += 1) {
  7544. styles[i].closed = true;
  7545. }
  7546. }
  7547. CVShapeElement.prototype.searchShapes = function(arr,itemsData, prevViewData, shouldRender, transforms){
  7548. var i, len = arr.length - 1;
  7549. var j, jLen;
  7550. var ownStyles = [], ownModifiers = [], processedPos, modifier, currentTransform;
  7551. var ownTransforms = [].concat(transforms);
  7552. for(i=len;i>=0;i-=1){
  7553. processedPos = this.searchProcessedElement(arr[i]);
  7554. if(!processedPos){
  7555. arr[i]._shouldRender = shouldRender;
  7556. } else {
  7557. itemsData[i] = prevViewData[processedPos - 1];
  7558. }
  7559. if(arr[i].ty == 'fl' || arr[i].ty == 'st'|| arr[i].ty == 'gf'|| arr[i].ty == 'gs'){
  7560. if(!processedPos){
  7561. itemsData[i] = this.createStyleElement(arr[i], ownTransforms);
  7562. } else {
  7563. itemsData[i].style.closed = false;
  7564. }
  7565. ownStyles.push(itemsData[i].style);
  7566. }else if(arr[i].ty == 'gr'){
  7567. if(!processedPos){
  7568. itemsData[i] = this.createGroupElement(arr[i]);
  7569. } else {
  7570. jLen = itemsData[i].it.length;
  7571. for(j=0;j<jLen;j+=1){
  7572. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  7573. }
  7574. }
  7575. this.searchShapes(arr[i].it,itemsData[i].it,itemsData[i].prevViewData, shouldRender, ownTransforms);
  7576. }else if(arr[i].ty == 'tr'){
  7577. if(!processedPos){
  7578. currentTransform = this.createTransformElement(arr[i]);
  7579. itemsData[i] = currentTransform;
  7580. }
  7581. ownTransforms.push(itemsData[i]);
  7582. this.addTransformToStyleList(itemsData[i]);
  7583. }else if(arr[i].ty == 'sh' || arr[i].ty == 'rc' || arr[i].ty == 'el' || arr[i].ty == 'sr'){
  7584. if(!processedPos){
  7585. itemsData[i] = this.createShapeElement(arr[i]);
  7586. }
  7587. }else if(arr[i].ty == 'tm' || arr[i].ty == 'rd'){
  7588. if(!processedPos){
  7589. modifier = ShapeModifiers.getModifier(arr[i].ty);
  7590. modifier.init(this,arr[i]);
  7591. itemsData[i] = modifier;
  7592. this.shapeModifiers.push(modifier);
  7593. } else {
  7594. modifier = itemsData[i];
  7595. modifier.closed = false;
  7596. }
  7597. ownModifiers.push(modifier);
  7598. } else if(arr[i].ty == 'rp'){
  7599. if(!processedPos){
  7600. modifier = ShapeModifiers.getModifier(arr[i].ty);
  7601. itemsData[i] = modifier;
  7602. modifier.init(this,arr,i,itemsData);
  7603. this.shapeModifiers.push(modifier);
  7604. shouldRender = false;
  7605. }else{
  7606. modifier = itemsData[i];
  7607. modifier.closed = true;
  7608. }
  7609. ownModifiers.push(modifier);
  7610. }
  7611. this.addProcessedElement(arr[i], i + 1);
  7612. }
  7613. this.removeTransformFromStyleList();
  7614. this.closeStyles(ownStyles);
  7615. len = ownModifiers.length;
  7616. for(i=0;i<len;i+=1){
  7617. ownModifiers[i].closed = true;
  7618. }
  7619. };
  7620. CVShapeElement.prototype.renderInnerContent = function() {
  7621. this.transformHelper.opacity = 1;
  7622. this.transformHelper._opMdf = false;
  7623. this.renderModifiers();
  7624. this.transformsManager.processSequences(this._isFirstFrame);
  7625. this.renderShape(this.transformHelper,this.shapesData,this.itemsData,true);
  7626. };
  7627. CVShapeElement.prototype.renderShapeTransform = function(parentTransform, groupTransform) {
  7628. var props, groupMatrix;
  7629. if(parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) {
  7630. groupTransform.opacity = parentTransform.opacity;
  7631. groupTransform.opacity *= groupTransform.op.v;
  7632. groupTransform._opMdf = true;
  7633. }
  7634. };
  7635. CVShapeElement.prototype.drawLayer = function() {
  7636. var i, len = this.stylesList.length;
  7637. var j, jLen, k, kLen,elems,nodes, renderer = this.globalData.renderer, ctx = this.globalData.canvasContext, type, currentStyle;
  7638. for(i=0;i<len;i+=1){
  7639. currentStyle = this.stylesList[i];
  7640. type = currentStyle.type;
  7641. //Skipping style when
  7642. //Stroke width equals 0
  7643. //style should not be rendered (extra unused repeaters)
  7644. //current opacity equals 0
  7645. //global opacity equals 0
  7646. if(((type === 'st' || type === 'gs') && currentStyle.wi === 0) || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0){
  7647. continue;
  7648. }
  7649. renderer.save();
  7650. elems = currentStyle.elements;
  7651. if(type === 'st' || type === 'gs'){
  7652. ctx.strokeStyle = type === 'st' ? currentStyle.co : currentStyle.grd;
  7653. ctx.lineWidth = currentStyle.wi;
  7654. ctx.lineCap = currentStyle.lc;
  7655. ctx.lineJoin = currentStyle.lj;
  7656. ctx.miterLimit = currentStyle.ml || 0;
  7657. } else {
  7658. ctx.fillStyle = type === 'fl' ? currentStyle.co : currentStyle.grd;
  7659. }
  7660. renderer.ctxOpacity(currentStyle.coOp);
  7661. if(type !== 'st' && type !== 'gs'){
  7662. ctx.beginPath();
  7663. }
  7664. renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props);
  7665. jLen = elems.length;
  7666. for(j=0;j<jLen;j+=1){
  7667. if(type === 'st' || type === 'gs'){
  7668. ctx.beginPath();
  7669. if(currentStyle.da){
  7670. ctx.setLineDash(currentStyle.da);
  7671. ctx.lineDashOffset = currentStyle.do;
  7672. }
  7673. }
  7674. nodes = elems[j].trNodes;
  7675. kLen = nodes.length;
  7676. for(k=0;k<kLen;k+=1){
  7677. if(nodes[k].t == 'm'){
  7678. ctx.moveTo(nodes[k].p[0],nodes[k].p[1]);
  7679. }else if(nodes[k].t == 'c'){
  7680. 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]);
  7681. }else{
  7682. ctx.closePath();
  7683. }
  7684. }
  7685. if(type === 'st' || type === 'gs'){
  7686. ctx.stroke();
  7687. if(currentStyle.da){
  7688. ctx.setLineDash(this.dashResetter);
  7689. }
  7690. }
  7691. }
  7692. if(type !== 'st' && type !== 'gs'){
  7693. ctx.fill(currentStyle.r);
  7694. }
  7695. renderer.restore();
  7696. }
  7697. };
  7698. CVShapeElement.prototype.renderShape = function(parentTransform,items,data,isMain){
  7699. var i, len = items.length - 1;
  7700. var groupTransform;
  7701. groupTransform = parentTransform;
  7702. for(i=len;i>=0;i-=1){
  7703. if(items[i].ty == 'tr'){
  7704. groupTransform = data[i].transform;
  7705. this.renderShapeTransform(parentTransform, groupTransform);
  7706. }else if(items[i].ty == 'sh' || items[i].ty == 'el' || items[i].ty == 'rc' || items[i].ty == 'sr'){
  7707. this.renderPath(items[i],data[i]);
  7708. }else if(items[i].ty == 'fl'){
  7709. this.renderFill(items[i],data[i],groupTransform);
  7710. }else if(items[i].ty == 'st'){
  7711. this.renderStroke(items[i],data[i],groupTransform);
  7712. }else if(items[i].ty == 'gf' || items[i].ty == 'gs'){
  7713. this.renderGradientFill(items[i],data[i],groupTransform);
  7714. }else if(items[i].ty == 'gr'){
  7715. this.renderShape(groupTransform,items[i].it,data[i].it);
  7716. }else if(items[i].ty == 'tm'){
  7717. //
  7718. }
  7719. }
  7720. if(isMain){
  7721. this.drawLayer();
  7722. }
  7723. };
  7724. CVShapeElement.prototype.renderStyledShape = function(styledShape, shape){
  7725. if(this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) {
  7726. var shapeNodes = styledShape.trNodes;
  7727. var paths = shape.paths;
  7728. var i, len, j, jLen = paths._length;
  7729. shapeNodes.length = 0;
  7730. var groupTransformMat = styledShape.transforms.finalTransform;
  7731. for (j = 0; j < jLen; j += 1) {
  7732. var pathNodes = paths.shapes[j];
  7733. if(pathNodes && pathNodes.v){
  7734. len = pathNodes._length;
  7735. for (i = 1; i < len; i += 1) {
  7736. if (i === 1) {
  7737. shapeNodes.push({
  7738. t: 'm',
  7739. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0)
  7740. });
  7741. }
  7742. shapeNodes.push({
  7743. t: 'c',
  7744. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i])
  7745. });
  7746. }
  7747. if (len === 1) {
  7748. shapeNodes.push({
  7749. t: 'm',
  7750. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0)
  7751. });
  7752. }
  7753. if (pathNodes.c && len) {
  7754. shapeNodes.push({
  7755. t: 'c',
  7756. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0])
  7757. });
  7758. shapeNodes.push({
  7759. t: 'z'
  7760. });
  7761. }
  7762. }
  7763. }
  7764. styledShape.trNodes = shapeNodes;
  7765. }
  7766. }
  7767. CVShapeElement.prototype.renderPath = function(pathData,itemData){
  7768. if(pathData.hd !== true && pathData._shouldRender) {
  7769. var i, len = itemData.styledShapes.length;
  7770. for (i = 0; i < len; i += 1) {
  7771. this.renderStyledShape(itemData.styledShapes[i], itemData.sh);
  7772. }
  7773. }
  7774. };
  7775. CVShapeElement.prototype.renderFill = function(styleData,itemData, groupTransform){
  7776. var styleElem = itemData.style;
  7777. if (itemData.c._mdf || this._isFirstFrame) {
  7778. styleElem.co = 'rgb('
  7779. + bm_floor(itemData.c.v[0]) + ','
  7780. + bm_floor(itemData.c.v[1]) + ','
  7781. + bm_floor(itemData.c.v[2]) + ')';
  7782. }
  7783. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  7784. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  7785. }
  7786. };
  7787. CVShapeElement.prototype.renderGradientFill = function(styleData,itemData, groupTransform){
  7788. var styleElem = itemData.style;
  7789. if(!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || (styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf))) {
  7790. var ctx = this.globalData.canvasContext;
  7791. var grd;
  7792. var pt1 = itemData.s.v, pt2 = itemData.e.v;
  7793. if (styleData.t === 1) {
  7794. grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]);
  7795. } else {
  7796. var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  7797. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  7798. var percent = itemData.h.v >= 1 ? 0.99 : itemData.h.v <= -1 ? -0.99: itemData.h.v;
  7799. var dist = rad * percent;
  7800. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  7801. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  7802. var grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad);
  7803. }
  7804. var i, len = styleData.g.p;
  7805. var cValues = itemData.g.c;
  7806. var opacity = 1;
  7807. for (i = 0; i < len; i += 1){
  7808. if(itemData.g._hasOpacity && itemData.g._collapsable) {
  7809. opacity = itemData.g.o[i*2 + 1];
  7810. }
  7811. grd.addColorStop(cValues[i * 4] / 100,'rgba('+ cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ','+cValues[i * 4 + 3] + ',' + opacity + ')');
  7812. }
  7813. styleElem.grd = grd;
  7814. }
  7815. styleElem.coOp = itemData.o.v*groupTransform.opacity;
  7816. };
  7817. CVShapeElement.prototype.renderStroke = function(styleData,itemData, groupTransform){
  7818. var styleElem = itemData.style;
  7819. var d = itemData.d;
  7820. if(d && (d._mdf || this._isFirstFrame)){
  7821. styleElem.da = d.dashArray;
  7822. styleElem.do = d.dashoffset[0];
  7823. }
  7824. if(itemData.c._mdf || this._isFirstFrame){
  7825. styleElem.co = 'rgb('+bm_floor(itemData.c.v[0])+','+bm_floor(itemData.c.v[1])+','+bm_floor(itemData.c.v[2])+')';
  7826. }
  7827. if(itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame){
  7828. styleElem.coOp = itemData.o.v*groupTransform.opacity;
  7829. }
  7830. if(itemData.w._mdf || this._isFirstFrame){
  7831. styleElem.wi = itemData.w.v;
  7832. }
  7833. };
  7834. CVShapeElement.prototype.destroy = function(){
  7835. this.shapesData = null;
  7836. this.globalData = null;
  7837. this.canvasContext = null;
  7838. this.stylesList.length = 0;
  7839. this.itemsData.length = 0;
  7840. };
  7841. function CVSolidElement(data, globalData, comp) {
  7842. this.initElement(data,globalData,comp);
  7843. }
  7844. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVSolidElement);
  7845. CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  7846. CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  7847. CVSolidElement.prototype.renderInnerContent = function() {
  7848. var ctx = this.canvasContext;
  7849. ctx.fillStyle = this.data.sc;
  7850. ctx.fillRect(0, 0, this.data.sw, this.data.sh);
  7851. //
  7852. };
  7853. function CVEffects() {
  7854. }
  7855. CVEffects.prototype.renderFrame = function(){};
  7856. var animationManager = (function(){
  7857. var moduleOb = {};
  7858. var registeredAnimations = [];
  7859. var initTime = 0;
  7860. var len = 0;
  7861. var playingAnimationsNum = 0;
  7862. var _stopped = true;
  7863. var _isFrozen = false;
  7864. function removeElement(ev){
  7865. var i = 0;
  7866. var animItem = ev.target;
  7867. while(i<len) {
  7868. if (registeredAnimations[i].animation === animItem) {
  7869. registeredAnimations.splice(i, 1);
  7870. i -= 1;
  7871. len -= 1;
  7872. if(!animItem.isPaused){
  7873. subtractPlayingCount();
  7874. }
  7875. }
  7876. i += 1;
  7877. }
  7878. }
  7879. function registerAnimation(element, animationData){
  7880. if(!element){
  7881. return null;
  7882. }
  7883. var i=0;
  7884. while(i<len){
  7885. if(registeredAnimations[i].elem == element && registeredAnimations[i].elem !== null ){
  7886. return registeredAnimations[i].animation;
  7887. }
  7888. i+=1;
  7889. }
  7890. var animItem = new AnimationItem();
  7891. setupAnimation(animItem, element);
  7892. animItem.setData(element, animationData);
  7893. return animItem;
  7894. }
  7895. function getRegisteredAnimations() {
  7896. var i, len = registeredAnimations.length;
  7897. var animations = [];
  7898. for(i = 0; i < len; i += 1) {
  7899. animations.push(registeredAnimations[i].animation);
  7900. }
  7901. return animations;
  7902. }
  7903. function addPlayingCount(){
  7904. playingAnimationsNum += 1;
  7905. activate();
  7906. }
  7907. function subtractPlayingCount(){
  7908. playingAnimationsNum -= 1;
  7909. }
  7910. function setupAnimation(animItem, element){
  7911. animItem.addEventListener('destroy',removeElement);
  7912. animItem.addEventListener('_active',addPlayingCount);
  7913. animItem.addEventListener('_idle',subtractPlayingCount);
  7914. registeredAnimations.push({elem: element,animation:animItem});
  7915. len += 1;
  7916. }
  7917. function loadAnimation(params){
  7918. var animItem = new AnimationItem();
  7919. setupAnimation(animItem, null);
  7920. animItem.setParams(params);
  7921. return animItem;
  7922. }
  7923. function setSpeed(val,animation){
  7924. var i;
  7925. for(i=0;i<len;i+=1){
  7926. registeredAnimations[i].animation.setSpeed(val, animation);
  7927. }
  7928. }
  7929. function setDirection(val, animation){
  7930. var i;
  7931. for(i=0;i<len;i+=1){
  7932. registeredAnimations[i].animation.setDirection(val, animation);
  7933. }
  7934. }
  7935. function play(animation){
  7936. var i;
  7937. for(i=0;i<len;i+=1){
  7938. registeredAnimations[i].animation.play(animation);
  7939. }
  7940. }
  7941. function resume(nowTime) {
  7942. var elapsedTime = nowTime - initTime;
  7943. var i;
  7944. for(i=0;i<len;i+=1){
  7945. registeredAnimations[i].animation.advanceTime(elapsedTime);
  7946. }
  7947. initTime = nowTime;
  7948. if(playingAnimationsNum && !_isFrozen) {
  7949. requestAnimationFrame(resume);
  7950. } else {
  7951. _stopped = true;
  7952. }
  7953. }
  7954. function first(nowTime){
  7955. initTime = nowTime;
  7956. requestAnimationFrame(resume);
  7957. }
  7958. function pause(animation) {
  7959. var i;
  7960. for(i=0;i<len;i+=1){
  7961. registeredAnimations[i].animation.pause(animation);
  7962. }
  7963. }
  7964. function goToAndStop(value,isFrame,animation) {
  7965. var i;
  7966. for(i=0;i<len;i+=1){
  7967. registeredAnimations[i].animation.goToAndStop(value,isFrame,animation);
  7968. }
  7969. }
  7970. function stop(animation) {
  7971. var i;
  7972. for(i=0;i<len;i+=1){
  7973. registeredAnimations[i].animation.stop(animation);
  7974. }
  7975. }
  7976. function togglePause(animation) {
  7977. var i;
  7978. for(i=0;i<len;i+=1){
  7979. registeredAnimations[i].animation.togglePause(animation);
  7980. }
  7981. }
  7982. function destroy(animation) {
  7983. var i;
  7984. for(i=(len-1);i>=0;i-=1){
  7985. registeredAnimations[i].animation.destroy(animation);
  7986. }
  7987. }
  7988. function searchAnimations(animationData, standalone, renderer){
  7989. throw new Error('Cannot access DOM from worker thread');
  7990. }
  7991. function resize(){
  7992. var i;
  7993. for(i=0;i<len;i+=1){
  7994. registeredAnimations[i].animation.resize();
  7995. }
  7996. }
  7997. function activate(){
  7998. if(!_isFrozen && playingAnimationsNum){
  7999. if(_stopped) {
  8000. requestAnimationFrame(first);
  8001. _stopped = false;
  8002. }
  8003. }
  8004. }
  8005. function freeze() {
  8006. _isFrozen = true;
  8007. }
  8008. function unfreeze() {
  8009. _isFrozen = false;
  8010. activate();
  8011. }
  8012. moduleOb.registerAnimation = registerAnimation;
  8013. moduleOb.loadAnimation = loadAnimation;
  8014. moduleOb.setSpeed = setSpeed;
  8015. moduleOb.setDirection = setDirection;
  8016. moduleOb.play = play;
  8017. moduleOb.pause = pause;
  8018. moduleOb.stop = stop;
  8019. moduleOb.togglePause = togglePause;
  8020. moduleOb.searchAnimations = searchAnimations;
  8021. moduleOb.resize = resize;
  8022. //moduleOb.start = start;
  8023. moduleOb.goToAndStop = goToAndStop;
  8024. moduleOb.destroy = destroy;
  8025. moduleOb.freeze = freeze;
  8026. moduleOb.unfreeze = unfreeze;
  8027. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  8028. return moduleOb;
  8029. }());
  8030. var AnimationItem = function () {
  8031. this._cbs = [];
  8032. this.name = '';
  8033. this.path = '';
  8034. this.isLoaded = false;
  8035. this.currentFrame = 0;
  8036. this.currentRawFrame = 0;
  8037. this.totalFrames = 0;
  8038. this.frameRate = 0;
  8039. this.frameMult = 0;
  8040. this.playSpeed = 1;
  8041. this.playDirection = 1;
  8042. this.playCount = 0;
  8043. this.animationData = {};
  8044. this.assets = [];
  8045. this.isPaused = true;
  8046. this.autoplay = false;
  8047. this.loop = true;
  8048. this.renderer = null;
  8049. this.animationID = createElementID();
  8050. this.assetsPath = '';
  8051. this.timeCompleted = 0;
  8052. this.segmentPos = 0;
  8053. this.subframeEnabled = subframeEnabled;
  8054. this.segments = [];
  8055. this._idle = true;
  8056. this._completedLoop = false;
  8057. this.projectInterface = ProjectInterface();
  8058. this.imagePreloader = new ImagePreloader();
  8059. };
  8060. extendPrototype([BaseEvent], AnimationItem);
  8061. AnimationItem.prototype.setParams = function(params) {
  8062. if(params.context){
  8063. this.context = params.context;
  8064. }
  8065. if(params.wrapper || params.container){
  8066. this.wrapper = params.wrapper || params.container;
  8067. }
  8068. var animType = params.animType ? params.animType : params.renderer ? params.renderer : 'svg';
  8069. switch(animType){
  8070. case 'canvas':
  8071. this.renderer = new CanvasRenderer(this, params.rendererSettings);
  8072. break;
  8073. case 'svg':
  8074. this.renderer = new SVGRenderer(this, params.rendererSettings);
  8075. break;
  8076. default:
  8077. this.renderer = new HybridRenderer(this, params.rendererSettings);
  8078. break;
  8079. }
  8080. this.renderer.setProjectInterface(this.projectInterface);
  8081. this.animType = animType;
  8082. if(params.loop === '' || params.loop === null){
  8083. }else if(params.loop === false){
  8084. this.loop = false;
  8085. }else if(params.loop === true){
  8086. this.loop = true;
  8087. }else{
  8088. this.loop = parseInt(params.loop);
  8089. }
  8090. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  8091. this.name = params.name ? params.name : '';
  8092. this.autoloadSegments = params.hasOwnProperty('autoloadSegments') ? params.autoloadSegments : true;
  8093. this.assetsPath = params.assetsPath;
  8094. if(params.animationData){
  8095. this.configAnimation(params.animationData);
  8096. }else if(params.path){
  8097. if(params.path.substr(-4) != 'json'){
  8098. if (params.path.substr(-1, 1) != '/') {
  8099. params.path += '/';
  8100. }
  8101. params.path += 'data.json';
  8102. }
  8103. if(params.path.lastIndexOf('\\') != -1){
  8104. this.path = params.path.substr(0,params.path.lastIndexOf('\\')+1);
  8105. }else{
  8106. this.path = params.path.substr(0,params.path.lastIndexOf('/')+1);
  8107. }
  8108. this.fileName = params.path.substr(params.path.lastIndexOf('/')+1);
  8109. this.fileName = this.fileName.substr(0,this.fileName.lastIndexOf('.json'));
  8110. assetLoader.load(params.path, this.configAnimation.bind(this), function() {
  8111. this.trigger('data_failed');
  8112. }.bind(this));
  8113. }
  8114. };
  8115. AnimationItem.prototype.setData = function (wrapper, animationData) {
  8116. var params = {
  8117. wrapper: wrapper,
  8118. animationData: animationData ? (typeof animationData === "object") ? animationData : JSON.parse(animationData) : null
  8119. };
  8120. var wrapperAttributes = wrapper.attributes;
  8121. params.path = wrapperAttributes.getNamedItem('data-animation-path') ? wrapperAttributes.getNamedItem('data-animation-path').value : wrapperAttributes.getNamedItem('data-bm-path') ? wrapperAttributes.getNamedItem('data-bm-path').value : wrapperAttributes.getNamedItem('bm-path') ? wrapperAttributes.getNamedItem('bm-path').value : '';
  8122. params.animType = wrapperAttributes.getNamedItem('data-anim-type') ? wrapperAttributes.getNamedItem('data-anim-type').value : wrapperAttributes.getNamedItem('data-bm-type') ? wrapperAttributes.getNamedItem('data-bm-type').value : wrapperAttributes.getNamedItem('bm-type') ? wrapperAttributes.getNamedItem('bm-type').value : wrapperAttributes.getNamedItem('data-bm-renderer') ? wrapperAttributes.getNamedItem('data-bm-renderer').value : wrapperAttributes.getNamedItem('bm-renderer') ? wrapperAttributes.getNamedItem('bm-renderer').value : 'canvas';
  8123. var loop = wrapperAttributes.getNamedItem('data-anim-loop') ? wrapperAttributes.getNamedItem('data-anim-loop').value : wrapperAttributes.getNamedItem('data-bm-loop') ? wrapperAttributes.getNamedItem('data-bm-loop').value : wrapperAttributes.getNamedItem('bm-loop') ? wrapperAttributes.getNamedItem('bm-loop').value : '';
  8124. if(loop === ''){
  8125. }else if(loop === 'false'){
  8126. params.loop = false;
  8127. }else if(loop === 'true'){
  8128. params.loop = true;
  8129. }else{
  8130. params.loop = parseInt(loop);
  8131. }
  8132. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') ? wrapperAttributes.getNamedItem('data-anim-autoplay').value : wrapperAttributes.getNamedItem('data-bm-autoplay') ? wrapperAttributes.getNamedItem('data-bm-autoplay').value : wrapperAttributes.getNamedItem('bm-autoplay') ? wrapperAttributes.getNamedItem('bm-autoplay').value : true;
  8133. params.autoplay = autoplay !== "false";
  8134. params.name = wrapperAttributes.getNamedItem('data-name') ? wrapperAttributes.getNamedItem('data-name').value : wrapperAttributes.getNamedItem('data-bm-name') ? wrapperAttributes.getNamedItem('data-bm-name').value : wrapperAttributes.getNamedItem('bm-name') ? wrapperAttributes.getNamedItem('bm-name').value : '';
  8135. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') ? wrapperAttributes.getNamedItem('data-anim-prerender').value : wrapperAttributes.getNamedItem('data-bm-prerender') ? wrapperAttributes.getNamedItem('data-bm-prerender').value : wrapperAttributes.getNamedItem('bm-prerender') ? wrapperAttributes.getNamedItem('bm-prerender').value : '';
  8136. if(prerender === 'false'){
  8137. params.prerender = false;
  8138. }
  8139. this.setParams(params);
  8140. };
  8141. AnimationItem.prototype.includeLayers = function(data) {
  8142. if(data.op > this.animationData.op){
  8143. this.animationData.op = data.op;
  8144. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  8145. }
  8146. var layers = this.animationData.layers;
  8147. var i, len = layers.length;
  8148. var newLayers = data.layers;
  8149. var j, jLen = newLayers.length;
  8150. for(j=0;j<jLen;j+=1){
  8151. i = 0;
  8152. while(i<len){
  8153. if(layers[i].id == newLayers[j].id){
  8154. layers[i] = newLayers[j];
  8155. break;
  8156. }
  8157. i += 1;
  8158. }
  8159. }
  8160. if(data.chars || data.fonts){
  8161. this.renderer.globalData.fontManager.addChars(data.chars);
  8162. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  8163. }
  8164. if(data.assets){
  8165. len = data.assets.length;
  8166. for(i = 0; i < len; i += 1){
  8167. this.animationData.assets.push(data.assets[i]);
  8168. }
  8169. }
  8170. this.animationData.__complete = false;
  8171. dataManager.completeData(this.animationData,this.renderer.globalData.fontManager);
  8172. this.renderer.includeLayers(data.layers);
  8173. if(expressionsPlugin){
  8174. expressionsPlugin.initExpressions(this);
  8175. }
  8176. this.loadNextSegment();
  8177. };
  8178. AnimationItem.prototype.loadNextSegment = function() {
  8179. var segments = this.animationData.segments;
  8180. if(!segments || segments.length === 0 || !this.autoloadSegments){
  8181. this.trigger('data_ready');
  8182. this.timeCompleted = this.totalFrames;
  8183. return;
  8184. }
  8185. var segment = segments.shift();
  8186. this.timeCompleted = segment.time * this.frameRate;
  8187. var segmentPath = this.path+this.fileName+'_' + this.segmentPos + '.json';
  8188. this.segmentPos += 1;
  8189. assetLoader.load(segmentPath, this.includeLayers.bind(this), function() {
  8190. this.trigger('data_failed');
  8191. }.bind(this));
  8192. };
  8193. AnimationItem.prototype.loadSegments = function() {
  8194. var segments = this.animationData.segments;
  8195. if(!segments) {
  8196. this.timeCompleted = this.totalFrames;
  8197. }
  8198. this.loadNextSegment();
  8199. };
  8200. AnimationItem.prototype.imagesLoaded = function() {
  8201. this.trigger('loaded_images');
  8202. this.checkLoaded()
  8203. }
  8204. AnimationItem.prototype.preloadImages = function() {
  8205. this.imagePreloader.setAssetsPath(this.assetsPath);
  8206. this.imagePreloader.setPath(this.path);
  8207. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  8208. }
  8209. AnimationItem.prototype.configAnimation = function (animData) {
  8210. if(!this.renderer){
  8211. return;
  8212. }
  8213. this.animationData = animData;
  8214. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  8215. this.renderer.configAnimation(animData);
  8216. if(!animData.assets){
  8217. animData.assets = [];
  8218. }
  8219. this.renderer.searchExtraCompositions(animData.assets);
  8220. this.assets = this.animationData.assets;
  8221. this.frameRate = this.animationData.fr;
  8222. this.firstFrame = Math.round(this.animationData.ip);
  8223. this.frameMult = this.animationData.fr / 1000;
  8224. this.trigger('config_ready');
  8225. this.preloadImages();
  8226. this.loadSegments();
  8227. this.updaFrameModifier();
  8228. this.waitForFontsLoaded();
  8229. };
  8230. AnimationItem.prototype.waitForFontsLoaded = function(){
  8231. if(!this.renderer) {
  8232. return;
  8233. }
  8234. if(this.renderer.globalData.fontManager.loaded()){
  8235. this.checkLoaded();
  8236. }else{
  8237. setTimeout(this.waitForFontsLoaded.bind(this),20);
  8238. }
  8239. }
  8240. AnimationItem.prototype.checkLoaded = function () {
  8241. if (!this.isLoaded && this.renderer.globalData.fontManager.loaded() && (this.imagePreloader.loaded() || this.renderer.rendererType !== 'canvas')) {
  8242. this.isLoaded = true;
  8243. dataManager.completeData(this.animationData, this.renderer.globalData.fontManager);
  8244. if(expressionsPlugin){
  8245. expressionsPlugin.initExpressions(this);
  8246. }
  8247. this.renderer.initItems();
  8248. setTimeout(function() {
  8249. this.trigger('DOMLoaded');
  8250. }.bind(this), 0);
  8251. this.gotoFrame();
  8252. if(this.autoplay){
  8253. this.play();
  8254. }
  8255. }
  8256. };
  8257. AnimationItem.prototype.resize = function () {
  8258. this.renderer.updateContainerSize();
  8259. };
  8260. AnimationItem.prototype.setSubframe = function(flag){
  8261. this.subframeEnabled = flag ? true : false;
  8262. };
  8263. AnimationItem.prototype.gotoFrame = function () {
  8264. this.currentFrame = this.subframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame;
  8265. if(this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted){
  8266. this.currentFrame = this.timeCompleted;
  8267. }
  8268. this.trigger('enterFrame');
  8269. this.renderFrame();
  8270. };
  8271. AnimationItem.prototype.renderFrame = function () {
  8272. if(this.isLoaded === false){
  8273. return;
  8274. }
  8275. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  8276. };
  8277. AnimationItem.prototype.play = function (name) {
  8278. if(name && this.name != name){
  8279. return;
  8280. }
  8281. if(this.isPaused === true){
  8282. this.isPaused = false;
  8283. if(this._idle){
  8284. this._idle = false;
  8285. this.trigger('_active');
  8286. }
  8287. }
  8288. };
  8289. AnimationItem.prototype.pause = function (name) {
  8290. if(name && this.name != name){
  8291. return;
  8292. }
  8293. if(this.isPaused === false){
  8294. this.isPaused = true;
  8295. this._idle = true;
  8296. this.trigger('_idle');
  8297. }
  8298. };
  8299. AnimationItem.prototype.togglePause = function (name) {
  8300. if(name && this.name != name){
  8301. return;
  8302. }
  8303. if(this.isPaused === true){
  8304. this.play();
  8305. }else{
  8306. this.pause();
  8307. }
  8308. };
  8309. AnimationItem.prototype.stop = function (name) {
  8310. if(name && this.name != name){
  8311. return;
  8312. }
  8313. this.pause();
  8314. this.playCount = 0;
  8315. this._completedLoop = false;
  8316. this.setCurrentRawFrameValue(0);
  8317. };
  8318. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  8319. if(name && this.name != name){
  8320. return;
  8321. }
  8322. if(isFrame){
  8323. this.setCurrentRawFrameValue(value);
  8324. }else{
  8325. this.setCurrentRawFrameValue(value * this.frameModifier);
  8326. }
  8327. this.pause();
  8328. };
  8329. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  8330. this.goToAndStop(value, isFrame, name);
  8331. this.play();
  8332. };
  8333. AnimationItem.prototype.advanceTime = function (value) {
  8334. if (this.isPaused === true || this.isLoaded === false) {
  8335. return;
  8336. }
  8337. var nextValue = this.currentRawFrame + value * this.frameModifier;
  8338. var _isComplete = false;
  8339. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  8340. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  8341. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  8342. if (!this.loop || this.playCount === this.loop) {
  8343. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  8344. _isComplete = true;
  8345. nextValue = this.totalFrames - 1;
  8346. }
  8347. } else if (nextValue >= this.totalFrames) {
  8348. this.playCount += 1;
  8349. if (!this.checkSegments(nextValue % this.totalFrames)) {
  8350. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  8351. this._completedLoop = true;
  8352. this.trigger('loopComplete');
  8353. }
  8354. } else {
  8355. this.setCurrentRawFrameValue(nextValue);
  8356. }
  8357. } else if(nextValue < 0) {
  8358. if (!this.checkSegments(nextValue % this.totalFrames)) {
  8359. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) {
  8360. this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames));
  8361. if(!this._completedLoop) {
  8362. this._completedLoop = true;
  8363. } else {
  8364. this.trigger('loopComplete');
  8365. }
  8366. } else {
  8367. _isComplete = true;
  8368. nextValue = 0;
  8369. }
  8370. }
  8371. } else {
  8372. this.setCurrentRawFrameValue(nextValue);
  8373. }
  8374. if (_isComplete) {
  8375. this.setCurrentRawFrameValue(nextValue);
  8376. this.pause();
  8377. this.trigger('complete');
  8378. }
  8379. };
  8380. AnimationItem.prototype.adjustSegment = function(arr, offset){
  8381. this.playCount = 0;
  8382. if(arr[1] < arr[0]){
  8383. if(this.frameModifier > 0){
  8384. if(this.playSpeed < 0){
  8385. this.setSpeed(-this.playSpeed);
  8386. } else {
  8387. this.setDirection(-1);
  8388. }
  8389. }
  8390. this.timeCompleted = this.totalFrames = arr[0] - arr[1];
  8391. this.firstFrame = arr[1];
  8392. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  8393. } else if(arr[1] > arr[0]){
  8394. if(this.frameModifier < 0){
  8395. if(this.playSpeed < 0){
  8396. this.setSpeed(-this.playSpeed);
  8397. } else {
  8398. this.setDirection(1);
  8399. }
  8400. }
  8401. this.timeCompleted = this.totalFrames = arr[1] - arr[0];
  8402. this.firstFrame = arr[0];
  8403. this.setCurrentRawFrameValue(0.001 + offset);
  8404. }
  8405. this.trigger('segmentStart');
  8406. };
  8407. AnimationItem.prototype.setSegment = function (init,end) {
  8408. var pendingFrame = -1;
  8409. if(this.isPaused) {
  8410. if (this.currentRawFrame + this.firstFrame < init) {
  8411. pendingFrame = init;
  8412. } else if (this.currentRawFrame + this.firstFrame > end) {
  8413. pendingFrame = end - init;
  8414. }
  8415. }
  8416. this.firstFrame = init;
  8417. this.timeCompleted = this.totalFrames = end - init;
  8418. if(pendingFrame !== -1) {
  8419. this.goToAndStop(pendingFrame,true);
  8420. }
  8421. };
  8422. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  8423. if (forceFlag) {
  8424. this.segments.length = 0;
  8425. }
  8426. if (typeof arr[0] === 'object') {
  8427. var i, len = arr.length;
  8428. for (i = 0; i < len; i += 1) {
  8429. this.segments.push(arr[i]);
  8430. }
  8431. } else {
  8432. this.segments.push(arr);
  8433. }
  8434. if (this.segments.length && forceFlag) {
  8435. this.adjustSegment(this.segments.shift(), 0);
  8436. }
  8437. if (this.isPaused) {
  8438. this.play();
  8439. }
  8440. };
  8441. AnimationItem.prototype.resetSegments = function (forceFlag) {
  8442. this.segments.length = 0;
  8443. this.segments.push([this.animationData.ip,this.animationData.op]);
  8444. //this.segments.push([this.animationData.ip*this.frameRate,Math.floor(this.animationData.op - this.animationData.ip+this.animationData.ip*this.frameRate)]);
  8445. if (forceFlag) {
  8446. this.checkSegments(0);
  8447. }
  8448. };
  8449. AnimationItem.prototype.checkSegments = function(offset) {
  8450. if (this.segments.length) {
  8451. this.adjustSegment(this.segments.shift(), offset);
  8452. return true;
  8453. }
  8454. return false;
  8455. };
  8456. AnimationItem.prototype.destroy = function (name) {
  8457. if ((name && this.name != name) || !this.renderer) {
  8458. return;
  8459. }
  8460. this.renderer.destroy();
  8461. this.imagePreloader.destroy();
  8462. this.trigger('destroy');
  8463. this._cbs = null;
  8464. this.onEnterFrame = this.onLoopComplete = this.onComplete = this.onSegmentStart = this.onDestroy = null;
  8465. this.renderer = null;
  8466. };
  8467. AnimationItem.prototype.setCurrentRawFrameValue = function(value){
  8468. this.currentRawFrame = value;
  8469. this.gotoFrame();
  8470. };
  8471. AnimationItem.prototype.setSpeed = function (val) {
  8472. this.playSpeed = val;
  8473. this.updaFrameModifier();
  8474. };
  8475. AnimationItem.prototype.setDirection = function (val) {
  8476. this.playDirection = val < 0 ? -1 : 1;
  8477. this.updaFrameModifier();
  8478. };
  8479. AnimationItem.prototype.updaFrameModifier = function () {
  8480. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  8481. };
  8482. AnimationItem.prototype.getPath = function () {
  8483. return this.path;
  8484. };
  8485. AnimationItem.prototype.getAssetsPath = function (assetData) {
  8486. var path = '';
  8487. if(assetData.e) {
  8488. path = assetData.p;
  8489. } else if(this.assetsPath){
  8490. var imagePath = assetData.p;
  8491. if(imagePath.indexOf('images/') !== -1){
  8492. imagePath = imagePath.split('/')[1];
  8493. }
  8494. path = this.assetsPath + imagePath;
  8495. } else {
  8496. path = this.path;
  8497. path += assetData.u ? assetData.u : '';
  8498. path += assetData.p;
  8499. }
  8500. return path;
  8501. };
  8502. AnimationItem.prototype.getAssetData = function (id) {
  8503. var i = 0, len = this.assets.length;
  8504. while (i < len) {
  8505. if(id == this.assets[i].id){
  8506. return this.assets[i];
  8507. }
  8508. i += 1;
  8509. }
  8510. };
  8511. AnimationItem.prototype.hide = function () {
  8512. this.renderer.hide();
  8513. };
  8514. AnimationItem.prototype.show = function () {
  8515. this.renderer.show();
  8516. };
  8517. AnimationItem.prototype.getDuration = function (isFrame) {
  8518. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  8519. };
  8520. AnimationItem.prototype.trigger = function(name){
  8521. if(this._cbs && this._cbs[name]){
  8522. switch(name){
  8523. case 'enterFrame':
  8524. this.triggerEvent(name,new BMEnterFrameEvent(name,this.currentFrame,this.totalFrames,this.frameModifier));
  8525. break;
  8526. case 'loopComplete':
  8527. this.triggerEvent(name,new BMCompleteLoopEvent(name,this.loop,this.playCount,this.frameMult));
  8528. break;
  8529. case 'complete':
  8530. this.triggerEvent(name,new BMCompleteEvent(name,this.frameMult));
  8531. break;
  8532. case 'segmentStart':
  8533. this.triggerEvent(name,new BMSegmentStartEvent(name,this.firstFrame,this.totalFrames));
  8534. break;
  8535. case 'destroy':
  8536. this.triggerEvent(name,new BMDestroyEvent(name,this));
  8537. break;
  8538. default:
  8539. this.triggerEvent(name);
  8540. }
  8541. }
  8542. if(name === 'enterFrame' && this.onEnterFrame){
  8543. this.onEnterFrame.call(this,new BMEnterFrameEvent(name,this.currentFrame,this.totalFrames,this.frameMult));
  8544. }
  8545. if(name === 'loopComplete' && this.onLoopComplete){
  8546. this.onLoopComplete.call(this,new BMCompleteLoopEvent(name,this.loop,this.playCount,this.frameMult));
  8547. }
  8548. if(name === 'complete' && this.onComplete){
  8549. this.onComplete.call(this,new BMCompleteEvent(name,this.frameMult));
  8550. }
  8551. if(name === 'segmentStart' && this.onSegmentStart){
  8552. this.onSegmentStart.call(this,new BMSegmentStartEvent(name,this.firstFrame,this.totalFrames));
  8553. }
  8554. if(name === 'destroy' && this.onDestroy){
  8555. this.onDestroy.call(this,new BMDestroyEvent(name,this));
  8556. }
  8557. };
  8558. AnimationItem.prototype.setParams = function(params) {
  8559. if(params.context){
  8560. this.context = params.context;
  8561. }
  8562. var animType = params.animType ? params.animType : params.renderer ? params.renderer : 'svg';
  8563. switch(animType){
  8564. case 'canvas':
  8565. this.renderer = new CanvasRenderer(this, params.rendererSettings);
  8566. break;
  8567. default:
  8568. throw new Error('Only canvas renderer is supported when using worker.');
  8569. break;
  8570. }
  8571. this.renderer.setProjectInterface(this.projectInterface);
  8572. this.animType = animType;
  8573. if(params.loop === '' || params.loop === null){
  8574. }else if(params.loop === false){
  8575. this.loop = false;
  8576. }else if(params.loop === true){
  8577. this.loop = true;
  8578. }else{
  8579. this.loop = parseInt(params.loop);
  8580. }
  8581. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  8582. this.name = params.name ? params.name : '';
  8583. this.autoloadSegments = params.hasOwnProperty('autoloadSegments') ? params.autoloadSegments : true;
  8584. this.assetsPath = null;
  8585. if(params.animationData){
  8586. this.configAnimation(params.animationData);
  8587. }else if(params.path){
  8588. throw new Error('Canvas worker renderer cannot load animation from url');
  8589. }
  8590. };
  8591. AnimationItem.prototype.setData = function (wrapper, animationData) {
  8592. throw new Error('Cannot set data on wrapper for canvas worker renderer');
  8593. };
  8594. AnimationItem.prototype.includeLayers = function(data) {
  8595. if(data.op > this.animationData.op){
  8596. this.animationData.op = data.op;
  8597. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  8598. }
  8599. var layers = this.animationData.layers;
  8600. var i, len = layers.length;
  8601. var newLayers = data.layers;
  8602. var j, jLen = newLayers.length;
  8603. for(j=0;j<jLen;j+=1){
  8604. i = 0;
  8605. while(i<len){
  8606. if(layers[i].id == newLayers[j].id){
  8607. layers[i] = newLayers[j];
  8608. break;
  8609. }
  8610. i += 1;
  8611. }
  8612. }
  8613. this.animationData.__complete = false;
  8614. dataManager.completeData(this.animationData,this.renderer.globalData.fontManager);
  8615. this.renderer.includeLayers(data.layers);
  8616. if(expressionsPlugin){
  8617. expressionsPlugin.initExpressions(this);
  8618. }
  8619. this.loadNextSegment();
  8620. };
  8621. AnimationItem.prototype.loadNextSegment = function() {
  8622. var segments = this.animationData.segments;
  8623. if(!segments || segments.length === 0 || !this.autoloadSegments){
  8624. this.timeCompleted = this.totalFrames;
  8625. return;
  8626. }
  8627. throw new Error('Cannot load multiple segments in worker.');
  8628. };
  8629. AnimationItem.prototype.loadSegments = function() {
  8630. var segments = this.animationData.segments;
  8631. if(!segments) {
  8632. this.timeCompleted = this.totalFrames;
  8633. }
  8634. this.loadNextSegment();
  8635. };
  8636. AnimationItem.prototype.imagesLoaded = null;
  8637. AnimationItem.prototype.preloadImages = null;
  8638. AnimationItem.prototype.configAnimation = function (animData) {
  8639. if(!this.renderer){
  8640. return;
  8641. }
  8642. this.animationData = animData;
  8643. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  8644. this.renderer.configAnimation(animData);
  8645. if(!animData.assets){
  8646. animData.assets = [];
  8647. }
  8648. this.renderer.searchExtraCompositions(animData.assets);
  8649. this.assets = this.animationData.assets;
  8650. this.frameRate = this.animationData.fr;
  8651. this.firstFrame = Math.round(this.animationData.ip);
  8652. this.frameMult = this.animationData.fr / 1000;
  8653. this.loadSegments();
  8654. this.updaFrameModifier();
  8655. this.checkLoaded();
  8656. };
  8657. AnimationItem.prototype.waitForFontsLoaded = null;
  8658. AnimationItem.prototype.checkLoaded = function () {
  8659. if (!this.isLoaded) {
  8660. this.isLoaded = true;
  8661. dataManager.completeData(this.animationData, null);
  8662. if(expressionsPlugin){
  8663. expressionsPlugin.initExpressions(this);
  8664. }
  8665. this.renderer.initItems();
  8666. this.gotoFrame();
  8667. }
  8668. };
  8669. AnimationItem.prototype.destroy = function (name) {
  8670. if ((name && this.name != name) || !this.renderer) {
  8671. return;
  8672. }
  8673. this.renderer.destroy();
  8674. this._cbs = null;
  8675. this.onEnterFrame = this.onLoopComplete = this.onComplete = this.onSegmentStart = this.onDestroy = null;
  8676. this.renderer = null;
  8677. };
  8678. AnimationItem.prototype.getPath = null;
  8679. var Expressions = (function(){
  8680. var ob = {};
  8681. ob.initExpressions = initExpressions;
  8682. function initExpressions(animation){
  8683. var stackCount = 0;
  8684. var registers = [];
  8685. function pushExpression() {
  8686. stackCount += 1;
  8687. }
  8688. function popExpression() {
  8689. stackCount -= 1;
  8690. if (stackCount === 0) {
  8691. releaseInstances();
  8692. }
  8693. }
  8694. function registerExpressionProperty(expression) {
  8695. if (registers.indexOf(expression) === -1) {
  8696. registers.push(expression)
  8697. }
  8698. }
  8699. function releaseInstances() {
  8700. var i, len = registers.length;
  8701. for (i = 0; i < len; i += 1) {
  8702. registers[i].release();
  8703. }
  8704. registers.length = 0;
  8705. }
  8706. animation.renderer.compInterface = CompExpressionInterface(animation.renderer);
  8707. animation.renderer.globalData.projectInterface.registerComposition(animation.renderer);
  8708. animation.renderer.globalData.pushExpression = pushExpression;
  8709. animation.renderer.globalData.popExpression = popExpression;
  8710. animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty;
  8711. }
  8712. return ob;
  8713. }());
  8714. expressionsPlugin = Expressions;
  8715. var ExpressionManager = (function(){
  8716. 'use strict';
  8717. var ob = {};
  8718. var Math = BMMath;
  8719. var window = null;
  8720. var document = null;
  8721. function $bm_isInstanceOfArray(arr) {
  8722. return arr.constructor === Array || arr.constructor === Float32Array;
  8723. }
  8724. function isNumerable(tOfV, v) {
  8725. return tOfV === 'number' || tOfV === 'boolean' || tOfV === 'string' || v instanceof Number;
  8726. }
  8727. function $bm_neg(a){
  8728. var tOfA = typeof a;
  8729. if(tOfA === 'number' || tOfA === 'boolean' || a instanceof Number ){
  8730. return -a;
  8731. }
  8732. if($bm_isInstanceOfArray(a)){
  8733. var i, lenA = a.length;
  8734. var retArr = [];
  8735. for(i=0;i<lenA;i+=1){
  8736. retArr[i] = -a[i];
  8737. }
  8738. return retArr;
  8739. }
  8740. if (a.propType) {
  8741. return a.v;
  8742. }
  8743. }
  8744. var easeInBez = BezierFactory.getBezierEasing(0.333,0,.833,.833, 'easeIn').get;
  8745. var easeOutBez = BezierFactory.getBezierEasing(0.167,0.167,.667,1, 'easeOut').get;
  8746. var easeInOutBez = BezierFactory.getBezierEasing(.33,0,.667,1, 'easeInOut').get;
  8747. function sum(a,b) {
  8748. var tOfA = typeof a;
  8749. var tOfB = typeof b;
  8750. if(tOfA === 'string' || tOfB === 'string'){
  8751. return a + b;
  8752. }
  8753. if(isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  8754. return a + b;
  8755. }
  8756. if($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)){
  8757. a = a.slice(0);
  8758. a[0] = a[0] + b;
  8759. return a;
  8760. }
  8761. if(isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)){
  8762. b = b.slice(0);
  8763. b[0] = a + b[0];
  8764. return b;
  8765. }
  8766. if($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)){
  8767. var i = 0, lenA = a.length, lenB = b.length;
  8768. var retArr = [];
  8769. while(i<lenA || i < lenB){
  8770. if((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)){
  8771. retArr[i] = a[i] + b[i];
  8772. }else{
  8773. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  8774. }
  8775. i += 1;
  8776. }
  8777. return retArr;
  8778. }
  8779. return 0;
  8780. }
  8781. var add = sum;
  8782. function sub(a,b) {
  8783. var tOfA = typeof a;
  8784. var tOfB = typeof b;
  8785. if(isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  8786. if(tOfA === 'string') {
  8787. a = parseInt(a);
  8788. }
  8789. if(tOfB === 'string') {
  8790. b = parseInt(b);
  8791. }
  8792. return a - b;
  8793. }
  8794. if( $bm_isInstanceOfArray(a) && isNumerable(tOfB, b)){
  8795. a = a.slice(0);
  8796. a[0] = a[0] - b;
  8797. return a;
  8798. }
  8799. if(isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)){
  8800. b = b.slice(0);
  8801. b[0] = a - b[0];
  8802. return b;
  8803. }
  8804. if($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)){
  8805. var i = 0, lenA = a.length, lenB = b.length;
  8806. var retArr = [];
  8807. while(i<lenA || i < lenB){
  8808. if((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)){
  8809. retArr[i] = a[i] - b[i];
  8810. }else{
  8811. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  8812. }
  8813. i += 1;
  8814. }
  8815. return retArr;
  8816. }
  8817. return 0;
  8818. }
  8819. function mul(a,b) {
  8820. var tOfA = typeof a;
  8821. var tOfB = typeof b;
  8822. var arr;
  8823. if(isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  8824. return a * b;
  8825. }
  8826. var i, len;
  8827. if($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)){
  8828. len = a.length;
  8829. arr = createTypedArray('float32', len);
  8830. for(i=0;i<len;i+=1){
  8831. arr[i] = a[i] * b;
  8832. }
  8833. return arr;
  8834. }
  8835. if(isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)){
  8836. len = b.length;
  8837. arr = createTypedArray('float32', len);
  8838. for(i=0;i<len;i+=1){
  8839. arr[i] = a * b[i];
  8840. }
  8841. return arr;
  8842. }
  8843. return 0;
  8844. }
  8845. function div(a,b) {
  8846. var tOfA = typeof a;
  8847. var tOfB = typeof b;
  8848. var arr;
  8849. if(isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  8850. return a / b;
  8851. }
  8852. var i, len;
  8853. if($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)){
  8854. len = a.length;
  8855. arr = createTypedArray('float32', len);
  8856. for(i=0;i<len;i+=1){
  8857. arr[i] = a[i] / b;
  8858. }
  8859. return arr;
  8860. }
  8861. if(isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)){
  8862. len = b.length;
  8863. arr = createTypedArray('float32', len);
  8864. for(i=0;i<len;i+=1){
  8865. arr[i] = a / b[i];
  8866. }
  8867. return arr;
  8868. }
  8869. return 0;
  8870. }
  8871. function mod(a,b) {
  8872. if(typeof a === 'string') {
  8873. a = parseInt(a);
  8874. }
  8875. if(typeof b === 'string') {
  8876. b = parseInt(b);
  8877. }
  8878. return a % b;
  8879. }
  8880. var $bm_sum = sum;
  8881. var $bm_sub = sub;
  8882. var $bm_mul = mul;
  8883. var $bm_div = div;
  8884. var $bm_mod = mod;
  8885. function clamp(num, min, max) {
  8886. if(min > max){
  8887. var mm = max;
  8888. max = min;
  8889. min = mm;
  8890. }
  8891. return Math.min(Math.max(num, min), max);
  8892. }
  8893. function radiansToDegrees(val) {
  8894. return val/degToRads;
  8895. }
  8896. var radians_to_degrees = radiansToDegrees;
  8897. function degreesToRadians(val) {
  8898. return val*degToRads;
  8899. }
  8900. var degrees_to_radians = radiansToDegrees;
  8901. var helperLengthArray = [0,0,0,0,0,0];
  8902. function length(arr1, arr2) {
  8903. if (typeof arr1 === 'number' || arr1 instanceof Number) {
  8904. arr2 = arr2 || 0;
  8905. return Math.abs(arr1 - arr2);
  8906. }
  8907. if(!arr2) {
  8908. arr2 = helperLengthArray;
  8909. }
  8910. var i, len = Math.min(arr1.length, arr2.length);
  8911. var addedLength = 0;
  8912. for (i = 0; i < len; i += 1) {
  8913. addedLength += Math.pow(arr2[i] - arr1[i], 2);
  8914. }
  8915. return Math.sqrt(addedLength);
  8916. }
  8917. function normalize(vec) {
  8918. return div(vec, length(vec));
  8919. }
  8920. function rgbToHsl(val) {
  8921. var r = val[0]; var g = val[1]; var b = val[2];
  8922. var max = Math.max(r, g, b), min = Math.min(r, g, b);
  8923. var h, s, l = (max + min) / 2;
  8924. if(max == min){
  8925. h = s = 0; // achromatic
  8926. }else{
  8927. var d = max - min;
  8928. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  8929. switch(max){
  8930. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  8931. case g: h = (b - r) / d + 2; break;
  8932. case b: h = (r - g) / d + 4; break;
  8933. }
  8934. h /= 6;
  8935. }
  8936. return [h, s, l,val[3]];
  8937. }
  8938. function hue2rgb(p, q, t){
  8939. if(t < 0) t += 1;
  8940. if(t > 1) t -= 1;
  8941. if(t < 1/6) return p + (q - p) * 6 * t;
  8942. if(t < 1/2) return q;
  8943. if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
  8944. return p;
  8945. }
  8946. function hslToRgb(val){
  8947. var h = val[0];
  8948. var s = val[1];
  8949. var l = val[2];
  8950. var r, g, b;
  8951. if(s === 0){
  8952. r = g = b = l; // achromatic
  8953. }else{
  8954. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  8955. var p = 2 * l - q;
  8956. r = hue2rgb(p, q, h + 1/3);
  8957. g = hue2rgb(p, q, h);
  8958. b = hue2rgb(p, q, h - 1/3);
  8959. }
  8960. return [r, g , b, val[3]];
  8961. }
  8962. function linear(t, tMin, tMax, value1, value2){
  8963. if(value1 === undefined || value2 === undefined){
  8964. value1 = tMin;
  8965. value2 = tMax;
  8966. tMin = 0;
  8967. tMax = 1;
  8968. }
  8969. if(tMax < tMin) {
  8970. var _tMin = tMax;
  8971. tMax = tMin;
  8972. tMin = _tMin;
  8973. }
  8974. if(t <= tMin) {
  8975. return value1;
  8976. }else if(t >= tMax){
  8977. return value2;
  8978. }
  8979. var perc = tMax === tMin ? 0 : (t-tMin)/(tMax-tMin);
  8980. if(!value1.length){
  8981. return value1 + (value2-value1)*perc;
  8982. }
  8983. var i, len = value1.length;
  8984. var arr = createTypedArray('float32', len);
  8985. for(i=0;i<len;i+=1){
  8986. arr[i] = value1[i] + (value2[i]-value1[i])*perc;
  8987. }
  8988. return arr;
  8989. }
  8990. function random(min,max){
  8991. if(max === undefined){
  8992. if(min === undefined){
  8993. min = 0;
  8994. max = 1;
  8995. } else {
  8996. max = min;
  8997. min = undefined;
  8998. }
  8999. }
  9000. if(max.length){
  9001. var i, len = max.length;
  9002. if(!min){
  9003. min = createTypedArray('float32', len);
  9004. }
  9005. var arr = createTypedArray('float32', len);
  9006. var rnd = BMMath.random();
  9007. for(i=0;i<len;i+=1){
  9008. arr[i] = min[i] + rnd*(max[i]-min[i]);
  9009. }
  9010. return arr;
  9011. }
  9012. if(min === undefined){
  9013. min = 0;
  9014. }
  9015. var rndm = BMMath.random();
  9016. return min + rndm*(max-min);
  9017. }
  9018. function createPath(points, inTangents, outTangents, closed) {
  9019. var i, len = points.length;
  9020. var path = shape_pool.newElement();
  9021. path.setPathData(!!closed, len);
  9022. var arrPlaceholder = [0,0], inVertexPoint, outVertexPoint;
  9023. for(i = 0; i < len; i += 1) {
  9024. inVertexPoint = (inTangents && inTangents[i]) ? inTangents[i] : arrPlaceholder;
  9025. outVertexPoint = (outTangents && outTangents[i]) ? outTangents[i] : arrPlaceholder;
  9026. 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);
  9027. }
  9028. return path;
  9029. }
  9030. function initiateExpression(elem,data,property){
  9031. var val = data.x;
  9032. var needsVelocity = /velocity(?![\w\d])/.test(val);
  9033. var _needsRandom = val.indexOf('random') !== -1;
  9034. var elemType = elem.data.ty;
  9035. var transform,$bm_transform,content,effect;
  9036. var thisProperty = property;
  9037. thisProperty.valueAtTime = thisProperty.getValueAtTime;
  9038. Object.defineProperty(thisProperty, 'value', {
  9039. get: function() {
  9040. return thisProperty.v
  9041. }
  9042. })
  9043. elem.comp.frameDuration = 1/elem.comp.globalData.frameRate;
  9044. elem.comp.displayStartTime = 0;
  9045. var inPoint = elem.data.ip/elem.comp.globalData.frameRate;
  9046. var outPoint = elem.data.op/elem.comp.globalData.frameRate;
  9047. var width = elem.data.sw ? elem.data.sw : 0;
  9048. var height = elem.data.sh ? elem.data.sh : 0;
  9049. var name = elem.data.nm;
  9050. var loopIn, loop_in, loopOut, loop_out, smooth;
  9051. var toWorld,fromWorld,fromComp,toComp,fromCompToSurface, position, rotation, anchorPoint, scale, thisLayer,thisComp,mask,valueAtTime,velocityAtTime;
  9052. var __expression_functions = [];
  9053. if(data.xf) {
  9054. var i, len = data.xf.length;
  9055. for(i = 0; i < len; i += 1) {
  9056. __expression_functions[i] = eval('(function(){ return ' + data.xf[i] + '}())');
  9057. }
  9058. }
  9059. var scoped_bm_rt;
  9060. var expression_function = eval('[function _expression_function(){' + val+';scoped_bm_rt=$bm_rt}' + ']')[0];
  9061. var numKeys = property.kf ? data.k.length : 0;
  9062. var active = !this.data || this.data.hd !== true;
  9063. var wiggle = function wiggle(freq,amp){
  9064. var i,j, len = this.pv.length ? this.pv.length : 1;
  9065. var addedAmps = createTypedArray('float32', len);
  9066. freq = 5;
  9067. var iterations = Math.floor(time*freq);
  9068. i = 0;
  9069. j = 0;
  9070. while(i<iterations){
  9071. //var rnd = BMMath.random();
  9072. for(j=0;j<len;j+=1){
  9073. addedAmps[j] += -amp + amp*2*BMMath.random();
  9074. //addedAmps[j] += -amp + amp*2*rnd;
  9075. }
  9076. i += 1;
  9077. }
  9078. //var rnd2 = BMMath.random();
  9079. var periods = time*freq;
  9080. var perc = periods - Math.floor(periods);
  9081. var arr = createTypedArray('float32', len);
  9082. if(len>1){
  9083. for(j=0;j<len;j+=1){
  9084. arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*BMMath.random())*perc;
  9085. //arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc;
  9086. //arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc);
  9087. }
  9088. return arr;
  9089. } else {
  9090. return this.pv + addedAmps[0] + (-amp + amp*2*BMMath.random())*perc;
  9091. }
  9092. }.bind(this);
  9093. if(thisProperty.loopIn) {
  9094. loopIn = thisProperty.loopIn.bind(thisProperty);
  9095. loop_in = loopIn;
  9096. }
  9097. if(thisProperty.loopOut) {
  9098. loopOut = thisProperty.loopOut.bind(thisProperty);
  9099. loop_out = loopOut;
  9100. }
  9101. if(thisProperty.smooth) {
  9102. smooth = thisProperty.smooth.bind(thisProperty);
  9103. }
  9104. function loopInDuration(type,duration){
  9105. return loopIn(type,duration,true);
  9106. }
  9107. function loopOutDuration(type,duration){
  9108. return loopOut(type,duration,true);
  9109. }
  9110. if(this.getValueAtTime) {
  9111. valueAtTime = this.getValueAtTime.bind(this);
  9112. }
  9113. if(this.getVelocityAtTime) {
  9114. velocityAtTime = this.getVelocityAtTime.bind(this);
  9115. }
  9116. var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface);
  9117. function lookAt(elem1,elem2){
  9118. var fVec = [elem2[0]-elem1[0],elem2[1]-elem1[1],elem2[2]-elem1[2]];
  9119. var pitch = Math.atan2(fVec[0],Math.sqrt(fVec[1]*fVec[1]+fVec[2]*fVec[2]))/degToRads;
  9120. var yaw = -Math.atan2(fVec[1],fVec[2])/degToRads;
  9121. return [yaw,pitch,0];
  9122. }
  9123. function easeOut(t, tMin, tMax, val1, val2){
  9124. return applyEase(easeOutBez, t, tMin, tMax, val1, val2);
  9125. }
  9126. function easeIn(t, tMin, tMax, val1, val2){
  9127. return applyEase(easeInBez, t, tMin, tMax, val1, val2);
  9128. }
  9129. function ease(t, tMin, tMax, val1, val2){
  9130. return applyEase(easeInOutBez, t, tMin, tMax, val1, val2);
  9131. }
  9132. function applyEase(fn, t, tMin, tMax, val1, val2) {
  9133. if(val1 === undefined){
  9134. val1 = tMin;
  9135. val2 = tMax;
  9136. } else {
  9137. t = (t - tMin) / (tMax - tMin);
  9138. }
  9139. t = t > 1 ? 1 : t < 0 ? 0 : t;
  9140. var mult = fn(t);
  9141. if($bm_isInstanceOfArray(val1)) {
  9142. var i, len = val1.length;
  9143. var arr = createTypedArray('float32', len);
  9144. for (i = 0; i < len; i += 1) {
  9145. arr[i] = (val2[i] - val1[i]) * mult + val1[i];
  9146. }
  9147. return arr;
  9148. } else {
  9149. return (val2 - val1) * mult + val1;
  9150. }
  9151. }
  9152. function nearestKey(time){
  9153. var i, len = data.k.length,index,keyTime;
  9154. if(!data.k.length || typeof(data.k[0]) === 'number'){
  9155. index = 0;
  9156. keyTime = 0;
  9157. } else {
  9158. index = -1;
  9159. time *= elem.comp.globalData.frameRate;
  9160. if (time < data.k[0].t) {
  9161. index = 1;
  9162. keyTime = data.k[0].t;
  9163. } else {
  9164. for(i=0;i<len-1;i+=1){
  9165. if(time === data.k[i].t){
  9166. index = i + 1;
  9167. keyTime = data.k[i].t;
  9168. break;
  9169. }else if(time>data.k[i].t && time<data.k[i+1].t){
  9170. if(time-data.k[i].t > data.k[i+1].t - time){
  9171. index = i + 2;
  9172. keyTime = data.k[i+1].t;
  9173. } else {
  9174. index = i + 1;
  9175. keyTime = data.k[i].t;
  9176. }
  9177. break;
  9178. }
  9179. }
  9180. if(index === -1){
  9181. index = i + 1;
  9182. keyTime = data.k[i].t;
  9183. }
  9184. }
  9185. }
  9186. var ob = {};
  9187. ob.index = index;
  9188. ob.time = keyTime/elem.comp.globalData.frameRate;
  9189. return ob;
  9190. }
  9191. function key(ind){
  9192. var ob, i, len;
  9193. if(!data.k.length || typeof(data.k[0]) === 'number'){
  9194. throw new Error('The property has no keyframe at index ' + ind);
  9195. }
  9196. ind -= 1;
  9197. ob = {
  9198. time: data.k[ind].t/elem.comp.globalData.frameRate,
  9199. value: []
  9200. };
  9201. var arr;
  9202. if(ind === data.k.length - 1 && !data.k[ind].h){
  9203. arr = (data.k[ind].s || data.k[ind].s === 0) ? data.k[ind-1].s : data.k[ind].e;
  9204. }else{
  9205. arr = data.k[ind].s;
  9206. }
  9207. len = arr.length;
  9208. for(i=0;i<len;i+=1){
  9209. ob[i] = arr[i];
  9210. ob.value[i] = arr[i]
  9211. }
  9212. return ob;
  9213. }
  9214. function framesToTime(frames, fps) {
  9215. if (!fps) {
  9216. fps = elem.comp.globalData.frameRate;
  9217. }
  9218. return frames / fps;
  9219. }
  9220. function timeToFrames(t, fps) {
  9221. if (!t && t !== 0) {
  9222. t = time;
  9223. }
  9224. if (!fps) {
  9225. fps = elem.comp.globalData.frameRate;
  9226. }
  9227. return t * fps;
  9228. }
  9229. function seedRandom(seed){
  9230. BMMath.seedrandom(randSeed + seed);
  9231. }
  9232. function sourceRectAtTime() {
  9233. return elem.sourceRectAtTime();
  9234. }
  9235. function substring(init, end) {
  9236. if(typeof value === 'string') {
  9237. if(end === undefined) {
  9238. return value.substring(init)
  9239. }
  9240. return value.substring(init, end)
  9241. }
  9242. return '';
  9243. }
  9244. function substr(init, end) {
  9245. if(typeof value === 'string') {
  9246. if(end === undefined) {
  9247. return value.substr(init)
  9248. }
  9249. return value.substr(init, end)
  9250. }
  9251. return '';
  9252. }
  9253. var time, velocity, value, text, textIndex, textTotal, selectorValue;
  9254. var index = elem.data.ind;
  9255. var hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  9256. var parent;
  9257. var randSeed = Math.floor(Math.random()*1000000);
  9258. var globalData = elem.globalData;
  9259. function executeExpression(_value) {
  9260. // globalData.pushExpression();
  9261. value = _value;
  9262. if (_needsRandom) {
  9263. seedRandom(randSeed);
  9264. }
  9265. if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') {
  9266. return value;
  9267. }
  9268. if(this.propType === 'textSelector'){
  9269. textIndex = this.textIndex;
  9270. textTotal = this.textTotal;
  9271. selectorValue = this.selectorValue;
  9272. }
  9273. if (!thisLayer) {
  9274. text = elem.layerInterface.text;
  9275. thisLayer = elem.layerInterface;
  9276. thisComp = elem.comp.compInterface;
  9277. toWorld = thisLayer.toWorld.bind(thisLayer);
  9278. fromWorld = thisLayer.fromWorld.bind(thisLayer);
  9279. fromComp = thisLayer.fromComp.bind(thisLayer);
  9280. toComp = thisLayer.toComp.bind(thisLayer);
  9281. mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null;
  9282. fromCompToSurface = fromComp;
  9283. }
  9284. if (!transform) {
  9285. transform = elem.layerInterface("ADBE Transform Group");
  9286. $bm_transform = transform;
  9287. if(transform) {
  9288. anchorPoint = transform.anchorPoint;
  9289. /*position = transform.position;
  9290. rotation = transform.rotation;
  9291. scale = transform.scale;*/
  9292. }
  9293. }
  9294. if (elemType === 4 && !content) {
  9295. content = thisLayer("ADBE Root Vectors Group");
  9296. }
  9297. if (!effect) {
  9298. effect = thisLayer(4);
  9299. }
  9300. hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  9301. if (hasParent && !parent) {
  9302. parent = elem.hierarchy[0].layerInterface;
  9303. }
  9304. time = this.comp.renderedFrame/this.comp.globalData.frameRate;
  9305. if (needsVelocity) {
  9306. velocity = velocityAtTime(time);
  9307. }
  9308. expression_function();
  9309. this.frameExpressionId = elem.globalData.frameId;
  9310. //TODO: Check if it's possible to return on ShapeInterface the .v value
  9311. if (scoped_bm_rt.propType === "shape") {
  9312. scoped_bm_rt = scoped_bm_rt.v;
  9313. }
  9314. // globalData.popExpression();
  9315. return scoped_bm_rt;
  9316. }
  9317. return executeExpression;
  9318. }
  9319. ob.initiateExpression = initiateExpression;
  9320. return ob;
  9321. }());
  9322. var expressionHelpers = (function(){
  9323. function searchExpressions(elem,data,prop){
  9324. if(data.x){
  9325. prop.k = true;
  9326. prop.x = true;
  9327. prop.initiateExpression = ExpressionManager.initiateExpression;
  9328. prop.effectsSequence.push(prop.initiateExpression(elem,data,prop).bind(prop));
  9329. }
  9330. }
  9331. function getValueAtTime(frameNum) {
  9332. frameNum *= this.elem.globalData.frameRate;
  9333. frameNum -= this.offsetTime;
  9334. if(frameNum !== this._cachingAtTime.lastFrame) {
  9335. this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
  9336. this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
  9337. this._cachingAtTime.lastFrame = frameNum;
  9338. }
  9339. return this._cachingAtTime.value;
  9340. }
  9341. function getSpeedAtTime(frameNum) {
  9342. var delta = -0.01;
  9343. var v1 = this.getValueAtTime(frameNum);
  9344. var v2 = this.getValueAtTime(frameNum + delta);
  9345. var speed = 0;
  9346. if(v1.length){
  9347. var i;
  9348. for(i=0;i<v1.length;i+=1){
  9349. speed += Math.pow(v2[i] - v1[i], 2);
  9350. }
  9351. speed = Math.sqrt(speed) * 100;
  9352. } else {
  9353. speed = 0;
  9354. }
  9355. return speed;
  9356. }
  9357. function getVelocityAtTime(frameNum) {
  9358. if(this.vel !== undefined){
  9359. return this.vel;
  9360. }
  9361. var delta = -0.001;
  9362. //frameNum += this.elem.data.st;
  9363. var v1 = this.getValueAtTime(frameNum);
  9364. var v2 = this.getValueAtTime(frameNum + delta);
  9365. var velocity;
  9366. if(v1.length){
  9367. velocity = createTypedArray('float32', v1.length);
  9368. var i;
  9369. for(i=0;i<v1.length;i+=1){
  9370. //removing frameRate
  9371. //if needed, don't add it here
  9372. //velocity[i] = this.elem.globalData.frameRate*((v2[i] - v1[i])/delta);
  9373. velocity[i] = (v2[i] - v1[i])/delta;
  9374. }
  9375. } else {
  9376. velocity = (v2 - v1)/delta;
  9377. }
  9378. return velocity;
  9379. }
  9380. function getStaticValueAtTime() {
  9381. return this.pv;
  9382. }
  9383. function setGroupProperty(propertyGroup){
  9384. this.propertyGroup = propertyGroup;
  9385. }
  9386. return {
  9387. searchExpressions: searchExpressions,
  9388. getSpeedAtTime: getSpeedAtTime,
  9389. getVelocityAtTime: getVelocityAtTime,
  9390. getValueAtTime: getValueAtTime,
  9391. getStaticValueAtTime: getStaticValueAtTime,
  9392. setGroupProperty: setGroupProperty,
  9393. }
  9394. }());
  9395. (function addPropertyDecorator() {
  9396. function loopOut(type,duration,durationFlag){
  9397. if(!this.k || !this.keyframes){
  9398. return this.pv;
  9399. }
  9400. type = type ? type.toLowerCase() : '';
  9401. var currentFrame = this.comp.renderedFrame;
  9402. var keyframes = this.keyframes;
  9403. var lastKeyFrame = keyframes[keyframes.length - 1].t;
  9404. if(currentFrame<=lastKeyFrame){
  9405. return this.pv;
  9406. }else{
  9407. var cycleDuration, firstKeyFrame;
  9408. if(!durationFlag){
  9409. if(!duration || duration > keyframes.length - 1){
  9410. duration = keyframes.length - 1;
  9411. }
  9412. firstKeyFrame = keyframes[keyframes.length - 1 - duration].t;
  9413. cycleDuration = lastKeyFrame - firstKeyFrame;
  9414. } else {
  9415. if(!duration){
  9416. cycleDuration = Math.max(0,lastKeyFrame - this.elem.data.ip);
  9417. } else {
  9418. cycleDuration = Math.abs(lastKeyFrame - elem.comp.globalData.frameRate*duration);
  9419. }
  9420. firstKeyFrame = lastKeyFrame - cycleDuration;
  9421. }
  9422. var i, len, ret;
  9423. if(type === 'pingpong') {
  9424. var iterations = Math.floor((currentFrame - firstKeyFrame)/cycleDuration);
  9425. if(iterations % 2 !== 0){
  9426. return this.getValueAtTime(((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0);
  9427. }
  9428. } else if(type === 'offset'){
  9429. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  9430. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  9431. var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
  9432. var repeats = Math.floor((currentFrame - firstKeyFrame)/cycleDuration);
  9433. if(this.pv.length){
  9434. ret = new Array(initV.length);
  9435. len = ret.length;
  9436. for(i=0;i<len;i+=1){
  9437. ret[i] = (endV[i]-initV[i])*repeats + current[i];
  9438. }
  9439. return ret;
  9440. }
  9441. return (endV-initV)*repeats + current;
  9442. } else if(type === 'continue'){
  9443. var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  9444. var nextLastValue = this.getValueAtTime((lastKeyFrame - 0.001) / this.comp.globalData.frameRate, 0);
  9445. if(this.pv.length){
  9446. ret = new Array(lastValue.length);
  9447. len = ret.length;
  9448. for(i=0;i<len;i+=1){
  9449. ret[i] = lastValue[i] + (lastValue[i]-nextLastValue[i])*((currentFrame - lastKeyFrame)/ this.comp.globalData.frameRate)/0.0005;
  9450. }
  9451. return ret;
  9452. }
  9453. return lastValue + (lastValue-nextLastValue)*(((currentFrame - lastKeyFrame))/0.001);
  9454. }
  9455. return this.getValueAtTime((((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0);
  9456. }
  9457. }
  9458. function loopIn(type,duration, durationFlag) {
  9459. if(!this.k){
  9460. return this.pv;
  9461. }
  9462. type = type ? type.toLowerCase() : '';
  9463. var currentFrame = this.comp.renderedFrame;
  9464. var keyframes = this.keyframes;
  9465. var firstKeyFrame = keyframes[0].t;
  9466. if(currentFrame>=firstKeyFrame){
  9467. return this.pv;
  9468. }else{
  9469. var cycleDuration, lastKeyFrame;
  9470. if(!durationFlag){
  9471. if(!duration || duration > keyframes.length - 1){
  9472. duration = keyframes.length - 1;
  9473. }
  9474. lastKeyFrame = keyframes[duration].t;
  9475. cycleDuration = lastKeyFrame - firstKeyFrame;
  9476. } else {
  9477. if(!duration){
  9478. cycleDuration = Math.max(0,this.elem.data.op - firstKeyFrame);
  9479. } else {
  9480. cycleDuration = Math.abs(elem.comp.globalData.frameRate*duration);
  9481. }
  9482. lastKeyFrame = firstKeyFrame + cycleDuration;
  9483. }
  9484. var i, len, ret;
  9485. if(type === 'pingpong') {
  9486. var iterations = Math.floor((firstKeyFrame - currentFrame)/cycleDuration);
  9487. if(iterations % 2 === 0){
  9488. return this.getValueAtTime((((firstKeyFrame - currentFrame)%cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0);
  9489. }
  9490. } else if(type === 'offset'){
  9491. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  9492. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  9493. var current = this.getValueAtTime((cycleDuration - (firstKeyFrame - currentFrame)%cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
  9494. var repeats = Math.floor((firstKeyFrame - currentFrame)/cycleDuration)+1;
  9495. if(this.pv.length){
  9496. ret = new Array(initV.length);
  9497. len = ret.length;
  9498. for(i=0;i<len;i+=1){
  9499. ret[i] = current[i]-(endV[i]-initV[i])*repeats;
  9500. }
  9501. return ret;
  9502. }
  9503. return current-(endV-initV)*repeats;
  9504. } else if(type === 'continue'){
  9505. var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  9506. var nextFirstValue = this.getValueAtTime((firstKeyFrame + 0.001) / this.comp.globalData.frameRate, 0);
  9507. if(this.pv.length){
  9508. ret = new Array(firstValue.length);
  9509. len = ret.length;
  9510. for(i=0;i<len;i+=1){
  9511. ret[i] = firstValue[i] + (firstValue[i]-nextFirstValue[i])*(firstKeyFrame - currentFrame)/0.001;
  9512. }
  9513. return ret;
  9514. }
  9515. return firstValue + (firstValue-nextFirstValue)*(firstKeyFrame - currentFrame)/0.001;
  9516. }
  9517. return this.getValueAtTime(((cycleDuration - (firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0);
  9518. }
  9519. }
  9520. function smooth(width, samples) {
  9521. if (!this.k){
  9522. return this.pv;
  9523. }
  9524. width = (width || 0.4) * 0.5;
  9525. samples = Math.floor(samples || 5);
  9526. if (samples <= 1) {
  9527. return this.pv;
  9528. }
  9529. var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate;
  9530. var initFrame = currentTime - width;
  9531. var endFrame = currentTime + width;
  9532. var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1;
  9533. var i = 0, j = 0;
  9534. var value;
  9535. if (this.pv.length) {
  9536. value = createTypedArray('float32', this.pv.length);
  9537. } else {
  9538. value = 0;
  9539. }
  9540. var sampleValue;
  9541. while (i < samples) {
  9542. sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency);
  9543. if(this.pv.length) {
  9544. for (j = 0; j < this.pv.length; j += 1) {
  9545. value[j] += sampleValue[j];
  9546. }
  9547. } else {
  9548. value += sampleValue;
  9549. }
  9550. i += 1;
  9551. }
  9552. if(this.pv.length) {
  9553. for (j = 0; j < this.pv.length; j += 1) {
  9554. value[j] /= samples;
  9555. }
  9556. } else {
  9557. value /= samples;
  9558. }
  9559. return value;
  9560. }
  9561. function getValueAtTime(frameNum) {
  9562. frameNum *= this.elem.globalData.frameRate;
  9563. frameNum -= this.offsetTime;
  9564. if(frameNum !== this._cachingAtTime.lastFrame) {
  9565. this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
  9566. this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
  9567. this._cachingAtTime.lastFrame = frameNum;
  9568. }
  9569. return this._cachingAtTime.value;
  9570. }
  9571. function getTransformValueAtTime(time) {
  9572. console.warn('Transform at time not supported');
  9573. }
  9574. function getTransformStaticValueAtTime(time) {
  9575. }
  9576. var getTransformProperty = TransformPropertyFactory.getTransformProperty;
  9577. TransformPropertyFactory.getTransformProperty = function(elem, data, container) {
  9578. var prop = getTransformProperty(elem, data, container);
  9579. if(prop.dynamicProperties.length) {
  9580. prop.getValueAtTime = getTransformValueAtTime.bind(prop);
  9581. } else {
  9582. prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop);
  9583. }
  9584. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  9585. return prop;
  9586. };
  9587. var propertyGetProp = PropertyFactory.getProp;
  9588. PropertyFactory.getProp = function(elem,data,type, mult, container){
  9589. var prop = propertyGetProp(elem,data,type, mult, container);
  9590. //prop.getVelocityAtTime = getVelocityAtTime;
  9591. //prop.loopOut = loopOut;
  9592. //prop.loopIn = loopIn;
  9593. if(prop.kf){
  9594. prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop);
  9595. } else {
  9596. prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop);
  9597. }
  9598. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  9599. prop.loopOut = loopOut;
  9600. prop.loopIn = loopIn;
  9601. prop.smooth = smooth;
  9602. prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop);
  9603. prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop);
  9604. prop.numKeys = data.a === 1 ? data.k.length : 0;
  9605. prop.propertyIndex = data.ix;
  9606. var value = 0;
  9607. if(type !== 0) {
  9608. value = createTypedArray('float32', data.a === 1 ? data.k[0].s.length : data.k.length);
  9609. }
  9610. prop._cachingAtTime = {
  9611. lastFrame: initialDefaultFrame,
  9612. lastIndex: 0,
  9613. value: value
  9614. };
  9615. expressionHelpers.searchExpressions(elem,data,prop);
  9616. if(prop.k){
  9617. container.addDynamicProperty(prop);
  9618. }
  9619. return prop;
  9620. };
  9621. function getShapeValueAtTime(frameNum) {
  9622. //For now this caching object is created only when needed instead of creating it when the shape is initialized.
  9623. if (!this._cachingAtTime) {
  9624. this._cachingAtTime = {
  9625. shapeValue: shape_pool.clone(this.pv),
  9626. lastIndex: 0,
  9627. lastTime: initialDefaultFrame
  9628. };
  9629. }
  9630. frameNum *= this.elem.globalData.frameRate;
  9631. frameNum -= this.offsetTime;
  9632. if(frameNum !== this._cachingAtTime.lastTime) {
  9633. this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0;
  9634. this._cachingAtTime.lastTime = frameNum;
  9635. this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime);
  9636. }
  9637. return this._cachingAtTime.shapeValue;
  9638. }
  9639. var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction();
  9640. var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction();
  9641. function ShapeExpressions(){}
  9642. ShapeExpressions.prototype = {
  9643. vertices: function(prop, time){
  9644. if (this.k) {
  9645. this.getValue();
  9646. }
  9647. var shapePath = this.v;
  9648. if(time !== undefined) {
  9649. shapePath = this.getValueAtTime(time, 0);
  9650. }
  9651. var i, len = shapePath._length;
  9652. var vertices = shapePath[prop];
  9653. var points = shapePath.v;
  9654. var arr = createSizedArray(len);
  9655. for(i = 0; i < len; i += 1) {
  9656. if(prop === 'i' || prop === 'o') {
  9657. arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]];
  9658. } else {
  9659. arr[i] = [vertices[i][0], vertices[i][1]];
  9660. }
  9661. }
  9662. return arr;
  9663. },
  9664. points: function(time){
  9665. return this.vertices('v', time);
  9666. },
  9667. inTangents: function(time){
  9668. return this.vertices('i', time);
  9669. },
  9670. outTangents: function(time){
  9671. return this.vertices('o', time);
  9672. },
  9673. isClosed: function(){
  9674. return this.v.c;
  9675. },
  9676. pointOnPath: function(perc, time){
  9677. var shapePath = this.v;
  9678. if(time !== undefined) {
  9679. shapePath = this.getValueAtTime(time, 0);
  9680. }
  9681. if(!this._segmentsLength) {
  9682. this._segmentsLength = bez.getSegmentsLength(shapePath);
  9683. }
  9684. var segmentsLength = this._segmentsLength;
  9685. var lengths = segmentsLength.lengths;
  9686. var lengthPos = segmentsLength.totalLength * perc;
  9687. var i = 0, len = lengths.length;
  9688. var j = 0, jLen;
  9689. var accumulatedLength = 0, pt;
  9690. while(i < len) {
  9691. if(accumulatedLength + lengths[i].addedLength > lengthPos) {
  9692. var initIndex = i;
  9693. var endIndex = (shapePath.c && i === len - 1) ? 0 : i + 1;
  9694. var segmentPerc = (lengthPos - accumulatedLength)/lengths[i].addedLength;
  9695. pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]);
  9696. break;
  9697. } else {
  9698. accumulatedLength += lengths[i].addedLength;
  9699. }
  9700. i += 1;
  9701. }
  9702. if(!pt){
  9703. pt = shapePath.c ? [shapePath.v[0][0],shapePath.v[0][1]]:[shapePath.v[shapePath._length-1][0],shapePath.v[shapePath._length-1][1]];
  9704. }
  9705. return pt;
  9706. },
  9707. vectorOnPath: function(perc, time, vectorType){
  9708. //perc doesn't use triple equality because it can be a Number object as well as a primitive.
  9709. perc = perc == 1 ? this.v.c ? 0 : 0.999 : perc;
  9710. var pt1 = this.pointOnPath(perc, time);
  9711. var pt2 = this.pointOnPath(perc + 0.001, time);
  9712. var xLength = pt2[0] - pt1[0];
  9713. var yLength = pt2[1] - pt1[1];
  9714. var magnitude = Math.sqrt(Math.pow(xLength,2) + Math.pow(yLength,2));
  9715. var unitVector = vectorType === 'tangent' ? [xLength/magnitude, yLength/magnitude] : [-yLength/magnitude, xLength/magnitude];
  9716. return unitVector;
  9717. },
  9718. tangentOnPath: function(perc, time){
  9719. return this.vectorOnPath(perc, time, 'tangent');
  9720. },
  9721. normalOnPath: function(perc, time){
  9722. return this.vectorOnPath(perc, time, 'normal');
  9723. },
  9724. setGroupProperty: expressionHelpers.setGroupProperty,
  9725. getValueAtTime: expressionHelpers.getStaticValueAtTime
  9726. };
  9727. extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction);
  9728. extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction);
  9729. KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime;
  9730. KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression;
  9731. var propertyGetShapeProp = ShapePropertyFactory.getShapeProp;
  9732. ShapePropertyFactory.getShapeProp = function(elem,data,type, arr, trims){
  9733. var prop = propertyGetShapeProp(elem,data,type, arr, trims);
  9734. prop.propertyIndex = data.ix;
  9735. prop.lock = false;
  9736. if(type === 3){
  9737. expressionHelpers.searchExpressions(elem,data.pt,prop);
  9738. } else if(type === 4){
  9739. expressionHelpers.searchExpressions(elem,data.ks,prop);
  9740. }
  9741. if(prop.k){
  9742. elem.addDynamicProperty(prop);
  9743. }
  9744. return prop;
  9745. };
  9746. }());
  9747. (function addDecorator() {
  9748. function searchExpressions(){
  9749. if(this.data.d.x){
  9750. this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem,this.data.d,this);
  9751. this.addEffect(this.getExpressionValue.bind(this));
  9752. return true;
  9753. }
  9754. }
  9755. TextProperty.prototype.getExpressionValue = function(currentValue, text) {
  9756. var newValue = this.calculateExpression(text);
  9757. if(currentValue.t !== newValue) {
  9758. var newData = {};
  9759. this.copyData(newData, currentValue);
  9760. newData.t = newValue.toString();
  9761. newData.__complete = false;
  9762. return newData;
  9763. }
  9764. return currentValue;
  9765. }
  9766. TextProperty.prototype.searchProperty = function(){
  9767. var isKeyframed = this.searchKeyframes();
  9768. var hasExpressions = this.searchExpressions();
  9769. this.kf = isKeyframed || hasExpressions;
  9770. return this.kf;
  9771. };
  9772. TextProperty.prototype.searchExpressions = searchExpressions;
  9773. }());
  9774. var ShapeExpressionInterface = (function(){
  9775. function iterateElements(shapes,view, propertyGroup){
  9776. var arr = [];
  9777. var i, len = shapes ? shapes.length : 0;
  9778. for(i=0;i<len;i+=1){
  9779. if(shapes[i].ty == 'gr'){
  9780. arr.push(groupInterfaceFactory(shapes[i],view[i],propertyGroup));
  9781. }else if(shapes[i].ty == 'fl'){
  9782. arr.push(fillInterfaceFactory(shapes[i],view[i],propertyGroup));
  9783. }else if(shapes[i].ty == 'st'){
  9784. arr.push(strokeInterfaceFactory(shapes[i],view[i],propertyGroup));
  9785. }else if(shapes[i].ty == 'tm'){
  9786. arr.push(trimInterfaceFactory(shapes[i],view[i],propertyGroup));
  9787. }else if(shapes[i].ty == 'tr'){
  9788. //arr.push(transformInterfaceFactory(shapes[i],view[i],propertyGroup));
  9789. }else if(shapes[i].ty == 'el'){
  9790. arr.push(ellipseInterfaceFactory(shapes[i],view[i],propertyGroup));
  9791. }else if(shapes[i].ty == 'sr'){
  9792. arr.push(starInterfaceFactory(shapes[i],view[i],propertyGroup));
  9793. } else if(shapes[i].ty == 'sh'){
  9794. arr.push(pathInterfaceFactory(shapes[i],view[i],propertyGroup));
  9795. } else if(shapes[i].ty == 'rc'){
  9796. arr.push(rectInterfaceFactory(shapes[i],view[i],propertyGroup));
  9797. } else if(shapes[i].ty == 'rd'){
  9798. arr.push(roundedInterfaceFactory(shapes[i],view[i],propertyGroup));
  9799. } else if(shapes[i].ty == 'rp'){
  9800. arr.push(repeaterInterfaceFactory(shapes[i],view[i],propertyGroup));
  9801. }
  9802. }
  9803. return arr;
  9804. }
  9805. function contentsInterfaceFactory(shape,view, propertyGroup){
  9806. var interfaces;
  9807. var interfaceFunction = function _interfaceFunction(value){
  9808. var i = 0, len = interfaces.length;
  9809. while(i<len){
  9810. if(interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value){
  9811. return interfaces[i];
  9812. }
  9813. i+=1;
  9814. }
  9815. if(typeof value === 'number'){
  9816. return interfaces[value-1];
  9817. }
  9818. };
  9819. interfaceFunction.propertyGroup = function(val){
  9820. if(val === 1){
  9821. return interfaceFunction;
  9822. } else{
  9823. return propertyGroup(val-1);
  9824. }
  9825. };
  9826. interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup);
  9827. interfaceFunction.numProperties = interfaces.length;
  9828. interfaceFunction.propertyIndex = shape.cix;
  9829. interfaceFunction._name = shape.nm;
  9830. return interfaceFunction;
  9831. }
  9832. function groupInterfaceFactory(shape,view, propertyGroup){
  9833. var interfaceFunction = function _interfaceFunction(value){
  9834. switch(value){
  9835. case 'ADBE Vectors Group':
  9836. case 'Contents':
  9837. case 2:
  9838. return interfaceFunction.content;
  9839. //Not necessary for now. Keeping them here in case a new case appears
  9840. //case 'ADBE Vector Transform Group':
  9841. //case 3:
  9842. default:
  9843. return interfaceFunction.transform;
  9844. }
  9845. };
  9846. interfaceFunction.propertyGroup = function(val){
  9847. if(val === 1){
  9848. return interfaceFunction;
  9849. } else{
  9850. return propertyGroup(val-1);
  9851. }
  9852. };
  9853. var content = contentsInterfaceFactory(shape,view,interfaceFunction.propertyGroup);
  9854. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1],view.it[view.it.length - 1],interfaceFunction.propertyGroup);
  9855. interfaceFunction.content = content;
  9856. interfaceFunction.transform = transformInterface;
  9857. Object.defineProperty(interfaceFunction, '_name', {
  9858. get: function(){
  9859. return shape.nm;
  9860. }
  9861. });
  9862. //interfaceFunction.content = interfaceFunction;
  9863. interfaceFunction.numProperties = shape.np;
  9864. interfaceFunction.propertyIndex = shape.ix;
  9865. interfaceFunction.nm = shape.nm;
  9866. interfaceFunction.mn = shape.mn;
  9867. return interfaceFunction;
  9868. }
  9869. function fillInterfaceFactory(shape,view,propertyGroup){
  9870. function interfaceFunction(val){
  9871. if(val === 'Color' || val === 'color'){
  9872. return interfaceFunction.color;
  9873. } else if(val === 'Opacity' || val === 'opacity'){
  9874. return interfaceFunction.opacity;
  9875. }
  9876. }
  9877. Object.defineProperties(interfaceFunction, {
  9878. 'color': {
  9879. get: ExpressionPropertyInterface(view.c)
  9880. },
  9881. 'opacity': {
  9882. get: ExpressionPropertyInterface(view.o)
  9883. },
  9884. '_name': { value: shape.nm },
  9885. 'mn': { value: shape.mn }
  9886. });
  9887. view.c.setGroupProperty(propertyGroup);
  9888. view.o.setGroupProperty(propertyGroup);
  9889. return interfaceFunction;
  9890. }
  9891. function strokeInterfaceFactory(shape,view,propertyGroup){
  9892. function _propertyGroup(val){
  9893. if(val === 1){
  9894. return ob;
  9895. } else{
  9896. return propertyGroup(val-1);
  9897. }
  9898. }
  9899. function _dashPropertyGroup(val){
  9900. if(val === 1){
  9901. return dashOb;
  9902. } else{
  9903. return _propertyGroup(val-1);
  9904. }
  9905. }
  9906. function addPropertyToDashOb(i) {
  9907. Object.defineProperty(dashOb, shape.d[i].nm, {
  9908. get: ExpressionPropertyInterface(view.d.dataProps[i].p)
  9909. });
  9910. }
  9911. var i, len = shape.d ? shape.d.length : 0;
  9912. var dashOb = {};
  9913. for (i = 0; i < len; i += 1) {
  9914. addPropertyToDashOb(i);
  9915. view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup);
  9916. }
  9917. function interfaceFunction(val){
  9918. if(val === 'Color' || val === 'color'){
  9919. return interfaceFunction.color;
  9920. } else if(val === 'Opacity' || val === 'opacity'){
  9921. return interfaceFunction.opacity;
  9922. } else if(val === 'Stroke Width' || val === 'stroke width'){
  9923. return interfaceFunction.strokeWidth;
  9924. }
  9925. }
  9926. Object.defineProperties(interfaceFunction, {
  9927. 'color': {
  9928. get: ExpressionPropertyInterface(view.c)
  9929. },
  9930. 'opacity': {
  9931. get: ExpressionPropertyInterface(view.o)
  9932. },
  9933. 'strokeWidth': {
  9934. get: ExpressionPropertyInterface(view.w)
  9935. },
  9936. 'dash': {
  9937. get: function() {
  9938. return dashOb;
  9939. }
  9940. },
  9941. '_name': { value: shape.nm },
  9942. 'mn': { value: shape.mn }
  9943. });
  9944. view.c.setGroupProperty(_propertyGroup);
  9945. view.o.setGroupProperty(_propertyGroup);
  9946. view.w.setGroupProperty(_propertyGroup);
  9947. return interfaceFunction;
  9948. }
  9949. function trimInterfaceFactory(shape,view,propertyGroup){
  9950. function _propertyGroup(val){
  9951. if(val == 1){
  9952. return interfaceFunction;
  9953. } else {
  9954. return propertyGroup(--val);
  9955. }
  9956. }
  9957. interfaceFunction.propertyIndex = shape.ix;
  9958. view.s.setGroupProperty(_propertyGroup);
  9959. view.e.setGroupProperty(_propertyGroup);
  9960. view.o.setGroupProperty(_propertyGroup);
  9961. function interfaceFunction(val){
  9962. if(val === shape.e.ix || val === 'End' || val === 'end'){
  9963. return interfaceFunction.end;
  9964. }
  9965. if(val === shape.s.ix){
  9966. return interfaceFunction.start;
  9967. }
  9968. if(val === shape.o.ix){
  9969. return interfaceFunction.offset;
  9970. }
  9971. }
  9972. interfaceFunction.propertyIndex = shape.ix;
  9973. interfaceFunction.propertyGroup = propertyGroup;
  9974. Object.defineProperties(interfaceFunction, {
  9975. 'start': {
  9976. get: ExpressionPropertyInterface(view.s)
  9977. },
  9978. 'end': {
  9979. get: ExpressionPropertyInterface(view.e)
  9980. },
  9981. 'offset': {
  9982. get: ExpressionPropertyInterface(view.o)
  9983. },
  9984. '_name': { value: shape.nm }
  9985. });
  9986. interfaceFunction.mn = shape.mn;
  9987. return interfaceFunction;
  9988. }
  9989. function transformInterfaceFactory(shape,view,propertyGroup){
  9990. function _propertyGroup(val){
  9991. if(val == 1){
  9992. return interfaceFunction;
  9993. } else {
  9994. return propertyGroup(--val);
  9995. }
  9996. }
  9997. view.transform.mProps.o.setGroupProperty(_propertyGroup);
  9998. view.transform.mProps.p.setGroupProperty(_propertyGroup);
  9999. view.transform.mProps.a.setGroupProperty(_propertyGroup);
  10000. view.transform.mProps.s.setGroupProperty(_propertyGroup);
  10001. view.transform.mProps.r.setGroupProperty(_propertyGroup);
  10002. if(view.transform.mProps.sk){
  10003. view.transform.mProps.sk.setGroupProperty(_propertyGroup);
  10004. view.transform.mProps.sa.setGroupProperty(_propertyGroup);
  10005. }
  10006. view.transform.op.setGroupProperty(_propertyGroup);
  10007. function interfaceFunction(value){
  10008. if(shape.a.ix === value || value === 'Anchor Point'){
  10009. return interfaceFunction.anchorPoint;
  10010. }
  10011. if(shape.o.ix === value || value === 'Opacity'){
  10012. return interfaceFunction.opacity;
  10013. }
  10014. if(shape.p.ix === value || value === 'Position'){
  10015. return interfaceFunction.position;
  10016. }
  10017. if(shape.r.ix === value || value === 'Rotation' || value === 'ADBE Vector Rotation'){
  10018. return interfaceFunction.rotation;
  10019. }
  10020. if(shape.s.ix === value || value === 'Scale'){
  10021. return interfaceFunction.scale;
  10022. }
  10023. if(shape.sk && shape.sk.ix === value || value === 'Skew'){
  10024. return interfaceFunction.skew;
  10025. }
  10026. if(shape.sa && shape.sa.ix === value || value === 'Skew Axis'){
  10027. return interfaceFunction.skewAxis;
  10028. }
  10029. }
  10030. Object.defineProperties(interfaceFunction, {
  10031. 'opacity': {
  10032. get: ExpressionPropertyInterface(view.transform.mProps.o)
  10033. },
  10034. 'position': {
  10035. get: ExpressionPropertyInterface(view.transform.mProps.p)
  10036. },
  10037. 'anchorPoint': {
  10038. get: ExpressionPropertyInterface(view.transform.mProps.a)
  10039. },
  10040. 'scale': {
  10041. get: ExpressionPropertyInterface(view.transform.mProps.s)
  10042. },
  10043. 'rotation': {
  10044. get: ExpressionPropertyInterface(view.transform.mProps.r)
  10045. },
  10046. 'skew': {
  10047. get: ExpressionPropertyInterface(view.transform.mProps.sk)
  10048. },
  10049. 'skewAxis': {
  10050. get: ExpressionPropertyInterface(view.transform.mProps.sa)
  10051. },
  10052. '_name': { value: shape.nm }
  10053. });
  10054. interfaceFunction.ty = 'tr';
  10055. interfaceFunction.mn = shape.mn;
  10056. interfaceFunction.propertyGroup = propertyGroup;
  10057. return interfaceFunction;
  10058. }
  10059. function ellipseInterfaceFactory(shape,view,propertyGroup){
  10060. function _propertyGroup(val){
  10061. if(val == 1){
  10062. return interfaceFunction;
  10063. } else {
  10064. return propertyGroup(--val);
  10065. }
  10066. }
  10067. interfaceFunction.propertyIndex = shape.ix;
  10068. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  10069. prop.s.setGroupProperty(_propertyGroup);
  10070. prop.p.setGroupProperty(_propertyGroup);
  10071. function interfaceFunction(value){
  10072. if(shape.p.ix === value){
  10073. return interfaceFunction.position;
  10074. }
  10075. if(shape.s.ix === value){
  10076. return interfaceFunction.size;
  10077. }
  10078. }
  10079. Object.defineProperties(interfaceFunction, {
  10080. 'size': {
  10081. get: ExpressionPropertyInterface(prop.s)
  10082. },
  10083. 'position': {
  10084. get: ExpressionPropertyInterface(prop.p)
  10085. },
  10086. '_name': { value: shape.nm }
  10087. });
  10088. interfaceFunction.mn = shape.mn;
  10089. return interfaceFunction;
  10090. }
  10091. function starInterfaceFactory(shape,view,propertyGroup){
  10092. function _propertyGroup(val){
  10093. if(val == 1){
  10094. return interfaceFunction;
  10095. } else {
  10096. return propertyGroup(--val);
  10097. }
  10098. }
  10099. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  10100. interfaceFunction.propertyIndex = shape.ix;
  10101. prop.or.setGroupProperty(_propertyGroup);
  10102. prop.os.setGroupProperty(_propertyGroup);
  10103. prop.pt.setGroupProperty(_propertyGroup);
  10104. prop.p.setGroupProperty(_propertyGroup);
  10105. prop.r.setGroupProperty(_propertyGroup);
  10106. if(shape.ir){
  10107. prop.ir.setGroupProperty(_propertyGroup);
  10108. prop.is.setGroupProperty(_propertyGroup);
  10109. }
  10110. function interfaceFunction(value){
  10111. if(shape.p.ix === value){
  10112. return interfaceFunction.position;
  10113. }
  10114. if(shape.r.ix === value){
  10115. return interfaceFunction.rotation;
  10116. }
  10117. if(shape.pt.ix === value){
  10118. return interfaceFunction.points;
  10119. }
  10120. if(shape.or.ix === value || 'ADBE Vector Star Outer Radius' === value){
  10121. return interfaceFunction.outerRadius;
  10122. }
  10123. if(shape.os.ix === value){
  10124. return interfaceFunction.outerRoundness;
  10125. }
  10126. if(shape.ir && (shape.ir.ix === value || 'ADBE Vector Star Inner Radius' === value)){
  10127. return interfaceFunction.innerRadius;
  10128. }
  10129. if(shape.is && shape.is.ix === value){
  10130. return interfaceFunction.innerRoundness;
  10131. }
  10132. }
  10133. Object.defineProperties(interfaceFunction, {
  10134. 'position': {
  10135. get: ExpressionPropertyInterface(prop.p)
  10136. },
  10137. 'rotation': {
  10138. get: ExpressionPropertyInterface(prop.r)
  10139. },
  10140. 'points': {
  10141. get: ExpressionPropertyInterface(prop.pt)
  10142. },
  10143. 'outerRadius': {
  10144. get: ExpressionPropertyInterface(prop.or)
  10145. },
  10146. 'outerRoundness': {
  10147. get: ExpressionPropertyInterface(prop.os)
  10148. },
  10149. 'innerRadius': {
  10150. get: ExpressionPropertyInterface(prop.ir)
  10151. },
  10152. 'innerRoundness': {
  10153. get: ExpressionPropertyInterface(prop.is)
  10154. },
  10155. '_name': { value: shape.nm }
  10156. });
  10157. interfaceFunction.mn = shape.mn;
  10158. return interfaceFunction;
  10159. }
  10160. function rectInterfaceFactory(shape,view,propertyGroup){
  10161. function _propertyGroup(val){
  10162. if(val == 1){
  10163. return interfaceFunction;
  10164. } else {
  10165. return propertyGroup(--val);
  10166. }
  10167. }
  10168. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  10169. interfaceFunction.propertyIndex = shape.ix;
  10170. prop.p.setGroupProperty(_propertyGroup);
  10171. prop.s.setGroupProperty(_propertyGroup);
  10172. prop.r.setGroupProperty(_propertyGroup);
  10173. function interfaceFunction(value){
  10174. if(shape.p.ix === value){
  10175. return interfaceFunction.position;
  10176. }
  10177. if(shape.r.ix === value){
  10178. return interfaceFunction.roundness;
  10179. }
  10180. if(shape.s.ix === value || value === 'Size' || value === 'ADBE Vector Rect Size'){
  10181. return interfaceFunction.size;
  10182. }
  10183. }
  10184. Object.defineProperties(interfaceFunction, {
  10185. 'position': {
  10186. get: ExpressionPropertyInterface(prop.p)
  10187. },
  10188. 'roundness': {
  10189. get: ExpressionPropertyInterface(prop.r)
  10190. },
  10191. 'size': {
  10192. get: ExpressionPropertyInterface(prop.s)
  10193. },
  10194. '_name': { value: shape.nm }
  10195. });
  10196. interfaceFunction.mn = shape.mn;
  10197. return interfaceFunction;
  10198. }
  10199. function roundedInterfaceFactory(shape,view,propertyGroup){
  10200. function _propertyGroup(val){
  10201. if(val == 1){
  10202. return interfaceFunction;
  10203. } else {
  10204. return propertyGroup(--val);
  10205. }
  10206. }
  10207. var prop = view;
  10208. interfaceFunction.propertyIndex = shape.ix;
  10209. prop.rd.setGroupProperty(_propertyGroup);
  10210. function interfaceFunction(value){
  10211. if(shape.r.ix === value || 'Round Corners 1' === value){
  10212. return interfaceFunction.radius;
  10213. }
  10214. }
  10215. Object.defineProperties(interfaceFunction, {
  10216. 'radius': {
  10217. get: ExpressionPropertyInterface(prop.rd)
  10218. },
  10219. '_name': { value: shape.nm }
  10220. });
  10221. interfaceFunction.mn = shape.mn;
  10222. return interfaceFunction;
  10223. }
  10224. function repeaterInterfaceFactory(shape,view,propertyGroup){
  10225. function _propertyGroup(val){
  10226. if(val == 1){
  10227. return interfaceFunction;
  10228. } else {
  10229. return propertyGroup(--val);
  10230. }
  10231. }
  10232. var prop = view;
  10233. interfaceFunction.propertyIndex = shape.ix;
  10234. prop.c.setGroupProperty(_propertyGroup);
  10235. prop.o.setGroupProperty(_propertyGroup);
  10236. function interfaceFunction(value){
  10237. if(shape.c.ix === value || 'Copies' === value){
  10238. return interfaceFunction.copies;
  10239. } else if(shape.o.ix === value || 'Offset' === value){
  10240. return interfaceFunction.offset;
  10241. }
  10242. }
  10243. Object.defineProperties(interfaceFunction, {
  10244. 'copies': {
  10245. get: ExpressionPropertyInterface(prop.c)
  10246. },
  10247. 'offset': {
  10248. get: ExpressionPropertyInterface(prop.o)
  10249. },
  10250. '_name': { value: shape.nm }
  10251. });
  10252. interfaceFunction.mn = shape.mn;
  10253. return interfaceFunction;
  10254. }
  10255. function pathInterfaceFactory(shape,view,propertyGroup){
  10256. var prop = view.sh;
  10257. function _propertyGroup(val){
  10258. if(val == 1){
  10259. return interfaceFunction;
  10260. } else {
  10261. return propertyGroup(--val);
  10262. }
  10263. }
  10264. prop.setGroupProperty(_propertyGroup);
  10265. function interfaceFunction(val){
  10266. if(val === 'Shape' || val === 'shape' || val === 'Path' || val === 'path' || val === 'ADBE Vector Shape' || val === 2){
  10267. return interfaceFunction.path;
  10268. }
  10269. }
  10270. Object.defineProperties(interfaceFunction, {
  10271. 'path': {
  10272. get: function(){
  10273. if(prop.k){
  10274. prop.getValue();
  10275. }
  10276. return prop;
  10277. }
  10278. },
  10279. 'shape': {
  10280. get: function(){
  10281. if(prop.k){
  10282. prop.getValue();
  10283. }
  10284. return prop;
  10285. }
  10286. },
  10287. '_name': { value: shape.nm },
  10288. 'ix': { value: shape.ix },
  10289. 'mn': { value: shape.mn }
  10290. });
  10291. return interfaceFunction;
  10292. }
  10293. return function(shapes,view,propertyGroup) {
  10294. var interfaces;
  10295. function _interfaceFunction(value){
  10296. if(typeof value === 'number'){
  10297. return interfaces[value-1];
  10298. } else {
  10299. var i = 0, len = interfaces.length;
  10300. while(i<len){
  10301. if(interfaces[i]._name === value){
  10302. return interfaces[i];
  10303. }
  10304. i+=1;
  10305. }
  10306. }
  10307. }
  10308. _interfaceFunction.propertyGroup = propertyGroup;
  10309. interfaces = iterateElements(shapes, view, _interfaceFunction);
  10310. _interfaceFunction.numProperties = interfaces.length;
  10311. return _interfaceFunction;
  10312. };
  10313. }());
  10314. var TextExpressionInterface = (function(){
  10315. return function(elem){
  10316. var _prevValue, _sourceText;
  10317. function _thisLayerFunction(){
  10318. }
  10319. Object.defineProperty(_thisLayerFunction, "sourceText", {
  10320. get: function(){
  10321. elem.textProperty.getValue()
  10322. var stringValue = elem.textProperty.currentData.t;
  10323. if(stringValue !== _prevValue) {
  10324. elem.textProperty.currentData.t = _prevValue;
  10325. _sourceText = new String(stringValue);
  10326. //If stringValue is an empty string, eval returns undefined, so it has to be returned as a String primitive
  10327. _sourceText.value = stringValue ? stringValue : new String(stringValue);
  10328. }
  10329. return _sourceText;
  10330. }
  10331. });
  10332. return _thisLayerFunction;
  10333. };
  10334. }());
  10335. var LayerExpressionInterface = (function (){
  10336. function toWorld(arr, time){
  10337. var toWorldMat = new Matrix();
  10338. toWorldMat.reset();
  10339. var transformMat;
  10340. if(time) {
  10341. //Todo implement value at time on transform properties
  10342. //transformMat = this._elem.finalTransform.mProp.getValueAtTime(time);
  10343. transformMat = this._elem.finalTransform.mProp;
  10344. } else {
  10345. transformMat = this._elem.finalTransform.mProp;
  10346. }
  10347. transformMat.applyToMatrix(toWorldMat);
  10348. if(this._elem.hierarchy && this._elem.hierarchy.length){
  10349. var i, len = this._elem.hierarchy.length;
  10350. for(i=0;i<len;i+=1){
  10351. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  10352. }
  10353. return toWorldMat.applyToPointArray(arr[0],arr[1],arr[2]||0);
  10354. }
  10355. return toWorldMat.applyToPointArray(arr[0],arr[1],arr[2]||0);
  10356. }
  10357. function fromWorld(arr, time){
  10358. var toWorldMat = new Matrix();
  10359. toWorldMat.reset();
  10360. var transformMat;
  10361. if(time) {
  10362. //Todo implement value at time on transform properties
  10363. //transformMat = this._elem.finalTransform.mProp.getValueAtTime(time);
  10364. transformMat = this._elem.finalTransform.mProp;
  10365. } else {
  10366. transformMat = this._elem.finalTransform.mProp;
  10367. }
  10368. transformMat.applyToMatrix(toWorldMat);
  10369. if(this._elem.hierarchy && this._elem.hierarchy.length){
  10370. var i, len = this._elem.hierarchy.length;
  10371. for(i=0;i<len;i+=1){
  10372. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  10373. }
  10374. return toWorldMat.inversePoint(arr);
  10375. }
  10376. return toWorldMat.inversePoint(arr);
  10377. }
  10378. function fromComp(arr){
  10379. var toWorldMat = new Matrix();
  10380. toWorldMat.reset();
  10381. this._elem.finalTransform.mProp.applyToMatrix(toWorldMat);
  10382. if(this._elem.hierarchy && this._elem.hierarchy.length){
  10383. var i, len = this._elem.hierarchy.length;
  10384. for(i=0;i<len;i+=1){
  10385. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  10386. }
  10387. return toWorldMat.inversePoint(arr);
  10388. }
  10389. return toWorldMat.inversePoint(arr);
  10390. }
  10391. function sampleImage() {
  10392. return [1,1,1,1];
  10393. }
  10394. return function(elem){
  10395. var transformInterface;
  10396. function _registerMaskInterface(maskManager){
  10397. _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem);
  10398. }
  10399. function _registerEffectsInterface(effects){
  10400. _thisLayerFunction.effect = effects;
  10401. }
  10402. function _thisLayerFunction(name){
  10403. switch(name){
  10404. case "ADBE Root Vectors Group":
  10405. case "Contents":
  10406. case 2:
  10407. return _thisLayerFunction.shapeInterface;
  10408. case 1:
  10409. case 6:
  10410. case "Transform":
  10411. case "transform":
  10412. case "ADBE Transform Group":
  10413. return transformInterface;
  10414. case 4:
  10415. case "ADBE Effect Parade":
  10416. case "effects":
  10417. case "Effects":
  10418. return _thisLayerFunction.effect;
  10419. }
  10420. }
  10421. _thisLayerFunction.toWorld = toWorld;
  10422. _thisLayerFunction.fromWorld = fromWorld;
  10423. _thisLayerFunction.toComp = toWorld;
  10424. _thisLayerFunction.fromComp = fromComp;
  10425. _thisLayerFunction.sampleImage = sampleImage;
  10426. _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem);
  10427. _thisLayerFunction._elem = elem;
  10428. transformInterface = TransformExpressionInterface(elem.finalTransform.mProp);
  10429. var anchorPointDescriptor = getDescriptor(transformInterface, 'anchorPoint');
  10430. Object.defineProperties(_thisLayerFunction,{
  10431. hasParent: {
  10432. get: function(){
  10433. return elem.hierarchy.length;
  10434. }
  10435. },
  10436. parent: {
  10437. get: function(){
  10438. return elem.hierarchy[0].layerInterface;
  10439. }
  10440. },
  10441. rotation: getDescriptor(transformInterface, 'rotation'),
  10442. scale: getDescriptor(transformInterface, 'scale'),
  10443. position: getDescriptor(transformInterface, 'position'),
  10444. opacity: getDescriptor(transformInterface, 'opacity'),
  10445. anchorPoint: anchorPointDescriptor,
  10446. anchor_point: anchorPointDescriptor,
  10447. transform: {
  10448. get: function () {
  10449. return transformInterface;
  10450. }
  10451. },
  10452. active: {
  10453. get: function(){
  10454. return elem.isInRange;
  10455. }
  10456. }
  10457. });
  10458. _thisLayerFunction.startTime = elem.data.st;
  10459. _thisLayerFunction.index = elem.data.ind;
  10460. _thisLayerFunction.source = elem.data.refId;
  10461. _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100;
  10462. _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100;
  10463. _thisLayerFunction.inPoint = elem.data.ip/elem.comp.globalData.frameRate;
  10464. _thisLayerFunction.outPoint = elem.data.op/elem.comp.globalData.frameRate;
  10465. _thisLayerFunction._name = elem.data.nm;
  10466. _thisLayerFunction.registerMaskInterface = _registerMaskInterface;
  10467. _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface;
  10468. return _thisLayerFunction;
  10469. };
  10470. }());
  10471. var CompExpressionInterface = (function (){
  10472. return function(comp){
  10473. function _thisLayerFunction(name){
  10474. var i=0, len = comp.layers.length;
  10475. while(i<len){
  10476. if(comp.layers[i].nm === name || comp.layers[i].ind === name){
  10477. return comp.elements[i].layerInterface;
  10478. }
  10479. i += 1;
  10480. }
  10481. return null;
  10482. //return {active:false};
  10483. }
  10484. Object.defineProperty(_thisLayerFunction, "_name", { value:comp.data.nm });
  10485. _thisLayerFunction.layer = _thisLayerFunction;
  10486. _thisLayerFunction.pixelAspect = 1;
  10487. _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h;
  10488. _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w;
  10489. _thisLayerFunction.pixelAspect = 1;
  10490. _thisLayerFunction.frameDuration = 1/comp.globalData.frameRate;
  10491. _thisLayerFunction.displayStartTime = 0;
  10492. _thisLayerFunction.numLayers = comp.layers.length;
  10493. return _thisLayerFunction;
  10494. };
  10495. }());
  10496. var TransformExpressionInterface = (function (){
  10497. return function(transform){
  10498. function _thisFunction(name){
  10499. switch(name){
  10500. case "scale":
  10501. case "Scale":
  10502. case "ADBE Scale":
  10503. case 6:
  10504. return _thisFunction.scale;
  10505. case "rotation":
  10506. case "Rotation":
  10507. case "ADBE Rotation":
  10508. case "ADBE Rotate Z":
  10509. case 10:
  10510. return _thisFunction.rotation;
  10511. case "ADBE Rotate X":
  10512. return _thisFunction.xRotation;
  10513. case "ADBE Rotate Y":
  10514. return _thisFunction.yRotation;
  10515. case "position":
  10516. case "Position":
  10517. case "ADBE Position":
  10518. case 2:
  10519. return _thisFunction.position;
  10520. case 'ADBE Position_0':
  10521. return _thisFunction.xPosition;
  10522. case 'ADBE Position_1':
  10523. return _thisFunction.yPosition;
  10524. case 'ADBE Position_2':
  10525. return _thisFunction.zPosition;
  10526. case "anchorPoint":
  10527. case "AnchorPoint":
  10528. case "Anchor Point":
  10529. case "ADBE AnchorPoint":
  10530. case 1:
  10531. return _thisFunction.anchorPoint;
  10532. case "opacity":
  10533. case "Opacity":
  10534. case 11:
  10535. return _thisFunction.opacity;
  10536. }
  10537. }
  10538. Object.defineProperty(_thisFunction, "rotation", {
  10539. get: ExpressionPropertyInterface(transform.r || transform.rz)
  10540. });
  10541. Object.defineProperty(_thisFunction, "zRotation", {
  10542. get: ExpressionPropertyInterface(transform.rz || transform.r)
  10543. });
  10544. Object.defineProperty(_thisFunction, "xRotation", {
  10545. get: ExpressionPropertyInterface(transform.rx)
  10546. });
  10547. Object.defineProperty(_thisFunction, "yRotation", {
  10548. get: ExpressionPropertyInterface(transform.ry)
  10549. });
  10550. Object.defineProperty(_thisFunction, "scale", {
  10551. get: ExpressionPropertyInterface(transform.s)
  10552. });
  10553. if(transform.p) {
  10554. var _transformFactory = ExpressionPropertyInterface(transform.p);
  10555. }
  10556. Object.defineProperty(_thisFunction, "position", {
  10557. get: function () {
  10558. if(transform.p) {
  10559. return _transformFactory();
  10560. } else {
  10561. return [transform.px.v, transform.py.v, transform.pz ? transform.pz.v : 0];
  10562. }
  10563. }
  10564. });
  10565. Object.defineProperty(_thisFunction, "xPosition", {
  10566. get: ExpressionPropertyInterface(transform.px)
  10567. });
  10568. Object.defineProperty(_thisFunction, "yPosition", {
  10569. get: ExpressionPropertyInterface(transform.py)
  10570. });
  10571. Object.defineProperty(_thisFunction, "zPosition", {
  10572. get: ExpressionPropertyInterface(transform.pz)
  10573. });
  10574. Object.defineProperty(_thisFunction, "anchorPoint", {
  10575. get: ExpressionPropertyInterface(transform.a)
  10576. });
  10577. Object.defineProperty(_thisFunction, "opacity", {
  10578. get: ExpressionPropertyInterface(transform.o)
  10579. });
  10580. Object.defineProperty(_thisFunction, "skew", {
  10581. get: ExpressionPropertyInterface(transform.sk)
  10582. });
  10583. Object.defineProperty(_thisFunction, "skewAxis", {
  10584. get: ExpressionPropertyInterface(transform.sa)
  10585. });
  10586. Object.defineProperty(_thisFunction, "orientation", {
  10587. get: ExpressionPropertyInterface(transform.or)
  10588. });
  10589. return _thisFunction;
  10590. };
  10591. }());
  10592. var ProjectInterface = (function (){
  10593. function registerComposition(comp){
  10594. this.compositions.push(comp);
  10595. }
  10596. return function(){
  10597. function _thisProjectFunction(name){
  10598. var i = 0, len = this.compositions.length;
  10599. while(i<len){
  10600. if(this.compositions[i].data && this.compositions[i].data.nm === name){
  10601. if(this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  10602. this.compositions[i].prepareFrame(this.currentFrame);
  10603. }
  10604. return this.compositions[i].compInterface;
  10605. }
  10606. i+=1;
  10607. }
  10608. }
  10609. _thisProjectFunction.compositions = [];
  10610. _thisProjectFunction.currentFrame = 0;
  10611. _thisProjectFunction.registerComposition = registerComposition;
  10612. return _thisProjectFunction;
  10613. };
  10614. }());
  10615. var EffectsExpressionInterface = (function (){
  10616. var ob = {
  10617. createEffectsInterface: createEffectsInterface
  10618. };
  10619. function createEffectsInterface(elem, propertyGroup){
  10620. if(elem.effectsManager){
  10621. var effectElements = [];
  10622. var effectsData = elem.data.ef;
  10623. var i, len = elem.effectsManager.effectElements.length;
  10624. for(i=0;i<len;i+=1){
  10625. effectElements.push(createGroupInterface(effectsData[i],elem.effectsManager.effectElements[i],propertyGroup,elem));
  10626. }
  10627. return function(name){
  10628. var effects = elem.data.ef || [], i = 0, len = effects.length;
  10629. while(i<len) {
  10630. if(name === effects[i].nm || name === effects[i].mn || name === effects[i].ix){
  10631. return effectElements[i];
  10632. }
  10633. i += 1;
  10634. }
  10635. };
  10636. }
  10637. }
  10638. function createGroupInterface(data,elements, propertyGroup, elem){
  10639. var effectElements = [];
  10640. var i, len = data.ef.length;
  10641. for(i=0;i<len;i+=1){
  10642. if(data.ef[i].ty === 5){
  10643. effectElements.push(createGroupInterface(data.ef[i],elements.effectElements[i],elements.effectElements[i].propertyGroup, elem));
  10644. } else {
  10645. effectElements.push(createValueInterface(elements.effectElements[i],data.ef[i].ty, elem, _propertyGroup));
  10646. }
  10647. }
  10648. function _propertyGroup(val) {
  10649. if(val === 1){
  10650. return groupInterface;
  10651. } else{
  10652. return propertyGroup(val-1);
  10653. }
  10654. }
  10655. var groupInterface = function(name){
  10656. var effects = data.ef, i = 0, len = effects.length;
  10657. while(i<len) {
  10658. if(name === effects[i].nm || name === effects[i].mn || name === effects[i].ix){
  10659. if(effects[i].ty === 5){
  10660. return effectElements[i];
  10661. } else {
  10662. return effectElements[i]();
  10663. }
  10664. }
  10665. i += 1;
  10666. }
  10667. return effectElements[0]();
  10668. };
  10669. groupInterface.propertyGroup = _propertyGroup;
  10670. if(data.mn === 'ADBE Color Control'){
  10671. Object.defineProperty(groupInterface, 'color', {
  10672. get: function(){
  10673. return effectElements[0]();
  10674. }
  10675. });
  10676. }
  10677. Object.defineProperty(groupInterface, 'numProperties', {
  10678. get: function(){
  10679. return data.np;
  10680. }
  10681. });
  10682. groupInterface.active = groupInterface.enabled = data.en !== 0;
  10683. return groupInterface;
  10684. }
  10685. function createValueInterface(element, type, elem, propertyGroup){
  10686. var expressionProperty = ExpressionPropertyInterface(element.p);
  10687. function interfaceFunction(){
  10688. if(type === 10){
  10689. return elem.comp.compInterface(element.p.v);
  10690. }
  10691. return expressionProperty();
  10692. }
  10693. if(element.p.setGroupProperty) {
  10694. element.p.setGroupProperty(propertyGroup);
  10695. }
  10696. return interfaceFunction;
  10697. }
  10698. return ob;
  10699. }());
  10700. var MaskManagerInterface = (function(){
  10701. function MaskInterface(mask, data){
  10702. this._mask = mask;
  10703. this._data = data;
  10704. }
  10705. Object.defineProperty(MaskInterface.prototype, 'maskPath', {
  10706. get: function(){
  10707. if(this._mask.prop.k){
  10708. this._mask.prop.getValue();
  10709. }
  10710. return this._mask.prop;
  10711. }
  10712. });
  10713. var MaskManager = function(maskManager, elem){
  10714. var _maskManager = maskManager;
  10715. var _elem = elem;
  10716. var _masksInterfaces = createSizedArray(maskManager.viewData.length);
  10717. var i, len = maskManager.viewData.length;
  10718. for(i = 0; i < len; i += 1) {
  10719. _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]);
  10720. }
  10721. var maskFunction = function(name){
  10722. i = 0;
  10723. while(i<len){
  10724. if(maskManager.masksProperties[i].nm === name){
  10725. return _masksInterfaces[i];
  10726. }
  10727. i += 1;
  10728. }
  10729. };
  10730. return maskFunction;
  10731. };
  10732. return MaskManager;
  10733. }());
  10734. var ExpressionPropertyInterface = (function() {
  10735. var defaultUnidimensionalValue = {pv:0, v:0, mult: 1}
  10736. var defaultMultidimensionalValue = {pv:[0,0,0], v:[0,0,0], mult: 1}
  10737. function completeProperty(expressionValue, property, type) {
  10738. Object.defineProperty(expressionValue, 'velocity', {
  10739. get: function(){
  10740. return property.getVelocityAtTime(property.comp.currentFrame);
  10741. }
  10742. });
  10743. expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0;
  10744. expressionValue.key = function(pos) {
  10745. if (!expressionValue.numKeys) {
  10746. return 0;
  10747. } else {
  10748. var value = '';
  10749. if ('s' in property.keyframes[pos-1]) {
  10750. value = property.keyframes[pos-1].s;
  10751. } else if ('e' in property.keyframes[pos-2]) {
  10752. value = property.keyframes[pos-2].e;
  10753. } else {
  10754. value = property.keyframes[pos-2].s;
  10755. }
  10756. var valueProp = type === 'unidimensional' ? new Number(value) : Object.assign({}, value);
  10757. valueProp.time = property.keyframes[pos-1].t / property.elem.comp.globalData.frameRate;
  10758. return valueProp;
  10759. }
  10760. };
  10761. expressionValue.valueAtTime = property.getValueAtTime;
  10762. expressionValue.speedAtTime = property.getSpeedAtTime;
  10763. expressionValue.velocityAtTime = property.getVelocityAtTime;
  10764. expressionValue.propertyGroup = property.propertyGroup;
  10765. }
  10766. function UnidimensionalPropertyInterface(property) {
  10767. if(!property || !('pv' in property)) {
  10768. property = defaultUnidimensionalValue;
  10769. }
  10770. var mult = 1 / property.mult;
  10771. var val = property.pv * mult;
  10772. var expressionValue = new Number(val);
  10773. expressionValue.value = val;
  10774. completeProperty(expressionValue, property, 'unidimensional');
  10775. return function() {
  10776. if (property.k) {
  10777. property.getValue();
  10778. }
  10779. val = property.v * mult;
  10780. if(expressionValue.value !== val) {
  10781. expressionValue = new Number(val);
  10782. expressionValue.value = val;
  10783. completeProperty(expressionValue, property, 'unidimensional');
  10784. }
  10785. return expressionValue;
  10786. }
  10787. }
  10788. function MultidimensionalPropertyInterface(property) {
  10789. if(!property || !('pv' in property)) {
  10790. property = defaultMultidimensionalValue;
  10791. }
  10792. var mult = 1 / property.mult;
  10793. var len = property.pv.length;
  10794. var expressionValue = createTypedArray('float32', len);
  10795. var arrValue = createTypedArray('float32', len);
  10796. expressionValue.value = arrValue;
  10797. completeProperty(expressionValue, property, 'multidimensional');
  10798. return function() {
  10799. if (property.k) {
  10800. property.getValue();
  10801. }
  10802. for (var i = 0; i < len; i += 1) {
  10803. expressionValue[i] = arrValue[i] = property.v[i] * mult;
  10804. }
  10805. return expressionValue;
  10806. }
  10807. }
  10808. //TODO: try to avoid using this getter
  10809. function defaultGetter() {
  10810. return defaultUnidimensionalValue;
  10811. }
  10812. return function(property) {
  10813. if(!property) {
  10814. return defaultGetter;
  10815. } else if (property.propType === 'unidimensional') {
  10816. return UnidimensionalPropertyInterface(property);
  10817. } else {
  10818. return MultidimensionalPropertyInterface(property);
  10819. }
  10820. }
  10821. }());
  10822. (function(){
  10823. var TextExpressionSelectorProp = (function(){
  10824. function getValueProxy(index,total){
  10825. this.textIndex = index+1;
  10826. this.textTotal = total;
  10827. this.v = this.getValue() * this.mult;
  10828. return this.v;
  10829. }
  10830. return function TextExpressionSelectorProp(elem,data){
  10831. this.pv = 1;
  10832. this.comp = elem.comp;
  10833. this.elem = elem;
  10834. this.mult = 0.01;
  10835. this.propType = 'textSelector';
  10836. this.textTotal = data.totalChars;
  10837. this.selectorValue = 100;
  10838. this.lastValue = [1,1,1];
  10839. this.k = true;
  10840. this.x = true;
  10841. this.getValue = ExpressionManager.initiateExpression.bind(this)(elem,data,this);
  10842. this.getMult = getValueProxy;
  10843. this.getVelocityAtTime = expressionHelpers.getVelocityAtTime;
  10844. if(this.kf){
  10845. this.getValueAtTime = expressionHelpers.getValueAtTime.bind(this);
  10846. } else {
  10847. this.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(this);
  10848. }
  10849. this.setGroupProperty = expressionHelpers.setGroupProperty;
  10850. };
  10851. }());
  10852. var propertyGetTextProp = TextSelectorProp.getTextSelectorProp;
  10853. TextSelectorProp.getTextSelectorProp = function(elem, data,arr){
  10854. if(data.t === 1){
  10855. return new TextExpressionSelectorProp(elem, data,arr);
  10856. } else {
  10857. return propertyGetTextProp(elem,data,arr);
  10858. }
  10859. };
  10860. }());
  10861. function SliderEffect(data,elem, container){
  10862. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  10863. }
  10864. function AngleEffect(data,elem, container){
  10865. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  10866. }
  10867. function ColorEffect(data,elem, container){
  10868. this.p = PropertyFactory.getProp(elem,data.v,1,0,container);
  10869. }
  10870. function PointEffect(data,elem, container){
  10871. this.p = PropertyFactory.getProp(elem,data.v,1,0,container);
  10872. }
  10873. function LayerIndexEffect(data,elem, container){
  10874. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  10875. }
  10876. function MaskIndexEffect(data,elem, container){
  10877. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  10878. }
  10879. function CheckboxEffect(data,elem, container){
  10880. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  10881. }
  10882. function NoValueEffect(){
  10883. this.p = {};
  10884. }
  10885. function EffectsManager(data,element){
  10886. var effects = data.ef || [];
  10887. this.effectElements = [];
  10888. var i,len = effects.length;
  10889. var effectItem;
  10890. for(i=0;i<len;i++) {
  10891. effectItem = new GroupEffect(effects[i],element);
  10892. this.effectElements.push(effectItem);
  10893. }
  10894. }
  10895. function GroupEffect(data,element){
  10896. this.init(data,element);
  10897. }
  10898. extendPrototype([DynamicPropertyContainer], GroupEffect);
  10899. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  10900. GroupEffect.prototype.init = function(data,element){
  10901. this.data = data;
  10902. this.effectElements = [];
  10903. this.initDynamicPropertyContainer(element);
  10904. var i, len = this.data.ef.length;
  10905. var eff, effects = this.data.ef;
  10906. for(i=0;i<len;i+=1){
  10907. eff = null;
  10908. switch(effects[i].ty){
  10909. case 0:
  10910. eff = new SliderEffect(effects[i],element,this);
  10911. break;
  10912. case 1:
  10913. eff = new AngleEffect(effects[i],element,this);
  10914. break;
  10915. case 2:
  10916. eff = new ColorEffect(effects[i],element,this);
  10917. break;
  10918. case 3:
  10919. eff = new PointEffect(effects[i],element,this);
  10920. break;
  10921. case 4:
  10922. case 7:
  10923. eff = new CheckboxEffect(effects[i],element,this);
  10924. break;
  10925. case 10:
  10926. eff = new LayerIndexEffect(effects[i],element,this);
  10927. break;
  10928. case 11:
  10929. eff = new MaskIndexEffect(effects[i],element,this);
  10930. break;
  10931. case 5:
  10932. eff = new EffectsManager(effects[i],element,this);
  10933. break;
  10934. //case 6:
  10935. default:
  10936. eff = new NoValueEffect(effects[i],element,this);
  10937. break;
  10938. }
  10939. if(eff) {
  10940. this.effectElements.push(eff);
  10941. }
  10942. }
  10943. };
  10944. var lottiejs = {};
  10945. var _isFrozen = false;
  10946. function loadAnimation(params) {
  10947. return animationManager.loadAnimation(params);
  10948. }
  10949. function setQuality(value) {
  10950. if (typeof value === 'string') {
  10951. switch (value) {
  10952. case 'high':
  10953. defaultCurveSegments = 200;
  10954. break;
  10955. case 'medium':
  10956. defaultCurveSegments = 50;
  10957. break;
  10958. case 'low':
  10959. defaultCurveSegments = 10;
  10960. break;
  10961. }
  10962. } else if (!isNaN(value) && value > 1) {
  10963. defaultCurveSegments = value;
  10964. }
  10965. if (defaultCurveSegments >= 50) {
  10966. roundValues(false);
  10967. } else {
  10968. roundValues(true);
  10969. }
  10970. }
  10971. lottiejs.play = animationManager.play;
  10972. lottiejs.pause = animationManager.pause;
  10973. lottiejs.togglePause = animationManager.togglePause;
  10974. lottiejs.setSpeed = animationManager.setSpeed;
  10975. lottiejs.setDirection = animationManager.setDirection;
  10976. lottiejs.stop = animationManager.stop;
  10977. lottiejs.registerAnimation = animationManager.registerAnimation;
  10978. lottiejs.loadAnimation = loadAnimation;
  10979. lottiejs.resize = animationManager.resize;
  10980. lottiejs.goToAndStop = animationManager.goToAndStop;
  10981. lottiejs.destroy = animationManager.destroy;
  10982. lottiejs.setQuality = setQuality;
  10983. lottiejs.freeze = animationManager.freeze;
  10984. lottiejs.unfreeze = animationManager.unfreeze;
  10985. lottiejs.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  10986. lottiejs.version = '5.5.2';
  10987. var renderer = '';
  10988. return lottiejs;
  10989. })({});
  10990. /**
  10991. * Code below is added to handle the messages sent to the worker thread. Its a
  10992. * a wrapper that manages animation control for each animation.
  10993. */
  10994. /**
  10995. * An instance of the currently running lottie animation.
  10996. * @type {?AnimationItem}
  10997. */
  10998. var currentAnimation = null;
  10999. /**
  11000. * Events sent back to the parent thread.
  11001. */
  11002. var events = {
  11003. INITIALIZED: 'initialized', // Send when the animation was successfully
  11004. // initialized.
  11005. RESIZED: 'resized', // Sent when the animation has been resized.
  11006. PLAYING: 'playing', // Send when the animation started playing.
  11007. PAUSED: 'paused', // Sent when the animation has paused.
  11008. STOPPED: 'stopped', // Sent when the animation has stopped.
  11009. };
  11010. /**
  11011. * Returns the size of the canvas on which the current animation is running on.
  11012. * @return {Object<string, number>} Returns the current size of canvas
  11013. */
  11014. function getCurrentCanvasSize() {
  11015. var canvas = currentAnimation.renderer.canvasContext.canvas;
  11016. return {
  11017. height: canvas.height,
  11018. width: canvas.width
  11019. };
  11020. }
  11021. /**
  11022. * Informs the parent thread that the canvas has been resized and also sends the
  11023. * new size.
  11024. */
  11025. function sendResizeEvent() {
  11026. var canvas = currentAnimation.renderer.canvasContext.canvas;
  11027. postMessage({
  11028. name: events.RESIZED,
  11029. size: getCurrentCanvasSize()
  11030. });
  11031. };
  11032. /**
  11033. * Informs the parent thread that the animation is playing.
  11034. */
  11035. function sendPlayEvent() {
  11036. postMessage({name: events.PLAYING});
  11037. }
  11038. /**
  11039. * Informs the parent thread that the animation is paused.
  11040. */
  11041. function sendPauseEvent() {
  11042. postMessage({name: events.PAUSED});
  11043. }
  11044. /**
  11045. * Informs the parent thread that the animation is stopped.
  11046. */
  11047. function sendStopEvent() {
  11048. postMessage({name: events.STOPPED});
  11049. }
  11050. /**
  11051. * Informs the parent thread that the animation has finished initializing.
  11052. */
  11053. function sendInitializedEvent() {
  11054. var canvas = currentAnimation.renderer.canvasContext.canvas;
  11055. postMessage({
  11056. name: events.INITIALIZED,
  11057. success: currentAnimation.isLoaded
  11058. })
  11059. }
  11060. /**
  11061. * Initializes the animation using the animation data sent from the parent
  11062. * thread along with the init parameters. If an animation is already initialized
  11063. * this is a no-op.
  11064. * @param {JSON} animationData JSON data for the animation.
  11065. * @param {Object} initParams Parameters to initialize the animation with.
  11066. * @param {OffscreenCanvas} canvas The offsccreen canvas that will display the
  11067. * animation.
  11068. */
  11069. function initAnimation(animationData, initParams, canvas) {
  11070. if (!animationData || !initParams) {
  11071. return;
  11072. }
  11073. var ctx = canvas.getContext("2d");
  11074. currentAnimation = lottiejs.loadAnimation({
  11075. renderer: 'canvas',
  11076. loop: initParams.loop,
  11077. autoplay: initParams.autoplay,
  11078. animationData: animationData,
  11079. rendererSettings: {
  11080. context: ctx,
  11081. scaleMode: 'noScale',
  11082. clearCanvas: true
  11083. }
  11084. });
  11085. sendInitializedEvent();
  11086. // Play the animation if its not already playing.
  11087. if (initParams.autoplay) {
  11088. currentAnimation.play();
  11089. }
  11090. if (currentAnimation.isLoaded && !currentAnimation.isPaused) {
  11091. sendPlayEvent();
  11092. }
  11093. }
  11094. /**
  11095. * Updates the canvas draw size. If an animation is already initialized or
  11096. * playing, this would update the canvas for that as well.
  11097. * @param {OffscreenCanvas} canvas Draw size for this canvas is updated.
  11098. * @param {Object<string, number>} size Draw size to update the canvas to.
  11099. */
  11100. function updateCanvasSize(canvas, size) {
  11101. if (!size || !canvas) {
  11102. return;
  11103. }
  11104. if (size.height > 0 && size.width > 0) {
  11105. canvas.height = size.height;
  11106. canvas.width = size.width;
  11107. }
  11108. // If an animation is already initialized then update its canvas size.
  11109. if (currentAnimation) {
  11110. currentAnimation.resize();
  11111. sendResizeEvent();
  11112. }
  11113. }
  11114. /**
  11115. * Updates the animation state to play or pause. Informs the parent thread if
  11116. * the state has changed.
  11117. * @param {Object<string, bool>} control Has information about playing or
  11118. * pausing the animation.
  11119. * @param {HTMLCanvasElement} canvas the canvas on which the animation is drawn.
  11120. */
  11121. function updateAnimationState(control, canvas) {
  11122. if (!control || !currentAnimation) {
  11123. return;
  11124. }
  11125. if (control.stop) {
  11126. currentAnimation.stop();
  11127. canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
  11128. sendStopEvent();
  11129. return;
  11130. }
  11131. if (control.play && currentAnimation.isPaused) {
  11132. currentAnimation.play();
  11133. sendPlayEvent();
  11134. } else if (!control.play && !currentAnimation.isPaused) {
  11135. currentAnimation.pause();
  11136. sendPauseEvent();
  11137. }
  11138. }
  11139. onmessage = function(evt) {
  11140. if (!evt || !evt.data) return;
  11141. var canvas = null;
  11142. if (currentAnimation) {
  11143. canvas = currentAnimation.renderer.canvasContext.canvas;
  11144. } else if (evt.data.canvas) {
  11145. canvas = evt.data.canvas;
  11146. } else {
  11147. return;
  11148. }
  11149. // Stop and clear the current animation to initialize a new one with the
  11150. // provided animation data.
  11151. if (currentAnimation && evt.data.animationData) {
  11152. currentAnimation.stop();
  11153. currentAnimation = null;
  11154. }
  11155. updateCanvasSize(canvas, evt.data.drawSize);
  11156. initAnimation(evt.data.animationData, evt.data.params, canvas);
  11157. updateAnimationState(evt.data.control, canvas);
  11158. };