lottie_canvas.js 447 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751
  1. (typeof navigator !== "undefined") && (function(root, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define(function() {
  4. return factory(root);
  5. });
  6. } else if (typeof module === "object" && module.exports) {
  7. module.exports = factory(root);
  8. } else {
  9. root.lottie = factory(root);
  10. root.bodymovin = root.lottie;
  11. }
  12. }((window || {}), function(window) {
  13. "use strict";
  14. var svgNS = "http://www.w3.org/2000/svg";
  15. var locationHref = '';
  16. var initialDefaultFrame = -999999;
  17. var subframeEnabled = true;
  18. var expressionsPlugin;
  19. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  20. var cachedColors = {};
  21. var bm_rounder = Math.round;
  22. var bm_rnd;
  23. var bm_pow = Math.pow;
  24. var bm_sqrt = Math.sqrt;
  25. var bm_abs = Math.abs;
  26. var bm_floor = Math.floor;
  27. var bm_max = Math.max;
  28. var bm_min = Math.min;
  29. var blitter = 10;
  30. var BMMath = {};
  31. (function(){
  32. 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"];
  33. var i, len = propertyNames.length;
  34. for(i=0;i<len;i+=1){
  35. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  36. }
  37. }());
  38. function ProjectInterface(){return {};}
  39. BMMath.random = Math.random;
  40. BMMath.abs = function(val){
  41. var tOfVal = typeof val;
  42. if(tOfVal === 'object' && val.length){
  43. var absArr = createSizedArray(val.length);
  44. var i, len = val.length;
  45. for(i=0;i<len;i+=1){
  46. absArr[i] = Math.abs(val[i]);
  47. }
  48. return absArr;
  49. }
  50. return Math.abs(val);
  51. };
  52. var defaultCurveSegments = 150;
  53. var degToRads = Math.PI/180;
  54. var roundCorner = 0.5519;
  55. function roundValues(flag){
  56. if(flag){
  57. bm_rnd = Math.round;
  58. }else{
  59. bm_rnd = function(val){
  60. return val;
  61. };
  62. }
  63. }
  64. roundValues(false);
  65. function styleDiv(element){
  66. element.style.position = 'absolute';
  67. element.style.top = 0;
  68. element.style.left = 0;
  69. element.style.display = 'block';
  70. element.style.transformOrigin = element.style.webkitTransformOrigin = '0 0';
  71. element.style.backfaceVisibility = element.style.webkitBackfaceVisibility = 'visible';
  72. element.style.transformStyle = element.style.webkitTransformStyle = element.style.mozTransformStyle = "preserve-3d";
  73. }
  74. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier){
  75. this.type = type;
  76. this.currentTime = currentTime;
  77. this.totalTime = totalTime;
  78. this.direction = frameMultiplier < 0 ? -1 : 1;
  79. }
  80. function BMCompleteEvent(type, frameMultiplier){
  81. this.type = type;
  82. this.direction = frameMultiplier < 0 ? -1 : 1;
  83. }
  84. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier){
  85. this.type = type;
  86. this.currentLoop = currentLoop;
  87. this.totalLoops = totalLoops;
  88. this.direction = frameMultiplier < 0 ? -1 : 1;
  89. }
  90. function BMSegmentStartEvent(type, firstFrame, totalFrames){
  91. this.type = type;
  92. this.firstFrame = firstFrame;
  93. this.totalFrames = totalFrames;
  94. }
  95. function BMDestroyEvent(type, target){
  96. this.type = type;
  97. this.target = target;
  98. }
  99. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  100. this.type = 'renderFrameError';
  101. this.nativeError = nativeError;
  102. this.currentTime = currentTime;
  103. }
  104. function BMConfigErrorEvent(nativeError) {
  105. this.type = 'configError';
  106. this.nativeError = nativeError;
  107. }
  108. function BMAnimationConfigErrorEvent(type, nativeError) {
  109. this.type = type;
  110. this.nativeError = nativeError;
  111. this.currentTime = currentTime;
  112. }
  113. var createElementID = (function(){
  114. var _count = 0;
  115. return function createID() {
  116. return '__lottie_element_' + ++_count
  117. }
  118. }())
  119. function HSVtoRGB(h, s, v) {
  120. var r, g, b, i, f, p, q, t;
  121. i = Math.floor(h * 6);
  122. f = h * 6 - i;
  123. p = v * (1 - s);
  124. q = v * (1 - f * s);
  125. t = v * (1 - (1 - f) * s);
  126. switch (i % 6) {
  127. case 0: r = v; g = t; b = p; break;
  128. case 1: r = q; g = v; b = p; break;
  129. case 2: r = p; g = v; b = t; break;
  130. case 3: r = p; g = q; b = v; break;
  131. case 4: r = t; g = p; b = v; break;
  132. case 5: r = v; g = p; b = q; break;
  133. }
  134. return [ r,
  135. g,
  136. b ];
  137. }
  138. function RGBtoHSV(r, g, b) {
  139. var max = Math.max(r, g, b), min = Math.min(r, g, b),
  140. d = max - min,
  141. h,
  142. s = (max === 0 ? 0 : d / max),
  143. v = max / 255;
  144. switch (max) {
  145. case min: h = 0; break;
  146. case r: h = (g - b) + d * (g < b ? 6: 0); h /= 6 * d; break;
  147. case g: h = (b - r) + d * 2; h /= 6 * d; break;
  148. case b: h = (r - g) + d * 4; h /= 6 * d; break;
  149. }
  150. return [
  151. h,
  152. s,
  153. v
  154. ];
  155. }
  156. function addSaturationToRGB(color,offset){
  157. var hsv = RGBtoHSV(color[0]*255,color[1]*255,color[2]*255);
  158. hsv[1] += offset;
  159. if (hsv[1] > 1) {
  160. hsv[1] = 1;
  161. }
  162. else if (hsv[1] <= 0) {
  163. hsv[1] = 0;
  164. }
  165. return HSVtoRGB(hsv[0],hsv[1],hsv[2]);
  166. }
  167. function addBrightnessToRGB(color,offset){
  168. var hsv = RGBtoHSV(color[0]*255,color[1]*255,color[2]*255);
  169. hsv[2] += offset;
  170. if (hsv[2] > 1) {
  171. hsv[2] = 1;
  172. }
  173. else if (hsv[2] < 0) {
  174. hsv[2] = 0;
  175. }
  176. return HSVtoRGB(hsv[0],hsv[1],hsv[2]);
  177. }
  178. function addHueToRGB(color,offset) {
  179. var hsv = RGBtoHSV(color[0]*255,color[1]*255,color[2]*255);
  180. hsv[0] += offset/360;
  181. if (hsv[0] > 1) {
  182. hsv[0] -= 1;
  183. }
  184. else if (hsv[0] < 0) {
  185. hsv[0] += 1;
  186. }
  187. return HSVtoRGB(hsv[0],hsv[1],hsv[2]);
  188. }
  189. var rgbToHex = (function(){
  190. var colorMap = [];
  191. var i;
  192. var hex;
  193. for(i=0;i<256;i+=1){
  194. hex = i.toString(16);
  195. colorMap[i] = hex.length == 1 ? '0' + hex : hex;
  196. }
  197. return function(r, g, b) {
  198. if(r<0){
  199. r = 0;
  200. }
  201. if(g<0){
  202. g = 0;
  203. }
  204. if(b<0){
  205. b = 0;
  206. }
  207. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  208. };
  209. }());
  210. function BaseEvent(){}
  211. BaseEvent.prototype = {
  212. triggerEvent: function (eventName, args) {
  213. if (this._cbs[eventName]) {
  214. var len = this._cbs[eventName].length;
  215. for (var i = 0; i < len; i++){
  216. this._cbs[eventName][i](args);
  217. }
  218. }
  219. },
  220. addEventListener: function (eventName, callback) {
  221. if (!this._cbs[eventName]){
  222. this._cbs[eventName] = [];
  223. }
  224. this._cbs[eventName].push(callback);
  225. return function() {
  226. this.removeEventListener(eventName, callback);
  227. }.bind(this);
  228. },
  229. removeEventListener: function (eventName,callback){
  230. if (!callback){
  231. this._cbs[eventName] = null;
  232. }else if(this._cbs[eventName]){
  233. var i = 0, len = this._cbs[eventName].length;
  234. while(i<len){
  235. if(this._cbs[eventName][i] === callback){
  236. this._cbs[eventName].splice(i,1);
  237. i -=1;
  238. len -= 1;
  239. }
  240. i += 1;
  241. }
  242. if(!this._cbs[eventName].length){
  243. this._cbs[eventName] = null;
  244. }
  245. }
  246. }
  247. };
  248. var createTypedArray = (function(){
  249. function createRegularArray(type, len){
  250. var i = 0, arr = [], value;
  251. switch(type) {
  252. case 'int16':
  253. case 'uint8c':
  254. value = 1;
  255. break;
  256. default:
  257. value = 1.1;
  258. break;
  259. }
  260. for(i = 0; i < len; i += 1) {
  261. arr.push(value);
  262. }
  263. return arr;
  264. }
  265. function createTypedArray(type, len){
  266. if(type === 'float32') {
  267. return new Float32Array(len);
  268. } else if(type === 'int16') {
  269. return new Int16Array(len);
  270. } else if(type === 'uint8c') {
  271. return new Uint8ClampedArray(len);
  272. }
  273. }
  274. if(typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  275. return createTypedArray;
  276. } else {
  277. return createRegularArray;
  278. }
  279. }());
  280. function createSizedArray(len) {
  281. return Array.apply(null,{length:len});
  282. }
  283. function createTag(type) {
  284. //return {appendChild:function(){},setAttribute:function(){},style:{}}
  285. return document.createElement(type);
  286. }
  287. function DynamicPropertyContainer(){};
  288. DynamicPropertyContainer.prototype = {
  289. addDynamicProperty: function(prop) {
  290. if(this.dynamicProperties.indexOf(prop) === -1) {
  291. this.dynamicProperties.push(prop);
  292. this.container.addDynamicProperty(this);
  293. this._isAnimated = true;
  294. }
  295. },
  296. iterateDynamicProperties: function(){
  297. this._mdf = false;
  298. var i, len = this.dynamicProperties.length;
  299. for(i=0;i<len;i+=1){
  300. this.dynamicProperties[i].getValue();
  301. if(this.dynamicProperties[i]._mdf) {
  302. this._mdf = true;
  303. }
  304. }
  305. },
  306. initDynamicPropertyContainer: function(container){
  307. this.container = container;
  308. this.dynamicProperties = [];
  309. this._mdf = false;
  310. this._isAnimated = false;
  311. }
  312. }
  313. var getBlendMode = (function() {
  314. var blendModeEnums = {
  315. 0:'source-over',
  316. 1:'multiply',
  317. 2:'screen',
  318. 3:'overlay',
  319. 4:'darken',
  320. 5:'lighten',
  321. 6:'color-dodge',
  322. 7:'color-burn',
  323. 8:'hard-light',
  324. 9:'soft-light',
  325. 10:'difference',
  326. 11:'exclusion',
  327. 12:'hue',
  328. 13:'saturation',
  329. 14:'color',
  330. 15:'luminosity'
  331. }
  332. return function(mode) {
  333. return blendModeEnums[mode] || '';
  334. }
  335. }())
  336. /*!
  337. Transformation Matrix v2.0
  338. (c) Epistemex 2014-2015
  339. www.epistemex.com
  340. By Ken Fyrstenberg
  341. Contributions by leeoniya.
  342. License: MIT, header required.
  343. */
  344. /**
  345. * 2D transformation matrix object initialized with identity matrix.
  346. *
  347. * The matrix can synchronize a canvas context by supplying the context
  348. * as an argument, or later apply current absolute transform to an
  349. * existing context.
  350. *
  351. * All values are handled as floating point values.
  352. *
  353. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  354. * @prop {number} a - scale x
  355. * @prop {number} b - shear y
  356. * @prop {number} c - shear x
  357. * @prop {number} d - scale y
  358. * @prop {number} e - translate x
  359. * @prop {number} f - translate y
  360. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  361. * @constructor
  362. */
  363. var Matrix = (function(){
  364. var _cos = Math.cos;
  365. var _sin = Math.sin;
  366. var _tan = Math.tan;
  367. var _rnd = Math.round;
  368. function reset(){
  369. this.props[0] = 1;
  370. this.props[1] = 0;
  371. this.props[2] = 0;
  372. this.props[3] = 0;
  373. this.props[4] = 0;
  374. this.props[5] = 1;
  375. this.props[6] = 0;
  376. this.props[7] = 0;
  377. this.props[8] = 0;
  378. this.props[9] = 0;
  379. this.props[10] = 1;
  380. this.props[11] = 0;
  381. this.props[12] = 0;
  382. this.props[13] = 0;
  383. this.props[14] = 0;
  384. this.props[15] = 1;
  385. return this;
  386. }
  387. function rotate(angle) {
  388. if(angle === 0){
  389. return this;
  390. }
  391. var mCos = _cos(angle);
  392. var mSin = _sin(angle);
  393. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  394. }
  395. function rotateX(angle){
  396. if(angle === 0){
  397. return this;
  398. }
  399. var mCos = _cos(angle);
  400. var mSin = _sin(angle);
  401. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  402. }
  403. function rotateY(angle){
  404. if(angle === 0){
  405. return this;
  406. }
  407. var mCos = _cos(angle);
  408. var mSin = _sin(angle);
  409. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  410. }
  411. function rotateZ(angle){
  412. if(angle === 0){
  413. return this;
  414. }
  415. var mCos = _cos(angle);
  416. var mSin = _sin(angle);
  417. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  418. }
  419. function shear(sx,sy){
  420. return this._t(1, sy, sx, 1, 0, 0);
  421. }
  422. function skew(ax, ay){
  423. return this.shear(_tan(ax), _tan(ay));
  424. }
  425. function skewFromAxis(ax, angle){
  426. var mCos = _cos(angle);
  427. var mSin = _sin(angle);
  428. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  429. ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  430. ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  431. //return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  432. }
  433. function scale(sx, sy, sz) {
  434. if(!sz && sz !== 0) {
  435. sz = 1;
  436. }
  437. if(sx === 1 && sy === 1 && sz === 1){
  438. return this;
  439. }
  440. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  441. }
  442. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  443. this.props[0] = a;
  444. this.props[1] = b;
  445. this.props[2] = c;
  446. this.props[3] = d;
  447. this.props[4] = e;
  448. this.props[5] = f;
  449. this.props[6] = g;
  450. this.props[7] = h;
  451. this.props[8] = i;
  452. this.props[9] = j;
  453. this.props[10] = k;
  454. this.props[11] = l;
  455. this.props[12] = m;
  456. this.props[13] = n;
  457. this.props[14] = o;
  458. this.props[15] = p;
  459. return this;
  460. }
  461. function translate(tx, ty, tz) {
  462. tz = tz || 0;
  463. if(tx !== 0 || ty !== 0 || tz !== 0){
  464. return this._t(1,0,0,0,0,1,0,0,0,0,1,0,tx,ty,tz,1);
  465. }
  466. return this;
  467. }
  468. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  469. var _p = this.props;
  470. 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){
  471. //NOTE: commenting this condition because TurboFan deoptimizes code when present
  472. //if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  473. _p[12] = _p[12] * a2 + _p[15] * m2;
  474. _p[13] = _p[13] * f2 + _p[15] * n2;
  475. _p[14] = _p[14] * k2 + _p[15] * o2;
  476. _p[15] = _p[15] * p2;
  477. //}
  478. this._identityCalculated = false;
  479. return this;
  480. }
  481. var a1 = _p[0];
  482. var b1 = _p[1];
  483. var c1 = _p[2];
  484. var d1 = _p[3];
  485. var e1 = _p[4];
  486. var f1 = _p[5];
  487. var g1 = _p[6];
  488. var h1 = _p[7];
  489. var i1 = _p[8];
  490. var j1 = _p[9];
  491. var k1 = _p[10];
  492. var l1 = _p[11];
  493. var m1 = _p[12];
  494. var n1 = _p[13];
  495. var o1 = _p[14];
  496. var p1 = _p[15];
  497. /* matrix order (canvas compatible):
  498. * ace
  499. * bdf
  500. * 001
  501. */
  502. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  503. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2 ;
  504. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2 ;
  505. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2 ;
  506. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2 ;
  507. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2 ;
  508. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2 ;
  509. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2 ;
  510. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2 ;
  511. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2 ;
  512. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2 ;
  513. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2 ;
  514. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2 ;
  515. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2 ;
  516. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2 ;
  517. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2 ;
  518. this._identityCalculated = false;
  519. return this;
  520. }
  521. function isIdentity() {
  522. if(!this._identityCalculated){
  523. 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);
  524. this._identityCalculated = true;
  525. }
  526. return this._identity;
  527. }
  528. function equals(matr){
  529. var i = 0;
  530. while (i < 16) {
  531. if(matr.props[i] !== this.props[i]) {
  532. return false;
  533. }
  534. i+=1;
  535. }
  536. return true;
  537. }
  538. function clone(matr){
  539. var i;
  540. for(i=0;i<16;i+=1){
  541. matr.props[i] = this.props[i];
  542. }
  543. }
  544. function cloneFromProps(props){
  545. var i;
  546. for(i=0;i<16;i+=1){
  547. this.props[i] = props[i];
  548. }
  549. }
  550. function applyToPoint(x, y, z) {
  551. return {
  552. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  553. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  554. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]
  555. };
  556. /*return {
  557. x: x * me.a + y * me.c + me.e,
  558. y: x * me.b + y * me.d + me.f
  559. };*/
  560. }
  561. function applyToX(x, y, z) {
  562. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  563. }
  564. function applyToY(x, y, z) {
  565. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  566. }
  567. function applyToZ(x, y, z) {
  568. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  569. }
  570. function getInverseMatrix() {
  571. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  572. var a = this.props[5]/determinant;
  573. var b = - this.props[1]/determinant;
  574. var c = - this.props[4]/determinant;
  575. var d = this.props[0]/determinant;
  576. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12])/determinant;
  577. var f = - (this.props[0] * this.props[13] - this.props[1] * this.props[12])/determinant;
  578. var inverseMatrix = new Matrix();
  579. inverseMatrix.props[0] = a;
  580. inverseMatrix.props[1] = b;
  581. inverseMatrix.props[4] = c;
  582. inverseMatrix.props[5] = d;
  583. inverseMatrix.props[12] = e;
  584. inverseMatrix.props[13] = f;
  585. return inverseMatrix;
  586. }
  587. function inversePoint(pt) {
  588. var inverseMatrix = this.getInverseMatrix();
  589. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0)
  590. }
  591. function inversePoints(pts){
  592. var i, len = pts.length, retPts = [];
  593. for(i=0;i<len;i+=1){
  594. retPts[i] = inversePoint(pts[i]);
  595. }
  596. return retPts;
  597. }
  598. function applyToTriplePoints(pt1, pt2, pt3) {
  599. var arr = createTypedArray('float32', 6);
  600. if(this.isIdentity()) {
  601. arr[0] = pt1[0];
  602. arr[1] = pt1[1];
  603. arr[2] = pt2[0];
  604. arr[3] = pt2[1];
  605. arr[4] = pt3[0];
  606. arr[5] = pt3[1];
  607. } else {
  608. 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];
  609. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  610. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  611. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  612. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  613. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  614. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  615. }
  616. return arr;
  617. }
  618. function applyToPointArray(x,y,z){
  619. var arr;
  620. if(this.isIdentity()) {
  621. arr = [x,y,z];
  622. } else {
  623. arr = [
  624. x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  625. x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  626. x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]
  627. ];
  628. }
  629. return arr;
  630. }
  631. function applyToPointStringified(x, y) {
  632. if(this.isIdentity()) {
  633. return x + ',' + y;
  634. }
  635. var _p = this.props;
  636. 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;
  637. }
  638. function toCSS() {
  639. //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.
  640. /*if(this.isIdentity()) {
  641. return '';
  642. }*/
  643. var i = 0;
  644. var props = this.props;
  645. var cssValue = 'matrix3d(';
  646. var v = 10000;
  647. while(i<16){
  648. cssValue += _rnd(props[i]*v)/v;
  649. cssValue += i === 15 ? ')':',';
  650. i += 1;
  651. }
  652. return cssValue;
  653. }
  654. function roundMatrixProperty(val) {
  655. var v = 10000;
  656. if((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
  657. return _rnd(val * v) / v;
  658. }
  659. return val;
  660. }
  661. function to2dCSS() {
  662. //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.
  663. /*if(this.isIdentity()) {
  664. return '';
  665. }*/
  666. var props = this.props;
  667. var _a = roundMatrixProperty(props[0]);
  668. var _b = roundMatrixProperty(props[1]);
  669. var _c = roundMatrixProperty(props[4]);
  670. var _d = roundMatrixProperty(props[5]);
  671. var _e = roundMatrixProperty(props[12]);
  672. var _f = roundMatrixProperty(props[13]);
  673. return "matrix(" + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ")";
  674. }
  675. return function(){
  676. this.reset = reset;
  677. this.rotate = rotate;
  678. this.rotateX = rotateX;
  679. this.rotateY = rotateY;
  680. this.rotateZ = rotateZ;
  681. this.skew = skew;
  682. this.skewFromAxis = skewFromAxis;
  683. this.shear = shear;
  684. this.scale = scale;
  685. this.setTransform = setTransform;
  686. this.translate = translate;
  687. this.transform = transform;
  688. this.applyToPoint = applyToPoint;
  689. this.applyToX = applyToX;
  690. this.applyToY = applyToY;
  691. this.applyToZ = applyToZ;
  692. this.applyToPointArray = applyToPointArray;
  693. this.applyToTriplePoints = applyToTriplePoints;
  694. this.applyToPointStringified = applyToPointStringified;
  695. this.toCSS = toCSS;
  696. this.to2dCSS = to2dCSS;
  697. this.clone = clone;
  698. this.cloneFromProps = cloneFromProps;
  699. this.equals = equals;
  700. this.inversePoints = inversePoints;
  701. this.inversePoint = inversePoint;
  702. this.getInverseMatrix = getInverseMatrix;
  703. this._t = this.transform;
  704. this.isIdentity = isIdentity;
  705. this._identity = true;
  706. this._identityCalculated = false;
  707. this.props = createTypedArray('float32', 16);
  708. this.reset();
  709. };
  710. }());
  711. /*
  712. Copyright 2014 David Bau.
  713. Permission is hereby granted, free of charge, to any person obtaining
  714. a copy of this software and associated documentation files (the
  715. "Software"), to deal in the Software without restriction, including
  716. without limitation the rights to use, copy, modify, merge, publish,
  717. distribute, sublicense, and/or sell copies of the Software, and to
  718. permit persons to whom the Software is furnished to do so, subject to
  719. the following conditions:
  720. The above copyright notice and this permission notice shall be
  721. included in all copies or substantial portions of the Software.
  722. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  723. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  724. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  725. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  726. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  727. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  728. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  729. */
  730. (function (pool, math) {
  731. //
  732. // The following constants are related to IEEE 754 limits.
  733. //
  734. var global = this,
  735. width = 256, // each RC4 output is 0 <= x < 256
  736. chunks = 6, // at least six RC4 outputs for each double
  737. digits = 52, // there are 52 significant digits in a double
  738. rngname = 'random', // rngname: name for Math.random and Math.seedrandom
  739. startdenom = math.pow(width, chunks),
  740. significance = math.pow(2, digits),
  741. overflow = significance * 2,
  742. mask = width - 1,
  743. nodecrypto; // node.js crypto module, initialized at the bottom.
  744. //
  745. // seedrandom()
  746. // This is the seedrandom function described above.
  747. //
  748. function seedrandom(seed, options, callback) {
  749. var key = [];
  750. options = (options === true) ? { entropy: true } : (options || {});
  751. // Flatten the seed string or build one from local entropy if needed.
  752. var shortseed = mixkey(flatten(
  753. options.entropy ? [seed, tostring(pool)] :
  754. (seed === null) ? autoseed() : seed, 3), key);
  755. // Use the seed to initialize an ARC4 generator.
  756. var arc4 = new ARC4(key);
  757. // This function returns a random double in [0, 1) that contains
  758. // randomness in every bit of the mantissa of the IEEE 754 value.
  759. var prng = function() {
  760. var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
  761. d = startdenom, // and denominator d = 2 ^ 48.
  762. x = 0; // and no 'extra last byte'.
  763. while (n < significance) { // Fill up all significant digits by
  764. n = (n + x) * width; // shifting numerator and
  765. d *= width; // denominator and generating a
  766. x = arc4.g(1); // new least-significant-byte.
  767. }
  768. while (n >= overflow) { // To avoid rounding up, before adding
  769. n /= 2; // last byte, shift everything
  770. d /= 2; // right using integer math until
  771. x >>>= 1; // we have exactly the desired bits.
  772. }
  773. return (n + x) / d; // Form the number within [0, 1).
  774. };
  775. prng.int32 = function() { return arc4.g(4) | 0; };
  776. prng.quick = function() { return arc4.g(4) / 0x100000000; };
  777. prng.double = prng;
  778. // Mix the randomness into accumulated entropy.
  779. mixkey(tostring(arc4.S), pool);
  780. // Calling convention: what to return as a function of prng, seed, is_math.
  781. return (options.pass || callback ||
  782. function(prng, seed, is_math_call, state) {
  783. if (state) {
  784. // Load the arc4 state from the given state if it has an S array.
  785. if (state.S) { copy(state, arc4); }
  786. // Only provide the .state method if requested via options.state.
  787. prng.state = function() { return copy(arc4, {}); };
  788. }
  789. // If called as a method of Math (Math.seedrandom()), mutate
  790. // Math.random because that is how seedrandom.js has worked since v1.0.
  791. if (is_math_call) { math[rngname] = prng; return seed; }
  792. // Otherwise, it is a newer calling convention, so return the
  793. // prng directly.
  794. else return prng;
  795. })(
  796. prng,
  797. shortseed,
  798. 'global' in options ? options.global : (this == math),
  799. options.state);
  800. }
  801. math['seed' + rngname] = seedrandom;
  802. //
  803. // ARC4
  804. //
  805. // An ARC4 implementation. The constructor takes a key in the form of
  806. // an array of at most (width) integers that should be 0 <= x < (width).
  807. //
  808. // The g(count) method returns a pseudorandom integer that concatenates
  809. // the next (count) outputs from ARC4. Its return value is a number x
  810. // that is in the range 0 <= x < (width ^ count).
  811. //
  812. function ARC4(key) {
  813. var t, keylen = key.length,
  814. me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
  815. // The empty key [] is treated as [0].
  816. if (!keylen) { key = [keylen++]; }
  817. // Set up S using the standard key scheduling algorithm.
  818. while (i < width) {
  819. s[i] = i++;
  820. }
  821. for (i = 0; i < width; i++) {
  822. s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
  823. s[j] = t;
  824. }
  825. // The "g" method returns the next (count) outputs as one number.
  826. me.g = function(count) {
  827. // Using instance members instead of closure state nearly doubles speed.
  828. var t, r = 0,
  829. i = me.i, j = me.j, s = me.S;
  830. while (count--) {
  831. t = s[i = mask & (i + 1)];
  832. r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
  833. }
  834. me.i = i; me.j = j;
  835. return r;
  836. // For robust unpredictability, the function call below automatically
  837. // discards an initial batch of values. This is called RC4-drop[256].
  838. // See http://google.com/search?q=rsa+fluhrer+response&btnI
  839. };
  840. }
  841. //
  842. // copy()
  843. // Copies internal state of ARC4 to or from a plain object.
  844. //
  845. function copy(f, t) {
  846. t.i = f.i;
  847. t.j = f.j;
  848. t.S = f.S.slice();
  849. return t;
  850. }
  851. //
  852. // flatten()
  853. // Converts an object tree to nested arrays of strings.
  854. //
  855. function flatten(obj, depth) {
  856. var result = [], typ = (typeof obj), prop;
  857. if (depth && typ == 'object') {
  858. for (prop in obj) {
  859. try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
  860. }
  861. }
  862. return (result.length ? result : typ == 'string' ? obj : obj + '\0');
  863. }
  864. //
  865. // mixkey()
  866. // Mixes a string seed into a key that is an array of integers, and
  867. // returns a shortened string seed that is equivalent to the result key.
  868. //
  869. function mixkey(seed, key) {
  870. var stringseed = seed + '', smear, j = 0;
  871. while (j < stringseed.length) {
  872. key[mask & j] =
  873. mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
  874. }
  875. return tostring(key);
  876. }
  877. //
  878. // autoseed()
  879. // Returns an object for autoseeding, using window.crypto and Node crypto
  880. // module if available.
  881. //
  882. function autoseed() {
  883. try {
  884. if (nodecrypto) { return tostring(nodecrypto.randomBytes(width)); }
  885. var out = new Uint8Array(width);
  886. (global.crypto || global.msCrypto).getRandomValues(out);
  887. return tostring(out);
  888. } catch (e) {
  889. var browser = global.navigator,
  890. plugins = browser && browser.plugins;
  891. return [+new Date(), global, plugins, global.screen, tostring(pool)];
  892. }
  893. }
  894. //
  895. // tostring()
  896. // Converts an array of charcodes to a string
  897. //
  898. function tostring(a) {
  899. return String.fromCharCode.apply(0, a);
  900. }
  901. //
  902. // When seedrandom.js is loaded, we immediately mix a few bits
  903. // from the built-in RNG into the entropy pool. Because we do
  904. // not want to interfere with deterministic PRNG state later,
  905. // seedrandom will not call math.random on its own again after
  906. // initialization.
  907. //
  908. mixkey(math.random(), pool);
  909. //
  910. // Nodejs and AMD support: export the implementation as a module using
  911. // either convention.
  912. //
  913. // End anonymous scope, and pass initial values.
  914. })(
  915. [], // pool: entropy pool starts empty
  916. BMMath // math: package containing random, pow, and seedrandom
  917. );
  918. var BezierFactory = (function(){
  919. /**
  920. * BezierEasing - use bezier curve for transition easing function
  921. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  922. *
  923. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  924. * Usage:
  925. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  926. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  927. *
  928. */
  929. var ob = {};
  930. ob.getBezierEasing = getBezierEasing;
  931. var beziers = {};
  932. function getBezierEasing(a,b,c,d,nm){
  933. var str = nm || ('bez_' + a+'_'+b+'_'+c+'_'+d).replace(/\./g, 'p');
  934. if(beziers[str]){
  935. return beziers[str];
  936. }
  937. var bezEasing = new BezierEasing([a,b,c,d]);
  938. beziers[str] = bezEasing;
  939. return bezEasing;
  940. }
  941. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  942. var NEWTON_ITERATIONS = 4;
  943. var NEWTON_MIN_SLOPE = 0.001;
  944. var SUBDIVISION_PRECISION = 0.0000001;
  945. var SUBDIVISION_MAX_ITERATIONS = 10;
  946. var kSplineTableSize = 11;
  947. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  948. var float32ArraySupported = typeof Float32Array === "function";
  949. function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
  950. function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
  951. function C (aA1) { return 3.0 * aA1; }
  952. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  953. function calcBezier (aT, aA1, aA2) {
  954. return ((A(aA1, aA2)*aT + B(aA1, aA2))*aT + C(aA1))*aT;
  955. }
  956. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  957. function getSlope (aT, aA1, aA2) {
  958. return 3.0 * A(aA1, aA2)*aT*aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  959. }
  960. function binarySubdivide (aX, aA, aB, mX1, mX2) {
  961. var currentX, currentT, i = 0;
  962. do {
  963. currentT = aA + (aB - aA) / 2.0;
  964. currentX = calcBezier(currentT, mX1, mX2) - aX;
  965. if (currentX > 0.0) {
  966. aB = currentT;
  967. } else {
  968. aA = currentT;
  969. }
  970. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  971. return currentT;
  972. }
  973. function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) {
  974. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  975. var currentSlope = getSlope(aGuessT, mX1, mX2);
  976. if (currentSlope === 0.0) return aGuessT;
  977. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  978. aGuessT -= currentX / currentSlope;
  979. }
  980. return aGuessT;
  981. }
  982. /**
  983. * points is an array of [ mX1, mY1, mX2, mY2 ]
  984. */
  985. function BezierEasing (points) {
  986. this._p = points;
  987. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  988. this._precomputed = false;
  989. this.get = this.get.bind(this);
  990. }
  991. BezierEasing.prototype = {
  992. get: function (x) {
  993. var mX1 = this._p[0],
  994. mY1 = this._p[1],
  995. mX2 = this._p[2],
  996. mY2 = this._p[3];
  997. if (!this._precomputed) this._precompute();
  998. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  999. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  1000. if (x === 0) return 0;
  1001. if (x === 1) return 1;
  1002. return calcBezier(this._getTForX(x), mY1, mY2);
  1003. },
  1004. // Private part
  1005. _precompute: function () {
  1006. var mX1 = this._p[0],
  1007. mY1 = this._p[1],
  1008. mX2 = this._p[2],
  1009. mY2 = this._p[3];
  1010. this._precomputed = true;
  1011. if (mX1 !== mY1 || mX2 !== mY2)
  1012. this._calcSampleValues();
  1013. },
  1014. _calcSampleValues: function () {
  1015. var mX1 = this._p[0],
  1016. mX2 = this._p[2];
  1017. for (var i = 0; i < kSplineTableSize; ++i) {
  1018. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  1019. }
  1020. },
  1021. /**
  1022. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  1023. */
  1024. _getTForX: function (aX) {
  1025. var mX1 = this._p[0],
  1026. mX2 = this._p[2],
  1027. mSampleValues = this._mSampleValues;
  1028. var intervalStart = 0.0;
  1029. var currentSample = 1;
  1030. var lastSample = kSplineTableSize - 1;
  1031. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  1032. intervalStart += kSampleStepSize;
  1033. }
  1034. --currentSample;
  1035. // Interpolate to provide an initial guess for t
  1036. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample+1] - mSampleValues[currentSample]);
  1037. var guessForT = intervalStart + dist * kSampleStepSize;
  1038. var initialSlope = getSlope(guessForT, mX1, mX2);
  1039. if (initialSlope >= NEWTON_MIN_SLOPE) {
  1040. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  1041. } else if (initialSlope === 0.0) {
  1042. return guessForT;
  1043. } else {
  1044. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  1045. }
  1046. }
  1047. };
  1048. return ob;
  1049. }());
  1050. (function () {
  1051. var lastTime = 0;
  1052. var vendors = ['ms', 'moz', 'webkit', 'o'];
  1053. for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
  1054. window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
  1055. window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
  1056. }
  1057. if(!window.requestAnimationFrame)
  1058. window.requestAnimationFrame = function (callback, element) {
  1059. var currTime = new Date().getTime();
  1060. var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  1061. var id = setTimeout(function () {
  1062. callback(currTime + timeToCall);
  1063. },
  1064. timeToCall);
  1065. lastTime = currTime + timeToCall;
  1066. return id;
  1067. };
  1068. if(!window.cancelAnimationFrame)
  1069. window.cancelAnimationFrame = function (id) {
  1070. clearTimeout(id);
  1071. };
  1072. }());
  1073. function extendPrototype(sources,destination){
  1074. var i, len = sources.length, sourcePrototype;
  1075. for (i = 0;i < len;i += 1) {
  1076. sourcePrototype = sources[i].prototype;
  1077. for (var attr in sourcePrototype) {
  1078. if (sourcePrototype.hasOwnProperty(attr)) destination.prototype[attr] = sourcePrototype[attr];
  1079. }
  1080. }
  1081. }
  1082. function getDescriptor(object, prop) {
  1083. return Object.getOwnPropertyDescriptor(object, prop);
  1084. }
  1085. function createProxyFunction(prototype) {
  1086. function ProxyFunction(){}
  1087. ProxyFunction.prototype = prototype;
  1088. return ProxyFunction;
  1089. }
  1090. function bezFunction(){
  1091. var easingFunctions = [];
  1092. var math = Math;
  1093. function pointOnLine2D(x1,y1, x2,y2, x3,y3){
  1094. var det1 = (x1*y2) + (y1*x3) + (x2*y3) - (x3*y2) - (y3*x1) - (x2*y1);
  1095. return det1 > -0.001 && det1 < 0.001;
  1096. }
  1097. function pointOnLine3D(x1,y1,z1, x2,y2,z2, x3,y3,z3){
  1098. if(z1 === 0 && z2 === 0 && z3 === 0) {
  1099. return pointOnLine2D(x1,y1, x2,y2, x3,y3);
  1100. }
  1101. var dist1 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) + Math.pow(z2 - z1, 2));
  1102. var dist2 = Math.sqrt(Math.pow(x3 - x1, 2) + Math.pow(y3 - y1, 2) + Math.pow(z3 - z1, 2));
  1103. var dist3 = Math.sqrt(Math.pow(x3 - x2, 2) + Math.pow(y3 - y2, 2) + Math.pow(z3 - z2, 2));
  1104. var diffDist;
  1105. if(dist1 > dist2){
  1106. if(dist1 > dist3){
  1107. diffDist = dist1 - dist2 - dist3;
  1108. } else {
  1109. diffDist = dist3 - dist2 - dist1;
  1110. }
  1111. } else if(dist3 > dist2){
  1112. diffDist = dist3 - dist2 - dist1;
  1113. } else {
  1114. diffDist = dist2 - dist1 - dist3;
  1115. }
  1116. return diffDist > -0.0001 && diffDist < 0.0001;
  1117. }
  1118. var getBezierLength = (function(){
  1119. return function(pt1,pt2,pt3,pt4){
  1120. var curveSegments = defaultCurveSegments;
  1121. var k;
  1122. var i, len;
  1123. var ptCoord,perc,addedLength = 0;
  1124. var ptDistance;
  1125. var point = [],lastPoint = [];
  1126. var lengthData = bezier_length_pool.newElement();
  1127. len = pt3.length;
  1128. for(k=0;k<curveSegments;k+=1){
  1129. perc = k/(curveSegments-1);
  1130. ptDistance = 0;
  1131. for(i=0;i<len;i+=1){
  1132. 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];
  1133. point[i] = ptCoord;
  1134. if(lastPoint[i] !== null){
  1135. ptDistance += bm_pow(point[i] - lastPoint[i],2);
  1136. }
  1137. lastPoint[i] = point[i];
  1138. }
  1139. if(ptDistance){
  1140. ptDistance = bm_sqrt(ptDistance);
  1141. addedLength += ptDistance;
  1142. }
  1143. lengthData.percents[k] = perc;
  1144. lengthData.lengths[k] = addedLength;
  1145. }
  1146. lengthData.addedLength = addedLength;
  1147. return lengthData;
  1148. };
  1149. }());
  1150. function getSegmentsLength(shapeData) {
  1151. var segmentsLength = segments_length_pool.newElement();
  1152. var closed = shapeData.c;
  1153. var pathV = shapeData.v;
  1154. var pathO = shapeData.o;
  1155. var pathI = shapeData.i;
  1156. var i, len = shapeData._length;
  1157. var lengths = segmentsLength.lengths;
  1158. var totalLength = 0;
  1159. for(i=0;i<len-1;i+=1){
  1160. lengths[i] = getBezierLength(pathV[i],pathV[i+1],pathO[i],pathI[i+1]);
  1161. totalLength += lengths[i].addedLength;
  1162. }
  1163. if(closed && len){
  1164. lengths[i] = getBezierLength(pathV[i],pathV[0],pathO[i],pathI[0]);
  1165. totalLength += lengths[i].addedLength;
  1166. }
  1167. segmentsLength.totalLength = totalLength;
  1168. return segmentsLength;
  1169. }
  1170. function BezierData(length){
  1171. this.segmentLength = 0;
  1172. this.points = new Array(length);
  1173. }
  1174. function PointData(partial,point){
  1175. this.partialLength = partial;
  1176. this.point = point;
  1177. }
  1178. var buildBezierData = (function(){
  1179. var storedData = {};
  1180. return function (pt1, pt2, pt3, pt4){
  1181. var bezierName = (pt1[0]+'_'+pt1[1]+'_'+pt2[0]+'_'+pt2[1]+'_'+pt3[0]+'_'+pt3[1]+'_'+pt4[0]+'_'+pt4[1]).replace(/\./g, 'p');
  1182. if(!storedData[bezierName]){
  1183. var curveSegments = defaultCurveSegments;
  1184. var k, i, len;
  1185. var ptCoord,perc,addedLength = 0;
  1186. var ptDistance;
  1187. var point,lastPoint = null;
  1188. 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])){
  1189. curveSegments = 2;
  1190. }
  1191. var bezierData = new BezierData(curveSegments);
  1192. len = pt3.length;
  1193. for (k = 0; k < curveSegments; k += 1) {
  1194. point = createSizedArray(len);
  1195. perc = k / (curveSegments - 1);
  1196. ptDistance = 0;
  1197. for (i = 0; i < len; i += 1){
  1198. 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];
  1199. point[i] = ptCoord;
  1200. if(lastPoint !== null){
  1201. ptDistance += bm_pow(point[i] - lastPoint[i],2);
  1202. }
  1203. }
  1204. ptDistance = bm_sqrt(ptDistance);
  1205. addedLength += ptDistance;
  1206. bezierData.points[k] = new PointData(ptDistance, point);
  1207. lastPoint = point;
  1208. }
  1209. bezierData.segmentLength = addedLength;
  1210. storedData[bezierName] = bezierData;
  1211. }
  1212. return storedData[bezierName];
  1213. };
  1214. }());
  1215. function getDistancePerc(perc,bezierData){
  1216. var percents = bezierData.percents;
  1217. var lengths = bezierData.lengths;
  1218. var len = percents.length;
  1219. var initPos = bm_floor((len-1)*perc);
  1220. var lengthPos = perc*bezierData.addedLength;
  1221. var lPerc = 0;
  1222. if(initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]){
  1223. return percents[initPos];
  1224. }else{
  1225. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  1226. var flag = true;
  1227. while(flag){
  1228. if(lengths[initPos] <= lengthPos && lengths[initPos+1] > lengthPos){
  1229. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos+1] - lengths[initPos]);
  1230. flag = false;
  1231. }else{
  1232. initPos += dir;
  1233. }
  1234. if(initPos < 0 || initPos >= len - 1){
  1235. //FIX for TypedArrays that don't store floating point values with enough accuracy
  1236. if(initPos === len - 1) {
  1237. return percents[initPos];
  1238. }
  1239. flag = false;
  1240. }
  1241. }
  1242. return percents[initPos] + (percents[initPos+1] - percents[initPos])*lPerc;
  1243. }
  1244. }
  1245. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  1246. var t1 = getDistancePerc(percent,bezierData);
  1247. var u0 = 1;
  1248. var u1 = 1 - t1;
  1249. 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;
  1250. 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;
  1251. return [ptX, ptY];
  1252. }
  1253. function getSegmentArray() {
  1254. }
  1255. var bezier_segment_points = createTypedArray('float32', 8);
  1256. function getNewSegment(pt1,pt2,pt3,pt4,startPerc,endPerc, bezierData){
  1257. startPerc = startPerc < 0 ? 0 : startPerc > 1 ? 1 : startPerc;
  1258. var t0 = getDistancePerc(startPerc,bezierData);
  1259. endPerc = endPerc > 1 ? 1 : endPerc;
  1260. var t1 = getDistancePerc(endPerc,bezierData);
  1261. var i, len = pt1.length;
  1262. var u0 = 1 - t0;
  1263. var u1 = 1 - t1;
  1264. var u0u0u0 = u0*u0*u0;
  1265. var t0u0u0_3 = t0*u0*u0*3;
  1266. var t0t0u0_3 = t0*t0*u0*3;
  1267. var t0t0t0 = t0*t0*t0;
  1268. //
  1269. var u0u0u1 = u0*u0*u1;
  1270. var t0u0u1_3 = t0*u0*u1 + u0*t0*u1 + u0*u0*t1;
  1271. var t0t0u1_3 = t0*t0*u1 + u0*t0*t1 + t0*u0*t1;
  1272. var t0t0t1 = t0*t0*t1;
  1273. //
  1274. var u0u1u1 = u0*u1*u1;
  1275. var t0u1u1_3 = t0*u1*u1 + u0*t1*u1 + u0*u1*t1;
  1276. var t0t1u1_3 = t0*t1*u1 + u0*t1*t1 + t0*u1*t1;
  1277. var t0t1t1 = t0*t1*t1;
  1278. //
  1279. var u1u1u1 = u1*u1*u1;
  1280. var t1u1u1_3 = t1*u1*u1 + u1*t1*u1 + u1*u1*t1;
  1281. var t1t1u1_3 = t1*t1*u1 + u1*t1*t1 + t1*u1*t1;
  1282. var t1t1t1 = t1*t1*t1;
  1283. for(i=0;i<len;i+=1){
  1284. bezier_segment_points[i * 4] = Math.round((u0u0u0 * pt1[i] + t0u0u0_3 * pt3[i] + t0t0u0_3 * pt4[i] + t0t0t0 * pt2[i]) * 1000) / 1000;
  1285. bezier_segment_points[i * 4 + 1] = Math.round((u0u0u1 * pt1[i] + t0u0u1_3 * pt3[i] + t0t0u1_3 * pt4[i] + t0t0t1 * pt2[i]) * 1000) / 1000;
  1286. bezier_segment_points[i * 4 + 2] = Math.round((u0u1u1 * pt1[i] + t0u1u1_3 * pt3[i] + t0t1u1_3 * pt4[i] + t0t1t1 * pt2[i]) * 1000) / 1000;
  1287. bezier_segment_points[i * 4 + 3] = Math.round((u1u1u1 * pt1[i] + t1u1u1_3 * pt3[i] + t1t1u1_3 * pt4[i] + t1t1t1 * pt2[i]) * 1000) / 1000;
  1288. }
  1289. return bezier_segment_points;
  1290. }
  1291. return {
  1292. getSegmentsLength : getSegmentsLength,
  1293. getNewSegment : getNewSegment,
  1294. getPointInSegment : getPointInSegment,
  1295. buildBezierData : buildBezierData,
  1296. pointOnLine2D : pointOnLine2D,
  1297. pointOnLine3D : pointOnLine3D
  1298. };
  1299. }
  1300. var bez = bezFunction();
  1301. function dataFunctionManager(){
  1302. //var tCanvasHelper = createTag('canvas').getContext('2d');
  1303. function completeLayers(layers, comps, fontManager){
  1304. var layerData;
  1305. var animArray, lastFrame;
  1306. var i, len = layers.length;
  1307. var j, jLen, k, kLen;
  1308. for(i=0;i<len;i+=1){
  1309. layerData = layers[i];
  1310. if(!('ks' in layerData) || layerData.completed){
  1311. continue;
  1312. }
  1313. layerData.completed = true;
  1314. if(layerData.tt){
  1315. layers[i-1].td = layerData.tt;
  1316. }
  1317. animArray = [];
  1318. lastFrame = -1;
  1319. if(layerData.hasMask){
  1320. var maskProps = layerData.masksProperties;
  1321. jLen = maskProps.length;
  1322. for(j=0;j<jLen;j+=1){
  1323. if(maskProps[j].pt.k.i){
  1324. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  1325. }else{
  1326. kLen = maskProps[j].pt.k.length;
  1327. for(k=0;k<kLen;k+=1){
  1328. if(maskProps[j].pt.k[k].s){
  1329. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  1330. }
  1331. if(maskProps[j].pt.k[k].e){
  1332. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. if(layerData.ty===0){
  1339. layerData.layers = findCompLayers(layerData.refId, comps);
  1340. completeLayers(layerData.layers,comps, fontManager);
  1341. }else if(layerData.ty === 4){
  1342. completeShapes(layerData.shapes);
  1343. }else if(layerData.ty == 5){
  1344. completeText(layerData, fontManager);
  1345. }
  1346. }
  1347. }
  1348. function findCompLayers(id,comps){
  1349. var i = 0, len = comps.length;
  1350. while(i<len){
  1351. if(comps[i].id === id){
  1352. if(!comps[i].layers.__used) {
  1353. comps[i].layers.__used = true;
  1354. return comps[i].layers;
  1355. }
  1356. return JSON.parse(JSON.stringify(comps[i].layers));
  1357. }
  1358. i += 1;
  1359. }
  1360. }
  1361. function completeShapes(arr){
  1362. var i, len = arr.length;
  1363. var j, jLen;
  1364. var hasPaths = false;
  1365. for(i=len-1;i>=0;i-=1){
  1366. if(arr[i].ty == 'sh'){
  1367. if(arr[i].ks.k.i){
  1368. convertPathsToAbsoluteValues(arr[i].ks.k);
  1369. }else{
  1370. jLen = arr[i].ks.k.length;
  1371. for(j=0;j<jLen;j+=1){
  1372. if(arr[i].ks.k[j].s){
  1373. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  1374. }
  1375. if(arr[i].ks.k[j].e){
  1376. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  1377. }
  1378. }
  1379. }
  1380. hasPaths = true;
  1381. }else if(arr[i].ty == 'gr'){
  1382. completeShapes(arr[i].it);
  1383. }
  1384. }
  1385. /*if(hasPaths){
  1386. //mx: distance
  1387. //ss: sensitivity
  1388. //dc: decay
  1389. arr.splice(arr.length-1,0,{
  1390. "ty": "ms",
  1391. "mx":20,
  1392. "ss":10,
  1393. "dc":0.001,
  1394. "maxDist":200
  1395. });
  1396. }*/
  1397. }
  1398. function convertPathsToAbsoluteValues(path){
  1399. var i, len = path.i.length;
  1400. for(i=0;i<len;i+=1){
  1401. path.i[i][0] += path.v[i][0];
  1402. path.i[i][1] += path.v[i][1];
  1403. path.o[i][0] += path.v[i][0];
  1404. path.o[i][1] += path.v[i][1];
  1405. }
  1406. }
  1407. function checkVersion(minimum,animVersionString){
  1408. var animVersion = animVersionString ? animVersionString.split('.') : [100,100,100];
  1409. if(minimum[0]>animVersion[0]){
  1410. return true;
  1411. } else if(animVersion[0] > minimum[0]){
  1412. return false;
  1413. }
  1414. if(minimum[1]>animVersion[1]){
  1415. return true;
  1416. } else if(animVersion[1] > minimum[1]){
  1417. return false;
  1418. }
  1419. if(minimum[2]>animVersion[2]){
  1420. return true;
  1421. } else if(animVersion[2] > minimum[2]){
  1422. return false;
  1423. }
  1424. }
  1425. var checkText = (function(){
  1426. var minimumVersion = [4,4,14];
  1427. function updateTextLayer(textLayer){
  1428. var documentData = textLayer.t.d;
  1429. textLayer.t.d = {
  1430. k: [
  1431. {
  1432. s:documentData,
  1433. t:0
  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 === 5){
  1442. updateTextLayer(layers[i]);
  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 checkChars = (function() {
  1461. var minimumVersion = [4,7,99];
  1462. return function (animationData){
  1463. if(animationData.chars && !checkVersion(minimumVersion,animationData.v)){
  1464. var i, len = animationData.chars.length, j, jLen, k, kLen;
  1465. var pathData, paths;
  1466. for(i = 0; i < len; i += 1) {
  1467. if(animationData.chars[i].data && animationData.chars[i].data.shapes) {
  1468. paths = animationData.chars[i].data.shapes[0].it;
  1469. jLen = paths.length;
  1470. for(j = 0; j < jLen; j += 1) {
  1471. pathData = paths[j].ks.k;
  1472. if(!pathData.__converted) {
  1473. convertPathsToAbsoluteValues(paths[j].ks.k);
  1474. pathData.__converted = true;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. };
  1481. }());
  1482. var checkColors = (function(){
  1483. var minimumVersion = [4,1,9];
  1484. function iterateShapes(shapes){
  1485. var i, len = shapes.length;
  1486. var j, jLen;
  1487. for(i=0;i<len;i+=1){
  1488. if(shapes[i].ty === 'gr'){
  1489. iterateShapes(shapes[i].it);
  1490. }else if(shapes[i].ty === 'fl' || shapes[i].ty === 'st'){
  1491. if(shapes[i].c.k && shapes[i].c.k[0].i){
  1492. jLen = shapes[i].c.k.length;
  1493. for(j=0;j<jLen;j+=1){
  1494. if(shapes[i].c.k[j].s){
  1495. shapes[i].c.k[j].s[0] /= 255;
  1496. shapes[i].c.k[j].s[1] /= 255;
  1497. shapes[i].c.k[j].s[2] /= 255;
  1498. shapes[i].c.k[j].s[3] /= 255;
  1499. }
  1500. if(shapes[i].c.k[j].e){
  1501. shapes[i].c.k[j].e[0] /= 255;
  1502. shapes[i].c.k[j].e[1] /= 255;
  1503. shapes[i].c.k[j].e[2] /= 255;
  1504. shapes[i].c.k[j].e[3] /= 255;
  1505. }
  1506. }
  1507. } else {
  1508. shapes[i].c.k[0] /= 255;
  1509. shapes[i].c.k[1] /= 255;
  1510. shapes[i].c.k[2] /= 255;
  1511. shapes[i].c.k[3] /= 255;
  1512. }
  1513. }
  1514. }
  1515. }
  1516. function iterateLayers(layers){
  1517. var i, len = layers.length;
  1518. for(i=0;i<len;i+=1){
  1519. if(layers[i].ty === 4){
  1520. iterateShapes(layers[i].shapes);
  1521. }
  1522. }
  1523. }
  1524. return function (animationData){
  1525. if(checkVersion(minimumVersion,animationData.v)){
  1526. iterateLayers(animationData.layers);
  1527. if(animationData.assets){
  1528. var i, len = animationData.assets.length;
  1529. for(i=0;i<len;i+=1){
  1530. if(animationData.assets[i].layers){
  1531. iterateLayers(animationData.assets[i].layers);
  1532. }
  1533. }
  1534. }
  1535. }
  1536. };
  1537. }());
  1538. var checkShapes = (function(){
  1539. var minimumVersion = [4,4,18];
  1540. function completeShapes(arr){
  1541. var i, len = arr.length;
  1542. var j, jLen;
  1543. var hasPaths = false;
  1544. for(i=len-1;i>=0;i-=1){
  1545. if(arr[i].ty == 'sh'){
  1546. if(arr[i].ks.k.i){
  1547. arr[i].ks.k.c = arr[i].closed;
  1548. }else{
  1549. jLen = arr[i].ks.k.length;
  1550. for(j=0;j<jLen;j+=1){
  1551. if(arr[i].ks.k[j].s){
  1552. arr[i].ks.k[j].s[0].c = arr[i].closed;
  1553. }
  1554. if(arr[i].ks.k[j].e){
  1555. arr[i].ks.k[j].e[0].c = arr[i].closed;
  1556. }
  1557. }
  1558. }
  1559. hasPaths = true;
  1560. }else if(arr[i].ty == 'gr'){
  1561. completeShapes(arr[i].it);
  1562. }
  1563. }
  1564. }
  1565. function iterateLayers(layers){
  1566. var layerData;
  1567. var i, len = layers.length;
  1568. var j, jLen, k, kLen;
  1569. for(i=0;i<len;i+=1){
  1570. layerData = layers[i];
  1571. if(layerData.hasMask){
  1572. var maskProps = layerData.masksProperties;
  1573. jLen = maskProps.length;
  1574. for(j=0;j<jLen;j+=1){
  1575. if(maskProps[j].pt.k.i){
  1576. maskProps[j].pt.k.c = maskProps[j].cl;
  1577. }else{
  1578. kLen = maskProps[j].pt.k.length;
  1579. for(k=0;k<kLen;k+=1){
  1580. if(maskProps[j].pt.k[k].s){
  1581. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  1582. }
  1583. if(maskProps[j].pt.k[k].e){
  1584. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  1585. }
  1586. }
  1587. }
  1588. }
  1589. }
  1590. if(layerData.ty === 4){
  1591. completeShapes(layerData.shapes);
  1592. }
  1593. }
  1594. }
  1595. return function (animationData){
  1596. if(checkVersion(minimumVersion,animationData.v)){
  1597. iterateLayers(animationData.layers);
  1598. if(animationData.assets){
  1599. var i, len = animationData.assets.length;
  1600. for(i=0;i<len;i+=1){
  1601. if(animationData.assets[i].layers){
  1602. iterateLayers(animationData.assets[i].layers);
  1603. }
  1604. }
  1605. }
  1606. }
  1607. };
  1608. }());
  1609. function completeData(animationData, fontManager){
  1610. if(animationData.__complete){
  1611. return;
  1612. }
  1613. checkColors(animationData);
  1614. checkText(animationData);
  1615. checkChars(animationData);
  1616. checkShapes(animationData);
  1617. completeLayers(animationData.layers, animationData.assets, fontManager);
  1618. animationData.__complete = true;
  1619. //blitAnimation(animationData, animationData.assets, fontManager);
  1620. }
  1621. function completeText(data, fontManager){
  1622. if(data.t.a.length === 0 && !('m' in data.t.p)){
  1623. data.singleShape = true;
  1624. }
  1625. }
  1626. var moduleOb = {};
  1627. moduleOb.completeData = completeData;
  1628. moduleOb.checkColors = checkColors;
  1629. moduleOb.checkChars = checkChars;
  1630. moduleOb.checkShapes = checkShapes;
  1631. moduleOb.completeLayers = completeLayers;
  1632. return moduleOb;
  1633. }
  1634. var dataManager = dataFunctionManager();
  1635. var FontManager = (function(){
  1636. var maxWaitingTime = 5000;
  1637. var emptyChar = {
  1638. w: 0,
  1639. size:0,
  1640. shapes:[]
  1641. };
  1642. var combinedCharacters = [];
  1643. //Hindi characters
  1644. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366
  1645. , 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379
  1646. , 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  1647. function trimFontOptions(font) {
  1648. var familyArray = font.split(',');
  1649. var i, len = familyArray.length;
  1650. var enabledFamilies = [];
  1651. for (i = 0; i < len; i += 1) {
  1652. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  1653. enabledFamilies.push(familyArray[i]);
  1654. }
  1655. }
  1656. return enabledFamilies.join(',');
  1657. }
  1658. function setUpNode(font, family){
  1659. var parentNode = createTag('span');
  1660. parentNode.style.fontFamily = family;
  1661. var node = createTag('span');
  1662. // Characters that vary significantly among different fonts
  1663. node.innerText = 'giItT1WQy@!-/#';
  1664. // Visible - so we can measure it - but not on the screen
  1665. parentNode.style.position = 'absolute';
  1666. parentNode.style.left = '-10000px';
  1667. parentNode.style.top = '-10000px';
  1668. // Large font size makes even subtle changes obvious
  1669. parentNode.style.fontSize = '300px';
  1670. // Reset any font properties
  1671. parentNode.style.fontVariant = 'normal';
  1672. parentNode.style.fontStyle = 'normal';
  1673. parentNode.style.fontWeight = 'normal';
  1674. parentNode.style.letterSpacing = '0';
  1675. parentNode.appendChild(node);
  1676. document.body.appendChild(parentNode);
  1677. // Remember width with no applied web font
  1678. var width = node.offsetWidth;
  1679. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  1680. return {node:node, w:width, parent:parentNode};
  1681. }
  1682. function checkLoadedFonts() {
  1683. var i, len = this.fonts.length;
  1684. var node, w;
  1685. var loadedCount = len;
  1686. for(i=0;i<len; i+= 1){
  1687. if(this.fonts[i].loaded){
  1688. loadedCount -= 1;
  1689. continue;
  1690. }
  1691. if(this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0){
  1692. this.fonts[i].loaded = true;
  1693. } else{
  1694. node = this.fonts[i].monoCase.node;
  1695. w = this.fonts[i].monoCase.w;
  1696. if(node.offsetWidth !== w){
  1697. loadedCount -= 1;
  1698. this.fonts[i].loaded = true;
  1699. }else{
  1700. node = this.fonts[i].sansCase.node;
  1701. w = this.fonts[i].sansCase.w;
  1702. if(node.offsetWidth !== w){
  1703. loadedCount -= 1;
  1704. this.fonts[i].loaded = true;
  1705. }
  1706. }
  1707. if(this.fonts[i].loaded){
  1708. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  1709. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  1710. }
  1711. }
  1712. }
  1713. if(loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime){
  1714. setTimeout(this.checkLoadedFontsBinded, 20);
  1715. }else{
  1716. setTimeout(this.setIsLoadedBinded, 10);
  1717. }
  1718. }
  1719. function createHelper(def, fontData){
  1720. var tHelper = createNS('text');
  1721. tHelper.style.fontSize = '100px';
  1722. //tHelper.style.fontFamily = fontData.fFamily;
  1723. tHelper.setAttribute('font-family', fontData.fFamily);
  1724. tHelper.setAttribute('font-style', fontData.fStyle);
  1725. tHelper.setAttribute('font-weight', fontData.fWeight);
  1726. tHelper.textContent = '1';
  1727. if(fontData.fClass){
  1728. tHelper.style.fontFamily = 'inherit';
  1729. tHelper.setAttribute('class', fontData.fClass);
  1730. } else {
  1731. tHelper.style.fontFamily = fontData.fFamily;
  1732. }
  1733. def.appendChild(tHelper);
  1734. var tCanvasHelper = createTag('canvas').getContext('2d');
  1735. tCanvasHelper.font = fontData.fWeight + ' ' + fontData.fStyle + ' 100px '+ fontData.fFamily;
  1736. //tCanvasHelper.font = ' 100px '+ fontData.fFamily;
  1737. return tHelper;
  1738. }
  1739. function addFonts(fontData, defs){
  1740. if(!fontData){
  1741. this.isLoaded = true;
  1742. return;
  1743. }
  1744. if(this.chars){
  1745. this.isLoaded = true;
  1746. this.fonts = fontData.list;
  1747. return;
  1748. }
  1749. var fontArr = fontData.list;
  1750. var i, len = fontArr.length;
  1751. var _pendingFonts = len;
  1752. for(i=0; i<len; i+= 1){
  1753. var shouldLoadFont = true;
  1754. var loadedSelector;
  1755. var j;
  1756. fontArr[i].loaded = false;
  1757. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily,'monospace');
  1758. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily,'sans-serif');
  1759. if(!fontArr[i].fPath) {
  1760. fontArr[i].loaded = true;
  1761. _pendingFonts -= 1;
  1762. }else if(fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3){
  1763. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="'+ fontArr[i].fFamily +'"], style[f-origin="3"][f-family="'+ fontArr[i].fFamily +'"]');
  1764. if (loadedSelector.length > 0) {
  1765. shouldLoadFont = false;
  1766. }
  1767. if (shouldLoadFont) {
  1768. var s = createTag('style');
  1769. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  1770. s.setAttribute('f-origin', fontArr[i].origin);
  1771. s.setAttribute('f-family', fontArr[i].fFamily);
  1772. s.type = "text/css";
  1773. s.innerText = "@font-face {" + "font-family: "+fontArr[i].fFamily+"; font-style: normal; src: url('"+fontArr[i].fPath+"');}";
  1774. defs.appendChild(s);
  1775. }
  1776. } else if(fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1){
  1777. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  1778. for (j = 0; j < loadedSelector.length; j++) {
  1779. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  1780. // Font is already loaded
  1781. shouldLoadFont = false;
  1782. }
  1783. }
  1784. if (shouldLoadFont) {
  1785. var l = createTag('link');
  1786. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  1787. l.setAttribute('f-origin', fontArr[i].origin);
  1788. l.type = "text/css";
  1789. l.rel = "stylesheet";
  1790. l.href = fontArr[i].fPath;
  1791. document.body.appendChild(l);
  1792. }
  1793. } else if(fontArr[i].fOrigin === 't' || fontArr[i].origin === 2){
  1794. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  1795. for (j = 0; j < loadedSelector.length; j++) {
  1796. if (fontArr[i].fPath === loadedSelector[j].src) {
  1797. // Font is already loaded
  1798. shouldLoadFont = false;
  1799. }
  1800. }
  1801. if (shouldLoadFont) {
  1802. var sc = createTag('link');
  1803. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  1804. sc.setAttribute('f-origin', fontArr[i].origin);
  1805. sc.setAttribute('rel','stylesheet');
  1806. sc.setAttribute('href',fontArr[i].fPath);
  1807. defs.appendChild(sc);
  1808. }
  1809. }
  1810. fontArr[i].helper = createHelper(defs,fontArr[i]);
  1811. fontArr[i].cache = {};
  1812. this.fonts.push(fontArr[i]);
  1813. }
  1814. if (_pendingFonts === 0) {
  1815. this.isLoaded = true;
  1816. } else {
  1817. //On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  1818. //Adding this timeout seems to fix it
  1819. setTimeout(this.checkLoadedFonts.bind(this), 100);
  1820. }
  1821. }
  1822. function addChars(chars){
  1823. if(!chars){
  1824. return;
  1825. }
  1826. if(!this.chars){
  1827. this.chars = [];
  1828. }
  1829. var i, len = chars.length;
  1830. var j, jLen = this.chars.length, found;
  1831. for(i=0;i<len;i+=1){
  1832. j = 0;
  1833. found = false;
  1834. while(j<jLen){
  1835. if(this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch){
  1836. found = true;
  1837. }
  1838. j += 1;
  1839. }
  1840. if(!found){
  1841. this.chars.push(chars[i]);
  1842. jLen += 1;
  1843. }
  1844. }
  1845. }
  1846. function getCharData(char, style, font){
  1847. var i = 0, len = this.chars.length;
  1848. while( i < len) {
  1849. if(this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font){
  1850. return this.chars[i];
  1851. }
  1852. i+= 1;
  1853. }
  1854. if((typeof char === 'string' && char.charCodeAt(0) !== 13 || !char) && console && console.warn) {
  1855. console.warn('Missing character from exported characters list: ', char, style, font);
  1856. }
  1857. return emptyChar;
  1858. }
  1859. function measureText(char, fontName, size) {
  1860. var fontData = this.getFontByName(fontName);
  1861. var index = char.charCodeAt(0);
  1862. if(!fontData.cache[index + 1]) {
  1863. var tHelper = fontData.helper;
  1864. //Canvas version
  1865. //fontData.cache[index] = tHelper.measureText(char).width / 100;
  1866. //SVG version
  1867. //console.log(tHelper.getBBox().width)
  1868. if (char === ' ') {
  1869. tHelper.textContent = '|' + char + '|';
  1870. var doubleSize = tHelper.getComputedTextLength();
  1871. tHelper.textContent = '||';
  1872. var singleSize = tHelper.getComputedTextLength();
  1873. fontData.cache[index + 1] = (doubleSize - singleSize)/100;
  1874. } else {
  1875. tHelper.textContent = char;
  1876. fontData.cache[index + 1] = (tHelper.getComputedTextLength())/100;
  1877. }
  1878. }
  1879. return fontData.cache[index + 1] * size;
  1880. }
  1881. function getFontByName(name){
  1882. var i = 0, len = this.fonts.length;
  1883. while(i<len){
  1884. if(this.fonts[i].fName === name) {
  1885. return this.fonts[i];
  1886. }
  1887. i += 1;
  1888. }
  1889. return this.fonts[0];
  1890. }
  1891. function getCombinedCharacterCodes() {
  1892. return combinedCharacters;
  1893. }
  1894. function setIsLoaded() {
  1895. this.isLoaded = true
  1896. }
  1897. var Font = function(){
  1898. this.fonts = [];
  1899. this.chars = null;
  1900. this.typekitLoaded = 0;
  1901. this.isLoaded = false;
  1902. this.initTime = Date.now();
  1903. this.setIsLoadedBinded = this.setIsLoaded.bind(this)
  1904. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this)
  1905. };
  1906. //TODO: for now I'm adding these methods to the Class and not the prototype. Think of a better way to implement it.
  1907. Font.getCombinedCharacterCodes = getCombinedCharacterCodes;
  1908. var fontPrototype = {
  1909. addChars: addChars,
  1910. addFonts: addFonts,
  1911. getCharData: getCharData,
  1912. getFontByName: getFontByName,
  1913. measureText: measureText,
  1914. checkLoadedFonts: checkLoadedFonts,
  1915. setIsLoaded: setIsLoaded,
  1916. }
  1917. Font.prototype = fontPrototype;
  1918. return Font;
  1919. }());
  1920. var PropertyFactory = (function(){
  1921. var initFrame = initialDefaultFrame;
  1922. var math_abs = Math.abs;
  1923. function interpolateValue(frameNum, caching) {
  1924. var offsetTime = this.offsetTime;
  1925. var newValue;
  1926. if (this.propType === 'multidimensional') {
  1927. newValue = createTypedArray('float32', this.pv.length);
  1928. }
  1929. var iterationIndex = caching.lastIndex;
  1930. var i = iterationIndex;
  1931. var len = this.keyframes.length - 1, flag = true;
  1932. var keyData, nextKeyData;
  1933. while (flag) {
  1934. keyData = this.keyframes[i];
  1935. nextKeyData = this.keyframes[i + 1];
  1936. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime){
  1937. if(keyData.h){
  1938. keyData = nextKeyData;
  1939. }
  1940. iterationIndex = 0;
  1941. break;
  1942. }
  1943. if ((nextKeyData.t - offsetTime) > frameNum){
  1944. iterationIndex = i;
  1945. break;
  1946. }
  1947. if (i < len - 1){
  1948. i += 1;
  1949. } else {
  1950. iterationIndex = 0;
  1951. flag = false;
  1952. }
  1953. }
  1954. var k, kLen, perc, jLen, j, fnc;
  1955. var nextKeyTime = nextKeyData.t - offsetTime;
  1956. var keyTime = keyData.t - offsetTime;
  1957. var endValue;
  1958. if (keyData.to) {
  1959. if (!keyData.bezierData) {
  1960. keyData.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  1961. }
  1962. var bezierData = keyData.bezierData;
  1963. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  1964. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  1965. kLen = bezierData.points[ind].point.length;
  1966. for (k = 0; k < kLen; k += 1) {
  1967. newValue[k] = bezierData.points[ind].point[k];
  1968. }
  1969. // caching._lastKeyframeIndex = -1;
  1970. } else {
  1971. if (keyData.__fnct) {
  1972. fnc = keyData.__fnct;
  1973. } else {
  1974. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  1975. keyData.__fnct = fnc;
  1976. }
  1977. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  1978. var distanceInLine = bezierData.segmentLength*perc;
  1979. var segmentPerc;
  1980. var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0;
  1981. j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0;
  1982. flag = true;
  1983. jLen = bezierData.points.length;
  1984. while (flag) {
  1985. addedLength += bezierData.points[j].partialLength;
  1986. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  1987. kLen = bezierData.points[j].point.length;
  1988. for (k = 0; k < kLen; k += 1) {
  1989. newValue[k] = bezierData.points[j].point[k];
  1990. }
  1991. break;
  1992. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  1993. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  1994. kLen = bezierData.points[j].point.length;
  1995. for (k = 0; k < kLen; k += 1) {
  1996. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  1997. }
  1998. break;
  1999. }
  2000. if (j < jLen - 1){
  2001. j += 1;
  2002. } else {
  2003. flag = false;
  2004. }
  2005. }
  2006. caching._lastPoint = j;
  2007. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2008. caching._lastKeyframeIndex = i;
  2009. }
  2010. } else {
  2011. var outX, outY, inX, inY, keyValue;
  2012. len = keyData.s.length;
  2013. endValue = nextKeyData.s || keyData.e;
  2014. if (this.sh && keyData.h !== 1) {
  2015. if (frameNum >= nextKeyTime) {
  2016. newValue[0] = endValue[0];
  2017. newValue[1] = endValue[1];
  2018. newValue[2] = endValue[2];
  2019. } else if (frameNum <= keyTime) {
  2020. newValue[0] = keyData.s[0];
  2021. newValue[1] = keyData.s[1];
  2022. newValue[2] = keyData.s[2];
  2023. } else {
  2024. var quatStart = createQuaternion(keyData.s);
  2025. var quatEnd = createQuaternion(endValue);
  2026. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2027. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2028. }
  2029. } else {
  2030. for(i = 0; i < len; i += 1) {
  2031. if (keyData.h !== 1) {
  2032. if (frameNum >= nextKeyTime) {
  2033. perc = 1;
  2034. } else if(frameNum < keyTime) {
  2035. perc = 0;
  2036. } else {
  2037. if(keyData.o.x.constructor === Array) {
  2038. if (!keyData.__fnct) {
  2039. keyData.__fnct = [];
  2040. }
  2041. if (!keyData.__fnct[i]) {
  2042. outX = (typeof keyData.o.x[i] === 'undefined') ? keyData.o.x[0] : keyData.o.x[i];
  2043. outY = (typeof keyData.o.y[i] === 'undefined') ? keyData.o.y[0] : keyData.o.y[i];
  2044. inX = (typeof keyData.i.x[i] === 'undefined') ? keyData.i.x[0] : keyData.i.x[i];
  2045. inY = (typeof keyData.i.y[i] === 'undefined') ? keyData.i.y[0] : keyData.i.y[i];
  2046. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2047. keyData.__fnct[i] = fnc;
  2048. } else {
  2049. fnc = keyData.__fnct[i];
  2050. }
  2051. } else {
  2052. if (!keyData.__fnct) {
  2053. outX = keyData.o.x;
  2054. outY = keyData.o.y;
  2055. inX = keyData.i.x;
  2056. inY = keyData.i.y;
  2057. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2058. keyData.__fnct = fnc;
  2059. } else {
  2060. fnc = keyData.__fnct;
  2061. }
  2062. }
  2063. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime ));
  2064. }
  2065. }
  2066. endValue = nextKeyData.s || keyData.e;
  2067. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2068. if (this.propType === 'multidimensional') {
  2069. newValue[i] = keyValue;
  2070. } else {
  2071. newValue = keyValue;
  2072. }
  2073. }
  2074. }
  2075. }
  2076. caching.lastIndex = iterationIndex;
  2077. return newValue;
  2078. }
  2079. //based on @Toji's https://github.com/toji/gl-matrix/
  2080. function slerp(a, b, t) {
  2081. var out = [];
  2082. var ax = a[0], ay = a[1], az = a[2], aw = a[3],
  2083. bx = b[0], by = b[1], bz = b[2], bw = b[3]
  2084. var omega, cosom, sinom, scale0, scale1;
  2085. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2086. if (cosom < 0.0) {
  2087. cosom = -cosom;
  2088. bx = -bx;
  2089. by = -by;
  2090. bz = -bz;
  2091. bw = -bw;
  2092. }
  2093. if ((1.0 - cosom) > 0.000001) {
  2094. omega = Math.acos(cosom);
  2095. sinom = Math.sin(omega);
  2096. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2097. scale1 = Math.sin(t * omega) / sinom;
  2098. } else {
  2099. scale0 = 1.0 - t;
  2100. scale1 = t;
  2101. }
  2102. out[0] = scale0 * ax + scale1 * bx;
  2103. out[1] = scale0 * ay + scale1 * by;
  2104. out[2] = scale0 * az + scale1 * bz;
  2105. out[3] = scale0 * aw + scale1 * bw;
  2106. return out;
  2107. }
  2108. function quaternionToEuler(out, quat) {
  2109. var qx = quat[0];
  2110. var qy = quat[1];
  2111. var qz = quat[2];
  2112. var qw = quat[3];
  2113. var heading = Math.atan2(2*qy*qw-2*qx*qz , 1 - 2*qy*qy - 2*qz*qz)
  2114. var attitude = Math.asin(2*qx*qy + 2*qz*qw)
  2115. var bank = Math.atan2(2*qx*qw-2*qy*qz , 1 - 2*qx*qx - 2*qz*qz);
  2116. out[0] = heading/degToRads;
  2117. out[1] = attitude/degToRads;
  2118. out[2] = bank/degToRads;
  2119. }
  2120. function createQuaternion(values) {
  2121. var heading = values[0] * degToRads;
  2122. var attitude = values[1] * degToRads;
  2123. var bank = values[2] * degToRads;
  2124. var c1 = Math.cos(heading / 2);
  2125. var c2 = Math.cos(attitude / 2);
  2126. var c3 = Math.cos(bank / 2);
  2127. var s1 = Math.sin(heading / 2);
  2128. var s2 = Math.sin(attitude / 2);
  2129. var s3 = Math.sin(bank / 2);
  2130. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2131. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2132. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2133. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2134. return [x,y,z,w];
  2135. }
  2136. function getValueAtCurrentTime(){
  2137. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2138. var initTime = this.keyframes[0].t - this.offsetTime;
  2139. var endTime = this.keyframes[this.keyframes.length- 1].t-this.offsetTime;
  2140. if(!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))){
  2141. if(this._caching.lastFrame >= frameNum) {
  2142. this._caching._lastKeyframeIndex = -1;
  2143. this._caching.lastIndex = 0;
  2144. }
  2145. var renderResult = this.interpolateValue(frameNum, this._caching);
  2146. this.pv = renderResult;
  2147. }
  2148. this._caching.lastFrame = frameNum;
  2149. return this.pv;
  2150. }
  2151. function setVValue(val) {
  2152. var multipliedValue;
  2153. if(this.propType === 'unidimensional') {
  2154. multipliedValue = val * this.mult;
  2155. if(math_abs(this.v - multipliedValue) > 0.00001) {
  2156. this.v = multipliedValue;
  2157. this._mdf = true;
  2158. }
  2159. } else {
  2160. var i = 0, len = this.v.length;
  2161. while (i < len) {
  2162. multipliedValue = val[i] * this.mult;
  2163. if (math_abs(this.v[i] - multipliedValue) > 0.00001) {
  2164. this.v[i] = multipliedValue;
  2165. this._mdf = true;
  2166. }
  2167. i += 1;
  2168. }
  2169. }
  2170. }
  2171. function processEffectsSequence() {
  2172. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  2173. return;
  2174. }
  2175. if(this.lock) {
  2176. this.setVValue(this.pv);
  2177. return;
  2178. }
  2179. this.lock = true;
  2180. this._mdf = this._isFirstFrame;
  2181. var multipliedValue;
  2182. var i, len = this.effectsSequence.length;
  2183. var finalValue = this.kf ? this.pv : this.data.k;
  2184. for(i = 0; i < len; i += 1) {
  2185. finalValue = this.effectsSequence[i](finalValue);
  2186. }
  2187. this.setVValue(finalValue);
  2188. this._isFirstFrame = false;
  2189. this.lock = false;
  2190. this.frameId = this.elem.globalData.frameId;
  2191. }
  2192. function addEffect(effectFunction) {
  2193. this.effectsSequence.push(effectFunction);
  2194. this.container.addDynamicProperty(this);
  2195. }
  2196. function ValueProperty(elem, data, mult, container){
  2197. this.propType = 'unidimensional';
  2198. this.mult = mult || 1;
  2199. this.data = data;
  2200. this.v = mult ? data.k * mult : data.k;
  2201. this.pv = data.k;
  2202. this._mdf = false;
  2203. this.elem = elem;
  2204. this.container = container;
  2205. this.comp = elem.comp;
  2206. this.k = false;
  2207. this.kf = false;
  2208. this.vel = 0;
  2209. this.effectsSequence = [];
  2210. this._isFirstFrame = true;
  2211. this.getValue = processEffectsSequence;
  2212. this.setVValue = setVValue;
  2213. this.addEffect = addEffect;
  2214. }
  2215. function MultiDimensionalProperty(elem, data, mult, container) {
  2216. this.propType = 'multidimensional';
  2217. this.mult = mult || 1;
  2218. this.data = data;
  2219. this._mdf = false;
  2220. this.elem = elem;
  2221. this.container = container;
  2222. this.comp = elem.comp;
  2223. this.k = false;
  2224. this.kf = false;
  2225. this.frameId = -1;
  2226. var i, len = data.k.length;
  2227. this.v = createTypedArray('float32', len);
  2228. this.pv = createTypedArray('float32', len);
  2229. var arr = createTypedArray('float32', len);
  2230. this.vel = createTypedArray('float32', len);
  2231. for (i = 0; i < len; i += 1) {
  2232. this.v[i] = data.k[i] * this.mult;
  2233. this.pv[i] = data.k[i];
  2234. }
  2235. this._isFirstFrame = true;
  2236. this.effectsSequence = [];
  2237. this.getValue = processEffectsSequence;
  2238. this.setVValue = setVValue;
  2239. this.addEffect = addEffect;
  2240. }
  2241. function KeyframedValueProperty(elem, data, mult, container) {
  2242. this.propType = 'unidimensional';
  2243. this.keyframes = data.k;
  2244. this.offsetTime = elem.data.st;
  2245. this.frameId = -1;
  2246. this._caching = {lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1};
  2247. this.k = true;
  2248. this.kf = true;
  2249. this.data = data;
  2250. this.mult = mult || 1;
  2251. this.elem = elem;
  2252. this.container = container;
  2253. this.comp = elem.comp;
  2254. this.v = initFrame;
  2255. this.pv = initFrame;
  2256. this._isFirstFrame = true;
  2257. this.getValue = processEffectsSequence;
  2258. this.setVValue = setVValue;
  2259. this.interpolateValue = interpolateValue;
  2260. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  2261. this.addEffect = addEffect;
  2262. }
  2263. function KeyframedMultidimensionalProperty(elem, data, mult, container){
  2264. this.propType = 'multidimensional';
  2265. var i, len = data.k.length;
  2266. var s, e,to,ti;
  2267. for (i = 0; i < len - 1; i += 1) {
  2268. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  2269. s = data.k[i].s;
  2270. e = data.k[i + 1].s;
  2271. to = data.k[i].to;
  2272. ti = data.k[i].ti;
  2273. 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]))){
  2274. data.k[i].to = null;
  2275. data.k[i].ti = null;
  2276. }
  2277. if(s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  2278. if(s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) {
  2279. data.k[i].to = null;
  2280. data.k[i].ti = null;
  2281. }
  2282. }
  2283. }
  2284. }
  2285. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  2286. this.keyframes = data.k;
  2287. this.offsetTime = elem.data.st;
  2288. this.k = true;
  2289. this.kf = true;
  2290. this._isFirstFrame = true;
  2291. this.mult = mult || 1;
  2292. this.elem = elem;
  2293. this.container = container;
  2294. this.comp = elem.comp;
  2295. this.getValue = processEffectsSequence;
  2296. this.setVValue = setVValue;
  2297. this.interpolateValue = interpolateValue;
  2298. this.frameId = -1;
  2299. var arrLen = data.k[0].s.length;
  2300. this.v = createTypedArray('float32', arrLen);
  2301. this.pv = createTypedArray('float32', arrLen);
  2302. for (i = 0; i < arrLen; i += 1) {
  2303. this.v[i] = initFrame;
  2304. this.pv[i] = initFrame;
  2305. }
  2306. this._caching={lastFrame:initFrame,lastIndex:0,value:createTypedArray('float32', arrLen)};
  2307. this.addEffect = addEffect;
  2308. }
  2309. function getProp(elem,data,type, mult, container) {
  2310. var p;
  2311. if(!data.k.length){
  2312. p = new ValueProperty(elem,data, mult, container);
  2313. }else if(typeof(data.k[0]) === 'number'){
  2314. p = new MultiDimensionalProperty(elem,data, mult, container);
  2315. }else{
  2316. switch(type){
  2317. case 0:
  2318. p = new KeyframedValueProperty(elem,data,mult, container);
  2319. break;
  2320. case 1:
  2321. p = new KeyframedMultidimensionalProperty(elem,data,mult, container);
  2322. break;
  2323. }
  2324. }
  2325. if(p.effectsSequence.length){
  2326. container.addDynamicProperty(p);
  2327. }
  2328. return p;
  2329. }
  2330. var ob = {
  2331. getProp: getProp
  2332. };
  2333. return ob;
  2334. }());
  2335. var TransformPropertyFactory = (function() {
  2336. var defaultVector = [0,0]
  2337. function applyToMatrix(mat) {
  2338. var _mdf = this._mdf;
  2339. this.iterateDynamicProperties();
  2340. this._mdf = this._mdf || _mdf;
  2341. if (this.a) {
  2342. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  2343. }
  2344. if (this.s) {
  2345. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  2346. }
  2347. if (this.sk) {
  2348. mat.skewFromAxis(-this.sk.v, this.sa.v);
  2349. }
  2350. if (this.r) {
  2351. mat.rotate(-this.r.v);
  2352. } else {
  2353. 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]);
  2354. }
  2355. if (this.data.p.s) {
  2356. if (this.data.p.z) {
  2357. mat.translate(this.px.v, this.py.v, -this.pz.v);
  2358. } else {
  2359. mat.translate(this.px.v, this.py.v, 0);
  2360. }
  2361. } else {
  2362. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  2363. }
  2364. }
  2365. function processKeys(forceRender){
  2366. if (this.elem.globalData.frameId === this.frameId) {
  2367. return;
  2368. }
  2369. if(this._isDirty) {
  2370. this.precalculateMatrix();
  2371. this._isDirty = false;
  2372. }
  2373. this.iterateDynamicProperties();
  2374. if (this._mdf || forceRender) {
  2375. this.v.cloneFromProps(this.pre.props);
  2376. if (this.appliedTransformations < 1) {
  2377. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  2378. }
  2379. if(this.appliedTransformations < 2) {
  2380. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  2381. }
  2382. if (this.sk && this.appliedTransformations < 3) {
  2383. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  2384. }
  2385. if (this.r && this.appliedTransformations < 4) {
  2386. this.v.rotate(-this.r.v);
  2387. } else if (!this.r && this.appliedTransformations < 4){
  2388. 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]);
  2389. }
  2390. if (this.autoOriented) {
  2391. var v1,v2, frameRate = this.elem.globalData.frameRate;
  2392. if(this.p && this.p.keyframes && this.p.getValueAtTime) {
  2393. if (this.p._caching.lastFrame+this.p.offsetTime <= this.p.keyframes[0].t) {
  2394. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate,0);
  2395. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  2396. } else if(this.p._caching.lastFrame+this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  2397. v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0);
  2398. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  2399. } else {
  2400. v1 = this.p.pv;
  2401. v2 = this.p.getValueAtTime((this.p._caching.lastFrame+this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  2402. }
  2403. } else if(this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  2404. v1 = [];
  2405. v2 = [];
  2406. var px = this.px, py = this.py, frameRate;
  2407. if (px._caching.lastFrame+px.offsetTime <= px.keyframes[0].t) {
  2408. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate,0);
  2409. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate,0);
  2410. v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate,0);
  2411. v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate,0);
  2412. } else if(px._caching.lastFrame+px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  2413. v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate),0);
  2414. v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate),0);
  2415. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate,0);
  2416. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate,0);
  2417. } else {
  2418. v1 = [px.pv, py.pv];
  2419. v2[0] = px.getValueAtTime((px._caching.lastFrame+px.offsetTime - 0.01) / frameRate,px.offsetTime);
  2420. v2[1] = py.getValueAtTime((py._caching.lastFrame+py.offsetTime - 0.01) / frameRate,py.offsetTime);
  2421. }
  2422. } else {
  2423. v1 = v2 = defaultVector
  2424. }
  2425. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  2426. }
  2427. if(this.data.p && this.data.p.s){
  2428. if(this.data.p.z) {
  2429. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  2430. } else {
  2431. this.v.translate(this.px.v, this.py.v, 0);
  2432. }
  2433. }else{
  2434. this.v.translate(this.p.v[0],this.p.v[1],-this.p.v[2]);
  2435. }
  2436. }
  2437. this.frameId = this.elem.globalData.frameId;
  2438. }
  2439. function precalculateMatrix() {
  2440. if(!this.a.k) {
  2441. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  2442. this.appliedTransformations = 1;
  2443. } else {
  2444. return;
  2445. }
  2446. if(!this.s.effectsSequence.length) {
  2447. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  2448. this.appliedTransformations = 2;
  2449. } else {
  2450. return;
  2451. }
  2452. if(this.sk) {
  2453. if(!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  2454. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  2455. this.appliedTransformations = 3;
  2456. } else {
  2457. return;
  2458. }
  2459. }
  2460. if (this.r) {
  2461. if(!this.r.effectsSequence.length) {
  2462. this.pre.rotate(-this.r.v);
  2463. this.appliedTransformations = 4;
  2464. } else {
  2465. return;
  2466. }
  2467. } else if(!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  2468. 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]);
  2469. this.appliedTransformations = 4;
  2470. }
  2471. }
  2472. function autoOrient(){
  2473. //
  2474. //var prevP = this.getValueAtTime();
  2475. }
  2476. function addDynamicProperty(prop) {
  2477. this._addDynamicProperty(prop);
  2478. this.elem.addDynamicProperty(prop);
  2479. this._isDirty = true;
  2480. }
  2481. function TransformProperty(elem,data,container){
  2482. this.elem = elem;
  2483. this.frameId = -1;
  2484. this.propType = 'transform';
  2485. this.data = data;
  2486. this.v = new Matrix();
  2487. //Precalculated matrix with non animated properties
  2488. this.pre = new Matrix();
  2489. this.appliedTransformations = 0;
  2490. this.initDynamicPropertyContainer(container || elem);
  2491. if(data.p && data.p.s){
  2492. this.px = PropertyFactory.getProp(elem,data.p.x,0,0,this);
  2493. this.py = PropertyFactory.getProp(elem,data.p.y,0,0,this);
  2494. if(data.p.z){
  2495. this.pz = PropertyFactory.getProp(elem,data.p.z,0,0,this);
  2496. }
  2497. }else{
  2498. this.p = PropertyFactory.getProp(elem,data.p || {k:[0,0,0]},1,0,this);
  2499. }
  2500. if(data.rx) {
  2501. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  2502. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  2503. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  2504. if(data.or.k[0].ti) {
  2505. var i, len = data.or.k.length;
  2506. for(i=0;i<len;i+=1) {
  2507. data.or.k[i].to = data.or.k[i].ti = null;
  2508. }
  2509. }
  2510. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  2511. //sh Indicates it needs to be capped between -180 and 180
  2512. this.or.sh = true;
  2513. } else {
  2514. this.r = PropertyFactory.getProp(elem, data.r || {k: 0}, 0, degToRads, this);
  2515. }
  2516. if(data.sk){
  2517. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  2518. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  2519. }
  2520. this.a = PropertyFactory.getProp(elem,data.a || {k:[0,0,0]},1,0,this);
  2521. this.s = PropertyFactory.getProp(elem,data.s || {k:[100,100,100]},1,0.01,this);
  2522. // 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.
  2523. if(data.o){
  2524. this.o = PropertyFactory.getProp(elem,data.o,0,0.01,elem);
  2525. } else {
  2526. this.o = {_mdf:false,v:1};
  2527. }
  2528. this._isDirty = true;
  2529. if(!this.dynamicProperties.length){
  2530. this.getValue(true);
  2531. }
  2532. }
  2533. TransformProperty.prototype = {
  2534. applyToMatrix: applyToMatrix,
  2535. getValue: processKeys,
  2536. precalculateMatrix: precalculateMatrix,
  2537. autoOrient: autoOrient
  2538. }
  2539. extendPrototype([DynamicPropertyContainer], TransformProperty);
  2540. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  2541. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  2542. function getTransformProperty(elem,data,container){
  2543. return new TransformProperty(elem,data,container);
  2544. }
  2545. return {
  2546. getTransformProperty: getTransformProperty
  2547. };
  2548. }());
  2549. function ShapePath(){
  2550. this.c = false;
  2551. this._length = 0;
  2552. this._maxLength = 8;
  2553. this.v = createSizedArray(this._maxLength);
  2554. this.o = createSizedArray(this._maxLength);
  2555. this.i = createSizedArray(this._maxLength);
  2556. }
  2557. ShapePath.prototype.setPathData = function(closed, len) {
  2558. this.c = closed;
  2559. this.setLength(len);
  2560. var i = 0;
  2561. while(i < len){
  2562. this.v[i] = point_pool.newElement();
  2563. this.o[i] = point_pool.newElement();
  2564. this.i[i] = point_pool.newElement();
  2565. i += 1;
  2566. }
  2567. };
  2568. ShapePath.prototype.setLength = function(len) {
  2569. while(this._maxLength < len) {
  2570. this.doubleArrayLength();
  2571. }
  2572. this._length = len;
  2573. };
  2574. ShapePath.prototype.doubleArrayLength = function() {
  2575. this.v = this.v.concat(createSizedArray(this._maxLength));
  2576. this.i = this.i.concat(createSizedArray(this._maxLength));
  2577. this.o = this.o.concat(createSizedArray(this._maxLength));
  2578. this._maxLength *= 2;
  2579. };
  2580. ShapePath.prototype.setXYAt = function(x, y, type, pos, replace) {
  2581. var arr;
  2582. this._length = Math.max(this._length, pos + 1);
  2583. if(this._length >= this._maxLength) {
  2584. this.doubleArrayLength();
  2585. }
  2586. switch(type){
  2587. case 'v':
  2588. arr = this.v;
  2589. break;
  2590. case 'i':
  2591. arr = this.i;
  2592. break;
  2593. case 'o':
  2594. arr = this.o;
  2595. break;
  2596. }
  2597. if(!arr[pos] || (arr[pos] && !replace)){
  2598. arr[pos] = point_pool.newElement();
  2599. }
  2600. arr[pos][0] = x;
  2601. arr[pos][1] = y;
  2602. };
  2603. ShapePath.prototype.setTripleAt = function(vX,vY,oX,oY,iX,iY,pos, replace) {
  2604. this.setXYAt(vX,vY,'v',pos, replace);
  2605. this.setXYAt(oX,oY,'o',pos, replace);
  2606. this.setXYAt(iX,iY,'i',pos, replace);
  2607. };
  2608. ShapePath.prototype.reverse = function() {
  2609. var newPath = new ShapePath();
  2610. newPath.setPathData(this.c, this._length);
  2611. var vertices = this.v, outPoints = this.o, inPoints = this.i;
  2612. var init = 0;
  2613. if (this.c) {
  2614. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  2615. init = 1;
  2616. }
  2617. var cnt = this._length - 1;
  2618. var len = this._length;
  2619. var i;
  2620. for (i = init; i < len; i += 1) {
  2621. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  2622. cnt -= 1;
  2623. }
  2624. return newPath;
  2625. };
  2626. var ShapePropertyFactory = (function(){
  2627. var initFrame = -999999;
  2628. function interpolateShape(frameNum, previousValue, caching) {
  2629. var iterationIndex = caching.lastIndex;
  2630. var keyPropS,keyPropE,isHold, j, k, jLen, kLen, perc, vertexValue;
  2631. var kf = this.keyframes;
  2632. if(frameNum < kf[0].t-this.offsetTime){
  2633. keyPropS = kf[0].s[0];
  2634. isHold = true;
  2635. iterationIndex = 0;
  2636. }else if(frameNum >= kf[kf.length - 1].t-this.offsetTime){
  2637. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  2638. /*if(kf[kf.length - 1].s){
  2639. keyPropS = kf[kf.length - 1].s[0];
  2640. }else{
  2641. keyPropS = kf[kf.length - 2].e[0];
  2642. }*/
  2643. isHold = true;
  2644. }else{
  2645. var i = iterationIndex;
  2646. var len = kf.length- 1,flag = true,keyData,nextKeyData;
  2647. while(flag){
  2648. keyData = kf[i];
  2649. nextKeyData = kf[i+1];
  2650. if((nextKeyData.t - this.offsetTime) > frameNum){
  2651. break;
  2652. }
  2653. if(i < len - 1){
  2654. i += 1;
  2655. }else{
  2656. flag = false;
  2657. }
  2658. }
  2659. isHold = keyData.h === 1;
  2660. iterationIndex = i;
  2661. if(!isHold){
  2662. if(frameNum >= nextKeyData.t-this.offsetTime){
  2663. perc = 1;
  2664. }else if(frameNum < keyData.t-this.offsetTime){
  2665. perc = 0;
  2666. }else{
  2667. var fnc;
  2668. if(keyData.__fnct){
  2669. fnc = keyData.__fnct;
  2670. }else{
  2671. fnc = BezierFactory.getBezierEasing(keyData.o.x,keyData.o.y,keyData.i.x,keyData.i.y).get;
  2672. keyData.__fnct = fnc;
  2673. }
  2674. perc = fnc((frameNum-(keyData.t-this.offsetTime))/((nextKeyData.t-this.offsetTime)-(keyData.t-this.offsetTime)));
  2675. }
  2676. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  2677. }
  2678. keyPropS = keyData.s[0];
  2679. }
  2680. jLen = previousValue._length;
  2681. kLen = keyPropS.i[0].length;
  2682. caching.lastIndex = iterationIndex;
  2683. for(j=0;j<jLen;j+=1){
  2684. for(k=0;k<kLen;k+=1){
  2685. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k]+(keyPropE.i[j][k]-keyPropS.i[j][k])*perc;
  2686. previousValue.i[j][k] = vertexValue;
  2687. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k]+(keyPropE.o[j][k]-keyPropS.o[j][k])*perc;
  2688. previousValue.o[j][k] = vertexValue;
  2689. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k]+(keyPropE.v[j][k]-keyPropS.v[j][k])*perc;
  2690. previousValue.v[j][k] = vertexValue;
  2691. }
  2692. }
  2693. }
  2694. function interpolateShapeCurrentTime(){
  2695. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2696. var initTime = this.keyframes[0].t - this.offsetTime;
  2697. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2698. var lastFrame = this._caching.lastFrame;
  2699. if(!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))){
  2700. ////
  2701. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  2702. this.interpolateShape(frameNum, this.pv, this._caching);
  2703. ////
  2704. }
  2705. this._caching.lastFrame = frameNum;
  2706. return this.pv;
  2707. }
  2708. function resetShape(){
  2709. this.paths = this.localShapeCollection;
  2710. }
  2711. function shapesEqual(shape1, shape2) {
  2712. if(shape1._length !== shape2._length || shape1.c !== shape2.c){
  2713. return false;
  2714. }
  2715. var i, len = shape1._length;
  2716. for(i = 0; i < len; i += 1) {
  2717. if(shape1.v[i][0] !== shape2.v[i][0]
  2718. || shape1.v[i][1] !== shape2.v[i][1]
  2719. || shape1.o[i][0] !== shape2.o[i][0]
  2720. || shape1.o[i][1] !== shape2.o[i][1]
  2721. || shape1.i[i][0] !== shape2.i[i][0]
  2722. || shape1.i[i][1] !== shape2.i[i][1]) {
  2723. return false;
  2724. }
  2725. }
  2726. return true;
  2727. }
  2728. function setVValue(newPath) {
  2729. if(!shapesEqual(this.v, newPath)) {
  2730. this.v = shape_pool.clone(newPath);
  2731. this.localShapeCollection.releaseShapes();
  2732. this.localShapeCollection.addShape(this.v);
  2733. this._mdf = true;
  2734. this.paths = this.localShapeCollection;
  2735. }
  2736. }
  2737. function processEffectsSequence() {
  2738. if (this.elem.globalData.frameId === this.frameId) {
  2739. return;
  2740. } else if (!this.effectsSequence.length) {
  2741. this._mdf = false;
  2742. return;
  2743. }
  2744. if (this.lock) {
  2745. this.setVValue(this.pv);
  2746. return;
  2747. }
  2748. this.lock = true;
  2749. this._mdf = false;
  2750. var finalValue = this.kf ? this.pv : this.data.ks ? this.data.ks.k : this.data.pt.k;
  2751. var i, len = this.effectsSequence.length;
  2752. for(i = 0; i < len; i += 1) {
  2753. finalValue = this.effectsSequence[i](finalValue);
  2754. }
  2755. this.setVValue(finalValue);
  2756. this.lock = false;
  2757. this.frameId = this.elem.globalData.frameId;
  2758. };
  2759. function ShapeProperty(elem, data, type){
  2760. this.propType = 'shape';
  2761. this.comp = elem.comp;
  2762. this.container = elem;
  2763. this.elem = elem;
  2764. this.data = data;
  2765. this.k = false;
  2766. this.kf = false;
  2767. this._mdf = false;
  2768. var pathData = type === 3 ? data.pt.k : data.ks.k;
  2769. this.v = shape_pool.clone(pathData);
  2770. this.pv = shape_pool.clone(this.v);
  2771. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2772. this.paths = this.localShapeCollection;
  2773. this.paths.addShape(this.v);
  2774. this.reset = resetShape;
  2775. this.effectsSequence = [];
  2776. }
  2777. function addEffect(effectFunction) {
  2778. this.effectsSequence.push(effectFunction);
  2779. this.container.addDynamicProperty(this);
  2780. }
  2781. ShapeProperty.prototype.interpolateShape = interpolateShape;
  2782. ShapeProperty.prototype.getValue = processEffectsSequence;
  2783. ShapeProperty.prototype.setVValue = setVValue;
  2784. ShapeProperty.prototype.addEffect = addEffect;
  2785. function KeyframedShapeProperty(elem,data,type){
  2786. this.propType = 'shape';
  2787. this.comp = elem.comp;
  2788. this.elem = elem;
  2789. this.container = elem;
  2790. this.offsetTime = elem.data.st;
  2791. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  2792. this.k = true;
  2793. this.kf = true;
  2794. var i, len = this.keyframes[0].s[0].i.length;
  2795. var jLen = this.keyframes[0].s[0].i[0].length;
  2796. this.v = shape_pool.newElement();
  2797. this.v.setPathData(this.keyframes[0].s[0].c, len);
  2798. this.pv = shape_pool.clone(this.v);
  2799. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2800. this.paths = this.localShapeCollection;
  2801. this.paths.addShape(this.v);
  2802. this.lastFrame = initFrame;
  2803. this.reset = resetShape;
  2804. this._caching = {lastFrame: initFrame, lastIndex: 0};
  2805. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  2806. }
  2807. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  2808. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  2809. KeyframedShapeProperty.prototype.setVValue = setVValue;
  2810. KeyframedShapeProperty.prototype.addEffect = addEffect;
  2811. var EllShapeProperty = (function(){
  2812. var cPoint = roundCorner;
  2813. function EllShapeProperty(elem,data) {
  2814. /*this.v = {
  2815. v: createSizedArray(4),
  2816. i: createSizedArray(4),
  2817. o: createSizedArray(4),
  2818. c: true
  2819. };*/
  2820. this.v = shape_pool.newElement();
  2821. this.v.setPathData(true, 4);
  2822. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2823. this.paths = this.localShapeCollection;
  2824. this.localShapeCollection.addShape(this.v);
  2825. this.d = data.d;
  2826. this.elem = elem;
  2827. this.comp = elem.comp;
  2828. this.frameId = -1;
  2829. this.initDynamicPropertyContainer(elem);
  2830. this.p = PropertyFactory.getProp(elem,data.p,1,0,this);
  2831. this.s = PropertyFactory.getProp(elem,data.s,1,0,this);
  2832. if(this.dynamicProperties.length){
  2833. this.k = true;
  2834. }else{
  2835. this.k = false;
  2836. this.convertEllToPath();
  2837. }
  2838. };
  2839. EllShapeProperty.prototype = {
  2840. reset: resetShape,
  2841. getValue: function (){
  2842. if(this.elem.globalData.frameId === this.frameId){
  2843. return;
  2844. }
  2845. this.frameId = this.elem.globalData.frameId;
  2846. this.iterateDynamicProperties();
  2847. if(this._mdf){
  2848. this.convertEllToPath();
  2849. }
  2850. },
  2851. convertEllToPath: function() {
  2852. var p0 = this.p.v[0], p1 = this.p.v[1], s0 = this.s.v[0]/2, s1 = this.s.v[1]/2;
  2853. var _cw = this.d !== 3;
  2854. var _v = this.v;
  2855. _v.v[0][0] = p0;
  2856. _v.v[0][1] = p1 - s1;
  2857. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  2858. _v.v[1][1] = p1;
  2859. _v.v[2][0] = p0;
  2860. _v.v[2][1] = p1 + s1;
  2861. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  2862. _v.v[3][1] = p1;
  2863. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  2864. _v.i[0][1] = p1 - s1;
  2865. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  2866. _v.i[1][1] = p1 - s1 * cPoint;
  2867. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  2868. _v.i[2][1] = p1 + s1;
  2869. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  2870. _v.i[3][1] = p1 + s1 * cPoint;
  2871. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  2872. _v.o[0][1] = p1 - s1;
  2873. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  2874. _v.o[1][1] = p1 + s1 * cPoint;
  2875. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  2876. _v.o[2][1] = p1 + s1;
  2877. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  2878. _v.o[3][1] = p1 - s1 * cPoint;
  2879. }
  2880. }
  2881. extendPrototype([DynamicPropertyContainer], EllShapeProperty);
  2882. return EllShapeProperty;
  2883. }());
  2884. var StarShapeProperty = (function() {
  2885. function StarShapeProperty(elem,data) {
  2886. this.v = shape_pool.newElement();
  2887. this.v.setPathData(true, 0);
  2888. this.elem = elem;
  2889. this.comp = elem.comp;
  2890. this.data = data;
  2891. this.frameId = -1;
  2892. this.d = data.d;
  2893. this.initDynamicPropertyContainer(elem);
  2894. if(data.sy === 1){
  2895. this.ir = PropertyFactory.getProp(elem,data.ir,0,0,this);
  2896. this.is = PropertyFactory.getProp(elem,data.is,0,0.01,this);
  2897. this.convertToPath = this.convertStarToPath;
  2898. } else {
  2899. this.convertToPath = this.convertPolygonToPath;
  2900. }
  2901. this.pt = PropertyFactory.getProp(elem,data.pt,0,0,this);
  2902. this.p = PropertyFactory.getProp(elem,data.p,1,0,this);
  2903. this.r = PropertyFactory.getProp(elem,data.r,0,degToRads,this);
  2904. this.or = PropertyFactory.getProp(elem,data.or,0,0,this);
  2905. this.os = PropertyFactory.getProp(elem,data.os,0,0.01,this);
  2906. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2907. this.localShapeCollection.addShape(this.v);
  2908. this.paths = this.localShapeCollection;
  2909. if(this.dynamicProperties.length){
  2910. this.k = true;
  2911. }else{
  2912. this.k = false;
  2913. this.convertToPath();
  2914. }
  2915. };
  2916. StarShapeProperty.prototype = {
  2917. reset: resetShape,
  2918. getValue: function() {
  2919. if(this.elem.globalData.frameId === this.frameId){
  2920. return;
  2921. }
  2922. this.frameId = this.elem.globalData.frameId;
  2923. this.iterateDynamicProperties();
  2924. if(this._mdf){
  2925. this.convertToPath();
  2926. }
  2927. },
  2928. convertStarToPath: function() {
  2929. var numPts = Math.floor(this.pt.v)*2;
  2930. var angle = Math.PI*2/numPts;
  2931. /*this.v.v.length = numPts;
  2932. this.v.i.length = numPts;
  2933. this.v.o.length = numPts;*/
  2934. var longFlag = true;
  2935. var longRad = this.or.v;
  2936. var shortRad = this.ir.v;
  2937. var longRound = this.os.v;
  2938. var shortRound = this.is.v;
  2939. var longPerimSegment = 2*Math.PI*longRad/(numPts*2);
  2940. var shortPerimSegment = 2*Math.PI*shortRad/(numPts*2);
  2941. var i, rad,roundness,perimSegment, currentAng = -Math.PI/ 2;
  2942. currentAng += this.r.v;
  2943. var dir = this.data.d === 3 ? -1 : 1;
  2944. this.v._length = 0;
  2945. for(i=0;i<numPts;i+=1){
  2946. rad = longFlag ? longRad : shortRad;
  2947. roundness = longFlag ? longRound : shortRound;
  2948. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  2949. var x = rad * Math.cos(currentAng);
  2950. var y = rad * Math.sin(currentAng);
  2951. var ox = x === 0 && y === 0 ? 0 : y/Math.sqrt(x*x + y*y);
  2952. var oy = x === 0 && y === 0 ? 0 : -x/Math.sqrt(x*x + y*y);
  2953. x += + this.p.v[0];
  2954. y += + this.p.v[1];
  2955. 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);
  2956. /*this.v.v[i] = [x,y];
  2957. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  2958. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  2959. this.v._length = numPts;*/
  2960. longFlag = !longFlag;
  2961. currentAng += angle*dir;
  2962. }
  2963. },
  2964. convertPolygonToPath: function() {
  2965. var numPts = Math.floor(this.pt.v);
  2966. var angle = Math.PI*2/numPts;
  2967. var rad = this.or.v;
  2968. var roundness = this.os.v;
  2969. var perimSegment = 2*Math.PI*rad/(numPts*4);
  2970. var i, currentAng = -Math.PI/ 2;
  2971. var dir = this.data.d === 3 ? -1 : 1;
  2972. currentAng += this.r.v;
  2973. this.v._length = 0;
  2974. for(i=0;i<numPts;i+=1){
  2975. var x = rad * Math.cos(currentAng);
  2976. var y = rad * Math.sin(currentAng);
  2977. var ox = x === 0 && y === 0 ? 0 : y/Math.sqrt(x*x + y*y);
  2978. var oy = x === 0 && y === 0 ? 0 : -x/Math.sqrt(x*x + y*y);
  2979. x += + this.p.v[0];
  2980. y += + this.p.v[1];
  2981. 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);
  2982. currentAng += angle*dir;
  2983. }
  2984. this.paths.length = 0;
  2985. this.paths[0] = this.v;
  2986. }
  2987. }
  2988. extendPrototype([DynamicPropertyContainer], StarShapeProperty);
  2989. return StarShapeProperty;
  2990. }());
  2991. var RectShapeProperty = (function() {
  2992. function RectShapeProperty(elem,data) {
  2993. this.v = shape_pool.newElement();
  2994. this.v.c = true;
  2995. this.localShapeCollection = shapeCollection_pool.newShapeCollection();
  2996. this.localShapeCollection.addShape(this.v);
  2997. this.paths = this.localShapeCollection;
  2998. this.elem = elem;
  2999. this.comp = elem.comp;
  3000. this.frameId = -1;
  3001. this.d = data.d;
  3002. this.initDynamicPropertyContainer(elem);
  3003. this.p = PropertyFactory.getProp(elem,data.p,1,0,this);
  3004. this.s = PropertyFactory.getProp(elem,data.s,1,0,this);
  3005. this.r = PropertyFactory.getProp(elem,data.r,0,0,this);
  3006. if(this.dynamicProperties.length){
  3007. this.k = true;
  3008. }else{
  3009. this.k = false;
  3010. this.convertRectToPath();
  3011. }
  3012. };
  3013. RectShapeProperty.prototype = {
  3014. convertRectToPath: function (){
  3015. var p0 = this.p.v[0], p1 = this.p.v[1], v0 = this.s.v[0]/2, v1 = this.s.v[1]/2;
  3016. var round = bm_min(v0,v1,this.r.v);
  3017. var cPoint = round*(1-roundCorner);
  3018. this.v._length = 0;
  3019. if(this.d === 2 || this.d === 1) {
  3020. this.v.setTripleAt(p0+v0, p1-v1+round,p0+v0, p1-v1+round,p0+v0,p1-v1+cPoint,0, true);
  3021. this.v.setTripleAt(p0+v0, p1+v1-round,p0+v0, p1+v1-cPoint,p0+v0, p1+v1-round,1, true);
  3022. if(round!== 0){
  3023. this.v.setTripleAt(p0+v0-round, p1+v1,p0+v0-round,p1+v1,p0+v0-cPoint,p1+v1,2, true);
  3024. this.v.setTripleAt(p0-v0+round,p1+v1,p0-v0+cPoint,p1+v1,p0-v0+round,p1+v1,3, true);
  3025. this.v.setTripleAt(p0-v0,p1+v1-round,p0-v0,p1+v1-round,p0-v0,p1+v1-cPoint,4, true);
  3026. this.v.setTripleAt(p0-v0,p1-v1+round,p0-v0,p1-v1+cPoint,p0-v0,p1-v1+round,5, true);
  3027. this.v.setTripleAt(p0-v0+round,p1-v1,p0-v0+round,p1-v1,p0-v0+cPoint,p1-v1,6, true);
  3028. this.v.setTripleAt(p0+v0-round,p1-v1,p0+v0-cPoint,p1-v1,p0+v0-round,p1-v1,7, true);
  3029. } else {
  3030. this.v.setTripleAt(p0-v0,p1+v1,p0-v0+cPoint,p1+v1,p0-v0,p1+v1,2);
  3031. this.v.setTripleAt(p0-v0,p1-v1,p0-v0,p1-v1+cPoint,p0-v0,p1-v1,3);
  3032. }
  3033. }else{
  3034. this.v.setTripleAt(p0+v0,p1-v1+round,p0+v0,p1-v1+cPoint,p0+v0,p1-v1+round,0, true);
  3035. if(round!== 0){
  3036. this.v.setTripleAt(p0+v0-round,p1-v1,p0+v0-round,p1-v1,p0+v0-cPoint,p1-v1,1, true);
  3037. this.v.setTripleAt(p0-v0+round,p1-v1,p0-v0+cPoint,p1-v1,p0-v0+round,p1-v1,2, true);
  3038. this.v.setTripleAt(p0-v0,p1-v1+round,p0-v0,p1-v1+round,p0-v0,p1-v1+cPoint,3, true);
  3039. this.v.setTripleAt(p0-v0,p1+v1-round,p0-v0,p1+v1-cPoint,p0-v0,p1+v1-round,4, true);
  3040. this.v.setTripleAt(p0-v0+round,p1+v1,p0-v0+round,p1+v1,p0-v0+cPoint,p1+v1,5, true);
  3041. this.v.setTripleAt(p0+v0-round,p1+v1,p0+v0-cPoint,p1+v1,p0+v0-round,p1+v1,6, true);
  3042. this.v.setTripleAt(p0+v0,p1+v1-round,p0+v0,p1+v1-round,p0+v0,p1+v1-cPoint,7, true);
  3043. } else {
  3044. this.v.setTripleAt(p0-v0,p1-v1,p0-v0+cPoint,p1-v1,p0-v0,p1-v1,1, true);
  3045. this.v.setTripleAt(p0-v0,p1+v1,p0-v0,p1+v1-cPoint,p0-v0,p1+v1,2, true);
  3046. this.v.setTripleAt(p0+v0,p1+v1,p0+v0-cPoint,p1+v1,p0+v0,p1+v1,3, true);
  3047. }
  3048. }
  3049. },
  3050. getValue: function(frameNum){
  3051. if(this.elem.globalData.frameId === this.frameId){
  3052. return;
  3053. }
  3054. this.frameId = this.elem.globalData.frameId;
  3055. this.iterateDynamicProperties();
  3056. if(this._mdf){
  3057. this.convertRectToPath();
  3058. }
  3059. },
  3060. reset: resetShape
  3061. }
  3062. extendPrototype([DynamicPropertyContainer], RectShapeProperty);
  3063. return RectShapeProperty;
  3064. }());
  3065. function getShapeProp(elem,data,type){
  3066. var prop;
  3067. if(type === 3 || type === 4){
  3068. var dataProp = type === 3 ? data.pt : data.ks;
  3069. var keys = dataProp.k;
  3070. if(keys.length){
  3071. prop = new KeyframedShapeProperty(elem, data, type);
  3072. }else{
  3073. prop = new ShapeProperty(elem, data, type);
  3074. }
  3075. }else if(type === 5){
  3076. prop = new RectShapeProperty(elem, data);
  3077. }else if(type === 6){
  3078. prop = new EllShapeProperty(elem, data);
  3079. }else if(type === 7){
  3080. prop = new StarShapeProperty(elem, data);
  3081. }
  3082. if(prop.k){
  3083. elem.addDynamicProperty(prop);
  3084. }
  3085. return prop;
  3086. }
  3087. function getConstructorFunction() {
  3088. return ShapeProperty;
  3089. }
  3090. function getKeyframedConstructorFunction() {
  3091. return KeyframedShapeProperty;
  3092. }
  3093. var ob = {};
  3094. ob.getShapeProp = getShapeProp;
  3095. ob.getConstructorFunction = getConstructorFunction;
  3096. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3097. return ob;
  3098. }());
  3099. var ShapeModifiers = (function(){
  3100. var ob = {};
  3101. var modifiers = {};
  3102. ob.registerModifier = registerModifier;
  3103. ob.getModifier = getModifier;
  3104. function registerModifier(nm,factory){
  3105. if(!modifiers[nm]){
  3106. modifiers[nm] = factory;
  3107. }
  3108. }
  3109. function getModifier(nm,elem, data){
  3110. return new modifiers[nm](elem, data);
  3111. }
  3112. return ob;
  3113. }());
  3114. function ShapeModifier(){}
  3115. ShapeModifier.prototype.initModifierProperties = function(){};
  3116. ShapeModifier.prototype.addShapeToModifier = function(){};
  3117. ShapeModifier.prototype.addShape = function(data){
  3118. if (!this.closed) {
  3119. // Adding shape to dynamic properties. It covers the case where a shape has no effects applied, to reset it's _mdf state on every tick.
  3120. data.sh.container.addDynamicProperty(data.sh);
  3121. var shapeData = {shape:data.sh, data: data, localShapeCollection:shapeCollection_pool.newShapeCollection()};
  3122. this.shapes.push(shapeData);
  3123. this.addShapeToModifier(shapeData);
  3124. if (this._isAnimated) {
  3125. data.setAsAnimated();
  3126. }
  3127. }
  3128. };
  3129. ShapeModifier.prototype.init = function(elem,data){
  3130. this.shapes = [];
  3131. this.elem = elem;
  3132. this.initDynamicPropertyContainer(elem);
  3133. this.initModifierProperties(elem,data);
  3134. this.frameId = initialDefaultFrame;
  3135. this.closed = false;
  3136. this.k = false;
  3137. if(this.dynamicProperties.length){
  3138. this.k = true;
  3139. }else{
  3140. this.getValue(true);
  3141. }
  3142. };
  3143. ShapeModifier.prototype.processKeys = function(){
  3144. if(this.elem.globalData.frameId === this.frameId){
  3145. return;
  3146. }
  3147. this.frameId = this.elem.globalData.frameId;
  3148. this.iterateDynamicProperties();
  3149. };
  3150. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  3151. function TrimModifier(){
  3152. }
  3153. extendPrototype([ShapeModifier], TrimModifier);
  3154. TrimModifier.prototype.initModifierProperties = function(elem, data) {
  3155. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  3156. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  3157. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  3158. this.sValue = 0;
  3159. this.eValue = 0;
  3160. this.getValue = this.processKeys;
  3161. this.m = data.m;
  3162. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  3163. };
  3164. TrimModifier.prototype.addShapeToModifier = function(shapeData){
  3165. shapeData.pathsData = [];
  3166. };
  3167. TrimModifier.prototype.calculateShapeEdges = function(s, e, shapeLength, addedLength, totalModifierLength) {
  3168. var segments = [];
  3169. if (e <= 1) {
  3170. segments.push({
  3171. s: s,
  3172. e: e
  3173. });
  3174. } else if (s >= 1) {
  3175. segments.push({
  3176. s: s - 1,
  3177. e: e - 1
  3178. });
  3179. } else {
  3180. segments.push({
  3181. s: s,
  3182. e: 1
  3183. });
  3184. segments.push({
  3185. s: 0,
  3186. e: e - 1
  3187. });
  3188. }
  3189. var shapeSegments = [];
  3190. var i, len = segments.length, segmentOb;
  3191. for (i = 0; i < len; i += 1) {
  3192. segmentOb = segments[i];
  3193. if (segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength) {
  3194. } else {
  3195. var shapeS, shapeE;
  3196. if (segmentOb.s * totalModifierLength <= addedLength) {
  3197. shapeS = 0;
  3198. } else {
  3199. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  3200. }
  3201. if(segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  3202. shapeE = 1;
  3203. } else {
  3204. shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength);
  3205. }
  3206. shapeSegments.push([shapeS, shapeE]);
  3207. }
  3208. }
  3209. if (!shapeSegments.length) {
  3210. shapeSegments.push([0, 0]);
  3211. }
  3212. return shapeSegments;
  3213. };
  3214. TrimModifier.prototype.releasePathsData = function(pathsData) {
  3215. var i, len = pathsData.length;
  3216. for (i = 0; i < len; i += 1) {
  3217. segments_length_pool.release(pathsData[i]);
  3218. }
  3219. pathsData.length = 0;
  3220. return pathsData;
  3221. };
  3222. TrimModifier.prototype.processShapes = function(_isFirstFrame) {
  3223. var s, e;
  3224. if (this._mdf || _isFirstFrame) {
  3225. var o = (this.o.v % 360) / 360;
  3226. if (o < 0) {
  3227. o += 1;
  3228. }
  3229. s = (this.s.v > 1 ? 1 : this.s.v < 0 ? 0 : this.s.v) + o;
  3230. e = (this.e.v > 1 ? 1 : this.e.v < 0 ? 0 : this.e.v) + o;
  3231. if (s === e) {
  3232. }
  3233. if (s > e) {
  3234. var _s = s;
  3235. s = e;
  3236. e = _s;
  3237. }
  3238. s = Math.round(s * 10000) * 0.0001;
  3239. e = Math.round(e * 10000) * 0.0001;
  3240. this.sValue = s;
  3241. this.eValue = e;
  3242. } else {
  3243. s = this.sValue;
  3244. e = this.eValue;
  3245. }
  3246. var shapePaths;
  3247. var i, len = this.shapes.length, j, jLen;
  3248. var pathsData, pathData, totalShapeLength, totalModifierLength = 0;
  3249. if (e === s) {
  3250. for (i = 0; i < len; i += 1) {
  3251. this.shapes[i].localShapeCollection.releaseShapes();
  3252. this.shapes[i].shape._mdf = true;
  3253. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  3254. if (this._mdf) {
  3255. this.shapes[i].pathsData.length = 0;
  3256. }
  3257. }
  3258. } else if (!((e === 1 && s === 0) || (e===0 && s === 1))){
  3259. var segments = [], shapeData, localShapeCollection;
  3260. for (i = 0; i < len; i += 1) {
  3261. shapeData = this.shapes[i];
  3262. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  3263. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  3264. shapeData.shape.paths = shapeData.localShapeCollection;
  3265. } else {
  3266. shapePaths = shapeData.shape.paths;
  3267. jLen = shapePaths._length;
  3268. totalShapeLength = 0;
  3269. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  3270. totalShapeLength = shapeData.totalShapeLength;
  3271. } else {
  3272. pathsData = this.releasePathsData(shapeData.pathsData);
  3273. for (j = 0; j < jLen; j += 1) {
  3274. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  3275. pathsData.push(pathData);
  3276. totalShapeLength += pathData.totalLength;
  3277. }
  3278. shapeData.totalShapeLength = totalShapeLength;
  3279. shapeData.pathsData = pathsData;
  3280. }
  3281. totalModifierLength += totalShapeLength;
  3282. shapeData.shape._mdf = true;
  3283. }
  3284. }
  3285. var shapeS = s, shapeE = e, addedLength = 0, edges;
  3286. for (i = len - 1; i >= 0; i -= 1) {
  3287. shapeData = this.shapes[i];
  3288. if (shapeData.shape._mdf) {
  3289. localShapeCollection = shapeData.localShapeCollection;
  3290. localShapeCollection.releaseShapes();
  3291. //if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  3292. if (this.m === 2 && len > 1) {
  3293. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  3294. addedLength += shapeData.totalShapeLength;
  3295. } else {
  3296. edges = [[shapeS, shapeE]];
  3297. }
  3298. jLen = edges.length;
  3299. for (j = 0; j < jLen; j += 1) {
  3300. shapeS = edges[j][0];
  3301. shapeE = edges[j][1];
  3302. segments.length = 0;
  3303. if (shapeE <= 1) {
  3304. segments.push({
  3305. s:shapeData.totalShapeLength * shapeS,
  3306. e:shapeData.totalShapeLength * shapeE
  3307. });
  3308. } else if (shapeS >= 1) {
  3309. segments.push({
  3310. s:shapeData.totalShapeLength * (shapeS - 1),
  3311. e:shapeData.totalShapeLength * (shapeE - 1)
  3312. });
  3313. } else {
  3314. segments.push({
  3315. s:shapeData.totalShapeLength * shapeS,
  3316. e:shapeData.totalShapeLength
  3317. });
  3318. segments.push({
  3319. s:0,
  3320. e:shapeData.totalShapeLength * (shapeE - 1)
  3321. });
  3322. }
  3323. var newShapesData = this.addShapes(shapeData,segments[0]);
  3324. if (segments[0].s !== segments[0].e) {
  3325. if (segments.length > 1) {
  3326. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  3327. if (lastShapeInCollection.c) {
  3328. var lastShape = newShapesData.pop();
  3329. this.addPaths(newShapesData, localShapeCollection);
  3330. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  3331. } else {
  3332. this.addPaths(newShapesData, localShapeCollection);
  3333. newShapesData = this.addShapes(shapeData, segments[1]);
  3334. }
  3335. }
  3336. this.addPaths(newShapesData, localShapeCollection);
  3337. }
  3338. }
  3339. shapeData.shape.paths = localShapeCollection;
  3340. }
  3341. }
  3342. } else if (this._mdf) {
  3343. for (i = 0; i < len; i += 1) {
  3344. //Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  3345. //Don't remove this even if it's losing cached info.
  3346. this.shapes[i].pathsData.length = 0;
  3347. this.shapes[i].shape._mdf = true;
  3348. }
  3349. }
  3350. };
  3351. TrimModifier.prototype.addPaths = function(newPaths, localShapeCollection) {
  3352. var i, len = newPaths.length;
  3353. for (i = 0; i < len; i += 1) {
  3354. localShapeCollection.addShape(newPaths[i]);
  3355. }
  3356. };
  3357. TrimModifier.prototype.addSegment = function(pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  3358. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  3359. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  3360. if(newShape){
  3361. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  3362. }
  3363. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  3364. };
  3365. TrimModifier.prototype.addSegmentFromArray = function(points, shapePath, pos, newShape) {
  3366. shapePath.setXYAt(points[1], points[5], 'o', pos);
  3367. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  3368. if(newShape){
  3369. shapePath.setXYAt(points[0], points[4], 'v', pos);
  3370. }
  3371. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  3372. };
  3373. TrimModifier.prototype.addShapes = function(shapeData, shapeSegment, shapePath) {
  3374. var pathsData = shapeData.pathsData;
  3375. var shapePaths = shapeData.shape.paths.shapes;
  3376. var i, len = shapeData.shape.paths._length, j, jLen;
  3377. var addedLength = 0;
  3378. var currentLengthData,segmentCount;
  3379. var lengths;
  3380. var segment;
  3381. var shapes = [];
  3382. var initPos;
  3383. var newShape = true;
  3384. if (!shapePath) {
  3385. shapePath = shape_pool.newElement();
  3386. segmentCount = 0;
  3387. initPos = 0;
  3388. } else {
  3389. segmentCount = shapePath._length;
  3390. initPos = shapePath._length;
  3391. }
  3392. shapes.push(shapePath);
  3393. for (i = 0; i < len; i += 1) {
  3394. lengths = pathsData[i].lengths;
  3395. shapePath.c = shapePaths[i].c;
  3396. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  3397. for (j = 1; j < jLen; j +=1) {
  3398. currentLengthData = lengths[j-1];
  3399. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  3400. addedLength += currentLengthData.addedLength;
  3401. shapePath.c = false;
  3402. } else if(addedLength > shapeSegment.e) {
  3403. shapePath.c = false;
  3404. break;
  3405. } else {
  3406. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  3407. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  3408. newShape = false;
  3409. } else {
  3410. 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]);
  3411. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  3412. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  3413. newShape = false;
  3414. shapePath.c = false;
  3415. }
  3416. addedLength += currentLengthData.addedLength;
  3417. segmentCount += 1;
  3418. }
  3419. }
  3420. if (shapePaths[i].c && lengths.length) {
  3421. currentLengthData = lengths[j - 1];
  3422. if (addedLength <= shapeSegment.e) {
  3423. var segmentLength = lengths[j - 1].addedLength;
  3424. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  3425. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  3426. newShape = false;
  3427. } else {
  3428. 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]);
  3429. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  3430. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  3431. newShape = false;
  3432. shapePath.c = false;
  3433. }
  3434. } else {
  3435. shapePath.c = false;
  3436. }
  3437. addedLength += currentLengthData.addedLength;
  3438. segmentCount += 1;
  3439. }
  3440. if (shapePath._length) {
  3441. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  3442. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1],'o', shapePath._length - 1);
  3443. }
  3444. if (addedLength > shapeSegment.e) {
  3445. break;
  3446. }
  3447. if (i < len - 1) {
  3448. shapePath = shape_pool.newElement();
  3449. newShape = true;
  3450. shapes.push(shapePath);
  3451. segmentCount = 0;
  3452. }
  3453. }
  3454. return shapes;
  3455. };
  3456. ShapeModifiers.registerModifier('tm', TrimModifier);
  3457. function RoundCornersModifier(){}
  3458. extendPrototype([ShapeModifier],RoundCornersModifier);
  3459. RoundCornersModifier.prototype.initModifierProperties = function(elem,data){
  3460. this.getValue = this.processKeys;
  3461. this.rd = PropertyFactory.getProp(elem,data.r,0,null,this);
  3462. this._isAnimated = !!this.rd.effectsSequence.length;
  3463. };
  3464. RoundCornersModifier.prototype.processPath = function(path, round){
  3465. var cloned_path = shape_pool.newElement();
  3466. cloned_path.c = path.c;
  3467. var i, len = path._length;
  3468. var currentV,currentI,currentO,closerV, newV,newO,newI,distance,newPosPerc,index = 0;
  3469. var vX,vY,oX,oY,iX,iY;
  3470. for(i=0;i<len;i+=1){
  3471. currentV = path.v[i];
  3472. currentO = path.o[i];
  3473. currentI = path.i[i];
  3474. if(currentV[0]===currentO[0] && currentV[1]===currentO[1] && currentV[0]===currentI[0] && currentV[1]===currentI[1]){
  3475. if((i===0 || i === len - 1) && !path.c){
  3476. cloned_path.setTripleAt(currentV[0],currentV[1],currentO[0],currentO[1],currentI[0],currentI[1],index);
  3477. /*cloned_path.v[index] = currentV;
  3478. cloned_path.o[index] = currentO;
  3479. cloned_path.i[index] = currentI;*/
  3480. index += 1;
  3481. } else {
  3482. if(i===0){
  3483. closerV = path.v[len-1];
  3484. } else {
  3485. closerV = path.v[i-1];
  3486. }
  3487. distance = Math.sqrt(Math.pow(currentV[0]-closerV[0],2)+Math.pow(currentV[1]-closerV[1],2));
  3488. newPosPerc = distance ? Math.min(distance/2,round)/distance : 0;
  3489. vX = iX = currentV[0]+(closerV[0]-currentV[0])*newPosPerc;
  3490. vY = iY = currentV[1]-(currentV[1]-closerV[1])*newPosPerc;
  3491. oX = vX-(vX-currentV[0])*roundCorner;
  3492. oY = vY-(vY-currentV[1])*roundCorner;
  3493. cloned_path.setTripleAt(vX,vY,oX,oY,iX,iY,index);
  3494. index += 1;
  3495. if(i === len - 1){
  3496. closerV = path.v[0];
  3497. } else {
  3498. closerV = path.v[i+1];
  3499. }
  3500. distance = Math.sqrt(Math.pow(currentV[0]-closerV[0],2)+Math.pow(currentV[1]-closerV[1],2));
  3501. newPosPerc = distance ? Math.min(distance/2,round)/distance : 0;
  3502. vX = oX = currentV[0]+(closerV[0]-currentV[0])*newPosPerc;
  3503. vY = oY = currentV[1]+(closerV[1]-currentV[1])*newPosPerc;
  3504. iX = vX-(vX-currentV[0])*roundCorner;
  3505. iY = vY-(vY-currentV[1])*roundCorner;
  3506. cloned_path.setTripleAt(vX,vY,oX,oY,iX,iY,index);
  3507. index += 1;
  3508. }
  3509. } else {
  3510. 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);
  3511. index += 1;
  3512. }
  3513. }
  3514. return cloned_path;
  3515. };
  3516. RoundCornersModifier.prototype.processShapes = function(_isFirstFrame){
  3517. var shapePaths;
  3518. var i, len = this.shapes.length;
  3519. var j, jLen;
  3520. var rd = this.rd.v;
  3521. if(rd !== 0){
  3522. var shapeData, newPaths, localShapeCollection;
  3523. for(i=0;i<len;i+=1){
  3524. shapeData = this.shapes[i];
  3525. newPaths = shapeData.shape.paths;
  3526. localShapeCollection = shapeData.localShapeCollection;
  3527. if(!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)){
  3528. localShapeCollection.releaseShapes();
  3529. shapeData.shape._mdf = true;
  3530. shapePaths = shapeData.shape.paths.shapes;
  3531. jLen = shapeData.shape.paths._length;
  3532. for(j=0;j<jLen;j+=1){
  3533. localShapeCollection.addShape(this.processPath(shapePaths[j],rd));
  3534. }
  3535. }
  3536. shapeData.shape.paths = shapeData.localShapeCollection;
  3537. }
  3538. }
  3539. if(!this.dynamicProperties.length){
  3540. this._mdf = false;
  3541. }
  3542. };
  3543. ShapeModifiers.registerModifier('rd',RoundCornersModifier);
  3544. function PuckerAndBloatModifier(){}
  3545. extendPrototype([ShapeModifier],PuckerAndBloatModifier);
  3546. PuckerAndBloatModifier.prototype.initModifierProperties = function(elem,data){
  3547. this.getValue = this.processKeys;
  3548. this.amount = PropertyFactory.getProp(elem,data.a,0,null,this);
  3549. this._isAnimated = !!this.amount.effectsSequence.length;
  3550. };
  3551. PuckerAndBloatModifier.prototype.processPath = function(path, amount){
  3552. var percent = amount / 100;
  3553. var centerPoint = [0, 0];
  3554. var pathLength = path._length, i = 0;
  3555. for (i = 0; i < pathLength; i += 1) {
  3556. centerPoint[0] += path.v[i][0];
  3557. centerPoint[1] += path.v[i][1];
  3558. }
  3559. centerPoint[0] /= pathLength;
  3560. centerPoint[1] /= pathLength;
  3561. var cloned_path = shape_pool.newElement();
  3562. cloned_path.c = path.c;
  3563. var vX, vY, oX, oY, iX, iY;
  3564. for(i = 0; i < pathLength; i += 1) {
  3565. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  3566. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  3567. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  3568. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  3569. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  3570. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  3571. cloned_path.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  3572. }
  3573. return cloned_path;
  3574. };
  3575. PuckerAndBloatModifier.prototype.processShapes = function(_isFirstFrame){
  3576. var shapePaths;
  3577. var i, len = this.shapes.length;
  3578. var j, jLen;
  3579. var amount = this.amount.v;
  3580. if(amount !== 0){
  3581. var shapeData, newPaths, localShapeCollection;
  3582. for(i=0;i<len;i+=1){
  3583. shapeData = this.shapes[i];
  3584. newPaths = shapeData.shape.paths;
  3585. localShapeCollection = shapeData.localShapeCollection;
  3586. if(!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)){
  3587. localShapeCollection.releaseShapes();
  3588. shapeData.shape._mdf = true;
  3589. shapePaths = shapeData.shape.paths.shapes;
  3590. jLen = shapeData.shape.paths._length;
  3591. for(j=0;j<jLen;j+=1){
  3592. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  3593. }
  3594. }
  3595. shapeData.shape.paths = shapeData.localShapeCollection;
  3596. }
  3597. }
  3598. if(!this.dynamicProperties.length){
  3599. this._mdf = false;
  3600. }
  3601. };
  3602. ShapeModifiers.registerModifier('pb',PuckerAndBloatModifier);
  3603. function RepeaterModifier(){}
  3604. extendPrototype([ShapeModifier], RepeaterModifier);
  3605. RepeaterModifier.prototype.initModifierProperties = function(elem,data){
  3606. this.getValue = this.processKeys;
  3607. this.c = PropertyFactory.getProp(elem,data.c,0,null,this);
  3608. this.o = PropertyFactory.getProp(elem,data.o,0,null,this);
  3609. this.tr = TransformPropertyFactory.getTransformProperty(elem,data.tr,this);
  3610. this.so = PropertyFactory.getProp(elem,data.tr.so,0,0.01,this);
  3611. this.eo = PropertyFactory.getProp(elem,data.tr.eo,0,0.01,this);
  3612. this.data = data;
  3613. if(!this.dynamicProperties.length){
  3614. this.getValue(true);
  3615. }
  3616. this._isAnimated = !!this.dynamicProperties.length;
  3617. this.pMatrix = new Matrix();
  3618. this.rMatrix = new Matrix();
  3619. this.sMatrix = new Matrix();
  3620. this.tMatrix = new Matrix();
  3621. this.matrix = new Matrix();
  3622. };
  3623. RepeaterModifier.prototype.applyTransforms = function(pMatrix, rMatrix, sMatrix, transform, perc, inv){
  3624. var dir = inv ? -1 : 1;
  3625. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  3626. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  3627. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  3628. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  3629. rMatrix.rotate(-transform.r.v * dir * perc);
  3630. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  3631. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  3632. sMatrix.scale(inv ? 1/scaleX : scaleX, inv ? 1/scaleY : scaleY);
  3633. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  3634. };
  3635. RepeaterModifier.prototype.init = function(elem, arr, pos, elemsData) {
  3636. this.elem = elem;
  3637. this.arr = arr;
  3638. this.pos = pos;
  3639. this.elemsData = elemsData;
  3640. this._currentCopies = 0;
  3641. this._elements = [];
  3642. this._groups = [];
  3643. this.frameId = -1;
  3644. this.initDynamicPropertyContainer(elem);
  3645. this.initModifierProperties(elem,arr[pos]);
  3646. var cont = 0;
  3647. while(pos>0){
  3648. pos -= 1;
  3649. //this._elements.unshift(arr.splice(pos,1)[0]);
  3650. this._elements.unshift(arr[pos]);
  3651. cont += 1;
  3652. }
  3653. if(this.dynamicProperties.length){
  3654. this.k = true;
  3655. }else{
  3656. this.getValue(true);
  3657. }
  3658. };
  3659. RepeaterModifier.prototype.resetElements = function(elements){
  3660. var i, len = elements.length;
  3661. for(i = 0; i < len; i += 1) {
  3662. elements[i]._processed = false;
  3663. if(elements[i].ty === 'gr'){
  3664. this.resetElements(elements[i].it);
  3665. }
  3666. }
  3667. };
  3668. RepeaterModifier.prototype.cloneElements = function(elements){
  3669. var i, len = elements.length;
  3670. var newElements = JSON.parse(JSON.stringify(elements));
  3671. this.resetElements(newElements);
  3672. return newElements;
  3673. };
  3674. RepeaterModifier.prototype.changeGroupRender = function(elements, renderFlag) {
  3675. var i, len = elements.length;
  3676. for(i = 0; i < len; i += 1) {
  3677. elements[i]._render = renderFlag;
  3678. if(elements[i].ty === 'gr') {
  3679. this.changeGroupRender(elements[i].it, renderFlag);
  3680. }
  3681. }
  3682. };
  3683. RepeaterModifier.prototype.processShapes = function(_isFirstFrame) {
  3684. var items, itemsTransform, i, dir, cont;
  3685. if(this._mdf || _isFirstFrame){
  3686. var copies = Math.ceil(this.c.v);
  3687. if(this._groups.length < copies){
  3688. while(this._groups.length < copies){
  3689. var group = {
  3690. it:this.cloneElements(this._elements),
  3691. ty:'gr'
  3692. };
  3693. 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"});
  3694. this.arr.splice(0,0,group);
  3695. this._groups.splice(0,0,group);
  3696. this._currentCopies += 1;
  3697. }
  3698. this.elem.reloadShapes();
  3699. }
  3700. cont = 0;
  3701. var renderFlag;
  3702. for(i = 0; i <= this._groups.length - 1; i += 1){
  3703. renderFlag = cont < copies;
  3704. this._groups[i]._render = renderFlag;
  3705. this.changeGroupRender(this._groups[i].it, renderFlag);
  3706. cont += 1;
  3707. }
  3708. this._currentCopies = copies;
  3709. ////
  3710. var offset = this.o.v;
  3711. var offsetModulo = offset%1;
  3712. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  3713. var k;
  3714. var tMat = this.tr.v.props;
  3715. var pProps = this.pMatrix.props;
  3716. var rProps = this.rMatrix.props;
  3717. var sProps = this.sMatrix.props;
  3718. this.pMatrix.reset();
  3719. this.rMatrix.reset();
  3720. this.sMatrix.reset();
  3721. this.tMatrix.reset();
  3722. this.matrix.reset();
  3723. var iteration = 0;
  3724. if(offset > 0) {
  3725. while(iteration<roundOffset){
  3726. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  3727. iteration += 1;
  3728. }
  3729. if(offsetModulo){
  3730. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  3731. iteration += offsetModulo;
  3732. }
  3733. } else if(offset < 0) {
  3734. while(iteration>roundOffset){
  3735. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  3736. iteration -= 1;
  3737. }
  3738. if(offsetModulo){
  3739. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, - offsetModulo, true);
  3740. iteration -= offsetModulo;
  3741. }
  3742. }
  3743. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  3744. dir = this.data.m === 1 ? 1 : -1;
  3745. cont = this._currentCopies;
  3746. var j, jLen;
  3747. while(cont){
  3748. items = this.elemsData[i].it;
  3749. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  3750. jLen = itemsTransform.length;
  3751. items[items.length - 1].transform.mProps._mdf = true;
  3752. items[items.length - 1].transform.op._mdf = true;
  3753. items[items.length - 1].transform.op.v = this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  3754. if(iteration !== 0){
  3755. if((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)){
  3756. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  3757. }
  3758. 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]);
  3759. 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]);
  3760. 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]);
  3761. for(j=0;j<jLen;j+=1) {
  3762. itemsTransform[j] = this.matrix.props[j];
  3763. }
  3764. this.matrix.reset();
  3765. } else {
  3766. this.matrix.reset();
  3767. for(j=0;j<jLen;j+=1) {
  3768. itemsTransform[j] = this.matrix.props[j];
  3769. }
  3770. }
  3771. iteration += 1;
  3772. cont -= 1;
  3773. i += dir;
  3774. }
  3775. } else {
  3776. cont = this._currentCopies;
  3777. i = 0;
  3778. dir = 1;
  3779. while(cont){
  3780. items = this.elemsData[i].it;
  3781. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  3782. items[items.length - 1].transform.mProps._mdf = false;
  3783. items[items.length - 1].transform.op._mdf = false;
  3784. cont -= 1;
  3785. i += dir;
  3786. }
  3787. }
  3788. };
  3789. RepeaterModifier.prototype.addShape = function(){};
  3790. ShapeModifiers.registerModifier('rp',RepeaterModifier);
  3791. function ShapeCollection(){
  3792. this._length = 0;
  3793. this._maxLength = 4;
  3794. this.shapes = createSizedArray(this._maxLength);
  3795. }
  3796. ShapeCollection.prototype.addShape = function(shapeData){
  3797. if(this._length === this._maxLength){
  3798. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3799. this._maxLength *= 2;
  3800. }
  3801. this.shapes[this._length] = shapeData;
  3802. this._length += 1;
  3803. };
  3804. ShapeCollection.prototype.releaseShapes = function(){
  3805. var i;
  3806. for(i = 0; i < this._length; i += 1) {
  3807. shape_pool.release(this.shapes[i]);
  3808. }
  3809. this._length = 0;
  3810. };
  3811. function DashProperty(elem, data, renderer, container) {
  3812. this.elem = elem;
  3813. this.frameId = -1;
  3814. this.dataProps = createSizedArray(data.length);
  3815. this.renderer = renderer;
  3816. this.k = false;
  3817. this.dashStr = '';
  3818. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  3819. this.dashoffset = createTypedArray('float32', 1);
  3820. this.initDynamicPropertyContainer(container);
  3821. var i, len = data.length || 0, prop;
  3822. for(i = 0; i < len; i += 1) {
  3823. prop = PropertyFactory.getProp(elem,data[i].v,0, 0, this);
  3824. this.k = prop.k || this.k;
  3825. this.dataProps[i] = {n:data[i].n,p:prop};
  3826. }
  3827. if(!this.k){
  3828. this.getValue(true);
  3829. }
  3830. this._isAnimated = this.k;
  3831. }
  3832. DashProperty.prototype.getValue = function(forceRender) {
  3833. if(this.elem.globalData.frameId === this.frameId && !forceRender){
  3834. return;
  3835. }
  3836. this.frameId = this.elem.globalData.frameId;
  3837. this.iterateDynamicProperties();
  3838. this._mdf = this._mdf || forceRender;
  3839. if (this._mdf) {
  3840. var i = 0, len = this.dataProps.length;
  3841. if(this.renderer === 'svg') {
  3842. this.dashStr = '';
  3843. }
  3844. for(i=0;i<len;i+=1){
  3845. if(this.dataProps[i].n != 'o'){
  3846. if(this.renderer === 'svg') {
  3847. this.dashStr += ' ' + this.dataProps[i].p.v;
  3848. }else{
  3849. this.dashArray[i] = this.dataProps[i].p.v;
  3850. }
  3851. }else{
  3852. this.dashoffset[0] = this.dataProps[i].p.v;
  3853. }
  3854. }
  3855. }
  3856. };
  3857. extendPrototype([DynamicPropertyContainer], DashProperty);
  3858. function GradientProperty(elem,data,container){
  3859. this.data = data;
  3860. this.c = createTypedArray('uint8c', data.p*4);
  3861. var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p*4) : data.k.k.length - data.p*4;
  3862. this.o = createTypedArray('float32', cLength);
  3863. this._cmdf = false;
  3864. this._omdf = false;
  3865. this._collapsable = this.checkCollapsable();
  3866. this._hasOpacity = cLength;
  3867. this.initDynamicPropertyContainer(container);
  3868. this.prop = PropertyFactory.getProp(elem,data.k,1,null,this);
  3869. this.k = this.prop.k;
  3870. this.getValue(true);
  3871. }
  3872. GradientProperty.prototype.comparePoints = function(values, points) {
  3873. var i = 0, len = this.o.length/2, diff;
  3874. while(i < len) {
  3875. diff = Math.abs(values[i*4] - values[points*4 + i*2]);
  3876. if(diff > 0.01){
  3877. return false;
  3878. }
  3879. i += 1;
  3880. }
  3881. return true;
  3882. };
  3883. GradientProperty.prototype.checkCollapsable = function() {
  3884. if (this.o.length/2 !== this.c.length/4) {
  3885. return false;
  3886. }
  3887. if (this.data.k.k[0].s) {
  3888. var i = 0, len = this.data.k.k.length;
  3889. while (i < len) {
  3890. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  3891. return false;
  3892. }
  3893. i += 1;
  3894. }
  3895. } else if(!this.comparePoints(this.data.k.k, this.data.p)) {
  3896. return false;
  3897. }
  3898. return true;
  3899. };
  3900. GradientProperty.prototype.getValue = function(forceRender){
  3901. this.prop.getValue();
  3902. this._mdf = false;
  3903. this._cmdf = false;
  3904. this._omdf = false;
  3905. if(this.prop._mdf || forceRender){
  3906. var i, len = this.data.p*4;
  3907. var mult, val;
  3908. for(i=0;i<len;i+=1){
  3909. mult = i%4 === 0 ? 100 : 255;
  3910. val = Math.round(this.prop.v[i]*mult);
  3911. if(this.c[i] !== val){
  3912. this.c[i] = val;
  3913. this._cmdf = !forceRender;
  3914. }
  3915. }
  3916. if(this.o.length){
  3917. len = this.prop.v.length;
  3918. for(i=this.data.p*4;i<len;i+=1){
  3919. mult = i%2 === 0 ? 100 : 1;
  3920. val = i%2 === 0 ? Math.round(this.prop.v[i]*100):this.prop.v[i];
  3921. if(this.o[i-this.data.p*4] !== val){
  3922. this.o[i-this.data.p*4] = val;
  3923. this._omdf = !forceRender;
  3924. }
  3925. }
  3926. }
  3927. this._mdf = !forceRender;
  3928. }
  3929. };
  3930. extendPrototype([DynamicPropertyContainer], GradientProperty);
  3931. var buildShapeString = function(pathNodes, length, closed, mat) {
  3932. if(length === 0) {
  3933. return '';
  3934. }
  3935. var _o = pathNodes.o;
  3936. var _i = pathNodes.i;
  3937. var _v = pathNodes.v;
  3938. var i, shapeString = " M" + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  3939. for(i = 1; i < length; i += 1) {
  3940. 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]);
  3941. }
  3942. if (closed && length) {
  3943. 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]);
  3944. shapeString += 'z';
  3945. }
  3946. return shapeString;
  3947. }
  3948. var audioControllerFactory = (function() {
  3949. function AudioController(audioFactory) {
  3950. this.audios = [];
  3951. this.audioFactory = audioFactory;
  3952. this._volume = 1;
  3953. this._isMuted = false;
  3954. }
  3955. AudioController.prototype = {
  3956. addAudio: function(audio) {
  3957. this.audios.push(audio);
  3958. },
  3959. pause: function() {
  3960. var i, len = this.audios.length;
  3961. for(i = 0; i < len; i += 1) {
  3962. this.audios[i].pause()
  3963. }
  3964. },
  3965. resume: function() {
  3966. var i, len = this.audios.length;
  3967. for(i = 0; i < len; i += 1) {
  3968. this.audios[i].resume()
  3969. }
  3970. },
  3971. setRate: function(rateValue) {
  3972. var i, len = this.audios.length;
  3973. for(i = 0; i < len; i += 1) {
  3974. this.audios[i].setRate(rateValue)
  3975. }
  3976. },
  3977. createAudio: function(assetPath) {
  3978. if (this.audioFactory) {
  3979. return this.audioFactory(assetPath);
  3980. } else if (Howl) {
  3981. return new Howl({
  3982. src: [assetPath]
  3983. })
  3984. } else {
  3985. return {
  3986. isPlaying: false,
  3987. play: function(){this.isPlaying = true},
  3988. seek: function(){this.isPlaying = false},
  3989. playing: function(){},
  3990. rate: function(){},
  3991. setVolume: function(){},
  3992. }
  3993. }
  3994. },
  3995. setAudioFactory: function(audioFactory) {
  3996. this.audioFactory = audioFactory;
  3997. },
  3998. setVolume: function(value) {
  3999. this._volume = value;
  4000. this._updateVolume();
  4001. },
  4002. mute: function() {
  4003. this._isMuted = true;
  4004. this._updateVolume();
  4005. },
  4006. unmute: function() {
  4007. this._isMuted = false;
  4008. this._updateVolume();
  4009. },
  4010. getVolume: function(value) {
  4011. return this._volume;
  4012. },
  4013. _updateVolume: function() {
  4014. var i, len = this.audios.length;
  4015. for(i = 0; i < len; i += 1) {
  4016. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1))
  4017. }
  4018. }
  4019. }
  4020. return function() {
  4021. return new AudioController()
  4022. }
  4023. }())
  4024. var ImagePreloader = (function(){
  4025. var proxyImage = (function(){
  4026. var canvas = createTag('canvas');
  4027. canvas.width = 1;
  4028. canvas.height = 1;
  4029. var ctx = canvas.getContext('2d');
  4030. ctx.fillStyle = 'rgba(0,0,0,0)';
  4031. ctx.fillRect(0, 0, 1, 1);
  4032. return canvas;
  4033. }())
  4034. function imageLoaded(){
  4035. this.loadedAssets += 1;
  4036. if(this.loadedAssets === this.totalImages){
  4037. if(this.imagesLoadedCb) {
  4038. this.imagesLoadedCb(null);
  4039. }
  4040. }
  4041. }
  4042. function getAssetsPath(assetData, assetsPath, original_path) {
  4043. var path = '';
  4044. if (assetData.e) {
  4045. path = assetData.p;
  4046. } else if(assetsPath) {
  4047. var imagePath = assetData.p;
  4048. if (imagePath.indexOf('images/') !== -1) {
  4049. imagePath = imagePath.split('/')[1];
  4050. }
  4051. path = assetsPath + imagePath;
  4052. } else {
  4053. path = original_path;
  4054. path += assetData.u ? assetData.u : '';
  4055. path += assetData.p;
  4056. }
  4057. return path;
  4058. }
  4059. function createImageData(assetData) {
  4060. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  4061. var img = createNS('image');
  4062. img.addEventListener('load', this._imageLoaded, false);
  4063. img.addEventListener('error', function() {
  4064. ob.img = proxyImage;
  4065. this._imageLoaded();
  4066. }.bind(this), false);
  4067. img.setAttributeNS('http://www.w3.org/1999/xlink','href', path);
  4068. var ob = {
  4069. img: img,
  4070. assetData: assetData
  4071. }
  4072. return ob;
  4073. }
  4074. function createImgData(assetData) {
  4075. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  4076. var img = createTag('img');
  4077. img.crossOrigin = 'anonymous';
  4078. img.addEventListener('load', this._imageLoaded, false);
  4079. img.addEventListener('error', function() {
  4080. ob.img = proxyImage;
  4081. this._imageLoaded();
  4082. }.bind(this), false);
  4083. img.src = path;
  4084. var ob = {
  4085. img: img,
  4086. assetData: assetData
  4087. }
  4088. return ob;
  4089. }
  4090. function loadAssets(assets, cb){
  4091. this.imagesLoadedCb = cb;
  4092. var i, len = assets.length;
  4093. for (i = 0; i < len; i += 1) {
  4094. if(!assets[i].layers){
  4095. this.totalImages += 1;
  4096. this.images.push(this._createImageData(assets[i]));
  4097. }
  4098. }
  4099. }
  4100. function setPath(path){
  4101. this.path = path || '';
  4102. }
  4103. function setAssetsPath(path){
  4104. this.assetsPath = path || '';
  4105. }
  4106. function getImage(assetData) {
  4107. var i = 0, len = this.images.length;
  4108. while (i < len) {
  4109. if (this.images[i].assetData === assetData) {
  4110. return this.images[i].img;
  4111. }
  4112. i += 1;
  4113. }
  4114. }
  4115. function destroy() {
  4116. this.imagesLoadedCb = null;
  4117. this.images.length = 0;
  4118. }
  4119. function loaded() {
  4120. return this.totalImages === this.loadedAssets;
  4121. }
  4122. function setCacheType(type) {
  4123. if (type === 'svg') {
  4124. this._createImageData = this.createImageData.bind(this);
  4125. } else {
  4126. this._createImageData = this.createImgData.bind(this);
  4127. }
  4128. }
  4129. function ImagePreloader(type){
  4130. this._imageLoaded = imageLoaded.bind(this);
  4131. this.assetsPath = '';
  4132. this.path = '';
  4133. this.totalImages = 0;
  4134. this.loadedAssets = 0;
  4135. this.imagesLoadedCb = null;
  4136. this.images = [];
  4137. };
  4138. ImagePreloader.prototype = {
  4139. loadAssets: loadAssets,
  4140. setAssetsPath: setAssetsPath,
  4141. setPath: setPath,
  4142. loaded: loaded,
  4143. destroy: destroy,
  4144. getImage: getImage,
  4145. createImgData: createImgData,
  4146. createImageData: createImageData,
  4147. imageLoaded: imageLoaded,
  4148. setCacheType: setCacheType,
  4149. }
  4150. return ImagePreloader;
  4151. }());
  4152. var featureSupport = (function(){
  4153. var ob = {
  4154. maskType: true
  4155. };
  4156. 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)) {
  4157. ob.maskType = false;
  4158. }
  4159. return ob;
  4160. }());
  4161. var filtersFactory = (function(){
  4162. var ob = {};
  4163. ob.createFilter = createFilter;
  4164. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  4165. function createFilter(filId){
  4166. var fil = createNS('filter');
  4167. fil.setAttribute('id',filId);
  4168. fil.setAttribute('filterUnits','objectBoundingBox');
  4169. fil.setAttribute('x','0%');
  4170. fil.setAttribute('y','0%');
  4171. fil.setAttribute('width','100%');
  4172. fil.setAttribute('height','100%');
  4173. return fil;
  4174. }
  4175. function createAlphaToLuminanceFilter(){
  4176. var feColorMatrix = createNS('feColorMatrix');
  4177. feColorMatrix.setAttribute('type','matrix');
  4178. feColorMatrix.setAttribute('color-interpolation-filters','sRGB');
  4179. feColorMatrix.setAttribute('values','0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  4180. return feColorMatrix;
  4181. }
  4182. return ob;
  4183. }());
  4184. var assetLoader = (function(){
  4185. function formatResponse(xhr) {
  4186. if(xhr.response && typeof xhr.response === 'object') {
  4187. return xhr.response;
  4188. } else if(xhr.response && typeof xhr.response === 'string') {
  4189. return JSON.parse(xhr.response);
  4190. } else if(xhr.responseText) {
  4191. return JSON.parse(xhr.responseText);
  4192. }
  4193. }
  4194. function loadAsset(path, callback, errorCallback) {
  4195. var response;
  4196. var xhr = new XMLHttpRequest();
  4197. xhr.open('GET', path, true);
  4198. // set responseType after calling open or IE will break.
  4199. try {
  4200. // This crashes on Android WebView prior to KitKat
  4201. xhr.responseType = "json";
  4202. } catch (err) {}
  4203. xhr.send();
  4204. xhr.onreadystatechange = function () {
  4205. if (xhr.readyState == 4) {
  4206. if(xhr.status == 200){
  4207. response = formatResponse(xhr);
  4208. callback(response);
  4209. }else{
  4210. try{
  4211. response = formatResponse(xhr);
  4212. callback(response);
  4213. }catch(err){
  4214. if(errorCallback) {
  4215. errorCallback(err);
  4216. }
  4217. }
  4218. }
  4219. }
  4220. };
  4221. }
  4222. return {
  4223. load: loadAsset
  4224. }
  4225. }())
  4226. function TextAnimatorProperty(textData, renderType, elem){
  4227. this._isFirstFrame = true;
  4228. this._hasMaskedPath = false;
  4229. this._frameId = -1;
  4230. this._textData = textData;
  4231. this._renderType = renderType;
  4232. this._elem = elem;
  4233. this._animatorsData = createSizedArray(this._textData.a.length);
  4234. this._pathData = {};
  4235. this._moreOptions = {
  4236. alignment: {}
  4237. };
  4238. this.renderedLetters = [];
  4239. this.lettersChangedFlag = false;
  4240. this.initDynamicPropertyContainer(elem);
  4241. }
  4242. TextAnimatorProperty.prototype.searchProperties = function(){
  4243. var i, len = this._textData.a.length, animatorProps;
  4244. var getProp = PropertyFactory.getProp;
  4245. for(i=0;i<len;i+=1){
  4246. animatorProps = this._textData.a[i];
  4247. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  4248. }
  4249. if(this._textData.p && 'm' in this._textData.p){
  4250. this._pathData = {
  4251. f: getProp(this._elem,this._textData.p.f,0,0,this),
  4252. l: getProp(this._elem,this._textData.p.l,0,0,this),
  4253. r: this._textData.p.r,
  4254. m: this._elem.maskManager.getMaskProperty(this._textData.p.m)
  4255. };
  4256. this._hasMaskedPath = true;
  4257. } else {
  4258. this._hasMaskedPath = false;
  4259. }
  4260. this._moreOptions.alignment = getProp(this._elem,this._textData.m.a,1,0,this);
  4261. };
  4262. TextAnimatorProperty.prototype.getMeasures = function(documentData, lettersChangedFlag){
  4263. this.lettersChangedFlag = lettersChangedFlag;
  4264. if(!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  4265. return;
  4266. }
  4267. this._isFirstFrame = false;
  4268. var alignment = this._moreOptions.alignment.v;
  4269. var animators = this._animatorsData;
  4270. var textData = this._textData;
  4271. var matrixHelper = this.mHelper;
  4272. var renderType = this._renderType;
  4273. var renderedLettersCount = this.renderedLetters.length;
  4274. var data = this.data;
  4275. var xPos,yPos;
  4276. var i, len;
  4277. var letters = documentData.l, pathInfo, currentLength, currentPoint, segmentLength, flag, pointInd, segmentInd, prevPoint, points, segments, partialLength, totalLength, perc, tanAngle, mask;
  4278. if(this._hasMaskedPath) {
  4279. mask = this._pathData.m;
  4280. if(!this._pathData.n || this._pathData._mdf){
  4281. var paths = mask.v;
  4282. if(this._pathData.r){
  4283. paths = paths.reverse();
  4284. }
  4285. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  4286. pathInfo = {
  4287. tLength: 0,
  4288. segments: []
  4289. };
  4290. len = paths._length - 1;
  4291. var bezierData;
  4292. totalLength = 0;
  4293. for (i = 0; i < len; i += 1) {
  4294. bezierData = bez.buildBezierData(paths.v[i]
  4295. , paths.v[i + 1]
  4296. , [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]]
  4297. , [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  4298. pathInfo.tLength += bezierData.segmentLength;
  4299. pathInfo.segments.push(bezierData);
  4300. totalLength += bezierData.segmentLength;
  4301. }
  4302. i = len;
  4303. if (mask.v.c) {
  4304. bezierData = bez.buildBezierData(paths.v[i]
  4305. , paths.v[0]
  4306. , [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]]
  4307. , [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  4308. pathInfo.tLength += bezierData.segmentLength;
  4309. pathInfo.segments.push(bezierData);
  4310. totalLength += bezierData.segmentLength;
  4311. }
  4312. this._pathData.pi = pathInfo;
  4313. }
  4314. pathInfo = this._pathData.pi;
  4315. currentLength = this._pathData.f.v;
  4316. segmentInd = 0;
  4317. pointInd = 1;
  4318. segmentLength = 0;
  4319. flag = true;
  4320. segments = pathInfo.segments;
  4321. if (currentLength < 0 && mask.v.c) {
  4322. if (pathInfo.tLength < Math.abs(currentLength)) {
  4323. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  4324. }
  4325. segmentInd = segments.length - 1;
  4326. points = segments[segmentInd].points;
  4327. pointInd = points.length - 1;
  4328. while (currentLength < 0) {
  4329. currentLength += points[pointInd].partialLength;
  4330. pointInd -= 1;
  4331. if (pointInd < 0) {
  4332. segmentInd -= 1;
  4333. points = segments[segmentInd].points;
  4334. pointInd = points.length - 1;
  4335. }
  4336. }
  4337. }
  4338. points = segments[segmentInd].points;
  4339. prevPoint = points[pointInd - 1];
  4340. currentPoint = points[pointInd];
  4341. partialLength = currentPoint.partialLength;
  4342. }
  4343. len = letters.length;
  4344. xPos = 0;
  4345. yPos = 0;
  4346. var yOff = documentData.finalSize * 1.2 * 0.714;
  4347. var firstLine = true;
  4348. var animatorProps, animatorSelector;
  4349. var j, jLen;
  4350. var letterValue;
  4351. jLen = animators.length;
  4352. var lastLetter;
  4353. var mult, ind = -1, offf, xPathPos, yPathPos;
  4354. var initPathPos = currentLength,initSegmentInd = segmentInd, initPointInd = pointInd, currentLine = -1;
  4355. var elemOpacity;
  4356. var sc,sw,fc,k;
  4357. var lineLength = 0;
  4358. var letterSw, letterSc, letterFc, letterM = '', letterP = this.defaultPropsArray, letterO;
  4359. //
  4360. if(documentData.j === 2 || documentData.j === 1) {
  4361. var animatorJustifyOffset = 0;
  4362. var animatorFirstCharOffset = 0;
  4363. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  4364. var lastIndex = 0;
  4365. var isNewLine = true;
  4366. for (i = 0; i < len; i += 1) {
  4367. if (letters[i].n) {
  4368. if(animatorJustifyOffset) {
  4369. animatorJustifyOffset += animatorFirstCharOffset;
  4370. }
  4371. while (lastIndex < i) {
  4372. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  4373. lastIndex += 1;
  4374. }
  4375. animatorJustifyOffset = 0;
  4376. isNewLine = true;
  4377. } else {
  4378. for (j = 0; j < jLen; j += 1) {
  4379. animatorProps = animators[j].a;
  4380. if (animatorProps.t.propType) {
  4381. if (isNewLine && documentData.j === 2) {
  4382. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  4383. }
  4384. animatorSelector = animators[j].s;
  4385. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  4386. if (mult.length) {
  4387. animatorJustifyOffset += animatorProps.t.v*mult[0] * justifyOffsetMult;
  4388. } else {
  4389. animatorJustifyOffset += animatorProps.t.v*mult * justifyOffsetMult;
  4390. }
  4391. }
  4392. }
  4393. isNewLine = false;
  4394. }
  4395. }
  4396. if(animatorJustifyOffset) {
  4397. animatorJustifyOffset += animatorFirstCharOffset;
  4398. }
  4399. while(lastIndex < i) {
  4400. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  4401. lastIndex += 1;
  4402. }
  4403. }
  4404. //
  4405. for( i = 0; i < len; i += 1) {
  4406. matrixHelper.reset();
  4407. elemOpacity = 1;
  4408. if(letters[i].n) {
  4409. xPos = 0;
  4410. yPos += documentData.yOffset;
  4411. yPos += firstLine ? 1 : 0;
  4412. currentLength = initPathPos ;
  4413. firstLine = false;
  4414. lineLength = 0;
  4415. if(this._hasMaskedPath) {
  4416. segmentInd = initSegmentInd;
  4417. pointInd = initPointInd;
  4418. points = segments[segmentInd].points;
  4419. prevPoint = points[pointInd - 1];
  4420. currentPoint = points[pointInd];
  4421. partialLength = currentPoint.partialLength;
  4422. segmentLength = 0;
  4423. }
  4424. letterO = letterSw = letterFc = letterM = '';
  4425. letterP = this.defaultPropsArray;
  4426. }else{
  4427. if(this._hasMaskedPath) {
  4428. if(currentLine !== letters[i].line){
  4429. switch(documentData.j){
  4430. case 1:
  4431. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  4432. break;
  4433. case 2:
  4434. currentLength += (totalLength - documentData.lineWidths[letters[i].line])/2;
  4435. break;
  4436. }
  4437. currentLine = letters[i].line;
  4438. }
  4439. if (ind !== letters[i].ind) {
  4440. if (letters[ind]) {
  4441. currentLength += letters[ind].extra;
  4442. }
  4443. currentLength += letters[i].an / 2;
  4444. ind = letters[i].ind;
  4445. }
  4446. currentLength += alignment[0] * letters[i].an / 200;
  4447. var animatorOffset = 0;
  4448. for (j = 0; j < jLen; j += 1) {
  4449. animatorProps = animators[j].a;
  4450. if (animatorProps.p.propType) {
  4451. animatorSelector = animators[j].s;
  4452. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4453. if(mult.length){
  4454. animatorOffset += animatorProps.p.v[0] * mult[0];
  4455. } else{
  4456. animatorOffset += animatorProps.p.v[0] * mult;
  4457. }
  4458. }
  4459. if (animatorProps.a.propType) {
  4460. animatorSelector = animators[j].s;
  4461. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4462. if(mult.length){
  4463. animatorOffset += animatorProps.a.v[0] * mult[0];
  4464. } else{
  4465. animatorOffset += animatorProps.a.v[0] * mult;
  4466. }
  4467. }
  4468. }
  4469. flag = true;
  4470. while (flag) {
  4471. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  4472. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  4473. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  4474. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  4475. matrixHelper.translate(-alignment[0]*letters[i].an/200, -(alignment[1] * yOff / 100));
  4476. flag = false;
  4477. } else if (points) {
  4478. segmentLength += currentPoint.partialLength;
  4479. pointInd += 1;
  4480. if (pointInd >= points.length) {
  4481. pointInd = 0;
  4482. segmentInd += 1;
  4483. if (!segments[segmentInd]) {
  4484. if (mask.v.c) {
  4485. pointInd = 0;
  4486. segmentInd = 0;
  4487. points = segments[segmentInd].points;
  4488. } else {
  4489. segmentLength -= currentPoint.partialLength;
  4490. points = null;
  4491. }
  4492. } else {
  4493. points = segments[segmentInd].points;
  4494. }
  4495. }
  4496. if (points) {
  4497. prevPoint = currentPoint;
  4498. currentPoint = points[pointInd];
  4499. partialLength = currentPoint.partialLength;
  4500. }
  4501. }
  4502. }
  4503. offf = letters[i].an / 2 - letters[i].add;
  4504. matrixHelper.translate(-offf, 0, 0);
  4505. } else {
  4506. offf = letters[i].an/2 - letters[i].add;
  4507. matrixHelper.translate(-offf,0,0);
  4508. // Grouping alignment
  4509. matrixHelper.translate(-alignment[0]*letters[i].an/200, -alignment[1]*yOff/100, 0);
  4510. }
  4511. lineLength += letters[i].l/2;
  4512. for(j=0;j<jLen;j+=1){
  4513. animatorProps = animators[j].a;
  4514. if (animatorProps.t.propType) {
  4515. animatorSelector = animators[j].s;
  4516. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4517. //This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  4518. if(xPos !== 0 || documentData.j !== 0) {
  4519. if(this._hasMaskedPath) {
  4520. if(mult.length) {
  4521. currentLength += animatorProps.t.v*mult[0];
  4522. } else {
  4523. currentLength += animatorProps.t.v*mult;
  4524. }
  4525. }else{
  4526. if(mult.length) {
  4527. xPos += animatorProps.t.v*mult[0];
  4528. } else {
  4529. xPos += animatorProps.t.v*mult;
  4530. }
  4531. }
  4532. }
  4533. }
  4534. }
  4535. lineLength += letters[i].l/2;
  4536. if(documentData.strokeWidthAnim) {
  4537. sw = documentData.sw || 0;
  4538. }
  4539. if(documentData.strokeColorAnim) {
  4540. if(documentData.sc){
  4541. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  4542. }else{
  4543. sc = [0,0,0];
  4544. }
  4545. }
  4546. if(documentData.fillColorAnim && documentData.fc) {
  4547. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  4548. }
  4549. for(j=0;j<jLen;j+=1){
  4550. animatorProps = animators[j].a;
  4551. if (animatorProps.a.propType) {
  4552. animatorSelector = animators[j].s;
  4553. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4554. if(mult.length){
  4555. matrixHelper.translate(-animatorProps.a.v[0]*mult[0], -animatorProps.a.v[1]*mult[1], animatorProps.a.v[2]*mult[2]);
  4556. } else {
  4557. matrixHelper.translate(-animatorProps.a.v[0]*mult, -animatorProps.a.v[1]*mult, animatorProps.a.v[2]*mult);
  4558. }
  4559. }
  4560. }
  4561. for(j=0;j<jLen;j+=1){
  4562. animatorProps = animators[j].a;
  4563. if (animatorProps.s.propType) {
  4564. animatorSelector = animators[j].s;
  4565. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4566. if(mult.length){
  4567. matrixHelper.scale(1+((animatorProps.s.v[0]-1)*mult[0]),1+((animatorProps.s.v[1]-1)*mult[1]),1);
  4568. } else {
  4569. matrixHelper.scale(1+((animatorProps.s.v[0]-1)*mult),1+((animatorProps.s.v[1]-1)*mult),1);
  4570. }
  4571. }
  4572. }
  4573. for(j=0;j<jLen;j+=1) {
  4574. animatorProps = animators[j].a;
  4575. animatorSelector = animators[j].s;
  4576. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4577. if (animatorProps.sk.propType) {
  4578. if(mult.length) {
  4579. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  4580. } else {
  4581. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  4582. }
  4583. }
  4584. if (animatorProps.r.propType) {
  4585. if(mult.length) {
  4586. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  4587. } else {
  4588. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  4589. }
  4590. }
  4591. if (animatorProps.ry.propType) {
  4592. if(mult.length) {
  4593. matrixHelper.rotateY(animatorProps.ry.v*mult[1]);
  4594. }else{
  4595. matrixHelper.rotateY(animatorProps.ry.v*mult);
  4596. }
  4597. }
  4598. if (animatorProps.rx.propType) {
  4599. if(mult.length) {
  4600. matrixHelper.rotateX(animatorProps.rx.v*mult[0]);
  4601. } else {
  4602. matrixHelper.rotateX(animatorProps.rx.v*mult);
  4603. }
  4604. }
  4605. if (animatorProps.o.propType) {
  4606. if(mult.length) {
  4607. elemOpacity += ((animatorProps.o.v)*mult[0] - elemOpacity)*mult[0];
  4608. } else {
  4609. elemOpacity += ((animatorProps.o.v)*mult - elemOpacity)*mult;
  4610. }
  4611. }
  4612. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  4613. if(mult.length) {
  4614. sw += animatorProps.sw.v*mult[0];
  4615. } else {
  4616. sw += animatorProps.sw.v*mult;
  4617. }
  4618. }
  4619. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  4620. for(k=0;k<3;k+=1){
  4621. if(mult.length) {
  4622. sc[k] = sc[k] + (animatorProps.sc.v[k] - sc[k])*mult[0];
  4623. } else {
  4624. sc[k] = sc[k] + (animatorProps.sc.v[k] - sc[k])*mult;
  4625. }
  4626. }
  4627. }
  4628. if (documentData.fillColorAnim && documentData.fc) {
  4629. if(animatorProps.fc.propType){
  4630. for(k=0;k<3;k+=1){
  4631. if(mult.length) {
  4632. fc[k] = fc[k] + (animatorProps.fc.v[k] - fc[k])*mult[0];
  4633. } else {
  4634. fc[k] = fc[k] + (animatorProps.fc.v[k] - fc[k])*mult;
  4635. }
  4636. }
  4637. }
  4638. if(animatorProps.fh.propType){
  4639. if(mult.length) {
  4640. fc = addHueToRGB(fc,animatorProps.fh.v*mult[0]);
  4641. } else {
  4642. fc = addHueToRGB(fc,animatorProps.fh.v*mult);
  4643. }
  4644. }
  4645. if(animatorProps.fs.propType){
  4646. if(mult.length) {
  4647. fc = addSaturationToRGB(fc,animatorProps.fs.v*mult[0]);
  4648. } else {
  4649. fc = addSaturationToRGB(fc,animatorProps.fs.v*mult);
  4650. }
  4651. }
  4652. if(animatorProps.fb.propType){
  4653. if(mult.length) {
  4654. fc = addBrightnessToRGB(fc,animatorProps.fb.v*mult[0]);
  4655. } else {
  4656. fc = addBrightnessToRGB(fc,animatorProps.fb.v*mult);
  4657. }
  4658. }
  4659. }
  4660. }
  4661. for(j=0;j<jLen;j+=1){
  4662. animatorProps = animators[j].a;
  4663. if (animatorProps.p.propType) {
  4664. animatorSelector = animators[j].s;
  4665. mult = animatorSelector.getMult(letters[i].anIndexes[j],textData.a[j].s.totalChars);
  4666. if(this._hasMaskedPath) {
  4667. if(mult.length) {
  4668. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  4669. } else {
  4670. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  4671. }
  4672. }else{
  4673. if(mult.length) {
  4674. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  4675. } else {
  4676. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  4677. }
  4678. }
  4679. }
  4680. }
  4681. if(documentData.strokeWidthAnim){
  4682. letterSw = sw < 0 ? 0 : sw;
  4683. }
  4684. if(documentData.strokeColorAnim){
  4685. letterSc = 'rgb('+Math.round(sc[0]*255)+','+Math.round(sc[1]*255)+','+Math.round(sc[2]*255)+')';
  4686. }
  4687. if(documentData.fillColorAnim && documentData.fc){
  4688. letterFc = 'rgb('+Math.round(fc[0]*255)+','+Math.round(fc[1]*255)+','+Math.round(fc[2]*255)+')';
  4689. }
  4690. if(this._hasMaskedPath) {
  4691. matrixHelper.translate(0,-documentData.ls);
  4692. matrixHelper.translate(0, alignment[1]*yOff/100 + yPos,0);
  4693. if (textData.p.p) {
  4694. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  4695. var rot = Math.atan(tanAngle) * 180 / Math.PI;
  4696. if (currentPoint.point[0] < prevPoint.point[0]) {
  4697. rot += 180;
  4698. }
  4699. matrixHelper.rotate(-rot * Math.PI / 180);
  4700. }
  4701. matrixHelper.translate(xPathPos, yPathPos, 0);
  4702. currentLength -= alignment[0]*letters[i].an/200;
  4703. if(letters[i+1] && ind !== letters[i+1].ind){
  4704. currentLength += letters[i].an / 2;
  4705. currentLength += documentData.tr/1000*documentData.finalSize;
  4706. }
  4707. }else{
  4708. matrixHelper.translate(xPos,yPos,0);
  4709. if(documentData.ps){
  4710. //matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  4711. matrixHelper.translate(documentData.ps[0],documentData.ps[1] + documentData.ascent,0);
  4712. }
  4713. switch(documentData.j){
  4714. case 1:
  4715. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]),0,0);
  4716. break;
  4717. case 2:
  4718. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line])/2,0,0);
  4719. break;
  4720. }
  4721. matrixHelper.translate(0,-documentData.ls);
  4722. matrixHelper.translate(offf,0,0);
  4723. matrixHelper.translate(alignment[0]*letters[i].an/200,alignment[1]*yOff/100,0);
  4724. xPos += letters[i].l + documentData.tr/1000*documentData.finalSize;
  4725. }
  4726. if(renderType === 'html'){
  4727. letterM = matrixHelper.toCSS();
  4728. }else if(renderType === 'svg'){
  4729. letterM = matrixHelper.to2dCSS();
  4730. }else{
  4731. 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]];
  4732. }
  4733. letterO = elemOpacity;
  4734. }
  4735. if(renderedLettersCount <= i) {
  4736. letterValue = new LetterProps(letterO,letterSw,letterSc,letterFc,letterM,letterP);
  4737. this.renderedLetters.push(letterValue);
  4738. renderedLettersCount += 1;
  4739. this.lettersChangedFlag = true;
  4740. } else {
  4741. letterValue = this.renderedLetters[i];
  4742. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  4743. }
  4744. }
  4745. };
  4746. TextAnimatorProperty.prototype.getValue = function(){
  4747. if(this._elem.globalData.frameId === this._frameId){
  4748. return;
  4749. }
  4750. this._frameId = this._elem.globalData.frameId;
  4751. this.iterateDynamicProperties();
  4752. };
  4753. TextAnimatorProperty.prototype.mHelper = new Matrix();
  4754. TextAnimatorProperty.prototype.defaultPropsArray = [];
  4755. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  4756. function TextAnimatorDataProperty(elem, animatorProps, container) {
  4757. var defaultData = {propType:false};
  4758. var getProp = PropertyFactory.getProp;
  4759. var textAnimator_animatables = animatorProps.a;
  4760. this.a = {
  4761. r: textAnimator_animatables.r ? getProp(elem, textAnimator_animatables.r, 0, degToRads, container) : defaultData,
  4762. rx: textAnimator_animatables.rx ? getProp(elem, textAnimator_animatables.rx, 0, degToRads, container) : defaultData,
  4763. ry: textAnimator_animatables.ry ? getProp(elem, textAnimator_animatables.ry, 0, degToRads, container) : defaultData,
  4764. sk: textAnimator_animatables.sk ? getProp(elem, textAnimator_animatables.sk, 0, degToRads, container) : defaultData,
  4765. sa: textAnimator_animatables.sa ? getProp(elem, textAnimator_animatables.sa, 0, degToRads, container) : defaultData,
  4766. s: textAnimator_animatables.s ? getProp(elem, textAnimator_animatables.s, 1, 0.01, container) : defaultData,
  4767. a: textAnimator_animatables.a ? getProp(elem, textAnimator_animatables.a, 1, 0, container) : defaultData,
  4768. o: textAnimator_animatables.o ? getProp(elem, textAnimator_animatables.o, 0, 0.01, container) : defaultData,
  4769. p: textAnimator_animatables.p ? getProp(elem,textAnimator_animatables.p, 1, 0, container) : defaultData,
  4770. sw: textAnimator_animatables.sw ? getProp(elem, textAnimator_animatables.sw, 0, 0, container) : defaultData,
  4771. sc: textAnimator_animatables.sc ? getProp(elem, textAnimator_animatables.sc, 1, 0, container) : defaultData,
  4772. fc: textAnimator_animatables.fc ? getProp(elem, textAnimator_animatables.fc, 1, 0, container) : defaultData,
  4773. fh: textAnimator_animatables.fh ? getProp(elem, textAnimator_animatables.fh, 0, 0, container) : defaultData,
  4774. fs: textAnimator_animatables.fs ? getProp(elem, textAnimator_animatables.fs, 0, 0.01, container) : defaultData,
  4775. fb: textAnimator_animatables.fb ? getProp(elem, textAnimator_animatables.fb, 0, 0.01, container) : defaultData,
  4776. t: textAnimator_animatables.t ? getProp(elem, textAnimator_animatables.t, 0, 0, container) : defaultData
  4777. };
  4778. this.s = TextSelectorProp.getTextSelectorProp(elem,animatorProps.s, container);
  4779. this.s.t = animatorProps.s.t;
  4780. }
  4781. function LetterProps(o, sw, sc, fc, m, p){
  4782. this.o = o;
  4783. this.sw = sw;
  4784. this.sc = sc;
  4785. this.fc = fc;
  4786. this.m = m;
  4787. this.p = p;
  4788. this._mdf = {
  4789. o: true,
  4790. sw: !!sw,
  4791. sc: !!sc,
  4792. fc: !!fc,
  4793. m: true,
  4794. p: true
  4795. };
  4796. }
  4797. LetterProps.prototype.update = function(o, sw, sc, fc, m, p) {
  4798. this._mdf.o = false;
  4799. this._mdf.sw = false;
  4800. this._mdf.sc = false;
  4801. this._mdf.fc = false;
  4802. this._mdf.m = false;
  4803. this._mdf.p = false;
  4804. var updated = false;
  4805. if(this.o !== o) {
  4806. this.o = o;
  4807. this._mdf.o = true;
  4808. updated = true;
  4809. }
  4810. if(this.sw !== sw) {
  4811. this.sw = sw;
  4812. this._mdf.sw = true;
  4813. updated = true;
  4814. }
  4815. if(this.sc !== sc) {
  4816. this.sc = sc;
  4817. this._mdf.sc = true;
  4818. updated = true;
  4819. }
  4820. if(this.fc !== fc) {
  4821. this.fc = fc;
  4822. this._mdf.fc = true;
  4823. updated = true;
  4824. }
  4825. if(this.m !== m) {
  4826. this.m = m;
  4827. this._mdf.m = true;
  4828. updated = true;
  4829. }
  4830. 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])) {
  4831. this.p = p;
  4832. this._mdf.p = true;
  4833. updated = true;
  4834. }
  4835. return updated;
  4836. };
  4837. function TextProperty(elem, data){
  4838. this._frameId = initialDefaultFrame;
  4839. this.pv = '';
  4840. this.v = '';
  4841. this.kf = false;
  4842. this._isFirstFrame = true;
  4843. this._mdf = false;
  4844. this.data = data;
  4845. this.elem = elem;
  4846. this.comp = this.elem.comp;
  4847. this.keysIndex = 0;
  4848. this.canResize = false;
  4849. this.minimumFontSize = 1;
  4850. this.effectsSequence = [];
  4851. this.currentData = {
  4852. ascent: 0,
  4853. boxWidth: this.defaultBoxWidth,
  4854. f: '',
  4855. fStyle: '',
  4856. fWeight: '',
  4857. fc: '',
  4858. j: '',
  4859. justifyOffset: '',
  4860. l: [],
  4861. lh: 0,
  4862. lineWidths: [],
  4863. ls: '',
  4864. of: '',
  4865. s: '',
  4866. sc: '',
  4867. sw: 0,
  4868. t: 0,
  4869. tr: 0,
  4870. sz:0,
  4871. ps:null,
  4872. fillColorAnim: false,
  4873. strokeColorAnim: false,
  4874. strokeWidthAnim: false,
  4875. yOffset: 0,
  4876. finalSize:0,
  4877. finalText:[],
  4878. finalLineHeight: 0,
  4879. __complete: false
  4880. };
  4881. this.copyData(this.currentData, this.data.d.k[0].s);
  4882. if(!this.searchProperty()) {
  4883. this.completeTextData(this.currentData);
  4884. }
  4885. }
  4886. TextProperty.prototype.defaultBoxWidth = [0,0];
  4887. TextProperty.prototype.copyData = function(obj, data) {
  4888. for(var s in data) {
  4889. if(data.hasOwnProperty(s)) {
  4890. obj[s] = data[s];
  4891. }
  4892. }
  4893. return obj;
  4894. }
  4895. TextProperty.prototype.setCurrentData = function(data){
  4896. if(!data.__complete) {
  4897. this.completeTextData(data);
  4898. }
  4899. this.currentData = data;
  4900. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  4901. this._mdf = true;
  4902. };
  4903. TextProperty.prototype.searchProperty = function() {
  4904. return this.searchKeyframes();
  4905. };
  4906. TextProperty.prototype.searchKeyframes = function() {
  4907. this.kf = this.data.d.k.length > 1;
  4908. if(this.kf) {
  4909. this.addEffect(this.getKeyframeValue.bind(this));
  4910. }
  4911. return this.kf;
  4912. }
  4913. TextProperty.prototype.addEffect = function(effectFunction) {
  4914. this.effectsSequence.push(effectFunction);
  4915. this.elem.addDynamicProperty(this);
  4916. };
  4917. TextProperty.prototype.getValue = function(_finalValue) {
  4918. if((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  4919. return;
  4920. }
  4921. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  4922. var currentValue = this.currentData;
  4923. var currentIndex = this.keysIndex;
  4924. if(this.lock) {
  4925. this.setCurrentData(this.currentData);
  4926. return;
  4927. }
  4928. this.lock = true;
  4929. this._mdf = false;
  4930. var multipliedValue;
  4931. var i, len = this.effectsSequence.length;
  4932. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  4933. for(i = 0; i < len; i += 1) {
  4934. //Checking if index changed to prevent creating a new object every time the expression updates.
  4935. if(currentIndex !== this.keysIndex) {
  4936. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  4937. } else {
  4938. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  4939. }
  4940. }
  4941. if(currentValue !== finalValue) {
  4942. this.setCurrentData(finalValue);
  4943. }
  4944. this.pv = this.v = this.currentData;
  4945. this.lock = false;
  4946. this.frameId = this.elem.globalData.frameId;
  4947. }
  4948. TextProperty.prototype.getKeyframeValue = function() {
  4949. var textKeys = this.data.d.k, textDocumentData;
  4950. var frameNum = this.elem.comp.renderedFrame;
  4951. var i = 0, len = textKeys.length;
  4952. while(i <= len - 1) {
  4953. textDocumentData = textKeys[i].s;
  4954. if(i === len - 1 || textKeys[i+1].t > frameNum){
  4955. break;
  4956. }
  4957. i += 1;
  4958. }
  4959. if(this.keysIndex !== i) {
  4960. this.keysIndex = i;
  4961. }
  4962. return this.data.d.k[this.keysIndex].s;
  4963. };
  4964. TextProperty.prototype.buildFinalText = function(text) {
  4965. var combinedCharacters = FontManager.getCombinedCharacterCodes();
  4966. var charactersArray = [];
  4967. var i = 0, len = text.length;
  4968. var charCode;
  4969. while (i < len) {
  4970. charCode = text.charCodeAt(i);
  4971. if (combinedCharacters.indexOf(charCode) !== -1) {
  4972. charactersArray[charactersArray.length - 1] += text.charAt(i);
  4973. } else {
  4974. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  4975. charCode = text.charCodeAt(i + 1);
  4976. if (charCode >= 0xDC00 && charCode <= 0xDFFF) {
  4977. charactersArray.push(text.substr(i, 2));
  4978. ++i;
  4979. } else {
  4980. charactersArray.push(text.charAt(i));
  4981. }
  4982. } else {
  4983. charactersArray.push(text.charAt(i));
  4984. }
  4985. }
  4986. i += 1;
  4987. }
  4988. return charactersArray;
  4989. }
  4990. TextProperty.prototype.completeTextData = function(documentData) {
  4991. documentData.__complete = true;
  4992. var fontManager = this.elem.globalData.fontManager;
  4993. var data = this.data;
  4994. var letters = [];
  4995. var i, len;
  4996. var newLineFlag, index = 0, val;
  4997. var anchorGrouping = data.m.g;
  4998. var currentSize = 0, currentPos = 0, currentLine = 0, lineWidths = [];
  4999. var lineWidth = 0;
  5000. var maxLineWidth = 0;
  5001. var j, jLen;
  5002. var fontData = fontManager.getFontByName(documentData.f);
  5003. var charData, cLength = 0;
  5004. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5005. var fWeight = 'normal', fStyle = 'normal';
  5006. len = styles.length;
  5007. var styleName;
  5008. for(i=0;i<len;i+=1){
  5009. styleName = styles[i].toLowerCase();
  5010. switch(styleName) {
  5011. case 'italic':
  5012. fStyle = 'italic';
  5013. break;
  5014. case 'bold':
  5015. fWeight = '700';
  5016. break;
  5017. case 'black':
  5018. fWeight = '900';
  5019. break;
  5020. case 'medium':
  5021. fWeight = '500';
  5022. break;
  5023. case 'regular':
  5024. case 'normal':
  5025. fWeight = '400';
  5026. break;
  5027. case 'light':
  5028. case 'thin':
  5029. fWeight = '200';
  5030. break;
  5031. }
  5032. }
  5033. documentData.fWeight = fontData.fWeight || fWeight;
  5034. documentData.fStyle = fStyle;
  5035. documentData.finalSize = documentData.s;
  5036. documentData.finalText = this.buildFinalText(documentData.t);
  5037. len = documentData.finalText.length;
  5038. documentData.finalLineHeight = documentData.lh;
  5039. var trackingOffset = documentData.tr/1000*documentData.finalSize;
  5040. var charCode;
  5041. if(documentData.sz){
  5042. var flag = true;
  5043. var boxWidth = documentData.sz[0];
  5044. var boxHeight = documentData.sz[1];
  5045. var currentHeight, finalText;
  5046. while(flag) {
  5047. finalText = this.buildFinalText(documentData.t);
  5048. currentHeight = 0;
  5049. lineWidth = 0;
  5050. len = finalText.length;
  5051. trackingOffset = documentData.tr/1000*documentData.finalSize;
  5052. var lastSpaceIndex = -1;
  5053. for(i=0;i<len;i+=1){
  5054. charCode = finalText[i].charCodeAt(0);
  5055. newLineFlag = false;
  5056. if(finalText[i] === ' '){
  5057. lastSpaceIndex = i;
  5058. }else if(charCode === 13 || charCode === 3){
  5059. lineWidth = 0;
  5060. newLineFlag = true;
  5061. currentHeight += documentData.finalLineHeight || documentData.finalSize*1.2;
  5062. }
  5063. if(fontManager.chars){
  5064. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  5065. cLength = newLineFlag ? 0 : charData.w*documentData.finalSize/100;
  5066. }else{
  5067. //tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  5068. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  5069. }
  5070. if(lineWidth + cLength > boxWidth && finalText[i] !== ' '){
  5071. if(lastSpaceIndex === -1){
  5072. len += 1;
  5073. } else {
  5074. i = lastSpaceIndex;
  5075. }
  5076. currentHeight += documentData.finalLineHeight || documentData.finalSize*1.2;
  5077. finalText.splice(i, lastSpaceIndex === i ? 1 : 0,"\r");
  5078. //finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  5079. lastSpaceIndex = -1;
  5080. lineWidth = 0;
  5081. }else {
  5082. lineWidth += cLength;
  5083. lineWidth += trackingOffset;
  5084. }
  5085. }
  5086. currentHeight += fontData.ascent*documentData.finalSize/100;
  5087. if(this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  5088. documentData.finalSize -= 1;
  5089. documentData.finalLineHeight = documentData.finalSize * documentData.lh / documentData.s;
  5090. } else {
  5091. documentData.finalText = finalText;
  5092. len = documentData.finalText.length;
  5093. flag = false;
  5094. }
  5095. }
  5096. }
  5097. lineWidth = - trackingOffset;
  5098. cLength = 0;
  5099. var uncollapsedSpaces = 0;
  5100. var currentChar;
  5101. for (i = 0;i < len ;i += 1) {
  5102. newLineFlag = false;
  5103. currentChar = documentData.finalText[i];
  5104. charCode = currentChar.charCodeAt(0);
  5105. if (charCode === 13 || charCode === 3) {
  5106. uncollapsedSpaces = 0;
  5107. lineWidths.push(lineWidth);
  5108. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  5109. lineWidth = - 2 * trackingOffset;
  5110. val = '';
  5111. newLineFlag = true;
  5112. currentLine += 1;
  5113. }else{
  5114. val = currentChar;
  5115. }
  5116. if(fontManager.chars){
  5117. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  5118. cLength = newLineFlag ? 0 : charData.w*documentData.finalSize/100;
  5119. }else{
  5120. //var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  5121. //tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  5122. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  5123. }
  5124. //
  5125. if(currentChar === ' '){
  5126. uncollapsedSpaces += cLength + trackingOffset;
  5127. } else {
  5128. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  5129. uncollapsedSpaces = 0;
  5130. }
  5131. letters.push({l:cLength,an:cLength,add:currentSize,n:newLineFlag, anIndexes:[], val: val, line: currentLine, animatorJustifyOffset: 0});
  5132. if(anchorGrouping == 2){
  5133. currentSize += cLength;
  5134. if(val === '' || val === ' ' || i === len - 1){
  5135. if(val === '' || val === ' '){
  5136. currentSize -= cLength;
  5137. }
  5138. while(currentPos<=i){
  5139. letters[currentPos].an = currentSize;
  5140. letters[currentPos].ind = index;
  5141. letters[currentPos].extra = cLength;
  5142. currentPos += 1;
  5143. }
  5144. index += 1;
  5145. currentSize = 0;
  5146. }
  5147. }else if(anchorGrouping == 3){
  5148. currentSize += cLength;
  5149. if(val === '' || i === len - 1){
  5150. if(val === ''){
  5151. currentSize -= cLength;
  5152. }
  5153. while(currentPos<=i){
  5154. letters[currentPos].an = currentSize;
  5155. letters[currentPos].ind = index;
  5156. letters[currentPos].extra = cLength;
  5157. currentPos += 1;
  5158. }
  5159. currentSize = 0;
  5160. index += 1;
  5161. }
  5162. }else{
  5163. letters[index].ind = index;
  5164. letters[index].extra = 0;
  5165. index += 1;
  5166. }
  5167. }
  5168. documentData.l = letters;
  5169. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  5170. lineWidths.push(lineWidth);
  5171. if(documentData.sz){
  5172. documentData.boxWidth = documentData.sz[0];
  5173. documentData.justifyOffset = 0;
  5174. }else{
  5175. documentData.boxWidth = maxLineWidth;
  5176. switch(documentData.j){
  5177. case 1:
  5178. documentData.justifyOffset = - documentData.boxWidth;
  5179. break;
  5180. case 2:
  5181. documentData.justifyOffset = - documentData.boxWidth/2;
  5182. break;
  5183. default:
  5184. documentData.justifyOffset = 0;
  5185. }
  5186. }
  5187. documentData.lineWidths = lineWidths;
  5188. var animators = data.a, animatorData, letterData;
  5189. jLen = animators.length;
  5190. var based, ind, indexes = [];
  5191. for(j=0;j<jLen;j+=1){
  5192. animatorData = animators[j];
  5193. if(animatorData.a.sc){
  5194. documentData.strokeColorAnim = true;
  5195. }
  5196. if(animatorData.a.sw){
  5197. documentData.strokeWidthAnim = true;
  5198. }
  5199. if(animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb){
  5200. documentData.fillColorAnim = true;
  5201. }
  5202. ind = 0;
  5203. based = animatorData.s.b;
  5204. for(i=0;i<len;i+=1){
  5205. letterData = letters[i];
  5206. letterData.anIndexes[j] = ind;
  5207. if((based == 1 && letterData.val !== '') || (based == 2 && letterData.val !== '' && letterData.val !== ' ') || (based == 3 && (letterData.n || letterData.val == ' ' || i == len - 1)) || (based == 4 && (letterData.n || i == len - 1))){
  5208. if(animatorData.s.rn === 1){
  5209. indexes.push(ind);
  5210. }
  5211. ind += 1;
  5212. }
  5213. }
  5214. data.a[j].s.totalChars = ind;
  5215. var currentInd = -1, newInd;
  5216. if(animatorData.s.rn === 1){
  5217. for(i = 0; i < len; i += 1){
  5218. letterData = letters[i];
  5219. if(currentInd != letterData.anIndexes[j]){
  5220. currentInd = letterData.anIndexes[j];
  5221. newInd = indexes.splice(Math.floor(Math.random()*indexes.length),1)[0];
  5222. }
  5223. letterData.anIndexes[j] = newInd;
  5224. }
  5225. }
  5226. }
  5227. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize*1.2;
  5228. documentData.ls = documentData.ls || 0;
  5229. documentData.ascent = fontData.ascent*documentData.finalSize/100;
  5230. };
  5231. TextProperty.prototype.updateDocumentData = function(newData, index) {
  5232. index = index === undefined ? this.keysIndex : index;
  5233. var dData = this.copyData({}, this.data.d.k[index].s);
  5234. dData = this.copyData(dData, newData);
  5235. this.data.d.k[index].s = dData;
  5236. this.recalculate(index);
  5237. this.elem.addDynamicProperty(this);
  5238. };
  5239. TextProperty.prototype.recalculate = function(index) {
  5240. var dData = this.data.d.k[index].s;
  5241. dData.__complete = false;
  5242. this.keysIndex = 0;
  5243. this._isFirstFrame = true;
  5244. this.getValue(dData);
  5245. }
  5246. TextProperty.prototype.canResizeFont = function(_canResize) {
  5247. this.canResize = _canResize;
  5248. this.recalculate(this.keysIndex);
  5249. this.elem.addDynamicProperty(this);
  5250. };
  5251. TextProperty.prototype.setMinimumFontSize = function(_fontValue) {
  5252. this.minimumFontSize = Math.floor(_fontValue) || 1;
  5253. this.recalculate(this.keysIndex);
  5254. this.elem.addDynamicProperty(this);
  5255. };
  5256. var TextSelectorProp = (function(){
  5257. var max = Math.max;
  5258. var min = Math.min;
  5259. var floor = Math.floor;
  5260. function TextSelectorProp(elem,data){
  5261. this._currentTextLength = -1;
  5262. this.k = false;
  5263. this.data = data;
  5264. this.elem = elem;
  5265. this.comp = elem.comp;
  5266. this.finalS = 0;
  5267. this.finalE = 0;
  5268. this.initDynamicPropertyContainer(elem);
  5269. this.s = PropertyFactory.getProp(elem,data.s || {k:0},0,0,this);
  5270. if('e' in data){
  5271. this.e = PropertyFactory.getProp(elem,data.e,0,0,this);
  5272. }else{
  5273. this.e = {v:100};
  5274. }
  5275. this.o = PropertyFactory.getProp(elem,data.o || {k:0},0,0,this);
  5276. this.xe = PropertyFactory.getProp(elem,data.xe || {k:0},0,0,this);
  5277. this.ne = PropertyFactory.getProp(elem,data.ne || {k:0},0,0,this);
  5278. this.a = PropertyFactory.getProp(elem,data.a,0,0.01,this);
  5279. if(!this.dynamicProperties.length){
  5280. this.getValue();
  5281. }
  5282. }
  5283. TextSelectorProp.prototype = {
  5284. getMult: function(ind) {
  5285. if(this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  5286. this.getValue();
  5287. }
  5288. //var easer = bez.getEasingCurve(this.ne.v/100,0,1-this.xe.v/100,1);
  5289. var x1 = 0;
  5290. var y1 = 0;
  5291. var x2 = 1;
  5292. var y2 = 1;
  5293. if(this.ne.v > 0) {
  5294. x1 = this.ne.v / 100.0;
  5295. }
  5296. else {
  5297. y1 = -this.ne.v / 100.0;
  5298. }
  5299. if(this.xe.v > 0) {
  5300. x2 = 1.0 - this.xe.v / 100.0;
  5301. }
  5302. else {
  5303. y2 = 1.0 + this.xe.v / 100.0;
  5304. }
  5305. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  5306. var mult = 0;
  5307. var s = this.finalS;
  5308. var e = this.finalE;
  5309. var type = this.data.sh;
  5310. if (type === 2){
  5311. if (e === s) {
  5312. mult = ind >= e ? 1 : 0;
  5313. } else {
  5314. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  5315. }
  5316. mult = easer(mult);
  5317. } else if(type === 3) {
  5318. if (e === s) {
  5319. mult = ind >= e ? 0 : 1;
  5320. }else{
  5321. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s),1));
  5322. }
  5323. mult = easer(mult);
  5324. } else if (type === 4) {
  5325. if (e === s) {
  5326. mult = 0;
  5327. } else {
  5328. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  5329. if (mult < 0.5) {
  5330. mult *= 2;
  5331. } else {
  5332. mult = 1 - 2 * (mult - 0.5);
  5333. }
  5334. }
  5335. mult = easer(mult);
  5336. } else if (type === 5) {
  5337. if (e === s){
  5338. mult = 0;
  5339. } else {
  5340. var tot = e - s;
  5341. /*ind += 0.5;
  5342. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind;*/
  5343. ind = min(max(0, ind + 0.5 - s), e - s);
  5344. var x = -tot/2+ind;
  5345. var a = tot/2;
  5346. mult = Math.sqrt(1 - (x * x) / (a * a));
  5347. }
  5348. mult = easer(mult);
  5349. } else if (type === 6) {
  5350. if (e === s){
  5351. mult = 0;
  5352. } else {
  5353. ind = min(max(0, ind + 0.5 - s), e - s);
  5354. mult = (1 + (Math.cos((Math.PI + Math.PI * 2 * (ind) / (e - s))))) / 2;
  5355. }
  5356. mult = easer(mult);
  5357. } else {
  5358. if (ind >= floor(s)) {
  5359. if (ind - s < 0) {
  5360. mult = max(0, min(min(e, 1) - (s - ind), 1));
  5361. } else {
  5362. mult = max(0, min(e - ind, 1));
  5363. }
  5364. }
  5365. mult = easer(mult);
  5366. }
  5367. return mult*this.a.v;
  5368. },
  5369. getValue: function(newCharsFlag) {
  5370. this.iterateDynamicProperties();
  5371. this._mdf = newCharsFlag || this._mdf;
  5372. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  5373. if(newCharsFlag && this.data.r === 2) {
  5374. this.e.v = this._currentTextLength;
  5375. }
  5376. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  5377. var o = this.o.v/divisor;
  5378. var s = this.s.v/divisor + o;
  5379. var e = (this.e.v/divisor) + o;
  5380. if(s>e){
  5381. var _s = s;
  5382. s = e;
  5383. e = _s;
  5384. }
  5385. this.finalS = s;
  5386. this.finalE = e;
  5387. }
  5388. }
  5389. extendPrototype([DynamicPropertyContainer], TextSelectorProp);
  5390. function getTextSelectorProp(elem, data,arr) {
  5391. return new TextSelectorProp(elem, data, arr);
  5392. }
  5393. return {
  5394. getTextSelectorProp: getTextSelectorProp
  5395. };
  5396. }());
  5397. var pool_factory = (function() {
  5398. return function(initialLength, _create, _release, _clone) {
  5399. var _length = 0;
  5400. var _maxLength = initialLength;
  5401. var pool = createSizedArray(_maxLength);
  5402. var ob = {
  5403. newElement: newElement,
  5404. release: release
  5405. };
  5406. function newElement(){
  5407. var element;
  5408. if(_length){
  5409. _length -= 1;
  5410. element = pool[_length];
  5411. } else {
  5412. element = _create();
  5413. }
  5414. return element;
  5415. }
  5416. function release(element) {
  5417. if(_length === _maxLength) {
  5418. pool = pooling.double(pool);
  5419. _maxLength = _maxLength*2;
  5420. }
  5421. if (_release) {
  5422. _release(element);
  5423. }
  5424. pool[_length] = element;
  5425. _length += 1;
  5426. }
  5427. function clone() {
  5428. var clonedElement = newElement();
  5429. return _clone(clonedElement);
  5430. }
  5431. return ob;
  5432. };
  5433. }());
  5434. var pooling = (function(){
  5435. function double(arr){
  5436. return arr.concat(createSizedArray(arr.length));
  5437. }
  5438. return {
  5439. double: double
  5440. };
  5441. }());
  5442. var point_pool = (function(){
  5443. function create() {
  5444. return createTypedArray('float32', 2);
  5445. }
  5446. return pool_factory(8, create);
  5447. }());
  5448. var shape_pool = (function(){
  5449. function create() {
  5450. return new ShapePath();
  5451. }
  5452. function release(shapePath) {
  5453. var len = shapePath._length, i;
  5454. for(i = 0; i < len; i += 1) {
  5455. point_pool.release(shapePath.v[i]);
  5456. point_pool.release(shapePath.i[i]);
  5457. point_pool.release(shapePath.o[i]);
  5458. shapePath.v[i] = null;
  5459. shapePath.i[i] = null;
  5460. shapePath.o[i] = null;
  5461. }
  5462. shapePath._length = 0;
  5463. shapePath.c = false;
  5464. }
  5465. function clone(shape) {
  5466. var cloned = factory.newElement();
  5467. var i, len = shape._length === undefined ? shape.v.length : shape._length;
  5468. cloned.setLength(len);
  5469. cloned.c = shape.c;
  5470. var pt;
  5471. for(i = 0; i < len; i += 1) {
  5472. 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);
  5473. }
  5474. return cloned;
  5475. }
  5476. var factory = pool_factory(4, create, release);
  5477. factory.clone = clone;
  5478. return factory;
  5479. }());
  5480. var shapeCollection_pool = (function(){
  5481. var ob = {
  5482. newShapeCollection: newShapeCollection,
  5483. release: release
  5484. };
  5485. var _length = 0;
  5486. var _maxLength = 4;
  5487. var pool = createSizedArray(_maxLength);
  5488. function newShapeCollection(){
  5489. var shapeCollection;
  5490. if(_length){
  5491. _length -= 1;
  5492. shapeCollection = pool[_length];
  5493. } else {
  5494. shapeCollection = new ShapeCollection();
  5495. }
  5496. return shapeCollection;
  5497. }
  5498. function release(shapeCollection) {
  5499. var i, len = shapeCollection._length;
  5500. for(i = 0; i < len; i += 1) {
  5501. shape_pool.release(shapeCollection.shapes[i]);
  5502. }
  5503. shapeCollection._length = 0;
  5504. if(_length === _maxLength) {
  5505. pool = pooling.double(pool);
  5506. _maxLength = _maxLength*2;
  5507. }
  5508. pool[_length] = shapeCollection;
  5509. _length += 1;
  5510. }
  5511. return ob;
  5512. }());
  5513. var segments_length_pool = (function(){
  5514. function create() {
  5515. return {
  5516. lengths: [],
  5517. totalLength: 0
  5518. };
  5519. }
  5520. function release(element) {
  5521. var i, len = element.lengths.length;
  5522. for(i=0;i<len;i+=1) {
  5523. bezier_length_pool.release(element.lengths[i]);
  5524. }
  5525. element.lengths.length = 0;
  5526. }
  5527. return pool_factory(8, create, release);
  5528. }());
  5529. var bezier_length_pool = (function(){
  5530. function create() {
  5531. return {
  5532. addedLength: 0,
  5533. percents: createTypedArray('float32', defaultCurveSegments),
  5534. lengths: createTypedArray('float32', defaultCurveSegments),
  5535. };
  5536. }
  5537. return pool_factory(8, create);
  5538. }());
  5539. function BaseRenderer(){}
  5540. BaseRenderer.prototype.checkLayers = function(num){
  5541. var i, len = this.layers.length, data;
  5542. this.completeLayers = true;
  5543. for (i = len - 1; i >= 0; i--) {
  5544. if (!this.elements[i]) {
  5545. data = this.layers[i];
  5546. if(data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st))
  5547. {
  5548. this.buildItem(i);
  5549. }
  5550. }
  5551. this.completeLayers = this.elements[i] ? this.completeLayers:false;
  5552. }
  5553. this.checkPendingElements();
  5554. };
  5555. BaseRenderer.prototype.createItem = function(layer){
  5556. switch(layer.ty){
  5557. case 2:
  5558. return this.createImage(layer);
  5559. case 0:
  5560. return this.createComp(layer);
  5561. case 1:
  5562. return this.createSolid(layer);
  5563. case 3:
  5564. return this.createNull(layer);
  5565. case 4:
  5566. return this.createShape(layer);
  5567. case 5:
  5568. return this.createText(layer);
  5569. case 6:
  5570. return this.createAudio(layer);
  5571. case 13:
  5572. return this.createCamera(layer);
  5573. }
  5574. return this.createNull(layer);
  5575. };
  5576. BaseRenderer.prototype.createCamera = function(){
  5577. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  5578. };
  5579. BaseRenderer.prototype.createAudio = function(data){
  5580. return new AudioElement(data, this.globalData, this);
  5581. };
  5582. BaseRenderer.prototype.buildAllItems = function(){
  5583. var i, len = this.layers.length;
  5584. for(i=0;i<len;i+=1){
  5585. this.buildItem(i);
  5586. }
  5587. this.checkPendingElements();
  5588. };
  5589. BaseRenderer.prototype.includeLayers = function(newLayers){
  5590. this.completeLayers = false;
  5591. var i, len = newLayers.length;
  5592. var j, jLen = this.layers.length;
  5593. for(i=0;i<len;i+=1){
  5594. j = 0;
  5595. while(j<jLen){
  5596. if(this.layers[j].id == newLayers[i].id){
  5597. this.layers[j] = newLayers[i];
  5598. break;
  5599. }
  5600. j += 1;
  5601. }
  5602. }
  5603. };
  5604. BaseRenderer.prototype.setProjectInterface = function(pInterface){
  5605. this.globalData.projectInterface = pInterface;
  5606. };
  5607. BaseRenderer.prototype.initItems = function(){
  5608. if(!this.globalData.progressiveLoad){
  5609. this.buildAllItems();
  5610. }
  5611. };
  5612. BaseRenderer.prototype.buildElementParenting = function(element, parentName, hierarchy) {
  5613. var elements = this.elements;
  5614. var layers = this.layers;
  5615. var i=0, len = layers.length;
  5616. while (i < len) {
  5617. if (layers[i].ind == parentName) {
  5618. if (!elements[i] || elements[i] === true) {
  5619. this.buildItem(i);
  5620. this.addPendingElement(element);
  5621. } else {
  5622. hierarchy.push(elements[i]);
  5623. elements[i].setAsParent();
  5624. if(layers[i].parent !== undefined) {
  5625. this.buildElementParenting(element, layers[i].parent, hierarchy);
  5626. } else {
  5627. element.setHierarchy(hierarchy);
  5628. }
  5629. }
  5630. }
  5631. i += 1;
  5632. }
  5633. };
  5634. BaseRenderer.prototype.addPendingElement = function(element){
  5635. this.pendingElements.push(element);
  5636. };
  5637. BaseRenderer.prototype.searchExtraCompositions = function(assets){
  5638. var i, len = assets.length;
  5639. for(i=0;i<len;i+=1){
  5640. if(assets[i].xt){
  5641. var comp = this.createComp(assets[i]);
  5642. comp.initExpressions();
  5643. this.globalData.projectInterface.registerComposition(comp);
  5644. }
  5645. }
  5646. };
  5647. BaseRenderer.prototype.setupGlobalData = function(animData, fontsContainer) {
  5648. this.globalData.fontManager = new FontManager();
  5649. this.globalData.fontManager.addChars(animData.chars);
  5650. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  5651. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  5652. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  5653. this.globalData.imageLoader = this.animationItem.imagePreloader;
  5654. this.globalData.audioController = this.animationItem.audioController;
  5655. this.globalData.frameId = 0;
  5656. this.globalData.frameRate = animData.fr;
  5657. this.globalData.nm = animData.nm;
  5658. this.globalData.compSize = {
  5659. w: animData.w,
  5660. h: animData.h
  5661. }
  5662. }
  5663. function SVGRenderer(animationItem, config){
  5664. this.animationItem = animationItem;
  5665. this.layers = null;
  5666. this.renderedFrame = -1;
  5667. this.svgElement = createNS('svg');
  5668. var ariaLabel = '';
  5669. if (config && config.title) {
  5670. var titleElement = createNS('title');
  5671. var titleId = createElementID();
  5672. titleElement.setAttribute('id', titleId);
  5673. titleElement.textContent = config.title;
  5674. this.svgElement.appendChild(titleElement);
  5675. ariaLabel += titleId;
  5676. }
  5677. if (config && config.description) {
  5678. var descElement = createNS('desc');
  5679. var descId = createElementID();
  5680. descElement.setAttribute('id', descId);
  5681. descElement.textContent = config.description;
  5682. this.svgElement.appendChild(descElement);
  5683. ariaLabel += ' ' + descId;
  5684. }
  5685. if (ariaLabel) {
  5686. this.svgElement.setAttribute('aria-labelledby', ariaLabel)
  5687. }
  5688. var defs = createNS( 'defs');
  5689. this.svgElement.appendChild(defs);
  5690. var maskElement = createNS('g');
  5691. this.svgElement.appendChild(maskElement);
  5692. this.layerElement = maskElement;
  5693. this.renderConfig = {
  5694. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  5695. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  5696. progressiveLoad: (config && config.progressiveLoad) || false,
  5697. hideOnTransparent: (config && config.hideOnTransparent === false) ? false : true,
  5698. viewBoxOnly: (config && config.viewBoxOnly) || false,
  5699. viewBoxSize: (config && config.viewBoxSize) || false,
  5700. className: (config && config.className) || '',
  5701. id: (config && config.id) || '',
  5702. focusable: config && config.focusable,
  5703. filterSize: {
  5704. width: config && config.filterSize && config.filterSize.width || '100%',
  5705. height: config && config.filterSize && config.filterSize.height || '100%',
  5706. x: config && config.filterSize && config.filterSize.x || '0%',
  5707. y: config && config.filterSize && config.filterSize.y || '0%',
  5708. }
  5709. };
  5710. this.globalData = {
  5711. _mdf: false,
  5712. frameNum: -1,
  5713. defs: defs,
  5714. renderConfig: this.renderConfig
  5715. };
  5716. this.elements = [];
  5717. this.pendingElements = [];
  5718. this.destroyed = false;
  5719. this.rendererType = 'svg';
  5720. }
  5721. extendPrototype([BaseRenderer],SVGRenderer);
  5722. SVGRenderer.prototype.createNull = function (data) {
  5723. return new NullElement(data,this.globalData,this);
  5724. };
  5725. SVGRenderer.prototype.createShape = function (data) {
  5726. return new SVGShapeElement(data,this.globalData,this);
  5727. };
  5728. SVGRenderer.prototype.createText = function (data) {
  5729. return new SVGTextElement(data,this.globalData,this);
  5730. };
  5731. SVGRenderer.prototype.createImage = function (data) {
  5732. return new IImageElement(data,this.globalData,this);
  5733. };
  5734. SVGRenderer.prototype.createComp = function (data) {
  5735. return new SVGCompElement(data,this.globalData,this);
  5736. };
  5737. SVGRenderer.prototype.createSolid = function (data) {
  5738. return new ISolidElement(data,this.globalData,this);
  5739. };
  5740. SVGRenderer.prototype.configAnimation = function(animData){
  5741. this.svgElement.setAttribute('xmlns','http://www.w3.org/2000/svg');
  5742. if(this.renderConfig.viewBoxSize) {
  5743. this.svgElement.setAttribute('viewBox',this.renderConfig.viewBoxSize);
  5744. } else {
  5745. this.svgElement.setAttribute('viewBox','0 0 '+animData.w+' '+animData.h);
  5746. }
  5747. if(!this.renderConfig.viewBoxOnly) {
  5748. this.svgElement.setAttribute('width',animData.w);
  5749. this.svgElement.setAttribute('height',animData.h);
  5750. this.svgElement.style.width = '100%';
  5751. this.svgElement.style.height = '100%';
  5752. this.svgElement.style.transform = 'translate3d(0,0,0)';
  5753. }
  5754. if (this.renderConfig.className) {
  5755. this.svgElement.setAttribute('class', this.renderConfig.className);
  5756. }
  5757. if (this.renderConfig.id) {
  5758. this.svgElement.setAttribute('id', this.renderConfig.id);
  5759. }
  5760. if (this.renderConfig.focusable !== undefined) {
  5761. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  5762. }
  5763. this.svgElement.setAttribute('preserveAspectRatio',this.renderConfig.preserveAspectRatio);
  5764. //this.layerElement.style.transform = 'translate3d(0,0,0)';
  5765. //this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  5766. this.animationItem.wrapper.appendChild(this.svgElement);
  5767. //Mask animation
  5768. var defs = this.globalData.defs;
  5769. this.setupGlobalData(animData, defs);
  5770. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  5771. this.data = animData;
  5772. var maskElement = createNS( 'clipPath');
  5773. var rect = createNS('rect');
  5774. rect.setAttribute('width',animData.w);
  5775. rect.setAttribute('height',animData.h);
  5776. rect.setAttribute('x',0);
  5777. rect.setAttribute('y',0);
  5778. var maskId = createElementID();
  5779. maskElement.setAttribute('id', maskId);
  5780. maskElement.appendChild(rect);
  5781. this.layerElement.setAttribute("clip-path", "url(" + locationHref + "#"+maskId+")");
  5782. defs.appendChild(maskElement);
  5783. this.layers = animData.layers;
  5784. this.elements = createSizedArray(animData.layers.length);
  5785. };
  5786. SVGRenderer.prototype.destroy = function () {
  5787. this.animationItem.wrapper.innerText = '';
  5788. this.layerElement = null;
  5789. this.globalData.defs = null;
  5790. var i, len = this.layers ? this.layers.length : 0;
  5791. for (i = 0; i < len; i++) {
  5792. if(this.elements[i]){
  5793. this.elements[i].destroy();
  5794. }
  5795. }
  5796. this.elements.length = 0;
  5797. this.destroyed = true;
  5798. this.animationItem = null;
  5799. };
  5800. SVGRenderer.prototype.updateContainerSize = function () {
  5801. };
  5802. SVGRenderer.prototype.buildItem = function(pos){
  5803. var elements = this.elements;
  5804. if(elements[pos] || this.layers[pos].ty == 99){
  5805. return;
  5806. }
  5807. elements[pos] = true;
  5808. var element = this.createItem(this.layers[pos]);
  5809. elements[pos] = element;
  5810. if(expressionsPlugin){
  5811. if(this.layers[pos].ty === 0){
  5812. this.globalData.projectInterface.registerComposition(element);
  5813. }
  5814. element.initExpressions();
  5815. }
  5816. this.appendElementInPos(element,pos);
  5817. if(this.layers[pos].tt){
  5818. if(!this.elements[pos - 1] || this.elements[pos - 1] === true){
  5819. this.buildItem(pos - 1);
  5820. this.addPendingElement(element);
  5821. } else {
  5822. element.setMatte(elements[pos - 1].layerId);
  5823. }
  5824. }
  5825. };
  5826. SVGRenderer.prototype.checkPendingElements = function(){
  5827. while(this.pendingElements.length){
  5828. var element = this.pendingElements.pop();
  5829. element.checkParenting();
  5830. if(element.data.tt){
  5831. var i = 0, len = this.elements.length;
  5832. while(i<len){
  5833. if(this.elements[i] === element){
  5834. element.setMatte(this.elements[i - 1].layerId);
  5835. break;
  5836. }
  5837. i += 1;
  5838. }
  5839. }
  5840. }
  5841. };
  5842. SVGRenderer.prototype.renderFrame = function(num){
  5843. if(this.renderedFrame === num || this.destroyed){
  5844. return;
  5845. }
  5846. if(num === null){
  5847. num = this.renderedFrame;
  5848. }else{
  5849. this.renderedFrame = num;
  5850. }
  5851. // console.log('-------');
  5852. // console.log('FRAME ',num);
  5853. this.globalData.frameNum = num;
  5854. this.globalData.frameId += 1;
  5855. this.globalData.projectInterface.currentFrame = num;
  5856. this.globalData._mdf = false;
  5857. var i, len = this.layers.length;
  5858. if(!this.completeLayers){
  5859. this.checkLayers(num);
  5860. }
  5861. for (i = len - 1; i >= 0; i--) {
  5862. if(this.completeLayers || this.elements[i]){
  5863. this.elements[i].prepareFrame(num - this.layers[i].st);
  5864. }
  5865. }
  5866. if(this.globalData._mdf) {
  5867. for (i = 0; i < len; i += 1) {
  5868. if(this.completeLayers || this.elements[i]){
  5869. this.elements[i].renderFrame();
  5870. }
  5871. }
  5872. }
  5873. };
  5874. SVGRenderer.prototype.appendElementInPos = function(element, pos){
  5875. var newElement = element.getBaseElement();
  5876. if(!newElement){
  5877. return;
  5878. }
  5879. var i = 0;
  5880. var nextElement;
  5881. while(i<pos){
  5882. if(this.elements[i] && this.elements[i]!== true && this.elements[i].getBaseElement()){
  5883. nextElement = this.elements[i].getBaseElement();
  5884. }
  5885. i += 1;
  5886. }
  5887. if(nextElement){
  5888. this.layerElement.insertBefore(newElement, nextElement);
  5889. } else {
  5890. this.layerElement.appendChild(newElement);
  5891. }
  5892. };
  5893. SVGRenderer.prototype.hide = function(){
  5894. this.layerElement.style.display = 'none';
  5895. };
  5896. SVGRenderer.prototype.show = function(){
  5897. this.layerElement.style.display = 'block';
  5898. };
  5899. function CanvasRenderer(animationItem, config){
  5900. this.animationItem = animationItem;
  5901. this.renderConfig = {
  5902. clearCanvas: (config && config.clearCanvas !== undefined) ? config.clearCanvas : true,
  5903. context: (config && config.context) || null,
  5904. progressiveLoad: (config && config.progressiveLoad) || false,
  5905. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  5906. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  5907. className: (config && config.className) || '',
  5908. id: (config && config.id) || '',
  5909. };
  5910. this.renderConfig.dpr = (config && config.dpr) || 1;
  5911. if (this.animationItem.wrapper) {
  5912. this.renderConfig.dpr = (config && config.dpr) || window.devicePixelRatio || 1;
  5913. }
  5914. this.renderedFrame = -1;
  5915. this.globalData = {
  5916. frameNum: -1,
  5917. _mdf: false,
  5918. renderConfig: this.renderConfig,
  5919. currentGlobalAlpha: -1
  5920. };
  5921. this.contextData = new CVContextData();
  5922. this.elements = [];
  5923. this.pendingElements = [];
  5924. this.transformMat = new Matrix();
  5925. this.completeLayers = false;
  5926. this.rendererType = 'canvas';
  5927. }
  5928. extendPrototype([BaseRenderer],CanvasRenderer);
  5929. CanvasRenderer.prototype.createShape = function (data) {
  5930. return new CVShapeElement(data, this.globalData, this);
  5931. };
  5932. CanvasRenderer.prototype.createText = function (data) {
  5933. return new CVTextElement(data, this.globalData, this);
  5934. };
  5935. CanvasRenderer.prototype.createImage = function (data) {
  5936. return new CVImageElement(data, this.globalData, this);
  5937. };
  5938. CanvasRenderer.prototype.createComp = function (data) {
  5939. return new CVCompElement(data, this.globalData, this);
  5940. };
  5941. CanvasRenderer.prototype.createSolid = function (data) {
  5942. return new CVSolidElement(data, this.globalData, this);
  5943. };
  5944. CanvasRenderer.prototype.createNull = SVGRenderer.prototype.createNull;
  5945. CanvasRenderer.prototype.ctxTransform = function(props){
  5946. if(props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0){
  5947. return;
  5948. }
  5949. if(!this.renderConfig.clearCanvas){
  5950. this.canvasContext.transform(props[0],props[1],props[4],props[5],props[12],props[13]);
  5951. return;
  5952. }
  5953. this.transformMat.cloneFromProps(props);
  5954. var cProps = this.contextData.cTr.props;
  5955. 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]);
  5956. //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]);
  5957. this.contextData.cTr.cloneFromProps(this.transformMat.props);
  5958. var trProps = this.contextData.cTr.props;
  5959. this.canvasContext.setTransform(trProps[0],trProps[1],trProps[4],trProps[5],trProps[12],trProps[13]);
  5960. };
  5961. CanvasRenderer.prototype.ctxOpacity = function(op){
  5962. /*if(op === 1){
  5963. return;
  5964. }*/
  5965. if(!this.renderConfig.clearCanvas){
  5966. this.canvasContext.globalAlpha *= op < 0 ? 0 : op;
  5967. this.globalData.currentGlobalAlpha = this.contextData.cO;
  5968. return;
  5969. }
  5970. this.contextData.cO *= op < 0 ? 0 : op;
  5971. if(this.globalData.currentGlobalAlpha !== this.contextData.cO) {
  5972. this.canvasContext.globalAlpha = this.contextData.cO;
  5973. this.globalData.currentGlobalAlpha = this.contextData.cO;
  5974. }
  5975. };
  5976. CanvasRenderer.prototype.reset = function(){
  5977. if(!this.renderConfig.clearCanvas){
  5978. this.canvasContext.restore();
  5979. return;
  5980. }
  5981. this.contextData.reset();
  5982. };
  5983. CanvasRenderer.prototype.save = function(actionFlag){
  5984. if(!this.renderConfig.clearCanvas){
  5985. this.canvasContext.save();
  5986. return;
  5987. }
  5988. if(actionFlag){
  5989. this.canvasContext.save();
  5990. }
  5991. var props = this.contextData.cTr.props;
  5992. if(this.contextData._length <= this.contextData.cArrPos) {
  5993. this.contextData.duplicate();
  5994. }
  5995. var i, arr = this.contextData.saved[this.contextData.cArrPos];
  5996. for (i = 0; i < 16; i += 1) {
  5997. arr[i] = props[i];
  5998. }
  5999. this.contextData.savedOp[this.contextData.cArrPos] = this.contextData.cO;
  6000. this.contextData.cArrPos += 1;
  6001. };
  6002. CanvasRenderer.prototype.restore = function(actionFlag){
  6003. if(!this.renderConfig.clearCanvas){
  6004. this.canvasContext.restore();
  6005. return;
  6006. }
  6007. if(actionFlag){
  6008. this.canvasContext.restore();
  6009. this.globalData.blendMode = 'source-over';
  6010. }
  6011. this.contextData.cArrPos -= 1;
  6012. var popped = this.contextData.saved[this.contextData.cArrPos];
  6013. var i,arr = this.contextData.cTr.props;
  6014. for(i=0;i<16;i+=1){
  6015. arr[i] = popped[i];
  6016. }
  6017. this.canvasContext.setTransform(popped[0],popped[1],popped[4],popped[5],popped[12],popped[13]);
  6018. popped = this.contextData.savedOp[this.contextData.cArrPos];
  6019. this.contextData.cO = popped;
  6020. if(this.globalData.currentGlobalAlpha !== popped) {
  6021. this.canvasContext.globalAlpha = popped;
  6022. this.globalData.currentGlobalAlpha = popped;
  6023. }
  6024. };
  6025. CanvasRenderer.prototype.configAnimation = function(animData){
  6026. if(this.animationItem.wrapper){
  6027. this.animationItem.container = createTag('canvas');
  6028. this.animationItem.container.style.width = '100%';
  6029. this.animationItem.container.style.height = '100%';
  6030. //this.animationItem.container.style.transform = 'translate3d(0,0,0)';
  6031. //this.animationItem.container.style.webkitTransform = 'translate3d(0,0,0)';
  6032. this.animationItem.container.style.transformOrigin = this.animationItem.container.style.mozTransformOrigin = this.animationItem.container.style.webkitTransformOrigin = this.animationItem.container.style['-webkit-transform'] = "0px 0px 0px";
  6033. this.animationItem.wrapper.appendChild(this.animationItem.container);
  6034. this.canvasContext = this.animationItem.container.getContext('2d');
  6035. if(this.renderConfig.className) {
  6036. this.animationItem.container.setAttribute('class', this.renderConfig.className);
  6037. }
  6038. if(this.renderConfig.id) {
  6039. this.animationItem.container.setAttribute('id', this.renderConfig.id);
  6040. }
  6041. }else{
  6042. this.canvasContext = this.renderConfig.context;
  6043. }
  6044. this.data = animData;
  6045. this.layers = animData.layers;
  6046. this.transformCanvas = {
  6047. w: animData.w,
  6048. h:animData.h,
  6049. sx:0,
  6050. sy:0,
  6051. tx:0,
  6052. ty:0
  6053. };
  6054. this.setupGlobalData(animData, document.body);
  6055. this.globalData.canvasContext = this.canvasContext;
  6056. this.globalData.renderer = this;
  6057. this.globalData.isDashed = false;
  6058. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  6059. this.globalData.transformCanvas = this.transformCanvas;
  6060. this.elements = createSizedArray(animData.layers.length);
  6061. this.updateContainerSize();
  6062. };
  6063. CanvasRenderer.prototype.updateContainerSize = function () {
  6064. this.reset();
  6065. var elementWidth,elementHeight;
  6066. if(this.animationItem.wrapper && this.animationItem.container){
  6067. elementWidth = this.animationItem.wrapper.offsetWidth;
  6068. elementHeight = this.animationItem.wrapper.offsetHeight;
  6069. this.animationItem.container.setAttribute('width',elementWidth * this.renderConfig.dpr );
  6070. this.animationItem.container.setAttribute('height',elementHeight * this.renderConfig.dpr);
  6071. }else{
  6072. elementWidth = this.canvasContext.canvas.width * this.renderConfig.dpr;
  6073. elementHeight = this.canvasContext.canvas.height * this.renderConfig.dpr;
  6074. }
  6075. var elementRel,animationRel;
  6076. if(this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1){
  6077. var par = this.renderConfig.preserveAspectRatio.split(' ');
  6078. var fillType = par[1] || 'meet';
  6079. var pos = par[0] || 'xMidYMid';
  6080. var xPos = pos.substr(0,4);
  6081. var yPos = pos.substr(4);
  6082. elementRel = elementWidth/elementHeight;
  6083. animationRel = this.transformCanvas.w/this.transformCanvas.h;
  6084. if(animationRel>elementRel && fillType === 'meet' || animationRel<elementRel && fillType === 'slice'){
  6085. this.transformCanvas.sx = elementWidth/(this.transformCanvas.w/this.renderConfig.dpr);
  6086. this.transformCanvas.sy = elementWidth/(this.transformCanvas.w/this.renderConfig.dpr);
  6087. }else{
  6088. this.transformCanvas.sx = elementHeight/(this.transformCanvas.h / this.renderConfig.dpr);
  6089. this.transformCanvas.sy = elementHeight/(this.transformCanvas.h / this.renderConfig.dpr);
  6090. }
  6091. if(xPos === 'xMid' && ((animationRel<elementRel && fillType==='meet') || (animationRel>elementRel && fillType === 'slice'))){
  6092. this.transformCanvas.tx = (elementWidth-this.transformCanvas.w*(elementHeight/this.transformCanvas.h))/2*this.renderConfig.dpr;
  6093. } else if(xPos === 'xMax' && ((animationRel<elementRel && fillType==='meet') || (animationRel>elementRel && fillType === 'slice'))){
  6094. this.transformCanvas.tx = (elementWidth-this.transformCanvas.w*(elementHeight/this.transformCanvas.h))*this.renderConfig.dpr;
  6095. } else {
  6096. this.transformCanvas.tx = 0;
  6097. }
  6098. if(yPos === 'YMid' && ((animationRel>elementRel && fillType==='meet') || (animationRel<elementRel && fillType === 'slice'))){
  6099. this.transformCanvas.ty = ((elementHeight-this.transformCanvas.h*(elementWidth/this.transformCanvas.w))/2)*this.renderConfig.dpr;
  6100. } else if(yPos === 'YMax' && ((animationRel>elementRel && fillType==='meet') || (animationRel<elementRel && fillType === 'slice'))){
  6101. this.transformCanvas.ty = ((elementHeight-this.transformCanvas.h*(elementWidth/this.transformCanvas.w)))*this.renderConfig.dpr;
  6102. } else {
  6103. this.transformCanvas.ty = 0;
  6104. }
  6105. }else if(this.renderConfig.preserveAspectRatio == 'none'){
  6106. this.transformCanvas.sx = elementWidth/(this.transformCanvas.w/this.renderConfig.dpr);
  6107. this.transformCanvas.sy = elementHeight/(this.transformCanvas.h/this.renderConfig.dpr);
  6108. this.transformCanvas.tx = 0;
  6109. this.transformCanvas.ty = 0;
  6110. }else{
  6111. this.transformCanvas.sx = this.renderConfig.dpr;
  6112. this.transformCanvas.sy = this.renderConfig.dpr;
  6113. this.transformCanvas.tx = 0;
  6114. this.transformCanvas.ty = 0;
  6115. }
  6116. 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];
  6117. /*var i, len = this.elements.length;
  6118. for(i=0;i<len;i+=1){
  6119. if(this.elements[i] && this.elements[i].data.ty === 0){
  6120. this.elements[i].resize(this.globalData.transformCanvas);
  6121. }
  6122. }*/
  6123. this.ctxTransform(this.transformCanvas.props);
  6124. this.canvasContext.beginPath();
  6125. this.canvasContext.rect(0,0,this.transformCanvas.w,this.transformCanvas.h);
  6126. this.canvasContext.closePath();
  6127. this.canvasContext.clip();
  6128. this.renderFrame(this.renderedFrame, true);
  6129. };
  6130. CanvasRenderer.prototype.destroy = function () {
  6131. if(this.renderConfig.clearCanvas) {
  6132. this.animationItem.wrapper.innerText = '';
  6133. }
  6134. var i, len = this.layers ? this.layers.length : 0;
  6135. for (i = len - 1; i >= 0; i-=1) {
  6136. if(this.elements[i]) {
  6137. this.elements[i].destroy();
  6138. }
  6139. }
  6140. this.elements.length = 0;
  6141. this.globalData.canvasContext = null;
  6142. this.animationItem.container = null;
  6143. this.destroyed = true;
  6144. };
  6145. CanvasRenderer.prototype.renderFrame = function(num, forceRender){
  6146. if((this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender) || this.destroyed || num === -1){
  6147. return;
  6148. }
  6149. this.renderedFrame = num;
  6150. this.globalData.frameNum = num - this.animationItem._isFirstFrame;
  6151. this.globalData.frameId += 1;
  6152. this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender;
  6153. this.globalData.projectInterface.currentFrame = num;
  6154. // console.log('--------');
  6155. // console.log('NEW: ',num);
  6156. var i, len = this.layers.length;
  6157. if(!this.completeLayers){
  6158. this.checkLayers(num);
  6159. }
  6160. for (i = 0; i < len; i++) {
  6161. if(this.completeLayers || this.elements[i]){
  6162. this.elements[i].prepareFrame(num - this.layers[i].st);
  6163. }
  6164. }
  6165. if(this.globalData._mdf) {
  6166. if(this.renderConfig.clearCanvas === true){
  6167. this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  6168. }else{
  6169. this.save();
  6170. }
  6171. for (i = len - 1; i >= 0; i-=1) {
  6172. if(this.completeLayers || this.elements[i]){
  6173. this.elements[i].renderFrame();
  6174. }
  6175. }
  6176. if(this.renderConfig.clearCanvas !== true){
  6177. this.restore();
  6178. }
  6179. }
  6180. };
  6181. CanvasRenderer.prototype.buildItem = function(pos){
  6182. var elements = this.elements;
  6183. if(elements[pos] || this.layers[pos].ty == 99){
  6184. return;
  6185. }
  6186. var element = this.createItem(this.layers[pos], this,this.globalData);
  6187. elements[pos] = element;
  6188. element.initExpressions();
  6189. /*if(this.layers[pos].ty === 0){
  6190. element.resize(this.globalData.transformCanvas);
  6191. }*/
  6192. };
  6193. CanvasRenderer.prototype.checkPendingElements = function(){
  6194. while(this.pendingElements.length){
  6195. var element = this.pendingElements.pop();
  6196. element.checkParenting();
  6197. }
  6198. };
  6199. CanvasRenderer.prototype.hide = function(){
  6200. this.animationItem.container.style.display = 'none';
  6201. };
  6202. CanvasRenderer.prototype.show = function(){
  6203. this.animationItem.container.style.display = 'block';
  6204. };
  6205. function MaskElement(data,element,globalData) {
  6206. this.data = data;
  6207. this.element = element;
  6208. this.globalData = globalData;
  6209. this.storedData = [];
  6210. this.masksProperties = this.data.masksProperties || [];
  6211. this.maskElement = null;
  6212. var defs = this.globalData.defs;
  6213. var i, len = this.masksProperties ? this.masksProperties.length : 0;
  6214. this.viewData = createSizedArray(len);
  6215. this.solidPath = '';
  6216. var path, properties = this.masksProperties;
  6217. var count = 0;
  6218. var currentMasks = [];
  6219. var j, jLen;
  6220. var layerId = createElementID();
  6221. var rect, expansor, feMorph,x;
  6222. var maskType = 'clipPath', maskRef = 'clip-path';
  6223. for (i = 0; i < len; i++) {
  6224. if((properties[i].mode !== 'a' && properties[i].mode !== 'n')|| properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x){
  6225. maskType = 'mask';
  6226. maskRef = 'mask';
  6227. }
  6228. if((properties[i].mode == 's' || properties[i].mode == 'i') && count === 0){
  6229. rect = createNS( 'rect');
  6230. rect.setAttribute('fill', '#ffffff');
  6231. rect.setAttribute('width', this.element.comp.data.w || 0);
  6232. rect.setAttribute('height', this.element.comp.data.h || 0);
  6233. currentMasks.push(rect);
  6234. } else {
  6235. rect = null;
  6236. }
  6237. path = createNS( 'path');
  6238. if(properties[i].mode == 'n') {
  6239. // TODO move this to a factory or to a constructor
  6240. this.viewData[i] = {
  6241. op: PropertyFactory.getProp(this.element,properties[i].o,0,0.01,this.element),
  6242. prop: ShapePropertyFactory.getShapeProp(this.element,properties[i],3),
  6243. elem: path,
  6244. lastPath: ''
  6245. };
  6246. defs.appendChild(path);
  6247. continue;
  6248. }
  6249. count += 1;
  6250. path.setAttribute('fill', properties[i].mode === 's' ? '#000000':'#ffffff');
  6251. path.setAttribute('clip-rule','nonzero');
  6252. var filterID;
  6253. if (properties[i].x.k !== 0) {
  6254. maskType = 'mask';
  6255. maskRef = 'mask';
  6256. x = PropertyFactory.getProp(this.element,properties[i].x,0,null,this.element);
  6257. filterID = createElementID();
  6258. expansor = createNS('filter');
  6259. expansor.setAttribute('id',filterID);
  6260. feMorph = createNS('feMorphology');
  6261. feMorph.setAttribute('operator','erode');
  6262. feMorph.setAttribute('in','SourceGraphic');
  6263. feMorph.setAttribute('radius','0');
  6264. expansor.appendChild(feMorph);
  6265. defs.appendChild(expansor);
  6266. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000':'#ffffff');
  6267. } else {
  6268. feMorph = null;
  6269. x = null;
  6270. }
  6271. // TODO move this to a factory or to a constructor
  6272. this.storedData[i] = {
  6273. elem: path,
  6274. x: x,
  6275. expan: feMorph,
  6276. lastPath: '',
  6277. lastOperator:'',
  6278. filterId:filterID,
  6279. lastRadius:0
  6280. };
  6281. if(properties[i].mode == 'i'){
  6282. jLen = currentMasks.length;
  6283. var g = createNS('g');
  6284. for(j=0;j<jLen;j+=1){
  6285. g.appendChild(currentMasks[j]);
  6286. }
  6287. var mask = createNS('mask');
  6288. mask.setAttribute('mask-type','alpha');
  6289. mask.setAttribute('id',layerId+'_'+count);
  6290. mask.appendChild(path);
  6291. defs.appendChild(mask);
  6292. g.setAttribute('mask','url(' + locationHref + '#'+layerId+'_'+count+')');
  6293. currentMasks.length = 0;
  6294. currentMasks.push(g);
  6295. }else{
  6296. currentMasks.push(path);
  6297. }
  6298. if(properties[i].inv && !this.solidPath){
  6299. this.solidPath = this.createLayerSolidPath();
  6300. }
  6301. // TODO move this to a factory or to a constructor
  6302. this.viewData[i] = {
  6303. elem: path,
  6304. lastPath: '',
  6305. op: PropertyFactory.getProp(this.element,properties[i].o,0,0.01,this.element),
  6306. prop:ShapePropertyFactory.getShapeProp(this.element,properties[i],3),
  6307. invRect: rect
  6308. };
  6309. if(!this.viewData[i].prop.k){
  6310. this.drawPath(properties[i],this.viewData[i].prop.v,this.viewData[i]);
  6311. }
  6312. }
  6313. this.maskElement = createNS( maskType);
  6314. len = currentMasks.length;
  6315. for(i=0;i<len;i+=1){
  6316. this.maskElement.appendChild(currentMasks[i]);
  6317. }
  6318. if(count > 0){
  6319. this.maskElement.setAttribute('id', layerId);
  6320. this.element.maskedElement.setAttribute(maskRef, "url(" + locationHref + "#" + layerId + ")");
  6321. defs.appendChild(this.maskElement);
  6322. }
  6323. if (this.viewData.length) {
  6324. this.element.addRenderableComponent(this);
  6325. }
  6326. }
  6327. MaskElement.prototype.getMaskProperty = function(pos){
  6328. return this.viewData[pos].prop;
  6329. };
  6330. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  6331. var finalMat = this.element.finalTransform.mat;
  6332. var i, len = this.masksProperties.length;
  6333. for (i = 0; i < len; i++) {
  6334. if(this.viewData[i].prop._mdf || isFirstFrame){
  6335. this.drawPath(this.masksProperties[i],this.viewData[i].prop.v,this.viewData[i]);
  6336. }
  6337. if(this.viewData[i].op._mdf || isFirstFrame){
  6338. this.viewData[i].elem.setAttribute('fill-opacity',this.viewData[i].op.v);
  6339. }
  6340. if(this.masksProperties[i].mode !== 'n'){
  6341. if(this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)){
  6342. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS())
  6343. }
  6344. if(this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)){
  6345. var feMorph = this.storedData[i].expan;
  6346. if(this.storedData[i].x.v < 0){
  6347. if(this.storedData[i].lastOperator !== 'erode'){
  6348. this.storedData[i].lastOperator = 'erode';
  6349. this.storedData[i].elem.setAttribute('filter','url(' + locationHref + '#'+this.storedData[i].filterId+')');
  6350. }
  6351. feMorph.setAttribute('radius',-this.storedData[i].x.v);
  6352. }else{
  6353. if(this.storedData[i].lastOperator !== 'dilate'){
  6354. this.storedData[i].lastOperator = 'dilate';
  6355. this.storedData[i].elem.setAttribute('filter',null);
  6356. }
  6357. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v*2);
  6358. }
  6359. }
  6360. }
  6361. }
  6362. };
  6363. MaskElement.prototype.getMaskelement = function () {
  6364. return this.maskElement;
  6365. };
  6366. MaskElement.prototype.createLayerSolidPath = function(){
  6367. var path = 'M0,0 ';
  6368. path += ' h' + this.globalData.compSize.w ;
  6369. path += ' v' + this.globalData.compSize.h ;
  6370. path += ' h-' + this.globalData.compSize.w ;
  6371. path += ' v-' + this.globalData.compSize.h + ' ';
  6372. return path;
  6373. };
  6374. MaskElement.prototype.drawPath = function(pathData,pathNodes,viewData){
  6375. var pathString = " M"+pathNodes.v[0][0]+','+pathNodes.v[0][1];
  6376. var i, len;
  6377. len = pathNodes._length;
  6378. for(i=1;i<len;i+=1){
  6379. //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];
  6380. 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];
  6381. }
  6382. //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];
  6383. if(pathNodes.c && len > 1){
  6384. 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];
  6385. }
  6386. //pathNodes.__renderedString = pathString;
  6387. if(viewData.lastPath !== pathString){
  6388. var pathShapeValue = '';
  6389. if(viewData.elem){
  6390. if(pathNodes.c){
  6391. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  6392. }
  6393. viewData.elem.setAttribute('d',pathShapeValue);
  6394. }
  6395. viewData.lastPath = pathString;
  6396. }
  6397. };
  6398. MaskElement.prototype.destroy = function(){
  6399. this.element = null;
  6400. this.globalData = null;
  6401. this.maskElement = null;
  6402. this.data = null;
  6403. this.masksProperties = null;
  6404. };
  6405. /**
  6406. * @file
  6407. * Handles AE's layer parenting property.
  6408. *
  6409. */
  6410. function HierarchyElement(){}
  6411. HierarchyElement.prototype = {
  6412. /**
  6413. * @function
  6414. * Initializes hierarchy properties
  6415. *
  6416. */
  6417. initHierarchy: function() {
  6418. //element's parent list
  6419. this.hierarchy = [];
  6420. //if element is parent of another layer _isParent will be true
  6421. this._isParent = false;
  6422. this.checkParenting();
  6423. },
  6424. /**
  6425. * @function
  6426. * Sets layer's hierarchy.
  6427. * @param {array} hierarch
  6428. * layer's parent list
  6429. *
  6430. */
  6431. setHierarchy: function(hierarchy){
  6432. this.hierarchy = hierarchy;
  6433. },
  6434. /**
  6435. * @function
  6436. * Sets layer as parent.
  6437. *
  6438. */
  6439. setAsParent: function() {
  6440. this._isParent = true;
  6441. },
  6442. /**
  6443. * @function
  6444. * Searches layer's parenting chain
  6445. *
  6446. */
  6447. checkParenting: function(){
  6448. if (this.data.parent !== undefined){
  6449. this.comp.buildElementParenting(this, this.data.parent, []);
  6450. }
  6451. }
  6452. };
  6453. /**
  6454. * @file
  6455. * Handles element's layer frame update.
  6456. * Checks layer in point and out point
  6457. *
  6458. */
  6459. function FrameElement(){}
  6460. FrameElement.prototype = {
  6461. /**
  6462. * @function
  6463. * Initializes frame related properties.
  6464. *
  6465. */
  6466. initFrame: function(){
  6467. //set to true when inpoint is rendered
  6468. this._isFirstFrame = false;
  6469. //list of animated properties
  6470. this.dynamicProperties = [];
  6471. // If layer has been modified in current tick this will be true
  6472. this._mdf = false;
  6473. },
  6474. /**
  6475. * @function
  6476. * Calculates all dynamic values
  6477. *
  6478. * @param {number} num
  6479. * current frame number in Layer's time
  6480. * @param {boolean} isVisible
  6481. * if layers is currently in range
  6482. *
  6483. */
  6484. prepareProperties: function(num, isVisible) {
  6485. var i, len = this.dynamicProperties.length;
  6486. for (i = 0;i < len; i += 1) {
  6487. if (isVisible || (this._isParent && this.dynamicProperties[i].propType === 'transform')) {
  6488. this.dynamicProperties[i].getValue();
  6489. if (this.dynamicProperties[i]._mdf) {
  6490. this.globalData._mdf = true;
  6491. this._mdf = true;
  6492. }
  6493. }
  6494. }
  6495. },
  6496. addDynamicProperty: function(prop) {
  6497. if(this.dynamicProperties.indexOf(prop) === -1) {
  6498. this.dynamicProperties.push(prop);
  6499. }
  6500. }
  6501. };
  6502. function TransformElement(){}
  6503. TransformElement.prototype = {
  6504. initTransform: function() {
  6505. this.finalTransform = {
  6506. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : {o:0},
  6507. _matMdf: false,
  6508. _opMdf: false,
  6509. mat: new Matrix()
  6510. };
  6511. if (this.data.ao) {
  6512. this.finalTransform.mProp.autoOriented = true;
  6513. }
  6514. //TODO: check TYPE 11: Guided elements
  6515. if (this.data.ty !== 11) {
  6516. //this.createElements();
  6517. }
  6518. },
  6519. renderTransform: function() {
  6520. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  6521. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  6522. if (this.hierarchy) {
  6523. var mat;
  6524. var finalMat = this.finalTransform.mat;
  6525. var i = 0, len = this.hierarchy.length;
  6526. //Checking if any of the transformation matrices in the hierarchy chain has changed.
  6527. if (!this.finalTransform._matMdf) {
  6528. while (i < len) {
  6529. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  6530. this.finalTransform._matMdf = true;
  6531. break;
  6532. }
  6533. i += 1;
  6534. }
  6535. }
  6536. if (this.finalTransform._matMdf) {
  6537. mat = this.finalTransform.mProp.v.props;
  6538. finalMat.cloneFromProps(mat);
  6539. for (i = 0; i < len; i += 1) {
  6540. mat = this.hierarchy[i].finalTransform.mProp.v.props;
  6541. 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]);
  6542. }
  6543. }
  6544. }
  6545. },
  6546. globalToLocal: function(pt) {
  6547. var transforms = [];
  6548. transforms.push(this.finalTransform);
  6549. var flag = true;
  6550. var comp = this.comp;
  6551. while (flag) {
  6552. if (comp.finalTransform) {
  6553. if (comp.data.hasMask) {
  6554. transforms.splice(0, 0, comp.finalTransform);
  6555. }
  6556. comp = comp.comp;
  6557. } else {
  6558. flag = false;
  6559. }
  6560. }
  6561. var i, len = transforms.length,ptNew;
  6562. for (i = 0; i < len; i += 1) {
  6563. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  6564. //ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  6565. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  6566. }
  6567. return pt;
  6568. },
  6569. mHelper: new Matrix()
  6570. };
  6571. function RenderableElement(){
  6572. }
  6573. RenderableElement.prototype = {
  6574. initRenderable: function() {
  6575. //layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6576. this.isInRange = false;
  6577. //layer's display state
  6578. this.hidden = false;
  6579. // If layer's transparency equals 0, it can be hidden
  6580. this.isTransparent = false;
  6581. //list of animated components
  6582. this.renderableComponents = [];
  6583. },
  6584. addRenderableComponent: function(component) {
  6585. if(this.renderableComponents.indexOf(component) === -1) {
  6586. this.renderableComponents.push(component);
  6587. }
  6588. },
  6589. removeRenderableComponent: function(component) {
  6590. if(this.renderableComponents.indexOf(component) !== -1) {
  6591. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6592. }
  6593. },
  6594. prepareRenderableFrame: function(num) {
  6595. this.checkLayerLimits(num);
  6596. },
  6597. checkTransparency: function(){
  6598. if(this.finalTransform.mProp.o.v <= 0) {
  6599. if(!this.isTransparent && this.globalData.renderConfig.hideOnTransparent){
  6600. this.isTransparent = true;
  6601. this.hide();
  6602. }
  6603. } else if(this.isTransparent) {
  6604. this.isTransparent = false;
  6605. this.show();
  6606. }
  6607. },
  6608. /**
  6609. * @function
  6610. * Initializes frame related properties.
  6611. *
  6612. * @param {number} num
  6613. * current frame number in Layer's time
  6614. *
  6615. */
  6616. checkLayerLimits: function(num) {
  6617. if(this.data.ip - this.data.st <= num && this.data.op - this.data.st > num)
  6618. {
  6619. if(this.isInRange !== true){
  6620. this.globalData._mdf = true;
  6621. this._mdf = true;
  6622. this.isInRange = true;
  6623. this.show();
  6624. }
  6625. } else {
  6626. if(this.isInRange !== false){
  6627. this.globalData._mdf = true;
  6628. this.isInRange = false;
  6629. this.hide();
  6630. }
  6631. }
  6632. },
  6633. renderRenderable: function() {
  6634. var i, len = this.renderableComponents.length;
  6635. for(i = 0; i < len; i += 1) {
  6636. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6637. }
  6638. /*this.maskManager.renderFrame(this.finalTransform.mat);
  6639. this.renderableEffectsManager.renderFrame(this._isFirstFrame);*/
  6640. },
  6641. sourceRectAtTime: function(){
  6642. return {
  6643. top:0,
  6644. left:0,
  6645. width:100,
  6646. height:100
  6647. };
  6648. },
  6649. getLayerSize: function(){
  6650. if(this.data.ty === 5){
  6651. return {w:this.data.textData.width,h:this.data.textData.height};
  6652. }else{
  6653. return {w:this.data.width,h:this.data.height};
  6654. }
  6655. }
  6656. };
  6657. function RenderableDOMElement() {}
  6658. (function(){
  6659. var _prototype = {
  6660. initElement: function(data,globalData,comp) {
  6661. this.initFrame();
  6662. this.initBaseData(data, globalData, comp);
  6663. this.initTransform(data, globalData, comp);
  6664. this.initHierarchy();
  6665. this.initRenderable();
  6666. this.initRendererElement();
  6667. this.createContainerElements();
  6668. this.createRenderableComponents();
  6669. this.createContent();
  6670. this.hide();
  6671. },
  6672. hide: function(){
  6673. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  6674. var elem = this.baseElement || this.layerElement;
  6675. elem.style.display = 'none';
  6676. this.hidden = true;
  6677. }
  6678. },
  6679. show: function(){
  6680. if (this.isInRange && !this.isTransparent){
  6681. if (!this.data.hd) {
  6682. var elem = this.baseElement || this.layerElement;
  6683. elem.style.display = 'block';
  6684. }
  6685. this.hidden = false;
  6686. this._isFirstFrame = true;
  6687. }
  6688. },
  6689. renderFrame: function() {
  6690. //If it is exported as hidden (data.hd === true) no need to render
  6691. //If it is not visible no need to render
  6692. if (this.data.hd || this.hidden) {
  6693. return;
  6694. }
  6695. this.renderTransform();
  6696. this.renderRenderable();
  6697. this.renderElement();
  6698. this.renderInnerContent();
  6699. if (this._isFirstFrame) {
  6700. this._isFirstFrame = false;
  6701. }
  6702. },
  6703. renderInnerContent: function() {},
  6704. prepareFrame: function(num) {
  6705. this._mdf = false;
  6706. this.prepareRenderableFrame(num);
  6707. this.prepareProperties(num, this.isInRange);
  6708. this.checkTransparency();
  6709. },
  6710. destroy: function(){
  6711. this.innerElem = null;
  6712. this.destroyBaseElement();
  6713. }
  6714. };
  6715. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  6716. }());
  6717. function ProcessedElement(element, position) {
  6718. this.elem = element;
  6719. this.pos = position;
  6720. }
  6721. function SVGShapeData(transformers, level, shape) {
  6722. this.caches = [];
  6723. this.styles = [];
  6724. this.transformers = transformers;
  6725. this.lStr = '';
  6726. this.sh = shape;
  6727. this.lvl = level;
  6728. //TODO find if there are some cases where _isAnimated can be false.
  6729. // For now, since shapes add up with other shapes. They have to be calculated every time.
  6730. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  6731. this._isAnimated = !!shape.k;
  6732. // TODO: commenting this for now since all shapes are animated
  6733. var i = 0, len = transformers.length;
  6734. while(i < len) {
  6735. if(transformers[i].mProps.dynamicProperties.length) {
  6736. this._isAnimated = true;
  6737. break;
  6738. }
  6739. i += 1;
  6740. }
  6741. }
  6742. SVGShapeData.prototype.setAsAnimated = function() {
  6743. this._isAnimated = true;
  6744. }
  6745. function ShapeGroupData() {
  6746. this.it = [];
  6747. this.prevViewData = [];
  6748. this.gr = createNS('g');
  6749. }
  6750. function ShapeTransformManager() {
  6751. this.sequences = {};
  6752. this.sequenceList = [];
  6753. this.transform_key_count = 0;
  6754. }
  6755. ShapeTransformManager.prototype = {
  6756. addTransformSequence: function(transforms) {
  6757. var i, len = transforms.length;
  6758. var key = '_';
  6759. for(i = 0; i < len; i += 1) {
  6760. key += transforms[i].transform.key + '_';
  6761. }
  6762. var sequence = this.sequences[key];
  6763. if(!sequence) {
  6764. sequence = {
  6765. transforms: [].concat(transforms),
  6766. finalTransform: new Matrix(),
  6767. _mdf: false
  6768. };
  6769. this.sequences[key] = sequence;
  6770. this.sequenceList.push(sequence);
  6771. }
  6772. return sequence;
  6773. },
  6774. processSequence: function(sequence, isFirstFrame) {
  6775. var i = 0, len = sequence.transforms.length, _mdf = isFirstFrame;
  6776. while (i < len && !isFirstFrame) {
  6777. if (sequence.transforms[i].transform.mProps._mdf) {
  6778. _mdf = true;
  6779. break;
  6780. }
  6781. i += 1
  6782. }
  6783. if (_mdf) {
  6784. var props;
  6785. sequence.finalTransform.reset();
  6786. for (i = len - 1; i >= 0; i -= 1) {
  6787. props = sequence.transforms[i].transform.mProps.v.props;
  6788. 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]);
  6789. }
  6790. }
  6791. sequence._mdf = _mdf;
  6792. },
  6793. processSequences: function(isFirstFrame) {
  6794. var i, len = this.sequenceList.length;
  6795. for (i = 0; i < len; i += 1) {
  6796. this.processSequence(this.sequenceList[i], isFirstFrame);
  6797. }
  6798. },
  6799. getNewKey: function() {
  6800. return '_' + this.transform_key_count++;
  6801. }
  6802. }
  6803. function CVShapeData(element, data, styles, transformsManager) {
  6804. this.styledShapes = [];
  6805. this.tr = [0,0,0,0,0,0];
  6806. var ty = 4;
  6807. if(data.ty == 'rc'){
  6808. ty = 5;
  6809. }else if(data.ty == 'el'){
  6810. ty = 6;
  6811. }else if(data.ty == 'sr'){
  6812. ty = 7;
  6813. }
  6814. this.sh = ShapePropertyFactory.getShapeProp(element,data,ty,element);
  6815. var i , len = styles.length,styledShape;
  6816. for (i = 0; i < len; i += 1) {
  6817. if (!styles[i].closed) {
  6818. styledShape = {
  6819. transforms: transformsManager.addTransformSequence(styles[i].transforms),
  6820. trNodes: []
  6821. }
  6822. this.styledShapes.push(styledShape);
  6823. styles[i].elements.push(styledShape);
  6824. }
  6825. }
  6826. }
  6827. CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated;
  6828. function BaseElement(){
  6829. }
  6830. BaseElement.prototype = {
  6831. checkMasks: function(){
  6832. if(!this.data.hasMask){
  6833. return false;
  6834. }
  6835. var i = 0, len = this.data.masksProperties.length;
  6836. while(i<len) {
  6837. if((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) {
  6838. return true;
  6839. }
  6840. i += 1;
  6841. }
  6842. return false;
  6843. },
  6844. initExpressions: function(){
  6845. this.layerInterface = LayerExpressionInterface(this);
  6846. if(this.data.hasMask && this.maskManager) {
  6847. this.layerInterface.registerMaskInterface(this.maskManager);
  6848. }
  6849. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this,this.layerInterface);
  6850. this.layerInterface.registerEffectsInterface(effectsInterface);
  6851. if(this.data.ty === 0 || this.data.xt){
  6852. this.compInterface = CompExpressionInterface(this);
  6853. } else if(this.data.ty === 4){
  6854. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData,this.itemsData,this.layerInterface);
  6855. this.layerInterface.content = this.layerInterface.shapeInterface;
  6856. } else if(this.data.ty === 5){
  6857. this.layerInterface.textInterface = TextExpressionInterface(this);
  6858. this.layerInterface.text = this.layerInterface.textInterface;
  6859. }
  6860. },
  6861. setBlendMode: function(){
  6862. var blendModeValue = getBlendMode(this.data.bm);
  6863. var elem = this.baseElement || this.layerElement;
  6864. elem.style['mix-blend-mode'] = blendModeValue;
  6865. },
  6866. initBaseData: function(data, globalData, comp){
  6867. this.globalData = globalData;
  6868. this.comp = comp;
  6869. this.data = data;
  6870. this.layerId = createElementID();
  6871. //Stretch factor for old animations missing this property.
  6872. if(!this.data.sr){
  6873. this.data.sr = 1;
  6874. }
  6875. // effects manager
  6876. this.effectsManager = new EffectsManager(this.data,this,this.dynamicProperties);
  6877. },
  6878. getType: function(){
  6879. return this.type;
  6880. }
  6881. ,sourceRectAtTime: function(){}
  6882. }
  6883. function NullElement(data,globalData,comp){
  6884. this.initFrame();
  6885. this.initBaseData(data, globalData, comp);
  6886. this.initFrame();
  6887. this.initTransform(data, globalData, comp);
  6888. this.initHierarchy();
  6889. }
  6890. NullElement.prototype.prepareFrame = function(num) {
  6891. this.prepareProperties(num, true);
  6892. };
  6893. NullElement.prototype.renderFrame = function() {
  6894. };
  6895. NullElement.prototype.getBaseElement = function() {
  6896. return null;
  6897. };
  6898. NullElement.prototype.destroy = function() {
  6899. };
  6900. NullElement.prototype.sourceRectAtTime = function() {
  6901. };
  6902. NullElement.prototype.hide = function() {
  6903. };
  6904. extendPrototype([BaseElement,TransformElement,HierarchyElement,FrameElement], NullElement);
  6905. function SVGBaseElement(){
  6906. }
  6907. SVGBaseElement.prototype = {
  6908. initRendererElement: function() {
  6909. this.layerElement = createNS('g');
  6910. },
  6911. createContainerElements: function(){
  6912. this.matteElement = createNS('g');
  6913. this.transformedElement = this.layerElement;
  6914. this.maskedElement = this.layerElement;
  6915. this._sizeChanged = false;
  6916. var layerElementParent = null;
  6917. //If this layer acts as a mask for the following layer
  6918. var filId, fil, gg;
  6919. if (this.data.td) {
  6920. if (this.data.td == 3 || this.data.td == 1) {
  6921. var masker = createNS('mask');
  6922. masker.setAttribute('id', this.layerId);
  6923. masker.setAttribute('mask-type', this.data.td == 3 ? 'luminance' : 'alpha');
  6924. masker.appendChild(this.layerElement);
  6925. layerElementParent = masker;
  6926. this.globalData.defs.appendChild(masker);
  6927. // This is only for IE and Edge when mask if of type alpha
  6928. if (!featureSupport.maskType && this.data.td == 1) {
  6929. masker.setAttribute('mask-type', 'luminance');
  6930. filId = createElementID();
  6931. fil = filtersFactory.createFilter(filId);
  6932. this.globalData.defs.appendChild(fil);
  6933. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  6934. gg = createNS('g');
  6935. gg.appendChild(this.layerElement);
  6936. layerElementParent = gg;
  6937. masker.appendChild(gg);
  6938. gg.setAttribute('filter','url(' + locationHref + '#' + filId + ')');
  6939. }
  6940. } else if(this.data.td == 2) {
  6941. var maskGroup = createNS('mask');
  6942. maskGroup.setAttribute('id', this.layerId);
  6943. maskGroup.setAttribute('mask-type','alpha');
  6944. var maskGrouper = createNS('g');
  6945. maskGroup.appendChild(maskGrouper);
  6946. filId = createElementID();
  6947. fil = filtersFactory.createFilter(filId);
  6948. ////
  6949. // This solution doesn't work on Android when meta tag with viewport attribute is set
  6950. /*var feColorMatrix = createNS('feColorMatrix');
  6951. feColorMatrix.setAttribute('type', 'matrix');
  6952. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  6953. feColorMatrix.setAttribute('values','1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 -1 1');
  6954. fil.appendChild(feColorMatrix);*/
  6955. ////
  6956. var feCTr = createNS('feComponentTransfer');
  6957. feCTr.setAttribute('in','SourceGraphic');
  6958. fil.appendChild(feCTr);
  6959. var feFunc = createNS('feFuncA');
  6960. feFunc.setAttribute('type','table');
  6961. feFunc.setAttribute('tableValues','1.0 0.0');
  6962. feCTr.appendChild(feFunc);
  6963. ////
  6964. this.globalData.defs.appendChild(fil);
  6965. var alphaRect = createNS('rect');
  6966. alphaRect.setAttribute('width', this.comp.data.w);
  6967. alphaRect.setAttribute('height', this.comp.data.h);
  6968. alphaRect.setAttribute('x','0');
  6969. alphaRect.setAttribute('y','0');
  6970. alphaRect.setAttribute('fill','#ffffff');
  6971. alphaRect.setAttribute('opacity','0');
  6972. maskGrouper.setAttribute('filter', 'url(' + locationHref + '#'+filId+')');
  6973. maskGrouper.appendChild(alphaRect);
  6974. maskGrouper.appendChild(this.layerElement);
  6975. layerElementParent = maskGrouper;
  6976. if (!featureSupport.maskType) {
  6977. maskGroup.setAttribute('mask-type', 'luminance');
  6978. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  6979. gg = createNS('g');
  6980. maskGrouper.appendChild(alphaRect);
  6981. gg.appendChild(this.layerElement);
  6982. layerElementParent = gg;
  6983. maskGrouper.appendChild(gg);
  6984. }
  6985. this.globalData.defs.appendChild(maskGroup);
  6986. }
  6987. } else if (this.data.tt) {
  6988. this.matteElement.appendChild(this.layerElement);
  6989. layerElementParent = this.matteElement;
  6990. this.baseElement = this.matteElement;
  6991. } else {
  6992. this.baseElement = this.layerElement;
  6993. }
  6994. if (this.data.ln) {
  6995. this.layerElement.setAttribute('id', this.data.ln);
  6996. }
  6997. if (this.data.cl) {
  6998. this.layerElement.setAttribute('class', this.data.cl);
  6999. }
  7000. //Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7001. if (this.data.ty === 0 && !this.data.hd) {
  7002. var cp = createNS( 'clipPath');
  7003. var pt = createNS('path');
  7004. pt.setAttribute('d','M0,0 L' + this.data.w + ',0' + ' L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7005. var clipId = createElementID();
  7006. cp.setAttribute('id',clipId);
  7007. cp.appendChild(pt);
  7008. this.globalData.defs.appendChild(cp);
  7009. if (this.checkMasks()) {
  7010. var cpGroup = createNS('g');
  7011. cpGroup.setAttribute('clip-path','url(' + locationHref + '#'+clipId + ')');
  7012. cpGroup.appendChild(this.layerElement);
  7013. this.transformedElement = cpGroup;
  7014. if (layerElementParent) {
  7015. layerElementParent.appendChild(this.transformedElement);
  7016. } else {
  7017. this.baseElement = this.transformedElement;
  7018. }
  7019. } else {
  7020. this.layerElement.setAttribute('clip-path','url(' + locationHref + '#'+clipId+')');
  7021. }
  7022. }
  7023. if (this.data.bm !== 0) {
  7024. this.setBlendMode();
  7025. }
  7026. },
  7027. renderElement: function() {
  7028. if (this.finalTransform._matMdf) {
  7029. this.transformedElement.setAttribute('transform', this.finalTransform.mat.to2dCSS());
  7030. }
  7031. if (this.finalTransform._opMdf) {
  7032. this.transformedElement.setAttribute('opacity', this.finalTransform.mProp.o.v);
  7033. }
  7034. },
  7035. destroyBaseElement: function() {
  7036. this.layerElement = null;
  7037. this.matteElement = null;
  7038. this.maskManager.destroy();
  7039. },
  7040. getBaseElement: function() {
  7041. if (this.data.hd) {
  7042. return null;
  7043. }
  7044. return this.baseElement;
  7045. },
  7046. createRenderableComponents: function() {
  7047. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7048. this.renderableEffectsManager = new SVGEffects(this);
  7049. },
  7050. setMatte: function(id) {
  7051. if (!this.matteElement) {
  7052. return;
  7053. }
  7054. this.matteElement.setAttribute("mask", "url(" + locationHref + "#" + id + ")");
  7055. }
  7056. };
  7057. function IShapeElement(){
  7058. }
  7059. IShapeElement.prototype = {
  7060. addShapeToModifiers: function(data) {
  7061. var i, len = this.shapeModifiers.length;
  7062. for(i=0;i<len;i+=1){
  7063. this.shapeModifiers[i].addShape(data);
  7064. }
  7065. },
  7066. isShapeInAnimatedModifiers: function(data) {
  7067. var i = 0, len = this.shapeModifiers.length;
  7068. while(i < len) {
  7069. if(this.shapeModifiers[i].isAnimatedWithShape(data)) {
  7070. return true;
  7071. }
  7072. }
  7073. return false;
  7074. },
  7075. renderModifiers: function() {
  7076. if(!this.shapeModifiers.length){
  7077. return;
  7078. }
  7079. var i, len = this.shapes.length;
  7080. for(i=0;i<len;i+=1){
  7081. this.shapes[i].sh.reset();
  7082. }
  7083. len = this.shapeModifiers.length;
  7084. for(i=len-1;i>=0;i-=1){
  7085. this.shapeModifiers[i].processShapes(this._isFirstFrame);
  7086. }
  7087. },
  7088. lcEnum: {
  7089. '1': 'butt',
  7090. '2': 'round',
  7091. '3': 'square'
  7092. },
  7093. ljEnum: {
  7094. '1': 'miter',
  7095. '2': 'round',
  7096. '3': 'bevel'
  7097. },
  7098. searchProcessedElement: function(elem){
  7099. var elements = this.processedElements;
  7100. var i = 0, len = elements.length;
  7101. while (i < len) {
  7102. if (elements[i].elem === elem) {
  7103. return elements[i].pos;
  7104. }
  7105. i += 1;
  7106. }
  7107. return 0;
  7108. },
  7109. addProcessedElement: function(elem, pos){
  7110. var elements = this.processedElements;
  7111. var i = elements.length;
  7112. while(i) {
  7113. i -= 1;
  7114. if (elements[i].elem === elem) {
  7115. elements[i].pos = pos;
  7116. return;
  7117. }
  7118. }
  7119. elements.push(new ProcessedElement(elem, pos));
  7120. },
  7121. prepareFrame: function(num) {
  7122. this.prepareRenderableFrame(num);
  7123. this.prepareProperties(num, this.isInRange);
  7124. }
  7125. };
  7126. function ITextElement(){
  7127. }
  7128. ITextElement.prototype.initElement = function(data,globalData,comp){
  7129. this.lettersChangedFlag = true;
  7130. this.initFrame();
  7131. this.initBaseData(data, globalData, comp);
  7132. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  7133. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  7134. this.initTransform(data, globalData, comp);
  7135. this.initHierarchy();
  7136. this.initRenderable();
  7137. this.initRendererElement();
  7138. this.createContainerElements();
  7139. this.createRenderableComponents();
  7140. this.createContent();
  7141. this.hide();
  7142. this.textAnimator.searchProperties(this.dynamicProperties);
  7143. };
  7144. ITextElement.prototype.prepareFrame = function(num) {
  7145. this._mdf = false;
  7146. this.prepareRenderableFrame(num);
  7147. this.prepareProperties(num, this.isInRange);
  7148. if(this.textProperty._mdf || this.textProperty._isFirstFrame) {
  7149. this.buildNewText();
  7150. this.textProperty._isFirstFrame = false;
  7151. this.textProperty._mdf = false;
  7152. }
  7153. };
  7154. ITextElement.prototype.createPathShape = function(matrixHelper, shapes) {
  7155. var j,jLen = shapes.length;
  7156. var k, kLen, pathNodes;
  7157. var shapeStr = '';
  7158. for(j=0;j<jLen;j+=1){
  7159. pathNodes = shapes[j].ks.k;
  7160. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  7161. }
  7162. return shapeStr;
  7163. };
  7164. ITextElement.prototype.updateDocumentData = function(newData, index) {
  7165. this.textProperty.updateDocumentData(newData, index);
  7166. };
  7167. ITextElement.prototype.canResizeFont = function(_canResize) {
  7168. this.textProperty.canResizeFont(_canResize);
  7169. };
  7170. ITextElement.prototype.setMinimumFontSize = function(_fontSize) {
  7171. this.textProperty.setMinimumFontSize(_fontSize);
  7172. };
  7173. ITextElement.prototype.applyTextPropertiesToMatrix = function(documentData, matrixHelper, lineNumber, xPos, yPos) {
  7174. if(documentData.ps){
  7175. matrixHelper.translate(documentData.ps[0],documentData.ps[1] + documentData.ascent,0);
  7176. }
  7177. matrixHelper.translate(0,-documentData.ls,0);
  7178. switch(documentData.j){
  7179. case 1:
  7180. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]),0,0);
  7181. break;
  7182. case 2:
  7183. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber] )/2,0,0);
  7184. break;
  7185. }
  7186. matrixHelper.translate(xPos, yPos, 0);
  7187. };
  7188. ITextElement.prototype.buildColor = function(colorData) {
  7189. return 'rgb(' + Math.round(colorData[0]*255) + ',' + Math.round(colorData[1]*255) + ',' + Math.round(colorData[2]*255) + ')';
  7190. };
  7191. ITextElement.prototype.emptyProp = new LetterProps();
  7192. ITextElement.prototype.destroy = function(){
  7193. };
  7194. function ICompElement(){}
  7195. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  7196. ICompElement.prototype.initElement = function(data,globalData,comp) {
  7197. this.initFrame();
  7198. this.initBaseData(data, globalData, comp);
  7199. this.initTransform(data, globalData, comp);
  7200. this.initRenderable();
  7201. this.initHierarchy();
  7202. this.initRendererElement();
  7203. this.createContainerElements();
  7204. this.createRenderableComponents();
  7205. if(this.data.xt || !globalData.progressiveLoad){
  7206. this.buildAllItems();
  7207. }
  7208. this.hide();
  7209. };
  7210. /*ICompElement.prototype.hide = function(){
  7211. if(!this.hidden){
  7212. this.hideElement();
  7213. var i,len = this.elements.length;
  7214. for( i = 0; i < len; i+=1 ){
  7215. if(this.elements[i]){
  7216. this.elements[i].hide();
  7217. }
  7218. }
  7219. }
  7220. };*/
  7221. ICompElement.prototype.prepareFrame = function(num){
  7222. this._mdf = false;
  7223. this.prepareRenderableFrame(num);
  7224. this.prepareProperties(num, this.isInRange);
  7225. if(!this.isInRange && !this.data.xt){
  7226. return;
  7227. }
  7228. if (!this.tm._placeholder) {
  7229. var timeRemapped = this.tm.v;
  7230. if(timeRemapped === this.data.op){
  7231. timeRemapped = this.data.op - 1;
  7232. }
  7233. this.renderedFrame = timeRemapped;
  7234. } else {
  7235. this.renderedFrame = num/this.data.sr;
  7236. }
  7237. var i,len = this.elements.length;
  7238. if(!this.completeLayers){
  7239. this.checkLayers(this.renderedFrame);
  7240. }
  7241. //This iteration needs to be backwards because of how expressions connect between each other
  7242. for( i = len - 1; i >= 0; i -= 1 ){
  7243. if(this.completeLayers || this.elements[i]){
  7244. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  7245. if(this.elements[i]._mdf) {
  7246. this._mdf = true;
  7247. }
  7248. }
  7249. }
  7250. };
  7251. ICompElement.prototype.renderInnerContent = function() {
  7252. var i,len = this.layers.length;
  7253. for( i = 0; i < len; i += 1 ){
  7254. if(this.completeLayers || this.elements[i]){
  7255. this.elements[i].renderFrame();
  7256. }
  7257. }
  7258. };
  7259. ICompElement.prototype.setElements = function(elems){
  7260. this.elements = elems;
  7261. };
  7262. ICompElement.prototype.getElements = function(){
  7263. return this.elements;
  7264. };
  7265. ICompElement.prototype.destroyElements = function(){
  7266. var i,len = this.layers.length;
  7267. for( i = 0; i < len; i+=1 ){
  7268. if(this.elements[i]){
  7269. this.elements[i].destroy();
  7270. }
  7271. }
  7272. };
  7273. ICompElement.prototype.destroy = function(){
  7274. this.destroyElements();
  7275. this.destroyBaseElement();
  7276. };
  7277. function IImageElement(data,globalData,comp){
  7278. this.assetData = globalData.getAssetData(data.refId);
  7279. this.initElement(data,globalData,comp);
  7280. this.sourceRect = {top:0,left:0,width:this.assetData.w,height:this.assetData.h};
  7281. }
  7282. extendPrototype([BaseElement,TransformElement,SVGBaseElement,HierarchyElement,FrameElement,RenderableDOMElement], IImageElement);
  7283. IImageElement.prototype.createContent = function(){
  7284. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7285. this.innerElem = createNS('image');
  7286. this.innerElem.setAttribute('width',this.assetData.w+"px");
  7287. this.innerElem.setAttribute('height',this.assetData.h+"px");
  7288. this.innerElem.setAttribute('preserveAspectRatio',this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7289. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink','href',assetPath);
  7290. this.layerElement.appendChild(this.innerElem);
  7291. };
  7292. IImageElement.prototype.sourceRectAtTime = function() {
  7293. return this.sourceRect;
  7294. }
  7295. function ISolidElement(data,globalData,comp){
  7296. this.initElement(data,globalData,comp);
  7297. }
  7298. extendPrototype([IImageElement], ISolidElement);
  7299. ISolidElement.prototype.createContent = function(){
  7300. var rect = createNS('rect');
  7301. ////rect.style.width = this.data.sw;
  7302. ////rect.style.height = this.data.sh;
  7303. ////rect.style.fill = this.data.sc;
  7304. rect.setAttribute('width',this.data.sw);
  7305. rect.setAttribute('height',this.data.sh);
  7306. rect.setAttribute('fill',this.data.sc);
  7307. this.layerElement.appendChild(rect);
  7308. };
  7309. function AudioElement(data,globalData,comp){
  7310. this.initFrame();
  7311. this.initRenderable();
  7312. this.assetData = globalData.getAssetData(data.refId);
  7313. this.initBaseData(data, globalData, comp);
  7314. this._isPlaying = false;
  7315. this._canPlay = false;
  7316. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7317. this.audio = this.globalData.audioController.createAudio(assetPath);
  7318. this._currentTime = 0;
  7319. this.globalData.audioController.addAudio(this);
  7320. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate,this) : {_placeholder:true};
  7321. }
  7322. AudioElement.prototype.prepareFrame = function(num) {
  7323. this.prepareRenderableFrame(num, true);
  7324. this.prepareProperties(num, true);
  7325. if (!this.tm._placeholder) {
  7326. var timeRemapped = this.tm.v;
  7327. this._currentTime = timeRemapped;
  7328. } else {
  7329. this._currentTime = num / this.data.sr;
  7330. }
  7331. };
  7332. extendPrototype([RenderableElement,BaseElement,FrameElement], AudioElement);
  7333. AudioElement.prototype.renderFrame = function() {
  7334. if (this.isInRange && this._canPlay) {
  7335. if (!this._isPlaying) {
  7336. this.audio.play();
  7337. this.audio.seek(this._currentTime / this.globalData.frameRate);
  7338. this._isPlaying = true;
  7339. } else if (!this.audio.playing()
  7340. || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1
  7341. ) {
  7342. this.audio.seek(this._currentTime / this.globalData.frameRate)
  7343. }
  7344. }
  7345. };
  7346. AudioElement.prototype.show = function() {
  7347. // this.audio.play()
  7348. };
  7349. AudioElement.prototype.hide = function() {
  7350. this.audio.pause();
  7351. this._isPlaying = false;
  7352. };
  7353. AudioElement.prototype.pause = function() {
  7354. this.audio.pause();
  7355. this._isPlaying = false;
  7356. this._canPlay = false;
  7357. };
  7358. AudioElement.prototype.resume = function() {
  7359. this._canPlay = true;
  7360. };
  7361. AudioElement.prototype.setRate = function(rateValue) {
  7362. this.audio.rate(rateValue);
  7363. };
  7364. AudioElement.prototype.volume = function(volumeValue) {
  7365. this.audio.volume(volumeValue);
  7366. };
  7367. AudioElement.prototype.getBaseElement = function() {
  7368. return null;
  7369. };
  7370. AudioElement.prototype.destroy = function() {
  7371. };
  7372. AudioElement.prototype.sourceRectAtTime = function() {
  7373. };
  7374. AudioElement.prototype.initExpressions = function() {
  7375. };
  7376. function SVGShapeElement(data,globalData,comp){
  7377. //List of drawable elements
  7378. this.shapes = [];
  7379. // Full shape data
  7380. this.shapesData = data.shapes;
  7381. //List of styles that will be applied to shapes
  7382. this.stylesList = [];
  7383. //List of modifiers that will be applied to shapes
  7384. this.shapeModifiers = [];
  7385. //List of items in shape tree
  7386. this.itemsData = [];
  7387. //List of items in previous shape tree
  7388. this.processedElements = [];
  7389. // List of animated components
  7390. this.animatedContents = [];
  7391. this.initElement(data,globalData,comp);
  7392. //Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  7393. // List of elements that have been created
  7394. this.prevViewData = [];
  7395. //Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  7396. }
  7397. extendPrototype([BaseElement,TransformElement,SVGBaseElement,IShapeElement,HierarchyElement,FrameElement,RenderableDOMElement], SVGShapeElement);
  7398. SVGShapeElement.prototype.initSecondaryElement = function() {
  7399. };
  7400. SVGShapeElement.prototype.identityMatrix = new Matrix();
  7401. SVGShapeElement.prototype.buildExpressionInterface = function(){};
  7402. SVGShapeElement.prototype.createContent = function(){
  7403. this.searchShapes(this.shapesData,this.itemsData,this.prevViewData,this.layerElement, 0, [], true);
  7404. this.filterUniqueShapes();
  7405. };
  7406. /*
  7407. This method searches for multiple shapes that affect a single element and one of them is animated
  7408. */
  7409. SVGShapeElement.prototype.filterUniqueShapes = function(){
  7410. var i, len = this.shapes.length, shape;
  7411. var j, jLen = this.stylesList.length;
  7412. var style, count = 0;
  7413. var tempShapes = [];
  7414. var areAnimated = false;
  7415. for(j = 0; j < jLen; j += 1) {
  7416. style = this.stylesList[j];
  7417. areAnimated = false;
  7418. tempShapes.length = 0;
  7419. for(i = 0; i < len; i += 1) {
  7420. shape = this.shapes[i];
  7421. if(shape.styles.indexOf(style) !== -1) {
  7422. tempShapes.push(shape);
  7423. areAnimated = shape._isAnimated || areAnimated;
  7424. }
  7425. }
  7426. if(tempShapes.length > 1 && areAnimated) {
  7427. this.setShapesAsAnimated(tempShapes);
  7428. }
  7429. }
  7430. }
  7431. SVGShapeElement.prototype.setShapesAsAnimated = function(shapes){
  7432. var i, len = shapes.length;
  7433. for(i = 0; i < len; i += 1) {
  7434. shapes[i].setAsAnimated();
  7435. }
  7436. }
  7437. SVGShapeElement.prototype.createStyleElement = function(data, level){
  7438. //TODO: prevent drawing of hidden styles
  7439. var elementData;
  7440. var styleOb = new SVGStyleData(data, level);
  7441. var pathElement = styleOb.pElem;
  7442. if(data.ty === 'st') {
  7443. elementData = new SVGStrokeStyleData(this, data, styleOb);
  7444. } else if(data.ty === 'fl') {
  7445. elementData = new SVGFillStyleData(this, data, styleOb);
  7446. } else if(data.ty === 'gf' || data.ty === 'gs') {
  7447. var gradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  7448. elementData = new gradientConstructor(this, data, styleOb);
  7449. this.globalData.defs.appendChild(elementData.gf);
  7450. if (elementData.maskId) {
  7451. this.globalData.defs.appendChild(elementData.ms);
  7452. this.globalData.defs.appendChild(elementData.of);
  7453. pathElement.setAttribute('mask','url(' + locationHref + '#' + elementData.maskId + ')');
  7454. }
  7455. }
  7456. if(data.ty === 'st' || data.ty === 'gs') {
  7457. pathElement.setAttribute('stroke-linecap', this.lcEnum[data.lc] || 'round');
  7458. pathElement.setAttribute('stroke-linejoin',this.ljEnum[data.lj] || 'round');
  7459. pathElement.setAttribute('fill-opacity','0');
  7460. if(data.lj === 1) {
  7461. pathElement.setAttribute('stroke-miterlimit',data.ml);
  7462. }
  7463. }
  7464. if(data.r === 2) {
  7465. pathElement.setAttribute('fill-rule', 'evenodd');
  7466. }
  7467. if(data.ln){
  7468. pathElement.setAttribute('id',data.ln);
  7469. }
  7470. if(data.cl){
  7471. pathElement.setAttribute('class',data.cl);
  7472. }
  7473. if(data.bm){
  7474. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  7475. }
  7476. this.stylesList.push(styleOb);
  7477. this.addToAnimatedContents(data, elementData);
  7478. return elementData;
  7479. };
  7480. SVGShapeElement.prototype.createGroupElement = function(data) {
  7481. var elementData = new ShapeGroupData();
  7482. if(data.ln){
  7483. elementData.gr.setAttribute('id',data.ln);
  7484. }
  7485. if(data.cl){
  7486. elementData.gr.setAttribute('class',data.cl);
  7487. }
  7488. if(data.bm){
  7489. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  7490. }
  7491. return elementData;
  7492. };
  7493. SVGShapeElement.prototype.createTransformElement = function(data, container) {
  7494. var transformProperty = TransformPropertyFactory.getTransformProperty(this,data,this);
  7495. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  7496. this.addToAnimatedContents(data, elementData);
  7497. return elementData;
  7498. };
  7499. SVGShapeElement.prototype.createShapeElement = function(data, ownTransformers, level) {
  7500. var ty = 4;
  7501. if(data.ty === 'rc'){
  7502. ty = 5;
  7503. }else if(data.ty === 'el'){
  7504. ty = 6;
  7505. }else if(data.ty === 'sr'){
  7506. ty = 7;
  7507. }
  7508. var shapeProperty = ShapePropertyFactory.getShapeProp(this,data,ty,this);
  7509. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  7510. this.shapes.push(elementData);
  7511. this.addShapeToModifiers(elementData);
  7512. this.addToAnimatedContents(data, elementData);
  7513. return elementData;
  7514. };
  7515. SVGShapeElement.prototype.addToAnimatedContents = function(data, element) {
  7516. var i = 0, len = this.animatedContents.length;
  7517. while(i < len) {
  7518. if(this.animatedContents[i].element === element) {
  7519. return;
  7520. }
  7521. i += 1;
  7522. }
  7523. this.animatedContents.push({
  7524. fn: SVGElementsRenderer.createRenderFunction(data),
  7525. element: element,
  7526. data: data
  7527. });
  7528. };
  7529. SVGShapeElement.prototype.setElementStyles = function(elementData){
  7530. var arr = elementData.styles;
  7531. var j, jLen = this.stylesList.length;
  7532. for (j = 0; j < jLen; j += 1) {
  7533. if (!this.stylesList[j].closed) {
  7534. arr.push(this.stylesList[j]);
  7535. }
  7536. }
  7537. };
  7538. SVGShapeElement.prototype.reloadShapes = function(){
  7539. this._isFirstFrame = true;
  7540. var i, len = this.itemsData.length;
  7541. for( i = 0; i < len; i += 1) {
  7542. this.prevViewData[i] = this.itemsData[i];
  7543. }
  7544. this.searchShapes(this.shapesData,this.itemsData,this.prevViewData,this.layerElement, 0, [], true);
  7545. this.filterUniqueShapes();
  7546. len = this.dynamicProperties.length;
  7547. for(i = 0; i < len; i += 1) {
  7548. this.dynamicProperties[i].getValue();
  7549. }
  7550. this.renderModifiers();
  7551. };
  7552. SVGShapeElement.prototype.searchShapes = function(arr,itemsData,prevViewData,container, level, transformers, render){
  7553. var ownTransformers = [].concat(transformers);
  7554. var i, len = arr.length - 1;
  7555. var j, jLen;
  7556. var ownStyles = [], ownModifiers = [], styleOb, currentTransform, modifier, processedPos;
  7557. for(i=len;i>=0;i-=1){
  7558. processedPos = this.searchProcessedElement(arr[i]);
  7559. if(!processedPos){
  7560. arr[i]._render = render;
  7561. } else {
  7562. itemsData[i] = prevViewData[processedPos - 1];
  7563. }
  7564. if(arr[i].ty == 'fl' || arr[i].ty == 'st' || arr[i].ty == 'gf' || arr[i].ty == 'gs'){
  7565. if(!processedPos){
  7566. itemsData[i] = this.createStyleElement(arr[i], level);
  7567. } else {
  7568. itemsData[i].style.closed = false;
  7569. }
  7570. if(arr[i]._render){
  7571. container.appendChild(itemsData[i].style.pElem);
  7572. }
  7573. ownStyles.push(itemsData[i].style);
  7574. }else if(arr[i].ty == 'gr'){
  7575. if(!processedPos){
  7576. itemsData[i] = this.createGroupElement(arr[i]);
  7577. } else {
  7578. jLen = itemsData[i].it.length;
  7579. for(j=0;j<jLen;j+=1){
  7580. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  7581. }
  7582. }
  7583. this.searchShapes(arr[i].it,itemsData[i].it,itemsData[i].prevViewData,itemsData[i].gr, level + 1, ownTransformers, render);
  7584. if(arr[i]._render){
  7585. container.appendChild(itemsData[i].gr);
  7586. }
  7587. }else if(arr[i].ty == 'tr'){
  7588. if(!processedPos){
  7589. itemsData[i] = this.createTransformElement(arr[i], container);
  7590. }
  7591. currentTransform = itemsData[i].transform;
  7592. ownTransformers.push(currentTransform);
  7593. }else if(arr[i].ty == 'sh' || arr[i].ty == 'rc' || arr[i].ty == 'el' || arr[i].ty == 'sr'){
  7594. if(!processedPos){
  7595. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  7596. }
  7597. this.setElementStyles(itemsData[i]);
  7598. }else if(arr[i].ty == 'tm' || arr[i].ty == 'rd' || arr[i].ty == 'ms' || arr[i].ty == 'pb'){
  7599. if(!processedPos){
  7600. modifier = ShapeModifiers.getModifier(arr[i].ty);
  7601. modifier.init(this,arr[i]);
  7602. itemsData[i] = modifier;
  7603. this.shapeModifiers.push(modifier);
  7604. } else {
  7605. modifier = itemsData[i];
  7606. modifier.closed = false;
  7607. }
  7608. ownModifiers.push(modifier);
  7609. }else if(arr[i].ty == 'rp'){
  7610. if(!processedPos){
  7611. modifier = ShapeModifiers.getModifier(arr[i].ty);
  7612. itemsData[i] = modifier;
  7613. modifier.init(this,arr,i,itemsData);
  7614. this.shapeModifiers.push(modifier);
  7615. render = false;
  7616. }else{
  7617. modifier = itemsData[i];
  7618. modifier.closed = true;
  7619. }
  7620. ownModifiers.push(modifier);
  7621. }
  7622. this.addProcessedElement(arr[i], i + 1);
  7623. }
  7624. len = ownStyles.length;
  7625. for(i=0;i<len;i+=1){
  7626. ownStyles[i].closed = true;
  7627. }
  7628. len = ownModifiers.length;
  7629. for(i=0;i<len;i+=1){
  7630. ownModifiers[i].closed = true;
  7631. }
  7632. };
  7633. SVGShapeElement.prototype.renderInnerContent = function() {
  7634. this.renderModifiers();
  7635. var i, len = this.stylesList.length;
  7636. for(i=0;i<len;i+=1){
  7637. this.stylesList[i].reset();
  7638. }
  7639. this.renderShape();
  7640. for (i = 0; i < len; i += 1) {
  7641. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  7642. if(this.stylesList[i].msElem){
  7643. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  7644. //Adding M0 0 fixes same mask bug on all browsers
  7645. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  7646. }
  7647. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  7648. }
  7649. }
  7650. };
  7651. SVGShapeElement.prototype.renderShape = function() {
  7652. var i, len = this.animatedContents.length;
  7653. var animatedContent;
  7654. for(i = 0; i < len; i += 1) {
  7655. animatedContent = this.animatedContents[i];
  7656. if((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  7657. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  7658. }
  7659. }
  7660. }
  7661. SVGShapeElement.prototype.destroy = function(){
  7662. this.destroyBaseElement();
  7663. this.shapesData = null;
  7664. this.itemsData = null;
  7665. };
  7666. function CVContextData() {
  7667. this.saved = [];
  7668. this.cArrPos = 0;
  7669. this.cTr = new Matrix();
  7670. this.cO = 1;
  7671. var i, len = 15;
  7672. this.savedOp = createTypedArray('float32', len);
  7673. for(i=0;i<len;i+=1){
  7674. this.saved[i] = createTypedArray('float32', 16);
  7675. }
  7676. this._length = len;
  7677. }
  7678. CVContextData.prototype.duplicate = function() {
  7679. var newLength = this._length * 2;
  7680. var currentSavedOp = this.savedOp;
  7681. this.savedOp = createTypedArray('float32', newLength);
  7682. this.savedOp.set(currentSavedOp);
  7683. var i = 0;
  7684. for(i = this._length; i < newLength; i += 1) {
  7685. this.saved[i] = createTypedArray('float32', 16);
  7686. }
  7687. this._length = newLength;
  7688. };
  7689. CVContextData.prototype.reset = function() {
  7690. this.cArrPos = 0;
  7691. this.cTr.reset();
  7692. this.cO = 1;
  7693. };
  7694. function CVBaseElement(){
  7695. }
  7696. CVBaseElement.prototype = {
  7697. createElements: function(){},
  7698. initRendererElement: function(){},
  7699. createContainerElements: function(){
  7700. this.canvasContext = this.globalData.canvasContext;
  7701. this.renderableEffectsManager = new CVEffects(this);
  7702. },
  7703. createContent: function(){},
  7704. setBlendMode: function(){
  7705. var globalData = this.globalData;
  7706. if(globalData.blendMode !== this.data.bm) {
  7707. globalData.blendMode = this.data.bm;
  7708. var blendModeValue = getBlendMode(this.data.bm);
  7709. globalData.canvasContext.globalCompositeOperation = blendModeValue;
  7710. }
  7711. },
  7712. createRenderableComponents: function(){
  7713. this.maskManager = new CVMaskElement(this.data, this);
  7714. },
  7715. hideElement: function(){
  7716. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7717. this.hidden = true;
  7718. }
  7719. },
  7720. showElement: function(){
  7721. if (this.isInRange && !this.isTransparent){
  7722. this.hidden = false;
  7723. this._isFirstFrame = true;
  7724. this.maskManager._isFirstFrame = true;
  7725. }
  7726. },
  7727. renderFrame: function() {
  7728. if (this.hidden || this.data.hd) {
  7729. return;
  7730. }
  7731. this.renderTransform();
  7732. this.renderRenderable();
  7733. this.setBlendMode();
  7734. var forceRealStack = this.data.ty === 0;
  7735. this.globalData.renderer.save(forceRealStack);
  7736. this.globalData.renderer.ctxTransform(this.finalTransform.mat.props);
  7737. this.globalData.renderer.ctxOpacity(this.finalTransform.mProp.o.v);
  7738. this.renderInnerContent();
  7739. this.globalData.renderer.restore(forceRealStack);
  7740. if(this.maskManager.hasMasks) {
  7741. this.globalData.renderer.restore(true);
  7742. }
  7743. if (this._isFirstFrame) {
  7744. this._isFirstFrame = false;
  7745. }
  7746. },
  7747. destroy: function(){
  7748. this.canvasContext = null;
  7749. this.data = null;
  7750. this.globalData = null;
  7751. this.maskManager.destroy();
  7752. },
  7753. mHelper: new Matrix()
  7754. };
  7755. CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement;
  7756. CVBaseElement.prototype.show = CVBaseElement.prototype.showElement;
  7757. function CVImageElement(data, globalData, comp){
  7758. this.assetData = globalData.getAssetData(data.refId);
  7759. this.img = globalData.imageLoader.getImage(this.assetData);
  7760. this.initElement(data,globalData,comp);
  7761. }
  7762. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVImageElement);
  7763. CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  7764. CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  7765. CVImageElement.prototype.createContent = function(){
  7766. if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) {
  7767. var canvas = createTag('canvas');
  7768. canvas.width = this.assetData.w;
  7769. canvas.height = this.assetData.h;
  7770. var ctx = canvas.getContext('2d');
  7771. var imgW = this.img.width;
  7772. var imgH = this.img.height;
  7773. var imgRel = imgW / imgH;
  7774. var canvasRel = this.assetData.w/this.assetData.h;
  7775. var widthCrop, heightCrop;
  7776. var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio;
  7777. if((imgRel > canvasRel && par === 'xMidYMid slice') || (imgRel < canvasRel && par !== 'xMidYMid slice')) {
  7778. heightCrop = imgH;
  7779. widthCrop = heightCrop*canvasRel;
  7780. } else {
  7781. widthCrop = imgW;
  7782. heightCrop = widthCrop/canvasRel;
  7783. }
  7784. ctx.drawImage(this.img,(imgW-widthCrop)/2,(imgH-heightCrop)/2,widthCrop,heightCrop,0,0,this.assetData.w,this.assetData.h);
  7785. this.img = canvas;
  7786. }
  7787. };
  7788. CVImageElement.prototype.renderInnerContent = function(parentMatrix){
  7789. this.canvasContext.drawImage(this.img, 0, 0);
  7790. };
  7791. CVImageElement.prototype.destroy = function(){
  7792. this.img = null;
  7793. };
  7794. function CVCompElement(data, globalData, comp) {
  7795. this.completeLayers = false;
  7796. this.layers = data.layers;
  7797. this.pendingElements = [];
  7798. this.elements = createSizedArray(this.layers.length);
  7799. this.initElement(data, globalData, comp);
  7800. this.tm = data.tm ? PropertyFactory.getProp(this,data.tm,0,globalData.frameRate, this) : {_placeholder:true};
  7801. }
  7802. extendPrototype([CanvasRenderer, ICompElement, CVBaseElement], CVCompElement);
  7803. CVCompElement.prototype.renderInnerContent = function() {
  7804. var ctx = this.canvasContext;
  7805. ctx.beginPath();
  7806. ctx.moveTo(0, 0);
  7807. ctx.lineTo(this.data.w, 0);
  7808. ctx.lineTo(this.data.w, this.data.h);
  7809. ctx.lineTo(0, this.data.h);
  7810. ctx.lineTo(0, 0);
  7811. ctx.clip();
  7812. var i,len = this.layers.length;
  7813. for( i = len - 1; i >= 0; i -= 1 ){
  7814. if(this.completeLayers || this.elements[i]){
  7815. this.elements[i].renderFrame();
  7816. }
  7817. }
  7818. };
  7819. CVCompElement.prototype.destroy = function(){
  7820. var i,len = this.layers.length;
  7821. for( i = len - 1; i >= 0; i -= 1 ){
  7822. if(this.elements[i]) {
  7823. this.elements[i].destroy();
  7824. }
  7825. }
  7826. this.layers = null;
  7827. this.elements = null;
  7828. };
  7829. function CVMaskElement(data,element){
  7830. this.data = data;
  7831. this.element = element;
  7832. this.masksProperties = this.data.masksProperties || [];
  7833. this.viewData = createSizedArray(this.masksProperties.length);
  7834. var i, len = this.masksProperties.length, hasMasks = false;
  7835. for (i = 0; i < len; i++) {
  7836. if(this.masksProperties[i].mode !== 'n'){
  7837. hasMasks = true;
  7838. }
  7839. this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element,this.masksProperties[i],3);
  7840. }
  7841. this.hasMasks = hasMasks;
  7842. if(hasMasks) {
  7843. this.element.addRenderableComponent(this);
  7844. }
  7845. }
  7846. CVMaskElement.prototype.renderFrame = function () {
  7847. if(!this.hasMasks){
  7848. return;
  7849. }
  7850. var transform = this.element.finalTransform.mat;
  7851. var ctx = this.element.canvasContext;
  7852. var i, len = this.masksProperties.length;
  7853. var pt,pts,data;
  7854. ctx.beginPath();
  7855. for (i = 0; i < len; i++) {
  7856. if(this.masksProperties[i].mode !== 'n'){
  7857. if (this.masksProperties[i].inv) {
  7858. ctx.moveTo(0, 0);
  7859. ctx.lineTo(this.element.globalData.compSize.w, 0);
  7860. ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h);
  7861. ctx.lineTo(0, this.element.globalData.compSize.h);
  7862. ctx.lineTo(0, 0);
  7863. }
  7864. data = this.viewData[i].v;
  7865. pt = transform.applyToPointArray(data.v[0][0],data.v[0][1],0);
  7866. ctx.moveTo(pt[0], pt[1]);
  7867. var j, jLen = data._length;
  7868. for (j = 1; j < jLen; j++) {
  7869. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]);
  7870. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  7871. }
  7872. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]);
  7873. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  7874. }
  7875. }
  7876. this.element.globalData.renderer.save(true);
  7877. ctx.clip();
  7878. };
  7879. CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty;
  7880. CVMaskElement.prototype.destroy = function(){
  7881. this.element = null;
  7882. };
  7883. function CVShapeElement(data, globalData, comp) {
  7884. this.shapes = [];
  7885. this.shapesData = data.shapes;
  7886. this.stylesList = [];
  7887. this.itemsData = [];
  7888. this.prevViewData = [];
  7889. this.shapeModifiers = [];
  7890. this.processedElements = [];
  7891. this.transformsManager = new ShapeTransformManager();
  7892. this.initElement(data, globalData, comp);
  7893. }
  7894. extendPrototype([BaseElement,TransformElement,CVBaseElement,IShapeElement,HierarchyElement,FrameElement,RenderableElement], CVShapeElement);
  7895. CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement;
  7896. CVShapeElement.prototype.transformHelper = {opacity:1,_opMdf:false};
  7897. CVShapeElement.prototype.dashResetter = [];
  7898. CVShapeElement.prototype.createContent = function(){
  7899. this.searchShapes(this.shapesData,this.itemsData,this.prevViewData, true, []);
  7900. };
  7901. CVShapeElement.prototype.createStyleElement = function(data, transforms) {
  7902. var styleElem = {
  7903. data: data,
  7904. type: data.ty,
  7905. preTransforms: this.transformsManager.addTransformSequence(transforms),
  7906. transforms: [],
  7907. elements: [],
  7908. closed: data.hd === true
  7909. };
  7910. var elementData = {};
  7911. if(data.ty == 'fl' || data.ty == 'st'){
  7912. elementData.c = PropertyFactory.getProp(this,data.c,1,255,this);
  7913. if(!elementData.c.k){
  7914. styleElem.co = 'rgb('+bm_floor(elementData.c.v[0])+','+bm_floor(elementData.c.v[1])+','+bm_floor(elementData.c.v[2])+')';
  7915. }
  7916. } else if (data.ty === 'gf' || data.ty === 'gs') {
  7917. elementData.s = PropertyFactory.getProp(this,data.s,1,null,this);
  7918. elementData.e = PropertyFactory.getProp(this,data.e,1,null,this);
  7919. elementData.h = PropertyFactory.getProp(this,data.h||{k:0},0,0.01,this);
  7920. elementData.a = PropertyFactory.getProp(this,data.a||{k:0},0,degToRads,this);
  7921. elementData.g = new GradientProperty(this,data.g,this);
  7922. }
  7923. elementData.o = PropertyFactory.getProp(this,data.o,0,0.01,this);
  7924. if(data.ty == 'st' || data.ty == 'gs') {
  7925. styleElem.lc = this.lcEnum[data.lc] || 'round';
  7926. styleElem.lj = this.ljEnum[data.lj] || 'round';
  7927. if(data.lj == 1) {
  7928. styleElem.ml = data.ml;
  7929. }
  7930. elementData.w = PropertyFactory.getProp(this,data.w,0,null,this);
  7931. if(!elementData.w.k){
  7932. styleElem.wi = elementData.w.v;
  7933. }
  7934. if(data.d){
  7935. var d = new DashProperty(this,data.d,'canvas', this);
  7936. elementData.d = d;
  7937. if(!elementData.d.k){
  7938. styleElem.da = elementData.d.dashArray;
  7939. styleElem.do = elementData.d.dashoffset[0];
  7940. }
  7941. }
  7942. } else {
  7943. styleElem.r = data.r === 2 ? 'evenodd' : 'nonzero';
  7944. }
  7945. this.stylesList.push(styleElem);
  7946. elementData.style = styleElem;
  7947. return elementData;
  7948. };
  7949. CVShapeElement.prototype.createGroupElement = function(data) {
  7950. var elementData = {
  7951. it: [],
  7952. prevViewData: []
  7953. };
  7954. return elementData;
  7955. };
  7956. CVShapeElement.prototype.createTransformElement = function(data) {
  7957. var elementData = {
  7958. transform : {
  7959. opacity: 1,
  7960. _opMdf:false,
  7961. key: this.transformsManager.getNewKey(),
  7962. op: PropertyFactory.getProp(this,data.o,0,0.01,this),
  7963. mProps: TransformPropertyFactory.getTransformProperty(this,data,this)
  7964. }
  7965. };
  7966. return elementData;
  7967. };
  7968. CVShapeElement.prototype.createShapeElement = function(data) {
  7969. var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager);
  7970. this.shapes.push(elementData);
  7971. this.addShapeToModifiers(elementData);
  7972. return elementData;
  7973. };
  7974. CVShapeElement.prototype.reloadShapes = function() {
  7975. this._isFirstFrame = true;
  7976. var i, len = this.itemsData.length;
  7977. for (i = 0; i < len; i += 1) {
  7978. this.prevViewData[i] = this.itemsData[i];
  7979. }
  7980. this.searchShapes(this.shapesData,this.itemsData,this.prevViewData, true, []);
  7981. len = this.dynamicProperties.length;
  7982. for (i = 0; i < len; i += 1) {
  7983. this.dynamicProperties[i].getValue();
  7984. }
  7985. this.renderModifiers();
  7986. this.transformsManager.processSequences(this._isFirstFrame);
  7987. };
  7988. CVShapeElement.prototype.addTransformToStyleList = function(transform) {
  7989. var i, len = this.stylesList.length;
  7990. for (i = 0; i < len; i += 1) {
  7991. if(!this.stylesList[i].closed) {
  7992. this.stylesList[i].transforms.push(transform);
  7993. }
  7994. }
  7995. }
  7996. CVShapeElement.prototype.removeTransformFromStyleList = function() {
  7997. var i, len = this.stylesList.length;
  7998. for (i = 0; i < len; i += 1) {
  7999. if(!this.stylesList[i].closed) {
  8000. this.stylesList[i].transforms.pop();
  8001. }
  8002. }
  8003. }
  8004. CVShapeElement.prototype.closeStyles = function(styles) {
  8005. var i, len = styles.length, j, jLen;
  8006. for (i = 0; i < len; i += 1) {
  8007. styles[i].closed = true;
  8008. }
  8009. }
  8010. CVShapeElement.prototype.searchShapes = function(arr,itemsData, prevViewData, shouldRender, transforms){
  8011. var i, len = arr.length - 1;
  8012. var j, jLen;
  8013. var ownStyles = [], ownModifiers = [], processedPos, modifier, currentTransform;
  8014. var ownTransforms = [].concat(transforms);
  8015. for(i=len;i>=0;i-=1){
  8016. processedPos = this.searchProcessedElement(arr[i]);
  8017. if(!processedPos){
  8018. arr[i]._shouldRender = shouldRender;
  8019. } else {
  8020. itemsData[i] = prevViewData[processedPos - 1];
  8021. }
  8022. if(arr[i].ty == 'fl' || arr[i].ty == 'st'|| arr[i].ty == 'gf'|| arr[i].ty == 'gs'){
  8023. if(!processedPos){
  8024. itemsData[i] = this.createStyleElement(arr[i], ownTransforms);
  8025. } else {
  8026. itemsData[i].style.closed = false;
  8027. }
  8028. ownStyles.push(itemsData[i].style);
  8029. }else if(arr[i].ty == 'gr'){
  8030. if(!processedPos){
  8031. itemsData[i] = this.createGroupElement(arr[i]);
  8032. } else {
  8033. jLen = itemsData[i].it.length;
  8034. for(j=0;j<jLen;j+=1){
  8035. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8036. }
  8037. }
  8038. this.searchShapes(arr[i].it,itemsData[i].it,itemsData[i].prevViewData, shouldRender, ownTransforms);
  8039. }else if(arr[i].ty == 'tr'){
  8040. if(!processedPos){
  8041. currentTransform = this.createTransformElement(arr[i]);
  8042. itemsData[i] = currentTransform;
  8043. }
  8044. ownTransforms.push(itemsData[i]);
  8045. this.addTransformToStyleList(itemsData[i]);
  8046. }else if(arr[i].ty == 'sh' || arr[i].ty == 'rc' || arr[i].ty == 'el' || arr[i].ty == 'sr'){
  8047. if(!processedPos){
  8048. itemsData[i] = this.createShapeElement(arr[i]);
  8049. }
  8050. }else if(arr[i].ty == 'tm' || arr[i].ty == 'rd' || arr[i].ty == 'pb'){
  8051. if(!processedPos){
  8052. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8053. modifier.init(this,arr[i]);
  8054. itemsData[i] = modifier;
  8055. this.shapeModifiers.push(modifier);
  8056. } else {
  8057. modifier = itemsData[i];
  8058. modifier.closed = false;
  8059. }
  8060. ownModifiers.push(modifier);
  8061. } else if(arr[i].ty == 'rp'){
  8062. if(!processedPos){
  8063. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8064. itemsData[i] = modifier;
  8065. modifier.init(this,arr,i,itemsData);
  8066. this.shapeModifiers.push(modifier);
  8067. shouldRender = false;
  8068. }else{
  8069. modifier = itemsData[i];
  8070. modifier.closed = true;
  8071. }
  8072. ownModifiers.push(modifier);
  8073. }
  8074. this.addProcessedElement(arr[i], i + 1);
  8075. }
  8076. this.removeTransformFromStyleList();
  8077. this.closeStyles(ownStyles);
  8078. len = ownModifiers.length;
  8079. for(i=0;i<len;i+=1){
  8080. ownModifiers[i].closed = true;
  8081. }
  8082. };
  8083. CVShapeElement.prototype.renderInnerContent = function() {
  8084. this.transformHelper.opacity = 1;
  8085. this.transformHelper._opMdf = false;
  8086. this.renderModifiers();
  8087. this.transformsManager.processSequences(this._isFirstFrame);
  8088. this.renderShape(this.transformHelper,this.shapesData,this.itemsData,true);
  8089. };
  8090. CVShapeElement.prototype.renderShapeTransform = function(parentTransform, groupTransform) {
  8091. var props, groupMatrix;
  8092. if(parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) {
  8093. groupTransform.opacity = parentTransform.opacity;
  8094. groupTransform.opacity *= groupTransform.op.v;
  8095. groupTransform._opMdf = true;
  8096. }
  8097. };
  8098. CVShapeElement.prototype.drawLayer = function() {
  8099. var i, len = this.stylesList.length;
  8100. var j, jLen, k, kLen,elems,nodes, renderer = this.globalData.renderer, ctx = this.globalData.canvasContext, type, currentStyle;
  8101. for(i=0;i<len;i+=1){
  8102. currentStyle = this.stylesList[i];
  8103. type = currentStyle.type;
  8104. //Skipping style when
  8105. //Stroke width equals 0
  8106. //style should not be rendered (extra unused repeaters)
  8107. //current opacity equals 0
  8108. //global opacity equals 0
  8109. if(((type === 'st' || type === 'gs') && currentStyle.wi === 0) || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0){
  8110. continue;
  8111. }
  8112. renderer.save();
  8113. elems = currentStyle.elements;
  8114. if(type === 'st' || type === 'gs'){
  8115. ctx.strokeStyle = type === 'st' ? currentStyle.co : currentStyle.grd;
  8116. ctx.lineWidth = currentStyle.wi;
  8117. ctx.lineCap = currentStyle.lc;
  8118. ctx.lineJoin = currentStyle.lj;
  8119. ctx.miterLimit = currentStyle.ml || 0;
  8120. } else {
  8121. ctx.fillStyle = type === 'fl' ? currentStyle.co : currentStyle.grd;
  8122. }
  8123. renderer.ctxOpacity(currentStyle.coOp);
  8124. if(type !== 'st' && type !== 'gs'){
  8125. ctx.beginPath();
  8126. }
  8127. renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props);
  8128. jLen = elems.length;
  8129. for(j=0;j<jLen;j+=1){
  8130. if(type === 'st' || type === 'gs'){
  8131. ctx.beginPath();
  8132. if(currentStyle.da){
  8133. ctx.setLineDash(currentStyle.da);
  8134. ctx.lineDashOffset = currentStyle.do;
  8135. }
  8136. }
  8137. nodes = elems[j].trNodes;
  8138. kLen = nodes.length;
  8139. for(k=0;k<kLen;k+=1){
  8140. if(nodes[k].t == 'm'){
  8141. ctx.moveTo(nodes[k].p[0],nodes[k].p[1]);
  8142. }else if(nodes[k].t == 'c'){
  8143. 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]);
  8144. }else{
  8145. ctx.closePath();
  8146. }
  8147. }
  8148. if(type === 'st' || type === 'gs'){
  8149. ctx.stroke();
  8150. if(currentStyle.da){
  8151. ctx.setLineDash(this.dashResetter);
  8152. }
  8153. }
  8154. }
  8155. if(type !== 'st' && type !== 'gs'){
  8156. ctx.fill(currentStyle.r);
  8157. }
  8158. renderer.restore();
  8159. }
  8160. };
  8161. CVShapeElement.prototype.renderShape = function(parentTransform,items,data,isMain){
  8162. var i, len = items.length - 1;
  8163. var groupTransform;
  8164. groupTransform = parentTransform;
  8165. for(i=len;i>=0;i-=1){
  8166. if(items[i].ty == 'tr'){
  8167. groupTransform = data[i].transform;
  8168. this.renderShapeTransform(parentTransform, groupTransform);
  8169. }else if(items[i].ty == 'sh' || items[i].ty == 'el' || items[i].ty == 'rc' || items[i].ty == 'sr'){
  8170. this.renderPath(items[i],data[i]);
  8171. }else if(items[i].ty == 'fl'){
  8172. this.renderFill(items[i],data[i],groupTransform);
  8173. }else if(items[i].ty == 'st'){
  8174. this.renderStroke(items[i],data[i],groupTransform);
  8175. }else if(items[i].ty == 'gf' || items[i].ty == 'gs'){
  8176. this.renderGradientFill(items[i],data[i],groupTransform);
  8177. }else if(items[i].ty == 'gr'){
  8178. this.renderShape(groupTransform,items[i].it,data[i].it);
  8179. }else if(items[i].ty == 'tm'){
  8180. //
  8181. }
  8182. }
  8183. if(isMain){
  8184. this.drawLayer();
  8185. }
  8186. };
  8187. CVShapeElement.prototype.renderStyledShape = function(styledShape, shape){
  8188. if(this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) {
  8189. var shapeNodes = styledShape.trNodes;
  8190. var paths = shape.paths;
  8191. var i, len, j, jLen = paths._length;
  8192. shapeNodes.length = 0;
  8193. var groupTransformMat = styledShape.transforms.finalTransform;
  8194. for (j = 0; j < jLen; j += 1) {
  8195. var pathNodes = paths.shapes[j];
  8196. if(pathNodes && pathNodes.v){
  8197. len = pathNodes._length;
  8198. for (i = 1; i < len; i += 1) {
  8199. if (i === 1) {
  8200. shapeNodes.push({
  8201. t: 'm',
  8202. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0)
  8203. });
  8204. }
  8205. shapeNodes.push({
  8206. t: 'c',
  8207. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i])
  8208. });
  8209. }
  8210. if (len === 1) {
  8211. shapeNodes.push({
  8212. t: 'm',
  8213. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0)
  8214. });
  8215. }
  8216. if (pathNodes.c && len) {
  8217. shapeNodes.push({
  8218. t: 'c',
  8219. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0])
  8220. });
  8221. shapeNodes.push({
  8222. t: 'z'
  8223. });
  8224. }
  8225. }
  8226. }
  8227. styledShape.trNodes = shapeNodes;
  8228. }
  8229. }
  8230. CVShapeElement.prototype.renderPath = function(pathData,itemData){
  8231. if(pathData.hd !== true && pathData._shouldRender) {
  8232. var i, len = itemData.styledShapes.length;
  8233. for (i = 0; i < len; i += 1) {
  8234. this.renderStyledShape(itemData.styledShapes[i], itemData.sh);
  8235. }
  8236. }
  8237. };
  8238. CVShapeElement.prototype.renderFill = function(styleData,itemData, groupTransform){
  8239. var styleElem = itemData.style;
  8240. if (itemData.c._mdf || this._isFirstFrame) {
  8241. styleElem.co = 'rgb('
  8242. + bm_floor(itemData.c.v[0]) + ','
  8243. + bm_floor(itemData.c.v[1]) + ','
  8244. + bm_floor(itemData.c.v[2]) + ')';
  8245. }
  8246. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  8247. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  8248. }
  8249. };
  8250. CVShapeElement.prototype.renderGradientFill = function(styleData,itemData, groupTransform){
  8251. var styleElem = itemData.style;
  8252. if(!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || (styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf))) {
  8253. var ctx = this.globalData.canvasContext;
  8254. var grd;
  8255. var pt1 = itemData.s.v, pt2 = itemData.e.v;
  8256. if (styleData.t === 1) {
  8257. grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]);
  8258. } else {
  8259. var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8260. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8261. var percent = itemData.h.v >= 1 ? 0.99 : itemData.h.v <= -1 ? -0.99: itemData.h.v;
  8262. var dist = rad * percent;
  8263. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8264. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8265. var grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad);
  8266. }
  8267. var i, len = styleData.g.p;
  8268. var cValues = itemData.g.c;
  8269. var opacity = 1;
  8270. for (i = 0; i < len; i += 1){
  8271. if(itemData.g._hasOpacity && itemData.g._collapsable) {
  8272. opacity = itemData.g.o[i*2 + 1];
  8273. }
  8274. grd.addColorStop(cValues[i * 4] / 100,'rgba('+ cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ','+cValues[i * 4 + 3] + ',' + opacity + ')');
  8275. }
  8276. styleElem.grd = grd;
  8277. }
  8278. styleElem.coOp = itemData.o.v*groupTransform.opacity;
  8279. };
  8280. CVShapeElement.prototype.renderStroke = function(styleData,itemData, groupTransform){
  8281. var styleElem = itemData.style;
  8282. var d = itemData.d;
  8283. if(d && (d._mdf || this._isFirstFrame)){
  8284. styleElem.da = d.dashArray;
  8285. styleElem.do = d.dashoffset[0];
  8286. }
  8287. if(itemData.c._mdf || this._isFirstFrame){
  8288. styleElem.co = 'rgb('+bm_floor(itemData.c.v[0])+','+bm_floor(itemData.c.v[1])+','+bm_floor(itemData.c.v[2])+')';
  8289. }
  8290. if(itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame){
  8291. styleElem.coOp = itemData.o.v*groupTransform.opacity;
  8292. }
  8293. if(itemData.w._mdf || this._isFirstFrame){
  8294. styleElem.wi = itemData.w.v;
  8295. }
  8296. };
  8297. CVShapeElement.prototype.destroy = function(){
  8298. this.shapesData = null;
  8299. this.globalData = null;
  8300. this.canvasContext = null;
  8301. this.stylesList.length = 0;
  8302. this.itemsData.length = 0;
  8303. };
  8304. function CVSolidElement(data, globalData, comp) {
  8305. this.initElement(data,globalData,comp);
  8306. }
  8307. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVSolidElement);
  8308. CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  8309. CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  8310. CVSolidElement.prototype.renderInnerContent = function() {
  8311. var ctx = this.canvasContext;
  8312. ctx.fillStyle = this.data.sc;
  8313. ctx.fillRect(0, 0, this.data.sw, this.data.sh);
  8314. //
  8315. };
  8316. function CVTextElement(data, globalData, comp){
  8317. this.textSpans = [];
  8318. this.yOffset = 0;
  8319. this.fillColorAnim = false;
  8320. this.strokeColorAnim = false;
  8321. this.strokeWidthAnim = false;
  8322. this.stroke = false;
  8323. this.fill = false;
  8324. this.justifyOffset = 0;
  8325. this.currentRender = null;
  8326. this.renderType = 'canvas';
  8327. this.values = {
  8328. fill: 'rgba(0,0,0,0)',
  8329. stroke: 'rgba(0,0,0,0)',
  8330. sWidth: 0,
  8331. fValue: ''
  8332. };
  8333. this.initElement(data,globalData,comp);
  8334. }
  8335. extendPrototype([BaseElement,TransformElement,CVBaseElement,HierarchyElement,FrameElement,RenderableElement,ITextElement], CVTextElement);
  8336. CVTextElement.prototype.tHelper = createTag('canvas').getContext('2d');
  8337. CVTextElement.prototype.buildNewText = function(){
  8338. var documentData = this.textProperty.currentData;
  8339. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  8340. var hasFill = false;
  8341. if(documentData.fc) {
  8342. hasFill = true;
  8343. this.values.fill = this.buildColor(documentData.fc);
  8344. }else{
  8345. this.values.fill = 'rgba(0,0,0,0)';
  8346. }
  8347. this.fill = hasFill;
  8348. var hasStroke = false;
  8349. if(documentData.sc){
  8350. hasStroke = true;
  8351. this.values.stroke = this.buildColor(documentData.sc);
  8352. this.values.sWidth = documentData.sw;
  8353. }
  8354. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  8355. var i, len;
  8356. var letters = documentData.l;
  8357. var matrixHelper = this.mHelper;
  8358. this.stroke = hasStroke;
  8359. this.values.fValue = documentData.finalSize + 'px '+ this.globalData.fontManager.getFontByName(documentData.f).fFamily;
  8360. len = documentData.finalText.length;
  8361. //this.tHelper.font = this.values.fValue;
  8362. var charData, shapeData, k, kLen, shapes, j, jLen, pathNodes, commands, pathArr, singleShape = this.data.singleShape;
  8363. var trackingOffset = documentData.tr/1000*documentData.finalSize;
  8364. var xPos = 0, yPos = 0, firstLine = true;
  8365. var cnt = 0;
  8366. for (i = 0; i < len; i += 1) {
  8367. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  8368. shapeData = charData && charData.data || {};
  8369. matrixHelper.reset();
  8370. if(singleShape && letters[i].n) {
  8371. xPos = -trackingOffset;
  8372. yPos += documentData.yOffset;
  8373. yPos += firstLine ? 1 : 0;
  8374. firstLine = false;
  8375. }
  8376. shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
  8377. jLen = shapes.length;
  8378. matrixHelper.scale(documentData.finalSize/100,documentData.finalSize/100);
  8379. if(singleShape){
  8380. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  8381. }
  8382. commands = createSizedArray(jLen);
  8383. for(j=0;j<jLen;j+=1){
  8384. kLen = shapes[j].ks.k.i.length;
  8385. pathNodes = shapes[j].ks.k;
  8386. pathArr = [];
  8387. for(k=1;k<kLen;k+=1){
  8388. if(k==1){
  8389. pathArr.push(matrixHelper.applyToX(pathNodes.v[0][0],pathNodes.v[0][1],0),matrixHelper.applyToY(pathNodes.v[0][0],pathNodes.v[0][1],0));
  8390. }
  8391. pathArr.push(matrixHelper.applyToX(pathNodes.o[k-1][0],pathNodes.o[k-1][1],0),matrixHelper.applyToY(pathNodes.o[k-1][0],pathNodes.o[k-1][1],0),matrixHelper.applyToX(pathNodes.i[k][0],pathNodes.i[k][1],0),matrixHelper.applyToY(pathNodes.i[k][0],pathNodes.i[k][1],0),matrixHelper.applyToX(pathNodes.v[k][0],pathNodes.v[k][1],0),matrixHelper.applyToY(pathNodes.v[k][0],pathNodes.v[k][1],0));
  8392. }
  8393. pathArr.push(matrixHelper.applyToX(pathNodes.o[k-1][0],pathNodes.o[k-1][1],0),matrixHelper.applyToY(pathNodes.o[k-1][0],pathNodes.o[k-1][1],0),matrixHelper.applyToX(pathNodes.i[0][0],pathNodes.i[0][1],0),matrixHelper.applyToY(pathNodes.i[0][0],pathNodes.i[0][1],0),matrixHelper.applyToX(pathNodes.v[0][0],pathNodes.v[0][1],0),matrixHelper.applyToY(pathNodes.v[0][0],pathNodes.v[0][1],0));
  8394. commands[j] = pathArr;
  8395. }
  8396. if(singleShape){
  8397. xPos += letters[i].l;
  8398. xPos += trackingOffset;
  8399. }
  8400. if(this.textSpans[cnt]){
  8401. this.textSpans[cnt].elem = commands;
  8402. } else {
  8403. this.textSpans[cnt] = {elem: commands};
  8404. }
  8405. cnt +=1;
  8406. }
  8407. };
  8408. CVTextElement.prototype.renderInnerContent = function(){
  8409. var ctx = this.canvasContext;
  8410. var finalMat = this.finalTransform.mat.props;
  8411. ctx.font = this.values.fValue;
  8412. ctx.lineCap = 'butt';
  8413. ctx.lineJoin = 'miter';
  8414. ctx.miterLimit = 4;
  8415. if(!this.data.singleShape){
  8416. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  8417. }
  8418. var i,len, j, jLen, k, kLen;
  8419. var renderedLetters = this.textAnimator.renderedLetters;
  8420. var letters = this.textProperty.currentData.l;
  8421. len = letters.length;
  8422. var renderedLetter;
  8423. var lastFill = null, lastStroke = null, lastStrokeW = null, commands, pathArr;
  8424. for(i=0;i<len;i+=1){
  8425. if(letters[i].n){
  8426. continue;
  8427. }
  8428. renderedLetter = renderedLetters[i];
  8429. if(renderedLetter){
  8430. this.globalData.renderer.save();
  8431. this.globalData.renderer.ctxTransform(renderedLetter.p);
  8432. this.globalData.renderer.ctxOpacity(renderedLetter.o);
  8433. }
  8434. if(this.fill){
  8435. if(renderedLetter && renderedLetter.fc){
  8436. if(lastFill !== renderedLetter.fc){
  8437. lastFill = renderedLetter.fc;
  8438. ctx.fillStyle = renderedLetter.fc;
  8439. }
  8440. }else if(lastFill !== this.values.fill){
  8441. lastFill = this.values.fill;
  8442. ctx.fillStyle = this.values.fill;
  8443. }
  8444. commands = this.textSpans[i].elem;
  8445. jLen = commands.length;
  8446. this.globalData.canvasContext.beginPath();
  8447. for(j=0;j<jLen;j+=1) {
  8448. pathArr = commands[j];
  8449. kLen = pathArr.length;
  8450. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  8451. for (k = 2; k < kLen; k += 6) {
  8452. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  8453. }
  8454. }
  8455. this.globalData.canvasContext.closePath();
  8456. this.globalData.canvasContext.fill();
  8457. ///ctx.fillText(this.textSpans[i].val,0,0);
  8458. }
  8459. if(this.stroke){
  8460. if(renderedLetter && renderedLetter.sw){
  8461. if(lastStrokeW !== renderedLetter.sw){
  8462. lastStrokeW = renderedLetter.sw;
  8463. ctx.lineWidth = renderedLetter.sw;
  8464. }
  8465. }else if(lastStrokeW !== this.values.sWidth){
  8466. lastStrokeW = this.values.sWidth;
  8467. ctx.lineWidth = this.values.sWidth;
  8468. }
  8469. if(renderedLetter && renderedLetter.sc){
  8470. if(lastStroke !== renderedLetter.sc){
  8471. lastStroke = renderedLetter.sc;
  8472. ctx.strokeStyle = renderedLetter.sc;
  8473. }
  8474. }else if(lastStroke !== this.values.stroke){
  8475. lastStroke = this.values.stroke;
  8476. ctx.strokeStyle = this.values.stroke;
  8477. }
  8478. commands = this.textSpans[i].elem;
  8479. jLen = commands.length;
  8480. this.globalData.canvasContext.beginPath();
  8481. for(j=0;j<jLen;j+=1) {
  8482. pathArr = commands[j];
  8483. kLen = pathArr.length;
  8484. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  8485. for (k = 2; k < kLen; k += 6) {
  8486. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  8487. }
  8488. }
  8489. this.globalData.canvasContext.closePath();
  8490. this.globalData.canvasContext.stroke();
  8491. ///ctx.strokeText(letters[i].val,0,0);
  8492. }
  8493. if(renderedLetter) {
  8494. this.globalData.renderer.restore();
  8495. }
  8496. }
  8497. };
  8498. function CVEffects() {
  8499. }
  8500. CVEffects.prototype.renderFrame = function(){};
  8501. var animationManager = (function(){
  8502. var moduleOb = {};
  8503. var registeredAnimations = [];
  8504. var initTime = 0;
  8505. var len = 0;
  8506. var playingAnimationsNum = 0;
  8507. var _stopped = true;
  8508. var _isFrozen = false;
  8509. function removeElement(ev){
  8510. var i = 0;
  8511. var animItem = ev.target;
  8512. while(i<len) {
  8513. if (registeredAnimations[i].animation === animItem) {
  8514. registeredAnimations.splice(i, 1);
  8515. i -= 1;
  8516. len -= 1;
  8517. if(!animItem.isPaused){
  8518. subtractPlayingCount();
  8519. }
  8520. }
  8521. i += 1;
  8522. }
  8523. }
  8524. function registerAnimation(element, animationData){
  8525. if(!element){
  8526. return null;
  8527. }
  8528. var i=0;
  8529. while(i<len){
  8530. if(registeredAnimations[i].elem == element && registeredAnimations[i].elem !== null ){
  8531. return registeredAnimations[i].animation;
  8532. }
  8533. i+=1;
  8534. }
  8535. var animItem = new AnimationItem();
  8536. setupAnimation(animItem, element);
  8537. animItem.setData(element, animationData);
  8538. return animItem;
  8539. }
  8540. function getRegisteredAnimations() {
  8541. var i, len = registeredAnimations.length;
  8542. var animations = [];
  8543. for(i = 0; i < len; i += 1) {
  8544. animations.push(registeredAnimations[i].animation);
  8545. }
  8546. return animations;
  8547. }
  8548. function addPlayingCount(){
  8549. playingAnimationsNum += 1;
  8550. activate();
  8551. }
  8552. function subtractPlayingCount(){
  8553. playingAnimationsNum -= 1;
  8554. }
  8555. function setupAnimation(animItem, element){
  8556. animItem.addEventListener('destroy',removeElement);
  8557. animItem.addEventListener('_active',addPlayingCount);
  8558. animItem.addEventListener('_idle',subtractPlayingCount);
  8559. registeredAnimations.push({elem: element,animation:animItem});
  8560. len += 1;
  8561. }
  8562. function loadAnimation(params){
  8563. var animItem = new AnimationItem();
  8564. setupAnimation(animItem, null);
  8565. animItem.setParams(params);
  8566. return animItem;
  8567. }
  8568. function setSpeed(val,animation){
  8569. var i;
  8570. for(i=0;i<len;i+=1){
  8571. registeredAnimations[i].animation.setSpeed(val, animation);
  8572. }
  8573. }
  8574. function setDirection(val, animation){
  8575. var i;
  8576. for(i=0;i<len;i+=1){
  8577. registeredAnimations[i].animation.setDirection(val, animation);
  8578. }
  8579. }
  8580. function play(animation){
  8581. var i;
  8582. for(i=0;i<len;i+=1){
  8583. registeredAnimations[i].animation.play(animation);
  8584. }
  8585. }
  8586. function resume(nowTime) {
  8587. var elapsedTime = nowTime - initTime;
  8588. var i;
  8589. for(i=0;i<len;i+=1){
  8590. registeredAnimations[i].animation.advanceTime(elapsedTime);
  8591. }
  8592. initTime = nowTime;
  8593. if(playingAnimationsNum && !_isFrozen) {
  8594. window.requestAnimationFrame(resume);
  8595. } else {
  8596. _stopped = true;
  8597. }
  8598. }
  8599. function first(nowTime){
  8600. initTime = nowTime;
  8601. window.requestAnimationFrame(resume);
  8602. }
  8603. function pause(animation) {
  8604. var i;
  8605. for(i=0;i<len;i+=1){
  8606. registeredAnimations[i].animation.pause(animation);
  8607. }
  8608. }
  8609. function goToAndStop(value,isFrame,animation) {
  8610. var i;
  8611. for(i=0;i<len;i+=1){
  8612. registeredAnimations[i].animation.goToAndStop(value,isFrame,animation);
  8613. }
  8614. }
  8615. function stop(animation) {
  8616. var i;
  8617. for(i=0;i<len;i+=1){
  8618. registeredAnimations[i].animation.stop(animation);
  8619. }
  8620. }
  8621. function togglePause(animation) {
  8622. var i;
  8623. for(i=0;i<len;i+=1){
  8624. registeredAnimations[i].animation.togglePause(animation);
  8625. }
  8626. }
  8627. function destroy(animation) {
  8628. var i;
  8629. for(i=(len-1);i>=0;i-=1){
  8630. registeredAnimations[i].animation.destroy(animation);
  8631. }
  8632. }
  8633. function searchAnimations(animationData, standalone, renderer){
  8634. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')),
  8635. [].slice.call(document.getElementsByClassName('bodymovin')));
  8636. var i, len = animElements.length;
  8637. for(i=0;i<len;i+=1){
  8638. if(renderer){
  8639. animElements[i].setAttribute('data-bm-type',renderer);
  8640. }
  8641. registerAnimation(animElements[i], animationData);
  8642. }
  8643. if(standalone && len === 0){
  8644. if(!renderer){
  8645. renderer = 'svg';
  8646. }
  8647. var body = document.getElementsByTagName('body')[0];
  8648. body.innerText = '';
  8649. var div = createTag('div');
  8650. div.style.width = '100%';
  8651. div.style.height = '100%';
  8652. div.setAttribute('data-bm-type',renderer);
  8653. body.appendChild(div);
  8654. registerAnimation(div, animationData);
  8655. }
  8656. }
  8657. function resize(){
  8658. var i;
  8659. for(i=0;i<len;i+=1){
  8660. registeredAnimations[i].animation.resize();
  8661. }
  8662. }
  8663. function activate(){
  8664. if(!_isFrozen && playingAnimationsNum){
  8665. if(_stopped) {
  8666. window.requestAnimationFrame(first);
  8667. _stopped = false;
  8668. }
  8669. }
  8670. }
  8671. function freeze() {
  8672. _isFrozen = true;
  8673. }
  8674. function unfreeze() {
  8675. _isFrozen = false;
  8676. activate();
  8677. }
  8678. function setVolume(val,animation) {
  8679. var i;
  8680. for(i=0;i<len;i+=1){
  8681. registeredAnimations[i].animation.setVolume(val, animation);
  8682. }
  8683. }
  8684. function mute(animation) {
  8685. var i;
  8686. for(i=0;i<len;i+=1){
  8687. registeredAnimations[i].animation.mute(animation);
  8688. }
  8689. }
  8690. function unmute(animation) {
  8691. var i;
  8692. for(i=0;i<len;i+=1){
  8693. registeredAnimations[i].animation.unmute(animation);
  8694. }
  8695. }
  8696. moduleOb.registerAnimation = registerAnimation;
  8697. moduleOb.loadAnimation = loadAnimation;
  8698. moduleOb.setSpeed = setSpeed;
  8699. moduleOb.setDirection = setDirection;
  8700. moduleOb.play = play;
  8701. moduleOb.pause = pause;
  8702. moduleOb.stop = stop;
  8703. moduleOb.togglePause = togglePause;
  8704. moduleOb.searchAnimations = searchAnimations;
  8705. moduleOb.resize = resize;
  8706. //moduleOb.start = start;
  8707. moduleOb.goToAndStop = goToAndStop;
  8708. moduleOb.destroy = destroy;
  8709. moduleOb.freeze = freeze;
  8710. moduleOb.unfreeze = unfreeze;
  8711. moduleOb.setVolume = setVolume;
  8712. moduleOb.mute = mute;
  8713. moduleOb.unmute = unmute;
  8714. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  8715. return moduleOb;
  8716. }());
  8717. var AnimationItem = function () {
  8718. this._cbs = [];
  8719. this.name = '';
  8720. this.path = '';
  8721. this.isLoaded = false;
  8722. this.currentFrame = 0;
  8723. this.currentRawFrame = 0;
  8724. this.firstFrame = 0;
  8725. this.totalFrames = 0;
  8726. this.frameRate = 0;
  8727. this.frameMult = 0;
  8728. this.playSpeed = 1;
  8729. this.playDirection = 1;
  8730. this.playCount = 0;
  8731. this.animationData = {};
  8732. this.assets = [];
  8733. this.isPaused = true;
  8734. this.autoplay = false;
  8735. this.loop = true;
  8736. this.renderer = null;
  8737. this.animationID = createElementID();
  8738. this.assetsPath = '';
  8739. this.timeCompleted = 0;
  8740. this.segmentPos = 0;
  8741. this.isSubframeEnabled = subframeEnabled;
  8742. this.segments = [];
  8743. this._idle = true;
  8744. this._completedLoop = false;
  8745. this.projectInterface = ProjectInterface();
  8746. this.imagePreloader = new ImagePreloader();
  8747. this.audioController = audioControllerFactory();
  8748. };
  8749. extendPrototype([BaseEvent], AnimationItem);
  8750. AnimationItem.prototype.setParams = function(params) {
  8751. if(params.wrapper || params.container){
  8752. this.wrapper = params.wrapper || params.container;
  8753. }
  8754. var animType = params.animType ? params.animType : params.renderer ? params.renderer : 'svg';
  8755. switch(animType){
  8756. case 'canvas':
  8757. this.renderer = new CanvasRenderer(this, params.rendererSettings);
  8758. break;
  8759. case 'svg':
  8760. this.renderer = new SVGRenderer(this, params.rendererSettings);
  8761. break;
  8762. default:
  8763. this.renderer = new HybridRenderer(this, params.rendererSettings);
  8764. break;
  8765. }
  8766. this.imagePreloader.setCacheType(animType);
  8767. this.renderer.setProjectInterface(this.projectInterface);
  8768. this.animType = animType;
  8769. if (params.loop === ''
  8770. || params.loop === null
  8771. || params.loop === undefined
  8772. || params.loop === true)
  8773. {
  8774. this.loop = true;
  8775. } else if (params.loop === false) {
  8776. this.loop = false;
  8777. } else {
  8778. this.loop = parseInt(params.loop);
  8779. }
  8780. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  8781. this.name = params.name ? params.name : '';
  8782. this.autoloadSegments = params.hasOwnProperty('autoloadSegments') ? params.autoloadSegments : true;
  8783. this.assetsPath = params.assetsPath;
  8784. this.initialSegment = params.initialSegment;
  8785. if (params.audioFactory) {
  8786. this.audioController.setAudioFactory(params.audioFactory);
  8787. }
  8788. if (params.animationData) {
  8789. this.configAnimation(params.animationData);
  8790. } else if(params.path){
  8791. if( params.path.lastIndexOf('\\') !== -1){
  8792. this.path = params.path.substr(0,params.path.lastIndexOf('\\')+1);
  8793. } else {
  8794. this.path = params.path.substr(0,params.path.lastIndexOf('/')+1);
  8795. }
  8796. this.fileName = params.path.substr(params.path.lastIndexOf('/')+1);
  8797. this.fileName = this.fileName.substr(0,this.fileName.lastIndexOf('.json'));
  8798. assetLoader.load(params.path, this.configAnimation.bind(this), function() {
  8799. this.trigger('data_failed');
  8800. }.bind(this));
  8801. }
  8802. };
  8803. AnimationItem.prototype.setData = function (wrapper, animationData) {
  8804. var params = {
  8805. wrapper: wrapper,
  8806. animationData: animationData ? (typeof animationData === "object") ? animationData : JSON.parse(animationData) : null
  8807. };
  8808. var wrapperAttributes = wrapper.attributes;
  8809. 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 : '';
  8810. 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';
  8811. 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 : '';
  8812. if(loop === ''){
  8813. }else if(loop === 'false'){
  8814. params.loop = false;
  8815. }else if(loop === 'true'){
  8816. params.loop = true;
  8817. }else{
  8818. params.loop = parseInt(loop);
  8819. }
  8820. 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;
  8821. params.autoplay = autoplay !== "false";
  8822. 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 : '';
  8823. 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 : '';
  8824. if(prerender === 'false'){
  8825. params.prerender = false;
  8826. }
  8827. this.setParams(params);
  8828. };
  8829. AnimationItem.prototype.includeLayers = function(data) {
  8830. if(data.op > this.animationData.op){
  8831. this.animationData.op = data.op;
  8832. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  8833. }
  8834. var layers = this.animationData.layers;
  8835. var i, len = layers.length;
  8836. var newLayers = data.layers;
  8837. var j, jLen = newLayers.length;
  8838. for(j=0;j<jLen;j+=1){
  8839. i = 0;
  8840. while(i<len){
  8841. if(layers[i].id == newLayers[j].id){
  8842. layers[i] = newLayers[j];
  8843. break;
  8844. }
  8845. i += 1;
  8846. }
  8847. }
  8848. if(data.chars || data.fonts){
  8849. this.renderer.globalData.fontManager.addChars(data.chars);
  8850. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  8851. }
  8852. if(data.assets){
  8853. len = data.assets.length;
  8854. for(i = 0; i < len; i += 1){
  8855. this.animationData.assets.push(data.assets[i]);
  8856. }
  8857. }
  8858. this.animationData.__complete = false;
  8859. dataManager.completeData(this.animationData,this.renderer.globalData.fontManager);
  8860. this.renderer.includeLayers(data.layers);
  8861. if(expressionsPlugin){
  8862. expressionsPlugin.initExpressions(this);
  8863. }
  8864. this.loadNextSegment();
  8865. };
  8866. AnimationItem.prototype.loadNextSegment = function() {
  8867. var segments = this.animationData.segments;
  8868. if(!segments || segments.length === 0 || !this.autoloadSegments){
  8869. this.trigger('data_ready');
  8870. this.timeCompleted = this.totalFrames;
  8871. return;
  8872. }
  8873. var segment = segments.shift();
  8874. this.timeCompleted = segment.time * this.frameRate;
  8875. var segmentPath = this.path+this.fileName+'_' + this.segmentPos + '.json';
  8876. this.segmentPos += 1;
  8877. assetLoader.load(segmentPath, this.includeLayers.bind(this), function() {
  8878. this.trigger('data_failed');
  8879. }.bind(this));
  8880. };
  8881. AnimationItem.prototype.loadSegments = function() {
  8882. var segments = this.animationData.segments;
  8883. if(!segments) {
  8884. this.timeCompleted = this.totalFrames;
  8885. }
  8886. this.loadNextSegment();
  8887. };
  8888. AnimationItem.prototype.imagesLoaded = function() {
  8889. this.trigger('loaded_images');
  8890. this.checkLoaded()
  8891. }
  8892. AnimationItem.prototype.preloadImages = function() {
  8893. this.imagePreloader.setAssetsPath(this.assetsPath);
  8894. this.imagePreloader.setPath(this.path);
  8895. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  8896. }
  8897. AnimationItem.prototype.configAnimation = function (animData) {
  8898. if(!this.renderer){
  8899. return;
  8900. }
  8901. try {
  8902. this.animationData = animData;
  8903. if (this.initialSegment) {
  8904. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  8905. this.firstFrame = Math.round(this.initialSegment[0]);
  8906. } else {
  8907. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  8908. this.firstFrame = Math.round(this.animationData.ip);
  8909. }
  8910. this.renderer.configAnimation(animData);
  8911. if(!animData.assets){
  8912. animData.assets = [];
  8913. }
  8914. this.assets = this.animationData.assets;
  8915. this.frameRate = this.animationData.fr;
  8916. this.frameMult = this.animationData.fr / 1000;
  8917. this.renderer.searchExtraCompositions(animData.assets);
  8918. this.trigger('config_ready');
  8919. this.preloadImages();
  8920. this.loadSegments();
  8921. this.updaFrameModifier();
  8922. this.waitForFontsLoaded();
  8923. if (this.isPaused) {
  8924. this.audioController.pause();
  8925. }
  8926. } catch(error) {
  8927. this.triggerConfigError(error);
  8928. }
  8929. };
  8930. AnimationItem.prototype.waitForFontsLoaded = function(){
  8931. if(!this.renderer) {
  8932. return;
  8933. }
  8934. if(this.renderer.globalData.fontManager.isLoaded){
  8935. this.checkLoaded();
  8936. }else{
  8937. setTimeout(this.waitForFontsLoaded.bind(this),20);
  8938. }
  8939. }
  8940. AnimationItem.prototype.checkLoaded = function () {
  8941. if (!this.isLoaded
  8942. && this.renderer.globalData.fontManager.isLoaded
  8943. && (this.imagePreloader.loaded() || this.renderer.rendererType !== 'canvas')
  8944. ) {
  8945. this.isLoaded = true;
  8946. dataManager.completeData(this.animationData, this.renderer.globalData.fontManager);
  8947. if(expressionsPlugin){
  8948. expressionsPlugin.initExpressions(this);
  8949. }
  8950. this.renderer.initItems();
  8951. setTimeout(function() {
  8952. this.trigger('DOMLoaded');
  8953. }.bind(this), 0);
  8954. this.gotoFrame();
  8955. if(this.autoplay){
  8956. this.play();
  8957. }
  8958. }
  8959. };
  8960. AnimationItem.prototype.resize = function () {
  8961. this.renderer.updateContainerSize();
  8962. };
  8963. AnimationItem.prototype.setSubframe = function(flag){
  8964. this.isSubframeEnabled = !!flag;
  8965. };
  8966. AnimationItem.prototype.gotoFrame = function () {
  8967. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame;
  8968. if(this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted){
  8969. this.currentFrame = this.timeCompleted;
  8970. }
  8971. this.trigger('enterFrame');
  8972. this.renderFrame();
  8973. };
  8974. AnimationItem.prototype.renderFrame = function () {
  8975. if(this.isLoaded === false){
  8976. return;
  8977. }
  8978. try {
  8979. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  8980. } catch(error) {
  8981. this.triggerRenderFrameError(error);
  8982. }
  8983. };
  8984. AnimationItem.prototype.play = function (name) {
  8985. if(name && this.name != name){
  8986. return;
  8987. }
  8988. if (this.isPaused === true) {
  8989. this.isPaused = false;
  8990. this.audioController.resume();
  8991. if(this._idle){
  8992. this._idle = false;
  8993. this.trigger('_active');
  8994. }
  8995. }
  8996. };
  8997. AnimationItem.prototype.pause = function (name) {
  8998. if(name && this.name != name){
  8999. return;
  9000. }
  9001. if(this.isPaused === false){
  9002. this.isPaused = true;
  9003. this._idle = true;
  9004. this.trigger('_idle');
  9005. this.audioController.pause();
  9006. }
  9007. };
  9008. AnimationItem.prototype.togglePause = function (name) {
  9009. if(name && this.name != name){
  9010. return;
  9011. }
  9012. if(this.isPaused === true){
  9013. this.play();
  9014. }else{
  9015. this.pause();
  9016. }
  9017. };
  9018. AnimationItem.prototype.stop = function (name) {
  9019. if(name && this.name != name){
  9020. return;
  9021. }
  9022. this.pause();
  9023. this.playCount = 0;
  9024. this._completedLoop = false;
  9025. this.setCurrentRawFrameValue(0);
  9026. };
  9027. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  9028. if(name && this.name != name){
  9029. return;
  9030. }
  9031. if(isFrame){
  9032. this.setCurrentRawFrameValue(value);
  9033. }else{
  9034. this.setCurrentRawFrameValue(value * this.frameModifier);
  9035. }
  9036. this.pause();
  9037. };
  9038. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  9039. this.goToAndStop(value, isFrame, name);
  9040. this.play();
  9041. };
  9042. AnimationItem.prototype.advanceTime = function (value) {
  9043. if (this.isPaused === true || this.isLoaded === false) {
  9044. return;
  9045. }
  9046. var nextValue = this.currentRawFrame + value * this.frameModifier;
  9047. var _isComplete = false;
  9048. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  9049. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  9050. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  9051. if (!this.loop || this.playCount === this.loop) {
  9052. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  9053. _isComplete = true;
  9054. nextValue = this.totalFrames - 1;
  9055. }
  9056. } else if (nextValue >= this.totalFrames) {
  9057. this.playCount += 1;
  9058. if (!this.checkSegments(nextValue % this.totalFrames)) {
  9059. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  9060. this._completedLoop = true;
  9061. this.trigger('loopComplete');
  9062. }
  9063. } else {
  9064. this.setCurrentRawFrameValue(nextValue);
  9065. }
  9066. } else if(nextValue < 0) {
  9067. if (!this.checkSegments(nextValue % this.totalFrames)) {
  9068. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) {
  9069. this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames));
  9070. if(!this._completedLoop) {
  9071. this._completedLoop = true;
  9072. } else {
  9073. this.trigger('loopComplete');
  9074. }
  9075. } else {
  9076. _isComplete = true;
  9077. nextValue = 0;
  9078. }
  9079. }
  9080. } else {
  9081. this.setCurrentRawFrameValue(nextValue);
  9082. }
  9083. if (_isComplete) {
  9084. this.setCurrentRawFrameValue(nextValue);
  9085. this.pause();
  9086. this.trigger('complete');
  9087. }
  9088. };
  9089. AnimationItem.prototype.adjustSegment = function(arr, offset){
  9090. this.playCount = 0;
  9091. if(arr[1] < arr[0]){
  9092. if(this.frameModifier > 0){
  9093. if(this.playSpeed < 0){
  9094. this.setSpeed(-this.playSpeed);
  9095. } else {
  9096. this.setDirection(-1);
  9097. }
  9098. }
  9099. this.timeCompleted = this.totalFrames = arr[0] - arr[1];
  9100. this.firstFrame = arr[1];
  9101. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  9102. } else if(arr[1] > arr[0]){
  9103. if(this.frameModifier < 0){
  9104. if(this.playSpeed < 0){
  9105. this.setSpeed(-this.playSpeed);
  9106. } else {
  9107. this.setDirection(1);
  9108. }
  9109. }
  9110. this.timeCompleted = this.totalFrames = arr[1] - arr[0];
  9111. this.firstFrame = arr[0];
  9112. this.setCurrentRawFrameValue(0.001 + offset);
  9113. }
  9114. this.trigger('segmentStart');
  9115. };
  9116. AnimationItem.prototype.setSegment = function (init,end) {
  9117. var pendingFrame = -1;
  9118. if(this.isPaused) {
  9119. if (this.currentRawFrame + this.firstFrame < init) {
  9120. pendingFrame = init;
  9121. } else if (this.currentRawFrame + this.firstFrame > end) {
  9122. pendingFrame = end - init;
  9123. }
  9124. }
  9125. this.firstFrame = init;
  9126. this.timeCompleted = this.totalFrames = end - init;
  9127. if(pendingFrame !== -1) {
  9128. this.goToAndStop(pendingFrame,true);
  9129. }
  9130. };
  9131. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  9132. if (forceFlag) {
  9133. this.segments.length = 0;
  9134. }
  9135. if (typeof arr[0] === 'object') {
  9136. var i, len = arr.length;
  9137. for (i = 0; i < len; i += 1) {
  9138. this.segments.push(arr[i]);
  9139. }
  9140. } else {
  9141. this.segments.push(arr);
  9142. }
  9143. if (this.segments.length && forceFlag) {
  9144. this.adjustSegment(this.segments.shift(), 0);
  9145. }
  9146. if (this.isPaused) {
  9147. this.play();
  9148. }
  9149. };
  9150. AnimationItem.prototype.resetSegments = function (forceFlag) {
  9151. this.segments.length = 0;
  9152. this.segments.push([this.animationData.ip,this.animationData.op]);
  9153. //this.segments.push([this.animationData.ip*this.frameRate,Math.floor(this.animationData.op - this.animationData.ip+this.animationData.ip*this.frameRate)]);
  9154. if (forceFlag) {
  9155. this.checkSegments(0);
  9156. }
  9157. };
  9158. AnimationItem.prototype.checkSegments = function(offset) {
  9159. if (this.segments.length) {
  9160. this.adjustSegment(this.segments.shift(), offset);
  9161. return true;
  9162. }
  9163. return false;
  9164. };
  9165. AnimationItem.prototype.destroy = function (name) {
  9166. if ((name && this.name != name) || !this.renderer) {
  9167. return;
  9168. }
  9169. this.renderer.destroy();
  9170. this.imagePreloader.destroy();
  9171. this.trigger('destroy');
  9172. this._cbs = null;
  9173. this.onEnterFrame = this.onLoopComplete = this.onComplete = this.onSegmentStart = this.onDestroy = null;
  9174. this.renderer = null;
  9175. };
  9176. AnimationItem.prototype.setCurrentRawFrameValue = function(value){
  9177. this.currentRawFrame = value;
  9178. this.gotoFrame();
  9179. };
  9180. AnimationItem.prototype.setSpeed = function (val) {
  9181. this.playSpeed = val;
  9182. this.updaFrameModifier();
  9183. };
  9184. AnimationItem.prototype.setDirection = function (val) {
  9185. this.playDirection = val < 0 ? -1 : 1;
  9186. this.updaFrameModifier();
  9187. };
  9188. AnimationItem.prototype.setVolume = function (val, name) {
  9189. if (name && this.name !== name) {
  9190. return;
  9191. }
  9192. this.audioController.setVolume(val);
  9193. };
  9194. AnimationItem.prototype.getVolume = function () {
  9195. return this.audioController.getVolume();
  9196. };
  9197. AnimationItem.prototype.mute = function (name) {
  9198. if (name && this.name !== name) {
  9199. return;
  9200. }
  9201. this.audioController.mute();
  9202. };
  9203. AnimationItem.prototype.unmute = function (name) {
  9204. if(name && this.name !== name){
  9205. return;
  9206. }
  9207. this.audioController.unmute();
  9208. };
  9209. AnimationItem.prototype.updaFrameModifier = function () {
  9210. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  9211. this.audioController.setRate(this.playSpeed * this.playDirection)
  9212. };
  9213. AnimationItem.prototype.getPath = function () {
  9214. return this.path;
  9215. };
  9216. AnimationItem.prototype.getAssetsPath = function (assetData) {
  9217. var path = '';
  9218. if(assetData.e) {
  9219. path = assetData.p;
  9220. } else if(this.assetsPath){
  9221. var imagePath = assetData.p;
  9222. if(imagePath.indexOf('images/') !== -1){
  9223. imagePath = imagePath.split('/')[1];
  9224. }
  9225. path = this.assetsPath + imagePath;
  9226. } else {
  9227. path = this.path;
  9228. path += assetData.u ? assetData.u : '';
  9229. path += assetData.p;
  9230. }
  9231. return path;
  9232. };
  9233. AnimationItem.prototype.getAssetData = function (id) {
  9234. var i = 0, len = this.assets.length;
  9235. while (i < len) {
  9236. if(id == this.assets[i].id){
  9237. return this.assets[i];
  9238. }
  9239. i += 1;
  9240. }
  9241. };
  9242. AnimationItem.prototype.hide = function () {
  9243. this.renderer.hide();
  9244. };
  9245. AnimationItem.prototype.show = function () {
  9246. this.renderer.show();
  9247. };
  9248. AnimationItem.prototype.getDuration = function (isFrame) {
  9249. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  9250. };
  9251. AnimationItem.prototype.trigger = function(name){
  9252. if(this._cbs && this._cbs[name]){
  9253. switch(name){
  9254. case 'enterFrame':
  9255. this.triggerEvent(name,new BMEnterFrameEvent(name,this.currentFrame,this.totalFrames,this.frameModifier));
  9256. break;
  9257. case 'loopComplete':
  9258. this.triggerEvent(name,new BMCompleteLoopEvent(name,this.loop,this.playCount,this.frameMult));
  9259. break;
  9260. case 'complete':
  9261. this.triggerEvent(name,new BMCompleteEvent(name,this.frameMult));
  9262. break;
  9263. case 'segmentStart':
  9264. this.triggerEvent(name,new BMSegmentStartEvent(name,this.firstFrame,this.totalFrames));
  9265. break;
  9266. case 'destroy':
  9267. this.triggerEvent(name,new BMDestroyEvent(name,this));
  9268. break;
  9269. default:
  9270. this.triggerEvent(name);
  9271. }
  9272. }
  9273. if(name === 'enterFrame' && this.onEnterFrame){
  9274. this.onEnterFrame.call(this,new BMEnterFrameEvent(name,this.currentFrame,this.totalFrames,this.frameMult));
  9275. }
  9276. if(name === 'loopComplete' && this.onLoopComplete){
  9277. this.onLoopComplete.call(this,new BMCompleteLoopEvent(name,this.loop,this.playCount,this.frameMult));
  9278. }
  9279. if(name === 'complete' && this.onComplete){
  9280. this.onComplete.call(this,new BMCompleteEvent(name,this.frameMult));
  9281. }
  9282. if(name === 'segmentStart' && this.onSegmentStart){
  9283. this.onSegmentStart.call(this,new BMSegmentStartEvent(name,this.firstFrame,this.totalFrames));
  9284. }
  9285. if(name === 'destroy' && this.onDestroy){
  9286. this.onDestroy.call(this,new BMDestroyEvent(name,this));
  9287. }
  9288. };
  9289. AnimationItem.prototype.triggerRenderFrameError = function(nativeError) {
  9290. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  9291. this.triggerEvent('error', error);
  9292. if (this.onError) {
  9293. this.onError.call(this, error);
  9294. }
  9295. }
  9296. AnimationItem.prototype.triggerConfigError = function(nativeError) {
  9297. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  9298. this.triggerEvent('error', error);
  9299. if (this.onError) {
  9300. this.onError.call(this, error);
  9301. }
  9302. }
  9303. var Expressions = (function(){
  9304. var ob = {};
  9305. ob.initExpressions = initExpressions;
  9306. function initExpressions(animation){
  9307. var stackCount = 0;
  9308. var registers = [];
  9309. function pushExpression() {
  9310. stackCount += 1;
  9311. }
  9312. function popExpression() {
  9313. stackCount -= 1;
  9314. if (stackCount === 0) {
  9315. releaseInstances();
  9316. }
  9317. }
  9318. function registerExpressionProperty(expression) {
  9319. if (registers.indexOf(expression) === -1) {
  9320. registers.push(expression)
  9321. }
  9322. }
  9323. function releaseInstances() {
  9324. var i, len = registers.length;
  9325. for (i = 0; i < len; i += 1) {
  9326. registers[i].release();
  9327. }
  9328. registers.length = 0;
  9329. }
  9330. animation.renderer.compInterface = CompExpressionInterface(animation.renderer);
  9331. animation.renderer.globalData.projectInterface.registerComposition(animation.renderer);
  9332. animation.renderer.globalData.pushExpression = pushExpression;
  9333. animation.renderer.globalData.popExpression = popExpression;
  9334. animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty;
  9335. }
  9336. return ob;
  9337. }());
  9338. expressionsPlugin = Expressions;
  9339. var ExpressionManager = (function(){
  9340. 'use strict';
  9341. var ob = {};
  9342. var Math = BMMath;
  9343. var window = null;
  9344. var document = null;
  9345. function $bm_isInstanceOfArray(arr) {
  9346. return arr.constructor === Array || arr.constructor === Float32Array;
  9347. }
  9348. function isNumerable(tOfV, v) {
  9349. return tOfV === 'number' || tOfV === 'boolean' || tOfV === 'string' || v instanceof Number;
  9350. }
  9351. function $bm_neg(a){
  9352. var tOfA = typeof a;
  9353. if(tOfA === 'number' || tOfA === 'boolean' || a instanceof Number ){
  9354. return -a;
  9355. }
  9356. if($bm_isInstanceOfArray(a)){
  9357. var i, lenA = a.length;
  9358. var retArr = [];
  9359. for(i=0;i<lenA;i+=1){
  9360. retArr[i] = -a[i];
  9361. }
  9362. return retArr;
  9363. }
  9364. if (a.propType) {
  9365. return a.v;
  9366. }
  9367. }
  9368. var easeInBez = BezierFactory.getBezierEasing(0.333,0,.833,.833, 'easeIn').get;
  9369. var easeOutBez = BezierFactory.getBezierEasing(0.167,0.167,.667,1, 'easeOut').get;
  9370. var easeInOutBez = BezierFactory.getBezierEasing(.33,0,.667,1, 'easeInOut').get;
  9371. function sum(a,b) {
  9372. var tOfA = typeof a;
  9373. var tOfB = typeof b;
  9374. if(tOfA === 'string' || tOfB === 'string'){
  9375. return a + b;
  9376. }
  9377. if(isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  9378. return a + b;
  9379. }
  9380. if($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)){
  9381. a = a.slice(0);
  9382. a[0] = a[0] + b;
  9383. return a;
  9384. }
  9385. if(isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)){
  9386. b = b.slice(0);
  9387. b[0] = a + b[0];
  9388. return b;
  9389. }
  9390. if($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)){
  9391. var i = 0, lenA = a.length, lenB = b.length;
  9392. var retArr = [];
  9393. while(i<lenA || i < lenB){
  9394. if((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)){
  9395. retArr[i] = a[i] + b[i];
  9396. }else{
  9397. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  9398. }
  9399. i += 1;
  9400. }
  9401. return retArr;
  9402. }
  9403. return 0;
  9404. }
  9405. var add = sum;
  9406. function sub(a,b) {
  9407. var tOfA = typeof a;
  9408. var tOfB = typeof b;
  9409. if(isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  9410. if(tOfA === 'string') {
  9411. a = parseInt(a);
  9412. }
  9413. if(tOfB === 'string') {
  9414. b = parseInt(b);
  9415. }
  9416. return a - b;
  9417. }
  9418. if( $bm_isInstanceOfArray(a) && isNumerable(tOfB, b)){
  9419. a = a.slice(0);
  9420. a[0] = a[0] - b;
  9421. return a;
  9422. }
  9423. if(isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)){
  9424. b = b.slice(0);
  9425. b[0] = a - b[0];
  9426. return b;
  9427. }
  9428. if($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)){
  9429. var i = 0, lenA = a.length, lenB = b.length;
  9430. var retArr = [];
  9431. while(i<lenA || i < lenB){
  9432. if((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)){
  9433. retArr[i] = a[i] - b[i];
  9434. }else{
  9435. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  9436. }
  9437. i += 1;
  9438. }
  9439. return retArr;
  9440. }
  9441. return 0;
  9442. }
  9443. function mul(a,b) {
  9444. var tOfA = typeof a;
  9445. var tOfB = typeof b;
  9446. var arr;
  9447. if(isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  9448. return a * b;
  9449. }
  9450. var i, len;
  9451. if($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)){
  9452. len = a.length;
  9453. arr = createTypedArray('float32', len);
  9454. for(i=0;i<len;i+=1){
  9455. arr[i] = a[i] * b;
  9456. }
  9457. return arr;
  9458. }
  9459. if(isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)){
  9460. len = b.length;
  9461. arr = createTypedArray('float32', len);
  9462. for(i=0;i<len;i+=1){
  9463. arr[i] = a * b[i];
  9464. }
  9465. return arr;
  9466. }
  9467. return 0;
  9468. }
  9469. function div(a,b) {
  9470. var tOfA = typeof a;
  9471. var tOfB = typeof b;
  9472. var arr;
  9473. if(isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  9474. return a / b;
  9475. }
  9476. var i, len;
  9477. if($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)){
  9478. len = a.length;
  9479. arr = createTypedArray('float32', len);
  9480. for(i=0;i<len;i+=1){
  9481. arr[i] = a[i] / b;
  9482. }
  9483. return arr;
  9484. }
  9485. if(isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)){
  9486. len = b.length;
  9487. arr = createTypedArray('float32', len);
  9488. for(i=0;i<len;i+=1){
  9489. arr[i] = a / b[i];
  9490. }
  9491. return arr;
  9492. }
  9493. return 0;
  9494. }
  9495. function mod(a,b) {
  9496. if(typeof a === 'string') {
  9497. a = parseInt(a);
  9498. }
  9499. if(typeof b === 'string') {
  9500. b = parseInt(b);
  9501. }
  9502. return a % b;
  9503. }
  9504. var $bm_sum = sum;
  9505. var $bm_sub = sub;
  9506. var $bm_mul = mul;
  9507. var $bm_div = div;
  9508. var $bm_mod = mod;
  9509. function clamp(num, min, max) {
  9510. if(min > max){
  9511. var mm = max;
  9512. max = min;
  9513. min = mm;
  9514. }
  9515. return Math.min(Math.max(num, min), max);
  9516. }
  9517. function radiansToDegrees(val) {
  9518. return val/degToRads;
  9519. }
  9520. var radians_to_degrees = radiansToDegrees;
  9521. function degreesToRadians(val) {
  9522. return val*degToRads;
  9523. }
  9524. var degrees_to_radians = radiansToDegrees;
  9525. var helperLengthArray = [0,0,0,0,0,0];
  9526. function length(arr1, arr2) {
  9527. if (typeof arr1 === 'number' || arr1 instanceof Number) {
  9528. arr2 = arr2 || 0;
  9529. return Math.abs(arr1 - arr2);
  9530. }
  9531. if(!arr2) {
  9532. arr2 = helperLengthArray;
  9533. }
  9534. var i, len = Math.min(arr1.length, arr2.length);
  9535. var addedLength = 0;
  9536. for (i = 0; i < len; i += 1) {
  9537. addedLength += Math.pow(arr2[i] - arr1[i], 2);
  9538. }
  9539. return Math.sqrt(addedLength);
  9540. }
  9541. function normalize(vec) {
  9542. return div(vec, length(vec));
  9543. }
  9544. function rgbToHsl(val) {
  9545. var r = val[0]; var g = val[1]; var b = val[2];
  9546. var max = Math.max(r, g, b), min = Math.min(r, g, b);
  9547. var h, s, l = (max + min) / 2;
  9548. if(max == min){
  9549. h = s = 0; // achromatic
  9550. }else{
  9551. var d = max - min;
  9552. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  9553. switch(max){
  9554. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  9555. case g: h = (b - r) / d + 2; break;
  9556. case b: h = (r - g) / d + 4; break;
  9557. }
  9558. h /= 6;
  9559. }
  9560. return [h, s, l,val[3]];
  9561. }
  9562. function hue2rgb(p, q, t){
  9563. if(t < 0) t += 1;
  9564. if(t > 1) t -= 1;
  9565. if(t < 1/6) return p + (q - p) * 6 * t;
  9566. if(t < 1/2) return q;
  9567. if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
  9568. return p;
  9569. }
  9570. function hslToRgb(val){
  9571. var h = val[0];
  9572. var s = val[1];
  9573. var l = val[2];
  9574. var r, g, b;
  9575. if(s === 0){
  9576. r = g = b = l; // achromatic
  9577. }else{
  9578. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  9579. var p = 2 * l - q;
  9580. r = hue2rgb(p, q, h + 1/3);
  9581. g = hue2rgb(p, q, h);
  9582. b = hue2rgb(p, q, h - 1/3);
  9583. }
  9584. return [r, g , b, val[3]];
  9585. }
  9586. function linear(t, tMin, tMax, value1, value2){
  9587. if(value1 === undefined || value2 === undefined){
  9588. value1 = tMin;
  9589. value2 = tMax;
  9590. tMin = 0;
  9591. tMax = 1;
  9592. }
  9593. if(tMax < tMin) {
  9594. var _tMin = tMax;
  9595. tMax = tMin;
  9596. tMin = _tMin;
  9597. }
  9598. if(t <= tMin) {
  9599. return value1;
  9600. }else if(t >= tMax){
  9601. return value2;
  9602. }
  9603. var perc = tMax === tMin ? 0 : (t-tMin)/(tMax-tMin);
  9604. if(!value1.length){
  9605. return value1 + (value2-value1)*perc;
  9606. }
  9607. var i, len = value1.length;
  9608. var arr = createTypedArray('float32', len);
  9609. for(i=0;i<len;i+=1){
  9610. arr[i] = value1[i] + (value2[i]-value1[i])*perc;
  9611. }
  9612. return arr;
  9613. }
  9614. function random(min,max){
  9615. if(max === undefined){
  9616. if(min === undefined){
  9617. min = 0;
  9618. max = 1;
  9619. } else {
  9620. max = min;
  9621. min = undefined;
  9622. }
  9623. }
  9624. if(max.length){
  9625. var i, len = max.length;
  9626. if(!min){
  9627. min = createTypedArray('float32', len);
  9628. }
  9629. var arr = createTypedArray('float32', len);
  9630. var rnd = BMMath.random();
  9631. for(i=0;i<len;i+=1){
  9632. arr[i] = min[i] + rnd*(max[i]-min[i]);
  9633. }
  9634. return arr;
  9635. }
  9636. if(min === undefined){
  9637. min = 0;
  9638. }
  9639. var rndm = BMMath.random();
  9640. return min + rndm*(max-min);
  9641. }
  9642. function createPath(points, inTangents, outTangents, closed) {
  9643. var i, len = points.length;
  9644. var path = shape_pool.newElement();
  9645. path.setPathData(!!closed, len);
  9646. var arrPlaceholder = [0,0], inVertexPoint, outVertexPoint;
  9647. for(i = 0; i < len; i += 1) {
  9648. inVertexPoint = (inTangents && inTangents[i]) ? inTangents[i] : arrPlaceholder;
  9649. outVertexPoint = (outTangents && outTangents[i]) ? outTangents[i] : arrPlaceholder;
  9650. 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);
  9651. }
  9652. return path;
  9653. }
  9654. function initiateExpression(elem,data,property){
  9655. var val = data.x;
  9656. var needsVelocity = /velocity(?![\w\d])/.test(val);
  9657. var _needsRandom = val.indexOf('random') !== -1;
  9658. var elemType = elem.data.ty;
  9659. var transform,$bm_transform,content,effect;
  9660. var thisProperty = property;
  9661. thisProperty.valueAtTime = thisProperty.getValueAtTime;
  9662. Object.defineProperty(thisProperty, 'value', {
  9663. get: function() {
  9664. return thisProperty.v
  9665. }
  9666. })
  9667. elem.comp.frameDuration = 1/elem.comp.globalData.frameRate;
  9668. elem.comp.displayStartTime = 0;
  9669. var inPoint = elem.data.ip/elem.comp.globalData.frameRate;
  9670. var outPoint = elem.data.op/elem.comp.globalData.frameRate;
  9671. var width = elem.data.sw ? elem.data.sw : 0;
  9672. var height = elem.data.sh ? elem.data.sh : 0;
  9673. var name = elem.data.nm;
  9674. var loopIn, loop_in, loopOut, loop_out, smooth;
  9675. var toWorld,fromWorld,fromComp,toComp,fromCompToSurface, position, rotation, anchorPoint, scale, thisLayer, thisComp,mask,valueAtTime,velocityAtTime;
  9676. var __expression_functions = [];
  9677. if(data.xf) {
  9678. var i, len = data.xf.length;
  9679. for(i = 0; i < len; i += 1) {
  9680. __expression_functions[i] = eval('(function(){ return ' + data.xf[i] + '}())');
  9681. }
  9682. }
  9683. var scoped_bm_rt;
  9684. var expression_function = eval('[function _expression_function(){' + val+';scoped_bm_rt=$bm_rt}' + ']')[0];
  9685. var numKeys = property.kf ? data.k.length : 0;
  9686. var active = !this.data || this.data.hd !== true;
  9687. var wiggle = function wiggle(freq,amp){
  9688. var i,j, len = this.pv.length ? this.pv.length : 1;
  9689. var addedAmps = createTypedArray('float32', len);
  9690. freq = 5;
  9691. var iterations = Math.floor(time*freq);
  9692. i = 0;
  9693. j = 0;
  9694. while(i<iterations){
  9695. //var rnd = BMMath.random();
  9696. for(j=0;j<len;j+=1){
  9697. addedAmps[j] += -amp + amp*2*BMMath.random();
  9698. //addedAmps[j] += -amp + amp*2*rnd;
  9699. }
  9700. i += 1;
  9701. }
  9702. //var rnd2 = BMMath.random();
  9703. var periods = time*freq;
  9704. var perc = periods - Math.floor(periods);
  9705. var arr = createTypedArray('float32', len);
  9706. if(len>1){
  9707. for(j=0;j<len;j+=1){
  9708. arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*BMMath.random())*perc;
  9709. //arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc;
  9710. //arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc);
  9711. }
  9712. return arr;
  9713. } else {
  9714. return this.pv + addedAmps[0] + (-amp + amp*2*BMMath.random())*perc;
  9715. }
  9716. }.bind(this);
  9717. if(thisProperty.loopIn) {
  9718. loopIn = thisProperty.loopIn.bind(thisProperty);
  9719. loop_in = loopIn;
  9720. }
  9721. if(thisProperty.loopOut) {
  9722. loopOut = thisProperty.loopOut.bind(thisProperty);
  9723. loop_out = loopOut;
  9724. }
  9725. if(thisProperty.smooth) {
  9726. smooth = thisProperty.smooth.bind(thisProperty);
  9727. }
  9728. function loopInDuration(type,duration){
  9729. return loopIn(type,duration,true);
  9730. }
  9731. function loopOutDuration(type,duration){
  9732. return loopOut(type,duration,true);
  9733. }
  9734. if(this.getValueAtTime) {
  9735. valueAtTime = this.getValueAtTime.bind(this);
  9736. }
  9737. if(this.getVelocityAtTime) {
  9738. velocityAtTime = this.getVelocityAtTime.bind(this);
  9739. }
  9740. var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface);
  9741. function lookAt(elem1,elem2){
  9742. var fVec = [elem2[0]-elem1[0],elem2[1]-elem1[1],elem2[2]-elem1[2]];
  9743. var pitch = Math.atan2(fVec[0],Math.sqrt(fVec[1]*fVec[1]+fVec[2]*fVec[2]))/degToRads;
  9744. var yaw = -Math.atan2(fVec[1],fVec[2])/degToRads;
  9745. return [yaw,pitch,0];
  9746. }
  9747. function easeOut(t, tMin, tMax, val1, val2){
  9748. return applyEase(easeOutBez, t, tMin, tMax, val1, val2);
  9749. }
  9750. function easeIn(t, tMin, tMax, val1, val2){
  9751. return applyEase(easeInBez, t, tMin, tMax, val1, val2);
  9752. }
  9753. function ease(t, tMin, tMax, val1, val2){
  9754. return applyEase(easeInOutBez, t, tMin, tMax, val1, val2);
  9755. }
  9756. function applyEase(fn, t, tMin, tMax, val1, val2) {
  9757. if(val1 === undefined){
  9758. val1 = tMin;
  9759. val2 = tMax;
  9760. } else {
  9761. t = (t - tMin) / (tMax - tMin);
  9762. }
  9763. t = t > 1 ? 1 : t < 0 ? 0 : t;
  9764. var mult = fn(t);
  9765. if($bm_isInstanceOfArray(val1)) {
  9766. var i, len = val1.length;
  9767. var arr = createTypedArray('float32', len);
  9768. for (i = 0; i < len; i += 1) {
  9769. arr[i] = (val2[i] - val1[i]) * mult + val1[i];
  9770. }
  9771. return arr;
  9772. } else {
  9773. return (val2 - val1) * mult + val1;
  9774. }
  9775. }
  9776. function nearestKey(time){
  9777. var i, len = data.k.length,index,keyTime;
  9778. if(!data.k.length || typeof(data.k[0]) === 'number'){
  9779. index = 0;
  9780. keyTime = 0;
  9781. } else {
  9782. index = -1;
  9783. time *= elem.comp.globalData.frameRate;
  9784. if (time < data.k[0].t) {
  9785. index = 1;
  9786. keyTime = data.k[0].t;
  9787. } else {
  9788. for(i=0;i<len-1;i+=1){
  9789. if(time === data.k[i].t){
  9790. index = i + 1;
  9791. keyTime = data.k[i].t;
  9792. break;
  9793. }else if(time>data.k[i].t && time<data.k[i+1].t){
  9794. if(time-data.k[i].t > data.k[i+1].t - time){
  9795. index = i + 2;
  9796. keyTime = data.k[i+1].t;
  9797. } else {
  9798. index = i + 1;
  9799. keyTime = data.k[i].t;
  9800. }
  9801. break;
  9802. }
  9803. }
  9804. if(index === -1){
  9805. index = i + 1;
  9806. keyTime = data.k[i].t;
  9807. }
  9808. }
  9809. }
  9810. var ob = {};
  9811. ob.index = index;
  9812. ob.time = keyTime/elem.comp.globalData.frameRate;
  9813. return ob;
  9814. }
  9815. function key(ind){
  9816. var ob, i, len;
  9817. if(!data.k.length || typeof(data.k[0]) === 'number'){
  9818. throw new Error('The property has no keyframe at index ' + ind);
  9819. }
  9820. ind -= 1;
  9821. ob = {
  9822. time: data.k[ind].t/elem.comp.globalData.frameRate,
  9823. value: []
  9824. };
  9825. var arr = data.k[ind].hasOwnProperty('s') ? data.k[ind].s : data.k[ind - 1].e;
  9826. len = arr.length;
  9827. for(i=0;i<len;i+=1){
  9828. ob[i] = arr[i];
  9829. ob.value[i] = arr[i]
  9830. }
  9831. return ob;
  9832. }
  9833. function framesToTime(frames, fps) {
  9834. if (!fps) {
  9835. fps = elem.comp.globalData.frameRate;
  9836. }
  9837. return frames / fps;
  9838. }
  9839. function timeToFrames(t, fps) {
  9840. if (!t && t !== 0) {
  9841. t = time;
  9842. }
  9843. if (!fps) {
  9844. fps = elem.comp.globalData.frameRate;
  9845. }
  9846. return t * fps;
  9847. }
  9848. function seedRandom(seed){
  9849. BMMath.seedrandom(randSeed + seed);
  9850. }
  9851. function sourceRectAtTime() {
  9852. return elem.sourceRectAtTime();
  9853. }
  9854. function substring(init, end) {
  9855. if(typeof value === 'string') {
  9856. if(end === undefined) {
  9857. return value.substring(init)
  9858. }
  9859. return value.substring(init, end)
  9860. }
  9861. return '';
  9862. }
  9863. function substr(init, end) {
  9864. if(typeof value === 'string') {
  9865. if(end === undefined) {
  9866. return value.substr(init)
  9867. }
  9868. return value.substr(init, end)
  9869. }
  9870. return '';
  9871. }
  9872. function posterizeTime(framesPerSecond) {
  9873. time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond
  9874. value = valueAtTime(time)
  9875. }
  9876. var time, velocity, value, text, textIndex, textTotal, selectorValue;
  9877. var index = elem.data.ind;
  9878. var hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  9879. var parent;
  9880. var randSeed = Math.floor(Math.random()*1000000);
  9881. var globalData = elem.globalData;
  9882. function executeExpression(_value) {
  9883. // globalData.pushExpression();
  9884. value = _value;
  9885. if (_needsRandom) {
  9886. seedRandom(randSeed);
  9887. }
  9888. if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') {
  9889. return value;
  9890. }
  9891. if(this.propType === 'textSelector'){
  9892. textIndex = this.textIndex;
  9893. textTotal = this.textTotal;
  9894. selectorValue = this.selectorValue;
  9895. }
  9896. if (!thisLayer) {
  9897. text = elem.layerInterface.text;
  9898. thisLayer = elem.layerInterface;
  9899. thisComp = elem.comp.compInterface;
  9900. toWorld = thisLayer.toWorld.bind(thisLayer);
  9901. fromWorld = thisLayer.fromWorld.bind(thisLayer);
  9902. fromComp = thisLayer.fromComp.bind(thisLayer);
  9903. toComp = thisLayer.toComp.bind(thisLayer);
  9904. mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null;
  9905. fromCompToSurface = fromComp;
  9906. }
  9907. if (!transform) {
  9908. transform = elem.layerInterface("ADBE Transform Group");
  9909. $bm_transform = transform;
  9910. if(transform) {
  9911. anchorPoint = transform.anchorPoint;
  9912. /*position = transform.position;
  9913. rotation = transform.rotation;
  9914. scale = transform.scale;*/
  9915. }
  9916. }
  9917. if (elemType === 4 && !content) {
  9918. content = thisLayer("ADBE Root Vectors Group");
  9919. }
  9920. if (!effect) {
  9921. effect = thisLayer(4);
  9922. }
  9923. hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  9924. if (hasParent && !parent) {
  9925. parent = elem.hierarchy[0].layerInterface;
  9926. }
  9927. time = this.comp.renderedFrame/this.comp.globalData.frameRate;
  9928. if (needsVelocity) {
  9929. velocity = velocityAtTime(time);
  9930. }
  9931. expression_function();
  9932. this.frameExpressionId = elem.globalData.frameId;
  9933. //TODO: Check if it's possible to return on ShapeInterface the .v value
  9934. if (scoped_bm_rt.propType === "shape") {
  9935. scoped_bm_rt = scoped_bm_rt.v;
  9936. }
  9937. // globalData.popExpression();
  9938. return scoped_bm_rt;
  9939. }
  9940. return executeExpression;
  9941. }
  9942. ob.initiateExpression = initiateExpression;
  9943. return ob;
  9944. }());
  9945. var expressionHelpers = (function(){
  9946. function searchExpressions(elem,data,prop){
  9947. if(data.x){
  9948. prop.k = true;
  9949. prop.x = true;
  9950. prop.initiateExpression = ExpressionManager.initiateExpression;
  9951. prop.effectsSequence.push(prop.initiateExpression(elem,data,prop).bind(prop));
  9952. }
  9953. }
  9954. function getValueAtTime(frameNum) {
  9955. frameNum *= this.elem.globalData.frameRate;
  9956. frameNum -= this.offsetTime;
  9957. if(frameNum !== this._cachingAtTime.lastFrame) {
  9958. this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
  9959. this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
  9960. this._cachingAtTime.lastFrame = frameNum;
  9961. }
  9962. return this._cachingAtTime.value;
  9963. }
  9964. function getSpeedAtTime(frameNum) {
  9965. var delta = -0.01;
  9966. var v1 = this.getValueAtTime(frameNum);
  9967. var v2 = this.getValueAtTime(frameNum + delta);
  9968. var speed = 0;
  9969. if(v1.length){
  9970. var i;
  9971. for(i=0;i<v1.length;i+=1){
  9972. speed += Math.pow(v2[i] - v1[i], 2);
  9973. }
  9974. speed = Math.sqrt(speed) * 100;
  9975. } else {
  9976. speed = 0;
  9977. }
  9978. return speed;
  9979. }
  9980. function getVelocityAtTime(frameNum) {
  9981. if(this.vel !== undefined){
  9982. return this.vel;
  9983. }
  9984. var delta = -0.001;
  9985. //frameNum += this.elem.data.st;
  9986. var v1 = this.getValueAtTime(frameNum);
  9987. var v2 = this.getValueAtTime(frameNum + delta);
  9988. var velocity;
  9989. if(v1.length){
  9990. velocity = createTypedArray('float32', v1.length);
  9991. var i;
  9992. for(i=0;i<v1.length;i+=1){
  9993. //removing frameRate
  9994. //if needed, don't add it here
  9995. //velocity[i] = this.elem.globalData.frameRate*((v2[i] - v1[i])/delta);
  9996. velocity[i] = (v2[i] - v1[i])/delta;
  9997. }
  9998. } else {
  9999. velocity = (v2 - v1)/delta;
  10000. }
  10001. return velocity;
  10002. }
  10003. function getStaticValueAtTime() {
  10004. return this.pv;
  10005. }
  10006. function setGroupProperty(propertyGroup){
  10007. this.propertyGroup = propertyGroup;
  10008. }
  10009. return {
  10010. searchExpressions: searchExpressions,
  10011. getSpeedAtTime: getSpeedAtTime,
  10012. getVelocityAtTime: getVelocityAtTime,
  10013. getValueAtTime: getValueAtTime,
  10014. getStaticValueAtTime: getStaticValueAtTime,
  10015. setGroupProperty: setGroupProperty,
  10016. }
  10017. }());
  10018. (function addPropertyDecorator() {
  10019. function loopOut(type,duration,durationFlag){
  10020. if(!this.k || !this.keyframes){
  10021. return this.pv;
  10022. }
  10023. type = type ? type.toLowerCase() : '';
  10024. var currentFrame = this.comp.renderedFrame;
  10025. var keyframes = this.keyframes;
  10026. var lastKeyFrame = keyframes[keyframes.length - 1].t;
  10027. if(currentFrame<=lastKeyFrame){
  10028. return this.pv;
  10029. }else{
  10030. var cycleDuration, firstKeyFrame;
  10031. if(!durationFlag){
  10032. if(!duration || duration > keyframes.length - 1){
  10033. duration = keyframes.length - 1;
  10034. }
  10035. firstKeyFrame = keyframes[keyframes.length - 1 - duration].t;
  10036. cycleDuration = lastKeyFrame - firstKeyFrame;
  10037. } else {
  10038. if(!duration){
  10039. cycleDuration = Math.max(0,lastKeyFrame - this.elem.data.ip);
  10040. } else {
  10041. cycleDuration = Math.abs(lastKeyFrame - elem.comp.globalData.frameRate*duration);
  10042. }
  10043. firstKeyFrame = lastKeyFrame - cycleDuration;
  10044. }
  10045. var i, len, ret;
  10046. if(type === 'pingpong') {
  10047. var iterations = Math.floor((currentFrame - firstKeyFrame)/cycleDuration);
  10048. if(iterations % 2 !== 0){
  10049. return this.getValueAtTime(((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0);
  10050. }
  10051. } else if(type === 'offset'){
  10052. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  10053. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  10054. var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
  10055. var repeats = Math.floor((currentFrame - firstKeyFrame)/cycleDuration);
  10056. if(this.pv.length){
  10057. ret = new Array(initV.length);
  10058. len = ret.length;
  10059. for(i=0;i<len;i+=1){
  10060. ret[i] = (endV[i]-initV[i])*repeats + current[i];
  10061. }
  10062. return ret;
  10063. }
  10064. return (endV-initV)*repeats + current;
  10065. } else if(type === 'continue'){
  10066. var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  10067. var nextLastValue = this.getValueAtTime((lastKeyFrame - 0.001) / this.comp.globalData.frameRate, 0);
  10068. if(this.pv.length){
  10069. ret = new Array(lastValue.length);
  10070. len = ret.length;
  10071. for(i=0;i<len;i+=1){
  10072. ret[i] = lastValue[i] + (lastValue[i]-nextLastValue[i])*((currentFrame - lastKeyFrame)/ this.comp.globalData.frameRate)/0.0005;
  10073. }
  10074. return ret;
  10075. }
  10076. return lastValue + (lastValue-nextLastValue)*(((currentFrame - lastKeyFrame))/0.001);
  10077. }
  10078. return this.getValueAtTime((((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0);
  10079. }
  10080. }
  10081. function loopIn(type,duration, durationFlag) {
  10082. if(!this.k){
  10083. return this.pv;
  10084. }
  10085. type = type ? type.toLowerCase() : '';
  10086. var currentFrame = this.comp.renderedFrame;
  10087. var keyframes = this.keyframes;
  10088. var firstKeyFrame = keyframes[0].t;
  10089. if(currentFrame>=firstKeyFrame){
  10090. return this.pv;
  10091. }else{
  10092. var cycleDuration, lastKeyFrame;
  10093. if(!durationFlag){
  10094. if(!duration || duration > keyframes.length - 1){
  10095. duration = keyframes.length - 1;
  10096. }
  10097. lastKeyFrame = keyframes[duration].t;
  10098. cycleDuration = lastKeyFrame - firstKeyFrame;
  10099. } else {
  10100. if(!duration){
  10101. cycleDuration = Math.max(0,this.elem.data.op - firstKeyFrame);
  10102. } else {
  10103. cycleDuration = Math.abs(elem.comp.globalData.frameRate*duration);
  10104. }
  10105. lastKeyFrame = firstKeyFrame + cycleDuration;
  10106. }
  10107. var i, len, ret;
  10108. if(type === 'pingpong') {
  10109. var iterations = Math.floor((firstKeyFrame - currentFrame)/cycleDuration);
  10110. if(iterations % 2 === 0){
  10111. return this.getValueAtTime((((firstKeyFrame - currentFrame)%cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0);
  10112. }
  10113. } else if(type === 'offset'){
  10114. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  10115. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  10116. var current = this.getValueAtTime((cycleDuration - (firstKeyFrame - currentFrame)%cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0);
  10117. var repeats = Math.floor((firstKeyFrame - currentFrame)/cycleDuration)+1;
  10118. if(this.pv.length){
  10119. ret = new Array(initV.length);
  10120. len = ret.length;
  10121. for(i=0;i<len;i+=1){
  10122. ret[i] = current[i]-(endV[i]-initV[i])*repeats;
  10123. }
  10124. return ret;
  10125. }
  10126. return current-(endV-initV)*repeats;
  10127. } else if(type === 'continue'){
  10128. var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  10129. var nextFirstValue = this.getValueAtTime((firstKeyFrame + 0.001) / this.comp.globalData.frameRate, 0);
  10130. if(this.pv.length){
  10131. ret = new Array(firstValue.length);
  10132. len = ret.length;
  10133. for(i=0;i<len;i+=1){
  10134. ret[i] = firstValue[i] + (firstValue[i]-nextFirstValue[i])*(firstKeyFrame - currentFrame)/0.001;
  10135. }
  10136. return ret;
  10137. }
  10138. return firstValue + (firstValue-nextFirstValue)*(firstKeyFrame - currentFrame)/0.001;
  10139. }
  10140. return this.getValueAtTime(((cycleDuration - (firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0);
  10141. }
  10142. }
  10143. function smooth(width, samples) {
  10144. if (!this.k){
  10145. return this.pv;
  10146. }
  10147. width = (width || 0.4) * 0.5;
  10148. samples = Math.floor(samples || 5);
  10149. if (samples <= 1) {
  10150. return this.pv;
  10151. }
  10152. var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate;
  10153. var initFrame = currentTime - width;
  10154. var endFrame = currentTime + width;
  10155. var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1;
  10156. var i = 0, j = 0;
  10157. var value;
  10158. if (this.pv.length) {
  10159. value = createTypedArray('float32', this.pv.length);
  10160. } else {
  10161. value = 0;
  10162. }
  10163. var sampleValue;
  10164. while (i < samples) {
  10165. sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency);
  10166. if(this.pv.length) {
  10167. for (j = 0; j < this.pv.length; j += 1) {
  10168. value[j] += sampleValue[j];
  10169. }
  10170. } else {
  10171. value += sampleValue;
  10172. }
  10173. i += 1;
  10174. }
  10175. if(this.pv.length) {
  10176. for (j = 0; j < this.pv.length; j += 1) {
  10177. value[j] /= samples;
  10178. }
  10179. } else {
  10180. value /= samples;
  10181. }
  10182. return value;
  10183. }
  10184. function getValueAtTime(frameNum) {
  10185. frameNum *= this.elem.globalData.frameRate;
  10186. frameNum -= this.offsetTime;
  10187. if(frameNum !== this._cachingAtTime.lastFrame) {
  10188. this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
  10189. this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
  10190. this._cachingAtTime.lastFrame = frameNum;
  10191. }
  10192. return this._cachingAtTime.value;
  10193. }
  10194. function getTransformValueAtTime(time) {
  10195. if (!this._transformCachingAtTime) {
  10196. this._transformCachingAtTime = {
  10197. v: new Matrix(),
  10198. };
  10199. }
  10200. ////
  10201. var matrix = this._transformCachingAtTime.v;
  10202. matrix.cloneFromProps(this.pre.props);
  10203. if (this.appliedTransformations < 1) {
  10204. var anchor = this.a.getValueAtTime(time);
  10205. matrix.translate(-anchor[0], -anchor[1], anchor[2]);
  10206. }
  10207. if (this.appliedTransformations < 2) {
  10208. var scale = this.s.getValueAtTime(time);
  10209. matrix.scale(scale[0], scale[1], scale[2]);
  10210. }
  10211. if (this.sk && this.appliedTransformations < 3) {
  10212. var skew = this.sk.getValueAtTime(time);
  10213. var skewAxis = this.sa.getValueAtTime(time);
  10214. matrix.skewFromAxis(-skew, skewAxis);
  10215. }
  10216. if (this.r && this.appliedTransformations < 4) {
  10217. var rotation = this.r.getValueAtTime(time);
  10218. matrix.rotate(-rotation);
  10219. } else if (!this.r && this.appliedTransformations < 4){
  10220. var rotationZ = this.rz.getValueAtTime(time);
  10221. var rotationY = this.ry.getValueAtTime(time);
  10222. var rotationX = this.rx.getValueAtTime(time);
  10223. var orientation = this.or.getValueAtTime(time);
  10224. matrix.rotateZ(-rotationZ.v)
  10225. .rotateY(rotationY.v)
  10226. .rotateX(rotationX.v)
  10227. .rotateZ(-orientation[2])
  10228. .rotateY(orientation[1])
  10229. .rotateX(orientation[0]);
  10230. }
  10231. if (this.data.p && this.data.p.s) {
  10232. var positionX = this.px.getValueAtTime(time);
  10233. var positionY = this.py.getValueAtTime(time);
  10234. if (this.data.p.z) {
  10235. var positionZ = this.pz.getValueAtTime(time);
  10236. matrix.translate(positionX, positionY, -positionZ);
  10237. } else {
  10238. matrix.translate(positionX, positionY, 0);
  10239. }
  10240. } else {
  10241. var position = this.p.getValueAtTime(time);
  10242. matrix.translate(position[0], position[1], -position[2]);
  10243. }
  10244. return matrix;
  10245. ////
  10246. }
  10247. function getTransformStaticValueAtTime(time) {
  10248. }
  10249. var getTransformProperty = TransformPropertyFactory.getTransformProperty;
  10250. TransformPropertyFactory.getTransformProperty = function(elem, data, container) {
  10251. var prop = getTransformProperty(elem, data, container);
  10252. if(prop.dynamicProperties.length) {
  10253. prop.getValueAtTime = getTransformValueAtTime.bind(prop);
  10254. } else {
  10255. prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop);
  10256. }
  10257. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  10258. return prop;
  10259. };
  10260. var propertyGetProp = PropertyFactory.getProp;
  10261. PropertyFactory.getProp = function(elem,data,type, mult, container){
  10262. var prop = propertyGetProp(elem,data,type, mult, container);
  10263. //prop.getVelocityAtTime = getVelocityAtTime;
  10264. //prop.loopOut = loopOut;
  10265. //prop.loopIn = loopIn;
  10266. if(prop.kf){
  10267. prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop);
  10268. } else {
  10269. prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop);
  10270. }
  10271. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  10272. prop.loopOut = loopOut;
  10273. prop.loopIn = loopIn;
  10274. prop.smooth = smooth;
  10275. prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop);
  10276. prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop);
  10277. prop.numKeys = data.a === 1 ? data.k.length : 0;
  10278. prop.propertyIndex = data.ix;
  10279. var value = 0;
  10280. if(type !== 0) {
  10281. value = createTypedArray('float32', data.a === 1 ? data.k[0].s.length : data.k.length);
  10282. }
  10283. prop._cachingAtTime = {
  10284. lastFrame: initialDefaultFrame,
  10285. lastIndex: 0,
  10286. value: value
  10287. };
  10288. expressionHelpers.searchExpressions(elem,data,prop);
  10289. if(prop.k){
  10290. container.addDynamicProperty(prop);
  10291. }
  10292. return prop;
  10293. };
  10294. function getShapeValueAtTime(frameNum) {
  10295. //For now this caching object is created only when needed instead of creating it when the shape is initialized.
  10296. if (!this._cachingAtTime) {
  10297. this._cachingAtTime = {
  10298. shapeValue: shape_pool.clone(this.pv),
  10299. lastIndex: 0,
  10300. lastTime: initialDefaultFrame
  10301. };
  10302. }
  10303. frameNum *= this.elem.globalData.frameRate;
  10304. frameNum -= this.offsetTime;
  10305. if(frameNum !== this._cachingAtTime.lastTime) {
  10306. this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0;
  10307. this._cachingAtTime.lastTime = frameNum;
  10308. this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime);
  10309. }
  10310. return this._cachingAtTime.shapeValue;
  10311. }
  10312. var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction();
  10313. var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction();
  10314. function ShapeExpressions(){}
  10315. ShapeExpressions.prototype = {
  10316. vertices: function(prop, time){
  10317. if (this.k) {
  10318. this.getValue();
  10319. }
  10320. var shapePath = this.v;
  10321. if(time !== undefined) {
  10322. shapePath = this.getValueAtTime(time, 0);
  10323. }
  10324. var i, len = shapePath._length;
  10325. var vertices = shapePath[prop];
  10326. var points = shapePath.v;
  10327. var arr = createSizedArray(len);
  10328. for(i = 0; i < len; i += 1) {
  10329. if(prop === 'i' || prop === 'o') {
  10330. arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]];
  10331. } else {
  10332. arr[i] = [vertices[i][0], vertices[i][1]];
  10333. }
  10334. }
  10335. return arr;
  10336. },
  10337. points: function(time){
  10338. return this.vertices('v', time);
  10339. },
  10340. inTangents: function(time){
  10341. return this.vertices('i', time);
  10342. },
  10343. outTangents: function(time){
  10344. return this.vertices('o', time);
  10345. },
  10346. isClosed: function(){
  10347. return this.v.c;
  10348. },
  10349. pointOnPath: function(perc, time){
  10350. var shapePath = this.v;
  10351. if(time !== undefined) {
  10352. shapePath = this.getValueAtTime(time, 0);
  10353. }
  10354. if(!this._segmentsLength) {
  10355. this._segmentsLength = bez.getSegmentsLength(shapePath);
  10356. }
  10357. var segmentsLength = this._segmentsLength;
  10358. var lengths = segmentsLength.lengths;
  10359. var lengthPos = segmentsLength.totalLength * perc;
  10360. var i = 0, len = lengths.length;
  10361. var j = 0, jLen;
  10362. var accumulatedLength = 0, pt;
  10363. while(i < len) {
  10364. if(accumulatedLength + lengths[i].addedLength > lengthPos) {
  10365. var initIndex = i;
  10366. var endIndex = (shapePath.c && i === len - 1) ? 0 : i + 1;
  10367. var segmentPerc = (lengthPos - accumulatedLength)/lengths[i].addedLength;
  10368. pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]);
  10369. break;
  10370. } else {
  10371. accumulatedLength += lengths[i].addedLength;
  10372. }
  10373. i += 1;
  10374. }
  10375. if(!pt){
  10376. pt = shapePath.c ? [shapePath.v[0][0],shapePath.v[0][1]]:[shapePath.v[shapePath._length-1][0],shapePath.v[shapePath._length-1][1]];
  10377. }
  10378. return pt;
  10379. },
  10380. vectorOnPath: function(perc, time, vectorType){
  10381. //perc doesn't use triple equality because it can be a Number object as well as a primitive.
  10382. perc = perc == 1 ? this.v.c ? 0 : 0.999 : perc;
  10383. var pt1 = this.pointOnPath(perc, time);
  10384. var pt2 = this.pointOnPath(perc + 0.001, time);
  10385. var xLength = pt2[0] - pt1[0];
  10386. var yLength = pt2[1] - pt1[1];
  10387. var magnitude = Math.sqrt(Math.pow(xLength,2) + Math.pow(yLength,2));
  10388. if (magnitude === 0) {
  10389. return [0,0];
  10390. }
  10391. var unitVector = vectorType === 'tangent' ? [xLength/magnitude, yLength/magnitude] : [-yLength/magnitude, xLength/magnitude];
  10392. return unitVector;
  10393. },
  10394. tangentOnPath: function(perc, time){
  10395. return this.vectorOnPath(perc, time, 'tangent');
  10396. },
  10397. normalOnPath: function(perc, time){
  10398. return this.vectorOnPath(perc, time, 'normal');
  10399. },
  10400. setGroupProperty: expressionHelpers.setGroupProperty,
  10401. getValueAtTime: expressionHelpers.getStaticValueAtTime
  10402. };
  10403. extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction);
  10404. extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction);
  10405. KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime;
  10406. KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression;
  10407. var propertyGetShapeProp = ShapePropertyFactory.getShapeProp;
  10408. ShapePropertyFactory.getShapeProp = function(elem,data,type, arr, trims){
  10409. var prop = propertyGetShapeProp(elem,data,type, arr, trims);
  10410. prop.propertyIndex = data.ix;
  10411. prop.lock = false;
  10412. if(type === 3){
  10413. expressionHelpers.searchExpressions(elem,data.pt,prop);
  10414. } else if(type === 4){
  10415. expressionHelpers.searchExpressions(elem,data.ks,prop);
  10416. }
  10417. if(prop.k){
  10418. elem.addDynamicProperty(prop);
  10419. }
  10420. return prop;
  10421. };
  10422. }());
  10423. (function addDecorator() {
  10424. function searchExpressions(){
  10425. if(this.data.d.x){
  10426. this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem,this.data.d,this);
  10427. this.addEffect(this.getExpressionValue.bind(this));
  10428. return true;
  10429. }
  10430. }
  10431. TextProperty.prototype.getExpressionValue = function(currentValue, text) {
  10432. var newValue = this.calculateExpression(text);
  10433. if(currentValue.t !== newValue) {
  10434. var newData = {};
  10435. this.copyData(newData, currentValue);
  10436. newData.t = newValue.toString();
  10437. newData.__complete = false;
  10438. return newData;
  10439. }
  10440. return currentValue;
  10441. }
  10442. TextProperty.prototype.searchProperty = function(){
  10443. var isKeyframed = this.searchKeyframes();
  10444. var hasExpressions = this.searchExpressions();
  10445. this.kf = isKeyframed || hasExpressions;
  10446. return this.kf;
  10447. };
  10448. TextProperty.prototype.searchExpressions = searchExpressions;
  10449. }());
  10450. var ShapePathInterface = (
  10451. function() {
  10452. return function pathInterfaceFactory(shape,view,propertyGroup){
  10453. var prop = view.sh;
  10454. function interfaceFunction(val){
  10455. if(val === 'Shape' || val === 'shape' || val === 'Path' || val === 'path' || val === 'ADBE Vector Shape' || val === 2){
  10456. return interfaceFunction.path;
  10457. }
  10458. }
  10459. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10460. prop.setGroupProperty(PropertyInterface('Path', _propertyGroup));
  10461. Object.defineProperties(interfaceFunction, {
  10462. 'path': {
  10463. get: function(){
  10464. if(prop.k){
  10465. prop.getValue();
  10466. }
  10467. return prop;
  10468. }
  10469. },
  10470. 'shape': {
  10471. get: function(){
  10472. if(prop.k){
  10473. prop.getValue();
  10474. }
  10475. return prop;
  10476. }
  10477. },
  10478. '_name': { value: shape.nm },
  10479. 'ix': { value: shape.ix },
  10480. 'propertyIndex': { value: shape.ix },
  10481. 'mn': { value: shape.mn },
  10482. 'propertyGroup': {value: propertyGroup},
  10483. });
  10484. return interfaceFunction;
  10485. }
  10486. }()
  10487. )
  10488. var propertyGroupFactory = (function() {
  10489. return function(interfaceFunction, parentPropertyGroup) {
  10490. return function(val) {
  10491. val = val === undefined ? 1 : val
  10492. if(val <= 0){
  10493. return interfaceFunction;
  10494. } else{
  10495. return parentPropertyGroup(val-1);
  10496. }
  10497. }
  10498. }
  10499. }())
  10500. var PropertyInterface = (function() {
  10501. return function(propertyName, propertyGroup) {
  10502. var interfaceFunction = {
  10503. _name: propertyName
  10504. }
  10505. function _propertyGroup(val){
  10506. val = val === undefined ? 1 : val
  10507. if(val <= 0){
  10508. return interfaceFunction;
  10509. } else {
  10510. return propertyGroup(--val);
  10511. }
  10512. }
  10513. return _propertyGroup;
  10514. }
  10515. }())
  10516. var ShapeExpressionInterface = (function(){
  10517. function iterateElements(shapes,view, propertyGroup){
  10518. var arr = [];
  10519. var i, len = shapes ? shapes.length : 0;
  10520. for(i=0;i<len;i+=1){
  10521. if(shapes[i].ty == 'gr'){
  10522. arr.push(groupInterfaceFactory(shapes[i],view[i],propertyGroup));
  10523. }else if(shapes[i].ty == 'fl'){
  10524. arr.push(fillInterfaceFactory(shapes[i],view[i],propertyGroup));
  10525. }else if(shapes[i].ty == 'st'){
  10526. arr.push(strokeInterfaceFactory(shapes[i],view[i],propertyGroup));
  10527. }else if(shapes[i].ty == 'tm'){
  10528. arr.push(trimInterfaceFactory(shapes[i],view[i],propertyGroup));
  10529. }else if(shapes[i].ty == 'tr'){
  10530. //arr.push(transformInterfaceFactory(shapes[i],view[i],propertyGroup));
  10531. }else if(shapes[i].ty == 'el'){
  10532. arr.push(ellipseInterfaceFactory(shapes[i],view[i],propertyGroup));
  10533. }else if(shapes[i].ty == 'sr'){
  10534. arr.push(starInterfaceFactory(shapes[i],view[i],propertyGroup));
  10535. } else if(shapes[i].ty == 'sh'){
  10536. arr.push(ShapePathInterface(shapes[i],view[i],propertyGroup));
  10537. } else if(shapes[i].ty == 'rc'){
  10538. arr.push(rectInterfaceFactory(shapes[i],view[i],propertyGroup));
  10539. } else if(shapes[i].ty == 'rd'){
  10540. arr.push(roundedInterfaceFactory(shapes[i],view[i],propertyGroup));
  10541. } else if(shapes[i].ty == 'rp'){
  10542. arr.push(repeaterInterfaceFactory(shapes[i],view[i],propertyGroup));
  10543. }
  10544. }
  10545. return arr;
  10546. }
  10547. function contentsInterfaceFactory(shape,view, propertyGroup){
  10548. var interfaces;
  10549. var interfaceFunction = function _interfaceFunction(value){
  10550. var i = 0, len = interfaces.length;
  10551. while(i<len){
  10552. if(interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value){
  10553. return interfaces[i];
  10554. }
  10555. i+=1;
  10556. }
  10557. if(typeof value === 'number'){
  10558. return interfaces[value-1];
  10559. }
  10560. };
  10561. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10562. interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup);
  10563. interfaceFunction.numProperties = interfaces.length;
  10564. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1],view.it[view.it.length - 1],interfaceFunction.propertyGroup);
  10565. interfaceFunction.transform = transformInterface;
  10566. interfaceFunction.propertyIndex = shape.cix;
  10567. interfaceFunction._name = shape.nm;
  10568. return interfaceFunction;
  10569. }
  10570. function groupInterfaceFactory(shape,view, propertyGroup){
  10571. var interfaceFunction = function _interfaceFunction(value){
  10572. switch(value){
  10573. case 'ADBE Vectors Group':
  10574. case 'Contents':
  10575. case 2:
  10576. return interfaceFunction.content;
  10577. //Not necessary for now. Keeping them here in case a new case appears
  10578. //case 'ADBE Vector Transform Group':
  10579. //case 3:
  10580. default:
  10581. return interfaceFunction.transform;
  10582. }
  10583. };
  10584. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10585. var content = contentsInterfaceFactory(shape,view,interfaceFunction.propertyGroup);
  10586. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1],view.it[view.it.length - 1],interfaceFunction.propertyGroup);
  10587. interfaceFunction.content = content;
  10588. interfaceFunction.transform = transformInterface;
  10589. Object.defineProperty(interfaceFunction, '_name', {
  10590. get: function(){
  10591. return shape.nm;
  10592. }
  10593. });
  10594. //interfaceFunction.content = interfaceFunction;
  10595. interfaceFunction.numProperties = shape.np;
  10596. interfaceFunction.propertyIndex = shape.ix;
  10597. interfaceFunction.nm = shape.nm;
  10598. interfaceFunction.mn = shape.mn;
  10599. return interfaceFunction;
  10600. }
  10601. function fillInterfaceFactory(shape,view,propertyGroup){
  10602. function interfaceFunction(val){
  10603. if(val === 'Color' || val === 'color'){
  10604. return interfaceFunction.color;
  10605. } else if(val === 'Opacity' || val === 'opacity'){
  10606. return interfaceFunction.opacity;
  10607. }
  10608. }
  10609. Object.defineProperties(interfaceFunction, {
  10610. 'color': {
  10611. get: ExpressionPropertyInterface(view.c)
  10612. },
  10613. 'opacity': {
  10614. get: ExpressionPropertyInterface(view.o)
  10615. },
  10616. '_name': { value: shape.nm },
  10617. 'mn': { value: shape.mn }
  10618. });
  10619. view.c.setGroupProperty(PropertyInterface('Color', propertyGroup));
  10620. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  10621. return interfaceFunction;
  10622. }
  10623. function strokeInterfaceFactory(shape,view,propertyGroup){
  10624. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10625. var _dashPropertyGroup = propertyGroupFactory(dashOb, _propertyGroup);
  10626. function addPropertyToDashOb(i) {
  10627. Object.defineProperty(dashOb, shape.d[i].nm, {
  10628. get: ExpressionPropertyInterface(view.d.dataProps[i].p)
  10629. });
  10630. }
  10631. var i, len = shape.d ? shape.d.length : 0;
  10632. var dashOb = {};
  10633. for (i = 0; i < len; i += 1) {
  10634. addPropertyToDashOb(i);
  10635. view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup);
  10636. }
  10637. function interfaceFunction(val){
  10638. if(val === 'Color' || val === 'color'){
  10639. return interfaceFunction.color;
  10640. } else if(val === 'Opacity' || val === 'opacity'){
  10641. return interfaceFunction.opacity;
  10642. } else if(val === 'Stroke Width' || val === 'stroke width'){
  10643. return interfaceFunction.strokeWidth;
  10644. }
  10645. }
  10646. Object.defineProperties(interfaceFunction, {
  10647. 'color': {
  10648. get: ExpressionPropertyInterface(view.c)
  10649. },
  10650. 'opacity': {
  10651. get: ExpressionPropertyInterface(view.o)
  10652. },
  10653. 'strokeWidth': {
  10654. get: ExpressionPropertyInterface(view.w)
  10655. },
  10656. 'dash': {
  10657. get: function() {
  10658. return dashOb;
  10659. }
  10660. },
  10661. '_name': { value: shape.nm },
  10662. 'mn': { value: shape.mn }
  10663. });
  10664. view.c.setGroupProperty(PropertyInterface('Color', _propertyGroup));
  10665. view.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  10666. view.w.setGroupProperty(PropertyInterface('Stroke Width', _propertyGroup));
  10667. return interfaceFunction;
  10668. }
  10669. function trimInterfaceFactory(shape,view,propertyGroup){
  10670. function interfaceFunction(val){
  10671. if(val === shape.e.ix || val === 'End' || val === 'end'){
  10672. return interfaceFunction.end;
  10673. }
  10674. if(val === shape.s.ix){
  10675. return interfaceFunction.start;
  10676. }
  10677. if(val === shape.o.ix){
  10678. return interfaceFunction.offset;
  10679. }
  10680. }
  10681. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10682. interfaceFunction.propertyIndex = shape.ix;
  10683. view.s.setGroupProperty(PropertyInterface('Start', _propertyGroup));
  10684. view.e.setGroupProperty(PropertyInterface('End', _propertyGroup));
  10685. view.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  10686. interfaceFunction.propertyIndex = shape.ix;
  10687. interfaceFunction.propertyGroup = propertyGroup;
  10688. Object.defineProperties(interfaceFunction, {
  10689. 'start': {
  10690. get: ExpressionPropertyInterface(view.s)
  10691. },
  10692. 'end': {
  10693. get: ExpressionPropertyInterface(view.e)
  10694. },
  10695. 'offset': {
  10696. get: ExpressionPropertyInterface(view.o)
  10697. },
  10698. '_name': { value: shape.nm }
  10699. });
  10700. interfaceFunction.mn = shape.mn;
  10701. return interfaceFunction;
  10702. }
  10703. function transformInterfaceFactory(shape,view,propertyGroup){
  10704. function interfaceFunction(value){
  10705. if(shape.a.ix === value || value === 'Anchor Point'){
  10706. return interfaceFunction.anchorPoint;
  10707. }
  10708. if(shape.o.ix === value || value === 'Opacity'){
  10709. return interfaceFunction.opacity;
  10710. }
  10711. if(shape.p.ix === value || value === 'Position'){
  10712. return interfaceFunction.position;
  10713. }
  10714. if(shape.r.ix === value || value === 'Rotation' || value === 'ADBE Vector Rotation'){
  10715. return interfaceFunction.rotation;
  10716. }
  10717. if(shape.s.ix === value || value === 'Scale'){
  10718. return interfaceFunction.scale;
  10719. }
  10720. if(shape.sk && shape.sk.ix === value || value === 'Skew'){
  10721. return interfaceFunction.skew;
  10722. }
  10723. if(shape.sa && shape.sa.ix === value || value === 'Skew Axis'){
  10724. return interfaceFunction.skewAxis;
  10725. }
  10726. }
  10727. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10728. view.transform.mProps.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  10729. view.transform.mProps.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  10730. view.transform.mProps.a.setGroupProperty(PropertyInterface('Anchor Point', _propertyGroup));
  10731. view.transform.mProps.s.setGroupProperty(PropertyInterface('Scale', _propertyGroup));
  10732. view.transform.mProps.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  10733. if(view.transform.mProps.sk){
  10734. view.transform.mProps.sk.setGroupProperty(PropertyInterface('Skew', _propertyGroup));
  10735. view.transform.mProps.sa.setGroupProperty(PropertyInterface('Skew Angle', _propertyGroup));
  10736. }
  10737. view.transform.op.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  10738. Object.defineProperties(interfaceFunction, {
  10739. 'opacity': {
  10740. get: ExpressionPropertyInterface(view.transform.mProps.o)
  10741. },
  10742. 'position': {
  10743. get: ExpressionPropertyInterface(view.transform.mProps.p)
  10744. },
  10745. 'anchorPoint': {
  10746. get: ExpressionPropertyInterface(view.transform.mProps.a)
  10747. },
  10748. 'scale': {
  10749. get: ExpressionPropertyInterface(view.transform.mProps.s)
  10750. },
  10751. 'rotation': {
  10752. get: ExpressionPropertyInterface(view.transform.mProps.r)
  10753. },
  10754. 'skew': {
  10755. get: ExpressionPropertyInterface(view.transform.mProps.sk)
  10756. },
  10757. 'skewAxis': {
  10758. get: ExpressionPropertyInterface(view.transform.mProps.sa)
  10759. },
  10760. '_name': { value: shape.nm }
  10761. });
  10762. interfaceFunction.ty = 'tr';
  10763. interfaceFunction.mn = shape.mn;
  10764. interfaceFunction.propertyGroup = propertyGroup;
  10765. return interfaceFunction;
  10766. }
  10767. function ellipseInterfaceFactory(shape,view,propertyGroup){
  10768. function interfaceFunction(value){
  10769. if(shape.p.ix === value){
  10770. return interfaceFunction.position;
  10771. }
  10772. if(shape.s.ix === value){
  10773. return interfaceFunction.size;
  10774. }
  10775. }
  10776. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10777. interfaceFunction.propertyIndex = shape.ix;
  10778. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  10779. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  10780. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  10781. Object.defineProperties(interfaceFunction, {
  10782. 'size': {
  10783. get: ExpressionPropertyInterface(prop.s)
  10784. },
  10785. 'position': {
  10786. get: ExpressionPropertyInterface(prop.p)
  10787. },
  10788. '_name': { value: shape.nm }
  10789. });
  10790. interfaceFunction.mn = shape.mn;
  10791. return interfaceFunction;
  10792. }
  10793. function starInterfaceFactory(shape,view,propertyGroup){
  10794. function interfaceFunction(value){
  10795. if(shape.p.ix === value){
  10796. return interfaceFunction.position;
  10797. }
  10798. if(shape.r.ix === value){
  10799. return interfaceFunction.rotation;
  10800. }
  10801. if(shape.pt.ix === value){
  10802. return interfaceFunction.points;
  10803. }
  10804. if(shape.or.ix === value || 'ADBE Vector Star Outer Radius' === value){
  10805. return interfaceFunction.outerRadius;
  10806. }
  10807. if(shape.os.ix === value){
  10808. return interfaceFunction.outerRoundness;
  10809. }
  10810. if(shape.ir && (shape.ir.ix === value || 'ADBE Vector Star Inner Radius' === value)){
  10811. return interfaceFunction.innerRadius;
  10812. }
  10813. if(shape.is && shape.is.ix === value){
  10814. return interfaceFunction.innerRoundness;
  10815. }
  10816. }
  10817. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10818. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  10819. interfaceFunction.propertyIndex = shape.ix;
  10820. prop.or.setGroupProperty(PropertyInterface('Outer Radius', _propertyGroup));
  10821. prop.os.setGroupProperty(PropertyInterface('Outer Roundness', _propertyGroup));
  10822. prop.pt.setGroupProperty(PropertyInterface('Points', _propertyGroup));
  10823. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  10824. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  10825. if(shape.ir){
  10826. prop.ir.setGroupProperty(PropertyInterface('Inner Radius', _propertyGroup));
  10827. prop.is.setGroupProperty(PropertyInterface('Inner Roundness', _propertyGroup));
  10828. }
  10829. Object.defineProperties(interfaceFunction, {
  10830. 'position': {
  10831. get: ExpressionPropertyInterface(prop.p)
  10832. },
  10833. 'rotation': {
  10834. get: ExpressionPropertyInterface(prop.r)
  10835. },
  10836. 'points': {
  10837. get: ExpressionPropertyInterface(prop.pt)
  10838. },
  10839. 'outerRadius': {
  10840. get: ExpressionPropertyInterface(prop.or)
  10841. },
  10842. 'outerRoundness': {
  10843. get: ExpressionPropertyInterface(prop.os)
  10844. },
  10845. 'innerRadius': {
  10846. get: ExpressionPropertyInterface(prop.ir)
  10847. },
  10848. 'innerRoundness': {
  10849. get: ExpressionPropertyInterface(prop.is)
  10850. },
  10851. '_name': { value: shape.nm }
  10852. });
  10853. interfaceFunction.mn = shape.mn;
  10854. return interfaceFunction;
  10855. }
  10856. function rectInterfaceFactory(shape,view,propertyGroup){
  10857. function interfaceFunction(value){
  10858. if(shape.p.ix === value){
  10859. return interfaceFunction.position;
  10860. }
  10861. if(shape.r.ix === value){
  10862. return interfaceFunction.roundness;
  10863. }
  10864. if(shape.s.ix === value || value === 'Size' || value === 'ADBE Vector Rect Size'){
  10865. return interfaceFunction.size;
  10866. }
  10867. }
  10868. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10869. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  10870. interfaceFunction.propertyIndex = shape.ix;
  10871. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  10872. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  10873. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  10874. Object.defineProperties(interfaceFunction, {
  10875. 'position': {
  10876. get: ExpressionPropertyInterface(prop.p)
  10877. },
  10878. 'roundness': {
  10879. get: ExpressionPropertyInterface(prop.r)
  10880. },
  10881. 'size': {
  10882. get: ExpressionPropertyInterface(prop.s)
  10883. },
  10884. '_name': { value: shape.nm }
  10885. });
  10886. interfaceFunction.mn = shape.mn;
  10887. return interfaceFunction;
  10888. }
  10889. function roundedInterfaceFactory(shape,view,propertyGroup){
  10890. function interfaceFunction(value){
  10891. if(shape.r.ix === value || 'Round Corners 1' === value){
  10892. return interfaceFunction.radius;
  10893. }
  10894. }
  10895. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10896. var prop = view;
  10897. interfaceFunction.propertyIndex = shape.ix;
  10898. prop.rd.setGroupProperty(PropertyInterface('Radius', _propertyGroup));
  10899. Object.defineProperties(interfaceFunction, {
  10900. 'radius': {
  10901. get: ExpressionPropertyInterface(prop.rd)
  10902. },
  10903. '_name': { value: shape.nm }
  10904. });
  10905. interfaceFunction.mn = shape.mn;
  10906. return interfaceFunction;
  10907. }
  10908. function repeaterInterfaceFactory(shape,view,propertyGroup){
  10909. function interfaceFunction(value){
  10910. if(shape.c.ix === value || 'Copies' === value){
  10911. return interfaceFunction.copies;
  10912. } else if(shape.o.ix === value || 'Offset' === value){
  10913. return interfaceFunction.offset;
  10914. }
  10915. }
  10916. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  10917. var prop = view;
  10918. interfaceFunction.propertyIndex = shape.ix;
  10919. prop.c.setGroupProperty(PropertyInterface('Copies', _propertyGroup));
  10920. prop.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  10921. Object.defineProperties(interfaceFunction, {
  10922. 'copies': {
  10923. get: ExpressionPropertyInterface(prop.c)
  10924. },
  10925. 'offset': {
  10926. get: ExpressionPropertyInterface(prop.o)
  10927. },
  10928. '_name': { value: shape.nm }
  10929. });
  10930. interfaceFunction.mn = shape.mn;
  10931. return interfaceFunction;
  10932. }
  10933. return function(shapes,view,propertyGroup) {
  10934. var interfaces;
  10935. function _interfaceFunction(value){
  10936. if(typeof value === 'number'){
  10937. value = value === undefined ? 1 : value
  10938. if (value === 0) {
  10939. return propertyGroup
  10940. } else {
  10941. return interfaces[value-1];
  10942. }
  10943. } else {
  10944. var i = 0, len = interfaces.length;
  10945. while(i<len){
  10946. if(interfaces[i]._name === value){
  10947. return interfaces[i];
  10948. }
  10949. i+=1;
  10950. }
  10951. }
  10952. }
  10953. _interfaceFunction.propertyGroup = propertyGroup;
  10954. interfaces = iterateElements(shapes, view, _interfaceFunction);
  10955. _interfaceFunction.numProperties = interfaces.length;
  10956. return _interfaceFunction;
  10957. };
  10958. }());
  10959. var TextExpressionInterface = (function(){
  10960. return function(elem){
  10961. var _prevValue, _sourceText;
  10962. function _thisLayerFunction(name){
  10963. switch(name){
  10964. case "ADBE Text Document":
  10965. return _thisLayerFunction.sourceText;
  10966. }
  10967. }
  10968. Object.defineProperty(_thisLayerFunction, "sourceText", {
  10969. get: function(){
  10970. elem.textProperty.getValue()
  10971. var stringValue = elem.textProperty.currentData.t;
  10972. if(stringValue !== _prevValue) {
  10973. elem.textProperty.currentData.t = _prevValue;
  10974. _sourceText = new String(stringValue);
  10975. //If stringValue is an empty string, eval returns undefined, so it has to be returned as a String primitive
  10976. _sourceText.value = stringValue ? stringValue : new String(stringValue);
  10977. }
  10978. return _sourceText;
  10979. }
  10980. });
  10981. return _thisLayerFunction;
  10982. };
  10983. }());
  10984. var LayerExpressionInterface = (function (){
  10985. function toWorld(arr, time){
  10986. var toWorldMat = new Matrix();
  10987. toWorldMat.reset();
  10988. var transformMat;
  10989. if (time !== undefined) {
  10990. toWorldMat = this._elem.finalTransform.mProp.getValueAtTime(time);
  10991. } else {
  10992. transformMat = this._elem.finalTransform.mProp;
  10993. transformMat.applyToMatrix(toWorldMat);
  10994. }
  10995. if(this._elem.hierarchy && this._elem.hierarchy.length){
  10996. var i, len = this._elem.hierarchy.length;
  10997. for(i=0;i<len;i+=1){
  10998. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  10999. }
  11000. return toWorldMat.applyToPointArray(arr[0],arr[1],arr[2]||0);
  11001. }
  11002. return toWorldMat.applyToPointArray(arr[0],arr[1],arr[2]||0);
  11003. }
  11004. function fromWorld(arr, time){
  11005. var toWorldMat = new Matrix();
  11006. toWorldMat.reset();
  11007. var transformMat;
  11008. if (time !== undefined) {
  11009. toWorldMat = this._elem.finalTransform.mProp.getValueAtTime(time);
  11010. } else {
  11011. transformMat = this._elem.finalTransform.mProp;
  11012. transformMat.applyToMatrix(toWorldMat);
  11013. }
  11014. if (this._elem.hierarchy && this._elem.hierarchy.length){
  11015. var i, len = this._elem.hierarchy.length;
  11016. for(i=0;i<len;i+=1){
  11017. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  11018. }
  11019. return toWorldMat.inversePoint(arr);
  11020. }
  11021. return toWorldMat.inversePoint(arr);
  11022. }
  11023. function fromComp(arr){
  11024. var toWorldMat = new Matrix();
  11025. toWorldMat.reset();
  11026. this._elem.finalTransform.mProp.applyToMatrix(toWorldMat);
  11027. if(this._elem.hierarchy && this._elem.hierarchy.length){
  11028. var i, len = this._elem.hierarchy.length;
  11029. for(i=0;i<len;i+=1){
  11030. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  11031. }
  11032. return toWorldMat.inversePoint(arr);
  11033. }
  11034. return toWorldMat.inversePoint(arr);
  11035. }
  11036. function sampleImage() {
  11037. return [1,1,1,1];
  11038. }
  11039. return function(elem){
  11040. var transformInterface;
  11041. function _registerMaskInterface(maskManager){
  11042. _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem);
  11043. }
  11044. function _registerEffectsInterface(effects){
  11045. _thisLayerFunction.effect = effects;
  11046. }
  11047. function _thisLayerFunction(name){
  11048. switch(name){
  11049. case "ADBE Root Vectors Group":
  11050. case "Contents":
  11051. case 2:
  11052. return _thisLayerFunction.shapeInterface;
  11053. case 1:
  11054. case 6:
  11055. case "Transform":
  11056. case "transform":
  11057. case "ADBE Transform Group":
  11058. return transformInterface;
  11059. case 4:
  11060. case "ADBE Effect Parade":
  11061. case "effects":
  11062. case "Effects":
  11063. return _thisLayerFunction.effect;
  11064. case "ADBE Text Properties":
  11065. return _thisLayerFunction.textInterface;
  11066. }
  11067. }
  11068. _thisLayerFunction.toWorld = toWorld;
  11069. _thisLayerFunction.fromWorld = fromWorld;
  11070. _thisLayerFunction.toComp = toWorld;
  11071. _thisLayerFunction.fromComp = fromComp;
  11072. _thisLayerFunction.sampleImage = sampleImage;
  11073. _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem);
  11074. _thisLayerFunction._elem = elem;
  11075. transformInterface = TransformExpressionInterface(elem.finalTransform.mProp);
  11076. var anchorPointDescriptor = getDescriptor(transformInterface, 'anchorPoint');
  11077. Object.defineProperties(_thisLayerFunction,{
  11078. hasParent: {
  11079. get: function(){
  11080. return elem.hierarchy.length;
  11081. }
  11082. },
  11083. parent: {
  11084. get: function(){
  11085. return elem.hierarchy[0].layerInterface;
  11086. }
  11087. },
  11088. rotation: getDescriptor(transformInterface, 'rotation'),
  11089. scale: getDescriptor(transformInterface, 'scale'),
  11090. position: getDescriptor(transformInterface, 'position'),
  11091. opacity: getDescriptor(transformInterface, 'opacity'),
  11092. anchorPoint: anchorPointDescriptor,
  11093. anchor_point: anchorPointDescriptor,
  11094. transform: {
  11095. get: function () {
  11096. return transformInterface;
  11097. }
  11098. },
  11099. active: {
  11100. get: function(){
  11101. return elem.isInRange;
  11102. }
  11103. }
  11104. });
  11105. _thisLayerFunction.startTime = elem.data.st;
  11106. _thisLayerFunction.index = elem.data.ind;
  11107. _thisLayerFunction.source = elem.data.refId;
  11108. _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100;
  11109. _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100;
  11110. _thisLayerFunction.inPoint = elem.data.ip/elem.comp.globalData.frameRate;
  11111. _thisLayerFunction.outPoint = elem.data.op/elem.comp.globalData.frameRate;
  11112. _thisLayerFunction._name = elem.data.nm;
  11113. _thisLayerFunction.registerMaskInterface = _registerMaskInterface;
  11114. _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface;
  11115. return _thisLayerFunction;
  11116. };
  11117. }());
  11118. var CompExpressionInterface = (function () {
  11119. return function(comp) {
  11120. function _thisLayerFunction(name) {
  11121. var i = 0, len = comp.layers.length;
  11122. while ( i < len) {
  11123. if (comp.layers[i].nm === name || comp.layers[i].ind === name) {
  11124. return comp.elements[i].layerInterface;
  11125. }
  11126. i += 1;
  11127. }
  11128. return null;
  11129. //return {active:false};
  11130. }
  11131. Object.defineProperty(_thisLayerFunction, "_name", { value: comp.data.nm });
  11132. _thisLayerFunction.layer = _thisLayerFunction;
  11133. _thisLayerFunction.pixelAspect = 1;
  11134. _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h;
  11135. _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w;
  11136. _thisLayerFunction.pixelAspect = 1;
  11137. _thisLayerFunction.frameDuration = 1 / comp.globalData.frameRate;
  11138. _thisLayerFunction.displayStartTime = 0;
  11139. _thisLayerFunction.numLayers = comp.layers.length;
  11140. return _thisLayerFunction;
  11141. };
  11142. }());
  11143. var TransformExpressionInterface = (function (){
  11144. return function(transform){
  11145. function _thisFunction(name){
  11146. switch(name){
  11147. case "scale":
  11148. case "Scale":
  11149. case "ADBE Scale":
  11150. case 6:
  11151. return _thisFunction.scale;
  11152. case "rotation":
  11153. case "Rotation":
  11154. case "ADBE Rotation":
  11155. case "ADBE Rotate Z":
  11156. case 10:
  11157. return _thisFunction.rotation;
  11158. case "ADBE Rotate X":
  11159. return _thisFunction.xRotation;
  11160. case "ADBE Rotate Y":
  11161. return _thisFunction.yRotation;
  11162. case "position":
  11163. case "Position":
  11164. case "ADBE Position":
  11165. case 2:
  11166. return _thisFunction.position;
  11167. case 'ADBE Position_0':
  11168. return _thisFunction.xPosition;
  11169. case 'ADBE Position_1':
  11170. return _thisFunction.yPosition;
  11171. case 'ADBE Position_2':
  11172. return _thisFunction.zPosition;
  11173. case "anchorPoint":
  11174. case "AnchorPoint":
  11175. case "Anchor Point":
  11176. case "ADBE AnchorPoint":
  11177. case 1:
  11178. return _thisFunction.anchorPoint;
  11179. case "opacity":
  11180. case "Opacity":
  11181. case 11:
  11182. return _thisFunction.opacity;
  11183. }
  11184. }
  11185. Object.defineProperty(_thisFunction, "rotation", {
  11186. get: ExpressionPropertyInterface(transform.r || transform.rz)
  11187. });
  11188. Object.defineProperty(_thisFunction, "zRotation", {
  11189. get: ExpressionPropertyInterface(transform.rz || transform.r)
  11190. });
  11191. Object.defineProperty(_thisFunction, "xRotation", {
  11192. get: ExpressionPropertyInterface(transform.rx)
  11193. });
  11194. Object.defineProperty(_thisFunction, "yRotation", {
  11195. get: ExpressionPropertyInterface(transform.ry)
  11196. });
  11197. Object.defineProperty(_thisFunction, "scale", {
  11198. get: ExpressionPropertyInterface(transform.s)
  11199. });
  11200. if(transform.p) {
  11201. var _transformFactory = ExpressionPropertyInterface(transform.p);
  11202. } else {
  11203. var _px = ExpressionPropertyInterface(transform.px);
  11204. var _py = ExpressionPropertyInterface(transform.py);
  11205. var _pz;
  11206. if (transform.pz) {
  11207. _pz = ExpressionPropertyInterface(transform.pz);
  11208. }
  11209. }
  11210. Object.defineProperty(_thisFunction, "position", {
  11211. get: function () {
  11212. if(transform.p) {
  11213. return _transformFactory();
  11214. } else {
  11215. return [
  11216. _px(),
  11217. _py(),
  11218. _pz ? _pz() : 0];
  11219. }
  11220. }
  11221. });
  11222. Object.defineProperty(_thisFunction, "xPosition", {
  11223. get: ExpressionPropertyInterface(transform.px)
  11224. });
  11225. Object.defineProperty(_thisFunction, "yPosition", {
  11226. get: ExpressionPropertyInterface(transform.py)
  11227. });
  11228. Object.defineProperty(_thisFunction, "zPosition", {
  11229. get: ExpressionPropertyInterface(transform.pz)
  11230. });
  11231. Object.defineProperty(_thisFunction, "anchorPoint", {
  11232. get: ExpressionPropertyInterface(transform.a)
  11233. });
  11234. Object.defineProperty(_thisFunction, "opacity", {
  11235. get: ExpressionPropertyInterface(transform.o)
  11236. });
  11237. Object.defineProperty(_thisFunction, "skew", {
  11238. get: ExpressionPropertyInterface(transform.sk)
  11239. });
  11240. Object.defineProperty(_thisFunction, "skewAxis", {
  11241. get: ExpressionPropertyInterface(transform.sa)
  11242. });
  11243. Object.defineProperty(_thisFunction, "orientation", {
  11244. get: ExpressionPropertyInterface(transform.or)
  11245. });
  11246. return _thisFunction;
  11247. };
  11248. }());
  11249. var ProjectInterface = (function (){
  11250. function registerComposition(comp){
  11251. this.compositions.push(comp);
  11252. }
  11253. return function(){
  11254. function _thisProjectFunction(name){
  11255. var i = 0, len = this.compositions.length;
  11256. while(i<len){
  11257. if(this.compositions[i].data && this.compositions[i].data.nm === name){
  11258. if(this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  11259. this.compositions[i].prepareFrame(this.currentFrame);
  11260. }
  11261. return this.compositions[i].compInterface;
  11262. }
  11263. i+=1;
  11264. }
  11265. }
  11266. _thisProjectFunction.compositions = [];
  11267. _thisProjectFunction.currentFrame = 0;
  11268. _thisProjectFunction.registerComposition = registerComposition;
  11269. return _thisProjectFunction;
  11270. };
  11271. }());
  11272. var EffectsExpressionInterface = (function (){
  11273. var ob = {
  11274. createEffectsInterface: createEffectsInterface
  11275. };
  11276. function createEffectsInterface(elem, propertyGroup){
  11277. if(elem.effectsManager){
  11278. var effectElements = [];
  11279. var effectsData = elem.data.ef;
  11280. var i, len = elem.effectsManager.effectElements.length;
  11281. for(i=0;i<len;i+=1){
  11282. effectElements.push(createGroupInterface(effectsData[i],elem.effectsManager.effectElements[i],propertyGroup,elem));
  11283. }
  11284. var effects = elem.data.ef || [];
  11285. var groupInterface = function(name){
  11286. i = 0, len = effects.length;
  11287. while(i<len) {
  11288. if(name === effects[i].nm || name === effects[i].mn || name === effects[i].ix){
  11289. return effectElements[i];
  11290. }
  11291. i += 1;
  11292. }
  11293. };
  11294. Object.defineProperty(groupInterface, 'numProperties', {
  11295. get: function(){
  11296. return effects.length;
  11297. }
  11298. });
  11299. return groupInterface
  11300. }
  11301. }
  11302. function createGroupInterface(data,elements, propertyGroup, elem){
  11303. function groupInterface(name){
  11304. var effects = data.ef, i = 0, len = effects.length;
  11305. while(i<len) {
  11306. if(name === effects[i].nm || name === effects[i].mn || name === effects[i].ix){
  11307. if(effects[i].ty === 5){
  11308. return effectElements[i];
  11309. } else {
  11310. return effectElements[i]();
  11311. }
  11312. }
  11313. i += 1;
  11314. }
  11315. throw new Error();
  11316. };
  11317. var _propertyGroup = propertyGroupFactory(groupInterface, propertyGroup);
  11318. var effectElements = [];
  11319. var i, len = data.ef.length;
  11320. for(i=0;i<len;i+=1){
  11321. if(data.ef[i].ty === 5){
  11322. effectElements.push(createGroupInterface(data.ef[i],elements.effectElements[i],elements.effectElements[i].propertyGroup, elem));
  11323. } else {
  11324. effectElements.push(createValueInterface(elements.effectElements[i],data.ef[i].ty, elem, _propertyGroup));
  11325. }
  11326. }
  11327. if(data.mn === 'ADBE Color Control'){
  11328. Object.defineProperty(groupInterface, 'color', {
  11329. get: function(){
  11330. return effectElements[0]();
  11331. }
  11332. });
  11333. }
  11334. Object.defineProperties(groupInterface, {
  11335. numProperties: {
  11336. get: function(){
  11337. return data.np;
  11338. }
  11339. },
  11340. _name: { value: data.nm },
  11341. propertyGroup: {value: _propertyGroup},
  11342. });
  11343. groupInterface.active = groupInterface.enabled = data.en !== 0;
  11344. return groupInterface;
  11345. }
  11346. function createValueInterface(element, type, elem, propertyGroup){
  11347. var expressionProperty = ExpressionPropertyInterface(element.p);
  11348. function interfaceFunction(){
  11349. if(type === 10){
  11350. return elem.comp.compInterface(element.p.v);
  11351. }
  11352. return expressionProperty();
  11353. }
  11354. if(element.p.setGroupProperty) {
  11355. element.p.setGroupProperty(PropertyInterface('', propertyGroup));
  11356. }
  11357. return interfaceFunction;
  11358. }
  11359. return ob;
  11360. }());
  11361. var MaskManagerInterface = (function(){
  11362. function MaskInterface(mask, data){
  11363. this._mask = mask;
  11364. this._data = data;
  11365. }
  11366. Object.defineProperty(MaskInterface.prototype, 'maskPath', {
  11367. get: function(){
  11368. if(this._mask.prop.k){
  11369. this._mask.prop.getValue();
  11370. }
  11371. return this._mask.prop;
  11372. }
  11373. });
  11374. Object.defineProperty(MaskInterface.prototype, 'maskOpacity', {
  11375. get: function(){
  11376. if(this._mask.op.k){
  11377. this._mask.op.getValue();
  11378. }
  11379. return this._mask.op.v * 100;
  11380. }
  11381. });
  11382. var MaskManager = function(maskManager, elem){
  11383. var _maskManager = maskManager;
  11384. var _elem = elem;
  11385. var _masksInterfaces = createSizedArray(maskManager.viewData.length);
  11386. var i, len = maskManager.viewData.length;
  11387. for(i = 0; i < len; i += 1) {
  11388. _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]);
  11389. }
  11390. var maskFunction = function(name){
  11391. i = 0;
  11392. while(i<len){
  11393. if(maskManager.masksProperties[i].nm === name){
  11394. return _masksInterfaces[i];
  11395. }
  11396. i += 1;
  11397. }
  11398. };
  11399. return maskFunction;
  11400. };
  11401. return MaskManager;
  11402. }());
  11403. var ExpressionPropertyInterface = (function() {
  11404. var defaultUnidimensionalValue = {pv:0, v:0, mult: 1}
  11405. var defaultMultidimensionalValue = {pv:[0,0,0], v:[0,0,0], mult: 1}
  11406. function completeProperty(expressionValue, property, type) {
  11407. Object.defineProperty(expressionValue, 'velocity', {
  11408. get: function(){
  11409. return property.getVelocityAtTime(property.comp.currentFrame);
  11410. }
  11411. });
  11412. expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0;
  11413. expressionValue.key = function(pos) {
  11414. if (!expressionValue.numKeys) {
  11415. return 0;
  11416. } else {
  11417. var value = '';
  11418. if ('s' in property.keyframes[pos-1]) {
  11419. value = property.keyframes[pos-1].s;
  11420. } else if ('e' in property.keyframes[pos-2]) {
  11421. value = property.keyframes[pos-2].e;
  11422. } else {
  11423. value = property.keyframes[pos-2].s;
  11424. }
  11425. var valueProp = type === 'unidimensional' ? new Number(value) : Object.assign({}, value);
  11426. valueProp.time = property.keyframes[pos-1].t / property.elem.comp.globalData.frameRate;
  11427. valueProp.value = type === 'unidimensional' ? value[0] : value;
  11428. return valueProp;
  11429. }
  11430. };
  11431. expressionValue.valueAtTime = property.getValueAtTime;
  11432. expressionValue.speedAtTime = property.getSpeedAtTime;
  11433. expressionValue.velocityAtTime = property.getVelocityAtTime;
  11434. expressionValue.propertyGroup = property.propertyGroup;
  11435. }
  11436. function UnidimensionalPropertyInterface(property) {
  11437. if(!property || !('pv' in property)) {
  11438. property = defaultUnidimensionalValue;
  11439. }
  11440. var mult = 1 / property.mult;
  11441. var val = property.pv * mult;
  11442. var expressionValue = new Number(val);
  11443. expressionValue.value = val;
  11444. completeProperty(expressionValue, property, 'unidimensional');
  11445. return function() {
  11446. if (property.k) {
  11447. property.getValue();
  11448. }
  11449. val = property.v * mult;
  11450. if(expressionValue.value !== val) {
  11451. expressionValue = new Number(val);
  11452. expressionValue.value = val;
  11453. completeProperty(expressionValue, property, 'unidimensional');
  11454. }
  11455. return expressionValue;
  11456. }
  11457. }
  11458. function MultidimensionalPropertyInterface(property) {
  11459. if(!property || !('pv' in property)) {
  11460. property = defaultMultidimensionalValue;
  11461. }
  11462. var mult = 1 / property.mult;
  11463. var len = property.pv.length;
  11464. var expressionValue = createTypedArray('float32', len);
  11465. var arrValue = createTypedArray('float32', len);
  11466. expressionValue.value = arrValue;
  11467. completeProperty(expressionValue, property, 'multidimensional');
  11468. return function() {
  11469. if (property.k) {
  11470. property.getValue();
  11471. }
  11472. for (var i = 0; i < len; i += 1) {
  11473. expressionValue[i] = arrValue[i] = property.v[i] * mult;
  11474. }
  11475. return expressionValue;
  11476. }
  11477. }
  11478. //TODO: try to avoid using this getter
  11479. function defaultGetter() {
  11480. return defaultUnidimensionalValue;
  11481. }
  11482. return function(property) {
  11483. if(!property) {
  11484. return defaultGetter;
  11485. } else if (property.propType === 'unidimensional') {
  11486. return UnidimensionalPropertyInterface(property);
  11487. } else {
  11488. return MultidimensionalPropertyInterface(property);
  11489. }
  11490. }
  11491. }());
  11492. (function(){
  11493. var TextExpressionSelectorProp = (function(){
  11494. function getValueProxy(index,total){
  11495. this.textIndex = index+1;
  11496. this.textTotal = total;
  11497. this.v = this.getValue() * this.mult;
  11498. return this.v;
  11499. }
  11500. return function TextExpressionSelectorProp(elem,data){
  11501. this.pv = 1;
  11502. this.comp = elem.comp;
  11503. this.elem = elem;
  11504. this.mult = 0.01;
  11505. this.propType = 'textSelector';
  11506. this.textTotal = data.totalChars;
  11507. this.selectorValue = 100;
  11508. this.lastValue = [1,1,1];
  11509. this.k = true;
  11510. this.x = true;
  11511. this.getValue = ExpressionManager.initiateExpression.bind(this)(elem,data,this);
  11512. this.getMult = getValueProxy;
  11513. this.getVelocityAtTime = expressionHelpers.getVelocityAtTime;
  11514. if(this.kf){
  11515. this.getValueAtTime = expressionHelpers.getValueAtTime.bind(this);
  11516. } else {
  11517. this.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(this);
  11518. }
  11519. this.setGroupProperty = expressionHelpers.setGroupProperty;
  11520. };
  11521. }());
  11522. var propertyGetTextProp = TextSelectorProp.getTextSelectorProp;
  11523. TextSelectorProp.getTextSelectorProp = function(elem, data,arr){
  11524. if(data.t === 1){
  11525. return new TextExpressionSelectorProp(elem, data,arr);
  11526. } else {
  11527. return propertyGetTextProp(elem,data,arr);
  11528. }
  11529. };
  11530. }());
  11531. function SliderEffect(data,elem, container){
  11532. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  11533. }
  11534. function AngleEffect(data,elem, container){
  11535. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  11536. }
  11537. function ColorEffect(data,elem, container){
  11538. this.p = PropertyFactory.getProp(elem,data.v,1,0,container);
  11539. }
  11540. function PointEffect(data,elem, container){
  11541. this.p = PropertyFactory.getProp(elem,data.v,1,0,container);
  11542. }
  11543. function LayerIndexEffect(data,elem, container){
  11544. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  11545. }
  11546. function MaskIndexEffect(data,elem, container){
  11547. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  11548. }
  11549. function CheckboxEffect(data,elem, container){
  11550. this.p = PropertyFactory.getProp(elem,data.v,0,0,container);
  11551. }
  11552. function NoValueEffect(){
  11553. this.p = {};
  11554. }
  11555. function EffectsManager(){}
  11556. function EffectsManager(data,element){
  11557. var effects = data.ef || [];
  11558. this.effectElements = [];
  11559. var i,len = effects.length;
  11560. var effectItem;
  11561. for(i=0;i<len;i++) {
  11562. effectItem = new GroupEffect(effects[i],element);
  11563. this.effectElements.push(effectItem);
  11564. }
  11565. }
  11566. function GroupEffect(data,element){
  11567. this.init(data,element);
  11568. }
  11569. extendPrototype([DynamicPropertyContainer], GroupEffect);
  11570. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  11571. GroupEffect.prototype.init = function(data,element){
  11572. this.data = data;
  11573. this.effectElements = [];
  11574. this.initDynamicPropertyContainer(element);
  11575. var i, len = this.data.ef.length;
  11576. var eff, effects = this.data.ef;
  11577. for(i=0;i<len;i+=1){
  11578. eff = null;
  11579. switch(effects[i].ty){
  11580. case 0:
  11581. eff = new SliderEffect(effects[i],element,this);
  11582. break;
  11583. case 1:
  11584. eff = new AngleEffect(effects[i],element,this);
  11585. break;
  11586. case 2:
  11587. eff = new ColorEffect(effects[i],element,this);
  11588. break;
  11589. case 3:
  11590. eff = new PointEffect(effects[i],element,this);
  11591. break;
  11592. case 4:
  11593. case 7:
  11594. eff = new CheckboxEffect(effects[i],element,this);
  11595. break;
  11596. case 10:
  11597. eff = new LayerIndexEffect(effects[i],element,this);
  11598. break;
  11599. case 11:
  11600. eff = new MaskIndexEffect(effects[i],element,this);
  11601. break;
  11602. case 5:
  11603. eff = new EffectsManager(effects[i],element,this);
  11604. break;
  11605. //case 6:
  11606. default:
  11607. eff = new NoValueEffect(effects[i],element,this);
  11608. break;
  11609. }
  11610. if(eff) {
  11611. this.effectElements.push(eff);
  11612. }
  11613. }
  11614. };
  11615. var lottie = {};
  11616. var _isFrozen = false;
  11617. function setLocationHref (href) {
  11618. locationHref = href;
  11619. }
  11620. function searchAnimations() {
  11621. if (standalone === true) {
  11622. animationManager.searchAnimations(animationData, standalone, renderer);
  11623. } else {
  11624. animationManager.searchAnimations();
  11625. }
  11626. }
  11627. function setSubframeRendering(flag) {
  11628. subframeEnabled = flag;
  11629. }
  11630. function loadAnimation(params) {
  11631. if (standalone === true) {
  11632. params.animationData = JSON.parse(animationData);
  11633. }
  11634. return animationManager.loadAnimation(params);
  11635. }
  11636. function setQuality(value) {
  11637. if (typeof value === 'string') {
  11638. switch (value) {
  11639. case 'high':
  11640. defaultCurveSegments = 200;
  11641. break;
  11642. case 'medium':
  11643. defaultCurveSegments = 50;
  11644. break;
  11645. case 'low':
  11646. defaultCurveSegments = 10;
  11647. break;
  11648. }
  11649. } else if (!isNaN(value) && value > 1) {
  11650. defaultCurveSegments = value;
  11651. }
  11652. if (defaultCurveSegments >= 50) {
  11653. roundValues(false);
  11654. } else {
  11655. roundValues(true);
  11656. }
  11657. }
  11658. function inBrowser() {
  11659. return typeof navigator !== 'undefined';
  11660. }
  11661. function installPlugin(type, plugin) {
  11662. if (type === 'expressions') {
  11663. expressionsPlugin = plugin;
  11664. }
  11665. }
  11666. function getFactory(name) {
  11667. switch (name) {
  11668. case "propertyFactory":
  11669. return PropertyFactory;
  11670. case "shapePropertyFactory":
  11671. return ShapePropertyFactory;
  11672. case "matrix":
  11673. return Matrix;
  11674. }
  11675. }
  11676. lottie.play = animationManager.play;
  11677. lottie.pause = animationManager.pause;
  11678. lottie.setLocationHref = setLocationHref;
  11679. lottie.togglePause = animationManager.togglePause;
  11680. lottie.setSpeed = animationManager.setSpeed;
  11681. lottie.setDirection = animationManager.setDirection;
  11682. lottie.stop = animationManager.stop;
  11683. lottie.searchAnimations = searchAnimations;
  11684. lottie.registerAnimation = animationManager.registerAnimation;
  11685. lottie.loadAnimation = loadAnimation;
  11686. lottie.setSubframeRendering = setSubframeRendering;
  11687. lottie.resize = animationManager.resize;
  11688. //lottie.start = start;
  11689. lottie.goToAndStop = animationManager.goToAndStop;
  11690. lottie.destroy = animationManager.destroy;
  11691. lottie.setQuality = setQuality;
  11692. lottie.inBrowser = inBrowser;
  11693. lottie.installPlugin = installPlugin;
  11694. lottie.freeze = animationManager.freeze;
  11695. lottie.unfreeze = animationManager.unfreeze;
  11696. lottie.setVolume = animationManager.setVolume;
  11697. lottie.mute = animationManager.mute;
  11698. lottie.unmute = animationManager.unmute;
  11699. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  11700. lottie.__getFactory = getFactory;
  11701. lottie.version = '5.7.3';
  11702. function checkReady() {
  11703. if (document.readyState === "complete") {
  11704. clearInterval(readyStateCheckInterval);
  11705. searchAnimations();
  11706. }
  11707. }
  11708. function getQueryVariable(variable) {
  11709. var vars = queryString.split('&');
  11710. for (var i = 0; i < vars.length; i++) {
  11711. var pair = vars[i].split('=');
  11712. if (decodeURIComponent(pair[0]) == variable) {
  11713. return decodeURIComponent(pair[1]);
  11714. }
  11715. }
  11716. }
  11717. var standalone = '__[STANDALONE]__';
  11718. var animationData = '__[ANIMATIONDATA]__';
  11719. var renderer = '';
  11720. if (standalone) {
  11721. var scripts = document.getElementsByTagName('script');
  11722. var index = scripts.length - 1;
  11723. var myScript = scripts[index] || {
  11724. src: ''
  11725. };
  11726. var queryString = myScript.src.replace(/^[^\?]+\??/, '');
  11727. renderer = getQueryVariable('renderer');
  11728. }
  11729. var readyStateCheckInterval = setInterval(checkReady, 100);
  11730. return lottie;
  11731. }));