lottie_light_canvas.js 446 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605
  1. (typeof document !== "undefined") && (typeof navigator !== "undefined") && (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.lottie = factory());
  5. })(this, (function () { 'use strict';
  6. var svgNS = 'http://www.w3.org/2000/svg';
  7. var locationHref = '';
  8. var _useWebWorker = false;
  9. var initialDefaultFrame = -999999;
  10. var setWebWorker = function setWebWorker(flag) {
  11. _useWebWorker = !!flag;
  12. };
  13. var getWebWorker = function getWebWorker() {
  14. return _useWebWorker;
  15. };
  16. var setLocationHref = function setLocationHref(value) {
  17. locationHref = value;
  18. };
  19. var getLocationHref = function getLocationHref() {
  20. return locationHref;
  21. };
  22. function createTag(type) {
  23. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  24. return document.createElement(type);
  25. }
  26. function extendPrototype(sources, destination) {
  27. var i;
  28. var len = sources.length;
  29. var sourcePrototype;
  30. for (i = 0; i < len; i += 1) {
  31. sourcePrototype = sources[i].prototype;
  32. for (var attr in sourcePrototype) {
  33. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  34. }
  35. }
  36. }
  37. function getDescriptor(object, prop) {
  38. return Object.getOwnPropertyDescriptor(object, prop);
  39. }
  40. function createProxyFunction(prototype) {
  41. function ProxyFunction() {}
  42. ProxyFunction.prototype = prototype;
  43. return ProxyFunction;
  44. }
  45. // import Howl from '../../3rd_party/howler';
  46. var audioControllerFactory = function () {
  47. function AudioController(audioFactory) {
  48. this.audios = [];
  49. this.audioFactory = audioFactory;
  50. this._volume = 1;
  51. this._isMuted = false;
  52. }
  53. AudioController.prototype = {
  54. addAudio: function addAudio(audio) {
  55. this.audios.push(audio);
  56. },
  57. pause: function pause() {
  58. var i;
  59. var len = this.audios.length;
  60. for (i = 0; i < len; i += 1) {
  61. this.audios[i].pause();
  62. }
  63. },
  64. resume: function resume() {
  65. var i;
  66. var len = this.audios.length;
  67. for (i = 0; i < len; i += 1) {
  68. this.audios[i].resume();
  69. }
  70. },
  71. setRate: function setRate(rateValue) {
  72. var i;
  73. var len = this.audios.length;
  74. for (i = 0; i < len; i += 1) {
  75. this.audios[i].setRate(rateValue);
  76. }
  77. },
  78. createAudio: function createAudio(assetPath) {
  79. if (this.audioFactory) {
  80. return this.audioFactory(assetPath);
  81. }
  82. if (window.Howl) {
  83. return new window.Howl({
  84. src: [assetPath]
  85. });
  86. }
  87. return {
  88. isPlaying: false,
  89. play: function play() {
  90. this.isPlaying = true;
  91. },
  92. seek: function seek() {
  93. this.isPlaying = false;
  94. },
  95. playing: function playing() {},
  96. rate: function rate() {},
  97. setVolume: function setVolume() {}
  98. };
  99. },
  100. setAudioFactory: function setAudioFactory(audioFactory) {
  101. this.audioFactory = audioFactory;
  102. },
  103. setVolume: function setVolume(value) {
  104. this._volume = value;
  105. this._updateVolume();
  106. },
  107. mute: function mute() {
  108. this._isMuted = true;
  109. this._updateVolume();
  110. },
  111. unmute: function unmute() {
  112. this._isMuted = false;
  113. this._updateVolume();
  114. },
  115. getVolume: function getVolume() {
  116. return this._volume;
  117. },
  118. _updateVolume: function _updateVolume() {
  119. var i;
  120. var len = this.audios.length;
  121. for (i = 0; i < len; i += 1) {
  122. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  123. }
  124. }
  125. };
  126. return function () {
  127. return new AudioController();
  128. };
  129. }();
  130. var createTypedArray = function () {
  131. function createRegularArray(type, len) {
  132. var i = 0;
  133. var arr = [];
  134. var value;
  135. switch (type) {
  136. case 'int16':
  137. case 'uint8c':
  138. value = 1;
  139. break;
  140. default:
  141. value = 1.1;
  142. break;
  143. }
  144. for (i = 0; i < len; i += 1) {
  145. arr.push(value);
  146. }
  147. return arr;
  148. }
  149. function createTypedArrayFactory(type, len) {
  150. if (type === 'float32') {
  151. return new Float32Array(len);
  152. }
  153. if (type === 'int16') {
  154. return new Int16Array(len);
  155. }
  156. if (type === 'uint8c') {
  157. return new Uint8ClampedArray(len);
  158. }
  159. return createRegularArray(type, len);
  160. }
  161. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  162. return createTypedArrayFactory;
  163. }
  164. return createRegularArray;
  165. }();
  166. function createSizedArray(len) {
  167. return Array.apply(null, {
  168. length: len
  169. });
  170. }
  171. function _typeof$3(o) { "@babel/helpers - typeof"; return _typeof$3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$3(o); }
  172. var subframeEnabled = true;
  173. var expressionsPlugin = null;
  174. var expressionsInterfaces = null;
  175. var idPrefix$1 = '';
  176. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  177. var _shouldRoundValues = false;
  178. var bmPow = Math.pow;
  179. var bmSqrt = Math.sqrt;
  180. var bmFloor = Math.floor;
  181. var bmMax = Math.max;
  182. var bmMin = Math.min;
  183. var BMMath = {};
  184. (function () {
  185. var propertyNames = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'atan2', 'ceil', 'cbrt', 'expm1', 'clz32', 'cos', 'cosh', 'exp', 'floor', 'fround', 'hypot', 'imul', 'log', 'log1p', 'log2', 'log10', 'max', 'min', 'pow', 'random', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', 'E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2'];
  186. var i;
  187. var len = propertyNames.length;
  188. for (i = 0; i < len; i += 1) {
  189. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  190. }
  191. })();
  192. function ProjectInterface$1() {
  193. return {};
  194. }
  195. BMMath.random = Math.random;
  196. BMMath.abs = function (val) {
  197. var tOfVal = _typeof$3(val);
  198. if (tOfVal === 'object' && val.length) {
  199. var absArr = createSizedArray(val.length);
  200. var i;
  201. var len = val.length;
  202. for (i = 0; i < len; i += 1) {
  203. absArr[i] = Math.abs(val[i]);
  204. }
  205. return absArr;
  206. }
  207. return Math.abs(val);
  208. };
  209. var defaultCurveSegments = 150;
  210. var degToRads = Math.PI / 180;
  211. var roundCorner = 0.5519;
  212. function roundValues(flag) {
  213. _shouldRoundValues = !!flag;
  214. }
  215. function bmRnd(value) {
  216. if (_shouldRoundValues) {
  217. return Math.round(value);
  218. }
  219. return value;
  220. }
  221. function styleDiv(element) {
  222. element.style.position = 'absolute';
  223. element.style.top = 0;
  224. element.style.left = 0;
  225. element.style.display = 'block';
  226. element.style.transformOrigin = '0 0';
  227. element.style.webkitTransformOrigin = '0 0';
  228. element.style.backfaceVisibility = 'visible';
  229. element.style.webkitBackfaceVisibility = 'visible';
  230. element.style.transformStyle = 'preserve-3d';
  231. element.style.webkitTransformStyle = 'preserve-3d';
  232. element.style.mozTransformStyle = 'preserve-3d';
  233. }
  234. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  235. this.type = type;
  236. this.currentTime = currentTime;
  237. this.totalTime = totalTime;
  238. this.direction = frameMultiplier < 0 ? -1 : 1;
  239. }
  240. function BMCompleteEvent(type, frameMultiplier) {
  241. this.type = type;
  242. this.direction = frameMultiplier < 0 ? -1 : 1;
  243. }
  244. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  245. this.type = type;
  246. this.currentLoop = currentLoop;
  247. this.totalLoops = totalLoops;
  248. this.direction = frameMultiplier < 0 ? -1 : 1;
  249. }
  250. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  251. this.type = type;
  252. this.firstFrame = firstFrame;
  253. this.totalFrames = totalFrames;
  254. }
  255. function BMDestroyEvent(type, target) {
  256. this.type = type;
  257. this.target = target;
  258. }
  259. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  260. this.type = 'renderFrameError';
  261. this.nativeError = nativeError;
  262. this.currentTime = currentTime;
  263. }
  264. function BMConfigErrorEvent(nativeError) {
  265. this.type = 'configError';
  266. this.nativeError = nativeError;
  267. }
  268. function BMAnimationConfigErrorEvent(type, nativeError) {
  269. this.type = type;
  270. this.nativeError = nativeError;
  271. }
  272. var createElementID = function () {
  273. var _count = 0;
  274. return function createID() {
  275. _count += 1;
  276. return idPrefix$1 + '__lottie_element_' + _count;
  277. };
  278. }();
  279. function HSVtoRGB(h, s, v) {
  280. var r;
  281. var g;
  282. var b;
  283. var i;
  284. var f;
  285. var p;
  286. var q;
  287. var t;
  288. i = Math.floor(h * 6);
  289. f = h * 6 - i;
  290. p = v * (1 - s);
  291. q = v * (1 - f * s);
  292. t = v * (1 - (1 - f) * s);
  293. switch (i % 6) {
  294. case 0:
  295. r = v;
  296. g = t;
  297. b = p;
  298. break;
  299. case 1:
  300. r = q;
  301. g = v;
  302. b = p;
  303. break;
  304. case 2:
  305. r = p;
  306. g = v;
  307. b = t;
  308. break;
  309. case 3:
  310. r = p;
  311. g = q;
  312. b = v;
  313. break;
  314. case 4:
  315. r = t;
  316. g = p;
  317. b = v;
  318. break;
  319. case 5:
  320. r = v;
  321. g = p;
  322. b = q;
  323. break;
  324. default:
  325. break;
  326. }
  327. return [r, g, b];
  328. }
  329. function RGBtoHSV(r, g, b) {
  330. var max = Math.max(r, g, b);
  331. var min = Math.min(r, g, b);
  332. var d = max - min;
  333. var h;
  334. var s = max === 0 ? 0 : d / max;
  335. var v = max / 255;
  336. switch (max) {
  337. case min:
  338. h = 0;
  339. break;
  340. case r:
  341. h = g - b + d * (g < b ? 6 : 0);
  342. h /= 6 * d;
  343. break;
  344. case g:
  345. h = b - r + d * 2;
  346. h /= 6 * d;
  347. break;
  348. case b:
  349. h = r - g + d * 4;
  350. h /= 6 * d;
  351. break;
  352. default:
  353. break;
  354. }
  355. return [h, s, v];
  356. }
  357. function addSaturationToRGB(color, offset) {
  358. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  359. hsv[1] += offset;
  360. if (hsv[1] > 1) {
  361. hsv[1] = 1;
  362. } else if (hsv[1] <= 0) {
  363. hsv[1] = 0;
  364. }
  365. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  366. }
  367. function addBrightnessToRGB(color, offset) {
  368. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  369. hsv[2] += offset;
  370. if (hsv[2] > 1) {
  371. hsv[2] = 1;
  372. } else if (hsv[2] < 0) {
  373. hsv[2] = 0;
  374. }
  375. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  376. }
  377. function addHueToRGB(color, offset) {
  378. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  379. hsv[0] += offset / 360;
  380. if (hsv[0] > 1) {
  381. hsv[0] -= 1;
  382. } else if (hsv[0] < 0) {
  383. hsv[0] += 1;
  384. }
  385. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  386. }
  387. var rgbToHex = function () {
  388. var colorMap = [];
  389. var i;
  390. var hex;
  391. for (i = 0; i < 256; i += 1) {
  392. hex = i.toString(16);
  393. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  394. }
  395. return function (r, g, b) {
  396. if (r < 0) {
  397. r = 0;
  398. }
  399. if (g < 0) {
  400. g = 0;
  401. }
  402. if (b < 0) {
  403. b = 0;
  404. }
  405. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  406. };
  407. }();
  408. var setSubframeEnabled = function setSubframeEnabled(flag) {
  409. subframeEnabled = !!flag;
  410. };
  411. var getSubframeEnabled = function getSubframeEnabled() {
  412. return subframeEnabled;
  413. };
  414. var setExpressionsPlugin = function setExpressionsPlugin(value) {
  415. expressionsPlugin = value;
  416. };
  417. var getExpressionsPlugin = function getExpressionsPlugin() {
  418. return expressionsPlugin;
  419. };
  420. var setExpressionInterfaces = function setExpressionInterfaces(value) {
  421. expressionsInterfaces = value;
  422. };
  423. var getExpressionInterfaces = function getExpressionInterfaces() {
  424. return expressionsInterfaces;
  425. };
  426. var setDefaultCurveSegments = function setDefaultCurveSegments(value) {
  427. defaultCurveSegments = value;
  428. };
  429. var getDefaultCurveSegments = function getDefaultCurveSegments() {
  430. return defaultCurveSegments;
  431. };
  432. var setIdPrefix = function setIdPrefix(value) {
  433. idPrefix$1 = value;
  434. };
  435. var getIdPrefix = function getIdPrefix() {
  436. return idPrefix$1;
  437. };
  438. function createNS(type) {
  439. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  440. return document.createElementNS(svgNS, type);
  441. }
  442. function _typeof$2(o) { "@babel/helpers - typeof"; return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$2(o); }
  443. var dataManager = function () {
  444. var _counterId = 1;
  445. var processes = [];
  446. var workerFn;
  447. var workerInstance;
  448. var workerProxy = {
  449. onmessage: function onmessage() {},
  450. postMessage: function postMessage(path) {
  451. workerFn({
  452. data: path
  453. });
  454. }
  455. };
  456. var _workerSelf = {
  457. postMessage: function postMessage(data) {
  458. workerProxy.onmessage({
  459. data: data
  460. });
  461. }
  462. };
  463. function createWorker(fn) {
  464. if (window.Worker && window.Blob && getWebWorker()) {
  465. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], {
  466. type: 'text/javascript'
  467. });
  468. // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  469. var url = URL.createObjectURL(blob);
  470. return new Worker(url);
  471. }
  472. workerFn = fn;
  473. return workerProxy;
  474. }
  475. function setupWorker() {
  476. if (!workerInstance) {
  477. workerInstance = createWorker(function workerStart(e) {
  478. function dataFunctionManager() {
  479. function completeLayers(layers, comps) {
  480. var layerData;
  481. var i;
  482. var len = layers.length;
  483. var j;
  484. var jLen;
  485. var k;
  486. var kLen;
  487. for (i = 0; i < len; i += 1) {
  488. layerData = layers[i];
  489. if ('ks' in layerData && !layerData.completed) {
  490. layerData.completed = true;
  491. if (layerData.hasMask) {
  492. var maskProps = layerData.masksProperties;
  493. jLen = maskProps.length;
  494. for (j = 0; j < jLen; j += 1) {
  495. if (maskProps[j].pt.k.i) {
  496. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  497. } else {
  498. kLen = maskProps[j].pt.k.length;
  499. for (k = 0; k < kLen; k += 1) {
  500. if (maskProps[j].pt.k[k].s) {
  501. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  502. }
  503. if (maskProps[j].pt.k[k].e) {
  504. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  505. }
  506. }
  507. }
  508. }
  509. }
  510. if (layerData.ty === 0) {
  511. layerData.layers = findCompLayers(layerData.refId, comps);
  512. completeLayers(layerData.layers, comps);
  513. } else if (layerData.ty === 4) {
  514. completeShapes(layerData.shapes);
  515. } else if (layerData.ty === 5) {
  516. completeText(layerData);
  517. }
  518. }
  519. }
  520. }
  521. function completeChars(chars, assets) {
  522. if (chars) {
  523. var i = 0;
  524. var len = chars.length;
  525. for (i = 0; i < len; i += 1) {
  526. if (chars[i].t === 1) {
  527. // var compData = findComp(chars[i].data.refId, assets);
  528. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
  529. // chars[i].data.ip = 0;
  530. // chars[i].data.op = 99999;
  531. // chars[i].data.st = 0;
  532. // chars[i].data.sr = 1;
  533. // chars[i].w = compData.w;
  534. // chars[i].data.ks = {
  535. // a: { k: [0, 0, 0], a: 0 },
  536. // p: { k: [0, -compData.h, 0], a: 0 },
  537. // r: { k: 0, a: 0 },
  538. // s: { k: [100, 100], a: 0 },
  539. // o: { k: 100, a: 0 },
  540. // };
  541. completeLayers(chars[i].data.layers, assets);
  542. }
  543. }
  544. }
  545. }
  546. function findComp(id, comps) {
  547. var i = 0;
  548. var len = comps.length;
  549. while (i < len) {
  550. if (comps[i].id === id) {
  551. return comps[i];
  552. }
  553. i += 1;
  554. }
  555. return null;
  556. }
  557. function findCompLayers(id, comps) {
  558. var comp = findComp(id, comps);
  559. if (comp) {
  560. if (!comp.layers.__used) {
  561. comp.layers.__used = true;
  562. return comp.layers;
  563. }
  564. return JSON.parse(JSON.stringify(comp.layers));
  565. }
  566. return null;
  567. }
  568. function completeShapes(arr) {
  569. var i;
  570. var len = arr.length;
  571. var j;
  572. var jLen;
  573. for (i = len - 1; i >= 0; i -= 1) {
  574. if (arr[i].ty === 'sh') {
  575. if (arr[i].ks.k.i) {
  576. convertPathsToAbsoluteValues(arr[i].ks.k);
  577. } else {
  578. jLen = arr[i].ks.k.length;
  579. for (j = 0; j < jLen; j += 1) {
  580. if (arr[i].ks.k[j].s) {
  581. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  582. }
  583. if (arr[i].ks.k[j].e) {
  584. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  585. }
  586. }
  587. }
  588. } else if (arr[i].ty === 'gr') {
  589. completeShapes(arr[i].it);
  590. }
  591. }
  592. }
  593. function convertPathsToAbsoluteValues(path) {
  594. var i;
  595. var len = path.i.length;
  596. for (i = 0; i < len; i += 1) {
  597. path.i[i][0] += path.v[i][0];
  598. path.i[i][1] += path.v[i][1];
  599. path.o[i][0] += path.v[i][0];
  600. path.o[i][1] += path.v[i][1];
  601. }
  602. }
  603. function checkVersion(minimum, animVersionString) {
  604. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  605. if (minimum[0] > animVersion[0]) {
  606. return true;
  607. }
  608. if (animVersion[0] > minimum[0]) {
  609. return false;
  610. }
  611. if (minimum[1] > animVersion[1]) {
  612. return true;
  613. }
  614. if (animVersion[1] > minimum[1]) {
  615. return false;
  616. }
  617. if (minimum[2] > animVersion[2]) {
  618. return true;
  619. }
  620. if (animVersion[2] > minimum[2]) {
  621. return false;
  622. }
  623. return null;
  624. }
  625. var checkText = function () {
  626. var minimumVersion = [4, 4, 14];
  627. function updateTextLayer(textLayer) {
  628. var documentData = textLayer.t.d;
  629. textLayer.t.d = {
  630. k: [{
  631. s: documentData,
  632. t: 0
  633. }]
  634. };
  635. }
  636. function iterateLayers(layers) {
  637. var i;
  638. var len = layers.length;
  639. for (i = 0; i < len; i += 1) {
  640. if (layers[i].ty === 5) {
  641. updateTextLayer(layers[i]);
  642. }
  643. }
  644. }
  645. return function (animationData) {
  646. if (checkVersion(minimumVersion, animationData.v)) {
  647. iterateLayers(animationData.layers);
  648. if (animationData.assets) {
  649. var i;
  650. var len = animationData.assets.length;
  651. for (i = 0; i < len; i += 1) {
  652. if (animationData.assets[i].layers) {
  653. iterateLayers(animationData.assets[i].layers);
  654. }
  655. }
  656. }
  657. }
  658. };
  659. }();
  660. var checkChars = function () {
  661. var minimumVersion = [4, 7, 99];
  662. return function (animationData) {
  663. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  664. var i;
  665. var len = animationData.chars.length;
  666. for (i = 0; i < len; i += 1) {
  667. var charData = animationData.chars[i];
  668. if (charData.data && charData.data.shapes) {
  669. completeShapes(charData.data.shapes);
  670. charData.data.ip = 0;
  671. charData.data.op = 99999;
  672. charData.data.st = 0;
  673. charData.data.sr = 1;
  674. charData.data.ks = {
  675. p: {
  676. k: [0, 0],
  677. a: 0
  678. },
  679. s: {
  680. k: [100, 100],
  681. a: 0
  682. },
  683. a: {
  684. k: [0, 0],
  685. a: 0
  686. },
  687. r: {
  688. k: 0,
  689. a: 0
  690. },
  691. o: {
  692. k: 100,
  693. a: 0
  694. }
  695. };
  696. if (!animationData.chars[i].t) {
  697. charData.data.shapes.push({
  698. ty: 'no'
  699. });
  700. charData.data.shapes[0].it.push({
  701. p: {
  702. k: [0, 0],
  703. a: 0
  704. },
  705. s: {
  706. k: [100, 100],
  707. a: 0
  708. },
  709. a: {
  710. k: [0, 0],
  711. a: 0
  712. },
  713. r: {
  714. k: 0,
  715. a: 0
  716. },
  717. o: {
  718. k: 100,
  719. a: 0
  720. },
  721. sk: {
  722. k: 0,
  723. a: 0
  724. },
  725. sa: {
  726. k: 0,
  727. a: 0
  728. },
  729. ty: 'tr'
  730. });
  731. }
  732. }
  733. }
  734. }
  735. };
  736. }();
  737. var checkPathProperties = function () {
  738. var minimumVersion = [5, 7, 15];
  739. function updateTextLayer(textLayer) {
  740. var pathData = textLayer.t.p;
  741. if (typeof pathData.a === 'number') {
  742. pathData.a = {
  743. a: 0,
  744. k: pathData.a
  745. };
  746. }
  747. if (typeof pathData.p === 'number') {
  748. pathData.p = {
  749. a: 0,
  750. k: pathData.p
  751. };
  752. }
  753. if (typeof pathData.r === 'number') {
  754. pathData.r = {
  755. a: 0,
  756. k: pathData.r
  757. };
  758. }
  759. }
  760. function iterateLayers(layers) {
  761. var i;
  762. var len = layers.length;
  763. for (i = 0; i < len; i += 1) {
  764. if (layers[i].ty === 5) {
  765. updateTextLayer(layers[i]);
  766. }
  767. }
  768. }
  769. return function (animationData) {
  770. if (checkVersion(minimumVersion, animationData.v)) {
  771. iterateLayers(animationData.layers);
  772. if (animationData.assets) {
  773. var i;
  774. var len = animationData.assets.length;
  775. for (i = 0; i < len; i += 1) {
  776. if (animationData.assets[i].layers) {
  777. iterateLayers(animationData.assets[i].layers);
  778. }
  779. }
  780. }
  781. }
  782. };
  783. }();
  784. var checkColors = function () {
  785. var minimumVersion = [4, 1, 9];
  786. function iterateShapes(shapes) {
  787. var i;
  788. var len = shapes.length;
  789. var j;
  790. var jLen;
  791. for (i = 0; i < len; i += 1) {
  792. if (shapes[i].ty === 'gr') {
  793. iterateShapes(shapes[i].it);
  794. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  795. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  796. jLen = shapes[i].c.k.length;
  797. for (j = 0; j < jLen; j += 1) {
  798. if (shapes[i].c.k[j].s) {
  799. shapes[i].c.k[j].s[0] /= 255;
  800. shapes[i].c.k[j].s[1] /= 255;
  801. shapes[i].c.k[j].s[2] /= 255;
  802. shapes[i].c.k[j].s[3] /= 255;
  803. }
  804. if (shapes[i].c.k[j].e) {
  805. shapes[i].c.k[j].e[0] /= 255;
  806. shapes[i].c.k[j].e[1] /= 255;
  807. shapes[i].c.k[j].e[2] /= 255;
  808. shapes[i].c.k[j].e[3] /= 255;
  809. }
  810. }
  811. } else {
  812. shapes[i].c.k[0] /= 255;
  813. shapes[i].c.k[1] /= 255;
  814. shapes[i].c.k[2] /= 255;
  815. shapes[i].c.k[3] /= 255;
  816. }
  817. }
  818. }
  819. }
  820. function iterateLayers(layers) {
  821. var i;
  822. var len = layers.length;
  823. for (i = 0; i < len; i += 1) {
  824. if (layers[i].ty === 4) {
  825. iterateShapes(layers[i].shapes);
  826. }
  827. }
  828. }
  829. return function (animationData) {
  830. if (checkVersion(minimumVersion, animationData.v)) {
  831. iterateLayers(animationData.layers);
  832. if (animationData.assets) {
  833. var i;
  834. var len = animationData.assets.length;
  835. for (i = 0; i < len; i += 1) {
  836. if (animationData.assets[i].layers) {
  837. iterateLayers(animationData.assets[i].layers);
  838. }
  839. }
  840. }
  841. }
  842. };
  843. }();
  844. var checkShapes = function () {
  845. var minimumVersion = [4, 4, 18];
  846. function completeClosingShapes(arr) {
  847. var i;
  848. var len = arr.length;
  849. var j;
  850. var jLen;
  851. for (i = len - 1; i >= 0; i -= 1) {
  852. if (arr[i].ty === 'sh') {
  853. if (arr[i].ks.k.i) {
  854. arr[i].ks.k.c = arr[i].closed;
  855. } else {
  856. jLen = arr[i].ks.k.length;
  857. for (j = 0; j < jLen; j += 1) {
  858. if (arr[i].ks.k[j].s) {
  859. arr[i].ks.k[j].s[0].c = arr[i].closed;
  860. }
  861. if (arr[i].ks.k[j].e) {
  862. arr[i].ks.k[j].e[0].c = arr[i].closed;
  863. }
  864. }
  865. }
  866. } else if (arr[i].ty === 'gr') {
  867. completeClosingShapes(arr[i].it);
  868. }
  869. }
  870. }
  871. function iterateLayers(layers) {
  872. var layerData;
  873. var i;
  874. var len = layers.length;
  875. var j;
  876. var jLen;
  877. var k;
  878. var kLen;
  879. for (i = 0; i < len; i += 1) {
  880. layerData = layers[i];
  881. if (layerData.hasMask) {
  882. var maskProps = layerData.masksProperties;
  883. jLen = maskProps.length;
  884. for (j = 0; j < jLen; j += 1) {
  885. if (maskProps[j].pt.k.i) {
  886. maskProps[j].pt.k.c = maskProps[j].cl;
  887. } else {
  888. kLen = maskProps[j].pt.k.length;
  889. for (k = 0; k < kLen; k += 1) {
  890. if (maskProps[j].pt.k[k].s) {
  891. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  892. }
  893. if (maskProps[j].pt.k[k].e) {
  894. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  895. }
  896. }
  897. }
  898. }
  899. }
  900. if (layerData.ty === 4) {
  901. completeClosingShapes(layerData.shapes);
  902. }
  903. }
  904. }
  905. return function (animationData) {
  906. if (checkVersion(minimumVersion, animationData.v)) {
  907. iterateLayers(animationData.layers);
  908. if (animationData.assets) {
  909. var i;
  910. var len = animationData.assets.length;
  911. for (i = 0; i < len; i += 1) {
  912. if (animationData.assets[i].layers) {
  913. iterateLayers(animationData.assets[i].layers);
  914. }
  915. }
  916. }
  917. }
  918. };
  919. }();
  920. function completeData(animationData) {
  921. if (animationData.__complete) {
  922. return;
  923. }
  924. checkColors(animationData);
  925. checkText(animationData);
  926. checkChars(animationData);
  927. checkPathProperties(animationData);
  928. checkShapes(animationData);
  929. completeLayers(animationData.layers, animationData.assets);
  930. completeChars(animationData.chars, animationData.assets);
  931. animationData.__complete = true;
  932. }
  933. function completeText(data) {
  934. if (data.t.a.length === 0 && !('m' in data.t.p)) {
  935. // data.singleShape = true;
  936. }
  937. }
  938. var moduleOb = {};
  939. moduleOb.completeData = completeData;
  940. moduleOb.checkColors = checkColors;
  941. moduleOb.checkChars = checkChars;
  942. moduleOb.checkPathProperties = checkPathProperties;
  943. moduleOb.checkShapes = checkShapes;
  944. moduleOb.completeLayers = completeLayers;
  945. return moduleOb;
  946. }
  947. if (!_workerSelf.dataManager) {
  948. _workerSelf.dataManager = dataFunctionManager();
  949. }
  950. if (!_workerSelf.assetLoader) {
  951. _workerSelf.assetLoader = function () {
  952. function formatResponse(xhr) {
  953. // using typeof doubles the time of execution of this method,
  954. // so if available, it's better to use the header to validate the type
  955. var contentTypeHeader = xhr.getResponseHeader('content-type');
  956. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  957. return xhr.response;
  958. }
  959. if (xhr.response && _typeof$2(xhr.response) === 'object') {
  960. return xhr.response;
  961. }
  962. if (xhr.response && typeof xhr.response === 'string') {
  963. return JSON.parse(xhr.response);
  964. }
  965. if (xhr.responseText) {
  966. return JSON.parse(xhr.responseText);
  967. }
  968. return null;
  969. }
  970. function loadAsset(path, fullPath, callback, errorCallback) {
  971. var response;
  972. var xhr = new XMLHttpRequest();
  973. // set responseType after calling open or IE will break.
  974. try {
  975. // This crashes on Android WebView prior to KitKat
  976. xhr.responseType = 'json';
  977. } catch (err) {} // eslint-disable-line no-empty
  978. xhr.onreadystatechange = function () {
  979. if (xhr.readyState === 4) {
  980. if (xhr.status === 200) {
  981. response = formatResponse(xhr);
  982. callback(response);
  983. } else {
  984. try {
  985. response = formatResponse(xhr);
  986. callback(response);
  987. } catch (err) {
  988. if (errorCallback) {
  989. errorCallback(err);
  990. }
  991. }
  992. }
  993. }
  994. };
  995. try {
  996. // Hack to workaround banner validation
  997. xhr.open(['G', 'E', 'T'].join(''), path, true);
  998. } catch (error) {
  999. // Hack to workaround banner validation
  1000. xhr.open(['G', 'E', 'T'].join(''), fullPath + '/' + path, true);
  1001. }
  1002. xhr.send();
  1003. }
  1004. return {
  1005. load: loadAsset
  1006. };
  1007. }();
  1008. }
  1009. if (e.data.type === 'loadAnimation') {
  1010. _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function (data) {
  1011. _workerSelf.dataManager.completeData(data);
  1012. _workerSelf.postMessage({
  1013. id: e.data.id,
  1014. payload: data,
  1015. status: 'success'
  1016. });
  1017. }, function () {
  1018. _workerSelf.postMessage({
  1019. id: e.data.id,
  1020. status: 'error'
  1021. });
  1022. });
  1023. } else if (e.data.type === 'complete') {
  1024. var animation = e.data.animation;
  1025. _workerSelf.dataManager.completeData(animation);
  1026. _workerSelf.postMessage({
  1027. id: e.data.id,
  1028. payload: animation,
  1029. status: 'success'
  1030. });
  1031. } else if (e.data.type === 'loadData') {
  1032. _workerSelf.assetLoader.load(e.data.path, e.data.fullPath, function (data) {
  1033. _workerSelf.postMessage({
  1034. id: e.data.id,
  1035. payload: data,
  1036. status: 'success'
  1037. });
  1038. }, function () {
  1039. _workerSelf.postMessage({
  1040. id: e.data.id,
  1041. status: 'error'
  1042. });
  1043. });
  1044. }
  1045. });
  1046. workerInstance.onmessage = function (event) {
  1047. var data = event.data;
  1048. var id = data.id;
  1049. var process = processes[id];
  1050. processes[id] = null;
  1051. if (data.status === 'success') {
  1052. process.onComplete(data.payload);
  1053. } else if (process.onError) {
  1054. process.onError();
  1055. }
  1056. };
  1057. }
  1058. }
  1059. function createProcess(onComplete, onError) {
  1060. _counterId += 1;
  1061. var id = 'processId_' + _counterId;
  1062. processes[id] = {
  1063. onComplete: onComplete,
  1064. onError: onError
  1065. };
  1066. return id;
  1067. }
  1068. function loadAnimation(path, onComplete, onError) {
  1069. setupWorker();
  1070. var processId = createProcess(onComplete, onError);
  1071. workerInstance.postMessage({
  1072. type: 'loadAnimation',
  1073. path: path,
  1074. fullPath: window.location.origin + window.location.pathname,
  1075. id: processId
  1076. });
  1077. }
  1078. function loadData(path, onComplete, onError) {
  1079. setupWorker();
  1080. var processId = createProcess(onComplete, onError);
  1081. workerInstance.postMessage({
  1082. type: 'loadData',
  1083. path: path,
  1084. fullPath: window.location.origin + window.location.pathname,
  1085. id: processId
  1086. });
  1087. }
  1088. function completeAnimation(anim, onComplete, onError) {
  1089. setupWorker();
  1090. var processId = createProcess(onComplete, onError);
  1091. workerInstance.postMessage({
  1092. type: 'complete',
  1093. animation: anim,
  1094. id: processId
  1095. });
  1096. }
  1097. return {
  1098. loadAnimation: loadAnimation,
  1099. loadData: loadData,
  1100. completeAnimation: completeAnimation
  1101. };
  1102. }();
  1103. var ImagePreloader = function () {
  1104. var proxyImage = function () {
  1105. var canvas = createTag('canvas');
  1106. canvas.width = 1;
  1107. canvas.height = 1;
  1108. var ctx = canvas.getContext('2d');
  1109. ctx.fillStyle = 'rgba(0,0,0,0)';
  1110. ctx.fillRect(0, 0, 1, 1);
  1111. return canvas;
  1112. }();
  1113. function imageLoaded() {
  1114. this.loadedAssets += 1;
  1115. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1116. if (this.imagesLoadedCb) {
  1117. this.imagesLoadedCb(null);
  1118. }
  1119. }
  1120. }
  1121. function footageLoaded() {
  1122. this.loadedFootagesCount += 1;
  1123. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1124. if (this.imagesLoadedCb) {
  1125. this.imagesLoadedCb(null);
  1126. }
  1127. }
  1128. }
  1129. function getAssetsPath(assetData, assetsPath, originalPath) {
  1130. var path = '';
  1131. if (assetData.e) {
  1132. path = assetData.p;
  1133. } else if (assetsPath) {
  1134. var imagePath = assetData.p;
  1135. if (imagePath.indexOf('images/') !== -1) {
  1136. imagePath = imagePath.split('/')[1];
  1137. }
  1138. path = assetsPath + imagePath;
  1139. } else {
  1140. path = originalPath;
  1141. path += assetData.u ? assetData.u : '';
  1142. path += assetData.p;
  1143. }
  1144. return path;
  1145. }
  1146. function testImageLoaded(img) {
  1147. var _count = 0;
  1148. var intervalId = setInterval(function () {
  1149. var box = img.getBBox();
  1150. if (box.width || _count > 500) {
  1151. this._imageLoaded();
  1152. clearInterval(intervalId);
  1153. }
  1154. _count += 1;
  1155. }.bind(this), 50);
  1156. }
  1157. function createImageData(assetData) {
  1158. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1159. var img = createNS('image');
  1160. if (isSafari) {
  1161. this.testImageLoaded(img);
  1162. } else {
  1163. img.addEventListener('load', this._imageLoaded, false);
  1164. }
  1165. img.addEventListener('error', function () {
  1166. ob.img = proxyImage;
  1167. this._imageLoaded();
  1168. }.bind(this), false);
  1169. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1170. if (this._elementHelper.append) {
  1171. this._elementHelper.append(img);
  1172. } else {
  1173. this._elementHelper.appendChild(img);
  1174. }
  1175. var ob = {
  1176. img: img,
  1177. assetData: assetData
  1178. };
  1179. return ob;
  1180. }
  1181. function createImgData(assetData) {
  1182. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1183. var img = createTag('img');
  1184. img.crossOrigin = 'anonymous';
  1185. img.addEventListener('load', this._imageLoaded, false);
  1186. img.addEventListener('error', function () {
  1187. ob.img = proxyImage;
  1188. this._imageLoaded();
  1189. }.bind(this), false);
  1190. img.src = path;
  1191. var ob = {
  1192. img: img,
  1193. assetData: assetData
  1194. };
  1195. return ob;
  1196. }
  1197. function createFootageData(data) {
  1198. var ob = {
  1199. assetData: data
  1200. };
  1201. var path = getAssetsPath(data, this.assetsPath, this.path);
  1202. dataManager.loadData(path, function (footageData) {
  1203. ob.img = footageData;
  1204. this._footageLoaded();
  1205. }.bind(this), function () {
  1206. ob.img = {};
  1207. this._footageLoaded();
  1208. }.bind(this));
  1209. return ob;
  1210. }
  1211. function loadAssets(assets, cb) {
  1212. this.imagesLoadedCb = cb;
  1213. var i;
  1214. var len = assets.length;
  1215. for (i = 0; i < len; i += 1) {
  1216. if (!assets[i].layers) {
  1217. if (!assets[i].t || assets[i].t === 'seq') {
  1218. this.totalImages += 1;
  1219. this.images.push(this._createImageData(assets[i]));
  1220. } else if (assets[i].t === 3) {
  1221. this.totalFootages += 1;
  1222. this.images.push(this.createFootageData(assets[i]));
  1223. }
  1224. }
  1225. }
  1226. }
  1227. function setPath(path) {
  1228. this.path = path || '';
  1229. }
  1230. function setAssetsPath(path) {
  1231. this.assetsPath = path || '';
  1232. }
  1233. function getAsset(assetData) {
  1234. var i = 0;
  1235. var len = this.images.length;
  1236. while (i < len) {
  1237. if (this.images[i].assetData === assetData) {
  1238. return this.images[i].img;
  1239. }
  1240. i += 1;
  1241. }
  1242. return null;
  1243. }
  1244. function destroy() {
  1245. this.imagesLoadedCb = null;
  1246. this.images.length = 0;
  1247. }
  1248. function loadedImages() {
  1249. return this.totalImages === this.loadedAssets;
  1250. }
  1251. function loadedFootages() {
  1252. return this.totalFootages === this.loadedFootagesCount;
  1253. }
  1254. function setCacheType(type, elementHelper) {
  1255. if (type === 'svg') {
  1256. this._elementHelper = elementHelper;
  1257. this._createImageData = this.createImageData.bind(this);
  1258. } else {
  1259. this._createImageData = this.createImgData.bind(this);
  1260. }
  1261. }
  1262. function ImagePreloaderFactory() {
  1263. this._imageLoaded = imageLoaded.bind(this);
  1264. this._footageLoaded = footageLoaded.bind(this);
  1265. this.testImageLoaded = testImageLoaded.bind(this);
  1266. this.createFootageData = createFootageData.bind(this);
  1267. this.assetsPath = '';
  1268. this.path = '';
  1269. this.totalImages = 0;
  1270. this.totalFootages = 0;
  1271. this.loadedAssets = 0;
  1272. this.loadedFootagesCount = 0;
  1273. this.imagesLoadedCb = null;
  1274. this.images = [];
  1275. }
  1276. ImagePreloaderFactory.prototype = {
  1277. loadAssets: loadAssets,
  1278. setAssetsPath: setAssetsPath,
  1279. setPath: setPath,
  1280. loadedImages: loadedImages,
  1281. loadedFootages: loadedFootages,
  1282. destroy: destroy,
  1283. getAsset: getAsset,
  1284. createImgData: createImgData,
  1285. createImageData: createImageData,
  1286. imageLoaded: imageLoaded,
  1287. footageLoaded: footageLoaded,
  1288. setCacheType: setCacheType
  1289. };
  1290. return ImagePreloaderFactory;
  1291. }();
  1292. function BaseEvent() {}
  1293. BaseEvent.prototype = {
  1294. triggerEvent: function triggerEvent(eventName, args) {
  1295. if (this._cbs[eventName]) {
  1296. var callbacks = this._cbs[eventName];
  1297. for (var i = 0; i < callbacks.length; i += 1) {
  1298. callbacks[i](args);
  1299. }
  1300. }
  1301. },
  1302. addEventListener: function addEventListener(eventName, callback) {
  1303. if (!this._cbs[eventName]) {
  1304. this._cbs[eventName] = [];
  1305. }
  1306. this._cbs[eventName].push(callback);
  1307. return function () {
  1308. this.removeEventListener(eventName, callback);
  1309. }.bind(this);
  1310. },
  1311. removeEventListener: function removeEventListener(eventName, callback) {
  1312. if (!callback) {
  1313. this._cbs[eventName] = null;
  1314. } else if (this._cbs[eventName]) {
  1315. var i = 0;
  1316. var len = this._cbs[eventName].length;
  1317. while (i < len) {
  1318. if (this._cbs[eventName][i] === callback) {
  1319. this._cbs[eventName].splice(i, 1);
  1320. i -= 1;
  1321. len -= 1;
  1322. }
  1323. i += 1;
  1324. }
  1325. if (!this._cbs[eventName].length) {
  1326. this._cbs[eventName] = null;
  1327. }
  1328. }
  1329. }
  1330. };
  1331. var markerParser = function () {
  1332. function parsePayloadLines(payload) {
  1333. var lines = payload.split('\r\n');
  1334. var keys = {};
  1335. var line;
  1336. var keysCount = 0;
  1337. for (var i = 0; i < lines.length; i += 1) {
  1338. line = lines[i].split(':');
  1339. if (line.length === 2) {
  1340. keys[line[0]] = line[1].trim();
  1341. keysCount += 1;
  1342. }
  1343. }
  1344. if (keysCount === 0) {
  1345. throw new Error();
  1346. }
  1347. return keys;
  1348. }
  1349. return function (_markers) {
  1350. var markers = [];
  1351. for (var i = 0; i < _markers.length; i += 1) {
  1352. var _marker = _markers[i];
  1353. var markerData = {
  1354. time: _marker.tm,
  1355. duration: _marker.dr
  1356. };
  1357. try {
  1358. markerData.payload = JSON.parse(_markers[i].cm);
  1359. } catch (_) {
  1360. try {
  1361. markerData.payload = parsePayloadLines(_markers[i].cm);
  1362. } catch (__) {
  1363. markerData.payload = {
  1364. name: _markers[i].cm
  1365. };
  1366. }
  1367. }
  1368. markers.push(markerData);
  1369. }
  1370. return markers;
  1371. };
  1372. }();
  1373. var ProjectInterface = function () {
  1374. function registerComposition(comp) {
  1375. this.compositions.push(comp);
  1376. }
  1377. return function () {
  1378. function _thisProjectFunction(name) {
  1379. var i = 0;
  1380. var len = this.compositions.length;
  1381. while (i < len) {
  1382. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1383. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1384. this.compositions[i].prepareFrame(this.currentFrame);
  1385. }
  1386. return this.compositions[i].compInterface;
  1387. }
  1388. i += 1;
  1389. }
  1390. return null;
  1391. }
  1392. _thisProjectFunction.compositions = [];
  1393. _thisProjectFunction.currentFrame = 0;
  1394. _thisProjectFunction.registerComposition = registerComposition;
  1395. return _thisProjectFunction;
  1396. };
  1397. }();
  1398. var renderers = {};
  1399. var registerRenderer = function registerRenderer(key, value) {
  1400. renderers[key] = value;
  1401. };
  1402. function getRenderer(key) {
  1403. return renderers[key];
  1404. }
  1405. function getRegisteredRenderer() {
  1406. // Returns canvas by default for compatibility
  1407. if (renderers.canvas) {
  1408. return 'canvas';
  1409. }
  1410. // Returns any renderer that is registered
  1411. for (var key in renderers) {
  1412. if (renderers[key]) {
  1413. return key;
  1414. }
  1415. }
  1416. return '';
  1417. }
  1418. function _typeof$1(o) { "@babel/helpers - typeof"; return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$1(o); }
  1419. var AnimationItem = function AnimationItem() {
  1420. this._cbs = [];
  1421. this.name = '';
  1422. this.path = '';
  1423. this.isLoaded = false;
  1424. this.currentFrame = 0;
  1425. this.currentRawFrame = 0;
  1426. this.firstFrame = 0;
  1427. this.totalFrames = 0;
  1428. this.frameRate = 0;
  1429. this.frameMult = 0;
  1430. this.playSpeed = 1;
  1431. this.playDirection = 1;
  1432. this.playCount = 0;
  1433. this.animationData = {};
  1434. this.assets = [];
  1435. this.isPaused = true;
  1436. this.autoplay = false;
  1437. this.loop = true;
  1438. this.renderer = null;
  1439. this.animationID = createElementID();
  1440. this.assetsPath = '';
  1441. this.timeCompleted = 0;
  1442. this.segmentPos = 0;
  1443. this.isSubframeEnabled = getSubframeEnabled();
  1444. this.segments = [];
  1445. this._idle = true;
  1446. this._completedLoop = false;
  1447. this.projectInterface = ProjectInterface();
  1448. this.imagePreloader = new ImagePreloader();
  1449. this.audioController = audioControllerFactory();
  1450. this.markers = [];
  1451. this.configAnimation = this.configAnimation.bind(this);
  1452. this.onSetupError = this.onSetupError.bind(this);
  1453. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1454. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1455. this.expressionsPlugin = getExpressionsPlugin();
  1456. };
  1457. extendPrototype([BaseEvent], AnimationItem);
  1458. AnimationItem.prototype.setParams = function (params) {
  1459. if (params.wrapper || params.container) {
  1460. this.wrapper = params.wrapper || params.container;
  1461. }
  1462. var animType = 'svg';
  1463. if (params.animType) {
  1464. animType = params.animType;
  1465. } else if (params.renderer) {
  1466. animType = params.renderer;
  1467. }
  1468. var RendererClass = getRenderer(animType);
  1469. this.renderer = new RendererClass(this, params.rendererSettings);
  1470. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1471. this.renderer.setProjectInterface(this.projectInterface);
  1472. this.animType = animType;
  1473. if (params.loop === '' || params.loop === null || params.loop === undefined || params.loop === true) {
  1474. this.loop = true;
  1475. } else if (params.loop === false) {
  1476. this.loop = false;
  1477. } else {
  1478. this.loop = parseInt(params.loop, 10);
  1479. }
  1480. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1481. this.name = params.name ? params.name : '';
  1482. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1483. this.assetsPath = params.assetsPath;
  1484. this.initialSegment = params.initialSegment;
  1485. if (params.audioFactory) {
  1486. this.audioController.setAudioFactory(params.audioFactory);
  1487. }
  1488. if (params.animationData) {
  1489. this.setupAnimation(params.animationData);
  1490. } else if (params.path) {
  1491. if (params.path.lastIndexOf('\\') !== -1) {
  1492. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1493. } else {
  1494. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1495. }
  1496. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1497. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1498. dataManager.loadAnimation(params.path, this.configAnimation, this.onSetupError);
  1499. }
  1500. };
  1501. AnimationItem.prototype.onSetupError = function () {
  1502. this.trigger('data_failed');
  1503. };
  1504. AnimationItem.prototype.setupAnimation = function (data) {
  1505. dataManager.completeAnimation(data, this.configAnimation);
  1506. };
  1507. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1508. if (animationData) {
  1509. if (_typeof$1(animationData) !== 'object') {
  1510. animationData = JSON.parse(animationData);
  1511. }
  1512. }
  1513. var params = {
  1514. wrapper: wrapper,
  1515. animationData: animationData
  1516. };
  1517. var wrapperAttributes = wrapper.attributes;
  1518. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1519. ? wrapperAttributes.getNamedItem('data-animation-path').value : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1520. ? wrapperAttributes.getNamedItem('data-bm-path').value : wrapperAttributes.getNamedItem('bm-path') ? wrapperAttributes.getNamedItem('bm-path').value : '';
  1521. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1522. ? wrapperAttributes.getNamedItem('data-anim-type').value : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1523. ? wrapperAttributes.getNamedItem('data-bm-type').value : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1524. ? wrapperAttributes.getNamedItem('bm-type').value : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1525. ? wrapperAttributes.getNamedItem('data-bm-renderer').value : wrapperAttributes.getNamedItem('bm-renderer') ? wrapperAttributes.getNamedItem('bm-renderer').value : getRegisteredRenderer() || 'canvas';
  1526. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1527. ? wrapperAttributes.getNamedItem('data-anim-loop').value : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1528. ? wrapperAttributes.getNamedItem('data-bm-loop').value : wrapperAttributes.getNamedItem('bm-loop') ? wrapperAttributes.getNamedItem('bm-loop').value : '';
  1529. if (loop === 'false') {
  1530. params.loop = false;
  1531. } else if (loop === 'true') {
  1532. params.loop = true;
  1533. } else if (loop !== '') {
  1534. params.loop = parseInt(loop, 10);
  1535. }
  1536. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1537. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1538. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value : wrapperAttributes.getNamedItem('bm-autoplay') ? wrapperAttributes.getNamedItem('bm-autoplay').value : true;
  1539. params.autoplay = autoplay !== 'false';
  1540. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1541. ? wrapperAttributes.getNamedItem('data-name').value : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1542. ? wrapperAttributes.getNamedItem('data-bm-name').value : wrapperAttributes.getNamedItem('bm-name') ? wrapperAttributes.getNamedItem('bm-name').value : '';
  1543. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1544. ? wrapperAttributes.getNamedItem('data-anim-prerender').value : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1545. ? wrapperAttributes.getNamedItem('data-bm-prerender').value : wrapperAttributes.getNamedItem('bm-prerender') ? wrapperAttributes.getNamedItem('bm-prerender').value : '';
  1546. if (prerender === 'false') {
  1547. params.prerender = false;
  1548. }
  1549. if (!params.path) {
  1550. this.trigger('destroy');
  1551. } else {
  1552. this.setParams(params);
  1553. }
  1554. };
  1555. AnimationItem.prototype.includeLayers = function (data) {
  1556. if (data.op > this.animationData.op) {
  1557. this.animationData.op = data.op;
  1558. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1559. }
  1560. var layers = this.animationData.layers;
  1561. var i;
  1562. var len = layers.length;
  1563. var newLayers = data.layers;
  1564. var j;
  1565. var jLen = newLayers.length;
  1566. for (j = 0; j < jLen; j += 1) {
  1567. i = 0;
  1568. while (i < len) {
  1569. if (layers[i].id === newLayers[j].id) {
  1570. layers[i] = newLayers[j];
  1571. break;
  1572. }
  1573. i += 1;
  1574. }
  1575. }
  1576. if (data.chars || data.fonts) {
  1577. this.renderer.globalData.fontManager.addChars(data.chars);
  1578. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1579. }
  1580. if (data.assets) {
  1581. len = data.assets.length;
  1582. for (i = 0; i < len; i += 1) {
  1583. this.animationData.assets.push(data.assets[i]);
  1584. }
  1585. }
  1586. this.animationData.__complete = false;
  1587. dataManager.completeAnimation(this.animationData, this.onSegmentComplete);
  1588. };
  1589. AnimationItem.prototype.onSegmentComplete = function (data) {
  1590. this.animationData = data;
  1591. var expressionsPlugin = getExpressionsPlugin();
  1592. if (expressionsPlugin) {
  1593. expressionsPlugin.initExpressions(this);
  1594. }
  1595. this.loadNextSegment();
  1596. };
  1597. AnimationItem.prototype.loadNextSegment = function () {
  1598. var segments = this.animationData.segments;
  1599. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1600. this.trigger('data_ready');
  1601. this.timeCompleted = this.totalFrames;
  1602. return;
  1603. }
  1604. var segment = segments.shift();
  1605. this.timeCompleted = segment.time * this.frameRate;
  1606. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1607. this.segmentPos += 1;
  1608. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1609. this.trigger('data_failed');
  1610. }.bind(this));
  1611. };
  1612. AnimationItem.prototype.loadSegments = function () {
  1613. var segments = this.animationData.segments;
  1614. if (!segments) {
  1615. this.timeCompleted = this.totalFrames;
  1616. }
  1617. this.loadNextSegment();
  1618. };
  1619. AnimationItem.prototype.imagesLoaded = function () {
  1620. this.trigger('loaded_images');
  1621. this.checkLoaded();
  1622. };
  1623. AnimationItem.prototype.preloadImages = function () {
  1624. this.imagePreloader.setAssetsPath(this.assetsPath);
  1625. this.imagePreloader.setPath(this.path);
  1626. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1627. };
  1628. AnimationItem.prototype.configAnimation = function (animData) {
  1629. if (!this.renderer) {
  1630. return;
  1631. }
  1632. try {
  1633. this.animationData = animData;
  1634. if (this.initialSegment) {
  1635. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1636. this.firstFrame = Math.round(this.initialSegment[0]);
  1637. } else {
  1638. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1639. this.firstFrame = Math.round(this.animationData.ip);
  1640. }
  1641. this.renderer.configAnimation(animData);
  1642. if (!animData.assets) {
  1643. animData.assets = [];
  1644. }
  1645. this.assets = this.animationData.assets;
  1646. this.frameRate = this.animationData.fr;
  1647. this.frameMult = this.animationData.fr / 1000;
  1648. this.renderer.searchExtraCompositions(animData.assets);
  1649. this.markers = markerParser(animData.markers || []);
  1650. this.trigger('config_ready');
  1651. this.preloadImages();
  1652. this.loadSegments();
  1653. this.updaFrameModifier();
  1654. this.waitForFontsLoaded();
  1655. if (this.isPaused) {
  1656. this.audioController.pause();
  1657. }
  1658. } catch (error) {
  1659. this.triggerConfigError(error);
  1660. }
  1661. };
  1662. AnimationItem.prototype.waitForFontsLoaded = function () {
  1663. if (!this.renderer) {
  1664. return;
  1665. }
  1666. if (this.renderer.globalData.fontManager.isLoaded) {
  1667. this.checkLoaded();
  1668. } else {
  1669. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1670. }
  1671. };
  1672. AnimationItem.prototype.checkLoaded = function () {
  1673. if (!this.isLoaded && this.renderer.globalData.fontManager.isLoaded && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas') && this.imagePreloader.loadedFootages()) {
  1674. this.isLoaded = true;
  1675. var expressionsPlugin = getExpressionsPlugin();
  1676. if (expressionsPlugin) {
  1677. expressionsPlugin.initExpressions(this);
  1678. }
  1679. this.renderer.initItems();
  1680. setTimeout(function () {
  1681. this.trigger('DOMLoaded');
  1682. }.bind(this), 0);
  1683. this.gotoFrame();
  1684. if (this.autoplay) {
  1685. this.play();
  1686. }
  1687. }
  1688. };
  1689. AnimationItem.prototype.resize = function (width, height) {
  1690. // Adding this validation for backwards compatibility in case an event object was being passed down
  1691. var _width = typeof width === 'number' ? width : undefined;
  1692. var _height = typeof height === 'number' ? height : undefined;
  1693. this.renderer.updateContainerSize(_width, _height);
  1694. };
  1695. AnimationItem.prototype.setSubframe = function (flag) {
  1696. this.isSubframeEnabled = !!flag;
  1697. };
  1698. AnimationItem.prototype.gotoFrame = function () {
  1699. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1700. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1701. this.currentFrame = this.timeCompleted;
  1702. }
  1703. this.trigger('enterFrame');
  1704. this.renderFrame();
  1705. this.trigger('drawnFrame');
  1706. };
  1707. AnimationItem.prototype.renderFrame = function () {
  1708. if (this.isLoaded === false || !this.renderer) {
  1709. return;
  1710. }
  1711. try {
  1712. if (this.expressionsPlugin) {
  1713. this.expressionsPlugin.resetFrame();
  1714. }
  1715. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1716. } catch (error) {
  1717. this.triggerRenderFrameError(error);
  1718. }
  1719. };
  1720. AnimationItem.prototype.play = function (name) {
  1721. if (name && this.name !== name) {
  1722. return;
  1723. }
  1724. if (this.isPaused === true) {
  1725. this.isPaused = false;
  1726. this.trigger('_play');
  1727. this.audioController.resume();
  1728. if (this._idle) {
  1729. this._idle = false;
  1730. this.trigger('_active');
  1731. }
  1732. }
  1733. };
  1734. AnimationItem.prototype.pause = function (name) {
  1735. if (name && this.name !== name) {
  1736. return;
  1737. }
  1738. if (this.isPaused === false) {
  1739. this.isPaused = true;
  1740. this.trigger('_pause');
  1741. this._idle = true;
  1742. this.trigger('_idle');
  1743. this.audioController.pause();
  1744. }
  1745. };
  1746. AnimationItem.prototype.togglePause = function (name) {
  1747. if (name && this.name !== name) {
  1748. return;
  1749. }
  1750. if (this.isPaused === true) {
  1751. this.play();
  1752. } else {
  1753. this.pause();
  1754. }
  1755. };
  1756. AnimationItem.prototype.stop = function (name) {
  1757. if (name && this.name !== name) {
  1758. return;
  1759. }
  1760. this.pause();
  1761. this.playCount = 0;
  1762. this._completedLoop = false;
  1763. this.setCurrentRawFrameValue(0);
  1764. };
  1765. AnimationItem.prototype.getMarkerData = function (markerName) {
  1766. var marker;
  1767. for (var i = 0; i < this.markers.length; i += 1) {
  1768. marker = this.markers[i];
  1769. if (marker.payload && marker.payload.name === markerName) {
  1770. return marker;
  1771. }
  1772. }
  1773. return null;
  1774. };
  1775. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1776. if (name && this.name !== name) {
  1777. return;
  1778. }
  1779. var numValue = Number(value);
  1780. if (isNaN(numValue)) {
  1781. var marker = this.getMarkerData(value);
  1782. if (marker) {
  1783. this.goToAndStop(marker.time, true);
  1784. }
  1785. } else if (isFrame) {
  1786. this.setCurrentRawFrameValue(value);
  1787. } else {
  1788. this.setCurrentRawFrameValue(value * this.frameModifier);
  1789. }
  1790. this.pause();
  1791. };
  1792. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1793. if (name && this.name !== name) {
  1794. return;
  1795. }
  1796. var numValue = Number(value);
  1797. if (isNaN(numValue)) {
  1798. var marker = this.getMarkerData(value);
  1799. if (marker) {
  1800. if (!marker.duration) {
  1801. this.goToAndStop(marker.time, true);
  1802. } else {
  1803. this.playSegments([marker.time, marker.time + marker.duration], true);
  1804. }
  1805. }
  1806. } else {
  1807. this.goToAndStop(numValue, isFrame, name);
  1808. }
  1809. this.play();
  1810. };
  1811. AnimationItem.prototype.advanceTime = function (value) {
  1812. if (this.isPaused === true || this.isLoaded === false) {
  1813. return;
  1814. }
  1815. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1816. var _isComplete = false;
  1817. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1818. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1819. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1820. if (!this.loop || this.playCount === this.loop) {
  1821. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1822. _isComplete = true;
  1823. nextValue = this.totalFrames - 1;
  1824. }
  1825. } else if (nextValue >= this.totalFrames) {
  1826. this.playCount += 1;
  1827. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1828. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1829. this._completedLoop = true;
  1830. this.trigger('loopComplete');
  1831. }
  1832. } else {
  1833. this.setCurrentRawFrameValue(nextValue);
  1834. }
  1835. } else if (nextValue < 0) {
  1836. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1837. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) {
  1838. // eslint-disable-line no-plusplus
  1839. this.setCurrentRawFrameValue(this.totalFrames + nextValue % this.totalFrames);
  1840. if (!this._completedLoop) {
  1841. this._completedLoop = true;
  1842. } else {
  1843. this.trigger('loopComplete');
  1844. }
  1845. } else {
  1846. _isComplete = true;
  1847. nextValue = 0;
  1848. }
  1849. }
  1850. } else {
  1851. this.setCurrentRawFrameValue(nextValue);
  1852. }
  1853. if (_isComplete) {
  1854. this.setCurrentRawFrameValue(nextValue);
  1855. this.pause();
  1856. this.trigger('complete');
  1857. }
  1858. };
  1859. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1860. this.playCount = 0;
  1861. if (arr[1] < arr[0]) {
  1862. if (this.frameModifier > 0) {
  1863. if (this.playSpeed < 0) {
  1864. this.setSpeed(-this.playSpeed);
  1865. } else {
  1866. this.setDirection(-1);
  1867. }
  1868. }
  1869. this.totalFrames = arr[0] - arr[1];
  1870. this.timeCompleted = this.totalFrames;
  1871. this.firstFrame = arr[1];
  1872. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1873. } else if (arr[1] > arr[0]) {
  1874. if (this.frameModifier < 0) {
  1875. if (this.playSpeed < 0) {
  1876. this.setSpeed(-this.playSpeed);
  1877. } else {
  1878. this.setDirection(1);
  1879. }
  1880. }
  1881. this.totalFrames = arr[1] - arr[0];
  1882. this.timeCompleted = this.totalFrames;
  1883. this.firstFrame = arr[0];
  1884. this.setCurrentRawFrameValue(0.001 + offset);
  1885. }
  1886. this.trigger('segmentStart');
  1887. };
  1888. AnimationItem.prototype.setSegment = function (init, end) {
  1889. var pendingFrame = -1;
  1890. if (this.isPaused) {
  1891. if (this.currentRawFrame + this.firstFrame < init) {
  1892. pendingFrame = init;
  1893. } else if (this.currentRawFrame + this.firstFrame > end) {
  1894. pendingFrame = end - init;
  1895. }
  1896. }
  1897. this.firstFrame = init;
  1898. this.totalFrames = end - init;
  1899. this.timeCompleted = this.totalFrames;
  1900. if (pendingFrame !== -1) {
  1901. this.goToAndStop(pendingFrame, true);
  1902. }
  1903. };
  1904. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1905. if (forceFlag) {
  1906. this.segments.length = 0;
  1907. }
  1908. if (_typeof$1(arr[0]) === 'object') {
  1909. var i;
  1910. var len = arr.length;
  1911. for (i = 0; i < len; i += 1) {
  1912. this.segments.push(arr[i]);
  1913. }
  1914. } else {
  1915. this.segments.push(arr);
  1916. }
  1917. if (this.segments.length && forceFlag) {
  1918. this.adjustSegment(this.segments.shift(), 0);
  1919. }
  1920. if (this.isPaused) {
  1921. this.play();
  1922. }
  1923. };
  1924. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1925. this.segments.length = 0;
  1926. this.segments.push([this.animationData.ip, this.animationData.op]);
  1927. if (forceFlag) {
  1928. this.checkSegments(0);
  1929. }
  1930. };
  1931. AnimationItem.prototype.checkSegments = function (offset) {
  1932. if (this.segments.length) {
  1933. this.adjustSegment(this.segments.shift(), offset);
  1934. return true;
  1935. }
  1936. return false;
  1937. };
  1938. AnimationItem.prototype.destroy = function (name) {
  1939. if (name && this.name !== name || !this.renderer) {
  1940. return;
  1941. }
  1942. this.renderer.destroy();
  1943. this.imagePreloader.destroy();
  1944. this.trigger('destroy');
  1945. this._cbs = null;
  1946. this.onEnterFrame = null;
  1947. this.onLoopComplete = null;
  1948. this.onComplete = null;
  1949. this.onSegmentStart = null;
  1950. this.onDestroy = null;
  1951. this.renderer = null;
  1952. this.expressionsPlugin = null;
  1953. this.imagePreloader = null;
  1954. this.projectInterface = null;
  1955. };
  1956. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1957. this.currentRawFrame = value;
  1958. this.gotoFrame();
  1959. };
  1960. AnimationItem.prototype.setSpeed = function (val) {
  1961. this.playSpeed = val;
  1962. this.updaFrameModifier();
  1963. };
  1964. AnimationItem.prototype.setDirection = function (val) {
  1965. this.playDirection = val < 0 ? -1 : 1;
  1966. this.updaFrameModifier();
  1967. };
  1968. AnimationItem.prototype.setLoop = function (isLooping) {
  1969. this.loop = isLooping;
  1970. };
  1971. AnimationItem.prototype.setVolume = function (val, name) {
  1972. if (name && this.name !== name) {
  1973. return;
  1974. }
  1975. this.audioController.setVolume(val);
  1976. };
  1977. AnimationItem.prototype.getVolume = function () {
  1978. return this.audioController.getVolume();
  1979. };
  1980. AnimationItem.prototype.mute = function (name) {
  1981. if (name && this.name !== name) {
  1982. return;
  1983. }
  1984. this.audioController.mute();
  1985. };
  1986. AnimationItem.prototype.unmute = function (name) {
  1987. if (name && this.name !== name) {
  1988. return;
  1989. }
  1990. this.audioController.unmute();
  1991. };
  1992. AnimationItem.prototype.updaFrameModifier = function () {
  1993. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1994. this.audioController.setRate(this.playSpeed * this.playDirection);
  1995. };
  1996. AnimationItem.prototype.getPath = function () {
  1997. return this.path;
  1998. };
  1999. AnimationItem.prototype.getAssetsPath = function (assetData) {
  2000. var path = '';
  2001. if (assetData.e) {
  2002. path = assetData.p;
  2003. } else if (this.assetsPath) {
  2004. var imagePath = assetData.p;
  2005. if (imagePath.indexOf('images/') !== -1) {
  2006. imagePath = imagePath.split('/')[1];
  2007. }
  2008. path = this.assetsPath + imagePath;
  2009. } else {
  2010. path = this.path;
  2011. path += assetData.u ? assetData.u : '';
  2012. path += assetData.p;
  2013. }
  2014. return path;
  2015. };
  2016. AnimationItem.prototype.getAssetData = function (id) {
  2017. var i = 0;
  2018. var len = this.assets.length;
  2019. while (i < len) {
  2020. if (id === this.assets[i].id) {
  2021. return this.assets[i];
  2022. }
  2023. i += 1;
  2024. }
  2025. return null;
  2026. };
  2027. AnimationItem.prototype.hide = function () {
  2028. this.renderer.hide();
  2029. };
  2030. AnimationItem.prototype.show = function () {
  2031. this.renderer.show();
  2032. };
  2033. AnimationItem.prototype.getDuration = function (isFrame) {
  2034. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  2035. };
  2036. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  2037. try {
  2038. var element = this.renderer.getElementByPath(path);
  2039. element.updateDocumentData(documentData, index);
  2040. } catch (error) {
  2041. // TODO: decide how to handle catch case
  2042. }
  2043. };
  2044. AnimationItem.prototype.trigger = function (name) {
  2045. if (this._cbs && this._cbs[name]) {
  2046. switch (name) {
  2047. case 'enterFrame':
  2048. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  2049. break;
  2050. case 'drawnFrame':
  2051. this.drawnFrameEvent.currentTime = this.currentFrame;
  2052. this.drawnFrameEvent.totalTime = this.totalFrames;
  2053. this.drawnFrameEvent.direction = this.frameModifier;
  2054. this.triggerEvent(name, this.drawnFrameEvent);
  2055. break;
  2056. case 'loopComplete':
  2057. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2058. break;
  2059. case 'complete':
  2060. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  2061. break;
  2062. case 'segmentStart':
  2063. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2064. break;
  2065. case 'destroy':
  2066. this.triggerEvent(name, new BMDestroyEvent(name, this));
  2067. break;
  2068. default:
  2069. this.triggerEvent(name);
  2070. }
  2071. }
  2072. if (name === 'enterFrame' && this.onEnterFrame) {
  2073. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  2074. }
  2075. if (name === 'loopComplete' && this.onLoopComplete) {
  2076. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2077. }
  2078. if (name === 'complete' && this.onComplete) {
  2079. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  2080. }
  2081. if (name === 'segmentStart' && this.onSegmentStart) {
  2082. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2083. }
  2084. if (name === 'destroy' && this.onDestroy) {
  2085. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  2086. }
  2087. };
  2088. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  2089. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2090. this.triggerEvent('error', error);
  2091. if (this.onError) {
  2092. this.onError.call(this, error);
  2093. }
  2094. };
  2095. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2096. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2097. this.triggerEvent('error', error);
  2098. if (this.onError) {
  2099. this.onError.call(this, error);
  2100. }
  2101. };
  2102. var animationManager = function () {
  2103. var moduleOb = {};
  2104. var registeredAnimations = [];
  2105. var initTime = 0;
  2106. var len = 0;
  2107. var playingAnimationsNum = 0;
  2108. var _stopped = true;
  2109. var _isFrozen = false;
  2110. function removeElement(ev) {
  2111. var i = 0;
  2112. var animItem = ev.target;
  2113. while (i < len) {
  2114. if (registeredAnimations[i].animation === animItem) {
  2115. registeredAnimations.splice(i, 1);
  2116. i -= 1;
  2117. len -= 1;
  2118. if (!animItem.isPaused) {
  2119. subtractPlayingCount();
  2120. }
  2121. }
  2122. i += 1;
  2123. }
  2124. }
  2125. function registerAnimation(element, animationData) {
  2126. if (!element) {
  2127. return null;
  2128. }
  2129. var i = 0;
  2130. while (i < len) {
  2131. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2132. return registeredAnimations[i].animation;
  2133. }
  2134. i += 1;
  2135. }
  2136. var animItem = new AnimationItem();
  2137. setupAnimation(animItem, element);
  2138. animItem.setData(element, animationData);
  2139. return animItem;
  2140. }
  2141. function getRegisteredAnimations() {
  2142. var i;
  2143. var lenAnims = registeredAnimations.length;
  2144. var animations = [];
  2145. for (i = 0; i < lenAnims; i += 1) {
  2146. animations.push(registeredAnimations[i].animation);
  2147. }
  2148. return animations;
  2149. }
  2150. function addPlayingCount() {
  2151. playingAnimationsNum += 1;
  2152. activate();
  2153. }
  2154. function subtractPlayingCount() {
  2155. playingAnimationsNum -= 1;
  2156. }
  2157. function setupAnimation(animItem, element) {
  2158. animItem.addEventListener('destroy', removeElement);
  2159. animItem.addEventListener('_active', addPlayingCount);
  2160. animItem.addEventListener('_idle', subtractPlayingCount);
  2161. registeredAnimations.push({
  2162. elem: element,
  2163. animation: animItem
  2164. });
  2165. len += 1;
  2166. }
  2167. function loadAnimation(params) {
  2168. var animItem = new AnimationItem();
  2169. setupAnimation(animItem, null);
  2170. animItem.setParams(params);
  2171. return animItem;
  2172. }
  2173. function setSpeed(val, animation) {
  2174. var i;
  2175. for (i = 0; i < len; i += 1) {
  2176. registeredAnimations[i].animation.setSpeed(val, animation);
  2177. }
  2178. }
  2179. function setDirection(val, animation) {
  2180. var i;
  2181. for (i = 0; i < len; i += 1) {
  2182. registeredAnimations[i].animation.setDirection(val, animation);
  2183. }
  2184. }
  2185. function play(animation) {
  2186. var i;
  2187. for (i = 0; i < len; i += 1) {
  2188. registeredAnimations[i].animation.play(animation);
  2189. }
  2190. }
  2191. function resume(nowTime) {
  2192. var elapsedTime = nowTime - initTime;
  2193. var i;
  2194. for (i = 0; i < len; i += 1) {
  2195. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2196. }
  2197. initTime = nowTime;
  2198. if (playingAnimationsNum && !_isFrozen) {
  2199. window.requestAnimationFrame(resume);
  2200. } else {
  2201. _stopped = true;
  2202. }
  2203. }
  2204. function first(nowTime) {
  2205. initTime = nowTime;
  2206. window.requestAnimationFrame(resume);
  2207. }
  2208. function pause(animation) {
  2209. var i;
  2210. for (i = 0; i < len; i += 1) {
  2211. registeredAnimations[i].animation.pause(animation);
  2212. }
  2213. }
  2214. function goToAndStop(value, isFrame, animation) {
  2215. var i;
  2216. for (i = 0; i < len; i += 1) {
  2217. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2218. }
  2219. }
  2220. function stop(animation) {
  2221. var i;
  2222. for (i = 0; i < len; i += 1) {
  2223. registeredAnimations[i].animation.stop(animation);
  2224. }
  2225. }
  2226. function togglePause(animation) {
  2227. var i;
  2228. for (i = 0; i < len; i += 1) {
  2229. registeredAnimations[i].animation.togglePause(animation);
  2230. }
  2231. }
  2232. function destroy(animation) {
  2233. var i;
  2234. for (i = len - 1; i >= 0; i -= 1) {
  2235. registeredAnimations[i].animation.destroy(animation);
  2236. }
  2237. }
  2238. function searchAnimations(animationData, standalone, renderer) {
  2239. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')), [].slice.call(document.getElementsByClassName('bodymovin')));
  2240. var i;
  2241. var lenAnims = animElements.length;
  2242. for (i = 0; i < lenAnims; i += 1) {
  2243. if (renderer) {
  2244. animElements[i].setAttribute('data-bm-type', renderer);
  2245. }
  2246. registerAnimation(animElements[i], animationData);
  2247. }
  2248. if (standalone && lenAnims === 0) {
  2249. if (!renderer) {
  2250. renderer = 'svg';
  2251. }
  2252. var body = document.getElementsByTagName('body')[0];
  2253. body.innerText = '';
  2254. var div = createTag('div');
  2255. div.style.width = '100%';
  2256. div.style.height = '100%';
  2257. div.setAttribute('data-bm-type', renderer);
  2258. body.appendChild(div);
  2259. registerAnimation(div, animationData);
  2260. }
  2261. }
  2262. function resize() {
  2263. var i;
  2264. for (i = 0; i < len; i += 1) {
  2265. registeredAnimations[i].animation.resize();
  2266. }
  2267. }
  2268. function activate() {
  2269. if (!_isFrozen && playingAnimationsNum) {
  2270. if (_stopped) {
  2271. window.requestAnimationFrame(first);
  2272. _stopped = false;
  2273. }
  2274. }
  2275. }
  2276. function freeze() {
  2277. _isFrozen = true;
  2278. }
  2279. function unfreeze() {
  2280. _isFrozen = false;
  2281. activate();
  2282. }
  2283. function setVolume(val, animation) {
  2284. var i;
  2285. for (i = 0; i < len; i += 1) {
  2286. registeredAnimations[i].animation.setVolume(val, animation);
  2287. }
  2288. }
  2289. function mute(animation) {
  2290. var i;
  2291. for (i = 0; i < len; i += 1) {
  2292. registeredAnimations[i].animation.mute(animation);
  2293. }
  2294. }
  2295. function unmute(animation) {
  2296. var i;
  2297. for (i = 0; i < len; i += 1) {
  2298. registeredAnimations[i].animation.unmute(animation);
  2299. }
  2300. }
  2301. moduleOb.registerAnimation = registerAnimation;
  2302. moduleOb.loadAnimation = loadAnimation;
  2303. moduleOb.setSpeed = setSpeed;
  2304. moduleOb.setDirection = setDirection;
  2305. moduleOb.play = play;
  2306. moduleOb.pause = pause;
  2307. moduleOb.stop = stop;
  2308. moduleOb.togglePause = togglePause;
  2309. moduleOb.searchAnimations = searchAnimations;
  2310. moduleOb.resize = resize;
  2311. // moduleOb.start = start;
  2312. moduleOb.goToAndStop = goToAndStop;
  2313. moduleOb.destroy = destroy;
  2314. moduleOb.freeze = freeze;
  2315. moduleOb.unfreeze = unfreeze;
  2316. moduleOb.setVolume = setVolume;
  2317. moduleOb.mute = mute;
  2318. moduleOb.unmute = unmute;
  2319. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2320. return moduleOb;
  2321. }();
  2322. /* eslint-disable */
  2323. var BezierFactory = function () {
  2324. /**
  2325. * BezierEasing - use bezier curve for transition easing function
  2326. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2327. *
  2328. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2329. * Usage:
  2330. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2331. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2332. *
  2333. */
  2334. var ob = {};
  2335. ob.getBezierEasing = getBezierEasing;
  2336. var beziers = {};
  2337. function getBezierEasing(a, b, c, d, nm) {
  2338. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2339. if (beziers[str]) {
  2340. return beziers[str];
  2341. }
  2342. var bezEasing = new BezierEasing([a, b, c, d]);
  2343. beziers[str] = bezEasing;
  2344. return bezEasing;
  2345. }
  2346. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2347. var NEWTON_ITERATIONS = 4;
  2348. var NEWTON_MIN_SLOPE = 0.001;
  2349. var SUBDIVISION_PRECISION = 0.0000001;
  2350. var SUBDIVISION_MAX_ITERATIONS = 10;
  2351. var kSplineTableSize = 11;
  2352. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2353. var float32ArraySupported = typeof Float32Array === 'function';
  2354. function A(aA1, aA2) {
  2355. return 1.0 - 3.0 * aA2 + 3.0 * aA1;
  2356. }
  2357. function B(aA1, aA2) {
  2358. return 3.0 * aA2 - 6.0 * aA1;
  2359. }
  2360. function C(aA1) {
  2361. return 3.0 * aA1;
  2362. }
  2363. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2364. function calcBezier(aT, aA1, aA2) {
  2365. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2366. }
  2367. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2368. function getSlope(aT, aA1, aA2) {
  2369. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2370. }
  2371. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2372. var currentX,
  2373. currentT,
  2374. i = 0;
  2375. do {
  2376. currentT = aA + (aB - aA) / 2.0;
  2377. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2378. if (currentX > 0.0) {
  2379. aB = currentT;
  2380. } else {
  2381. aA = currentT;
  2382. }
  2383. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2384. return currentT;
  2385. }
  2386. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2387. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2388. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2389. if (currentSlope === 0.0) return aGuessT;
  2390. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2391. aGuessT -= currentX / currentSlope;
  2392. }
  2393. return aGuessT;
  2394. }
  2395. /**
  2396. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2397. */
  2398. function BezierEasing(points) {
  2399. this._p = points;
  2400. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2401. this._precomputed = false;
  2402. this.get = this.get.bind(this);
  2403. }
  2404. BezierEasing.prototype = {
  2405. get: function get(x) {
  2406. var mX1 = this._p[0],
  2407. mY1 = this._p[1],
  2408. mX2 = this._p[2],
  2409. mY2 = this._p[3];
  2410. if (!this._precomputed) this._precompute();
  2411. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2412. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2413. if (x === 0) return 0;
  2414. if (x === 1) return 1;
  2415. return calcBezier(this._getTForX(x), mY1, mY2);
  2416. },
  2417. // Private part
  2418. _precompute: function _precompute() {
  2419. var mX1 = this._p[0],
  2420. mY1 = this._p[1],
  2421. mX2 = this._p[2],
  2422. mY2 = this._p[3];
  2423. this._precomputed = true;
  2424. if (mX1 !== mY1 || mX2 !== mY2) {
  2425. this._calcSampleValues();
  2426. }
  2427. },
  2428. _calcSampleValues: function _calcSampleValues() {
  2429. var mX1 = this._p[0],
  2430. mX2 = this._p[2];
  2431. for (var i = 0; i < kSplineTableSize; ++i) {
  2432. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2433. }
  2434. },
  2435. /**
  2436. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2437. */
  2438. _getTForX: function _getTForX(aX) {
  2439. var mX1 = this._p[0],
  2440. mX2 = this._p[2],
  2441. mSampleValues = this._mSampleValues;
  2442. var intervalStart = 0.0;
  2443. var currentSample = 1;
  2444. var lastSample = kSplineTableSize - 1;
  2445. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2446. intervalStart += kSampleStepSize;
  2447. }
  2448. --currentSample;
  2449. // Interpolate to provide an initial guess for t
  2450. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2451. var guessForT = intervalStart + dist * kSampleStepSize;
  2452. var initialSlope = getSlope(guessForT, mX1, mX2);
  2453. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2454. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2455. }
  2456. if (initialSlope === 0.0) {
  2457. return guessForT;
  2458. }
  2459. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2460. }
  2461. };
  2462. return ob;
  2463. }();
  2464. var pooling = function () {
  2465. function _double(arr) {
  2466. return arr.concat(createSizedArray(arr.length));
  2467. }
  2468. return {
  2469. "double": _double
  2470. };
  2471. }();
  2472. var poolFactory = function () {
  2473. return function (initialLength, _create, _release) {
  2474. var _length = 0;
  2475. var _maxLength = initialLength;
  2476. var pool = createSizedArray(_maxLength);
  2477. var ob = {
  2478. newElement: newElement,
  2479. release: release
  2480. };
  2481. function newElement() {
  2482. var element;
  2483. if (_length) {
  2484. _length -= 1;
  2485. element = pool[_length];
  2486. } else {
  2487. element = _create();
  2488. }
  2489. return element;
  2490. }
  2491. function release(element) {
  2492. if (_length === _maxLength) {
  2493. pool = pooling["double"](pool);
  2494. _maxLength *= 2;
  2495. }
  2496. if (_release) {
  2497. _release(element);
  2498. }
  2499. pool[_length] = element;
  2500. _length += 1;
  2501. }
  2502. return ob;
  2503. };
  2504. }();
  2505. var bezierLengthPool = function () {
  2506. function create() {
  2507. return {
  2508. addedLength: 0,
  2509. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2510. lengths: createTypedArray('float32', getDefaultCurveSegments())
  2511. };
  2512. }
  2513. return poolFactory(8, create);
  2514. }();
  2515. var segmentsLengthPool = function () {
  2516. function create() {
  2517. return {
  2518. lengths: [],
  2519. totalLength: 0
  2520. };
  2521. }
  2522. function release(element) {
  2523. var i;
  2524. var len = element.lengths.length;
  2525. for (i = 0; i < len; i += 1) {
  2526. bezierLengthPool.release(element.lengths[i]);
  2527. }
  2528. element.lengths.length = 0;
  2529. }
  2530. return poolFactory(8, create, release);
  2531. }();
  2532. function bezFunction() {
  2533. var math = Math;
  2534. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2535. var det1 = x1 * y2 + y1 * x3 + x2 * y3 - x3 * y2 - y3 * x1 - x2 * y1;
  2536. return det1 > -0.001 && det1 < 0.001;
  2537. }
  2538. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2539. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2540. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2541. }
  2542. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2543. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2544. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2545. var diffDist;
  2546. if (dist1 > dist2) {
  2547. if (dist1 > dist3) {
  2548. diffDist = dist1 - dist2 - dist3;
  2549. } else {
  2550. diffDist = dist3 - dist2 - dist1;
  2551. }
  2552. } else if (dist3 > dist2) {
  2553. diffDist = dist3 - dist2 - dist1;
  2554. } else {
  2555. diffDist = dist2 - dist1 - dist3;
  2556. }
  2557. return diffDist > -0.0001 && diffDist < 0.0001;
  2558. }
  2559. var getBezierLength = function () {
  2560. return function (pt1, pt2, pt3, pt4) {
  2561. var curveSegments = getDefaultCurveSegments();
  2562. var k;
  2563. var i;
  2564. var len;
  2565. var ptCoord;
  2566. var perc;
  2567. var addedLength = 0;
  2568. var ptDistance;
  2569. var point = [];
  2570. var lastPoint = [];
  2571. var lengthData = bezierLengthPool.newElement();
  2572. len = pt3.length;
  2573. for (k = 0; k < curveSegments; k += 1) {
  2574. perc = k / (curveSegments - 1);
  2575. ptDistance = 0;
  2576. for (i = 0; i < len; i += 1) {
  2577. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * pt3[i] + 3 * (1 - perc) * bmPow(perc, 2) * pt4[i] + bmPow(perc, 3) * pt2[i];
  2578. point[i] = ptCoord;
  2579. if (lastPoint[i] !== null) {
  2580. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2581. }
  2582. lastPoint[i] = point[i];
  2583. }
  2584. if (ptDistance) {
  2585. ptDistance = bmSqrt(ptDistance);
  2586. addedLength += ptDistance;
  2587. }
  2588. lengthData.percents[k] = perc;
  2589. lengthData.lengths[k] = addedLength;
  2590. }
  2591. lengthData.addedLength = addedLength;
  2592. return lengthData;
  2593. };
  2594. }();
  2595. function getSegmentsLength(shapeData) {
  2596. var segmentsLength = segmentsLengthPool.newElement();
  2597. var closed = shapeData.c;
  2598. var pathV = shapeData.v;
  2599. var pathO = shapeData.o;
  2600. var pathI = shapeData.i;
  2601. var i;
  2602. var len = shapeData._length;
  2603. var lengths = segmentsLength.lengths;
  2604. var totalLength = 0;
  2605. for (i = 0; i < len - 1; i += 1) {
  2606. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2607. totalLength += lengths[i].addedLength;
  2608. }
  2609. if (closed && len) {
  2610. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2611. totalLength += lengths[i].addedLength;
  2612. }
  2613. segmentsLength.totalLength = totalLength;
  2614. return segmentsLength;
  2615. }
  2616. function BezierData(length) {
  2617. this.segmentLength = 0;
  2618. this.points = new Array(length);
  2619. }
  2620. function PointData(partial, point) {
  2621. this.partialLength = partial;
  2622. this.point = point;
  2623. }
  2624. var buildBezierData = function () {
  2625. var storedData = {};
  2626. return function (pt1, pt2, pt3, pt4) {
  2627. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2628. if (!storedData[bezierName]) {
  2629. var curveSegments = getDefaultCurveSegments();
  2630. var k;
  2631. var i;
  2632. var len;
  2633. var ptCoord;
  2634. var perc;
  2635. var addedLength = 0;
  2636. var ptDistance;
  2637. var point;
  2638. var lastPoint = null;
  2639. 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])) {
  2640. curveSegments = 2;
  2641. }
  2642. var bezierData = new BezierData(curveSegments);
  2643. len = pt3.length;
  2644. for (k = 0; k < curveSegments; k += 1) {
  2645. point = createSizedArray(len);
  2646. perc = k / (curveSegments - 1);
  2647. ptDistance = 0;
  2648. for (i = 0; i < len; i += 1) {
  2649. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * (pt1[i] + pt3[i]) + 3 * (1 - perc) * bmPow(perc, 2) * (pt2[i] + pt4[i]) + bmPow(perc, 3) * pt2[i];
  2650. point[i] = ptCoord;
  2651. if (lastPoint !== null) {
  2652. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2653. }
  2654. }
  2655. ptDistance = bmSqrt(ptDistance);
  2656. addedLength += ptDistance;
  2657. bezierData.points[k] = new PointData(ptDistance, point);
  2658. lastPoint = point;
  2659. }
  2660. bezierData.segmentLength = addedLength;
  2661. storedData[bezierName] = bezierData;
  2662. }
  2663. return storedData[bezierName];
  2664. };
  2665. }();
  2666. function getDistancePerc(perc, bezierData) {
  2667. var percents = bezierData.percents;
  2668. var lengths = bezierData.lengths;
  2669. var len = percents.length;
  2670. var initPos = bmFloor((len - 1) * perc);
  2671. var lengthPos = perc * bezierData.addedLength;
  2672. var lPerc = 0;
  2673. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2674. return percents[initPos];
  2675. }
  2676. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2677. var flag = true;
  2678. while (flag) {
  2679. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2680. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2681. flag = false;
  2682. } else {
  2683. initPos += dir;
  2684. }
  2685. if (initPos < 0 || initPos >= len - 1) {
  2686. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2687. if (initPos === len - 1) {
  2688. return percents[initPos];
  2689. }
  2690. flag = false;
  2691. }
  2692. }
  2693. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2694. }
  2695. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2696. var t1 = getDistancePerc(percent, bezierData);
  2697. var u1 = 1 - t1;
  2698. 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;
  2699. 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;
  2700. return [ptX, ptY];
  2701. }
  2702. var bezierSegmentPoints = createTypedArray('float32', 8);
  2703. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2704. if (startPerc < 0) {
  2705. startPerc = 0;
  2706. } else if (startPerc > 1) {
  2707. startPerc = 1;
  2708. }
  2709. var t0 = getDistancePerc(startPerc, bezierData);
  2710. endPerc = endPerc > 1 ? 1 : endPerc;
  2711. var t1 = getDistancePerc(endPerc, bezierData);
  2712. var i;
  2713. var len = pt1.length;
  2714. var u0 = 1 - t0;
  2715. var u1 = 1 - t1;
  2716. var u0u0u0 = u0 * u0 * u0;
  2717. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2718. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2719. var t0t0t0 = t0 * t0 * t0;
  2720. //
  2721. var u0u0u1 = u0 * u0 * u1;
  2722. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2723. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2724. var t0t0t1 = t0 * t0 * t1;
  2725. //
  2726. var u0u1u1 = u0 * u1 * u1;
  2727. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2728. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2729. var t0t1t1 = t0 * t1 * t1;
  2730. //
  2731. var u1u1u1 = u1 * u1 * u1;
  2732. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2733. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2734. var t1t1t1 = t1 * t1 * t1;
  2735. for (i = 0; i < len; i += 1) {
  2736. bezierSegmentPoints[i * 4] = math.round((u0u0u0 * pt1[i] + t0u0u0_3 * pt3[i] + t0t0u0_3 * pt4[i] + t0t0t0 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2737. bezierSegmentPoints[i * 4 + 1] = math.round((u0u0u1 * pt1[i] + t0u0u1_3 * pt3[i] + t0t0u1_3 * pt4[i] + t0t0t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2738. bezierSegmentPoints[i * 4 + 2] = math.round((u0u1u1 * pt1[i] + t0u1u1_3 * pt3[i] + t0t1u1_3 * pt4[i] + t0t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2739. bezierSegmentPoints[i * 4 + 3] = math.round((u1u1u1 * pt1[i] + t1u1u1_3 * pt3[i] + t1t1u1_3 * pt4[i] + t1t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2740. }
  2741. return bezierSegmentPoints;
  2742. }
  2743. return {
  2744. getSegmentsLength: getSegmentsLength,
  2745. getNewSegment: getNewSegment,
  2746. getPointInSegment: getPointInSegment,
  2747. buildBezierData: buildBezierData,
  2748. pointOnLine2D: pointOnLine2D,
  2749. pointOnLine3D: pointOnLine3D
  2750. };
  2751. }
  2752. var bez = bezFunction();
  2753. var initFrame = initialDefaultFrame;
  2754. var mathAbs = Math.abs;
  2755. function interpolateValue(frameNum, caching) {
  2756. var offsetTime = this.offsetTime;
  2757. var newValue;
  2758. if (this.propType === 'multidimensional') {
  2759. newValue = createTypedArray('float32', this.pv.length);
  2760. }
  2761. var iterationIndex = caching.lastIndex;
  2762. var i = iterationIndex;
  2763. var len = this.keyframes.length - 1;
  2764. var flag = true;
  2765. var keyData;
  2766. var nextKeyData;
  2767. var keyframeMetadata;
  2768. while (flag) {
  2769. keyData = this.keyframes[i];
  2770. nextKeyData = this.keyframes[i + 1];
  2771. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2772. if (keyData.h) {
  2773. keyData = nextKeyData;
  2774. }
  2775. iterationIndex = 0;
  2776. break;
  2777. }
  2778. if (nextKeyData.t - offsetTime > frameNum) {
  2779. iterationIndex = i;
  2780. break;
  2781. }
  2782. if (i < len - 1) {
  2783. i += 1;
  2784. } else {
  2785. iterationIndex = 0;
  2786. flag = false;
  2787. }
  2788. }
  2789. keyframeMetadata = this.keyframesMetadata[i] || {};
  2790. var k;
  2791. var kLen;
  2792. var perc;
  2793. var jLen;
  2794. var j;
  2795. var fnc;
  2796. var nextKeyTime = nextKeyData.t - offsetTime;
  2797. var keyTime = keyData.t - offsetTime;
  2798. var endValue;
  2799. if (keyData.to) {
  2800. if (!keyframeMetadata.bezierData) {
  2801. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2802. }
  2803. var bezierData = keyframeMetadata.bezierData;
  2804. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2805. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2806. kLen = bezierData.points[ind].point.length;
  2807. for (k = 0; k < kLen; k += 1) {
  2808. newValue[k] = bezierData.points[ind].point[k];
  2809. }
  2810. // caching._lastKeyframeIndex = -1;
  2811. } else {
  2812. if (keyframeMetadata.__fnct) {
  2813. fnc = keyframeMetadata.__fnct;
  2814. } else {
  2815. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2816. keyframeMetadata.__fnct = fnc;
  2817. }
  2818. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2819. var distanceInLine = bezierData.segmentLength * perc;
  2820. var segmentPerc;
  2821. var addedLength = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastAddedLength : 0;
  2822. j = caching.lastFrame < frameNum && caching._lastKeyframeIndex === i ? caching._lastPoint : 0;
  2823. flag = true;
  2824. jLen = bezierData.points.length;
  2825. while (flag) {
  2826. addedLength += bezierData.points[j].partialLength;
  2827. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2828. kLen = bezierData.points[j].point.length;
  2829. for (k = 0; k < kLen; k += 1) {
  2830. newValue[k] = bezierData.points[j].point[k];
  2831. }
  2832. break;
  2833. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2834. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2835. kLen = bezierData.points[j].point.length;
  2836. for (k = 0; k < kLen; k += 1) {
  2837. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2838. }
  2839. break;
  2840. }
  2841. if (j < jLen - 1) {
  2842. j += 1;
  2843. } else {
  2844. flag = false;
  2845. }
  2846. }
  2847. caching._lastPoint = j;
  2848. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2849. caching._lastKeyframeIndex = i;
  2850. }
  2851. } else {
  2852. var outX;
  2853. var outY;
  2854. var inX;
  2855. var inY;
  2856. var keyValue;
  2857. len = keyData.s.length;
  2858. endValue = nextKeyData.s || keyData.e;
  2859. if (this.sh && keyData.h !== 1) {
  2860. if (frameNum >= nextKeyTime) {
  2861. newValue[0] = endValue[0];
  2862. newValue[1] = endValue[1];
  2863. newValue[2] = endValue[2];
  2864. } else if (frameNum <= keyTime) {
  2865. newValue[0] = keyData.s[0];
  2866. newValue[1] = keyData.s[1];
  2867. newValue[2] = keyData.s[2];
  2868. } else {
  2869. var quatStart = createQuaternion(keyData.s);
  2870. var quatEnd = createQuaternion(endValue);
  2871. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2872. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2873. }
  2874. } else {
  2875. for (i = 0; i < len; i += 1) {
  2876. if (keyData.h !== 1) {
  2877. if (frameNum >= nextKeyTime) {
  2878. perc = 1;
  2879. } else if (frameNum < keyTime) {
  2880. perc = 0;
  2881. } else {
  2882. if (keyData.o.x.constructor === Array) {
  2883. if (!keyframeMetadata.__fnct) {
  2884. keyframeMetadata.__fnct = [];
  2885. }
  2886. if (!keyframeMetadata.__fnct[i]) {
  2887. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2888. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2889. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2890. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2891. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2892. keyframeMetadata.__fnct[i] = fnc;
  2893. } else {
  2894. fnc = keyframeMetadata.__fnct[i];
  2895. }
  2896. } else if (!keyframeMetadata.__fnct) {
  2897. outX = keyData.o.x;
  2898. outY = keyData.o.y;
  2899. inX = keyData.i.x;
  2900. inY = keyData.i.y;
  2901. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2902. keyData.keyframeMetadata = fnc;
  2903. } else {
  2904. fnc = keyframeMetadata.__fnct;
  2905. }
  2906. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2907. }
  2908. }
  2909. endValue = nextKeyData.s || keyData.e;
  2910. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2911. if (this.propType === 'multidimensional') {
  2912. newValue[i] = keyValue;
  2913. } else {
  2914. newValue = keyValue;
  2915. }
  2916. }
  2917. }
  2918. }
  2919. caching.lastIndex = iterationIndex;
  2920. return newValue;
  2921. }
  2922. // based on @Toji's https://github.com/toji/gl-matrix/
  2923. function slerp(a, b, t) {
  2924. var out = [];
  2925. var ax = a[0];
  2926. var ay = a[1];
  2927. var az = a[2];
  2928. var aw = a[3];
  2929. var bx = b[0];
  2930. var by = b[1];
  2931. var bz = b[2];
  2932. var bw = b[3];
  2933. var omega;
  2934. var cosom;
  2935. var sinom;
  2936. var scale0;
  2937. var scale1;
  2938. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2939. if (cosom < 0.0) {
  2940. cosom = -cosom;
  2941. bx = -bx;
  2942. by = -by;
  2943. bz = -bz;
  2944. bw = -bw;
  2945. }
  2946. if (1.0 - cosom > 0.000001) {
  2947. omega = Math.acos(cosom);
  2948. sinom = Math.sin(omega);
  2949. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2950. scale1 = Math.sin(t * omega) / sinom;
  2951. } else {
  2952. scale0 = 1.0 - t;
  2953. scale1 = t;
  2954. }
  2955. out[0] = scale0 * ax + scale1 * bx;
  2956. out[1] = scale0 * ay + scale1 * by;
  2957. out[2] = scale0 * az + scale1 * bz;
  2958. out[3] = scale0 * aw + scale1 * bw;
  2959. return out;
  2960. }
  2961. function quaternionToEuler(out, quat) {
  2962. var qx = quat[0];
  2963. var qy = quat[1];
  2964. var qz = quat[2];
  2965. var qw = quat[3];
  2966. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2967. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2968. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2969. out[0] = heading / degToRads;
  2970. out[1] = attitude / degToRads;
  2971. out[2] = bank / degToRads;
  2972. }
  2973. function createQuaternion(values) {
  2974. var heading = values[0] * degToRads;
  2975. var attitude = values[1] * degToRads;
  2976. var bank = values[2] * degToRads;
  2977. var c1 = Math.cos(heading / 2);
  2978. var c2 = Math.cos(attitude / 2);
  2979. var c3 = Math.cos(bank / 2);
  2980. var s1 = Math.sin(heading / 2);
  2981. var s2 = Math.sin(attitude / 2);
  2982. var s3 = Math.sin(bank / 2);
  2983. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2984. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2985. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2986. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2987. return [x, y, z, w];
  2988. }
  2989. function getValueAtCurrentTime() {
  2990. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2991. var initTime = this.keyframes[0].t - this.offsetTime;
  2992. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2993. if (!(frameNum === this._caching.lastFrame || this._caching.lastFrame !== initFrame && (this._caching.lastFrame >= endTime && frameNum >= endTime || this._caching.lastFrame < initTime && frameNum < initTime))) {
  2994. if (this._caching.lastFrame >= frameNum) {
  2995. this._caching._lastKeyframeIndex = -1;
  2996. this._caching.lastIndex = 0;
  2997. }
  2998. var renderResult = this.interpolateValue(frameNum, this._caching);
  2999. this.pv = renderResult;
  3000. }
  3001. this._caching.lastFrame = frameNum;
  3002. return this.pv;
  3003. }
  3004. function setVValue(val) {
  3005. var multipliedValue;
  3006. if (this.propType === 'unidimensional') {
  3007. multipliedValue = val * this.mult;
  3008. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  3009. this.v = multipliedValue;
  3010. this._mdf = true;
  3011. }
  3012. } else {
  3013. var i = 0;
  3014. var len = this.v.length;
  3015. while (i < len) {
  3016. multipliedValue = val[i] * this.mult;
  3017. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  3018. this.v[i] = multipliedValue;
  3019. this._mdf = true;
  3020. }
  3021. i += 1;
  3022. }
  3023. }
  3024. }
  3025. function processEffectsSequence() {
  3026. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  3027. return;
  3028. }
  3029. if (this.lock) {
  3030. this.setVValue(this.pv);
  3031. return;
  3032. }
  3033. this.lock = true;
  3034. this._mdf = this._isFirstFrame;
  3035. var i;
  3036. var len = this.effectsSequence.length;
  3037. var finalValue = this.kf ? this.pv : this.data.k;
  3038. for (i = 0; i < len; i += 1) {
  3039. finalValue = this.effectsSequence[i](finalValue);
  3040. }
  3041. this.setVValue(finalValue);
  3042. this._isFirstFrame = false;
  3043. this.lock = false;
  3044. this.frameId = this.elem.globalData.frameId;
  3045. }
  3046. function addEffect(effectFunction) {
  3047. this.effectsSequence.push(effectFunction);
  3048. this.container.addDynamicProperty(this);
  3049. }
  3050. function ValueProperty(elem, data, mult, container) {
  3051. this.propType = 'unidimensional';
  3052. this.mult = mult || 1;
  3053. this.data = data;
  3054. this.v = mult ? data.k * mult : data.k;
  3055. this.pv = data.k;
  3056. this._mdf = false;
  3057. this.elem = elem;
  3058. this.container = container;
  3059. this.comp = elem.comp;
  3060. this.k = false;
  3061. this.kf = false;
  3062. this.vel = 0;
  3063. this.effectsSequence = [];
  3064. this._isFirstFrame = true;
  3065. this.getValue = processEffectsSequence;
  3066. this.setVValue = setVValue;
  3067. this.addEffect = addEffect;
  3068. }
  3069. function MultiDimensionalProperty(elem, data, mult, container) {
  3070. this.propType = 'multidimensional';
  3071. this.mult = mult || 1;
  3072. this.data = data;
  3073. this._mdf = false;
  3074. this.elem = elem;
  3075. this.container = container;
  3076. this.comp = elem.comp;
  3077. this.k = false;
  3078. this.kf = false;
  3079. this.frameId = -1;
  3080. var i;
  3081. var len = data.k.length;
  3082. this.v = createTypedArray('float32', len);
  3083. this.pv = createTypedArray('float32', len);
  3084. this.vel = createTypedArray('float32', len);
  3085. for (i = 0; i < len; i += 1) {
  3086. this.v[i] = data.k[i] * this.mult;
  3087. this.pv[i] = data.k[i];
  3088. }
  3089. this._isFirstFrame = true;
  3090. this.effectsSequence = [];
  3091. this.getValue = processEffectsSequence;
  3092. this.setVValue = setVValue;
  3093. this.addEffect = addEffect;
  3094. }
  3095. function KeyframedValueProperty(elem, data, mult, container) {
  3096. this.propType = 'unidimensional';
  3097. this.keyframes = data.k;
  3098. this.keyframesMetadata = [];
  3099. this.offsetTime = elem.data.st;
  3100. this.frameId = -1;
  3101. this._caching = {
  3102. lastFrame: initFrame,
  3103. lastIndex: 0,
  3104. value: 0,
  3105. _lastKeyframeIndex: -1
  3106. };
  3107. this.k = true;
  3108. this.kf = true;
  3109. this.data = data;
  3110. this.mult = mult || 1;
  3111. this.elem = elem;
  3112. this.container = container;
  3113. this.comp = elem.comp;
  3114. this.v = initFrame;
  3115. this.pv = initFrame;
  3116. this._isFirstFrame = true;
  3117. this.getValue = processEffectsSequence;
  3118. this.setVValue = setVValue;
  3119. this.interpolateValue = interpolateValue;
  3120. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3121. this.addEffect = addEffect;
  3122. }
  3123. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3124. this.propType = 'multidimensional';
  3125. var i;
  3126. var len = data.k.length;
  3127. var s;
  3128. var e;
  3129. var to;
  3130. var ti;
  3131. for (i = 0; i < len - 1; i += 1) {
  3132. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3133. s = data.k[i].s;
  3134. e = data.k[i + 1].s;
  3135. to = data.k[i].to;
  3136. ti = data.k[i].ti;
  3137. 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])) {
  3138. data.k[i].to = null;
  3139. data.k[i].ti = null;
  3140. }
  3141. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3142. if (s.length === 2 || s[2] === e[2] && to[2] === 0 && ti[2] === 0) {
  3143. data.k[i].to = null;
  3144. data.k[i].ti = null;
  3145. }
  3146. }
  3147. }
  3148. }
  3149. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3150. this.data = data;
  3151. this.keyframes = data.k;
  3152. this.keyframesMetadata = [];
  3153. this.offsetTime = elem.data.st;
  3154. this.k = true;
  3155. this.kf = true;
  3156. this._isFirstFrame = true;
  3157. this.mult = mult || 1;
  3158. this.elem = elem;
  3159. this.container = container;
  3160. this.comp = elem.comp;
  3161. this.getValue = processEffectsSequence;
  3162. this.setVValue = setVValue;
  3163. this.interpolateValue = interpolateValue;
  3164. this.frameId = -1;
  3165. var arrLen = data.k[0].s.length;
  3166. this.v = createTypedArray('float32', arrLen);
  3167. this.pv = createTypedArray('float32', arrLen);
  3168. for (i = 0; i < arrLen; i += 1) {
  3169. this.v[i] = initFrame;
  3170. this.pv[i] = initFrame;
  3171. }
  3172. this._caching = {
  3173. lastFrame: initFrame,
  3174. lastIndex: 0,
  3175. value: createTypedArray('float32', arrLen)
  3176. };
  3177. this.addEffect = addEffect;
  3178. }
  3179. var PropertyFactory = function () {
  3180. function getProp(elem, data, type, mult, container) {
  3181. if (data.sid) {
  3182. data = elem.globalData.slotManager.getProp(data);
  3183. }
  3184. var p;
  3185. if (!data.k.length) {
  3186. p = new ValueProperty(elem, data, mult, container);
  3187. } else if (typeof data.k[0] === 'number') {
  3188. p = new MultiDimensionalProperty(elem, data, mult, container);
  3189. } else {
  3190. switch (type) {
  3191. case 0:
  3192. p = new KeyframedValueProperty(elem, data, mult, container);
  3193. break;
  3194. case 1:
  3195. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3196. break;
  3197. default:
  3198. break;
  3199. }
  3200. }
  3201. if (p.effectsSequence.length) {
  3202. container.addDynamicProperty(p);
  3203. }
  3204. return p;
  3205. }
  3206. var ob = {
  3207. getProp: getProp
  3208. };
  3209. return ob;
  3210. }();
  3211. function DynamicPropertyContainer() {}
  3212. DynamicPropertyContainer.prototype = {
  3213. addDynamicProperty: function addDynamicProperty(prop) {
  3214. if (this.dynamicProperties.indexOf(prop) === -1) {
  3215. this.dynamicProperties.push(prop);
  3216. this.container.addDynamicProperty(this);
  3217. this._isAnimated = true;
  3218. }
  3219. },
  3220. iterateDynamicProperties: function iterateDynamicProperties() {
  3221. this._mdf = false;
  3222. var i;
  3223. var len = this.dynamicProperties.length;
  3224. for (i = 0; i < len; i += 1) {
  3225. this.dynamicProperties[i].getValue();
  3226. if (this.dynamicProperties[i]._mdf) {
  3227. this._mdf = true;
  3228. }
  3229. }
  3230. },
  3231. initDynamicPropertyContainer: function initDynamicPropertyContainer(container) {
  3232. this.container = container;
  3233. this.dynamicProperties = [];
  3234. this._mdf = false;
  3235. this._isAnimated = false;
  3236. }
  3237. };
  3238. var pointPool = function () {
  3239. function create() {
  3240. return createTypedArray('float32', 2);
  3241. }
  3242. return poolFactory(8, create);
  3243. }();
  3244. function ShapePath() {
  3245. this.c = false;
  3246. this._length = 0;
  3247. this._maxLength = 8;
  3248. this.v = createSizedArray(this._maxLength);
  3249. this.o = createSizedArray(this._maxLength);
  3250. this.i = createSizedArray(this._maxLength);
  3251. }
  3252. ShapePath.prototype.setPathData = function (closed, len) {
  3253. this.c = closed;
  3254. this.setLength(len);
  3255. var i = 0;
  3256. while (i < len) {
  3257. this.v[i] = pointPool.newElement();
  3258. this.o[i] = pointPool.newElement();
  3259. this.i[i] = pointPool.newElement();
  3260. i += 1;
  3261. }
  3262. };
  3263. ShapePath.prototype.setLength = function (len) {
  3264. while (this._maxLength < len) {
  3265. this.doubleArrayLength();
  3266. }
  3267. this._length = len;
  3268. };
  3269. ShapePath.prototype.doubleArrayLength = function () {
  3270. this.v = this.v.concat(createSizedArray(this._maxLength));
  3271. this.i = this.i.concat(createSizedArray(this._maxLength));
  3272. this.o = this.o.concat(createSizedArray(this._maxLength));
  3273. this._maxLength *= 2;
  3274. };
  3275. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3276. var arr;
  3277. this._length = Math.max(this._length, pos + 1);
  3278. if (this._length >= this._maxLength) {
  3279. this.doubleArrayLength();
  3280. }
  3281. switch (type) {
  3282. case 'v':
  3283. arr = this.v;
  3284. break;
  3285. case 'i':
  3286. arr = this.i;
  3287. break;
  3288. case 'o':
  3289. arr = this.o;
  3290. break;
  3291. default:
  3292. arr = [];
  3293. break;
  3294. }
  3295. if (!arr[pos] || arr[pos] && !replace) {
  3296. arr[pos] = pointPool.newElement();
  3297. }
  3298. arr[pos][0] = x;
  3299. arr[pos][1] = y;
  3300. };
  3301. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3302. this.setXYAt(vX, vY, 'v', pos, replace);
  3303. this.setXYAt(oX, oY, 'o', pos, replace);
  3304. this.setXYAt(iX, iY, 'i', pos, replace);
  3305. };
  3306. ShapePath.prototype.reverse = function () {
  3307. var newPath = new ShapePath();
  3308. newPath.setPathData(this.c, this._length);
  3309. var vertices = this.v;
  3310. var outPoints = this.o;
  3311. var inPoints = this.i;
  3312. var init = 0;
  3313. if (this.c) {
  3314. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3315. init = 1;
  3316. }
  3317. var cnt = this._length - 1;
  3318. var len = this._length;
  3319. var i;
  3320. for (i = init; i < len; i += 1) {
  3321. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3322. cnt -= 1;
  3323. }
  3324. return newPath;
  3325. };
  3326. ShapePath.prototype.length = function () {
  3327. return this._length;
  3328. };
  3329. var shapePool = function () {
  3330. function create() {
  3331. return new ShapePath();
  3332. }
  3333. function release(shapePath) {
  3334. var len = shapePath._length;
  3335. var i;
  3336. for (i = 0; i < len; i += 1) {
  3337. pointPool.release(shapePath.v[i]);
  3338. pointPool.release(shapePath.i[i]);
  3339. pointPool.release(shapePath.o[i]);
  3340. shapePath.v[i] = null;
  3341. shapePath.i[i] = null;
  3342. shapePath.o[i] = null;
  3343. }
  3344. shapePath._length = 0;
  3345. shapePath.c = false;
  3346. }
  3347. function clone(shape) {
  3348. var cloned = factory.newElement();
  3349. var i;
  3350. var len = shape._length === undefined ? shape.v.length : shape._length;
  3351. cloned.setLength(len);
  3352. cloned.c = shape.c;
  3353. for (i = 0; i < len; i += 1) {
  3354. 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);
  3355. }
  3356. return cloned;
  3357. }
  3358. var factory = poolFactory(4, create, release);
  3359. factory.clone = clone;
  3360. return factory;
  3361. }();
  3362. function ShapeCollection() {
  3363. this._length = 0;
  3364. this._maxLength = 4;
  3365. this.shapes = createSizedArray(this._maxLength);
  3366. }
  3367. ShapeCollection.prototype.addShape = function (shapeData) {
  3368. if (this._length === this._maxLength) {
  3369. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3370. this._maxLength *= 2;
  3371. }
  3372. this.shapes[this._length] = shapeData;
  3373. this._length += 1;
  3374. };
  3375. ShapeCollection.prototype.releaseShapes = function () {
  3376. var i;
  3377. for (i = 0; i < this._length; i += 1) {
  3378. shapePool.release(this.shapes[i]);
  3379. }
  3380. this._length = 0;
  3381. };
  3382. var shapeCollectionPool = function () {
  3383. var ob = {
  3384. newShapeCollection: newShapeCollection,
  3385. release: release
  3386. };
  3387. var _length = 0;
  3388. var _maxLength = 4;
  3389. var pool = createSizedArray(_maxLength);
  3390. function newShapeCollection() {
  3391. var shapeCollection;
  3392. if (_length) {
  3393. _length -= 1;
  3394. shapeCollection = pool[_length];
  3395. } else {
  3396. shapeCollection = new ShapeCollection();
  3397. }
  3398. return shapeCollection;
  3399. }
  3400. function release(shapeCollection) {
  3401. var i;
  3402. var len = shapeCollection._length;
  3403. for (i = 0; i < len; i += 1) {
  3404. shapePool.release(shapeCollection.shapes[i]);
  3405. }
  3406. shapeCollection._length = 0;
  3407. if (_length === _maxLength) {
  3408. pool = pooling["double"](pool);
  3409. _maxLength *= 2;
  3410. }
  3411. pool[_length] = shapeCollection;
  3412. _length += 1;
  3413. }
  3414. return ob;
  3415. }();
  3416. var ShapePropertyFactory = function () {
  3417. var initFrame = -999999;
  3418. function interpolateShape(frameNum, previousValue, caching) {
  3419. var iterationIndex = caching.lastIndex;
  3420. var keyPropS;
  3421. var keyPropE;
  3422. var isHold;
  3423. var j;
  3424. var k;
  3425. var jLen;
  3426. var kLen;
  3427. var perc;
  3428. var vertexValue;
  3429. var kf = this.keyframes;
  3430. if (frameNum < kf[0].t - this.offsetTime) {
  3431. keyPropS = kf[0].s[0];
  3432. isHold = true;
  3433. iterationIndex = 0;
  3434. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3435. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3436. /* if(kf[kf.length - 1].s){
  3437. keyPropS = kf[kf.length - 1].s[0];
  3438. }else{
  3439. keyPropS = kf[kf.length - 2].e[0];
  3440. } */
  3441. isHold = true;
  3442. } else {
  3443. var i = iterationIndex;
  3444. var len = kf.length - 1;
  3445. var flag = true;
  3446. var keyData;
  3447. var nextKeyData;
  3448. var keyframeMetadata;
  3449. while (flag) {
  3450. keyData = kf[i];
  3451. nextKeyData = kf[i + 1];
  3452. if (nextKeyData.t - this.offsetTime > frameNum) {
  3453. break;
  3454. }
  3455. if (i < len - 1) {
  3456. i += 1;
  3457. } else {
  3458. flag = false;
  3459. }
  3460. }
  3461. keyframeMetadata = this.keyframesMetadata[i] || {};
  3462. isHold = keyData.h === 1;
  3463. iterationIndex = i;
  3464. if (!isHold) {
  3465. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3466. perc = 1;
  3467. } else if (frameNum < keyData.t - this.offsetTime) {
  3468. perc = 0;
  3469. } else {
  3470. var fnc;
  3471. if (keyframeMetadata.__fnct) {
  3472. fnc = keyframeMetadata.__fnct;
  3473. } else {
  3474. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3475. keyframeMetadata.__fnct = fnc;
  3476. }
  3477. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / (nextKeyData.t - this.offsetTime - (keyData.t - this.offsetTime)));
  3478. }
  3479. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3480. }
  3481. keyPropS = keyData.s[0];
  3482. }
  3483. jLen = previousValue._length;
  3484. kLen = keyPropS.i[0].length;
  3485. caching.lastIndex = iterationIndex;
  3486. for (j = 0; j < jLen; j += 1) {
  3487. for (k = 0; k < kLen; k += 1) {
  3488. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3489. previousValue.i[j][k] = vertexValue;
  3490. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3491. previousValue.o[j][k] = vertexValue;
  3492. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3493. previousValue.v[j][k] = vertexValue;
  3494. }
  3495. }
  3496. }
  3497. function interpolateShapeCurrentTime() {
  3498. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3499. var initTime = this.keyframes[0].t - this.offsetTime;
  3500. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3501. var lastFrame = this._caching.lastFrame;
  3502. if (!(lastFrame !== initFrame && (lastFrame < initTime && frameNum < initTime || lastFrame > endTime && frameNum > endTime))) {
  3503. /// /
  3504. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3505. this.interpolateShape(frameNum, this.pv, this._caching);
  3506. /// /
  3507. }
  3508. this._caching.lastFrame = frameNum;
  3509. return this.pv;
  3510. }
  3511. function resetShape() {
  3512. this.paths = this.localShapeCollection;
  3513. }
  3514. function shapesEqual(shape1, shape2) {
  3515. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3516. return false;
  3517. }
  3518. var i;
  3519. var len = shape1._length;
  3520. for (i = 0; i < len; i += 1) {
  3521. if (shape1.v[i][0] !== shape2.v[i][0] || shape1.v[i][1] !== shape2.v[i][1] || shape1.o[i][0] !== shape2.o[i][0] || shape1.o[i][1] !== shape2.o[i][1] || shape1.i[i][0] !== shape2.i[i][0] || shape1.i[i][1] !== shape2.i[i][1]) {
  3522. return false;
  3523. }
  3524. }
  3525. return true;
  3526. }
  3527. function setVValue(newPath) {
  3528. if (!shapesEqual(this.v, newPath)) {
  3529. this.v = shapePool.clone(newPath);
  3530. this.localShapeCollection.releaseShapes();
  3531. this.localShapeCollection.addShape(this.v);
  3532. this._mdf = true;
  3533. this.paths = this.localShapeCollection;
  3534. }
  3535. }
  3536. function processEffectsSequence() {
  3537. if (this.elem.globalData.frameId === this.frameId) {
  3538. return;
  3539. }
  3540. if (!this.effectsSequence.length) {
  3541. this._mdf = false;
  3542. return;
  3543. }
  3544. if (this.lock) {
  3545. this.setVValue(this.pv);
  3546. return;
  3547. }
  3548. this.lock = true;
  3549. this._mdf = false;
  3550. var finalValue;
  3551. if (this.kf) {
  3552. finalValue = this.pv;
  3553. } else if (this.data.ks) {
  3554. finalValue = this.data.ks.k;
  3555. } else {
  3556. finalValue = this.data.pt.k;
  3557. }
  3558. var i;
  3559. var len = this.effectsSequence.length;
  3560. for (i = 0; i < len; i += 1) {
  3561. finalValue = this.effectsSequence[i](finalValue);
  3562. }
  3563. this.setVValue(finalValue);
  3564. this.lock = false;
  3565. this.frameId = this.elem.globalData.frameId;
  3566. }
  3567. function ShapeProperty(elem, data, type) {
  3568. this.propType = 'shape';
  3569. this.comp = elem.comp;
  3570. this.container = elem;
  3571. this.elem = elem;
  3572. this.data = data;
  3573. this.k = false;
  3574. this.kf = false;
  3575. this._mdf = false;
  3576. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3577. this.v = shapePool.clone(pathData);
  3578. this.pv = shapePool.clone(this.v);
  3579. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3580. this.paths = this.localShapeCollection;
  3581. this.paths.addShape(this.v);
  3582. this.reset = resetShape;
  3583. this.effectsSequence = [];
  3584. }
  3585. function addEffect(effectFunction) {
  3586. this.effectsSequence.push(effectFunction);
  3587. this.container.addDynamicProperty(this);
  3588. }
  3589. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3590. ShapeProperty.prototype.getValue = processEffectsSequence;
  3591. ShapeProperty.prototype.setVValue = setVValue;
  3592. ShapeProperty.prototype.addEffect = addEffect;
  3593. function KeyframedShapeProperty(elem, data, type) {
  3594. this.propType = 'shape';
  3595. this.comp = elem.comp;
  3596. this.elem = elem;
  3597. this.container = elem;
  3598. this.offsetTime = elem.data.st;
  3599. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3600. this.keyframesMetadata = [];
  3601. this.k = true;
  3602. this.kf = true;
  3603. var len = this.keyframes[0].s[0].i.length;
  3604. this.v = shapePool.newElement();
  3605. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3606. this.pv = shapePool.clone(this.v);
  3607. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3608. this.paths = this.localShapeCollection;
  3609. this.paths.addShape(this.v);
  3610. this.lastFrame = initFrame;
  3611. this.reset = resetShape;
  3612. this._caching = {
  3613. lastFrame: initFrame,
  3614. lastIndex: 0
  3615. };
  3616. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3617. }
  3618. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3619. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3620. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3621. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3622. var EllShapeProperty = function () {
  3623. var cPoint = roundCorner;
  3624. function EllShapePropertyFactory(elem, data) {
  3625. this.v = shapePool.newElement();
  3626. this.v.setPathData(true, 4);
  3627. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3628. this.paths = this.localShapeCollection;
  3629. this.localShapeCollection.addShape(this.v);
  3630. this.d = data.d;
  3631. this.elem = elem;
  3632. this.comp = elem.comp;
  3633. this.frameId = -1;
  3634. this.initDynamicPropertyContainer(elem);
  3635. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3636. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3637. if (this.dynamicProperties.length) {
  3638. this.k = true;
  3639. } else {
  3640. this.k = false;
  3641. this.convertEllToPath();
  3642. }
  3643. }
  3644. EllShapePropertyFactory.prototype = {
  3645. reset: resetShape,
  3646. getValue: function getValue() {
  3647. if (this.elem.globalData.frameId === this.frameId) {
  3648. return;
  3649. }
  3650. this.frameId = this.elem.globalData.frameId;
  3651. this.iterateDynamicProperties();
  3652. if (this._mdf) {
  3653. this.convertEllToPath();
  3654. }
  3655. },
  3656. convertEllToPath: function convertEllToPath() {
  3657. var p0 = this.p.v[0];
  3658. var p1 = this.p.v[1];
  3659. var s0 = this.s.v[0] / 2;
  3660. var s1 = this.s.v[1] / 2;
  3661. var _cw = this.d !== 3;
  3662. var _v = this.v;
  3663. _v.v[0][0] = p0;
  3664. _v.v[0][1] = p1 - s1;
  3665. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3666. _v.v[1][1] = p1;
  3667. _v.v[2][0] = p0;
  3668. _v.v[2][1] = p1 + s1;
  3669. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3670. _v.v[3][1] = p1;
  3671. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3672. _v.i[0][1] = p1 - s1;
  3673. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3674. _v.i[1][1] = p1 - s1 * cPoint;
  3675. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3676. _v.i[2][1] = p1 + s1;
  3677. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3678. _v.i[3][1] = p1 + s1 * cPoint;
  3679. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3680. _v.o[0][1] = p1 - s1;
  3681. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3682. _v.o[1][1] = p1 + s1 * cPoint;
  3683. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3684. _v.o[2][1] = p1 + s1;
  3685. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3686. _v.o[3][1] = p1 - s1 * cPoint;
  3687. }
  3688. };
  3689. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3690. return EllShapePropertyFactory;
  3691. }();
  3692. var StarShapeProperty = function () {
  3693. function StarShapePropertyFactory(elem, data) {
  3694. this.v = shapePool.newElement();
  3695. this.v.setPathData(true, 0);
  3696. this.elem = elem;
  3697. this.comp = elem.comp;
  3698. this.data = data;
  3699. this.frameId = -1;
  3700. this.d = data.d;
  3701. this.initDynamicPropertyContainer(elem);
  3702. if (data.sy === 1) {
  3703. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3704. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3705. this.convertToPath = this.convertStarToPath;
  3706. } else {
  3707. this.convertToPath = this.convertPolygonToPath;
  3708. }
  3709. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3710. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3711. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3712. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3713. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3714. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3715. this.localShapeCollection.addShape(this.v);
  3716. this.paths = this.localShapeCollection;
  3717. if (this.dynamicProperties.length) {
  3718. this.k = true;
  3719. } else {
  3720. this.k = false;
  3721. this.convertToPath();
  3722. }
  3723. }
  3724. StarShapePropertyFactory.prototype = {
  3725. reset: resetShape,
  3726. getValue: function getValue() {
  3727. if (this.elem.globalData.frameId === this.frameId) {
  3728. return;
  3729. }
  3730. this.frameId = this.elem.globalData.frameId;
  3731. this.iterateDynamicProperties();
  3732. if (this._mdf) {
  3733. this.convertToPath();
  3734. }
  3735. },
  3736. convertStarToPath: function convertStarToPath() {
  3737. var numPts = Math.floor(this.pt.v) * 2;
  3738. var angle = Math.PI * 2 / numPts;
  3739. /* this.v.v.length = numPts;
  3740. this.v.i.length = numPts;
  3741. this.v.o.length = numPts; */
  3742. var longFlag = true;
  3743. var longRad = this.or.v;
  3744. var shortRad = this.ir.v;
  3745. var longRound = this.os.v;
  3746. var shortRound = this.is.v;
  3747. var longPerimSegment = 2 * Math.PI * longRad / (numPts * 2);
  3748. var shortPerimSegment = 2 * Math.PI * shortRad / (numPts * 2);
  3749. var i;
  3750. var rad;
  3751. var roundness;
  3752. var perimSegment;
  3753. var currentAng = -Math.PI / 2;
  3754. currentAng += this.r.v;
  3755. var dir = this.data.d === 3 ? -1 : 1;
  3756. this.v._length = 0;
  3757. for (i = 0; i < numPts; i += 1) {
  3758. rad = longFlag ? longRad : shortRad;
  3759. roundness = longFlag ? longRound : shortRound;
  3760. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3761. var x = rad * Math.cos(currentAng);
  3762. var y = rad * Math.sin(currentAng);
  3763. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3764. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3765. x += +this.p.v[0];
  3766. y += +this.p.v[1];
  3767. 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);
  3768. /* this.v.v[i] = [x,y];
  3769. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3770. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3771. this.v._length = numPts; */
  3772. longFlag = !longFlag;
  3773. currentAng += angle * dir;
  3774. }
  3775. },
  3776. convertPolygonToPath: function convertPolygonToPath() {
  3777. var numPts = Math.floor(this.pt.v);
  3778. var angle = Math.PI * 2 / numPts;
  3779. var rad = this.or.v;
  3780. var roundness = this.os.v;
  3781. var perimSegment = 2 * Math.PI * rad / (numPts * 4);
  3782. var i;
  3783. var currentAng = -Math.PI * 0.5;
  3784. var dir = this.data.d === 3 ? -1 : 1;
  3785. currentAng += this.r.v;
  3786. this.v._length = 0;
  3787. for (i = 0; i < numPts; i += 1) {
  3788. var x = rad * Math.cos(currentAng);
  3789. var y = rad * Math.sin(currentAng);
  3790. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3791. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3792. x += +this.p.v[0];
  3793. y += +this.p.v[1];
  3794. 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);
  3795. currentAng += angle * dir;
  3796. }
  3797. this.paths.length = 0;
  3798. this.paths[0] = this.v;
  3799. }
  3800. };
  3801. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3802. return StarShapePropertyFactory;
  3803. }();
  3804. var RectShapeProperty = function () {
  3805. function RectShapePropertyFactory(elem, data) {
  3806. this.v = shapePool.newElement();
  3807. this.v.c = true;
  3808. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3809. this.localShapeCollection.addShape(this.v);
  3810. this.paths = this.localShapeCollection;
  3811. this.elem = elem;
  3812. this.comp = elem.comp;
  3813. this.frameId = -1;
  3814. this.d = data.d;
  3815. this.initDynamicPropertyContainer(elem);
  3816. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3817. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3818. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3819. if (this.dynamicProperties.length) {
  3820. this.k = true;
  3821. } else {
  3822. this.k = false;
  3823. this.convertRectToPath();
  3824. }
  3825. }
  3826. RectShapePropertyFactory.prototype = {
  3827. convertRectToPath: function convertRectToPath() {
  3828. var p0 = this.p.v[0];
  3829. var p1 = this.p.v[1];
  3830. var v0 = this.s.v[0] / 2;
  3831. var v1 = this.s.v[1] / 2;
  3832. var round = bmMin(v0, v1, this.r.v);
  3833. var cPoint = round * (1 - roundCorner);
  3834. this.v._length = 0;
  3835. if (this.d === 2 || this.d === 1) {
  3836. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3837. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3838. if (round !== 0) {
  3839. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3840. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3841. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3842. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3843. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3844. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3845. } else {
  3846. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3847. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3848. }
  3849. } else {
  3850. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3851. if (round !== 0) {
  3852. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3853. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3854. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3855. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3856. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3857. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3858. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3859. } else {
  3860. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3861. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3862. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3863. }
  3864. }
  3865. },
  3866. getValue: function getValue() {
  3867. if (this.elem.globalData.frameId === this.frameId) {
  3868. return;
  3869. }
  3870. this.frameId = this.elem.globalData.frameId;
  3871. this.iterateDynamicProperties();
  3872. if (this._mdf) {
  3873. this.convertRectToPath();
  3874. }
  3875. },
  3876. reset: resetShape
  3877. };
  3878. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3879. return RectShapePropertyFactory;
  3880. }();
  3881. function getShapeProp(elem, data, type) {
  3882. var prop;
  3883. if (type === 3 || type === 4) {
  3884. var dataProp = type === 3 ? data.pt : data.ks;
  3885. var keys = dataProp.k;
  3886. if (keys.length) {
  3887. prop = new KeyframedShapeProperty(elem, data, type);
  3888. } else {
  3889. prop = new ShapeProperty(elem, data, type);
  3890. }
  3891. } else if (type === 5) {
  3892. prop = new RectShapeProperty(elem, data);
  3893. } else if (type === 6) {
  3894. prop = new EllShapeProperty(elem, data);
  3895. } else if (type === 7) {
  3896. prop = new StarShapeProperty(elem, data);
  3897. }
  3898. if (prop.k) {
  3899. elem.addDynamicProperty(prop);
  3900. }
  3901. return prop;
  3902. }
  3903. function getConstructorFunction() {
  3904. return ShapeProperty;
  3905. }
  3906. function getKeyframedConstructorFunction() {
  3907. return KeyframedShapeProperty;
  3908. }
  3909. var ob = {};
  3910. ob.getShapeProp = getShapeProp;
  3911. ob.getConstructorFunction = getConstructorFunction;
  3912. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3913. return ob;
  3914. }();
  3915. /*!
  3916. Transformation Matrix v2.0
  3917. (c) Epistemex 2014-2015
  3918. www.epistemex.com
  3919. By Ken Fyrstenberg
  3920. Contributions by leeoniya.
  3921. License: MIT, header required.
  3922. */
  3923. /**
  3924. * 2D transformation matrix object initialized with identity matrix.
  3925. *
  3926. * The matrix can synchronize a canvas context by supplying the context
  3927. * as an argument, or later apply current absolute transform to an
  3928. * existing context.
  3929. *
  3930. * All values are handled as floating point values.
  3931. *
  3932. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3933. * @prop {number} a - scale x
  3934. * @prop {number} b - shear y
  3935. * @prop {number} c - shear x
  3936. * @prop {number} d - scale y
  3937. * @prop {number} e - translate x
  3938. * @prop {number} f - translate y
  3939. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3940. * @constructor
  3941. */
  3942. var Matrix = function () {
  3943. var _cos = Math.cos;
  3944. var _sin = Math.sin;
  3945. var _tan = Math.tan;
  3946. var _rnd = Math.round;
  3947. function reset() {
  3948. this.props[0] = 1;
  3949. this.props[1] = 0;
  3950. this.props[2] = 0;
  3951. this.props[3] = 0;
  3952. this.props[4] = 0;
  3953. this.props[5] = 1;
  3954. this.props[6] = 0;
  3955. this.props[7] = 0;
  3956. this.props[8] = 0;
  3957. this.props[9] = 0;
  3958. this.props[10] = 1;
  3959. this.props[11] = 0;
  3960. this.props[12] = 0;
  3961. this.props[13] = 0;
  3962. this.props[14] = 0;
  3963. this.props[15] = 1;
  3964. return this;
  3965. }
  3966. function rotate(angle) {
  3967. if (angle === 0) {
  3968. return this;
  3969. }
  3970. var mCos = _cos(angle);
  3971. var mSin = _sin(angle);
  3972. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3973. }
  3974. function rotateX(angle) {
  3975. if (angle === 0) {
  3976. return this;
  3977. }
  3978. var mCos = _cos(angle);
  3979. var mSin = _sin(angle);
  3980. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3981. }
  3982. function rotateY(angle) {
  3983. if (angle === 0) {
  3984. return this;
  3985. }
  3986. var mCos = _cos(angle);
  3987. var mSin = _sin(angle);
  3988. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3989. }
  3990. function rotateZ(angle) {
  3991. if (angle === 0) {
  3992. return this;
  3993. }
  3994. var mCos = _cos(angle);
  3995. var mSin = _sin(angle);
  3996. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3997. }
  3998. function shear(sx, sy) {
  3999. return this._t(1, sy, sx, 1, 0, 0);
  4000. }
  4001. function skew(ax, ay) {
  4002. return this.shear(_tan(ax), _tan(ay));
  4003. }
  4004. function skewFromAxis(ax, angle) {
  4005. var mCos = _cos(angle);
  4006. var mSin = _sin(angle);
  4007. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4008. // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  4009. }
  4010. function scale(sx, sy, sz) {
  4011. if (!sz && sz !== 0) {
  4012. sz = 1;
  4013. }
  4014. if (sx === 1 && sy === 1 && sz === 1) {
  4015. return this;
  4016. }
  4017. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  4018. }
  4019. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  4020. this.props[0] = a;
  4021. this.props[1] = b;
  4022. this.props[2] = c;
  4023. this.props[3] = d;
  4024. this.props[4] = e;
  4025. this.props[5] = f;
  4026. this.props[6] = g;
  4027. this.props[7] = h;
  4028. this.props[8] = i;
  4029. this.props[9] = j;
  4030. this.props[10] = k;
  4031. this.props[11] = l;
  4032. this.props[12] = m;
  4033. this.props[13] = n;
  4034. this.props[14] = o;
  4035. this.props[15] = p;
  4036. return this;
  4037. }
  4038. function translate(tx, ty, tz) {
  4039. tz = tz || 0;
  4040. if (tx !== 0 || ty !== 0 || tz !== 0) {
  4041. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  4042. }
  4043. return this;
  4044. }
  4045. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  4046. var _p = this.props;
  4047. 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) {
  4048. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  4049. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  4050. _p[12] = _p[12] * a2 + _p[15] * m2;
  4051. _p[13] = _p[13] * f2 + _p[15] * n2;
  4052. _p[14] = _p[14] * k2 + _p[15] * o2;
  4053. _p[15] *= p2;
  4054. // }
  4055. this._identityCalculated = false;
  4056. return this;
  4057. }
  4058. var a1 = _p[0];
  4059. var b1 = _p[1];
  4060. var c1 = _p[2];
  4061. var d1 = _p[3];
  4062. var e1 = _p[4];
  4063. var f1 = _p[5];
  4064. var g1 = _p[6];
  4065. var h1 = _p[7];
  4066. var i1 = _p[8];
  4067. var j1 = _p[9];
  4068. var k1 = _p[10];
  4069. var l1 = _p[11];
  4070. var m1 = _p[12];
  4071. var n1 = _p[13];
  4072. var o1 = _p[14];
  4073. var p1 = _p[15];
  4074. /* matrix order (canvas compatible):
  4075. * ace
  4076. * bdf
  4077. * 001
  4078. */
  4079. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  4080. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  4081. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  4082. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  4083. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  4084. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  4085. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  4086. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  4087. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  4088. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  4089. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  4090. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  4091. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  4092. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  4093. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  4094. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  4095. this._identityCalculated = false;
  4096. return this;
  4097. }
  4098. function multiply(matrix) {
  4099. var matrixProps = matrix.props;
  4100. return this.transform(matrixProps[0], matrixProps[1], matrixProps[2], matrixProps[3], matrixProps[4], matrixProps[5], matrixProps[6], matrixProps[7], matrixProps[8], matrixProps[9], matrixProps[10], matrixProps[11], matrixProps[12], matrixProps[13], matrixProps[14], matrixProps[15]);
  4101. }
  4102. function isIdentity() {
  4103. if (!this._identityCalculated) {
  4104. 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);
  4105. this._identityCalculated = true;
  4106. }
  4107. return this._identity;
  4108. }
  4109. function equals(matr) {
  4110. var i = 0;
  4111. while (i < 16) {
  4112. if (matr.props[i] !== this.props[i]) {
  4113. return false;
  4114. }
  4115. i += 1;
  4116. }
  4117. return true;
  4118. }
  4119. function clone(matr) {
  4120. var i;
  4121. for (i = 0; i < 16; i += 1) {
  4122. matr.props[i] = this.props[i];
  4123. }
  4124. return matr;
  4125. }
  4126. function cloneFromProps(props) {
  4127. var i;
  4128. for (i = 0; i < 16; i += 1) {
  4129. this.props[i] = props[i];
  4130. }
  4131. }
  4132. function applyToPoint(x, y, z) {
  4133. return {
  4134. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4135. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4136. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]
  4137. };
  4138. /* return {
  4139. x: x * me.a + y * me.c + me.e,
  4140. y: x * me.b + y * me.d + me.f
  4141. }; */
  4142. }
  4143. function applyToX(x, y, z) {
  4144. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4145. }
  4146. function applyToY(x, y, z) {
  4147. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4148. }
  4149. function applyToZ(x, y, z) {
  4150. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4151. }
  4152. function getInverseMatrix() {
  4153. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4154. var a = this.props[5] / determinant;
  4155. var b = -this.props[1] / determinant;
  4156. var c = -this.props[4] / determinant;
  4157. var d = this.props[0] / determinant;
  4158. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4159. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4160. var inverseMatrix = new Matrix();
  4161. inverseMatrix.props[0] = a;
  4162. inverseMatrix.props[1] = b;
  4163. inverseMatrix.props[4] = c;
  4164. inverseMatrix.props[5] = d;
  4165. inverseMatrix.props[12] = e;
  4166. inverseMatrix.props[13] = f;
  4167. return inverseMatrix;
  4168. }
  4169. function inversePoint(pt) {
  4170. var inverseMatrix = this.getInverseMatrix();
  4171. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4172. }
  4173. function inversePoints(pts) {
  4174. var i;
  4175. var len = pts.length;
  4176. var retPts = [];
  4177. for (i = 0; i < len; i += 1) {
  4178. retPts[i] = inversePoint(pts[i]);
  4179. }
  4180. return retPts;
  4181. }
  4182. function applyToTriplePoints(pt1, pt2, pt3) {
  4183. var arr = createTypedArray('float32', 6);
  4184. if (this.isIdentity()) {
  4185. arr[0] = pt1[0];
  4186. arr[1] = pt1[1];
  4187. arr[2] = pt2[0];
  4188. arr[3] = pt2[1];
  4189. arr[4] = pt3[0];
  4190. arr[5] = pt3[1];
  4191. } else {
  4192. var p0 = this.props[0];
  4193. var p1 = this.props[1];
  4194. var p4 = this.props[4];
  4195. var p5 = this.props[5];
  4196. var p12 = this.props[12];
  4197. var p13 = this.props[13];
  4198. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4199. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4200. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4201. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4202. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4203. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4204. }
  4205. return arr;
  4206. }
  4207. function applyToPointArray(x, y, z) {
  4208. var arr;
  4209. if (this.isIdentity()) {
  4210. arr = [x, y, z];
  4211. } else {
  4212. arr = [x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12], x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13], x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]];
  4213. }
  4214. return arr;
  4215. }
  4216. function applyToPointStringified(x, y) {
  4217. if (this.isIdentity()) {
  4218. return x + ',' + y;
  4219. }
  4220. var _p = this.props;
  4221. 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;
  4222. }
  4223. function toCSS() {
  4224. // 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.
  4225. /* if(this.isIdentity()) {
  4226. return '';
  4227. } */
  4228. var i = 0;
  4229. var props = this.props;
  4230. var cssValue = 'matrix3d(';
  4231. var v = 10000;
  4232. while (i < 16) {
  4233. cssValue += _rnd(props[i] * v) / v;
  4234. cssValue += i === 15 ? ')' : ',';
  4235. i += 1;
  4236. }
  4237. return cssValue;
  4238. }
  4239. function roundMatrixProperty(val) {
  4240. var v = 10000;
  4241. if (val < 0.000001 && val > 0 || val > -0.000001 && val < 0) {
  4242. return _rnd(val * v) / v;
  4243. }
  4244. return val;
  4245. }
  4246. function to2dCSS() {
  4247. // 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.
  4248. /* if(this.isIdentity()) {
  4249. return '';
  4250. } */
  4251. var props = this.props;
  4252. var _a = roundMatrixProperty(props[0]);
  4253. var _b = roundMatrixProperty(props[1]);
  4254. var _c = roundMatrixProperty(props[4]);
  4255. var _d = roundMatrixProperty(props[5]);
  4256. var _e = roundMatrixProperty(props[12]);
  4257. var _f = roundMatrixProperty(props[13]);
  4258. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4259. }
  4260. return function () {
  4261. this.reset = reset;
  4262. this.rotate = rotate;
  4263. this.rotateX = rotateX;
  4264. this.rotateY = rotateY;
  4265. this.rotateZ = rotateZ;
  4266. this.skew = skew;
  4267. this.skewFromAxis = skewFromAxis;
  4268. this.shear = shear;
  4269. this.scale = scale;
  4270. this.setTransform = setTransform;
  4271. this.translate = translate;
  4272. this.transform = transform;
  4273. this.multiply = multiply;
  4274. this.applyToPoint = applyToPoint;
  4275. this.applyToX = applyToX;
  4276. this.applyToY = applyToY;
  4277. this.applyToZ = applyToZ;
  4278. this.applyToPointArray = applyToPointArray;
  4279. this.applyToTriplePoints = applyToTriplePoints;
  4280. this.applyToPointStringified = applyToPointStringified;
  4281. this.toCSS = toCSS;
  4282. this.to2dCSS = to2dCSS;
  4283. this.clone = clone;
  4284. this.cloneFromProps = cloneFromProps;
  4285. this.equals = equals;
  4286. this.inversePoints = inversePoints;
  4287. this.inversePoint = inversePoint;
  4288. this.getInverseMatrix = getInverseMatrix;
  4289. this._t = this.transform;
  4290. this.isIdentity = isIdentity;
  4291. this._identity = true;
  4292. this._identityCalculated = false;
  4293. this.props = createTypedArray('float32', 16);
  4294. this.reset();
  4295. };
  4296. }();
  4297. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  4298. var lottie = {};
  4299. var standalone = '__[STANDALONE]__';
  4300. var animationData = '__[ANIMATIONDATA]__';
  4301. var renderer = '';
  4302. function setLocation(href) {
  4303. setLocationHref(href);
  4304. }
  4305. function searchAnimations() {
  4306. if (standalone === true) {
  4307. animationManager.searchAnimations(animationData, standalone, renderer);
  4308. } else {
  4309. animationManager.searchAnimations();
  4310. }
  4311. }
  4312. function setSubframeRendering(flag) {
  4313. setSubframeEnabled(flag);
  4314. }
  4315. function setPrefix(prefix) {
  4316. setIdPrefix(prefix);
  4317. }
  4318. function loadAnimation(params) {
  4319. if (standalone === true) {
  4320. params.animationData = JSON.parse(animationData);
  4321. }
  4322. return animationManager.loadAnimation(params);
  4323. }
  4324. function setQuality(value) {
  4325. if (typeof value === 'string') {
  4326. switch (value) {
  4327. case 'high':
  4328. setDefaultCurveSegments(200);
  4329. break;
  4330. default:
  4331. case 'medium':
  4332. setDefaultCurveSegments(50);
  4333. break;
  4334. case 'low':
  4335. setDefaultCurveSegments(10);
  4336. break;
  4337. }
  4338. } else if (!isNaN(value) && value > 1) {
  4339. setDefaultCurveSegments(value);
  4340. }
  4341. if (getDefaultCurveSegments() >= 50) {
  4342. roundValues(false);
  4343. } else {
  4344. roundValues(true);
  4345. }
  4346. }
  4347. function inBrowser() {
  4348. return typeof navigator !== 'undefined';
  4349. }
  4350. function installPlugin(type, plugin) {
  4351. if (type === 'expressions') {
  4352. setExpressionsPlugin(plugin);
  4353. }
  4354. }
  4355. function getFactory(name) {
  4356. switch (name) {
  4357. case 'propertyFactory':
  4358. return PropertyFactory;
  4359. case 'shapePropertyFactory':
  4360. return ShapePropertyFactory;
  4361. case 'matrix':
  4362. return Matrix;
  4363. default:
  4364. return null;
  4365. }
  4366. }
  4367. lottie.play = animationManager.play;
  4368. lottie.pause = animationManager.pause;
  4369. lottie.setLocationHref = setLocation;
  4370. lottie.togglePause = animationManager.togglePause;
  4371. lottie.setSpeed = animationManager.setSpeed;
  4372. lottie.setDirection = animationManager.setDirection;
  4373. lottie.stop = animationManager.stop;
  4374. lottie.searchAnimations = searchAnimations;
  4375. lottie.registerAnimation = animationManager.registerAnimation;
  4376. lottie.loadAnimation = loadAnimation;
  4377. lottie.setSubframeRendering = setSubframeRendering;
  4378. lottie.resize = animationManager.resize;
  4379. // lottie.start = start;
  4380. lottie.goToAndStop = animationManager.goToAndStop;
  4381. lottie.destroy = animationManager.destroy;
  4382. lottie.setQuality = setQuality;
  4383. lottie.inBrowser = inBrowser;
  4384. lottie.installPlugin = installPlugin;
  4385. lottie.freeze = animationManager.freeze;
  4386. lottie.unfreeze = animationManager.unfreeze;
  4387. lottie.setVolume = animationManager.setVolume;
  4388. lottie.mute = animationManager.mute;
  4389. lottie.unmute = animationManager.unmute;
  4390. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4391. lottie.useWebWorker = setWebWorker;
  4392. lottie.setIDPrefix = setPrefix;
  4393. lottie.__getFactory = getFactory;
  4394. lottie.version = '5.13.0';
  4395. function checkReady() {
  4396. if (document.readyState === 'complete') {
  4397. clearInterval(readyStateCheckInterval);
  4398. searchAnimations();
  4399. }
  4400. }
  4401. function getQueryVariable(variable) {
  4402. var vars = queryString.split('&');
  4403. for (var i = 0; i < vars.length; i += 1) {
  4404. var pair = vars[i].split('=');
  4405. if (decodeURIComponent(pair[0]) == variable) {
  4406. // eslint-disable-line eqeqeq
  4407. return decodeURIComponent(pair[1]);
  4408. }
  4409. }
  4410. return null;
  4411. }
  4412. var queryString = '';
  4413. if (standalone) {
  4414. var scripts = document.getElementsByTagName('script');
  4415. var index = scripts.length - 1;
  4416. var myScript = scripts[index] || {
  4417. src: ''
  4418. };
  4419. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4420. renderer = getQueryVariable('renderer');
  4421. }
  4422. var readyStateCheckInterval = setInterval(checkReady, 100);
  4423. // this adds bodymovin to the window object for backwards compatibility
  4424. try {
  4425. if (!((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined') && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4426. ) {
  4427. window.bodymovin = lottie;
  4428. }
  4429. } catch (err) {
  4430. //
  4431. }
  4432. var ShapeModifiers = function () {
  4433. var ob = {};
  4434. var modifiers = {};
  4435. ob.registerModifier = registerModifier;
  4436. ob.getModifier = getModifier;
  4437. function registerModifier(nm, factory) {
  4438. if (!modifiers[nm]) {
  4439. modifiers[nm] = factory;
  4440. }
  4441. }
  4442. function getModifier(nm, elem, data) {
  4443. return new modifiers[nm](elem, data);
  4444. }
  4445. return ob;
  4446. }();
  4447. function ShapeModifier() {}
  4448. ShapeModifier.prototype.initModifierProperties = function () {};
  4449. ShapeModifier.prototype.addShapeToModifier = function () {};
  4450. ShapeModifier.prototype.addShape = function (data) {
  4451. if (!this.closed) {
  4452. // 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.
  4453. data.sh.container.addDynamicProperty(data.sh);
  4454. var shapeData = {
  4455. shape: data.sh,
  4456. data: data,
  4457. localShapeCollection: shapeCollectionPool.newShapeCollection()
  4458. };
  4459. this.shapes.push(shapeData);
  4460. this.addShapeToModifier(shapeData);
  4461. if (this._isAnimated) {
  4462. data.setAsAnimated();
  4463. }
  4464. }
  4465. };
  4466. ShapeModifier.prototype.init = function (elem, data) {
  4467. this.shapes = [];
  4468. this.elem = elem;
  4469. this.initDynamicPropertyContainer(elem);
  4470. this.initModifierProperties(elem, data);
  4471. this.frameId = initialDefaultFrame;
  4472. this.closed = false;
  4473. this.k = false;
  4474. if (this.dynamicProperties.length) {
  4475. this.k = true;
  4476. } else {
  4477. this.getValue(true);
  4478. }
  4479. };
  4480. ShapeModifier.prototype.processKeys = function () {
  4481. if (this.elem.globalData.frameId === this.frameId) {
  4482. return;
  4483. }
  4484. this.frameId = this.elem.globalData.frameId;
  4485. this.iterateDynamicProperties();
  4486. };
  4487. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4488. function TrimModifier() {}
  4489. extendPrototype([ShapeModifier], TrimModifier);
  4490. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4491. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4492. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4493. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4494. this.sValue = 0;
  4495. this.eValue = 0;
  4496. this.getValue = this.processKeys;
  4497. this.m = data.m;
  4498. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4499. };
  4500. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4501. shapeData.pathsData = [];
  4502. };
  4503. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4504. var segments = [];
  4505. if (e <= 1) {
  4506. segments.push({
  4507. s: s,
  4508. e: e
  4509. });
  4510. } else if (s >= 1) {
  4511. segments.push({
  4512. s: s - 1,
  4513. e: e - 1
  4514. });
  4515. } else {
  4516. segments.push({
  4517. s: s,
  4518. e: 1
  4519. });
  4520. segments.push({
  4521. s: 0,
  4522. e: e - 1
  4523. });
  4524. }
  4525. var shapeSegments = [];
  4526. var i;
  4527. var len = segments.length;
  4528. var segmentOb;
  4529. for (i = 0; i < len; i += 1) {
  4530. segmentOb = segments[i];
  4531. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4532. var shapeS;
  4533. var shapeE;
  4534. if (segmentOb.s * totalModifierLength <= addedLength) {
  4535. shapeS = 0;
  4536. } else {
  4537. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4538. }
  4539. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4540. shapeE = 1;
  4541. } else {
  4542. shapeE = (segmentOb.e * totalModifierLength - addedLength) / shapeLength;
  4543. }
  4544. shapeSegments.push([shapeS, shapeE]);
  4545. }
  4546. }
  4547. if (!shapeSegments.length) {
  4548. shapeSegments.push([0, 0]);
  4549. }
  4550. return shapeSegments;
  4551. };
  4552. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4553. var i;
  4554. var len = pathsData.length;
  4555. for (i = 0; i < len; i += 1) {
  4556. segmentsLengthPool.release(pathsData[i]);
  4557. }
  4558. pathsData.length = 0;
  4559. return pathsData;
  4560. };
  4561. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4562. var s;
  4563. var e;
  4564. if (this._mdf || _isFirstFrame) {
  4565. var o = this.o.v % 360 / 360;
  4566. if (o < 0) {
  4567. o += 1;
  4568. }
  4569. if (this.s.v > 1) {
  4570. s = 1 + o;
  4571. } else if (this.s.v < 0) {
  4572. s = 0 + o;
  4573. } else {
  4574. s = this.s.v + o;
  4575. }
  4576. if (this.e.v > 1) {
  4577. e = 1 + o;
  4578. } else if (this.e.v < 0) {
  4579. e = 0 + o;
  4580. } else {
  4581. e = this.e.v + o;
  4582. }
  4583. if (s > e) {
  4584. var _s = s;
  4585. s = e;
  4586. e = _s;
  4587. }
  4588. s = Math.round(s * 10000) * 0.0001;
  4589. e = Math.round(e * 10000) * 0.0001;
  4590. this.sValue = s;
  4591. this.eValue = e;
  4592. } else {
  4593. s = this.sValue;
  4594. e = this.eValue;
  4595. }
  4596. var shapePaths;
  4597. var i;
  4598. var len = this.shapes.length;
  4599. var j;
  4600. var jLen;
  4601. var pathsData;
  4602. var pathData;
  4603. var totalShapeLength;
  4604. var totalModifierLength = 0;
  4605. if (e === s) {
  4606. for (i = 0; i < len; i += 1) {
  4607. this.shapes[i].localShapeCollection.releaseShapes();
  4608. this.shapes[i].shape._mdf = true;
  4609. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4610. if (this._mdf) {
  4611. this.shapes[i].pathsData.length = 0;
  4612. }
  4613. }
  4614. } else if (!(e === 1 && s === 0 || e === 0 && s === 1)) {
  4615. var segments = [];
  4616. var shapeData;
  4617. var localShapeCollection;
  4618. for (i = 0; i < len; i += 1) {
  4619. shapeData = this.shapes[i];
  4620. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4621. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4622. shapeData.shape.paths = shapeData.localShapeCollection;
  4623. } else {
  4624. shapePaths = shapeData.shape.paths;
  4625. jLen = shapePaths._length;
  4626. totalShapeLength = 0;
  4627. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4628. totalShapeLength = shapeData.totalShapeLength;
  4629. } else {
  4630. pathsData = this.releasePathsData(shapeData.pathsData);
  4631. for (j = 0; j < jLen; j += 1) {
  4632. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4633. pathsData.push(pathData);
  4634. totalShapeLength += pathData.totalLength;
  4635. }
  4636. shapeData.totalShapeLength = totalShapeLength;
  4637. shapeData.pathsData = pathsData;
  4638. }
  4639. totalModifierLength += totalShapeLength;
  4640. shapeData.shape._mdf = true;
  4641. }
  4642. }
  4643. var shapeS = s;
  4644. var shapeE = e;
  4645. var addedLength = 0;
  4646. var edges;
  4647. for (i = len - 1; i >= 0; i -= 1) {
  4648. shapeData = this.shapes[i];
  4649. if (shapeData.shape._mdf) {
  4650. localShapeCollection = shapeData.localShapeCollection;
  4651. localShapeCollection.releaseShapes();
  4652. // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4653. if (this.m === 2 && len > 1) {
  4654. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4655. addedLength += shapeData.totalShapeLength;
  4656. } else {
  4657. edges = [[shapeS, shapeE]];
  4658. }
  4659. jLen = edges.length;
  4660. for (j = 0; j < jLen; j += 1) {
  4661. shapeS = edges[j][0];
  4662. shapeE = edges[j][1];
  4663. segments.length = 0;
  4664. if (shapeE <= 1) {
  4665. segments.push({
  4666. s: shapeData.totalShapeLength * shapeS,
  4667. e: shapeData.totalShapeLength * shapeE
  4668. });
  4669. } else if (shapeS >= 1) {
  4670. segments.push({
  4671. s: shapeData.totalShapeLength * (shapeS - 1),
  4672. e: shapeData.totalShapeLength * (shapeE - 1)
  4673. });
  4674. } else {
  4675. segments.push({
  4676. s: shapeData.totalShapeLength * shapeS,
  4677. e: shapeData.totalShapeLength
  4678. });
  4679. segments.push({
  4680. s: 0,
  4681. e: shapeData.totalShapeLength * (shapeE - 1)
  4682. });
  4683. }
  4684. var newShapesData = this.addShapes(shapeData, segments[0]);
  4685. if (segments[0].s !== segments[0].e) {
  4686. if (segments.length > 1) {
  4687. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4688. if (lastShapeInCollection.c) {
  4689. var lastShape = newShapesData.pop();
  4690. this.addPaths(newShapesData, localShapeCollection);
  4691. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4692. } else {
  4693. this.addPaths(newShapesData, localShapeCollection);
  4694. newShapesData = this.addShapes(shapeData, segments[1]);
  4695. }
  4696. }
  4697. this.addPaths(newShapesData, localShapeCollection);
  4698. }
  4699. }
  4700. shapeData.shape.paths = localShapeCollection;
  4701. }
  4702. }
  4703. } else if (this._mdf) {
  4704. for (i = 0; i < len; i += 1) {
  4705. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4706. // Don't remove this even if it's losing cached info.
  4707. this.shapes[i].pathsData.length = 0;
  4708. this.shapes[i].shape._mdf = true;
  4709. }
  4710. }
  4711. };
  4712. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4713. var i;
  4714. var len = newPaths.length;
  4715. for (i = 0; i < len; i += 1) {
  4716. localShapeCollection.addShape(newPaths[i]);
  4717. }
  4718. };
  4719. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4720. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4721. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4722. if (newShape) {
  4723. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4724. }
  4725. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4726. };
  4727. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4728. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4729. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4730. if (newShape) {
  4731. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4732. }
  4733. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4734. };
  4735. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4736. var pathsData = shapeData.pathsData;
  4737. var shapePaths = shapeData.shape.paths.shapes;
  4738. var i;
  4739. var len = shapeData.shape.paths._length;
  4740. var j;
  4741. var jLen;
  4742. var addedLength = 0;
  4743. var currentLengthData;
  4744. var segmentCount;
  4745. var lengths;
  4746. var segment;
  4747. var shapes = [];
  4748. var initPos;
  4749. var newShape = true;
  4750. if (!shapePath) {
  4751. shapePath = shapePool.newElement();
  4752. segmentCount = 0;
  4753. initPos = 0;
  4754. } else {
  4755. segmentCount = shapePath._length;
  4756. initPos = shapePath._length;
  4757. }
  4758. shapes.push(shapePath);
  4759. for (i = 0; i < len; i += 1) {
  4760. lengths = pathsData[i].lengths;
  4761. shapePath.c = shapePaths[i].c;
  4762. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4763. for (j = 1; j < jLen; j += 1) {
  4764. currentLengthData = lengths[j - 1];
  4765. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4766. addedLength += currentLengthData.addedLength;
  4767. shapePath.c = false;
  4768. } else if (addedLength > shapeSegment.e) {
  4769. shapePath.c = false;
  4770. break;
  4771. } else {
  4772. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4773. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4774. newShape = false;
  4775. } else {
  4776. 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]);
  4777. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4778. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4779. newShape = false;
  4780. shapePath.c = false;
  4781. }
  4782. addedLength += currentLengthData.addedLength;
  4783. segmentCount += 1;
  4784. }
  4785. }
  4786. if (shapePaths[i].c && lengths.length) {
  4787. currentLengthData = lengths[j - 1];
  4788. if (addedLength <= shapeSegment.e) {
  4789. var segmentLength = lengths[j - 1].addedLength;
  4790. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4791. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4792. newShape = false;
  4793. } else {
  4794. 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]);
  4795. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4796. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4797. newShape = false;
  4798. shapePath.c = false;
  4799. }
  4800. } else {
  4801. shapePath.c = false;
  4802. }
  4803. addedLength += currentLengthData.addedLength;
  4804. segmentCount += 1;
  4805. }
  4806. if (shapePath._length) {
  4807. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4808. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4809. }
  4810. if (addedLength > shapeSegment.e) {
  4811. break;
  4812. }
  4813. if (i < len - 1) {
  4814. shapePath = shapePool.newElement();
  4815. newShape = true;
  4816. shapes.push(shapePath);
  4817. segmentCount = 0;
  4818. }
  4819. }
  4820. return shapes;
  4821. };
  4822. function PuckerAndBloatModifier() {}
  4823. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4824. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4825. this.getValue = this.processKeys;
  4826. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4827. this._isAnimated = !!this.amount.effectsSequence.length;
  4828. };
  4829. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4830. var percent = amount / 100;
  4831. var centerPoint = [0, 0];
  4832. var pathLength = path._length;
  4833. var i = 0;
  4834. for (i = 0; i < pathLength; i += 1) {
  4835. centerPoint[0] += path.v[i][0];
  4836. centerPoint[1] += path.v[i][1];
  4837. }
  4838. centerPoint[0] /= pathLength;
  4839. centerPoint[1] /= pathLength;
  4840. var clonedPath = shapePool.newElement();
  4841. clonedPath.c = path.c;
  4842. var vX;
  4843. var vY;
  4844. var oX;
  4845. var oY;
  4846. var iX;
  4847. var iY;
  4848. for (i = 0; i < pathLength; i += 1) {
  4849. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4850. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4851. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4852. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4853. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4854. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4855. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4856. }
  4857. return clonedPath;
  4858. };
  4859. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4860. var shapePaths;
  4861. var i;
  4862. var len = this.shapes.length;
  4863. var j;
  4864. var jLen;
  4865. var amount = this.amount.v;
  4866. if (amount !== 0) {
  4867. var shapeData;
  4868. var localShapeCollection;
  4869. for (i = 0; i < len; i += 1) {
  4870. shapeData = this.shapes[i];
  4871. localShapeCollection = shapeData.localShapeCollection;
  4872. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4873. localShapeCollection.releaseShapes();
  4874. shapeData.shape._mdf = true;
  4875. shapePaths = shapeData.shape.paths.shapes;
  4876. jLen = shapeData.shape.paths._length;
  4877. for (j = 0; j < jLen; j += 1) {
  4878. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4879. }
  4880. }
  4881. shapeData.shape.paths = shapeData.localShapeCollection;
  4882. }
  4883. }
  4884. if (!this.dynamicProperties.length) {
  4885. this._mdf = false;
  4886. }
  4887. };
  4888. var TransformPropertyFactory = function () {
  4889. var defaultVector = [0, 0];
  4890. function applyToMatrix(mat) {
  4891. var _mdf = this._mdf;
  4892. this.iterateDynamicProperties();
  4893. this._mdf = this._mdf || _mdf;
  4894. if (this.a) {
  4895. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4896. }
  4897. if (this.s) {
  4898. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4899. }
  4900. if (this.sk) {
  4901. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4902. }
  4903. if (this.r) {
  4904. mat.rotate(-this.r.v);
  4905. } else {
  4906. 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]);
  4907. }
  4908. if (this.data.p.s) {
  4909. if (this.data.p.z) {
  4910. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4911. } else {
  4912. mat.translate(this.px.v, this.py.v, 0);
  4913. }
  4914. } else {
  4915. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4916. }
  4917. }
  4918. function processKeys(forceRender) {
  4919. if (this.elem.globalData.frameId === this.frameId) {
  4920. return;
  4921. }
  4922. if (this._isDirty) {
  4923. this.precalculateMatrix();
  4924. this._isDirty = false;
  4925. }
  4926. this.iterateDynamicProperties();
  4927. if (this._mdf || forceRender) {
  4928. var frameRate;
  4929. this.v.cloneFromProps(this.pre.props);
  4930. if (this.appliedTransformations < 1) {
  4931. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4932. }
  4933. if (this.appliedTransformations < 2) {
  4934. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4935. }
  4936. if (this.sk && this.appliedTransformations < 3) {
  4937. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4938. }
  4939. if (this.r && this.appliedTransformations < 4) {
  4940. this.v.rotate(-this.r.v);
  4941. } else if (!this.r && this.appliedTransformations < 4) {
  4942. 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]);
  4943. }
  4944. if (this.autoOriented) {
  4945. var v1;
  4946. var v2;
  4947. frameRate = this.elem.globalData.frameRate;
  4948. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4949. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4950. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4951. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4952. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4953. v1 = this.p.getValueAtTime(this.p.keyframes[this.p.keyframes.length - 1].t / frameRate, 0);
  4954. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4955. } else {
  4956. v1 = this.p.pv;
  4957. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4958. }
  4959. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4960. v1 = [];
  4961. v2 = [];
  4962. var px = this.px;
  4963. var py = this.py;
  4964. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4965. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4966. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4967. v2[0] = px.getValueAtTime(px.keyframes[0].t / frameRate, 0);
  4968. v2[1] = py.getValueAtTime(py.keyframes[0].t / frameRate, 0);
  4969. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4970. v1[0] = px.getValueAtTime(px.keyframes[px.keyframes.length - 1].t / frameRate, 0);
  4971. v1[1] = py.getValueAtTime(py.keyframes[py.keyframes.length - 1].t / frameRate, 0);
  4972. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4973. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4974. } else {
  4975. v1 = [px.pv, py.pv];
  4976. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4977. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4978. }
  4979. } else {
  4980. v2 = defaultVector;
  4981. v1 = v2;
  4982. }
  4983. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4984. }
  4985. if (this.data.p && this.data.p.s) {
  4986. if (this.data.p.z) {
  4987. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4988. } else {
  4989. this.v.translate(this.px.v, this.py.v, 0);
  4990. }
  4991. } else {
  4992. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4993. }
  4994. }
  4995. this.frameId = this.elem.globalData.frameId;
  4996. }
  4997. function precalculateMatrix() {
  4998. this.appliedTransformations = 0;
  4999. this.pre.reset();
  5000. if (!this.a.effectsSequence.length) {
  5001. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  5002. this.appliedTransformations = 1;
  5003. } else {
  5004. return;
  5005. }
  5006. if (!this.s.effectsSequence.length) {
  5007. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  5008. this.appliedTransformations = 2;
  5009. } else {
  5010. return;
  5011. }
  5012. if (this.sk) {
  5013. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  5014. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  5015. this.appliedTransformations = 3;
  5016. } else {
  5017. return;
  5018. }
  5019. }
  5020. if (this.r) {
  5021. if (!this.r.effectsSequence.length) {
  5022. this.pre.rotate(-this.r.v);
  5023. this.appliedTransformations = 4;
  5024. }
  5025. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  5026. 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]);
  5027. this.appliedTransformations = 4;
  5028. }
  5029. }
  5030. function autoOrient() {
  5031. //
  5032. // var prevP = this.getValueAtTime();
  5033. }
  5034. function addDynamicProperty(prop) {
  5035. this._addDynamicProperty(prop);
  5036. this.elem.addDynamicProperty(prop);
  5037. this._isDirty = true;
  5038. }
  5039. function TransformProperty(elem, data, container) {
  5040. this.elem = elem;
  5041. this.frameId = -1;
  5042. this.propType = 'transform';
  5043. this.data = data;
  5044. this.v = new Matrix();
  5045. // Precalculated matrix with non animated properties
  5046. this.pre = new Matrix();
  5047. this.appliedTransformations = 0;
  5048. this.initDynamicPropertyContainer(container || elem);
  5049. if (data.p && data.p.s) {
  5050. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  5051. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  5052. if (data.p.z) {
  5053. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  5054. }
  5055. } else {
  5056. this.p = PropertyFactory.getProp(elem, data.p || {
  5057. k: [0, 0, 0]
  5058. }, 1, 0, this);
  5059. }
  5060. if (data.rx) {
  5061. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  5062. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  5063. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  5064. if (data.or.k[0].ti) {
  5065. var i;
  5066. var len = data.or.k.length;
  5067. for (i = 0; i < len; i += 1) {
  5068. data.or.k[i].to = null;
  5069. data.or.k[i].ti = null;
  5070. }
  5071. }
  5072. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  5073. // sh Indicates it needs to be capped between -180 and 180
  5074. this.or.sh = true;
  5075. } else {
  5076. this.r = PropertyFactory.getProp(elem, data.r || {
  5077. k: 0
  5078. }, 0, degToRads, this);
  5079. }
  5080. if (data.sk) {
  5081. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  5082. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  5083. }
  5084. this.a = PropertyFactory.getProp(elem, data.a || {
  5085. k: [0, 0, 0]
  5086. }, 1, 0, this);
  5087. this.s = PropertyFactory.getProp(elem, data.s || {
  5088. k: [100, 100, 100]
  5089. }, 1, 0.01, this);
  5090. // 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.
  5091. if (data.o) {
  5092. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  5093. } else {
  5094. this.o = {
  5095. _mdf: false,
  5096. v: 1
  5097. };
  5098. }
  5099. this._isDirty = true;
  5100. if (!this.dynamicProperties.length) {
  5101. this.getValue(true);
  5102. }
  5103. }
  5104. TransformProperty.prototype = {
  5105. applyToMatrix: applyToMatrix,
  5106. getValue: processKeys,
  5107. precalculateMatrix: precalculateMatrix,
  5108. autoOrient: autoOrient
  5109. };
  5110. extendPrototype([DynamicPropertyContainer], TransformProperty);
  5111. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  5112. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  5113. function getTransformProperty(elem, data, container) {
  5114. return new TransformProperty(elem, data, container);
  5115. }
  5116. return {
  5117. getTransformProperty: getTransformProperty
  5118. };
  5119. }();
  5120. function RepeaterModifier() {}
  5121. extendPrototype([ShapeModifier], RepeaterModifier);
  5122. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5123. this.getValue = this.processKeys;
  5124. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5125. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5126. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5127. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5128. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5129. this.data = data;
  5130. if (!this.dynamicProperties.length) {
  5131. this.getValue(true);
  5132. }
  5133. this._isAnimated = !!this.dynamicProperties.length;
  5134. this.pMatrix = new Matrix();
  5135. this.rMatrix = new Matrix();
  5136. this.sMatrix = new Matrix();
  5137. this.tMatrix = new Matrix();
  5138. this.matrix = new Matrix();
  5139. };
  5140. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5141. var dir = inv ? -1 : 1;
  5142. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5143. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5144. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5145. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5146. rMatrix.rotate(-transform.r.v * dir * perc);
  5147. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5148. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5149. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5150. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5151. };
  5152. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5153. this.elem = elem;
  5154. this.arr = arr;
  5155. this.pos = pos;
  5156. this.elemsData = elemsData;
  5157. this._currentCopies = 0;
  5158. this._elements = [];
  5159. this._groups = [];
  5160. this.frameId = -1;
  5161. this.initDynamicPropertyContainer(elem);
  5162. this.initModifierProperties(elem, arr[pos]);
  5163. while (pos > 0) {
  5164. pos -= 1;
  5165. // this._elements.unshift(arr.splice(pos,1)[0]);
  5166. this._elements.unshift(arr[pos]);
  5167. }
  5168. if (this.dynamicProperties.length) {
  5169. this.k = true;
  5170. } else {
  5171. this.getValue(true);
  5172. }
  5173. };
  5174. RepeaterModifier.prototype.resetElements = function (elements) {
  5175. var i;
  5176. var len = elements.length;
  5177. for (i = 0; i < len; i += 1) {
  5178. elements[i]._processed = false;
  5179. if (elements[i].ty === 'gr') {
  5180. this.resetElements(elements[i].it);
  5181. }
  5182. }
  5183. };
  5184. RepeaterModifier.prototype.cloneElements = function (elements) {
  5185. var newElements = JSON.parse(JSON.stringify(elements));
  5186. this.resetElements(newElements);
  5187. return newElements;
  5188. };
  5189. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5190. var i;
  5191. var len = elements.length;
  5192. for (i = 0; i < len; i += 1) {
  5193. elements[i]._render = renderFlag;
  5194. if (elements[i].ty === 'gr') {
  5195. this.changeGroupRender(elements[i].it, renderFlag);
  5196. }
  5197. }
  5198. };
  5199. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5200. var items;
  5201. var itemsTransform;
  5202. var i;
  5203. var dir;
  5204. var cont;
  5205. var hasReloaded = false;
  5206. if (this._mdf || _isFirstFrame) {
  5207. var copies = Math.ceil(this.c.v);
  5208. if (this._groups.length < copies) {
  5209. while (this._groups.length < copies) {
  5210. var group = {
  5211. it: this.cloneElements(this._elements),
  5212. ty: 'gr'
  5213. };
  5214. group.it.push({
  5215. a: {
  5216. a: 0,
  5217. ix: 1,
  5218. k: [0, 0]
  5219. },
  5220. nm: 'Transform',
  5221. o: {
  5222. a: 0,
  5223. ix: 7,
  5224. k: 100
  5225. },
  5226. p: {
  5227. a: 0,
  5228. ix: 2,
  5229. k: [0, 0]
  5230. },
  5231. r: {
  5232. a: 1,
  5233. ix: 6,
  5234. k: [{
  5235. s: 0,
  5236. e: 0,
  5237. t: 0
  5238. }, {
  5239. s: 0,
  5240. e: 0,
  5241. t: 1
  5242. }]
  5243. },
  5244. s: {
  5245. a: 0,
  5246. ix: 3,
  5247. k: [100, 100]
  5248. },
  5249. sa: {
  5250. a: 0,
  5251. ix: 5,
  5252. k: 0
  5253. },
  5254. sk: {
  5255. a: 0,
  5256. ix: 4,
  5257. k: 0
  5258. },
  5259. ty: 'tr'
  5260. });
  5261. this.arr.splice(0, 0, group);
  5262. this._groups.splice(0, 0, group);
  5263. this._currentCopies += 1;
  5264. }
  5265. this.elem.reloadShapes();
  5266. hasReloaded = true;
  5267. }
  5268. cont = 0;
  5269. var renderFlag;
  5270. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5271. renderFlag = cont < copies;
  5272. this._groups[i]._render = renderFlag;
  5273. this.changeGroupRender(this._groups[i].it, renderFlag);
  5274. if (!renderFlag) {
  5275. var elems = this.elemsData[i].it;
  5276. var transformData = elems[elems.length - 1];
  5277. if (transformData.transform.op.v !== 0) {
  5278. transformData.transform.op._mdf = true;
  5279. transformData.transform.op.v = 0;
  5280. } else {
  5281. transformData.transform.op._mdf = false;
  5282. }
  5283. }
  5284. cont += 1;
  5285. }
  5286. this._currentCopies = copies;
  5287. /// /
  5288. var offset = this.o.v;
  5289. var offsetModulo = offset % 1;
  5290. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5291. var pProps = this.pMatrix.props;
  5292. var rProps = this.rMatrix.props;
  5293. var sProps = this.sMatrix.props;
  5294. this.pMatrix.reset();
  5295. this.rMatrix.reset();
  5296. this.sMatrix.reset();
  5297. this.tMatrix.reset();
  5298. this.matrix.reset();
  5299. var iteration = 0;
  5300. if (offset > 0) {
  5301. while (iteration < roundOffset) {
  5302. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5303. iteration += 1;
  5304. }
  5305. if (offsetModulo) {
  5306. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5307. iteration += offsetModulo;
  5308. }
  5309. } else if (offset < 0) {
  5310. while (iteration > roundOffset) {
  5311. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5312. iteration -= 1;
  5313. }
  5314. if (offsetModulo) {
  5315. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5316. iteration -= offsetModulo;
  5317. }
  5318. }
  5319. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5320. dir = this.data.m === 1 ? 1 : -1;
  5321. cont = this._currentCopies;
  5322. var j;
  5323. var jLen;
  5324. while (cont) {
  5325. items = this.elemsData[i].it;
  5326. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5327. jLen = itemsTransform.length;
  5328. items[items.length - 1].transform.mProps._mdf = true;
  5329. items[items.length - 1].transform.op._mdf = true;
  5330. items[items.length - 1].transform.op.v = this._currentCopies === 1 ? this.so.v : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5331. if (iteration !== 0) {
  5332. if (i !== 0 && dir === 1 || i !== this._currentCopies - 1 && dir === -1) {
  5333. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5334. }
  5335. 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]);
  5336. 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]);
  5337. 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]);
  5338. for (j = 0; j < jLen; j += 1) {
  5339. itemsTransform[j] = this.matrix.props[j];
  5340. }
  5341. this.matrix.reset();
  5342. } else {
  5343. this.matrix.reset();
  5344. for (j = 0; j < jLen; j += 1) {
  5345. itemsTransform[j] = this.matrix.props[j];
  5346. }
  5347. }
  5348. iteration += 1;
  5349. cont -= 1;
  5350. i += dir;
  5351. }
  5352. } else {
  5353. cont = this._currentCopies;
  5354. i = 0;
  5355. dir = 1;
  5356. while (cont) {
  5357. items = this.elemsData[i].it;
  5358. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5359. items[items.length - 1].transform.mProps._mdf = false;
  5360. items[items.length - 1].transform.op._mdf = false;
  5361. cont -= 1;
  5362. i += dir;
  5363. }
  5364. }
  5365. return hasReloaded;
  5366. };
  5367. RepeaterModifier.prototype.addShape = function () {};
  5368. function RoundCornersModifier() {}
  5369. extendPrototype([ShapeModifier], RoundCornersModifier);
  5370. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5371. this.getValue = this.processKeys;
  5372. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5373. this._isAnimated = !!this.rd.effectsSequence.length;
  5374. };
  5375. RoundCornersModifier.prototype.processPath = function (path, round) {
  5376. var clonedPath = shapePool.newElement();
  5377. clonedPath.c = path.c;
  5378. var i;
  5379. var len = path._length;
  5380. var currentV;
  5381. var currentI;
  5382. var currentO;
  5383. var closerV;
  5384. var distance;
  5385. var newPosPerc;
  5386. var index = 0;
  5387. var vX;
  5388. var vY;
  5389. var oX;
  5390. var oY;
  5391. var iX;
  5392. var iY;
  5393. for (i = 0; i < len; i += 1) {
  5394. currentV = path.v[i];
  5395. currentO = path.o[i];
  5396. currentI = path.i[i];
  5397. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5398. if ((i === 0 || i === len - 1) && !path.c) {
  5399. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5400. /* clonedPath.v[index] = currentV;
  5401. clonedPath.o[index] = currentO;
  5402. clonedPath.i[index] = currentI; */
  5403. index += 1;
  5404. } else {
  5405. if (i === 0) {
  5406. closerV = path.v[len - 1];
  5407. } else {
  5408. closerV = path.v[i - 1];
  5409. }
  5410. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5411. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5412. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5413. vX = iX;
  5414. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5415. vY = iY;
  5416. oX = vX - (vX - currentV[0]) * roundCorner;
  5417. oY = vY - (vY - currentV[1]) * roundCorner;
  5418. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5419. index += 1;
  5420. if (i === len - 1) {
  5421. closerV = path.v[0];
  5422. } else {
  5423. closerV = path.v[i + 1];
  5424. }
  5425. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5426. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5427. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5428. vX = oX;
  5429. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5430. vY = oY;
  5431. iX = vX - (vX - currentV[0]) * roundCorner;
  5432. iY = vY - (vY - currentV[1]) * roundCorner;
  5433. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5434. index += 1;
  5435. }
  5436. } else {
  5437. clonedPath.setTripleAt(path.v[i][0], path.v[i][1], path.o[i][0], path.o[i][1], path.i[i][0], path.i[i][1], index);
  5438. index += 1;
  5439. }
  5440. }
  5441. return clonedPath;
  5442. };
  5443. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5444. var shapePaths;
  5445. var i;
  5446. var len = this.shapes.length;
  5447. var j;
  5448. var jLen;
  5449. var rd = this.rd.v;
  5450. if (rd !== 0) {
  5451. var shapeData;
  5452. var localShapeCollection;
  5453. for (i = 0; i < len; i += 1) {
  5454. shapeData = this.shapes[i];
  5455. localShapeCollection = shapeData.localShapeCollection;
  5456. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5457. localShapeCollection.releaseShapes();
  5458. shapeData.shape._mdf = true;
  5459. shapePaths = shapeData.shape.paths.shapes;
  5460. jLen = shapeData.shape.paths._length;
  5461. for (j = 0; j < jLen; j += 1) {
  5462. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5463. }
  5464. }
  5465. shapeData.shape.paths = shapeData.localShapeCollection;
  5466. }
  5467. }
  5468. if (!this.dynamicProperties.length) {
  5469. this._mdf = false;
  5470. }
  5471. };
  5472. function floatEqual(a, b) {
  5473. return Math.abs(a - b) * 100000 <= Math.min(Math.abs(a), Math.abs(b));
  5474. }
  5475. function floatZero(f) {
  5476. return Math.abs(f) <= 0.00001;
  5477. }
  5478. function lerp(p0, p1, amount) {
  5479. return p0 * (1 - amount) + p1 * amount;
  5480. }
  5481. function lerpPoint(p0, p1, amount) {
  5482. return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
  5483. }
  5484. function quadRoots(a, b, c) {
  5485. // no root
  5486. if (a === 0) return [];
  5487. var s = b * b - 4 * a * c;
  5488. // Complex roots
  5489. if (s < 0) return [];
  5490. var singleRoot = -b / (2 * a);
  5491. // 1 root
  5492. if (s === 0) return [singleRoot];
  5493. var delta = Math.sqrt(s) / (2 * a);
  5494. // 2 roots
  5495. return [singleRoot - delta, singleRoot + delta];
  5496. }
  5497. function polynomialCoefficients(p0, p1, p2, p3) {
  5498. return [-p0 + 3 * p1 - 3 * p2 + p3, 3 * p0 - 6 * p1 + 3 * p2, -3 * p0 + 3 * p1, p0];
  5499. }
  5500. function singlePoint(p) {
  5501. return new PolynomialBezier(p, p, p, p, false);
  5502. }
  5503. function PolynomialBezier(p0, p1, p2, p3, linearize) {
  5504. if (linearize && pointEqual(p0, p1)) {
  5505. p1 = lerpPoint(p0, p3, 1 / 3);
  5506. }
  5507. if (linearize && pointEqual(p2, p3)) {
  5508. p2 = lerpPoint(p0, p3, 2 / 3);
  5509. }
  5510. var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
  5511. var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
  5512. this.a = [coeffx[0], coeffy[0]];
  5513. this.b = [coeffx[1], coeffy[1]];
  5514. this.c = [coeffx[2], coeffy[2]];
  5515. this.d = [coeffx[3], coeffy[3]];
  5516. this.points = [p0, p1, p2, p3];
  5517. }
  5518. PolynomialBezier.prototype.point = function (t) {
  5519. return [((this.a[0] * t + this.b[0]) * t + this.c[0]) * t + this.d[0], ((this.a[1] * t + this.b[1]) * t + this.c[1]) * t + this.d[1]];
  5520. };
  5521. PolynomialBezier.prototype.derivative = function (t) {
  5522. return [(3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0], (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1]];
  5523. };
  5524. PolynomialBezier.prototype.tangentAngle = function (t) {
  5525. var p = this.derivative(t);
  5526. return Math.atan2(p[1], p[0]);
  5527. };
  5528. PolynomialBezier.prototype.normalAngle = function (t) {
  5529. var p = this.derivative(t);
  5530. return Math.atan2(p[0], p[1]);
  5531. };
  5532. PolynomialBezier.prototype.inflectionPoints = function () {
  5533. var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
  5534. if (floatZero(denom)) return [];
  5535. var tcusp = -0.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1]) / denom;
  5536. var square = tcusp * tcusp - 1 / 3 * (this.b[1] * this.c[0] - this.b[0] * this.c[1]) / denom;
  5537. if (square < 0) return [];
  5538. var root = Math.sqrt(square);
  5539. if (floatZero(root)) {
  5540. if (root > 0 && root < 1) return [tcusp];
  5541. return [];
  5542. }
  5543. return [tcusp - root, tcusp + root].filter(function (r) {
  5544. return r > 0 && r < 1;
  5545. });
  5546. };
  5547. PolynomialBezier.prototype.split = function (t) {
  5548. if (t <= 0) return [singlePoint(this.points[0]), this];
  5549. if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
  5550. var p10 = lerpPoint(this.points[0], this.points[1], t);
  5551. var p11 = lerpPoint(this.points[1], this.points[2], t);
  5552. var p12 = lerpPoint(this.points[2], this.points[3], t);
  5553. var p20 = lerpPoint(p10, p11, t);
  5554. var p21 = lerpPoint(p11, p12, t);
  5555. var p3 = lerpPoint(p20, p21, t);
  5556. return [new PolynomialBezier(this.points[0], p10, p20, p3, true), new PolynomialBezier(p3, p21, p12, this.points[3], true)];
  5557. };
  5558. function extrema(bez, comp) {
  5559. var min = bez.points[0][comp];
  5560. var max = bez.points[bez.points.length - 1][comp];
  5561. if (min > max) {
  5562. var e = max;
  5563. max = min;
  5564. min = e;
  5565. }
  5566. // Derivative roots to find min/max
  5567. var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
  5568. for (var i = 0; i < f.length; i += 1) {
  5569. if (f[i] > 0 && f[i] < 1) {
  5570. var val = bez.point(f[i])[comp];
  5571. if (val < min) min = val;else if (val > max) max = val;
  5572. }
  5573. }
  5574. return {
  5575. min: min,
  5576. max: max
  5577. };
  5578. }
  5579. PolynomialBezier.prototype.bounds = function () {
  5580. return {
  5581. x: extrema(this, 0),
  5582. y: extrema(this, 1)
  5583. };
  5584. };
  5585. PolynomialBezier.prototype.boundingBox = function () {
  5586. var bounds = this.bounds();
  5587. return {
  5588. left: bounds.x.min,
  5589. right: bounds.x.max,
  5590. top: bounds.y.min,
  5591. bottom: bounds.y.max,
  5592. width: bounds.x.max - bounds.x.min,
  5593. height: bounds.y.max - bounds.y.min,
  5594. cx: (bounds.x.max + bounds.x.min) / 2,
  5595. cy: (bounds.y.max + bounds.y.min) / 2
  5596. };
  5597. };
  5598. function intersectData(bez, t1, t2) {
  5599. var box = bez.boundingBox();
  5600. return {
  5601. cx: box.cx,
  5602. cy: box.cy,
  5603. width: box.width,
  5604. height: box.height,
  5605. bez: bez,
  5606. t: (t1 + t2) / 2,
  5607. t1: t1,
  5608. t2: t2
  5609. };
  5610. }
  5611. function splitData(data) {
  5612. var split = data.bez.split(0.5);
  5613. return [intersectData(split[0], data.t1, data.t), intersectData(split[1], data.t, data.t2)];
  5614. }
  5615. function boxIntersect(b1, b2) {
  5616. return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
  5617. }
  5618. function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
  5619. if (!boxIntersect(d1, d2)) return;
  5620. if (depth >= maxRecursion || d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance) {
  5621. intersections.push([d1.t, d2.t]);
  5622. return;
  5623. }
  5624. var d1s = splitData(d1);
  5625. var d2s = splitData(d2);
  5626. intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5627. intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5628. intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5629. intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5630. }
  5631. PolynomialBezier.prototype.intersections = function (other, tolerance, maxRecursion) {
  5632. if (tolerance === undefined) tolerance = 2;
  5633. if (maxRecursion === undefined) maxRecursion = 7;
  5634. var intersections = [];
  5635. intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
  5636. return intersections;
  5637. };
  5638. PolynomialBezier.shapeSegment = function (shapePath, index) {
  5639. var nextIndex = (index + 1) % shapePath.length();
  5640. return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
  5641. };
  5642. PolynomialBezier.shapeSegmentInverted = function (shapePath, index) {
  5643. var nextIndex = (index + 1) % shapePath.length();
  5644. return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
  5645. };
  5646. function crossProduct(a, b) {
  5647. return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
  5648. }
  5649. function lineIntersection(start1, end1, start2, end2) {
  5650. var v1 = [start1[0], start1[1], 1];
  5651. var v2 = [end1[0], end1[1], 1];
  5652. var v3 = [start2[0], start2[1], 1];
  5653. var v4 = [end2[0], end2[1], 1];
  5654. var r = crossProduct(crossProduct(v1, v2), crossProduct(v3, v4));
  5655. if (floatZero(r[2])) return null;
  5656. return [r[0] / r[2], r[1] / r[2]];
  5657. }
  5658. function polarOffset(p, angle, length) {
  5659. return [p[0] + Math.cos(angle) * length, p[1] - Math.sin(angle) * length];
  5660. }
  5661. function pointDistance(p1, p2) {
  5662. return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
  5663. }
  5664. function pointEqual(p1, p2) {
  5665. return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
  5666. }
  5667. function ZigZagModifier() {}
  5668. extendPrototype([ShapeModifier], ZigZagModifier);
  5669. ZigZagModifier.prototype.initModifierProperties = function (elem, data) {
  5670. this.getValue = this.processKeys;
  5671. this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
  5672. this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5673. this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
  5674. this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
  5675. };
  5676. function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
  5677. var angO = angle - Math.PI / 2;
  5678. var angI = angle + Math.PI / 2;
  5679. var px = point[0] + Math.cos(angle) * direction * amplitude;
  5680. var py = point[1] - Math.sin(angle) * direction * amplitude;
  5681. outputBezier.setTripleAt(px, py, px + Math.cos(angO) * outAmplitude, py - Math.sin(angO) * outAmplitude, px + Math.cos(angI) * inAmplitude, py - Math.sin(angI) * inAmplitude, outputBezier.length());
  5682. }
  5683. function getPerpendicularVector(pt1, pt2) {
  5684. var vector = [pt2[0] - pt1[0], pt2[1] - pt1[1]];
  5685. var rot = -Math.PI * 0.5;
  5686. var rotatedVector = [Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1], Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1]];
  5687. return rotatedVector;
  5688. }
  5689. function getProjectingAngle(path, cur) {
  5690. var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
  5691. var nextIndex = (cur + 1) % path.length();
  5692. var prevPoint = path.v[prevIndex];
  5693. var nextPoint = path.v[nextIndex];
  5694. var pVector = getPerpendicularVector(prevPoint, nextPoint);
  5695. return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
  5696. }
  5697. function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
  5698. var angle = getProjectingAngle(path, cur);
  5699. var point = path.v[cur % path._length];
  5700. var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
  5701. var nextPoint = path.v[(cur + 1) % path._length];
  5702. var prevDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2)) : 0;
  5703. var nextDist = pointType === 2 ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2)) : 0;
  5704. setPoint(outputBezier, path.v[cur % path._length], angle, direction, amplitude, nextDist / ((frequency + 1) * 2), prevDist / ((frequency + 1) * 2), pointType);
  5705. }
  5706. function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
  5707. for (var i = 0; i < frequency; i += 1) {
  5708. var t = (i + 1) / (frequency + 1);
  5709. var dist = pointType === 2 ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2)) : 0;
  5710. var angle = segment.normalAngle(t);
  5711. var point = segment.point(t);
  5712. setPoint(outputBezier, point, angle, direction, amplitude, dist / ((frequency + 1) * 2), dist / ((frequency + 1) * 2), pointType);
  5713. direction = -direction;
  5714. }
  5715. return direction;
  5716. }
  5717. ZigZagModifier.prototype.processPath = function (path, amplitude, frequency, pointType) {
  5718. var count = path._length;
  5719. var clonedPath = shapePool.newElement();
  5720. clonedPath.c = path.c;
  5721. if (!path.c) {
  5722. count -= 1;
  5723. }
  5724. if (count === 0) return clonedPath;
  5725. var direction = -1;
  5726. var segment = PolynomialBezier.shapeSegment(path, 0);
  5727. zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
  5728. for (var i = 0; i < count; i += 1) {
  5729. direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
  5730. if (i === count - 1 && !path.c) {
  5731. segment = null;
  5732. } else {
  5733. segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
  5734. }
  5735. zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
  5736. }
  5737. return clonedPath;
  5738. };
  5739. ZigZagModifier.prototype.processShapes = function (_isFirstFrame) {
  5740. var shapePaths;
  5741. var i;
  5742. var len = this.shapes.length;
  5743. var j;
  5744. var jLen;
  5745. var amplitude = this.amplitude.v;
  5746. var frequency = Math.max(0, Math.round(this.frequency.v));
  5747. var pointType = this.pointsType.v;
  5748. if (amplitude !== 0) {
  5749. var shapeData;
  5750. var localShapeCollection;
  5751. for (i = 0; i < len; i += 1) {
  5752. shapeData = this.shapes[i];
  5753. localShapeCollection = shapeData.localShapeCollection;
  5754. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5755. localShapeCollection.releaseShapes();
  5756. shapeData.shape._mdf = true;
  5757. shapePaths = shapeData.shape.paths.shapes;
  5758. jLen = shapeData.shape.paths._length;
  5759. for (j = 0; j < jLen; j += 1) {
  5760. localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
  5761. }
  5762. }
  5763. shapeData.shape.paths = shapeData.localShapeCollection;
  5764. }
  5765. }
  5766. if (!this.dynamicProperties.length) {
  5767. this._mdf = false;
  5768. }
  5769. };
  5770. function linearOffset(p1, p2, amount) {
  5771. var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
  5772. return [polarOffset(p1, angle, amount), polarOffset(p2, angle, amount)];
  5773. }
  5774. function offsetSegment(segment, amount) {
  5775. var p0;
  5776. var p1a;
  5777. var p1b;
  5778. var p2b;
  5779. var p2a;
  5780. var p3;
  5781. var e;
  5782. e = linearOffset(segment.points[0], segment.points[1], amount);
  5783. p0 = e[0];
  5784. p1a = e[1];
  5785. e = linearOffset(segment.points[1], segment.points[2], amount);
  5786. p1b = e[0];
  5787. p2b = e[1];
  5788. e = linearOffset(segment.points[2], segment.points[3], amount);
  5789. p2a = e[0];
  5790. p3 = e[1];
  5791. var p1 = lineIntersection(p0, p1a, p1b, p2b);
  5792. if (p1 === null) p1 = p1a;
  5793. var p2 = lineIntersection(p2a, p3, p1b, p2b);
  5794. if (p2 === null) p2 = p2a;
  5795. return new PolynomialBezier(p0, p1, p2, p3);
  5796. }
  5797. function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
  5798. var p0 = seg1.points[3];
  5799. var p1 = seg2.points[0];
  5800. // Bevel
  5801. if (lineJoin === 3) return p0;
  5802. // Connected, they don't need a joint
  5803. if (pointEqual(p0, p1)) return p0;
  5804. // Round
  5805. if (lineJoin === 2) {
  5806. var angleOut = -seg1.tangentAngle(1);
  5807. var angleIn = -seg2.tangentAngle(0) + Math.PI;
  5808. var center = lineIntersection(p0, polarOffset(p0, angleOut + Math.PI / 2, 100), p1, polarOffset(p1, angleOut + Math.PI / 2, 100));
  5809. var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
  5810. var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
  5811. outputBezier.setXYAt(tan[0], tan[1], 'o', outputBezier.length() - 1);
  5812. tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
  5813. outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
  5814. return p1;
  5815. }
  5816. // Miter
  5817. var t0 = pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2];
  5818. var t1 = pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1];
  5819. var intersection = lineIntersection(t0, p0, p1, t1);
  5820. if (intersection && pointDistance(intersection, p0) < miterLimit) {
  5821. outputBezier.setTripleAt(intersection[0], intersection[1], intersection[0], intersection[1], intersection[0], intersection[1], outputBezier.length());
  5822. return intersection;
  5823. }
  5824. return p0;
  5825. }
  5826. function getIntersection(a, b) {
  5827. var intersect = a.intersections(b);
  5828. if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
  5829. if (intersect.length) return intersect[0];
  5830. return null;
  5831. }
  5832. function pruneSegmentIntersection(a, b) {
  5833. var outa = a.slice();
  5834. var outb = b.slice();
  5835. var intersect = getIntersection(a[a.length - 1], b[0]);
  5836. if (intersect) {
  5837. outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
  5838. outb[0] = b[0].split(intersect[1])[1];
  5839. }
  5840. if (a.length > 1 && b.length > 1) {
  5841. intersect = getIntersection(a[0], b[b.length - 1]);
  5842. if (intersect) {
  5843. return [[a[0].split(intersect[0])[0]], [b[b.length - 1].split(intersect[1])[1]]];
  5844. }
  5845. }
  5846. return [outa, outb];
  5847. }
  5848. function pruneIntersections(segments) {
  5849. var e;
  5850. for (var i = 1; i < segments.length; i += 1) {
  5851. e = pruneSegmentIntersection(segments[i - 1], segments[i]);
  5852. segments[i - 1] = e[0];
  5853. segments[i] = e[1];
  5854. }
  5855. if (segments.length > 1) {
  5856. e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
  5857. segments[segments.length - 1] = e[0];
  5858. segments[0] = e[1];
  5859. }
  5860. return segments;
  5861. }
  5862. function offsetSegmentSplit(segment, amount) {
  5863. /*
  5864. We split each bezier segment into smaller pieces based
  5865. on inflection points, this ensures the control point
  5866. polygon is convex.
  5867. (A cubic bezier can have none, one, or two inflection points)
  5868. */
  5869. var flex = segment.inflectionPoints();
  5870. var left;
  5871. var right;
  5872. var split;
  5873. var mid;
  5874. if (flex.length === 0) {
  5875. return [offsetSegment(segment, amount)];
  5876. }
  5877. if (flex.length === 1 || floatEqual(flex[1], 1)) {
  5878. split = segment.split(flex[0]);
  5879. left = split[0];
  5880. right = split[1];
  5881. return [offsetSegment(left, amount), offsetSegment(right, amount)];
  5882. }
  5883. split = segment.split(flex[0]);
  5884. left = split[0];
  5885. var t = (flex[1] - flex[0]) / (1 - flex[0]);
  5886. split = split[1].split(t);
  5887. mid = split[0];
  5888. right = split[1];
  5889. return [offsetSegment(left, amount), offsetSegment(mid, amount), offsetSegment(right, amount)];
  5890. }
  5891. function OffsetPathModifier() {}
  5892. extendPrototype([ShapeModifier], OffsetPathModifier);
  5893. OffsetPathModifier.prototype.initModifierProperties = function (elem, data) {
  5894. this.getValue = this.processKeys;
  5895. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  5896. this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
  5897. this.lineJoin = data.lj;
  5898. this._isAnimated = this.amount.effectsSequence.length !== 0;
  5899. };
  5900. OffsetPathModifier.prototype.processPath = function (inputBezier, amount, lineJoin, miterLimit) {
  5901. var outputBezier = shapePool.newElement();
  5902. outputBezier.c = inputBezier.c;
  5903. var count = inputBezier.length();
  5904. if (!inputBezier.c) {
  5905. count -= 1;
  5906. }
  5907. var i;
  5908. var j;
  5909. var segment;
  5910. var multiSegments = [];
  5911. for (i = 0; i < count; i += 1) {
  5912. segment = PolynomialBezier.shapeSegment(inputBezier, i);
  5913. multiSegments.push(offsetSegmentSplit(segment, amount));
  5914. }
  5915. if (!inputBezier.c) {
  5916. for (i = count - 1; i >= 0; i -= 1) {
  5917. segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
  5918. multiSegments.push(offsetSegmentSplit(segment, amount));
  5919. }
  5920. }
  5921. multiSegments = pruneIntersections(multiSegments);
  5922. // Add bezier segments to the output and apply line joints
  5923. var lastPoint = null;
  5924. var lastSeg = null;
  5925. for (i = 0; i < multiSegments.length; i += 1) {
  5926. var multiSegment = multiSegments[i];
  5927. if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
  5928. lastSeg = multiSegment[multiSegment.length - 1];
  5929. for (j = 0; j < multiSegment.length; j += 1) {
  5930. segment = multiSegment[j];
  5931. if (lastPoint && pointEqual(segment.points[0], lastPoint)) {
  5932. outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], 'o', outputBezier.length() - 1);
  5933. } else {
  5934. outputBezier.setTripleAt(segment.points[0][0], segment.points[0][1], segment.points[1][0], segment.points[1][1], segment.points[0][0], segment.points[0][1], outputBezier.length());
  5935. }
  5936. outputBezier.setTripleAt(segment.points[3][0], segment.points[3][1], segment.points[3][0], segment.points[3][1], segment.points[2][0], segment.points[2][1], outputBezier.length());
  5937. lastPoint = segment.points[3];
  5938. }
  5939. }
  5940. if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
  5941. return outputBezier;
  5942. };
  5943. OffsetPathModifier.prototype.processShapes = function (_isFirstFrame) {
  5944. var shapePaths;
  5945. var i;
  5946. var len = this.shapes.length;
  5947. var j;
  5948. var jLen;
  5949. var amount = this.amount.v;
  5950. var miterLimit = this.miterLimit.v;
  5951. var lineJoin = this.lineJoin;
  5952. if (amount !== 0) {
  5953. var shapeData;
  5954. var localShapeCollection;
  5955. for (i = 0; i < len; i += 1) {
  5956. shapeData = this.shapes[i];
  5957. localShapeCollection = shapeData.localShapeCollection;
  5958. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5959. localShapeCollection.releaseShapes();
  5960. shapeData.shape._mdf = true;
  5961. shapePaths = shapeData.shape.paths.shapes;
  5962. jLen = shapeData.shape.paths._length;
  5963. for (j = 0; j < jLen; j += 1) {
  5964. localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
  5965. }
  5966. }
  5967. shapeData.shape.paths = shapeData.localShapeCollection;
  5968. }
  5969. }
  5970. if (!this.dynamicProperties.length) {
  5971. this._mdf = false;
  5972. }
  5973. };
  5974. function getFontProperties(fontData) {
  5975. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5976. var fWeight = 'normal';
  5977. var fStyle = 'normal';
  5978. var len = styles.length;
  5979. var styleName;
  5980. for (var i = 0; i < len; i += 1) {
  5981. styleName = styles[i].toLowerCase();
  5982. switch (styleName) {
  5983. case 'italic':
  5984. fStyle = 'italic';
  5985. break;
  5986. case 'bold':
  5987. fWeight = '700';
  5988. break;
  5989. case 'black':
  5990. fWeight = '900';
  5991. break;
  5992. case 'medium':
  5993. fWeight = '500';
  5994. break;
  5995. case 'regular':
  5996. case 'normal':
  5997. fWeight = '400';
  5998. break;
  5999. case 'light':
  6000. case 'thin':
  6001. fWeight = '200';
  6002. break;
  6003. default:
  6004. break;
  6005. }
  6006. }
  6007. return {
  6008. style: fStyle,
  6009. weight: fontData.fWeight || fWeight
  6010. };
  6011. }
  6012. var FontManager = function () {
  6013. var maxWaitingTime = 5000;
  6014. var emptyChar = {
  6015. w: 0,
  6016. size: 0,
  6017. shapes: [],
  6018. data: {
  6019. shapes: []
  6020. }
  6021. };
  6022. var combinedCharacters = [];
  6023. // Hindi characters
  6024. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366, 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379, 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  6025. var BLACK_FLAG_CODE_POINT = 127988;
  6026. var CANCEL_TAG_CODE_POINT = 917631;
  6027. var A_TAG_CODE_POINT = 917601;
  6028. var Z_TAG_CODE_POINT = 917626;
  6029. var VARIATION_SELECTOR_16_CODE_POINT = 65039;
  6030. var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
  6031. var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
  6032. var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
  6033. var surrogateModifiers = ['d83cdffb', 'd83cdffc', 'd83cdffd', 'd83cdffe', 'd83cdfff'];
  6034. function trimFontOptions(font) {
  6035. var familyArray = font.split(',');
  6036. var i;
  6037. var len = familyArray.length;
  6038. var enabledFamilies = [];
  6039. for (i = 0; i < len; i += 1) {
  6040. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  6041. enabledFamilies.push(familyArray[i]);
  6042. }
  6043. }
  6044. return enabledFamilies.join(',');
  6045. }
  6046. function setUpNode(font, family) {
  6047. var parentNode = createTag('span');
  6048. // Node is invisible to screen readers.
  6049. parentNode.setAttribute('aria-hidden', true);
  6050. parentNode.style.fontFamily = family;
  6051. var node = createTag('span');
  6052. // Characters that vary significantly among different fonts
  6053. node.innerText = 'giItT1WQy@!-/#';
  6054. // Visible - so we can measure it - but not on the screen
  6055. parentNode.style.position = 'absolute';
  6056. parentNode.style.left = '-10000px';
  6057. parentNode.style.top = '-10000px';
  6058. // Large font size makes even subtle changes obvious
  6059. parentNode.style.fontSize = '300px';
  6060. // Reset any font properties
  6061. parentNode.style.fontVariant = 'normal';
  6062. parentNode.style.fontStyle = 'normal';
  6063. parentNode.style.fontWeight = 'normal';
  6064. parentNode.style.letterSpacing = '0';
  6065. parentNode.appendChild(node);
  6066. document.body.appendChild(parentNode);
  6067. // Remember width with no applied web font
  6068. var width = node.offsetWidth;
  6069. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  6070. return {
  6071. node: node,
  6072. w: width,
  6073. parent: parentNode
  6074. };
  6075. }
  6076. function checkLoadedFonts() {
  6077. var i;
  6078. var len = this.fonts.length;
  6079. var node;
  6080. var w;
  6081. var loadedCount = len;
  6082. for (i = 0; i < len; i += 1) {
  6083. if (this.fonts[i].loaded) {
  6084. loadedCount -= 1;
  6085. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  6086. this.fonts[i].loaded = true;
  6087. } else {
  6088. node = this.fonts[i].monoCase.node;
  6089. w = this.fonts[i].monoCase.w;
  6090. if (node.offsetWidth !== w) {
  6091. loadedCount -= 1;
  6092. this.fonts[i].loaded = true;
  6093. } else {
  6094. node = this.fonts[i].sansCase.node;
  6095. w = this.fonts[i].sansCase.w;
  6096. if (node.offsetWidth !== w) {
  6097. loadedCount -= 1;
  6098. this.fonts[i].loaded = true;
  6099. }
  6100. }
  6101. if (this.fonts[i].loaded) {
  6102. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  6103. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  6104. }
  6105. }
  6106. }
  6107. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  6108. setTimeout(this.checkLoadedFontsBinded, 20);
  6109. } else {
  6110. setTimeout(this.setIsLoadedBinded, 10);
  6111. }
  6112. }
  6113. function createHelper(fontData, def) {
  6114. var engine = document.body && def ? 'svg' : 'canvas';
  6115. var helper;
  6116. var fontProps = getFontProperties(fontData);
  6117. if (engine === 'svg') {
  6118. var tHelper = createNS('text');
  6119. tHelper.style.fontSize = '100px';
  6120. // tHelper.style.fontFamily = fontData.fFamily;
  6121. tHelper.setAttribute('font-family', fontData.fFamily);
  6122. tHelper.setAttribute('font-style', fontProps.style);
  6123. tHelper.setAttribute('font-weight', fontProps.weight);
  6124. tHelper.textContent = '1';
  6125. if (fontData.fClass) {
  6126. tHelper.style.fontFamily = 'inherit';
  6127. tHelper.setAttribute('class', fontData.fClass);
  6128. } else {
  6129. tHelper.style.fontFamily = fontData.fFamily;
  6130. }
  6131. def.appendChild(tHelper);
  6132. helper = tHelper;
  6133. } else {
  6134. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  6135. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  6136. helper = tCanvasHelper;
  6137. }
  6138. function measure(text) {
  6139. if (engine === 'svg') {
  6140. helper.textContent = text;
  6141. return helper.getComputedTextLength();
  6142. }
  6143. return helper.measureText(text).width;
  6144. }
  6145. return {
  6146. measureText: measure
  6147. };
  6148. }
  6149. function addFonts(fontData, defs) {
  6150. if (!fontData) {
  6151. this.isLoaded = true;
  6152. return;
  6153. }
  6154. if (this.chars) {
  6155. this.isLoaded = true;
  6156. this.fonts = fontData.list;
  6157. return;
  6158. }
  6159. if (!document.body) {
  6160. this.isLoaded = true;
  6161. fontData.list.forEach(function (data) {
  6162. data.helper = createHelper(data);
  6163. data.cache = {};
  6164. });
  6165. this.fonts = fontData.list;
  6166. return;
  6167. }
  6168. var fontArr = fontData.list;
  6169. var i;
  6170. var len = fontArr.length;
  6171. var _pendingFonts = len;
  6172. for (i = 0; i < len; i += 1) {
  6173. var shouldLoadFont = true;
  6174. var loadedSelector;
  6175. var j;
  6176. fontArr[i].loaded = false;
  6177. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  6178. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  6179. if (!fontArr[i].fPath) {
  6180. fontArr[i].loaded = true;
  6181. _pendingFonts -= 1;
  6182. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  6183. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  6184. if (loadedSelector.length > 0) {
  6185. shouldLoadFont = false;
  6186. }
  6187. if (shouldLoadFont) {
  6188. var s = createTag('style');
  6189. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  6190. s.setAttribute('f-origin', fontArr[i].origin);
  6191. s.setAttribute('f-family', fontArr[i].fFamily);
  6192. s.type = 'text/css';
  6193. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  6194. defs.appendChild(s);
  6195. }
  6196. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  6197. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  6198. for (j = 0; j < loadedSelector.length; j += 1) {
  6199. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  6200. // Font is already loaded
  6201. shouldLoadFont = false;
  6202. }
  6203. }
  6204. if (shouldLoadFont) {
  6205. var l = createTag('link');
  6206. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  6207. l.setAttribute('f-origin', fontArr[i].origin);
  6208. l.type = 'text/css';
  6209. l.rel = 'stylesheet';
  6210. l.href = fontArr[i].fPath;
  6211. document.body.appendChild(l);
  6212. }
  6213. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  6214. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  6215. for (j = 0; j < loadedSelector.length; j += 1) {
  6216. if (fontArr[i].fPath === loadedSelector[j].src) {
  6217. // Font is already loaded
  6218. shouldLoadFont = false;
  6219. }
  6220. }
  6221. if (shouldLoadFont) {
  6222. var sc = createTag('link');
  6223. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  6224. sc.setAttribute('f-origin', fontArr[i].origin);
  6225. sc.setAttribute('rel', 'stylesheet');
  6226. sc.setAttribute('href', fontArr[i].fPath);
  6227. defs.appendChild(sc);
  6228. }
  6229. }
  6230. fontArr[i].helper = createHelper(fontArr[i], defs);
  6231. fontArr[i].cache = {};
  6232. this.fonts.push(fontArr[i]);
  6233. }
  6234. if (_pendingFonts === 0) {
  6235. this.isLoaded = true;
  6236. } else {
  6237. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  6238. // Adding this timeout seems to fix it
  6239. setTimeout(this.checkLoadedFonts.bind(this), 100);
  6240. }
  6241. }
  6242. function addChars(chars) {
  6243. if (!chars) {
  6244. return;
  6245. }
  6246. if (!this.chars) {
  6247. this.chars = [];
  6248. }
  6249. var i;
  6250. var len = chars.length;
  6251. var j;
  6252. var jLen = this.chars.length;
  6253. var found;
  6254. for (i = 0; i < len; i += 1) {
  6255. j = 0;
  6256. found = false;
  6257. while (j < jLen) {
  6258. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  6259. found = true;
  6260. }
  6261. j += 1;
  6262. }
  6263. if (!found) {
  6264. this.chars.push(chars[i]);
  6265. jLen += 1;
  6266. }
  6267. }
  6268. }
  6269. function getCharData(_char, style, font) {
  6270. var i = 0;
  6271. var len = this.chars.length;
  6272. while (i < len) {
  6273. if (this.chars[i].ch === _char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  6274. return this.chars[i];
  6275. }
  6276. i += 1;
  6277. }
  6278. if ((typeof _char === 'string' && _char.charCodeAt(0) !== 13 || !_char) && console && console.warn // eslint-disable-line no-console
  6279. && !this._warned) {
  6280. this._warned = true;
  6281. console.warn('Missing character from exported characters list: ', _char, style, font); // eslint-disable-line no-console
  6282. }
  6283. return emptyChar;
  6284. }
  6285. function measureText(_char2, fontName, size) {
  6286. var fontData = this.getFontByName(fontName);
  6287. // Using the char instead of char.charCodeAt(0)
  6288. // to avoid collisions between equal chars
  6289. var index = _char2;
  6290. if (!fontData.cache[index]) {
  6291. var tHelper = fontData.helper;
  6292. if (_char2 === ' ') {
  6293. var doubleSize = tHelper.measureText('|' + _char2 + '|');
  6294. var singleSize = tHelper.measureText('||');
  6295. fontData.cache[index] = (doubleSize - singleSize) / 100;
  6296. } else {
  6297. fontData.cache[index] = tHelper.measureText(_char2) / 100;
  6298. }
  6299. }
  6300. return fontData.cache[index] * size;
  6301. }
  6302. function getFontByName(name) {
  6303. var i = 0;
  6304. var len = this.fonts.length;
  6305. while (i < len) {
  6306. if (this.fonts[i].fName === name) {
  6307. return this.fonts[i];
  6308. }
  6309. i += 1;
  6310. }
  6311. return this.fonts[0];
  6312. }
  6313. function getCodePoint(string) {
  6314. var codePoint = 0;
  6315. var first = string.charCodeAt(0);
  6316. if (first >= 0xD800 && first <= 0xDBFF) {
  6317. var second = string.charCodeAt(1);
  6318. if (second >= 0xDC00 && second <= 0xDFFF) {
  6319. codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  6320. }
  6321. }
  6322. return codePoint;
  6323. }
  6324. // Skin tone modifiers
  6325. function isModifier(firstCharCode, secondCharCode) {
  6326. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  6327. return surrogateModifiers.indexOf(sum) !== -1;
  6328. }
  6329. function isZeroWidthJoiner(charCode) {
  6330. return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
  6331. }
  6332. // This codepoint may change the appearance of the preceding character.
  6333. // If that is a symbol, dingbat or emoji, U+FE0F forces it to be rendered
  6334. // as a colorful image as compared to a monochrome text variant.
  6335. function isVariationSelector(charCode) {
  6336. return charCode === VARIATION_SELECTOR_16_CODE_POINT;
  6337. }
  6338. // The regional indicator symbols are a set of 26 alphabetic Unicode
  6339. /// characters (A–Z) intended to be used to encode ISO 3166-1 alpha-2
  6340. // two-letter country codes in a way that allows optional special treatment.
  6341. function isRegionalCode(string) {
  6342. var codePoint = getCodePoint(string);
  6343. if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) {
  6344. return true;
  6345. }
  6346. return false;
  6347. }
  6348. // Some Emoji implementations represent combinations of
  6349. // two “regional indicator” letters as a single flag symbol.
  6350. function isFlagEmoji(string) {
  6351. return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
  6352. }
  6353. function isCombinedCharacter(_char3) {
  6354. return combinedCharacters.indexOf(_char3) !== -1;
  6355. }
  6356. // Regional flags start with a BLACK_FLAG_CODE_POINT
  6357. // folowed by 5 chars in the TAG range
  6358. // and end with a CANCEL_TAG_CODE_POINT
  6359. function isRegionalFlag(text, index) {
  6360. var codePoint = getCodePoint(text.substr(index, 2));
  6361. if (codePoint !== BLACK_FLAG_CODE_POINT) {
  6362. return false;
  6363. }
  6364. var count = 0;
  6365. index += 2;
  6366. while (count < 5) {
  6367. codePoint = getCodePoint(text.substr(index, 2));
  6368. if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) {
  6369. return false;
  6370. }
  6371. count += 1;
  6372. index += 2;
  6373. }
  6374. return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
  6375. }
  6376. function setIsLoaded() {
  6377. this.isLoaded = true;
  6378. }
  6379. var Font = function Font() {
  6380. this.fonts = [];
  6381. this.chars = null;
  6382. this.typekitLoaded = 0;
  6383. this.isLoaded = false;
  6384. this._warned = false;
  6385. this.initTime = Date.now();
  6386. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  6387. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  6388. };
  6389. Font.isModifier = isModifier;
  6390. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  6391. Font.isFlagEmoji = isFlagEmoji;
  6392. Font.isRegionalCode = isRegionalCode;
  6393. Font.isCombinedCharacter = isCombinedCharacter;
  6394. Font.isRegionalFlag = isRegionalFlag;
  6395. Font.isVariationSelector = isVariationSelector;
  6396. Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
  6397. var fontPrototype = {
  6398. addChars: addChars,
  6399. addFonts: addFonts,
  6400. getCharData: getCharData,
  6401. getFontByName: getFontByName,
  6402. measureText: measureText,
  6403. checkLoadedFonts: checkLoadedFonts,
  6404. setIsLoaded: setIsLoaded
  6405. };
  6406. Font.prototype = fontPrototype;
  6407. return Font;
  6408. }();
  6409. function SlotManager(animationData) {
  6410. this.animationData = animationData;
  6411. }
  6412. SlotManager.prototype.getProp = function (data) {
  6413. if (this.animationData.slots && this.animationData.slots[data.sid]) {
  6414. return Object.assign(data, this.animationData.slots[data.sid].p);
  6415. }
  6416. return data;
  6417. };
  6418. function slotFactory(animationData) {
  6419. return new SlotManager(animationData);
  6420. }
  6421. function RenderableElement() {}
  6422. RenderableElement.prototype = {
  6423. initRenderable: function initRenderable() {
  6424. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6425. this.isInRange = false;
  6426. // layer's display state
  6427. this.hidden = false;
  6428. // If layer's transparency equals 0, it can be hidden
  6429. this.isTransparent = false;
  6430. // list of animated components
  6431. this.renderableComponents = [];
  6432. },
  6433. addRenderableComponent: function addRenderableComponent(component) {
  6434. if (this.renderableComponents.indexOf(component) === -1) {
  6435. this.renderableComponents.push(component);
  6436. }
  6437. },
  6438. removeRenderableComponent: function removeRenderableComponent(component) {
  6439. if (this.renderableComponents.indexOf(component) !== -1) {
  6440. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6441. }
  6442. },
  6443. prepareRenderableFrame: function prepareRenderableFrame(num) {
  6444. this.checkLayerLimits(num);
  6445. },
  6446. checkTransparency: function checkTransparency() {
  6447. if (this.finalTransform.mProp.o.v <= 0) {
  6448. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  6449. this.isTransparent = true;
  6450. this.hide();
  6451. }
  6452. } else if (this.isTransparent) {
  6453. this.isTransparent = false;
  6454. this.show();
  6455. }
  6456. },
  6457. /**
  6458. * @function
  6459. * Initializes frame related properties.
  6460. *
  6461. * @param {number} num
  6462. * current frame number in Layer's time
  6463. *
  6464. */
  6465. checkLayerLimits: function checkLayerLimits(num) {
  6466. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  6467. if (this.isInRange !== true) {
  6468. this.globalData._mdf = true;
  6469. this._mdf = true;
  6470. this.isInRange = true;
  6471. this.show();
  6472. }
  6473. } else if (this.isInRange !== false) {
  6474. this.globalData._mdf = true;
  6475. this.isInRange = false;
  6476. this.hide();
  6477. }
  6478. },
  6479. renderRenderable: function renderRenderable() {
  6480. var i;
  6481. var len = this.renderableComponents.length;
  6482. for (i = 0; i < len; i += 1) {
  6483. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6484. }
  6485. /* this.maskManager.renderFrame(this.finalTransform.mat);
  6486. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  6487. },
  6488. sourceRectAtTime: function sourceRectAtTime() {
  6489. return {
  6490. top: 0,
  6491. left: 0,
  6492. width: 100,
  6493. height: 100
  6494. };
  6495. },
  6496. getLayerSize: function getLayerSize() {
  6497. if (this.data.ty === 5) {
  6498. return {
  6499. w: this.data.textData.width,
  6500. h: this.data.textData.height
  6501. };
  6502. }
  6503. return {
  6504. w: this.data.width,
  6505. h: this.data.height
  6506. };
  6507. }
  6508. };
  6509. var getBlendMode = function () {
  6510. var blendModeEnums = {
  6511. 0: 'source-over',
  6512. 1: 'multiply',
  6513. 2: 'screen',
  6514. 3: 'overlay',
  6515. 4: 'darken',
  6516. 5: 'lighten',
  6517. 6: 'color-dodge',
  6518. 7: 'color-burn',
  6519. 8: 'hard-light',
  6520. 9: 'soft-light',
  6521. 10: 'difference',
  6522. 11: 'exclusion',
  6523. 12: 'hue',
  6524. 13: 'saturation',
  6525. 14: 'color',
  6526. 15: 'luminosity'
  6527. };
  6528. return function (mode) {
  6529. return blendModeEnums[mode] || '';
  6530. };
  6531. }();
  6532. function SliderEffect(data, elem, container) {
  6533. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6534. }
  6535. function AngleEffect(data, elem, container) {
  6536. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6537. }
  6538. function ColorEffect(data, elem, container) {
  6539. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6540. }
  6541. function PointEffect(data, elem, container) {
  6542. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6543. }
  6544. function LayerIndexEffect(data, elem, container) {
  6545. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6546. }
  6547. function MaskIndexEffect(data, elem, container) {
  6548. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6549. }
  6550. function CheckboxEffect(data, elem, container) {
  6551. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6552. }
  6553. function NoValueEffect() {
  6554. this.p = {};
  6555. }
  6556. function EffectsManager(data, element) {
  6557. var effects = data.ef || [];
  6558. this.effectElements = [];
  6559. var i;
  6560. var len = effects.length;
  6561. var effectItem;
  6562. for (i = 0; i < len; i += 1) {
  6563. effectItem = new GroupEffect(effects[i], element);
  6564. this.effectElements.push(effectItem);
  6565. }
  6566. }
  6567. function GroupEffect(data, element) {
  6568. this.init(data, element);
  6569. }
  6570. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6571. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6572. GroupEffect.prototype.init = function (data, element) {
  6573. this.data = data;
  6574. this.effectElements = [];
  6575. this.initDynamicPropertyContainer(element);
  6576. var i;
  6577. var len = this.data.ef.length;
  6578. var eff;
  6579. var effects = this.data.ef;
  6580. for (i = 0; i < len; i += 1) {
  6581. eff = null;
  6582. switch (effects[i].ty) {
  6583. case 0:
  6584. eff = new SliderEffect(effects[i], element, this);
  6585. break;
  6586. case 1:
  6587. eff = new AngleEffect(effects[i], element, this);
  6588. break;
  6589. case 2:
  6590. eff = new ColorEffect(effects[i], element, this);
  6591. break;
  6592. case 3:
  6593. eff = new PointEffect(effects[i], element, this);
  6594. break;
  6595. case 4:
  6596. case 7:
  6597. eff = new CheckboxEffect(effects[i], element, this);
  6598. break;
  6599. case 10:
  6600. eff = new LayerIndexEffect(effects[i], element, this);
  6601. break;
  6602. case 11:
  6603. eff = new MaskIndexEffect(effects[i], element, this);
  6604. break;
  6605. case 5:
  6606. eff = new EffectsManager(effects[i], element, this);
  6607. break;
  6608. // case 6:
  6609. default:
  6610. eff = new NoValueEffect(effects[i], element, this);
  6611. break;
  6612. }
  6613. if (eff) {
  6614. this.effectElements.push(eff);
  6615. }
  6616. }
  6617. };
  6618. function BaseElement() {}
  6619. BaseElement.prototype = {
  6620. checkMasks: function checkMasks() {
  6621. if (!this.data.hasMask) {
  6622. return false;
  6623. }
  6624. var i = 0;
  6625. var len = this.data.masksProperties.length;
  6626. while (i < len) {
  6627. if (this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false) {
  6628. return true;
  6629. }
  6630. i += 1;
  6631. }
  6632. return false;
  6633. },
  6634. initExpressions: function initExpressions() {
  6635. var expressionsInterfaces = getExpressionInterfaces();
  6636. if (!expressionsInterfaces) {
  6637. return;
  6638. }
  6639. var LayerExpressionInterface = expressionsInterfaces('layer');
  6640. var EffectsExpressionInterface = expressionsInterfaces('effects');
  6641. var ShapeExpressionInterface = expressionsInterfaces('shape');
  6642. var TextExpressionInterface = expressionsInterfaces('text');
  6643. var CompExpressionInterface = expressionsInterfaces('comp');
  6644. this.layerInterface = LayerExpressionInterface(this);
  6645. if (this.data.hasMask && this.maskManager) {
  6646. this.layerInterface.registerMaskInterface(this.maskManager);
  6647. }
  6648. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
  6649. this.layerInterface.registerEffectsInterface(effectsInterface);
  6650. if (this.data.ty === 0 || this.data.xt) {
  6651. this.compInterface = CompExpressionInterface(this);
  6652. } else if (this.data.ty === 4) {
  6653. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
  6654. this.layerInterface.content = this.layerInterface.shapeInterface;
  6655. } else if (this.data.ty === 5) {
  6656. this.layerInterface.textInterface = TextExpressionInterface(this);
  6657. this.layerInterface.text = this.layerInterface.textInterface;
  6658. }
  6659. },
  6660. setBlendMode: function setBlendMode() {
  6661. var blendModeValue = getBlendMode(this.data.bm);
  6662. var elem = this.baseElement || this.layerElement;
  6663. elem.style['mix-blend-mode'] = blendModeValue;
  6664. },
  6665. initBaseData: function initBaseData(data, globalData, comp) {
  6666. this.globalData = globalData;
  6667. this.comp = comp;
  6668. this.data = data;
  6669. this.layerId = createElementID();
  6670. // Stretch factor for old animations missing this property.
  6671. if (!this.data.sr) {
  6672. this.data.sr = 1;
  6673. }
  6674. // effects manager
  6675. this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
  6676. },
  6677. getType: function getType() {
  6678. return this.type;
  6679. },
  6680. sourceRectAtTime: function sourceRectAtTime() {}
  6681. };
  6682. /**
  6683. * @file
  6684. * Handles element's layer frame update.
  6685. * Checks layer in point and out point
  6686. *
  6687. */
  6688. function FrameElement() {}
  6689. FrameElement.prototype = {
  6690. /**
  6691. * @function
  6692. * Initializes frame related properties.
  6693. *
  6694. */
  6695. initFrame: function initFrame() {
  6696. // set to true when inpoint is rendered
  6697. this._isFirstFrame = false;
  6698. // list of animated properties
  6699. this.dynamicProperties = [];
  6700. // If layer has been modified in current tick this will be true
  6701. this._mdf = false;
  6702. },
  6703. /**
  6704. * @function
  6705. * Calculates all dynamic values
  6706. *
  6707. * @param {number} num
  6708. * current frame number in Layer's time
  6709. * @param {boolean} isVisible
  6710. * if layers is currently in range
  6711. *
  6712. */
  6713. prepareProperties: function prepareProperties(num, isVisible) {
  6714. var i;
  6715. var len = this.dynamicProperties.length;
  6716. for (i = 0; i < len; i += 1) {
  6717. if (isVisible || this._isParent && this.dynamicProperties[i].propType === 'transform') {
  6718. this.dynamicProperties[i].getValue();
  6719. if (this.dynamicProperties[i]._mdf) {
  6720. this.globalData._mdf = true;
  6721. this._mdf = true;
  6722. }
  6723. }
  6724. }
  6725. },
  6726. addDynamicProperty: function addDynamicProperty(prop) {
  6727. if (this.dynamicProperties.indexOf(prop) === -1) {
  6728. this.dynamicProperties.push(prop);
  6729. }
  6730. }
  6731. };
  6732. function FootageElement(data, globalData, comp) {
  6733. this.initFrame();
  6734. this.initRenderable();
  6735. this.assetData = globalData.getAssetData(data.refId);
  6736. this.footageData = globalData.imageLoader.getAsset(this.assetData);
  6737. this.initBaseData(data, globalData, comp);
  6738. }
  6739. FootageElement.prototype.prepareFrame = function () {};
  6740. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  6741. FootageElement.prototype.getBaseElement = function () {
  6742. return null;
  6743. };
  6744. FootageElement.prototype.renderFrame = function () {};
  6745. FootageElement.prototype.destroy = function () {};
  6746. FootageElement.prototype.initExpressions = function () {
  6747. var expressionsInterfaces = getExpressionInterfaces();
  6748. if (!expressionsInterfaces) {
  6749. return;
  6750. }
  6751. var FootageInterface = expressionsInterfaces('footage');
  6752. this.layerInterface = FootageInterface(this);
  6753. };
  6754. FootageElement.prototype.getFootageData = function () {
  6755. return this.footageData;
  6756. };
  6757. function AudioElement(data, globalData, comp) {
  6758. this.initFrame();
  6759. this.initRenderable();
  6760. this.assetData = globalData.getAssetData(data.refId);
  6761. this.initBaseData(data, globalData, comp);
  6762. this._isPlaying = false;
  6763. this._canPlay = false;
  6764. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6765. this.audio = this.globalData.audioController.createAudio(assetPath);
  6766. this._currentTime = 0;
  6767. this.globalData.audioController.addAudio(this);
  6768. this._volumeMultiplier = 1;
  6769. this._volume = 1;
  6770. this._previousVolume = null;
  6771. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  6772. _placeholder: true
  6773. };
  6774. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : {
  6775. k: [100]
  6776. }, 1, 0.01, this);
  6777. }
  6778. AudioElement.prototype.prepareFrame = function (num) {
  6779. this.prepareRenderableFrame(num, true);
  6780. this.prepareProperties(num, true);
  6781. if (!this.tm._placeholder) {
  6782. var timeRemapped = this.tm.v;
  6783. this._currentTime = timeRemapped;
  6784. } else {
  6785. this._currentTime = num / this.data.sr;
  6786. }
  6787. this._volume = this.lv.v[0];
  6788. var totalVolume = this._volume * this._volumeMultiplier;
  6789. if (this._previousVolume !== totalVolume) {
  6790. this._previousVolume = totalVolume;
  6791. this.audio.volume(totalVolume);
  6792. }
  6793. };
  6794. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  6795. AudioElement.prototype.renderFrame = function () {
  6796. if (this.isInRange && this._canPlay) {
  6797. if (!this._isPlaying) {
  6798. this.audio.play();
  6799. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6800. this._isPlaying = true;
  6801. } else if (!this.audio.playing() || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1) {
  6802. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6803. }
  6804. }
  6805. };
  6806. AudioElement.prototype.show = function () {
  6807. // this.audio.play()
  6808. };
  6809. AudioElement.prototype.hide = function () {
  6810. this.audio.pause();
  6811. this._isPlaying = false;
  6812. };
  6813. AudioElement.prototype.pause = function () {
  6814. this.audio.pause();
  6815. this._isPlaying = false;
  6816. this._canPlay = false;
  6817. };
  6818. AudioElement.prototype.resume = function () {
  6819. this._canPlay = true;
  6820. };
  6821. AudioElement.prototype.setRate = function (rateValue) {
  6822. this.audio.rate(rateValue);
  6823. };
  6824. AudioElement.prototype.volume = function (volumeValue) {
  6825. this._volumeMultiplier = volumeValue;
  6826. this._previousVolume = volumeValue * this._volume;
  6827. this.audio.volume(this._previousVolume);
  6828. };
  6829. AudioElement.prototype.getBaseElement = function () {
  6830. return null;
  6831. };
  6832. AudioElement.prototype.destroy = function () {};
  6833. AudioElement.prototype.sourceRectAtTime = function () {};
  6834. AudioElement.prototype.initExpressions = function () {};
  6835. function BaseRenderer() {}
  6836. BaseRenderer.prototype.checkLayers = function (num) {
  6837. var i;
  6838. var len = this.layers.length;
  6839. var data;
  6840. this.completeLayers = true;
  6841. for (i = len - 1; i >= 0; i -= 1) {
  6842. if (!this.elements[i]) {
  6843. data = this.layers[i];
  6844. if (data.ip - data.st <= num - this.layers[i].st && data.op - data.st > num - this.layers[i].st) {
  6845. this.buildItem(i);
  6846. }
  6847. }
  6848. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  6849. }
  6850. this.checkPendingElements();
  6851. };
  6852. BaseRenderer.prototype.createItem = function (layer) {
  6853. switch (layer.ty) {
  6854. case 2:
  6855. return this.createImage(layer);
  6856. case 0:
  6857. return this.createComp(layer);
  6858. case 1:
  6859. return this.createSolid(layer);
  6860. case 3:
  6861. return this.createNull(layer);
  6862. case 4:
  6863. return this.createShape(layer);
  6864. case 5:
  6865. return this.createText(layer);
  6866. case 6:
  6867. return this.createAudio(layer);
  6868. case 13:
  6869. return this.createCamera(layer);
  6870. case 15:
  6871. return this.createFootage(layer);
  6872. default:
  6873. return this.createNull(layer);
  6874. }
  6875. };
  6876. BaseRenderer.prototype.createCamera = function () {
  6877. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  6878. };
  6879. BaseRenderer.prototype.createAudio = function (data) {
  6880. return new AudioElement(data, this.globalData, this);
  6881. };
  6882. BaseRenderer.prototype.createFootage = function (data) {
  6883. return new FootageElement(data, this.globalData, this);
  6884. };
  6885. BaseRenderer.prototype.buildAllItems = function () {
  6886. var i;
  6887. var len = this.layers.length;
  6888. for (i = 0; i < len; i += 1) {
  6889. this.buildItem(i);
  6890. }
  6891. this.checkPendingElements();
  6892. };
  6893. BaseRenderer.prototype.includeLayers = function (newLayers) {
  6894. this.completeLayers = false;
  6895. var i;
  6896. var len = newLayers.length;
  6897. var j;
  6898. var jLen = this.layers.length;
  6899. for (i = 0; i < len; i += 1) {
  6900. j = 0;
  6901. while (j < jLen) {
  6902. if (this.layers[j].id === newLayers[i].id) {
  6903. this.layers[j] = newLayers[i];
  6904. break;
  6905. }
  6906. j += 1;
  6907. }
  6908. }
  6909. };
  6910. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  6911. this.globalData.projectInterface = pInterface;
  6912. };
  6913. BaseRenderer.prototype.initItems = function () {
  6914. if (!this.globalData.progressiveLoad) {
  6915. this.buildAllItems();
  6916. }
  6917. };
  6918. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  6919. var elements = this.elements;
  6920. var layers = this.layers;
  6921. var i = 0;
  6922. var len = layers.length;
  6923. while (i < len) {
  6924. if (layers[i].ind == parentName) {
  6925. // eslint-disable-line eqeqeq
  6926. if (!elements[i] || elements[i] === true) {
  6927. this.buildItem(i);
  6928. this.addPendingElement(element);
  6929. } else {
  6930. hierarchy.push(elements[i]);
  6931. elements[i].setAsParent();
  6932. if (layers[i].parent !== undefined) {
  6933. this.buildElementParenting(element, layers[i].parent, hierarchy);
  6934. } else {
  6935. element.setHierarchy(hierarchy);
  6936. }
  6937. }
  6938. }
  6939. i += 1;
  6940. }
  6941. };
  6942. BaseRenderer.prototype.addPendingElement = function (element) {
  6943. this.pendingElements.push(element);
  6944. };
  6945. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  6946. var i;
  6947. var len = assets.length;
  6948. for (i = 0; i < len; i += 1) {
  6949. if (assets[i].xt) {
  6950. var comp = this.createComp(assets[i]);
  6951. comp.initExpressions();
  6952. this.globalData.projectInterface.registerComposition(comp);
  6953. }
  6954. }
  6955. };
  6956. BaseRenderer.prototype.getElementById = function (ind) {
  6957. var i;
  6958. var len = this.elements.length;
  6959. for (i = 0; i < len; i += 1) {
  6960. if (this.elements[i].data.ind === ind) {
  6961. return this.elements[i];
  6962. }
  6963. }
  6964. return null;
  6965. };
  6966. BaseRenderer.prototype.getElementByPath = function (path) {
  6967. var pathValue = path.shift();
  6968. var element;
  6969. if (typeof pathValue === 'number') {
  6970. element = this.elements[pathValue];
  6971. } else {
  6972. var i;
  6973. var len = this.elements.length;
  6974. for (i = 0; i < len; i += 1) {
  6975. if (this.elements[i].data.nm === pathValue) {
  6976. element = this.elements[i];
  6977. break;
  6978. }
  6979. }
  6980. }
  6981. if (path.length === 0) {
  6982. return element;
  6983. }
  6984. return element.getElementByPath(path);
  6985. };
  6986. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  6987. this.globalData.fontManager = new FontManager();
  6988. this.globalData.slotManager = slotFactory(animData);
  6989. this.globalData.fontManager.addChars(animData.chars);
  6990. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  6991. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  6992. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  6993. this.globalData.imageLoader = this.animationItem.imagePreloader;
  6994. this.globalData.audioController = this.animationItem.audioController;
  6995. this.globalData.frameId = 0;
  6996. this.globalData.frameRate = animData.fr;
  6997. this.globalData.nm = animData.nm;
  6998. this.globalData.compSize = {
  6999. w: animData.w,
  7000. h: animData.h
  7001. };
  7002. };
  7003. var effectTypes = {
  7004. TRANSFORM_EFFECT: 'transformEFfect'
  7005. };
  7006. function TransformElement() {}
  7007. TransformElement.prototype = {
  7008. initTransform: function initTransform() {
  7009. var mat = new Matrix();
  7010. this.finalTransform = {
  7011. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : {
  7012. o: 0
  7013. },
  7014. _matMdf: false,
  7015. _localMatMdf: false,
  7016. _opMdf: false,
  7017. mat: mat,
  7018. localMat: mat,
  7019. localOpacity: 1
  7020. };
  7021. if (this.data.ao) {
  7022. this.finalTransform.mProp.autoOriented = true;
  7023. }
  7024. // TODO: check TYPE 11: Guided elements
  7025. if (this.data.ty !== 11) {
  7026. // this.createElements();
  7027. }
  7028. },
  7029. renderTransform: function renderTransform() {
  7030. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  7031. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  7032. if (this.hierarchy) {
  7033. var mat;
  7034. var finalMat = this.finalTransform.mat;
  7035. var i = 0;
  7036. var len = this.hierarchy.length;
  7037. // Checking if any of the transformation matrices in the hierarchy chain has changed.
  7038. if (!this.finalTransform._matMdf) {
  7039. while (i < len) {
  7040. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  7041. this.finalTransform._matMdf = true;
  7042. break;
  7043. }
  7044. i += 1;
  7045. }
  7046. }
  7047. if (this.finalTransform._matMdf) {
  7048. mat = this.finalTransform.mProp.v.props;
  7049. finalMat.cloneFromProps(mat);
  7050. for (i = 0; i < len; i += 1) {
  7051. finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
  7052. }
  7053. }
  7054. }
  7055. if (!this.localTransforms || this.finalTransform._matMdf) {
  7056. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7057. }
  7058. if (this.finalTransform._opMdf) {
  7059. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7060. }
  7061. },
  7062. renderLocalTransform: function renderLocalTransform() {
  7063. if (this.localTransforms) {
  7064. var i = 0;
  7065. var len = this.localTransforms.length;
  7066. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7067. if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) {
  7068. while (i < len) {
  7069. if (this.localTransforms[i]._mdf) {
  7070. this.finalTransform._localMatMdf = true;
  7071. }
  7072. if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
  7073. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7074. this.finalTransform._opMdf = true;
  7075. }
  7076. i += 1;
  7077. }
  7078. }
  7079. if (this.finalTransform._localMatMdf) {
  7080. var localMat = this.finalTransform.localMat;
  7081. this.localTransforms[0].matrix.clone(localMat);
  7082. for (i = 1; i < len; i += 1) {
  7083. var lmat = this.localTransforms[i].matrix;
  7084. localMat.multiply(lmat);
  7085. }
  7086. localMat.multiply(this.finalTransform.mat);
  7087. }
  7088. if (this.finalTransform._opMdf) {
  7089. var localOp = this.finalTransform.localOpacity;
  7090. for (i = 0; i < len; i += 1) {
  7091. localOp *= this.localTransforms[i].opacity * 0.01;
  7092. }
  7093. this.finalTransform.localOpacity = localOp;
  7094. }
  7095. }
  7096. },
  7097. searchEffectTransforms: function searchEffectTransforms() {
  7098. if (this.renderableEffectsManager) {
  7099. var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  7100. if (transformEffects.length) {
  7101. this.localTransforms = [];
  7102. this.finalTransform.localMat = new Matrix();
  7103. var i = 0;
  7104. var len = transformEffects.length;
  7105. for (i = 0; i < len; i += 1) {
  7106. this.localTransforms.push(transformEffects[i]);
  7107. }
  7108. }
  7109. }
  7110. },
  7111. globalToLocal: function globalToLocal(pt) {
  7112. var transforms = [];
  7113. transforms.push(this.finalTransform);
  7114. var flag = true;
  7115. var comp = this.comp;
  7116. while (flag) {
  7117. if (comp.finalTransform) {
  7118. if (comp.data.hasMask) {
  7119. transforms.splice(0, 0, comp.finalTransform);
  7120. }
  7121. comp = comp.comp;
  7122. } else {
  7123. flag = false;
  7124. }
  7125. }
  7126. var i;
  7127. var len = transforms.length;
  7128. var ptNew;
  7129. for (i = 0; i < len; i += 1) {
  7130. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  7131. // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7132. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7133. }
  7134. return pt;
  7135. },
  7136. mHelper: new Matrix()
  7137. };
  7138. function MaskElement(data, element, globalData) {
  7139. this.data = data;
  7140. this.element = element;
  7141. this.globalData = globalData;
  7142. this.storedData = [];
  7143. this.masksProperties = this.data.masksProperties || [];
  7144. this.maskElement = null;
  7145. var defs = this.globalData.defs;
  7146. var i;
  7147. var len = this.masksProperties ? this.masksProperties.length : 0;
  7148. this.viewData = createSizedArray(len);
  7149. this.solidPath = '';
  7150. var path;
  7151. var properties = this.masksProperties;
  7152. var count = 0;
  7153. var currentMasks = [];
  7154. var j;
  7155. var jLen;
  7156. var layerId = createElementID();
  7157. var rect;
  7158. var expansor;
  7159. var feMorph;
  7160. var x;
  7161. var maskType = 'clipPath';
  7162. var maskRef = 'clip-path';
  7163. for (i = 0; i < len; i += 1) {
  7164. if (properties[i].mode !== 'a' && properties[i].mode !== 'n' || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7165. maskType = 'mask';
  7166. maskRef = 'mask';
  7167. }
  7168. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7169. rect = createNS('rect');
  7170. rect.setAttribute('fill', '#ffffff');
  7171. rect.setAttribute('width', this.element.comp.data.w || 0);
  7172. rect.setAttribute('height', this.element.comp.data.h || 0);
  7173. currentMasks.push(rect);
  7174. } else {
  7175. rect = null;
  7176. }
  7177. path = createNS('path');
  7178. if (properties[i].mode === 'n') {
  7179. // TODO move this to a factory or to a constructor
  7180. this.viewData[i] = {
  7181. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7182. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7183. elem: path,
  7184. lastPath: ''
  7185. };
  7186. defs.appendChild(path);
  7187. } else {
  7188. count += 1;
  7189. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7190. path.setAttribute('clip-rule', 'nonzero');
  7191. var filterID;
  7192. if (properties[i].x.k !== 0) {
  7193. maskType = 'mask';
  7194. maskRef = 'mask';
  7195. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7196. filterID = createElementID();
  7197. expansor = createNS('filter');
  7198. expansor.setAttribute('id', filterID);
  7199. feMorph = createNS('feMorphology');
  7200. feMorph.setAttribute('operator', 'erode');
  7201. feMorph.setAttribute('in', 'SourceGraphic');
  7202. feMorph.setAttribute('radius', '0');
  7203. expansor.appendChild(feMorph);
  7204. defs.appendChild(expansor);
  7205. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7206. } else {
  7207. feMorph = null;
  7208. x = null;
  7209. }
  7210. // TODO move this to a factory or to a constructor
  7211. this.storedData[i] = {
  7212. elem: path,
  7213. x: x,
  7214. expan: feMorph,
  7215. lastPath: '',
  7216. lastOperator: '',
  7217. filterId: filterID,
  7218. lastRadius: 0
  7219. };
  7220. if (properties[i].mode === 'i') {
  7221. jLen = currentMasks.length;
  7222. var g = createNS('g');
  7223. for (j = 0; j < jLen; j += 1) {
  7224. g.appendChild(currentMasks[j]);
  7225. }
  7226. var mask = createNS('mask');
  7227. mask.setAttribute('mask-type', 'alpha');
  7228. mask.setAttribute('id', layerId + '_' + count);
  7229. mask.appendChild(path);
  7230. defs.appendChild(mask);
  7231. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7232. currentMasks.length = 0;
  7233. currentMasks.push(g);
  7234. } else {
  7235. currentMasks.push(path);
  7236. }
  7237. if (properties[i].inv && !this.solidPath) {
  7238. this.solidPath = this.createLayerSolidPath();
  7239. }
  7240. // TODO move this to a factory or to a constructor
  7241. this.viewData[i] = {
  7242. elem: path,
  7243. lastPath: '',
  7244. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7245. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7246. invRect: rect
  7247. };
  7248. if (!this.viewData[i].prop.k) {
  7249. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7250. }
  7251. }
  7252. }
  7253. this.maskElement = createNS(maskType);
  7254. len = currentMasks.length;
  7255. for (i = 0; i < len; i += 1) {
  7256. this.maskElement.appendChild(currentMasks[i]);
  7257. }
  7258. if (count > 0) {
  7259. this.maskElement.setAttribute('id', layerId);
  7260. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7261. defs.appendChild(this.maskElement);
  7262. }
  7263. if (this.viewData.length) {
  7264. this.element.addRenderableComponent(this);
  7265. }
  7266. }
  7267. MaskElement.prototype.getMaskProperty = function (pos) {
  7268. return this.viewData[pos].prop;
  7269. };
  7270. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7271. var finalMat = this.element.finalTransform.mat;
  7272. var i;
  7273. var len = this.masksProperties.length;
  7274. for (i = 0; i < len; i += 1) {
  7275. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7276. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7277. }
  7278. if (this.viewData[i].op._mdf || isFirstFrame) {
  7279. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7280. }
  7281. if (this.masksProperties[i].mode !== 'n') {
  7282. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7283. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7284. }
  7285. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7286. var feMorph = this.storedData[i].expan;
  7287. if (this.storedData[i].x.v < 0) {
  7288. if (this.storedData[i].lastOperator !== 'erode') {
  7289. this.storedData[i].lastOperator = 'erode';
  7290. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7291. }
  7292. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7293. } else {
  7294. if (this.storedData[i].lastOperator !== 'dilate') {
  7295. this.storedData[i].lastOperator = 'dilate';
  7296. this.storedData[i].elem.setAttribute('filter', null);
  7297. }
  7298. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7299. }
  7300. }
  7301. }
  7302. }
  7303. };
  7304. MaskElement.prototype.getMaskelement = function () {
  7305. return this.maskElement;
  7306. };
  7307. MaskElement.prototype.createLayerSolidPath = function () {
  7308. var path = 'M0,0 ';
  7309. path += ' h' + this.globalData.compSize.w;
  7310. path += ' v' + this.globalData.compSize.h;
  7311. path += ' h-' + this.globalData.compSize.w;
  7312. path += ' v-' + this.globalData.compSize.h + ' ';
  7313. return path;
  7314. };
  7315. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7316. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7317. var i;
  7318. var len;
  7319. len = pathNodes._length;
  7320. for (i = 1; i < len; i += 1) {
  7321. // 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];
  7322. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[i][0] + ',' + pathNodes.i[i][1] + ' ' + pathNodes.v[i][0] + ',' + pathNodes.v[i][1];
  7323. }
  7324. // 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];
  7325. if (pathNodes.c && len > 1) {
  7326. 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];
  7327. }
  7328. // pathNodes.__renderedString = pathString;
  7329. if (viewData.lastPath !== pathString) {
  7330. var pathShapeValue = '';
  7331. if (viewData.elem) {
  7332. if (pathNodes.c) {
  7333. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7334. }
  7335. viewData.elem.setAttribute('d', pathShapeValue);
  7336. }
  7337. viewData.lastPath = pathString;
  7338. }
  7339. };
  7340. MaskElement.prototype.destroy = function () {
  7341. this.element = null;
  7342. this.globalData = null;
  7343. this.maskElement = null;
  7344. this.data = null;
  7345. this.masksProperties = null;
  7346. };
  7347. var filtersFactory = function () {
  7348. var ob = {};
  7349. ob.createFilter = createFilter;
  7350. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7351. function createFilter(filId, skipCoordinates) {
  7352. var fil = createNS('filter');
  7353. fil.setAttribute('id', filId);
  7354. if (skipCoordinates !== true) {
  7355. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7356. fil.setAttribute('x', '0%');
  7357. fil.setAttribute('y', '0%');
  7358. fil.setAttribute('width', '100%');
  7359. fil.setAttribute('height', '100%');
  7360. }
  7361. return fil;
  7362. }
  7363. function createAlphaToLuminanceFilter() {
  7364. var feColorMatrix = createNS('feColorMatrix');
  7365. feColorMatrix.setAttribute('type', 'matrix');
  7366. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7367. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7368. return feColorMatrix;
  7369. }
  7370. return ob;
  7371. }();
  7372. var featureSupport = function () {
  7373. var ob = {
  7374. maskType: true,
  7375. svgLumaHidden: true,
  7376. offscreenCanvas: typeof OffscreenCanvas !== 'undefined'
  7377. };
  7378. 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)) {
  7379. ob.maskType = false;
  7380. }
  7381. if (/firefox/i.test(navigator.userAgent)) {
  7382. ob.svgLumaHidden = false;
  7383. }
  7384. return ob;
  7385. }();
  7386. var registeredEffects$1 = {};
  7387. var idPrefix = 'filter_result_';
  7388. function SVGEffects(elem) {
  7389. var i;
  7390. var source = 'SourceGraphic';
  7391. var len = elem.data.ef ? elem.data.ef.length : 0;
  7392. var filId = createElementID();
  7393. var fil = filtersFactory.createFilter(filId, true);
  7394. var count = 0;
  7395. this.filters = [];
  7396. var filterManager;
  7397. for (i = 0; i < len; i += 1) {
  7398. filterManager = null;
  7399. var type = elem.data.ef[i].ty;
  7400. if (registeredEffects$1[type]) {
  7401. var Effect = registeredEffects$1[type].effect;
  7402. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7403. source = idPrefix + count;
  7404. if (registeredEffects$1[type].countsAsEffect) {
  7405. count += 1;
  7406. }
  7407. }
  7408. if (filterManager) {
  7409. this.filters.push(filterManager);
  7410. }
  7411. }
  7412. if (count) {
  7413. elem.globalData.defs.appendChild(fil);
  7414. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7415. }
  7416. if (this.filters.length) {
  7417. elem.addRenderableComponent(this);
  7418. }
  7419. }
  7420. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7421. var i;
  7422. var len = this.filters.length;
  7423. for (i = 0; i < len; i += 1) {
  7424. this.filters[i].renderFrame(_isFirstFrame);
  7425. }
  7426. };
  7427. SVGEffects.prototype.getEffects = function (type) {
  7428. var i;
  7429. var len = this.filters.length;
  7430. var effects = [];
  7431. for (i = 0; i < len; i += 1) {
  7432. if (this.filters[i].type === type) {
  7433. effects.push(this.filters[i]);
  7434. }
  7435. }
  7436. return effects;
  7437. };
  7438. function registerEffect$1(id, effect, countsAsEffect) {
  7439. registeredEffects$1[id] = {
  7440. effect: effect,
  7441. countsAsEffect: countsAsEffect
  7442. };
  7443. }
  7444. function SVGBaseElement() {}
  7445. SVGBaseElement.prototype = {
  7446. initRendererElement: function initRendererElement() {
  7447. this.layerElement = createNS('g');
  7448. },
  7449. createContainerElements: function createContainerElements() {
  7450. this.matteElement = createNS('g');
  7451. this.transformedElement = this.layerElement;
  7452. this.maskedElement = this.layerElement;
  7453. this._sizeChanged = false;
  7454. var layerElementParent = null;
  7455. // If this layer acts as a mask for the following layer
  7456. if (this.data.td) {
  7457. this.matteMasks = {};
  7458. var gg = createNS('g');
  7459. gg.setAttribute('id', this.layerId);
  7460. gg.appendChild(this.layerElement);
  7461. layerElementParent = gg;
  7462. this.globalData.defs.appendChild(gg);
  7463. } else if (this.data.tt) {
  7464. this.matteElement.appendChild(this.layerElement);
  7465. layerElementParent = this.matteElement;
  7466. this.baseElement = this.matteElement;
  7467. } else {
  7468. this.baseElement = this.layerElement;
  7469. }
  7470. if (this.data.ln) {
  7471. this.layerElement.setAttribute('id', this.data.ln);
  7472. }
  7473. if (this.data.cl) {
  7474. this.layerElement.setAttribute('class', this.data.cl);
  7475. }
  7476. // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7477. if (this.data.ty === 0 && !this.data.hd) {
  7478. var cp = createNS('clipPath');
  7479. var pt = createNS('path');
  7480. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7481. var clipId = createElementID();
  7482. cp.setAttribute('id', clipId);
  7483. cp.appendChild(pt);
  7484. this.globalData.defs.appendChild(cp);
  7485. if (this.checkMasks()) {
  7486. var cpGroup = createNS('g');
  7487. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7488. cpGroup.appendChild(this.layerElement);
  7489. this.transformedElement = cpGroup;
  7490. if (layerElementParent) {
  7491. layerElementParent.appendChild(this.transformedElement);
  7492. } else {
  7493. this.baseElement = this.transformedElement;
  7494. }
  7495. } else {
  7496. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7497. }
  7498. }
  7499. if (this.data.bm !== 0) {
  7500. this.setBlendMode();
  7501. }
  7502. },
  7503. renderElement: function renderElement() {
  7504. if (this.finalTransform._localMatMdf) {
  7505. this.transformedElement.setAttribute('transform', this.finalTransform.localMat.to2dCSS());
  7506. }
  7507. if (this.finalTransform._opMdf) {
  7508. this.transformedElement.setAttribute('opacity', this.finalTransform.localOpacity);
  7509. }
  7510. },
  7511. destroyBaseElement: function destroyBaseElement() {
  7512. this.layerElement = null;
  7513. this.matteElement = null;
  7514. this.maskManager.destroy();
  7515. },
  7516. getBaseElement: function getBaseElement() {
  7517. if (this.data.hd) {
  7518. return null;
  7519. }
  7520. return this.baseElement;
  7521. },
  7522. createRenderableComponents: function createRenderableComponents() {
  7523. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7524. this.renderableEffectsManager = new SVGEffects(this);
  7525. this.searchEffectTransforms();
  7526. },
  7527. getMatte: function getMatte(matteType) {
  7528. // This should not be a common case. But for backward compatibility, we'll create the matte object.
  7529. // It solves animations that have two consecutive layers marked as matte masks.
  7530. // Which is an undefined behavior in AE.
  7531. if (!this.matteMasks) {
  7532. this.matteMasks = {};
  7533. }
  7534. if (!this.matteMasks[matteType]) {
  7535. var id = this.layerId + '_' + matteType;
  7536. var filId;
  7537. var fil;
  7538. var useElement;
  7539. var gg;
  7540. if (matteType === 1 || matteType === 3) {
  7541. var masker = createNS('mask');
  7542. masker.setAttribute('id', id);
  7543. masker.setAttribute('mask-type', matteType === 3 ? 'luminance' : 'alpha');
  7544. useElement = createNS('use');
  7545. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7546. masker.appendChild(useElement);
  7547. this.globalData.defs.appendChild(masker);
  7548. if (!featureSupport.maskType && matteType === 1) {
  7549. masker.setAttribute('mask-type', 'luminance');
  7550. filId = createElementID();
  7551. fil = filtersFactory.createFilter(filId);
  7552. this.globalData.defs.appendChild(fil);
  7553. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7554. gg = createNS('g');
  7555. gg.appendChild(useElement);
  7556. masker.appendChild(gg);
  7557. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7558. }
  7559. } else if (matteType === 2) {
  7560. var maskGroup = createNS('mask');
  7561. maskGroup.setAttribute('id', id);
  7562. maskGroup.setAttribute('mask-type', 'alpha');
  7563. var maskGrouper = createNS('g');
  7564. maskGroup.appendChild(maskGrouper);
  7565. filId = createElementID();
  7566. fil = filtersFactory.createFilter(filId);
  7567. /// /
  7568. var feCTr = createNS('feComponentTransfer');
  7569. feCTr.setAttribute('in', 'SourceGraphic');
  7570. fil.appendChild(feCTr);
  7571. var feFunc = createNS('feFuncA');
  7572. feFunc.setAttribute('type', 'table');
  7573. feFunc.setAttribute('tableValues', '1.0 0.0');
  7574. feCTr.appendChild(feFunc);
  7575. /// /
  7576. this.globalData.defs.appendChild(fil);
  7577. var alphaRect = createNS('rect');
  7578. alphaRect.setAttribute('width', this.comp.data.w);
  7579. alphaRect.setAttribute('height', this.comp.data.h);
  7580. alphaRect.setAttribute('x', '0');
  7581. alphaRect.setAttribute('y', '0');
  7582. alphaRect.setAttribute('fill', '#ffffff');
  7583. alphaRect.setAttribute('opacity', '0');
  7584. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7585. maskGrouper.appendChild(alphaRect);
  7586. useElement = createNS('use');
  7587. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7588. maskGrouper.appendChild(useElement);
  7589. if (!featureSupport.maskType) {
  7590. maskGroup.setAttribute('mask-type', 'luminance');
  7591. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7592. gg = createNS('g');
  7593. maskGrouper.appendChild(alphaRect);
  7594. gg.appendChild(this.layerElement);
  7595. maskGrouper.appendChild(gg);
  7596. }
  7597. this.globalData.defs.appendChild(maskGroup);
  7598. }
  7599. this.matteMasks[matteType] = id;
  7600. }
  7601. return this.matteMasks[matteType];
  7602. },
  7603. setMatte: function setMatte(id) {
  7604. if (!this.matteElement) {
  7605. return;
  7606. }
  7607. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7608. }
  7609. };
  7610. /**
  7611. * @file
  7612. * Handles AE's layer parenting property.
  7613. *
  7614. */
  7615. function HierarchyElement() {}
  7616. HierarchyElement.prototype = {
  7617. /**
  7618. * @function
  7619. * Initializes hierarchy properties
  7620. *
  7621. */
  7622. initHierarchy: function initHierarchy() {
  7623. // element's parent list
  7624. this.hierarchy = [];
  7625. // if element is parent of another layer _isParent will be true
  7626. this._isParent = false;
  7627. this.checkParenting();
  7628. },
  7629. /**
  7630. * @function
  7631. * Sets layer's hierarchy.
  7632. * @param {array} hierarch
  7633. * layer's parent list
  7634. *
  7635. */
  7636. setHierarchy: function setHierarchy(hierarchy) {
  7637. this.hierarchy = hierarchy;
  7638. },
  7639. /**
  7640. * @function
  7641. * Sets layer as parent.
  7642. *
  7643. */
  7644. setAsParent: function setAsParent() {
  7645. this._isParent = true;
  7646. },
  7647. /**
  7648. * @function
  7649. * Searches layer's parenting chain
  7650. *
  7651. */
  7652. checkParenting: function checkParenting() {
  7653. if (this.data.parent !== undefined) {
  7654. this.comp.buildElementParenting(this, this.data.parent, []);
  7655. }
  7656. }
  7657. };
  7658. function RenderableDOMElement() {}
  7659. (function () {
  7660. var _prototype = {
  7661. initElement: function initElement(data, globalData, comp) {
  7662. this.initFrame();
  7663. this.initBaseData(data, globalData, comp);
  7664. this.initTransform(data, globalData, comp);
  7665. this.initHierarchy();
  7666. this.initRenderable();
  7667. this.initRendererElement();
  7668. this.createContainerElements();
  7669. this.createRenderableComponents();
  7670. this.createContent();
  7671. this.hide();
  7672. },
  7673. hide: function hide() {
  7674. // console.log('HIDE', this);
  7675. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7676. var elem = this.baseElement || this.layerElement;
  7677. elem.style.display = 'none';
  7678. this.hidden = true;
  7679. }
  7680. },
  7681. show: function show() {
  7682. // console.log('SHOW', this);
  7683. if (this.isInRange && !this.isTransparent) {
  7684. if (!this.data.hd) {
  7685. var elem = this.baseElement || this.layerElement;
  7686. elem.style.display = 'block';
  7687. }
  7688. this.hidden = false;
  7689. this._isFirstFrame = true;
  7690. }
  7691. },
  7692. renderFrame: function renderFrame() {
  7693. // If it is exported as hidden (data.hd === true) no need to render
  7694. // If it is not visible no need to render
  7695. if (this.data.hd || this.hidden) {
  7696. return;
  7697. }
  7698. this.renderTransform();
  7699. this.renderRenderable();
  7700. this.renderLocalTransform();
  7701. this.renderElement();
  7702. this.renderInnerContent();
  7703. if (this._isFirstFrame) {
  7704. this._isFirstFrame = false;
  7705. }
  7706. },
  7707. renderInnerContent: function renderInnerContent() {},
  7708. prepareFrame: function prepareFrame(num) {
  7709. this._mdf = false;
  7710. this.prepareRenderableFrame(num);
  7711. this.prepareProperties(num, this.isInRange);
  7712. this.checkTransparency();
  7713. },
  7714. destroy: function destroy() {
  7715. this.innerElem = null;
  7716. this.destroyBaseElement();
  7717. }
  7718. };
  7719. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  7720. })();
  7721. function IImageElement(data, globalData, comp) {
  7722. this.assetData = globalData.getAssetData(data.refId);
  7723. if (this.assetData && this.assetData.sid) {
  7724. this.assetData = globalData.slotManager.getProp(this.assetData);
  7725. }
  7726. this.initElement(data, globalData, comp);
  7727. this.sourceRect = {
  7728. top: 0,
  7729. left: 0,
  7730. width: this.assetData.w,
  7731. height: this.assetData.h
  7732. };
  7733. }
  7734. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  7735. IImageElement.prototype.createContent = function () {
  7736. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7737. this.innerElem = createNS('image');
  7738. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  7739. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  7740. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7741. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  7742. this.layerElement.appendChild(this.innerElem);
  7743. };
  7744. IImageElement.prototype.sourceRectAtTime = function () {
  7745. return this.sourceRect;
  7746. };
  7747. function ProcessedElement(element, position) {
  7748. this.elem = element;
  7749. this.pos = position;
  7750. }
  7751. function IShapeElement() {}
  7752. IShapeElement.prototype = {
  7753. addShapeToModifiers: function addShapeToModifiers(data) {
  7754. var i;
  7755. var len = this.shapeModifiers.length;
  7756. for (i = 0; i < len; i += 1) {
  7757. this.shapeModifiers[i].addShape(data);
  7758. }
  7759. },
  7760. isShapeInAnimatedModifiers: function isShapeInAnimatedModifiers(data) {
  7761. var i = 0;
  7762. var len = this.shapeModifiers.length;
  7763. while (i < len) {
  7764. if (this.shapeModifiers[i].isAnimatedWithShape(data)) {
  7765. return true;
  7766. }
  7767. }
  7768. return false;
  7769. },
  7770. renderModifiers: function renderModifiers() {
  7771. if (!this.shapeModifiers.length) {
  7772. return;
  7773. }
  7774. var i;
  7775. var len = this.shapes.length;
  7776. for (i = 0; i < len; i += 1) {
  7777. this.shapes[i].sh.reset();
  7778. }
  7779. len = this.shapeModifiers.length;
  7780. var shouldBreakProcess;
  7781. for (i = len - 1; i >= 0; i -= 1) {
  7782. shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame);
  7783. // workaround to fix cases where a repeater resets the shape so the following processes get called twice
  7784. // TODO: find a better solution for this
  7785. if (shouldBreakProcess) {
  7786. break;
  7787. }
  7788. }
  7789. },
  7790. searchProcessedElement: function searchProcessedElement(elem) {
  7791. var elements = this.processedElements;
  7792. var i = 0;
  7793. var len = elements.length;
  7794. while (i < len) {
  7795. if (elements[i].elem === elem) {
  7796. return elements[i].pos;
  7797. }
  7798. i += 1;
  7799. }
  7800. return 0;
  7801. },
  7802. addProcessedElement: function addProcessedElement(elem, pos) {
  7803. var elements = this.processedElements;
  7804. var i = elements.length;
  7805. while (i) {
  7806. i -= 1;
  7807. if (elements[i].elem === elem) {
  7808. elements[i].pos = pos;
  7809. return;
  7810. }
  7811. }
  7812. elements.push(new ProcessedElement(elem, pos));
  7813. },
  7814. prepareFrame: function prepareFrame(num) {
  7815. this.prepareRenderableFrame(num);
  7816. this.prepareProperties(num, this.isInRange);
  7817. }
  7818. };
  7819. var lineCapEnum = {
  7820. 1: 'butt',
  7821. 2: 'round',
  7822. 3: 'square'
  7823. };
  7824. var lineJoinEnum = {
  7825. 1: 'miter',
  7826. 2: 'round',
  7827. 3: 'bevel'
  7828. };
  7829. function SVGShapeData(transformers, level, shape) {
  7830. this.caches = [];
  7831. this.styles = [];
  7832. this.transformers = transformers;
  7833. this.lStr = '';
  7834. this.sh = shape;
  7835. this.lvl = level;
  7836. // TODO find if there are some cases where _isAnimated can be false.
  7837. // For now, since shapes add up with other shapes. They have to be calculated every time.
  7838. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  7839. this._isAnimated = !!shape.k;
  7840. // TODO: commenting this for now since all shapes are animated
  7841. var i = 0;
  7842. var len = transformers.length;
  7843. while (i < len) {
  7844. if (transformers[i].mProps.dynamicProperties.length) {
  7845. this._isAnimated = true;
  7846. break;
  7847. }
  7848. i += 1;
  7849. }
  7850. }
  7851. SVGShapeData.prototype.setAsAnimated = function () {
  7852. this._isAnimated = true;
  7853. };
  7854. function SVGStyleData(data, level) {
  7855. this.data = data;
  7856. this.type = data.ty;
  7857. this.d = '';
  7858. this.lvl = level;
  7859. this._mdf = false;
  7860. this.closed = data.hd === true;
  7861. this.pElem = createNS('path');
  7862. this.msElem = null;
  7863. }
  7864. SVGStyleData.prototype.reset = function () {
  7865. this.d = '';
  7866. this._mdf = false;
  7867. };
  7868. function DashProperty(elem, data, renderer, container) {
  7869. this.elem = elem;
  7870. this.frameId = -1;
  7871. this.dataProps = createSizedArray(data.length);
  7872. this.renderer = renderer;
  7873. this.k = false;
  7874. this.dashStr = '';
  7875. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  7876. this.dashoffset = createTypedArray('float32', 1);
  7877. this.initDynamicPropertyContainer(container);
  7878. var i;
  7879. var len = data.length || 0;
  7880. var prop;
  7881. for (i = 0; i < len; i += 1) {
  7882. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  7883. this.k = prop.k || this.k;
  7884. this.dataProps[i] = {
  7885. n: data[i].n,
  7886. p: prop
  7887. };
  7888. }
  7889. if (!this.k) {
  7890. this.getValue(true);
  7891. }
  7892. this._isAnimated = this.k;
  7893. }
  7894. DashProperty.prototype.getValue = function (forceRender) {
  7895. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  7896. return;
  7897. }
  7898. this.frameId = this.elem.globalData.frameId;
  7899. this.iterateDynamicProperties();
  7900. this._mdf = this._mdf || forceRender;
  7901. if (this._mdf) {
  7902. var i = 0;
  7903. var len = this.dataProps.length;
  7904. if (this.renderer === 'svg') {
  7905. this.dashStr = '';
  7906. }
  7907. for (i = 0; i < len; i += 1) {
  7908. if (this.dataProps[i].n !== 'o') {
  7909. if (this.renderer === 'svg') {
  7910. this.dashStr += ' ' + this.dataProps[i].p.v;
  7911. } else {
  7912. this.dashArray[i] = this.dataProps[i].p.v;
  7913. }
  7914. } else {
  7915. this.dashoffset[0] = this.dataProps[i].p.v;
  7916. }
  7917. }
  7918. }
  7919. };
  7920. extendPrototype([DynamicPropertyContainer], DashProperty);
  7921. function SVGStrokeStyleData(elem, data, styleOb) {
  7922. this.initDynamicPropertyContainer(elem);
  7923. this.getValue = this.iterateDynamicProperties;
  7924. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7925. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  7926. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  7927. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7928. this.style = styleOb;
  7929. this._isAnimated = !!this._isAnimated;
  7930. }
  7931. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  7932. function SVGFillStyleData(elem, data, styleOb) {
  7933. this.initDynamicPropertyContainer(elem);
  7934. this.getValue = this.iterateDynamicProperties;
  7935. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7936. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7937. this.style = styleOb;
  7938. }
  7939. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  7940. function SVGNoStyleData(elem, data, styleOb) {
  7941. this.initDynamicPropertyContainer(elem);
  7942. this.getValue = this.iterateDynamicProperties;
  7943. this.style = styleOb;
  7944. }
  7945. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  7946. function GradientProperty(elem, data, container) {
  7947. this.data = data;
  7948. this.c = createTypedArray('uint8c', data.p * 4);
  7949. var cLength = data.k.k[0].s ? data.k.k[0].s.length - data.p * 4 : data.k.k.length - data.p * 4;
  7950. this.o = createTypedArray('float32', cLength);
  7951. this._cmdf = false;
  7952. this._omdf = false;
  7953. this._collapsable = this.checkCollapsable();
  7954. this._hasOpacity = cLength;
  7955. this.initDynamicPropertyContainer(container);
  7956. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  7957. this.k = this.prop.k;
  7958. this.getValue(true);
  7959. }
  7960. GradientProperty.prototype.comparePoints = function (values, points) {
  7961. var i = 0;
  7962. var len = this.o.length / 2;
  7963. var diff;
  7964. while (i < len) {
  7965. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  7966. if (diff > 0.01) {
  7967. return false;
  7968. }
  7969. i += 1;
  7970. }
  7971. return true;
  7972. };
  7973. GradientProperty.prototype.checkCollapsable = function () {
  7974. if (this.o.length / 2 !== this.c.length / 4) {
  7975. return false;
  7976. }
  7977. if (this.data.k.k[0].s) {
  7978. var i = 0;
  7979. var len = this.data.k.k.length;
  7980. while (i < len) {
  7981. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  7982. return false;
  7983. }
  7984. i += 1;
  7985. }
  7986. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  7987. return false;
  7988. }
  7989. return true;
  7990. };
  7991. GradientProperty.prototype.getValue = function (forceRender) {
  7992. this.prop.getValue();
  7993. this._mdf = false;
  7994. this._cmdf = false;
  7995. this._omdf = false;
  7996. if (this.prop._mdf || forceRender) {
  7997. var i;
  7998. var len = this.data.p * 4;
  7999. var mult;
  8000. var val;
  8001. for (i = 0; i < len; i += 1) {
  8002. mult = i % 4 === 0 ? 100 : 255;
  8003. val = Math.round(this.prop.v[i] * mult);
  8004. if (this.c[i] !== val) {
  8005. this.c[i] = val;
  8006. this._cmdf = !forceRender;
  8007. }
  8008. }
  8009. if (this.o.length) {
  8010. len = this.prop.v.length;
  8011. for (i = this.data.p * 4; i < len; i += 1) {
  8012. mult = i % 2 === 0 ? 100 : 1;
  8013. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  8014. if (this.o[i - this.data.p * 4] !== val) {
  8015. this.o[i - this.data.p * 4] = val;
  8016. this._omdf = !forceRender;
  8017. }
  8018. }
  8019. }
  8020. this._mdf = !forceRender;
  8021. }
  8022. };
  8023. extendPrototype([DynamicPropertyContainer], GradientProperty);
  8024. function SVGGradientFillStyleData(elem, data, styleOb) {
  8025. this.initDynamicPropertyContainer(elem);
  8026. this.getValue = this.iterateDynamicProperties;
  8027. this.initGradientData(elem, data, styleOb);
  8028. }
  8029. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  8030. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8031. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  8032. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  8033. this.h = PropertyFactory.getProp(elem, data.h || {
  8034. k: 0
  8035. }, 0, 0.01, this);
  8036. this.a = PropertyFactory.getProp(elem, data.a || {
  8037. k: 0
  8038. }, 0, degToRads, this);
  8039. this.g = new GradientProperty(elem, data.g, this);
  8040. this.style = styleOb;
  8041. this.stops = [];
  8042. this.setGradientData(styleOb.pElem, data);
  8043. this.setGradientOpacity(data, styleOb);
  8044. this._isAnimated = !!this._isAnimated;
  8045. };
  8046. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  8047. var gradientId = createElementID();
  8048. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8049. gfill.setAttribute('id', gradientId);
  8050. gfill.setAttribute('spreadMethod', 'pad');
  8051. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8052. var stops = [];
  8053. var stop;
  8054. var j;
  8055. var jLen;
  8056. jLen = data.g.p * 4;
  8057. for (j = 0; j < jLen; j += 4) {
  8058. stop = createNS('stop');
  8059. gfill.appendChild(stop);
  8060. stops.push(stop);
  8061. }
  8062. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  8063. this.gf = gfill;
  8064. this.cst = stops;
  8065. };
  8066. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  8067. if (this.g._hasOpacity && !this.g._collapsable) {
  8068. var stop;
  8069. var j;
  8070. var jLen;
  8071. var mask = createNS('mask');
  8072. var maskElement = createNS('path');
  8073. mask.appendChild(maskElement);
  8074. var opacityId = createElementID();
  8075. var maskId = createElementID();
  8076. mask.setAttribute('id', maskId);
  8077. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8078. opFill.setAttribute('id', opacityId);
  8079. opFill.setAttribute('spreadMethod', 'pad');
  8080. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8081. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8082. var stops = this.stops;
  8083. for (j = data.g.p * 4; j < jLen; j += 2) {
  8084. stop = createNS('stop');
  8085. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8086. opFill.appendChild(stop);
  8087. stops.push(stop);
  8088. }
  8089. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8090. if (data.ty === 'gs') {
  8091. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8092. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8093. if (data.lj === 1) {
  8094. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8095. }
  8096. }
  8097. this.of = opFill;
  8098. this.ms = mask;
  8099. this.ost = stops;
  8100. this.maskId = maskId;
  8101. styleOb.msElem = maskElement;
  8102. }
  8103. };
  8104. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8105. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8106. this.initDynamicPropertyContainer(elem);
  8107. this.getValue = this.iterateDynamicProperties;
  8108. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8109. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8110. this.initGradientData(elem, data, styleOb);
  8111. this._isAnimated = !!this._isAnimated;
  8112. }
  8113. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8114. function ShapeGroupData() {
  8115. this.it = [];
  8116. this.prevViewData = [];
  8117. this.gr = createNS('g');
  8118. }
  8119. function SVGTransformData(mProps, op, container) {
  8120. this.transform = {
  8121. mProps: mProps,
  8122. op: op,
  8123. container: container
  8124. };
  8125. this.elements = [];
  8126. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8127. }
  8128. var buildShapeString = function buildShapeString(pathNodes, length, closed, mat) {
  8129. if (length === 0) {
  8130. return '';
  8131. }
  8132. var _o = pathNodes.o;
  8133. var _i = pathNodes.i;
  8134. var _v = pathNodes.v;
  8135. var i;
  8136. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8137. for (i = 1; i < length; i += 1) {
  8138. 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]);
  8139. }
  8140. if (closed && length) {
  8141. 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]);
  8142. shapeString += 'z';
  8143. }
  8144. return shapeString;
  8145. };
  8146. var SVGElementsRenderer = function () {
  8147. var _identityMatrix = new Matrix();
  8148. var _matrixHelper = new Matrix();
  8149. var ob = {
  8150. createRenderFunction: createRenderFunction
  8151. };
  8152. function createRenderFunction(data) {
  8153. switch (data.ty) {
  8154. case 'fl':
  8155. return renderFill;
  8156. case 'gf':
  8157. return renderGradient;
  8158. case 'gs':
  8159. return renderGradientStroke;
  8160. case 'st':
  8161. return renderStroke;
  8162. case 'sh':
  8163. case 'el':
  8164. case 'rc':
  8165. case 'sr':
  8166. return renderPath;
  8167. case 'tr':
  8168. return renderContentTransform;
  8169. case 'no':
  8170. return renderNoop;
  8171. default:
  8172. return null;
  8173. }
  8174. }
  8175. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8176. if (isFirstFrame || itemData.transform.op._mdf) {
  8177. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8178. }
  8179. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8180. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8181. }
  8182. }
  8183. function renderNoop() {}
  8184. function renderPath(styleData, itemData, isFirstFrame) {
  8185. var j;
  8186. var jLen;
  8187. var pathStringTransformed;
  8188. var redraw;
  8189. var pathNodes;
  8190. var l;
  8191. var lLen = itemData.styles.length;
  8192. var lvl = itemData.lvl;
  8193. var paths;
  8194. var mat;
  8195. var iterations;
  8196. var k;
  8197. for (l = 0; l < lLen; l += 1) {
  8198. redraw = itemData.sh._mdf || isFirstFrame;
  8199. if (itemData.styles[l].lvl < lvl) {
  8200. mat = _matrixHelper.reset();
  8201. iterations = lvl - itemData.styles[l].lvl;
  8202. k = itemData.transformers.length - 1;
  8203. while (!redraw && iterations > 0) {
  8204. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8205. iterations -= 1;
  8206. k -= 1;
  8207. }
  8208. if (redraw) {
  8209. iterations = lvl - itemData.styles[l].lvl;
  8210. k = itemData.transformers.length - 1;
  8211. while (iterations > 0) {
  8212. mat.multiply(itemData.transformers[k].mProps.v);
  8213. iterations -= 1;
  8214. k -= 1;
  8215. }
  8216. }
  8217. } else {
  8218. mat = _identityMatrix;
  8219. }
  8220. paths = itemData.sh.paths;
  8221. jLen = paths._length;
  8222. if (redraw) {
  8223. pathStringTransformed = '';
  8224. for (j = 0; j < jLen; j += 1) {
  8225. pathNodes = paths.shapes[j];
  8226. if (pathNodes && pathNodes._length) {
  8227. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8228. }
  8229. }
  8230. itemData.caches[l] = pathStringTransformed;
  8231. } else {
  8232. pathStringTransformed = itemData.caches[l];
  8233. }
  8234. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8235. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8236. }
  8237. }
  8238. function renderFill(styleData, itemData, isFirstFrame) {
  8239. var styleElem = itemData.style;
  8240. if (itemData.c._mdf || isFirstFrame) {
  8241. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8242. }
  8243. if (itemData.o._mdf || isFirstFrame) {
  8244. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8245. }
  8246. }
  8247. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8248. renderGradient(styleData, itemData, isFirstFrame);
  8249. renderStroke(styleData, itemData, isFirstFrame);
  8250. }
  8251. function renderGradient(styleData, itemData, isFirstFrame) {
  8252. var gfill = itemData.gf;
  8253. var hasOpacity = itemData.g._hasOpacity;
  8254. var pt1 = itemData.s.v;
  8255. var pt2 = itemData.e.v;
  8256. if (itemData.o._mdf || isFirstFrame) {
  8257. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8258. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8259. }
  8260. if (itemData.s._mdf || isFirstFrame) {
  8261. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8262. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8263. gfill.setAttribute(attr1, pt1[0]);
  8264. gfill.setAttribute(attr2, pt1[1]);
  8265. if (hasOpacity && !itemData.g._collapsable) {
  8266. itemData.of.setAttribute(attr1, pt1[0]);
  8267. itemData.of.setAttribute(attr2, pt1[1]);
  8268. }
  8269. }
  8270. var stops;
  8271. var i;
  8272. var len;
  8273. var stop;
  8274. if (itemData.g._cmdf || isFirstFrame) {
  8275. stops = itemData.cst;
  8276. var cValues = itemData.g.c;
  8277. len = stops.length;
  8278. for (i = 0; i < len; i += 1) {
  8279. stop = stops[i];
  8280. stop.setAttribute('offset', cValues[i * 4] + '%');
  8281. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8282. }
  8283. }
  8284. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8285. var oValues = itemData.g.o;
  8286. if (itemData.g._collapsable) {
  8287. stops = itemData.cst;
  8288. } else {
  8289. stops = itemData.ost;
  8290. }
  8291. len = stops.length;
  8292. for (i = 0; i < len; i += 1) {
  8293. stop = stops[i];
  8294. if (!itemData.g._collapsable) {
  8295. stop.setAttribute('offset', oValues[i * 2] + '%');
  8296. }
  8297. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8298. }
  8299. }
  8300. if (styleData.t === 1) {
  8301. if (itemData.e._mdf || isFirstFrame) {
  8302. gfill.setAttribute('x2', pt2[0]);
  8303. gfill.setAttribute('y2', pt2[1]);
  8304. if (hasOpacity && !itemData.g._collapsable) {
  8305. itemData.of.setAttribute('x2', pt2[0]);
  8306. itemData.of.setAttribute('y2', pt2[1]);
  8307. }
  8308. }
  8309. } else {
  8310. var rad;
  8311. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8312. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8313. gfill.setAttribute('r', rad);
  8314. if (hasOpacity && !itemData.g._collapsable) {
  8315. itemData.of.setAttribute('r', rad);
  8316. }
  8317. }
  8318. if (itemData.s._mdf || itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8319. if (!rad) {
  8320. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8321. }
  8322. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8323. var percent = itemData.h.v;
  8324. if (percent >= 1) {
  8325. percent = 0.99;
  8326. } else if (percent <= -1) {
  8327. percent = -0.99;
  8328. }
  8329. var dist = rad * percent;
  8330. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8331. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8332. gfill.setAttribute('fx', x);
  8333. gfill.setAttribute('fy', y);
  8334. if (hasOpacity && !itemData.g._collapsable) {
  8335. itemData.of.setAttribute('fx', x);
  8336. itemData.of.setAttribute('fy', y);
  8337. }
  8338. }
  8339. // gfill.setAttribute('fy','200');
  8340. }
  8341. }
  8342. function renderStroke(styleData, itemData, isFirstFrame) {
  8343. var styleElem = itemData.style;
  8344. var d = itemData.d;
  8345. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8346. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8347. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8348. }
  8349. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8350. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8351. }
  8352. if (itemData.o._mdf || isFirstFrame) {
  8353. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8354. }
  8355. if (itemData.w._mdf || isFirstFrame) {
  8356. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8357. if (styleElem.msElem) {
  8358. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8359. }
  8360. }
  8361. }
  8362. return ob;
  8363. }();
  8364. function SVGShapeElement(data, globalData, comp) {
  8365. // List of drawable elements
  8366. this.shapes = [];
  8367. // Full shape data
  8368. this.shapesData = data.shapes;
  8369. // List of styles that will be applied to shapes
  8370. this.stylesList = [];
  8371. // List of modifiers that will be applied to shapes
  8372. this.shapeModifiers = [];
  8373. // List of items in shape tree
  8374. this.itemsData = [];
  8375. // List of items in previous shape tree
  8376. this.processedElements = [];
  8377. // List of animated components
  8378. this.animatedContents = [];
  8379. this.initElement(data, globalData, comp);
  8380. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8381. // List of elements that have been created
  8382. this.prevViewData = [];
  8383. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8384. }
  8385. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8386. SVGShapeElement.prototype.initSecondaryElement = function () {};
  8387. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8388. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8389. SVGShapeElement.prototype.createContent = function () {
  8390. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8391. this.filterUniqueShapes();
  8392. };
  8393. /*
  8394. This method searches for multiple shapes that affect a single element and one of them is animated
  8395. */
  8396. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8397. var i;
  8398. var len = this.shapes.length;
  8399. var shape;
  8400. var j;
  8401. var jLen = this.stylesList.length;
  8402. var style;
  8403. var tempShapes = [];
  8404. var areAnimated = false;
  8405. for (j = 0; j < jLen; j += 1) {
  8406. style = this.stylesList[j];
  8407. areAnimated = false;
  8408. tempShapes.length = 0;
  8409. for (i = 0; i < len; i += 1) {
  8410. shape = this.shapes[i];
  8411. if (shape.styles.indexOf(style) !== -1) {
  8412. tempShapes.push(shape);
  8413. areAnimated = shape._isAnimated || areAnimated;
  8414. }
  8415. }
  8416. if (tempShapes.length > 1 && areAnimated) {
  8417. this.setShapesAsAnimated(tempShapes);
  8418. }
  8419. }
  8420. };
  8421. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8422. var i;
  8423. var len = shapes.length;
  8424. for (i = 0; i < len; i += 1) {
  8425. shapes[i].setAsAnimated();
  8426. }
  8427. };
  8428. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8429. // TODO: prevent drawing of hidden styles
  8430. var elementData;
  8431. var styleOb = new SVGStyleData(data, level);
  8432. var pathElement = styleOb.pElem;
  8433. if (data.ty === 'st') {
  8434. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8435. } else if (data.ty === 'fl') {
  8436. elementData = new SVGFillStyleData(this, data, styleOb);
  8437. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8438. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8439. elementData = new GradientConstructor(this, data, styleOb);
  8440. this.globalData.defs.appendChild(elementData.gf);
  8441. if (elementData.maskId) {
  8442. this.globalData.defs.appendChild(elementData.ms);
  8443. this.globalData.defs.appendChild(elementData.of);
  8444. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8445. }
  8446. } else if (data.ty === 'no') {
  8447. elementData = new SVGNoStyleData(this, data, styleOb);
  8448. }
  8449. if (data.ty === 'st' || data.ty === 'gs') {
  8450. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8451. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8452. pathElement.setAttribute('fill-opacity', '0');
  8453. if (data.lj === 1) {
  8454. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8455. }
  8456. }
  8457. if (data.r === 2) {
  8458. pathElement.setAttribute('fill-rule', 'evenodd');
  8459. }
  8460. if (data.ln) {
  8461. pathElement.setAttribute('id', data.ln);
  8462. }
  8463. if (data.cl) {
  8464. pathElement.setAttribute('class', data.cl);
  8465. }
  8466. if (data.bm) {
  8467. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8468. }
  8469. this.stylesList.push(styleOb);
  8470. this.addToAnimatedContents(data, elementData);
  8471. return elementData;
  8472. };
  8473. SVGShapeElement.prototype.createGroupElement = function (data) {
  8474. var elementData = new ShapeGroupData();
  8475. if (data.ln) {
  8476. elementData.gr.setAttribute('id', data.ln);
  8477. }
  8478. if (data.cl) {
  8479. elementData.gr.setAttribute('class', data.cl);
  8480. }
  8481. if (data.bm) {
  8482. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8483. }
  8484. return elementData;
  8485. };
  8486. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8487. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8488. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8489. this.addToAnimatedContents(data, elementData);
  8490. return elementData;
  8491. };
  8492. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8493. var ty = 4;
  8494. if (data.ty === 'rc') {
  8495. ty = 5;
  8496. } else if (data.ty === 'el') {
  8497. ty = 6;
  8498. } else if (data.ty === 'sr') {
  8499. ty = 7;
  8500. }
  8501. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8502. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8503. this.shapes.push(elementData);
  8504. this.addShapeToModifiers(elementData);
  8505. this.addToAnimatedContents(data, elementData);
  8506. return elementData;
  8507. };
  8508. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8509. var i = 0;
  8510. var len = this.animatedContents.length;
  8511. while (i < len) {
  8512. if (this.animatedContents[i].element === element) {
  8513. return;
  8514. }
  8515. i += 1;
  8516. }
  8517. this.animatedContents.push({
  8518. fn: SVGElementsRenderer.createRenderFunction(data),
  8519. element: element,
  8520. data: data
  8521. });
  8522. };
  8523. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8524. var arr = elementData.styles;
  8525. var j;
  8526. var jLen = this.stylesList.length;
  8527. for (j = 0; j < jLen; j += 1) {
  8528. if (arr.indexOf(this.stylesList[j]) === -1 && !this.stylesList[j].closed) {
  8529. arr.push(this.stylesList[j]);
  8530. }
  8531. }
  8532. };
  8533. SVGShapeElement.prototype.reloadShapes = function () {
  8534. this._isFirstFrame = true;
  8535. var i;
  8536. var len = this.itemsData.length;
  8537. for (i = 0; i < len; i += 1) {
  8538. this.prevViewData[i] = this.itemsData[i];
  8539. }
  8540. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8541. this.filterUniqueShapes();
  8542. len = this.dynamicProperties.length;
  8543. for (i = 0; i < len; i += 1) {
  8544. this.dynamicProperties[i].getValue();
  8545. }
  8546. this.renderModifiers();
  8547. };
  8548. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8549. var ownTransformers = [].concat(transformers);
  8550. var i;
  8551. var len = arr.length - 1;
  8552. var j;
  8553. var jLen;
  8554. var ownStyles = [];
  8555. var ownModifiers = [];
  8556. var currentTransform;
  8557. var modifier;
  8558. var processedPos;
  8559. for (i = len; i >= 0; i -= 1) {
  8560. processedPos = this.searchProcessedElement(arr[i]);
  8561. if (!processedPos) {
  8562. arr[i]._render = render;
  8563. } else {
  8564. itemsData[i] = prevViewData[processedPos - 1];
  8565. }
  8566. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8567. if (!processedPos) {
  8568. itemsData[i] = this.createStyleElement(arr[i], level);
  8569. } else {
  8570. itemsData[i].style.closed = arr[i].hd;
  8571. }
  8572. if (arr[i]._render) {
  8573. if (itemsData[i].style.pElem.parentNode !== container) {
  8574. container.appendChild(itemsData[i].style.pElem);
  8575. }
  8576. }
  8577. ownStyles.push(itemsData[i].style);
  8578. } else if (arr[i].ty === 'gr') {
  8579. if (!processedPos) {
  8580. itemsData[i] = this.createGroupElement(arr[i]);
  8581. } else {
  8582. jLen = itemsData[i].it.length;
  8583. for (j = 0; j < jLen; j += 1) {
  8584. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8585. }
  8586. }
  8587. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8588. if (arr[i]._render) {
  8589. if (itemsData[i].gr.parentNode !== container) {
  8590. container.appendChild(itemsData[i].gr);
  8591. }
  8592. }
  8593. } else if (arr[i].ty === 'tr') {
  8594. if (!processedPos) {
  8595. itemsData[i] = this.createTransformElement(arr[i], container);
  8596. }
  8597. currentTransform = itemsData[i].transform;
  8598. ownTransformers.push(currentTransform);
  8599. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8600. if (!processedPos) {
  8601. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8602. }
  8603. this.setElementStyles(itemsData[i]);
  8604. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'ms' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  8605. if (!processedPos) {
  8606. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8607. modifier.init(this, arr[i]);
  8608. itemsData[i] = modifier;
  8609. this.shapeModifiers.push(modifier);
  8610. } else {
  8611. modifier = itemsData[i];
  8612. modifier.closed = false;
  8613. }
  8614. ownModifiers.push(modifier);
  8615. } else if (arr[i].ty === 'rp') {
  8616. if (!processedPos) {
  8617. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8618. itemsData[i] = modifier;
  8619. modifier.init(this, arr, i, itemsData);
  8620. this.shapeModifiers.push(modifier);
  8621. render = false;
  8622. } else {
  8623. modifier = itemsData[i];
  8624. modifier.closed = true;
  8625. }
  8626. ownModifiers.push(modifier);
  8627. }
  8628. this.addProcessedElement(arr[i], i + 1);
  8629. }
  8630. len = ownStyles.length;
  8631. for (i = 0; i < len; i += 1) {
  8632. ownStyles[i].closed = true;
  8633. }
  8634. len = ownModifiers.length;
  8635. for (i = 0; i < len; i += 1) {
  8636. ownModifiers[i].closed = true;
  8637. }
  8638. };
  8639. SVGShapeElement.prototype.renderInnerContent = function () {
  8640. this.renderModifiers();
  8641. var i;
  8642. var len = this.stylesList.length;
  8643. for (i = 0; i < len; i += 1) {
  8644. this.stylesList[i].reset();
  8645. }
  8646. this.renderShape();
  8647. for (i = 0; i < len; i += 1) {
  8648. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8649. if (this.stylesList[i].msElem) {
  8650. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  8651. // Adding M0 0 fixes same mask bug on all browsers
  8652. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8653. }
  8654. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8655. }
  8656. }
  8657. };
  8658. SVGShapeElement.prototype.renderShape = function () {
  8659. var i;
  8660. var len = this.animatedContents.length;
  8661. var animatedContent;
  8662. for (i = 0; i < len; i += 1) {
  8663. animatedContent = this.animatedContents[i];
  8664. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8665. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8666. }
  8667. }
  8668. };
  8669. SVGShapeElement.prototype.destroy = function () {
  8670. this.destroyBaseElement();
  8671. this.shapesData = null;
  8672. this.itemsData = null;
  8673. };
  8674. function LetterProps(o, sw, sc, fc, m, p) {
  8675. this.o = o;
  8676. this.sw = sw;
  8677. this.sc = sc;
  8678. this.fc = fc;
  8679. this.m = m;
  8680. this.p = p;
  8681. this._mdf = {
  8682. o: true,
  8683. sw: !!sw,
  8684. sc: !!sc,
  8685. fc: !!fc,
  8686. m: true,
  8687. p: true
  8688. };
  8689. }
  8690. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  8691. this._mdf.o = false;
  8692. this._mdf.sw = false;
  8693. this._mdf.sc = false;
  8694. this._mdf.fc = false;
  8695. this._mdf.m = false;
  8696. this._mdf.p = false;
  8697. var updated = false;
  8698. if (this.o !== o) {
  8699. this.o = o;
  8700. this._mdf.o = true;
  8701. updated = true;
  8702. }
  8703. if (this.sw !== sw) {
  8704. this.sw = sw;
  8705. this._mdf.sw = true;
  8706. updated = true;
  8707. }
  8708. if (this.sc !== sc) {
  8709. this.sc = sc;
  8710. this._mdf.sc = true;
  8711. updated = true;
  8712. }
  8713. if (this.fc !== fc) {
  8714. this.fc = fc;
  8715. this._mdf.fc = true;
  8716. updated = true;
  8717. }
  8718. if (this.m !== m) {
  8719. this.m = m;
  8720. this._mdf.m = true;
  8721. updated = true;
  8722. }
  8723. 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])) {
  8724. this.p = p;
  8725. this._mdf.p = true;
  8726. updated = true;
  8727. }
  8728. return updated;
  8729. };
  8730. function TextProperty(elem, data) {
  8731. this._frameId = initialDefaultFrame;
  8732. this.pv = '';
  8733. this.v = '';
  8734. this.kf = false;
  8735. this._isFirstFrame = true;
  8736. this._mdf = false;
  8737. if (data.d && data.d.sid) {
  8738. data.d = elem.globalData.slotManager.getProp(data.d);
  8739. }
  8740. this.data = data;
  8741. this.elem = elem;
  8742. this.comp = this.elem.comp;
  8743. this.keysIndex = 0;
  8744. this.canResize = false;
  8745. this.minimumFontSize = 1;
  8746. this.effectsSequence = [];
  8747. this.currentData = {
  8748. ascent: 0,
  8749. boxWidth: this.defaultBoxWidth,
  8750. f: '',
  8751. fStyle: '',
  8752. fWeight: '',
  8753. fc: '',
  8754. j: '',
  8755. justifyOffset: '',
  8756. l: [],
  8757. lh: 0,
  8758. lineWidths: [],
  8759. ls: '',
  8760. of: '',
  8761. s: '',
  8762. sc: '',
  8763. sw: 0,
  8764. t: 0,
  8765. tr: 0,
  8766. sz: 0,
  8767. ps: null,
  8768. fillColorAnim: false,
  8769. strokeColorAnim: false,
  8770. strokeWidthAnim: false,
  8771. yOffset: 0,
  8772. finalSize: 0,
  8773. finalText: [],
  8774. finalLineHeight: 0,
  8775. __complete: false
  8776. };
  8777. this.copyData(this.currentData, this.data.d.k[0].s);
  8778. if (!this.searchProperty()) {
  8779. this.completeTextData(this.currentData);
  8780. }
  8781. }
  8782. TextProperty.prototype.defaultBoxWidth = [0, 0];
  8783. TextProperty.prototype.copyData = function (obj, data) {
  8784. for (var s in data) {
  8785. if (Object.prototype.hasOwnProperty.call(data, s)) {
  8786. obj[s] = data[s];
  8787. }
  8788. }
  8789. return obj;
  8790. };
  8791. TextProperty.prototype.setCurrentData = function (data) {
  8792. if (!data.__complete) {
  8793. this.completeTextData(data);
  8794. }
  8795. this.currentData = data;
  8796. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  8797. this._mdf = true;
  8798. };
  8799. TextProperty.prototype.searchProperty = function () {
  8800. return this.searchKeyframes();
  8801. };
  8802. TextProperty.prototype.searchKeyframes = function () {
  8803. this.kf = this.data.d.k.length > 1;
  8804. if (this.kf) {
  8805. this.addEffect(this.getKeyframeValue.bind(this));
  8806. }
  8807. return this.kf;
  8808. };
  8809. TextProperty.prototype.addEffect = function (effectFunction) {
  8810. this.effectsSequence.push(effectFunction);
  8811. this.elem.addDynamicProperty(this);
  8812. };
  8813. TextProperty.prototype.getValue = function (_finalValue) {
  8814. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  8815. return;
  8816. }
  8817. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  8818. var currentValue = this.currentData;
  8819. var currentIndex = this.keysIndex;
  8820. if (this.lock) {
  8821. this.setCurrentData(this.currentData);
  8822. return;
  8823. }
  8824. this.lock = true;
  8825. this._mdf = false;
  8826. var i;
  8827. var len = this.effectsSequence.length;
  8828. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  8829. for (i = 0; i < len; i += 1) {
  8830. // Checking if index changed to prevent creating a new object every time the expression updates.
  8831. if (currentIndex !== this.keysIndex) {
  8832. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  8833. } else {
  8834. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  8835. }
  8836. }
  8837. if (currentValue !== finalValue) {
  8838. this.setCurrentData(finalValue);
  8839. }
  8840. this.v = this.currentData;
  8841. this.pv = this.v;
  8842. this.lock = false;
  8843. this.frameId = this.elem.globalData.frameId;
  8844. };
  8845. TextProperty.prototype.getKeyframeValue = function () {
  8846. var textKeys = this.data.d.k;
  8847. var frameNum = this.elem.comp.renderedFrame;
  8848. var i = 0;
  8849. var len = textKeys.length;
  8850. while (i <= len - 1) {
  8851. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  8852. break;
  8853. }
  8854. i += 1;
  8855. }
  8856. if (this.keysIndex !== i) {
  8857. this.keysIndex = i;
  8858. }
  8859. return this.data.d.k[this.keysIndex].s;
  8860. };
  8861. TextProperty.prototype.buildFinalText = function (text) {
  8862. var charactersArray = [];
  8863. var i = 0;
  8864. var len = text.length;
  8865. var charCode;
  8866. var secondCharCode;
  8867. var shouldCombine = false;
  8868. var shouldCombineNext = false;
  8869. var currentChars = '';
  8870. while (i < len) {
  8871. shouldCombine = shouldCombineNext;
  8872. shouldCombineNext = false;
  8873. charCode = text.charCodeAt(i);
  8874. currentChars = text.charAt(i);
  8875. if (FontManager.isCombinedCharacter(charCode)) {
  8876. shouldCombine = true;
  8877. // It's a potential surrogate pair (this is the High surrogate)
  8878. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  8879. if (FontManager.isRegionalFlag(text, i)) {
  8880. currentChars = text.substr(i, 14);
  8881. } else {
  8882. secondCharCode = text.charCodeAt(i + 1);
  8883. // It's a surrogate pair (this is the Low surrogate)
  8884. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  8885. if (FontManager.isModifier(charCode, secondCharCode)) {
  8886. currentChars = text.substr(i, 2);
  8887. shouldCombine = true;
  8888. } else if (FontManager.isFlagEmoji(text.substr(i, 4))) {
  8889. currentChars = text.substr(i, 4);
  8890. } else {
  8891. currentChars = text.substr(i, 2);
  8892. }
  8893. }
  8894. }
  8895. } else if (charCode > 0xDBFF) {
  8896. secondCharCode = text.charCodeAt(i + 1);
  8897. if (FontManager.isVariationSelector(charCode)) {
  8898. shouldCombine = true;
  8899. }
  8900. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  8901. shouldCombine = true;
  8902. shouldCombineNext = true;
  8903. }
  8904. if (shouldCombine) {
  8905. charactersArray[charactersArray.length - 1] += currentChars;
  8906. shouldCombine = false;
  8907. } else {
  8908. charactersArray.push(currentChars);
  8909. }
  8910. i += currentChars.length;
  8911. }
  8912. return charactersArray;
  8913. };
  8914. TextProperty.prototype.completeTextData = function (documentData) {
  8915. documentData.__complete = true;
  8916. var fontManager = this.elem.globalData.fontManager;
  8917. var data = this.data;
  8918. var letters = [];
  8919. var i;
  8920. var len;
  8921. var newLineFlag;
  8922. var index = 0;
  8923. var val;
  8924. var anchorGrouping = data.m.g;
  8925. var currentSize = 0;
  8926. var currentPos = 0;
  8927. var currentLine = 0;
  8928. var lineWidths = [];
  8929. var lineWidth = 0;
  8930. var maxLineWidth = 0;
  8931. var j;
  8932. var jLen;
  8933. var fontData = fontManager.getFontByName(documentData.f);
  8934. var charData;
  8935. var cLength = 0;
  8936. var fontProps = getFontProperties(fontData);
  8937. documentData.fWeight = fontProps.weight;
  8938. documentData.fStyle = fontProps.style;
  8939. documentData.finalSize = documentData.s;
  8940. documentData.finalText = this.buildFinalText(documentData.t);
  8941. len = documentData.finalText.length;
  8942. documentData.finalLineHeight = documentData.lh;
  8943. var trackingOffset = documentData.tr / 1000 * documentData.finalSize;
  8944. var charCode;
  8945. if (documentData.sz) {
  8946. var flag = true;
  8947. var boxWidth = documentData.sz[0];
  8948. var boxHeight = documentData.sz[1];
  8949. var currentHeight;
  8950. var finalText;
  8951. while (flag) {
  8952. finalText = this.buildFinalText(documentData.t);
  8953. currentHeight = 0;
  8954. lineWidth = 0;
  8955. len = finalText.length;
  8956. trackingOffset = documentData.tr / 1000 * documentData.finalSize;
  8957. var lastSpaceIndex = -1;
  8958. for (i = 0; i < len; i += 1) {
  8959. charCode = finalText[i].charCodeAt(0);
  8960. newLineFlag = false;
  8961. if (finalText[i] === ' ') {
  8962. lastSpaceIndex = i;
  8963. } else if (charCode === 13 || charCode === 3) {
  8964. lineWidth = 0;
  8965. newLineFlag = true;
  8966. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8967. }
  8968. if (fontManager.chars) {
  8969. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  8970. cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
  8971. } else {
  8972. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  8973. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  8974. }
  8975. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  8976. if (lastSpaceIndex === -1) {
  8977. len += 1;
  8978. } else {
  8979. i = lastSpaceIndex;
  8980. }
  8981. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8982. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r');
  8983. // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  8984. lastSpaceIndex = -1;
  8985. lineWidth = 0;
  8986. } else {
  8987. lineWidth += cLength;
  8988. lineWidth += trackingOffset;
  8989. }
  8990. }
  8991. currentHeight += fontData.ascent * documentData.finalSize / 100;
  8992. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  8993. documentData.finalSize -= 1;
  8994. documentData.finalLineHeight = documentData.finalSize * documentData.lh / documentData.s;
  8995. } else {
  8996. documentData.finalText = finalText;
  8997. len = documentData.finalText.length;
  8998. flag = false;
  8999. }
  9000. }
  9001. }
  9002. lineWidth = -trackingOffset;
  9003. cLength = 0;
  9004. var uncollapsedSpaces = 0;
  9005. var currentChar;
  9006. for (i = 0; i < len; i += 1) {
  9007. newLineFlag = false;
  9008. currentChar = documentData.finalText[i];
  9009. charCode = currentChar.charCodeAt(0);
  9010. if (charCode === 13 || charCode === 3) {
  9011. uncollapsedSpaces = 0;
  9012. lineWidths.push(lineWidth);
  9013. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9014. lineWidth = -2 * trackingOffset;
  9015. val = '';
  9016. newLineFlag = true;
  9017. currentLine += 1;
  9018. } else {
  9019. val = currentChar;
  9020. }
  9021. if (fontManager.chars) {
  9022. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  9023. cLength = newLineFlag ? 0 : charData.w * documentData.finalSize / 100;
  9024. } else {
  9025. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9026. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  9027. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9028. }
  9029. //
  9030. if (currentChar === ' ') {
  9031. uncollapsedSpaces += cLength + trackingOffset;
  9032. } else {
  9033. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  9034. uncollapsedSpaces = 0;
  9035. }
  9036. letters.push({
  9037. l: cLength,
  9038. an: cLength,
  9039. add: currentSize,
  9040. n: newLineFlag,
  9041. anIndexes: [],
  9042. val: val,
  9043. line: currentLine,
  9044. animatorJustifyOffset: 0
  9045. });
  9046. if (anchorGrouping == 2) {
  9047. // eslint-disable-line eqeqeq
  9048. currentSize += cLength;
  9049. if (val === '' || val === ' ' || i === len - 1) {
  9050. if (val === '' || val === ' ') {
  9051. currentSize -= cLength;
  9052. }
  9053. while (currentPos <= i) {
  9054. letters[currentPos].an = currentSize;
  9055. letters[currentPos].ind = index;
  9056. letters[currentPos].extra = cLength;
  9057. currentPos += 1;
  9058. }
  9059. index += 1;
  9060. currentSize = 0;
  9061. }
  9062. } else if (anchorGrouping == 3) {
  9063. // eslint-disable-line eqeqeq
  9064. currentSize += cLength;
  9065. if (val === '' || i === len - 1) {
  9066. if (val === '') {
  9067. currentSize -= cLength;
  9068. }
  9069. while (currentPos <= i) {
  9070. letters[currentPos].an = currentSize;
  9071. letters[currentPos].ind = index;
  9072. letters[currentPos].extra = cLength;
  9073. currentPos += 1;
  9074. }
  9075. currentSize = 0;
  9076. index += 1;
  9077. }
  9078. } else {
  9079. letters[index].ind = index;
  9080. letters[index].extra = 0;
  9081. index += 1;
  9082. }
  9083. }
  9084. documentData.l = letters;
  9085. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9086. lineWidths.push(lineWidth);
  9087. if (documentData.sz) {
  9088. documentData.boxWidth = documentData.sz[0];
  9089. documentData.justifyOffset = 0;
  9090. } else {
  9091. documentData.boxWidth = maxLineWidth;
  9092. switch (documentData.j) {
  9093. case 1:
  9094. documentData.justifyOffset = -documentData.boxWidth;
  9095. break;
  9096. case 2:
  9097. documentData.justifyOffset = -documentData.boxWidth / 2;
  9098. break;
  9099. default:
  9100. documentData.justifyOffset = 0;
  9101. }
  9102. }
  9103. documentData.lineWidths = lineWidths;
  9104. var animators = data.a;
  9105. var animatorData;
  9106. var letterData;
  9107. jLen = animators.length;
  9108. var based;
  9109. var ind;
  9110. var indexes = [];
  9111. for (j = 0; j < jLen; j += 1) {
  9112. animatorData = animators[j];
  9113. if (animatorData.a.sc) {
  9114. documentData.strokeColorAnim = true;
  9115. }
  9116. if (animatorData.a.sw) {
  9117. documentData.strokeWidthAnim = true;
  9118. }
  9119. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9120. documentData.fillColorAnim = true;
  9121. }
  9122. ind = 0;
  9123. based = animatorData.s.b;
  9124. for (i = 0; i < len; i += 1) {
  9125. letterData = letters[i];
  9126. letterData.anIndexes[j] = ind;
  9127. 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)) {
  9128. // eslint-disable-line eqeqeq
  9129. if (animatorData.s.rn === 1) {
  9130. indexes.push(ind);
  9131. }
  9132. ind += 1;
  9133. }
  9134. }
  9135. data.a[j].s.totalChars = ind;
  9136. var currentInd = -1;
  9137. var newInd;
  9138. if (animatorData.s.rn === 1) {
  9139. for (i = 0; i < len; i += 1) {
  9140. letterData = letters[i];
  9141. if (currentInd != letterData.anIndexes[j]) {
  9142. // eslint-disable-line eqeqeq
  9143. currentInd = letterData.anIndexes[j];
  9144. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9145. }
  9146. letterData.anIndexes[j] = newInd;
  9147. }
  9148. }
  9149. }
  9150. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9151. documentData.ls = documentData.ls || 0;
  9152. documentData.ascent = fontData.ascent * documentData.finalSize / 100;
  9153. };
  9154. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9155. index = index === undefined ? this.keysIndex : index;
  9156. var dData = this.copyData({}, this.data.d.k[index].s);
  9157. dData = this.copyData(dData, newData);
  9158. this.data.d.k[index].s = dData;
  9159. this.recalculate(index);
  9160. this.setCurrentData(dData);
  9161. this.elem.addDynamicProperty(this);
  9162. };
  9163. TextProperty.prototype.recalculate = function (index) {
  9164. var dData = this.data.d.k[index].s;
  9165. dData.__complete = false;
  9166. this.keysIndex = 0;
  9167. this._isFirstFrame = true;
  9168. this.getValue(dData);
  9169. };
  9170. TextProperty.prototype.canResizeFont = function (_canResize) {
  9171. this.canResize = _canResize;
  9172. this.recalculate(this.keysIndex);
  9173. this.elem.addDynamicProperty(this);
  9174. };
  9175. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9176. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9177. this.recalculate(this.keysIndex);
  9178. this.elem.addDynamicProperty(this);
  9179. };
  9180. var TextSelectorProp = function () {
  9181. var max = Math.max;
  9182. var min = Math.min;
  9183. var floor = Math.floor;
  9184. function TextSelectorPropFactory(elem, data) {
  9185. this._currentTextLength = -1;
  9186. this.k = false;
  9187. this.data = data;
  9188. this.elem = elem;
  9189. this.comp = elem.comp;
  9190. this.finalS = 0;
  9191. this.finalE = 0;
  9192. this.initDynamicPropertyContainer(elem);
  9193. this.s = PropertyFactory.getProp(elem, data.s || {
  9194. k: 0
  9195. }, 0, 0, this);
  9196. if ('e' in data) {
  9197. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9198. } else {
  9199. this.e = {
  9200. v: 100
  9201. };
  9202. }
  9203. this.o = PropertyFactory.getProp(elem, data.o || {
  9204. k: 0
  9205. }, 0, 0, this);
  9206. this.xe = PropertyFactory.getProp(elem, data.xe || {
  9207. k: 0
  9208. }, 0, 0, this);
  9209. this.ne = PropertyFactory.getProp(elem, data.ne || {
  9210. k: 0
  9211. }, 0, 0, this);
  9212. this.sm = PropertyFactory.getProp(elem, data.sm || {
  9213. k: 100
  9214. }, 0, 0, this);
  9215. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9216. if (!this.dynamicProperties.length) {
  9217. this.getValue();
  9218. }
  9219. }
  9220. TextSelectorPropFactory.prototype = {
  9221. getMult: function getMult(ind) {
  9222. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9223. this.getValue();
  9224. }
  9225. var x1 = 0;
  9226. var y1 = 0;
  9227. var x2 = 1;
  9228. var y2 = 1;
  9229. if (this.ne.v > 0) {
  9230. x1 = this.ne.v / 100.0;
  9231. } else {
  9232. y1 = -this.ne.v / 100.0;
  9233. }
  9234. if (this.xe.v > 0) {
  9235. x2 = 1.0 - this.xe.v / 100.0;
  9236. } else {
  9237. y2 = 1.0 + this.xe.v / 100.0;
  9238. }
  9239. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9240. var mult = 0;
  9241. var s = this.finalS;
  9242. var e = this.finalE;
  9243. var type = this.data.sh;
  9244. if (type === 2) {
  9245. if (e === s) {
  9246. mult = ind >= e ? 1 : 0;
  9247. } else {
  9248. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9249. }
  9250. mult = easer(mult);
  9251. } else if (type === 3) {
  9252. if (e === s) {
  9253. mult = ind >= e ? 0 : 1;
  9254. } else {
  9255. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9256. }
  9257. mult = easer(mult);
  9258. } else if (type === 4) {
  9259. if (e === s) {
  9260. mult = 0;
  9261. } else {
  9262. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9263. if (mult < 0.5) {
  9264. mult *= 2;
  9265. } else {
  9266. mult = 1 - 2 * (mult - 0.5);
  9267. }
  9268. }
  9269. mult = easer(mult);
  9270. } else if (type === 5) {
  9271. if (e === s) {
  9272. mult = 0;
  9273. } else {
  9274. var tot = e - s;
  9275. /* ind += 0.5;
  9276. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9277. ind = min(max(0, ind + 0.5 - s), e - s);
  9278. var x = -tot / 2 + ind;
  9279. var a = tot / 2;
  9280. mult = Math.sqrt(1 - x * x / (a * a));
  9281. }
  9282. mult = easer(mult);
  9283. } else if (type === 6) {
  9284. if (e === s) {
  9285. mult = 0;
  9286. } else {
  9287. ind = min(max(0, ind + 0.5 - s), e - s);
  9288. mult = (1 + Math.cos(Math.PI + Math.PI * 2 * ind / (e - s))) / 2; // eslint-disable-line
  9289. }
  9290. mult = easer(mult);
  9291. } else {
  9292. if (ind >= floor(s)) {
  9293. if (ind - s < 0) {
  9294. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9295. } else {
  9296. mult = max(0, min(e - ind, 1));
  9297. }
  9298. }
  9299. mult = easer(mult);
  9300. }
  9301. // Smoothness implementation.
  9302. // The smoothness represents a reduced range of the original [0; 1] range.
  9303. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9304. // Steps are:
  9305. // - find the lower value of the new range (threshold)
  9306. // - if multiplier is smaller than that value, floor it to 0
  9307. // - if it is larger,
  9308. // - subtract the threshold
  9309. // - divide it by the smoothness (this will return the range to [0; 1])
  9310. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9311. if (this.sm.v !== 100) {
  9312. var smoothness = this.sm.v * 0.01;
  9313. if (smoothness === 0) {
  9314. smoothness = 0.00000001;
  9315. }
  9316. var threshold = 0.5 - smoothness * 0.5;
  9317. if (mult < threshold) {
  9318. mult = 0;
  9319. } else {
  9320. mult = (mult - threshold) / smoothness;
  9321. if (mult > 1) {
  9322. mult = 1;
  9323. }
  9324. }
  9325. }
  9326. return mult * this.a.v;
  9327. },
  9328. getValue: function getValue(newCharsFlag) {
  9329. this.iterateDynamicProperties();
  9330. this._mdf = newCharsFlag || this._mdf;
  9331. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9332. if (newCharsFlag && this.data.r === 2) {
  9333. this.e.v = this._currentTextLength;
  9334. }
  9335. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9336. var o = this.o.v / divisor;
  9337. var s = this.s.v / divisor + o;
  9338. var e = this.e.v / divisor + o;
  9339. if (s > e) {
  9340. var _s = s;
  9341. s = e;
  9342. e = _s;
  9343. }
  9344. this.finalS = s;
  9345. this.finalE = e;
  9346. }
  9347. };
  9348. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9349. function getTextSelectorProp(elem, data, arr) {
  9350. return new TextSelectorPropFactory(elem, data, arr);
  9351. }
  9352. return {
  9353. getTextSelectorProp: getTextSelectorProp
  9354. };
  9355. }();
  9356. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9357. var defaultData = {
  9358. propType: false
  9359. };
  9360. var getProp = PropertyFactory.getProp;
  9361. var textAnimatorAnimatables = animatorProps.a;
  9362. this.a = {
  9363. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9364. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9365. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9366. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9367. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9368. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9369. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9370. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9371. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9372. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9373. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9374. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9375. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9376. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9377. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9378. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData
  9379. };
  9380. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9381. this.s.t = animatorProps.s.t;
  9382. }
  9383. function TextAnimatorProperty(textData, renderType, elem) {
  9384. this._isFirstFrame = true;
  9385. this._hasMaskedPath = false;
  9386. this._frameId = -1;
  9387. this._textData = textData;
  9388. this._renderType = renderType;
  9389. this._elem = elem;
  9390. this._animatorsData = createSizedArray(this._textData.a.length);
  9391. this._pathData = {};
  9392. this._moreOptions = {
  9393. alignment: {}
  9394. };
  9395. this.renderedLetters = [];
  9396. this.lettersChangedFlag = false;
  9397. this.initDynamicPropertyContainer(elem);
  9398. }
  9399. TextAnimatorProperty.prototype.searchProperties = function () {
  9400. var i;
  9401. var len = this._textData.a.length;
  9402. var animatorProps;
  9403. var getProp = PropertyFactory.getProp;
  9404. for (i = 0; i < len; i += 1) {
  9405. animatorProps = this._textData.a[i];
  9406. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9407. }
  9408. if (this._textData.p && 'm' in this._textData.p) {
  9409. this._pathData = {
  9410. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9411. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9412. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9413. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9414. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9415. m: this._elem.maskManager.getMaskProperty(this._textData.p.m)
  9416. };
  9417. this._hasMaskedPath = true;
  9418. } else {
  9419. this._hasMaskedPath = false;
  9420. }
  9421. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9422. };
  9423. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9424. this.lettersChangedFlag = lettersChangedFlag;
  9425. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9426. return;
  9427. }
  9428. this._isFirstFrame = false;
  9429. var alignment = this._moreOptions.alignment.v;
  9430. var animators = this._animatorsData;
  9431. var textData = this._textData;
  9432. var matrixHelper = this.mHelper;
  9433. var renderType = this._renderType;
  9434. var renderedLettersCount = this.renderedLetters.length;
  9435. var xPos;
  9436. var yPos;
  9437. var i;
  9438. var len;
  9439. var letters = documentData.l;
  9440. var pathInfo;
  9441. var currentLength;
  9442. var currentPoint;
  9443. var segmentLength;
  9444. var flag;
  9445. var pointInd;
  9446. var segmentInd;
  9447. var prevPoint;
  9448. var points;
  9449. var segments;
  9450. var partialLength;
  9451. var totalLength;
  9452. var perc;
  9453. var tanAngle;
  9454. var mask;
  9455. if (this._hasMaskedPath) {
  9456. mask = this._pathData.m;
  9457. if (!this._pathData.n || this._pathData._mdf) {
  9458. var paths = mask.v;
  9459. if (this._pathData.r.v) {
  9460. paths = paths.reverse();
  9461. }
  9462. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9463. pathInfo = {
  9464. tLength: 0,
  9465. segments: []
  9466. };
  9467. len = paths._length - 1;
  9468. var bezierData;
  9469. totalLength = 0;
  9470. for (i = 0; i < len; i += 1) {
  9471. bezierData = bez.buildBezierData(paths.v[i], paths.v[i + 1], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9472. pathInfo.tLength += bezierData.segmentLength;
  9473. pathInfo.segments.push(bezierData);
  9474. totalLength += bezierData.segmentLength;
  9475. }
  9476. i = len;
  9477. if (mask.v.c) {
  9478. bezierData = bez.buildBezierData(paths.v[i], paths.v[0], [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9479. pathInfo.tLength += bezierData.segmentLength;
  9480. pathInfo.segments.push(bezierData);
  9481. totalLength += bezierData.segmentLength;
  9482. }
  9483. this._pathData.pi = pathInfo;
  9484. }
  9485. pathInfo = this._pathData.pi;
  9486. currentLength = this._pathData.f.v;
  9487. segmentInd = 0;
  9488. pointInd = 1;
  9489. segmentLength = 0;
  9490. flag = true;
  9491. segments = pathInfo.segments;
  9492. if (currentLength < 0 && mask.v.c) {
  9493. if (pathInfo.tLength < Math.abs(currentLength)) {
  9494. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9495. }
  9496. segmentInd = segments.length - 1;
  9497. points = segments[segmentInd].points;
  9498. pointInd = points.length - 1;
  9499. while (currentLength < 0) {
  9500. currentLength += points[pointInd].partialLength;
  9501. pointInd -= 1;
  9502. if (pointInd < 0) {
  9503. segmentInd -= 1;
  9504. points = segments[segmentInd].points;
  9505. pointInd = points.length - 1;
  9506. }
  9507. }
  9508. }
  9509. points = segments[segmentInd].points;
  9510. prevPoint = points[pointInd - 1];
  9511. currentPoint = points[pointInd];
  9512. partialLength = currentPoint.partialLength;
  9513. }
  9514. len = letters.length;
  9515. xPos = 0;
  9516. yPos = 0;
  9517. var yOff = documentData.finalSize * 1.2 * 0.714;
  9518. var firstLine = true;
  9519. var animatorProps;
  9520. var animatorSelector;
  9521. var j;
  9522. var jLen;
  9523. var letterValue;
  9524. jLen = animators.length;
  9525. var mult;
  9526. var ind = -1;
  9527. var offf;
  9528. var xPathPos;
  9529. var yPathPos;
  9530. var initPathPos = currentLength;
  9531. var initSegmentInd = segmentInd;
  9532. var initPointInd = pointInd;
  9533. var currentLine = -1;
  9534. var elemOpacity;
  9535. var sc;
  9536. var sw;
  9537. var fc;
  9538. var k;
  9539. var letterSw;
  9540. var letterSc;
  9541. var letterFc;
  9542. var letterM = '';
  9543. var letterP = this.defaultPropsArray;
  9544. var letterO;
  9545. //
  9546. if (documentData.j === 2 || documentData.j === 1) {
  9547. var animatorJustifyOffset = 0;
  9548. var animatorFirstCharOffset = 0;
  9549. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9550. var lastIndex = 0;
  9551. var isNewLine = true;
  9552. for (i = 0; i < len; i += 1) {
  9553. if (letters[i].n) {
  9554. if (animatorJustifyOffset) {
  9555. animatorJustifyOffset += animatorFirstCharOffset;
  9556. }
  9557. while (lastIndex < i) {
  9558. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9559. lastIndex += 1;
  9560. }
  9561. animatorJustifyOffset = 0;
  9562. isNewLine = true;
  9563. } else {
  9564. for (j = 0; j < jLen; j += 1) {
  9565. animatorProps = animators[j].a;
  9566. if (animatorProps.t.propType) {
  9567. if (isNewLine && documentData.j === 2) {
  9568. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9569. }
  9570. animatorSelector = animators[j].s;
  9571. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9572. if (mult.length) {
  9573. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9574. } else {
  9575. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9576. }
  9577. }
  9578. }
  9579. isNewLine = false;
  9580. }
  9581. }
  9582. if (animatorJustifyOffset) {
  9583. animatorJustifyOffset += animatorFirstCharOffset;
  9584. }
  9585. while (lastIndex < i) {
  9586. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9587. lastIndex += 1;
  9588. }
  9589. }
  9590. //
  9591. for (i = 0; i < len; i += 1) {
  9592. matrixHelper.reset();
  9593. elemOpacity = 1;
  9594. if (letters[i].n) {
  9595. xPos = 0;
  9596. yPos += documentData.yOffset;
  9597. yPos += firstLine ? 1 : 0;
  9598. currentLength = initPathPos;
  9599. firstLine = false;
  9600. if (this._hasMaskedPath) {
  9601. segmentInd = initSegmentInd;
  9602. pointInd = initPointInd;
  9603. points = segments[segmentInd].points;
  9604. prevPoint = points[pointInd - 1];
  9605. currentPoint = points[pointInd];
  9606. partialLength = currentPoint.partialLength;
  9607. segmentLength = 0;
  9608. }
  9609. letterM = '';
  9610. letterFc = '';
  9611. letterSw = '';
  9612. letterO = '';
  9613. letterP = this.defaultPropsArray;
  9614. } else {
  9615. if (this._hasMaskedPath) {
  9616. if (currentLine !== letters[i].line) {
  9617. switch (documentData.j) {
  9618. case 1:
  9619. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9620. break;
  9621. case 2:
  9622. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9623. break;
  9624. default:
  9625. break;
  9626. }
  9627. currentLine = letters[i].line;
  9628. }
  9629. if (ind !== letters[i].ind) {
  9630. if (letters[ind]) {
  9631. currentLength += letters[ind].extra;
  9632. }
  9633. currentLength += letters[i].an / 2;
  9634. ind = letters[i].ind;
  9635. }
  9636. currentLength += alignment[0] * letters[i].an * 0.005;
  9637. var animatorOffset = 0;
  9638. for (j = 0; j < jLen; j += 1) {
  9639. animatorProps = animators[j].a;
  9640. if (animatorProps.p.propType) {
  9641. animatorSelector = animators[j].s;
  9642. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9643. if (mult.length) {
  9644. animatorOffset += animatorProps.p.v[0] * mult[0];
  9645. } else {
  9646. animatorOffset += animatorProps.p.v[0] * mult;
  9647. }
  9648. }
  9649. if (animatorProps.a.propType) {
  9650. animatorSelector = animators[j].s;
  9651. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9652. if (mult.length) {
  9653. animatorOffset += animatorProps.a.v[0] * mult[0];
  9654. } else {
  9655. animatorOffset += animatorProps.a.v[0] * mult;
  9656. }
  9657. }
  9658. }
  9659. flag = true;
  9660. // Force alignment only works with a single line for now
  9661. if (this._pathData.a.v) {
  9662. currentLength = letters[0].an * 0.5 + (totalLength - this._pathData.f.v - letters[0].an * 0.5 - letters[letters.length - 1].an * 0.5) * ind / (len - 1);
  9663. currentLength += this._pathData.f.v;
  9664. }
  9665. while (flag) {
  9666. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9667. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9668. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9669. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9670. matrixHelper.translate(-alignment[0] * letters[i].an * 0.005, -(alignment[1] * yOff) * 0.01);
  9671. flag = false;
  9672. } else if (points) {
  9673. segmentLength += currentPoint.partialLength;
  9674. pointInd += 1;
  9675. if (pointInd >= points.length) {
  9676. pointInd = 0;
  9677. segmentInd += 1;
  9678. if (!segments[segmentInd]) {
  9679. if (mask.v.c) {
  9680. pointInd = 0;
  9681. segmentInd = 0;
  9682. points = segments[segmentInd].points;
  9683. } else {
  9684. segmentLength -= currentPoint.partialLength;
  9685. points = null;
  9686. }
  9687. } else {
  9688. points = segments[segmentInd].points;
  9689. }
  9690. }
  9691. if (points) {
  9692. prevPoint = currentPoint;
  9693. currentPoint = points[pointInd];
  9694. partialLength = currentPoint.partialLength;
  9695. }
  9696. }
  9697. }
  9698. offf = letters[i].an / 2 - letters[i].add;
  9699. matrixHelper.translate(-offf, 0, 0);
  9700. } else {
  9701. offf = letters[i].an / 2 - letters[i].add;
  9702. matrixHelper.translate(-offf, 0, 0);
  9703. // Grouping alignment
  9704. matrixHelper.translate(-alignment[0] * letters[i].an * 0.005, -alignment[1] * yOff * 0.01, 0);
  9705. }
  9706. for (j = 0; j < jLen; j += 1) {
  9707. animatorProps = animators[j].a;
  9708. if (animatorProps.t.propType) {
  9709. animatorSelector = animators[j].s;
  9710. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9711. // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9712. if (xPos !== 0 || documentData.j !== 0) {
  9713. if (this._hasMaskedPath) {
  9714. if (mult.length) {
  9715. currentLength += animatorProps.t.v * mult[0];
  9716. } else {
  9717. currentLength += animatorProps.t.v * mult;
  9718. }
  9719. } else if (mult.length) {
  9720. xPos += animatorProps.t.v * mult[0];
  9721. } else {
  9722. xPos += animatorProps.t.v * mult;
  9723. }
  9724. }
  9725. }
  9726. }
  9727. if (documentData.strokeWidthAnim) {
  9728. sw = documentData.sw || 0;
  9729. }
  9730. if (documentData.strokeColorAnim) {
  9731. if (documentData.sc) {
  9732. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  9733. } else {
  9734. sc = [0, 0, 0];
  9735. }
  9736. }
  9737. if (documentData.fillColorAnim && documentData.fc) {
  9738. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  9739. }
  9740. for (j = 0; j < jLen; j += 1) {
  9741. animatorProps = animators[j].a;
  9742. if (animatorProps.a.propType) {
  9743. animatorSelector = animators[j].s;
  9744. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9745. if (mult.length) {
  9746. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  9747. } else {
  9748. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  9749. }
  9750. }
  9751. }
  9752. for (j = 0; j < jLen; j += 1) {
  9753. animatorProps = animators[j].a;
  9754. if (animatorProps.s.propType) {
  9755. animatorSelector = animators[j].s;
  9756. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9757. if (mult.length) {
  9758. matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult[0], 1 + (animatorProps.s.v[1] - 1) * mult[1], 1);
  9759. } else {
  9760. matrixHelper.scale(1 + (animatorProps.s.v[0] - 1) * mult, 1 + (animatorProps.s.v[1] - 1) * mult, 1);
  9761. }
  9762. }
  9763. }
  9764. for (j = 0; j < jLen; j += 1) {
  9765. animatorProps = animators[j].a;
  9766. animatorSelector = animators[j].s;
  9767. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9768. if (animatorProps.sk.propType) {
  9769. if (mult.length) {
  9770. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  9771. } else {
  9772. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  9773. }
  9774. }
  9775. if (animatorProps.r.propType) {
  9776. if (mult.length) {
  9777. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  9778. } else {
  9779. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  9780. }
  9781. }
  9782. if (animatorProps.ry.propType) {
  9783. if (mult.length) {
  9784. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  9785. } else {
  9786. matrixHelper.rotateY(animatorProps.ry.v * mult);
  9787. }
  9788. }
  9789. if (animatorProps.rx.propType) {
  9790. if (mult.length) {
  9791. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  9792. } else {
  9793. matrixHelper.rotateX(animatorProps.rx.v * mult);
  9794. }
  9795. }
  9796. if (animatorProps.o.propType) {
  9797. if (mult.length) {
  9798. elemOpacity += (animatorProps.o.v * mult[0] - elemOpacity) * mult[0];
  9799. } else {
  9800. elemOpacity += (animatorProps.o.v * mult - elemOpacity) * mult;
  9801. }
  9802. }
  9803. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  9804. if (mult.length) {
  9805. sw += animatorProps.sw.v * mult[0];
  9806. } else {
  9807. sw += animatorProps.sw.v * mult;
  9808. }
  9809. }
  9810. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  9811. for (k = 0; k < 3; k += 1) {
  9812. if (mult.length) {
  9813. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  9814. } else {
  9815. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  9816. }
  9817. }
  9818. }
  9819. if (documentData.fillColorAnim && documentData.fc) {
  9820. if (animatorProps.fc.propType) {
  9821. for (k = 0; k < 3; k += 1) {
  9822. if (mult.length) {
  9823. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  9824. } else {
  9825. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  9826. }
  9827. }
  9828. }
  9829. if (animatorProps.fh.propType) {
  9830. if (mult.length) {
  9831. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  9832. } else {
  9833. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  9834. }
  9835. }
  9836. if (animatorProps.fs.propType) {
  9837. if (mult.length) {
  9838. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  9839. } else {
  9840. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  9841. }
  9842. }
  9843. if (animatorProps.fb.propType) {
  9844. if (mult.length) {
  9845. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  9846. } else {
  9847. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  9848. }
  9849. }
  9850. }
  9851. }
  9852. for (j = 0; j < jLen; j += 1) {
  9853. animatorProps = animators[j].a;
  9854. if (animatorProps.p.propType) {
  9855. animatorSelector = animators[j].s;
  9856. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9857. if (this._hasMaskedPath) {
  9858. if (mult.length) {
  9859. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  9860. } else {
  9861. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9862. }
  9863. } else if (mult.length) {
  9864. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  9865. } else {
  9866. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9867. }
  9868. }
  9869. }
  9870. if (documentData.strokeWidthAnim) {
  9871. letterSw = sw < 0 ? 0 : sw;
  9872. }
  9873. if (documentData.strokeColorAnim) {
  9874. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  9875. }
  9876. if (documentData.fillColorAnim && documentData.fc) {
  9877. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  9878. }
  9879. if (this._hasMaskedPath) {
  9880. matrixHelper.translate(0, -documentData.ls);
  9881. matrixHelper.translate(0, alignment[1] * yOff * 0.01 + yPos, 0);
  9882. if (this._pathData.p.v) {
  9883. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  9884. var rot = Math.atan(tanAngle) * 180 / Math.PI;
  9885. if (currentPoint.point[0] < prevPoint.point[0]) {
  9886. rot += 180;
  9887. }
  9888. matrixHelper.rotate(-rot * Math.PI / 180);
  9889. }
  9890. matrixHelper.translate(xPathPos, yPathPos, 0);
  9891. currentLength -= alignment[0] * letters[i].an * 0.005;
  9892. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  9893. currentLength += letters[i].an / 2;
  9894. currentLength += documentData.tr * 0.001 * documentData.finalSize;
  9895. }
  9896. } else {
  9897. matrixHelper.translate(xPos, yPos, 0);
  9898. if (documentData.ps) {
  9899. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  9900. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9901. }
  9902. switch (documentData.j) {
  9903. case 1:
  9904. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  9905. break;
  9906. case 2:
  9907. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  9908. break;
  9909. default:
  9910. break;
  9911. }
  9912. matrixHelper.translate(0, -documentData.ls);
  9913. matrixHelper.translate(offf, 0, 0);
  9914. matrixHelper.translate(alignment[0] * letters[i].an * 0.005, alignment[1] * yOff * 0.01, 0);
  9915. xPos += letters[i].l + documentData.tr * 0.001 * documentData.finalSize;
  9916. }
  9917. if (renderType === 'html') {
  9918. letterM = matrixHelper.toCSS();
  9919. } else if (renderType === 'svg') {
  9920. letterM = matrixHelper.to2dCSS();
  9921. } else {
  9922. 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]];
  9923. }
  9924. letterO = elemOpacity;
  9925. }
  9926. if (renderedLettersCount <= i) {
  9927. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  9928. this.renderedLetters.push(letterValue);
  9929. renderedLettersCount += 1;
  9930. this.lettersChangedFlag = true;
  9931. } else {
  9932. letterValue = this.renderedLetters[i];
  9933. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  9934. }
  9935. }
  9936. };
  9937. TextAnimatorProperty.prototype.getValue = function () {
  9938. if (this._elem.globalData.frameId === this._frameId) {
  9939. return;
  9940. }
  9941. this._frameId = this._elem.globalData.frameId;
  9942. this.iterateDynamicProperties();
  9943. };
  9944. TextAnimatorProperty.prototype.mHelper = new Matrix();
  9945. TextAnimatorProperty.prototype.defaultPropsArray = [];
  9946. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  9947. function ITextElement() {}
  9948. ITextElement.prototype.initElement = function (data, globalData, comp) {
  9949. this.lettersChangedFlag = true;
  9950. this.initFrame();
  9951. this.initBaseData(data, globalData, comp);
  9952. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  9953. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  9954. this.initTransform(data, globalData, comp);
  9955. this.initHierarchy();
  9956. this.initRenderable();
  9957. this.initRendererElement();
  9958. this.createContainerElements();
  9959. this.createRenderableComponents();
  9960. this.createContent();
  9961. this.hide();
  9962. this.textAnimator.searchProperties(this.dynamicProperties);
  9963. };
  9964. ITextElement.prototype.prepareFrame = function (num) {
  9965. this._mdf = false;
  9966. this.prepareRenderableFrame(num);
  9967. this.prepareProperties(num, this.isInRange);
  9968. };
  9969. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  9970. var j;
  9971. var jLen = shapes.length;
  9972. var pathNodes;
  9973. var shapeStr = '';
  9974. for (j = 0; j < jLen; j += 1) {
  9975. if (shapes[j].ty === 'sh') {
  9976. pathNodes = shapes[j].ks.k;
  9977. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  9978. }
  9979. }
  9980. return shapeStr;
  9981. };
  9982. ITextElement.prototype.updateDocumentData = function (newData, index) {
  9983. this.textProperty.updateDocumentData(newData, index);
  9984. };
  9985. ITextElement.prototype.canResizeFont = function (_canResize) {
  9986. this.textProperty.canResizeFont(_canResize);
  9987. };
  9988. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  9989. this.textProperty.setMinimumFontSize(_fontSize);
  9990. };
  9991. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  9992. if (documentData.ps) {
  9993. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9994. }
  9995. matrixHelper.translate(0, -documentData.ls, 0);
  9996. switch (documentData.j) {
  9997. case 1:
  9998. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  9999. break;
  10000. case 2:
  10001. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  10002. break;
  10003. default:
  10004. break;
  10005. }
  10006. matrixHelper.translate(xPos, yPos, 0);
  10007. };
  10008. ITextElement.prototype.buildColor = function (colorData) {
  10009. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  10010. };
  10011. ITextElement.prototype.emptyProp = new LetterProps();
  10012. ITextElement.prototype.destroy = function () {};
  10013. ITextElement.prototype.validateText = function () {
  10014. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  10015. this.buildNewText();
  10016. this.textProperty._isFirstFrame = false;
  10017. this.textProperty._mdf = false;
  10018. }
  10019. };
  10020. var emptyShapeData = {
  10021. shapes: []
  10022. };
  10023. function SVGTextLottieElement(data, globalData, comp) {
  10024. this.textSpans = [];
  10025. this.renderType = 'svg';
  10026. this.initElement(data, globalData, comp);
  10027. }
  10028. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  10029. SVGTextLottieElement.prototype.createContent = function () {
  10030. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  10031. this.textContainer = createNS('text');
  10032. }
  10033. };
  10034. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  10035. var i = 0;
  10036. var len = textArray.length;
  10037. var textContents = [];
  10038. var currentTextContent = '';
  10039. while (i < len) {
  10040. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  10041. textContents.push(currentTextContent);
  10042. currentTextContent = '';
  10043. } else {
  10044. currentTextContent += textArray[i];
  10045. }
  10046. i += 1;
  10047. }
  10048. textContents.push(currentTextContent);
  10049. return textContents;
  10050. };
  10051. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  10052. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  10053. // but since text internal content gets only rendered once and then it's never rerendered,
  10054. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  10055. // Avoiding cloning is preferred since cloning each character shape data is expensive
  10056. if (data.shapes && data.shapes.length) {
  10057. var shape = data.shapes[0];
  10058. if (shape.it) {
  10059. var shapeItem = shape.it[shape.it.length - 1];
  10060. if (shapeItem.s) {
  10061. shapeItem.s.k[0] = scale;
  10062. shapeItem.s.k[1] = scale;
  10063. }
  10064. }
  10065. }
  10066. return data;
  10067. };
  10068. SVGTextLottieElement.prototype.buildNewText = function () {
  10069. this.addDynamicProperty(this);
  10070. var i;
  10071. var len;
  10072. var documentData = this.textProperty.currentData;
  10073. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  10074. if (documentData.fc) {
  10075. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  10076. } else {
  10077. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  10078. }
  10079. if (documentData.sc) {
  10080. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  10081. this.layerElement.setAttribute('stroke-width', documentData.sw);
  10082. }
  10083. this.layerElement.setAttribute('font-size', documentData.finalSize);
  10084. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10085. if (fontData.fClass) {
  10086. this.layerElement.setAttribute('class', fontData.fClass);
  10087. } else {
  10088. this.layerElement.setAttribute('font-family', fontData.fFamily);
  10089. var fWeight = documentData.fWeight;
  10090. var fStyle = documentData.fStyle;
  10091. this.layerElement.setAttribute('font-style', fStyle);
  10092. this.layerElement.setAttribute('font-weight', fWeight);
  10093. }
  10094. this.layerElement.setAttribute('aria-label', documentData.t);
  10095. var letters = documentData.l || [];
  10096. var usesGlyphs = !!this.globalData.fontManager.chars;
  10097. len = letters.length;
  10098. var tSpan;
  10099. var matrixHelper = this.mHelper;
  10100. var shapeStr = '';
  10101. var singleShape = this.data.singleShape;
  10102. var xPos = 0;
  10103. var yPos = 0;
  10104. var firstLine = true;
  10105. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10106. if (singleShape && !usesGlyphs && !documentData.sz) {
  10107. var tElement = this.textContainer;
  10108. var justify = 'start';
  10109. switch (documentData.j) {
  10110. case 1:
  10111. justify = 'end';
  10112. break;
  10113. case 2:
  10114. justify = 'middle';
  10115. break;
  10116. default:
  10117. justify = 'start';
  10118. break;
  10119. }
  10120. tElement.setAttribute('text-anchor', justify);
  10121. tElement.setAttribute('letter-spacing', trackingOffset);
  10122. var textContent = this.buildTextContents(documentData.finalText);
  10123. len = textContent.length;
  10124. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10125. for (i = 0; i < len; i += 1) {
  10126. tSpan = this.textSpans[i].span || createNS('tspan');
  10127. tSpan.textContent = textContent[i];
  10128. tSpan.setAttribute('x', 0);
  10129. tSpan.setAttribute('y', yPos);
  10130. tSpan.style.display = 'inherit';
  10131. tElement.appendChild(tSpan);
  10132. if (!this.textSpans[i]) {
  10133. this.textSpans[i] = {
  10134. span: null,
  10135. glyph: null
  10136. };
  10137. }
  10138. this.textSpans[i].span = tSpan;
  10139. yPos += documentData.finalLineHeight;
  10140. }
  10141. this.layerElement.appendChild(tElement);
  10142. } else {
  10143. var cachedSpansLength = this.textSpans.length;
  10144. var charData;
  10145. for (i = 0; i < len; i += 1) {
  10146. if (!this.textSpans[i]) {
  10147. this.textSpans[i] = {
  10148. span: null,
  10149. childSpan: null,
  10150. glyph: null
  10151. };
  10152. }
  10153. if (!usesGlyphs || !singleShape || i === 0) {
  10154. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10155. if (cachedSpansLength <= i) {
  10156. tSpan.setAttribute('stroke-linecap', 'butt');
  10157. tSpan.setAttribute('stroke-linejoin', 'round');
  10158. tSpan.setAttribute('stroke-miterlimit', '4');
  10159. this.textSpans[i].span = tSpan;
  10160. if (usesGlyphs) {
  10161. var childSpan = createNS('g');
  10162. tSpan.appendChild(childSpan);
  10163. this.textSpans[i].childSpan = childSpan;
  10164. }
  10165. this.textSpans[i].span = tSpan;
  10166. this.layerElement.appendChild(tSpan);
  10167. }
  10168. tSpan.style.display = 'inherit';
  10169. }
  10170. matrixHelper.reset();
  10171. if (singleShape) {
  10172. if (letters[i].n) {
  10173. xPos = -trackingOffset;
  10174. yPos += documentData.yOffset;
  10175. yPos += firstLine ? 1 : 0;
  10176. firstLine = false;
  10177. }
  10178. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10179. xPos += letters[i].l || 0;
  10180. // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10181. xPos += trackingOffset;
  10182. }
  10183. if (usesGlyphs) {
  10184. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  10185. var glyphElement;
  10186. // t === 1 means the character has been replaced with an animated shaped
  10187. if (charData.t === 1) {
  10188. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10189. } else {
  10190. var data = emptyShapeData;
  10191. if (charData.data && charData.data.shapes) {
  10192. data = this.buildShapeData(charData.data, documentData.finalSize);
  10193. }
  10194. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10195. }
  10196. if (this.textSpans[i].glyph) {
  10197. var glyph = this.textSpans[i].glyph;
  10198. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10199. glyph.destroy();
  10200. }
  10201. this.textSpans[i].glyph = glyphElement;
  10202. glyphElement._debug = true;
  10203. glyphElement.prepareFrame(0);
  10204. glyphElement.renderFrame();
  10205. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
  10206. // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10207. // this might have issues with strokes and might need a different solution
  10208. if (charData.t === 1) {
  10209. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10210. }
  10211. } else {
  10212. if (singleShape) {
  10213. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10214. }
  10215. tSpan.textContent = letters[i].val;
  10216. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10217. }
  10218. //
  10219. }
  10220. if (singleShape && tSpan) {
  10221. tSpan.setAttribute('d', shapeStr);
  10222. }
  10223. }
  10224. while (i < this.textSpans.length) {
  10225. this.textSpans[i].span.style.display = 'none';
  10226. i += 1;
  10227. }
  10228. this._sizeChanged = true;
  10229. };
  10230. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10231. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10232. this.renderInnerContent();
  10233. if (this._sizeChanged) {
  10234. this._sizeChanged = false;
  10235. var textBox = this.layerElement.getBBox();
  10236. this.bbox = {
  10237. top: textBox.y,
  10238. left: textBox.x,
  10239. width: textBox.width,
  10240. height: textBox.height
  10241. };
  10242. }
  10243. return this.bbox;
  10244. };
  10245. SVGTextLottieElement.prototype.getValue = function () {
  10246. var i;
  10247. var len = this.textSpans.length;
  10248. var glyphElement;
  10249. this.renderedFrame = this.comp.renderedFrame;
  10250. for (i = 0; i < len; i += 1) {
  10251. glyphElement = this.textSpans[i].glyph;
  10252. if (glyphElement) {
  10253. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10254. if (glyphElement._mdf) {
  10255. this._mdf = true;
  10256. }
  10257. }
  10258. }
  10259. };
  10260. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10261. this.validateText();
  10262. if (!this.data.singleShape || this._mdf) {
  10263. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10264. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10265. this._sizeChanged = true;
  10266. var i;
  10267. var len;
  10268. var renderedLetters = this.textAnimator.renderedLetters;
  10269. var letters = this.textProperty.currentData.l;
  10270. len = letters.length;
  10271. var renderedLetter;
  10272. var textSpan;
  10273. var glyphElement;
  10274. for (i = 0; i < len; i += 1) {
  10275. if (!letters[i].n) {
  10276. renderedLetter = renderedLetters[i];
  10277. textSpan = this.textSpans[i].span;
  10278. glyphElement = this.textSpans[i].glyph;
  10279. if (glyphElement) {
  10280. glyphElement.renderFrame();
  10281. }
  10282. if (renderedLetter._mdf.m) {
  10283. textSpan.setAttribute('transform', renderedLetter.m);
  10284. }
  10285. if (renderedLetter._mdf.o) {
  10286. textSpan.setAttribute('opacity', renderedLetter.o);
  10287. }
  10288. if (renderedLetter._mdf.sw) {
  10289. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10290. }
  10291. if (renderedLetter._mdf.sc) {
  10292. textSpan.setAttribute('stroke', renderedLetter.sc);
  10293. }
  10294. if (renderedLetter._mdf.fc) {
  10295. textSpan.setAttribute('fill', renderedLetter.fc);
  10296. }
  10297. }
  10298. }
  10299. }
  10300. }
  10301. };
  10302. function ISolidElement(data, globalData, comp) {
  10303. this.initElement(data, globalData, comp);
  10304. }
  10305. extendPrototype([IImageElement], ISolidElement);
  10306. ISolidElement.prototype.createContent = function () {
  10307. var rect = createNS('rect');
  10308. /// /rect.style.width = this.data.sw;
  10309. /// /rect.style.height = this.data.sh;
  10310. /// /rect.style.fill = this.data.sc;
  10311. rect.setAttribute('width', this.data.sw);
  10312. rect.setAttribute('height', this.data.sh);
  10313. rect.setAttribute('fill', this.data.sc);
  10314. this.layerElement.appendChild(rect);
  10315. };
  10316. function NullElement(data, globalData, comp) {
  10317. this.initFrame();
  10318. this.initBaseData(data, globalData, comp);
  10319. this.initFrame();
  10320. this.initTransform(data, globalData, comp);
  10321. this.initHierarchy();
  10322. }
  10323. NullElement.prototype.prepareFrame = function (num) {
  10324. this.prepareProperties(num, true);
  10325. };
  10326. NullElement.prototype.renderFrame = function () {};
  10327. NullElement.prototype.getBaseElement = function () {
  10328. return null;
  10329. };
  10330. NullElement.prototype.destroy = function () {};
  10331. NullElement.prototype.sourceRectAtTime = function () {};
  10332. NullElement.prototype.hide = function () {};
  10333. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10334. function SVGRendererBase() {}
  10335. extendPrototype([BaseRenderer], SVGRendererBase);
  10336. SVGRendererBase.prototype.createNull = function (data) {
  10337. return new NullElement(data, this.globalData, this);
  10338. };
  10339. SVGRendererBase.prototype.createShape = function (data) {
  10340. return new SVGShapeElement(data, this.globalData, this);
  10341. };
  10342. SVGRendererBase.prototype.createText = function (data) {
  10343. return new SVGTextLottieElement(data, this.globalData, this);
  10344. };
  10345. SVGRendererBase.prototype.createImage = function (data) {
  10346. return new IImageElement(data, this.globalData, this);
  10347. };
  10348. SVGRendererBase.prototype.createSolid = function (data) {
  10349. return new ISolidElement(data, this.globalData, this);
  10350. };
  10351. SVGRendererBase.prototype.configAnimation = function (animData) {
  10352. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10353. this.svgElement.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  10354. if (this.renderConfig.viewBoxSize) {
  10355. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10356. } else {
  10357. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10358. }
  10359. if (!this.renderConfig.viewBoxOnly) {
  10360. this.svgElement.setAttribute('width', animData.w);
  10361. this.svgElement.setAttribute('height', animData.h);
  10362. this.svgElement.style.width = '100%';
  10363. this.svgElement.style.height = '100%';
  10364. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10365. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10366. }
  10367. if (this.renderConfig.width) {
  10368. this.svgElement.setAttribute('width', this.renderConfig.width);
  10369. }
  10370. if (this.renderConfig.height) {
  10371. this.svgElement.setAttribute('height', this.renderConfig.height);
  10372. }
  10373. if (this.renderConfig.className) {
  10374. this.svgElement.setAttribute('class', this.renderConfig.className);
  10375. }
  10376. if (this.renderConfig.id) {
  10377. this.svgElement.setAttribute('id', this.renderConfig.id);
  10378. }
  10379. if (this.renderConfig.focusable !== undefined) {
  10380. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10381. }
  10382. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio);
  10383. // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10384. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10385. this.animationItem.wrapper.appendChild(this.svgElement);
  10386. // Mask animation
  10387. var defs = this.globalData.defs;
  10388. this.setupGlobalData(animData, defs);
  10389. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10390. this.data = animData;
  10391. var maskElement = createNS('clipPath');
  10392. var rect = createNS('rect');
  10393. rect.setAttribute('width', animData.w);
  10394. rect.setAttribute('height', animData.h);
  10395. rect.setAttribute('x', 0);
  10396. rect.setAttribute('y', 0);
  10397. var maskId = createElementID();
  10398. maskElement.setAttribute('id', maskId);
  10399. maskElement.appendChild(rect);
  10400. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10401. defs.appendChild(maskElement);
  10402. this.layers = animData.layers;
  10403. this.elements = createSizedArray(animData.layers.length);
  10404. };
  10405. SVGRendererBase.prototype.destroy = function () {
  10406. if (this.animationItem.wrapper) {
  10407. this.animationItem.wrapper.innerText = '';
  10408. }
  10409. this.layerElement = null;
  10410. this.globalData.defs = null;
  10411. var i;
  10412. var len = this.layers ? this.layers.length : 0;
  10413. for (i = 0; i < len; i += 1) {
  10414. if (this.elements[i] && this.elements[i].destroy) {
  10415. this.elements[i].destroy();
  10416. }
  10417. }
  10418. this.elements.length = 0;
  10419. this.destroyed = true;
  10420. this.animationItem = null;
  10421. };
  10422. SVGRendererBase.prototype.updateContainerSize = function () {};
  10423. SVGRendererBase.prototype.findIndexByInd = function (ind) {
  10424. var i = 0;
  10425. var len = this.layers.length;
  10426. for (i = 0; i < len; i += 1) {
  10427. if (this.layers[i].ind === ind) {
  10428. return i;
  10429. }
  10430. }
  10431. return -1;
  10432. };
  10433. SVGRendererBase.prototype.buildItem = function (pos) {
  10434. var elements = this.elements;
  10435. if (elements[pos] || this.layers[pos].ty === 99) {
  10436. return;
  10437. }
  10438. elements[pos] = true;
  10439. var element = this.createItem(this.layers[pos]);
  10440. elements[pos] = element;
  10441. if (getExpressionsPlugin()) {
  10442. if (this.layers[pos].ty === 0) {
  10443. this.globalData.projectInterface.registerComposition(element);
  10444. }
  10445. element.initExpressions();
  10446. }
  10447. this.appendElementInPos(element, pos);
  10448. if (this.layers[pos].tt) {
  10449. var elementIndex = 'tp' in this.layers[pos] ? this.findIndexByInd(this.layers[pos].tp) : pos - 1;
  10450. if (elementIndex === -1) {
  10451. return;
  10452. }
  10453. if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
  10454. this.buildItem(elementIndex);
  10455. this.addPendingElement(element);
  10456. } else {
  10457. var matteElement = elements[elementIndex];
  10458. var matteMask = matteElement.getMatte(this.layers[pos].tt);
  10459. element.setMatte(matteMask);
  10460. }
  10461. }
  10462. };
  10463. SVGRendererBase.prototype.checkPendingElements = function () {
  10464. while (this.pendingElements.length) {
  10465. var element = this.pendingElements.pop();
  10466. element.checkParenting();
  10467. if (element.data.tt) {
  10468. var i = 0;
  10469. var len = this.elements.length;
  10470. while (i < len) {
  10471. if (this.elements[i] === element) {
  10472. var elementIndex = 'tp' in element.data ? this.findIndexByInd(element.data.tp) : i - 1;
  10473. var matteElement = this.elements[elementIndex];
  10474. var matteMask = matteElement.getMatte(this.layers[i].tt);
  10475. element.setMatte(matteMask);
  10476. break;
  10477. }
  10478. i += 1;
  10479. }
  10480. }
  10481. }
  10482. };
  10483. SVGRendererBase.prototype.renderFrame = function (num) {
  10484. if (this.renderedFrame === num || this.destroyed) {
  10485. return;
  10486. }
  10487. if (num === null) {
  10488. num = this.renderedFrame;
  10489. } else {
  10490. this.renderedFrame = num;
  10491. }
  10492. // console.log('-------');
  10493. // console.log('FRAME ',num);
  10494. this.globalData.frameNum = num;
  10495. this.globalData.frameId += 1;
  10496. this.globalData.projectInterface.currentFrame = num;
  10497. this.globalData._mdf = false;
  10498. var i;
  10499. var len = this.layers.length;
  10500. if (!this.completeLayers) {
  10501. this.checkLayers(num);
  10502. }
  10503. for (i = len - 1; i >= 0; i -= 1) {
  10504. if (this.completeLayers || this.elements[i]) {
  10505. this.elements[i].prepareFrame(num - this.layers[i].st);
  10506. }
  10507. }
  10508. if (this.globalData._mdf) {
  10509. for (i = 0; i < len; i += 1) {
  10510. if (this.completeLayers || this.elements[i]) {
  10511. this.elements[i].renderFrame();
  10512. }
  10513. }
  10514. }
  10515. };
  10516. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10517. var newElement = element.getBaseElement();
  10518. if (!newElement) {
  10519. return;
  10520. }
  10521. var i = 0;
  10522. var nextElement;
  10523. while (i < pos) {
  10524. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10525. nextElement = this.elements[i].getBaseElement();
  10526. }
  10527. i += 1;
  10528. }
  10529. if (nextElement) {
  10530. this.layerElement.insertBefore(newElement, nextElement);
  10531. } else {
  10532. this.layerElement.appendChild(newElement);
  10533. }
  10534. };
  10535. SVGRendererBase.prototype.hide = function () {
  10536. this.layerElement.style.display = 'none';
  10537. };
  10538. SVGRendererBase.prototype.show = function () {
  10539. this.layerElement.style.display = 'block';
  10540. };
  10541. function ICompElement() {}
  10542. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10543. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10544. this.initFrame();
  10545. this.initBaseData(data, globalData, comp);
  10546. this.initTransform(data, globalData, comp);
  10547. this.initRenderable();
  10548. this.initHierarchy();
  10549. this.initRendererElement();
  10550. this.createContainerElements();
  10551. this.createRenderableComponents();
  10552. if (this.data.xt || !globalData.progressiveLoad) {
  10553. this.buildAllItems();
  10554. }
  10555. this.hide();
  10556. };
  10557. /* ICompElement.prototype.hide = function(){
  10558. if(!this.hidden){
  10559. this.hideElement();
  10560. var i,len = this.elements.length;
  10561. for( i = 0; i < len; i+=1 ){
  10562. if(this.elements[i]){
  10563. this.elements[i].hide();
  10564. }
  10565. }
  10566. }
  10567. }; */
  10568. ICompElement.prototype.prepareFrame = function (num) {
  10569. this._mdf = false;
  10570. this.prepareRenderableFrame(num);
  10571. this.prepareProperties(num, this.isInRange);
  10572. if (!this.isInRange && !this.data.xt) {
  10573. return;
  10574. }
  10575. if (!this.tm._placeholder) {
  10576. var timeRemapped = this.tm.v;
  10577. if (timeRemapped === this.data.op) {
  10578. timeRemapped = this.data.op - 1;
  10579. }
  10580. this.renderedFrame = timeRemapped;
  10581. } else {
  10582. this.renderedFrame = num / this.data.sr;
  10583. }
  10584. var i;
  10585. var len = this.elements.length;
  10586. if (!this.completeLayers) {
  10587. this.checkLayers(this.renderedFrame);
  10588. }
  10589. // This iteration needs to be backwards because of how expressions connect between each other
  10590. for (i = len - 1; i >= 0; i -= 1) {
  10591. if (this.completeLayers || this.elements[i]) {
  10592. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10593. if (this.elements[i]._mdf) {
  10594. this._mdf = true;
  10595. }
  10596. }
  10597. }
  10598. };
  10599. ICompElement.prototype.renderInnerContent = function () {
  10600. var i;
  10601. var len = this.layers.length;
  10602. for (i = 0; i < len; i += 1) {
  10603. if (this.completeLayers || this.elements[i]) {
  10604. this.elements[i].renderFrame();
  10605. }
  10606. }
  10607. };
  10608. ICompElement.prototype.setElements = function (elems) {
  10609. this.elements = elems;
  10610. };
  10611. ICompElement.prototype.getElements = function () {
  10612. return this.elements;
  10613. };
  10614. ICompElement.prototype.destroyElements = function () {
  10615. var i;
  10616. var len = this.layers.length;
  10617. for (i = 0; i < len; i += 1) {
  10618. if (this.elements[i]) {
  10619. this.elements[i].destroy();
  10620. }
  10621. }
  10622. };
  10623. ICompElement.prototype.destroy = function () {
  10624. this.destroyElements();
  10625. this.destroyBaseElement();
  10626. };
  10627. function SVGCompElement(data, globalData, comp) {
  10628. this.layers = data.layers;
  10629. this.supports3d = true;
  10630. this.completeLayers = false;
  10631. this.pendingElements = [];
  10632. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10633. this.initElement(data, globalData, comp);
  10634. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  10635. _placeholder: true
  10636. };
  10637. }
  10638. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10639. SVGCompElement.prototype.createComp = function (data) {
  10640. return new SVGCompElement(data, this.globalData, this);
  10641. };
  10642. function SVGRenderer(animationItem, config) {
  10643. this.animationItem = animationItem;
  10644. this.layers = null;
  10645. this.renderedFrame = -1;
  10646. this.svgElement = createNS('svg');
  10647. var ariaLabel = '';
  10648. if (config && config.title) {
  10649. var titleElement = createNS('title');
  10650. var titleId = createElementID();
  10651. titleElement.setAttribute('id', titleId);
  10652. titleElement.textContent = config.title;
  10653. this.svgElement.appendChild(titleElement);
  10654. ariaLabel += titleId;
  10655. }
  10656. if (config && config.description) {
  10657. var descElement = createNS('desc');
  10658. var descId = createElementID();
  10659. descElement.setAttribute('id', descId);
  10660. descElement.textContent = config.description;
  10661. this.svgElement.appendChild(descElement);
  10662. ariaLabel += ' ' + descId;
  10663. }
  10664. if (ariaLabel) {
  10665. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10666. }
  10667. var defs = createNS('defs');
  10668. this.svgElement.appendChild(defs);
  10669. var maskElement = createNS('g');
  10670. this.svgElement.appendChild(maskElement);
  10671. this.layerElement = maskElement;
  10672. this.renderConfig = {
  10673. preserveAspectRatio: config && config.preserveAspectRatio || 'xMidYMid meet',
  10674. imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || 'xMidYMid slice',
  10675. contentVisibility: config && config.contentVisibility || 'visible',
  10676. progressiveLoad: config && config.progressiveLoad || false,
  10677. hideOnTransparent: !(config && config.hideOnTransparent === false),
  10678. viewBoxOnly: config && config.viewBoxOnly || false,
  10679. viewBoxSize: config && config.viewBoxSize || false,
  10680. className: config && config.className || '',
  10681. id: config && config.id || '',
  10682. focusable: config && config.focusable,
  10683. filterSize: {
  10684. width: config && config.filterSize && config.filterSize.width || '100%',
  10685. height: config && config.filterSize && config.filterSize.height || '100%',
  10686. x: config && config.filterSize && config.filterSize.x || '0%',
  10687. y: config && config.filterSize && config.filterSize.y || '0%'
  10688. },
  10689. width: config && config.width,
  10690. height: config && config.height,
  10691. runExpressions: !config || config.runExpressions === undefined || config.runExpressions
  10692. };
  10693. this.globalData = {
  10694. _mdf: false,
  10695. frameNum: -1,
  10696. defs: defs,
  10697. renderConfig: this.renderConfig
  10698. };
  10699. this.elements = [];
  10700. this.pendingElements = [];
  10701. this.destroyed = false;
  10702. this.rendererType = 'svg';
  10703. }
  10704. extendPrototype([SVGRendererBase], SVGRenderer);
  10705. SVGRenderer.prototype.createComp = function (data) {
  10706. return new SVGCompElement(data, this.globalData, this);
  10707. };
  10708. function ShapeTransformManager() {
  10709. this.sequences = {};
  10710. this.sequenceList = [];
  10711. this.transform_key_count = 0;
  10712. }
  10713. ShapeTransformManager.prototype = {
  10714. addTransformSequence: function addTransformSequence(transforms) {
  10715. var i;
  10716. var len = transforms.length;
  10717. var key = '_';
  10718. for (i = 0; i < len; i += 1) {
  10719. key += transforms[i].transform.key + '_';
  10720. }
  10721. var sequence = this.sequences[key];
  10722. if (!sequence) {
  10723. sequence = {
  10724. transforms: [].concat(transforms),
  10725. finalTransform: new Matrix(),
  10726. _mdf: false
  10727. };
  10728. this.sequences[key] = sequence;
  10729. this.sequenceList.push(sequence);
  10730. }
  10731. return sequence;
  10732. },
  10733. processSequence: function processSequence(sequence, isFirstFrame) {
  10734. var i = 0;
  10735. var len = sequence.transforms.length;
  10736. var _mdf = isFirstFrame;
  10737. while (i < len && !isFirstFrame) {
  10738. if (sequence.transforms[i].transform.mProps._mdf) {
  10739. _mdf = true;
  10740. break;
  10741. }
  10742. i += 1;
  10743. }
  10744. if (_mdf) {
  10745. sequence.finalTransform.reset();
  10746. for (i = len - 1; i >= 0; i -= 1) {
  10747. sequence.finalTransform.multiply(sequence.transforms[i].transform.mProps.v);
  10748. }
  10749. }
  10750. sequence._mdf = _mdf;
  10751. },
  10752. processSequences: function processSequences(isFirstFrame) {
  10753. var i;
  10754. var len = this.sequenceList.length;
  10755. for (i = 0; i < len; i += 1) {
  10756. this.processSequence(this.sequenceList[i], isFirstFrame);
  10757. }
  10758. },
  10759. getNewKey: function getNewKey() {
  10760. this.transform_key_count += 1;
  10761. return '_' + this.transform_key_count;
  10762. }
  10763. };
  10764. var lumaLoader = function lumaLoader() {
  10765. var id = '__lottie_element_luma_buffer';
  10766. var lumaBuffer = null;
  10767. var lumaBufferCtx = null;
  10768. var svg = null;
  10769. // This alternate solution has a slight delay before the filter is applied, resulting in a flicker on the first frame.
  10770. // Keeping this here for reference, and in the future, if offscreen canvas supports url filters, this can be used.
  10771. // For now, neither of them work for offscreen canvas, so canvas workers can't support the luma track matte mask.
  10772. // Naming it solution 2 to mark the extra comment lines.
  10773. /*
  10774. var svgString = [
  10775. '<svg xmlns="http://www.w3.org/2000/svg">',
  10776. '<filter id="' + id + '">',
  10777. '<feColorMatrix type="matrix" color-interpolation-filters="sRGB" values="',
  10778. '0.3, 0.3, 0.3, 0, 0, ',
  10779. '0.3, 0.3, 0.3, 0, 0, ',
  10780. '0.3, 0.3, 0.3, 0, 0, ',
  10781. '0.3, 0.3, 0.3, 0, 0',
  10782. '"/>',
  10783. '</filter>',
  10784. '</svg>',
  10785. ].join('');
  10786. var blob = new Blob([svgString], { type: 'image/svg+xml' });
  10787. var url = URL.createObjectURL(blob);
  10788. */
  10789. function createLumaSvgFilter() {
  10790. var _svg = createNS('svg');
  10791. var fil = createNS('filter');
  10792. var matrix = createNS('feColorMatrix');
  10793. fil.setAttribute('id', id);
  10794. matrix.setAttribute('type', 'matrix');
  10795. matrix.setAttribute('color-interpolation-filters', 'sRGB');
  10796. matrix.setAttribute('values', '0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0');
  10797. fil.appendChild(matrix);
  10798. _svg.appendChild(fil);
  10799. _svg.setAttribute('id', id + '_svg');
  10800. if (featureSupport.svgLumaHidden) {
  10801. _svg.style.display = 'none';
  10802. }
  10803. return _svg;
  10804. }
  10805. function loadLuma() {
  10806. if (!lumaBuffer) {
  10807. svg = createLumaSvgFilter();
  10808. document.body.appendChild(svg);
  10809. lumaBuffer = createTag('canvas');
  10810. lumaBufferCtx = lumaBuffer.getContext('2d');
  10811. // lumaBufferCtx.filter = `url('${url}#__lottie_element_luma_buffer')`; // part of solution 2
  10812. lumaBufferCtx.filter = 'url(#' + id + ')';
  10813. lumaBufferCtx.fillStyle = 'rgba(0,0,0,0)';
  10814. lumaBufferCtx.fillRect(0, 0, 1, 1);
  10815. }
  10816. }
  10817. function getLuma(canvas) {
  10818. if (!lumaBuffer) {
  10819. loadLuma();
  10820. }
  10821. lumaBuffer.width = canvas.width;
  10822. lumaBuffer.height = canvas.height;
  10823. // lumaBufferCtx.filter = `url('${url}#__lottie_element_luma_buffer')`; // part of solution 2
  10824. lumaBufferCtx.filter = 'url(#' + id + ')';
  10825. return lumaBuffer;
  10826. }
  10827. return {
  10828. load: loadLuma,
  10829. get: getLuma
  10830. };
  10831. };
  10832. function createCanvas(width, height) {
  10833. if (featureSupport.offscreenCanvas) {
  10834. return new OffscreenCanvas(width, height);
  10835. }
  10836. var canvas = createTag('canvas');
  10837. canvas.width = width;
  10838. canvas.height = height;
  10839. return canvas;
  10840. }
  10841. var assetLoader = function () {
  10842. return {
  10843. loadLumaCanvas: lumaLoader.load,
  10844. getLumaCanvas: lumaLoader.get,
  10845. createCanvas: createCanvas
  10846. };
  10847. }();
  10848. var registeredEffects = {};
  10849. function CVEffects(elem) {
  10850. var i;
  10851. var len = elem.data.ef ? elem.data.ef.length : 0;
  10852. this.filters = [];
  10853. var filterManager;
  10854. for (i = 0; i < len; i += 1) {
  10855. filterManager = null;
  10856. var type = elem.data.ef[i].ty;
  10857. if (registeredEffects[type]) {
  10858. var Effect = registeredEffects[type].effect;
  10859. filterManager = new Effect(elem.effectsManager.effectElements[i], elem);
  10860. }
  10861. if (filterManager) {
  10862. this.filters.push(filterManager);
  10863. }
  10864. }
  10865. if (this.filters.length) {
  10866. elem.addRenderableComponent(this);
  10867. }
  10868. }
  10869. CVEffects.prototype.renderFrame = function (_isFirstFrame) {
  10870. var i;
  10871. var len = this.filters.length;
  10872. for (i = 0; i < len; i += 1) {
  10873. this.filters[i].renderFrame(_isFirstFrame);
  10874. }
  10875. };
  10876. CVEffects.prototype.getEffects = function (type) {
  10877. var i;
  10878. var len = this.filters.length;
  10879. var effects = [];
  10880. for (i = 0; i < len; i += 1) {
  10881. if (this.filters[i].type === type) {
  10882. effects.push(this.filters[i]);
  10883. }
  10884. }
  10885. return effects;
  10886. };
  10887. function registerEffect(id, effect) {
  10888. registeredEffects[id] = {
  10889. effect: effect
  10890. };
  10891. }
  10892. function CVMaskElement(data, element) {
  10893. this.data = data;
  10894. this.element = element;
  10895. this.masksProperties = this.data.masksProperties || [];
  10896. this.viewData = createSizedArray(this.masksProperties.length);
  10897. var i;
  10898. var len = this.masksProperties.length;
  10899. var hasMasks = false;
  10900. for (i = 0; i < len; i += 1) {
  10901. if (this.masksProperties[i].mode !== 'n') {
  10902. hasMasks = true;
  10903. }
  10904. this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element, this.masksProperties[i], 3);
  10905. }
  10906. this.hasMasks = hasMasks;
  10907. if (hasMasks) {
  10908. this.element.addRenderableComponent(this);
  10909. }
  10910. }
  10911. CVMaskElement.prototype.renderFrame = function () {
  10912. if (!this.hasMasks) {
  10913. return;
  10914. }
  10915. var transform = this.element.finalTransform.mat;
  10916. var ctx = this.element.canvasContext;
  10917. var i;
  10918. var len = this.masksProperties.length;
  10919. var pt;
  10920. var pts;
  10921. var data;
  10922. ctx.beginPath();
  10923. for (i = 0; i < len; i += 1) {
  10924. if (this.masksProperties[i].mode !== 'n') {
  10925. if (this.masksProperties[i].inv) {
  10926. ctx.moveTo(0, 0);
  10927. ctx.lineTo(this.element.globalData.compSize.w, 0);
  10928. ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h);
  10929. ctx.lineTo(0, this.element.globalData.compSize.h);
  10930. ctx.lineTo(0, 0);
  10931. }
  10932. data = this.viewData[i].v;
  10933. pt = transform.applyToPointArray(data.v[0][0], data.v[0][1], 0);
  10934. ctx.moveTo(pt[0], pt[1]);
  10935. var j;
  10936. var jLen = data._length;
  10937. for (j = 1; j < jLen; j += 1) {
  10938. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]);
  10939. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  10940. }
  10941. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]);
  10942. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  10943. }
  10944. }
  10945. this.element.globalData.renderer.save(true);
  10946. ctx.clip();
  10947. };
  10948. CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty;
  10949. CVMaskElement.prototype.destroy = function () {
  10950. this.element = null;
  10951. };
  10952. function CVBaseElement() {}
  10953. var operationsMap = {
  10954. 1: 'source-in',
  10955. 2: 'source-out',
  10956. 3: 'source-in',
  10957. 4: 'source-out'
  10958. };
  10959. CVBaseElement.prototype = {
  10960. createElements: function createElements() {},
  10961. initRendererElement: function initRendererElement() {},
  10962. createContainerElements: function createContainerElements() {
  10963. // If the layer is masked we will use two buffers to store each different states of the drawing
  10964. // This solution is not ideal for several reason. But unfortunately, because of the recursive
  10965. // nature of the render tree, it's the only simple way to make sure one inner mask doesn't override an outer mask.
  10966. // TODO: try to reduce the size of these buffers to the size of the composition contaning the layer
  10967. // It might be challenging because the layer most likely is transformed in some way
  10968. if (this.data.tt >= 1) {
  10969. this.buffers = [];
  10970. var canvasContext = this.globalData.canvasContext;
  10971. var bufferCanvas = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
  10972. this.buffers.push(bufferCanvas);
  10973. var bufferCanvas2 = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
  10974. this.buffers.push(bufferCanvas2);
  10975. if (this.data.tt >= 3 && !document._isProxy) {
  10976. assetLoader.loadLumaCanvas();
  10977. }
  10978. }
  10979. this.canvasContext = this.globalData.canvasContext;
  10980. this.transformCanvas = this.globalData.transformCanvas;
  10981. this.renderableEffectsManager = new CVEffects(this);
  10982. this.searchEffectTransforms();
  10983. },
  10984. createContent: function createContent() {},
  10985. setBlendMode: function setBlendMode() {
  10986. var globalData = this.globalData;
  10987. if (globalData.blendMode !== this.data.bm) {
  10988. globalData.blendMode = this.data.bm;
  10989. var blendModeValue = getBlendMode(this.data.bm);
  10990. globalData.canvasContext.globalCompositeOperation = blendModeValue;
  10991. }
  10992. },
  10993. createRenderableComponents: function createRenderableComponents() {
  10994. this.maskManager = new CVMaskElement(this.data, this);
  10995. this.transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  10996. },
  10997. hideElement: function hideElement() {
  10998. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  10999. this.hidden = true;
  11000. }
  11001. },
  11002. showElement: function showElement() {
  11003. if (this.isInRange && !this.isTransparent) {
  11004. this.hidden = false;
  11005. this._isFirstFrame = true;
  11006. this.maskManager._isFirstFrame = true;
  11007. }
  11008. },
  11009. clearCanvas: function clearCanvas(canvasContext) {
  11010. canvasContext.clearRect(this.transformCanvas.tx, this.transformCanvas.ty, this.transformCanvas.w * this.transformCanvas.sx, this.transformCanvas.h * this.transformCanvas.sy);
  11011. },
  11012. prepareLayer: function prepareLayer() {
  11013. if (this.data.tt >= 1) {
  11014. var buffer = this.buffers[0];
  11015. var bufferCtx = buffer.getContext('2d');
  11016. this.clearCanvas(bufferCtx);
  11017. // on the first buffer we store the current state of the global drawing
  11018. bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11019. // The next four lines are to clear the canvas
  11020. // TODO: Check if there is a way to clear the canvas without resetting the transform
  11021. this.currentTransform = this.canvasContext.getTransform();
  11022. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11023. this.clearCanvas(this.canvasContext);
  11024. this.canvasContext.setTransform(this.currentTransform);
  11025. }
  11026. },
  11027. exitLayer: function exitLayer() {
  11028. if (this.data.tt >= 1) {
  11029. var buffer = this.buffers[1];
  11030. // On the second buffer we store the current state of the global drawing
  11031. // that only contains the content of this layer
  11032. // (if it is a composition, it also includes the nested layers)
  11033. var bufferCtx = buffer.getContext('2d');
  11034. this.clearCanvas(bufferCtx);
  11035. bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11036. // We clear the canvas again
  11037. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11038. this.clearCanvas(this.canvasContext);
  11039. this.canvasContext.setTransform(this.currentTransform);
  11040. // We draw the mask
  11041. var mask = this.comp.getElementById('tp' in this.data ? this.data.tp : this.data.ind - 1);
  11042. mask.renderFrame(true);
  11043. // We draw the second buffer (that contains the content of this layer)
  11044. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11045. // If the mask is a Luma matte, we need to do two extra painting operations
  11046. // the _isProxy check is to avoid drawing a fake canvas in workers that will throw an error
  11047. if (this.data.tt >= 3 && !document._isProxy) {
  11048. // We copy the painted mask to a buffer that has a color matrix filter applied to it
  11049. // that applies the rgb values to the alpha channel
  11050. var lumaBuffer = assetLoader.getLumaCanvas(this.canvasContext.canvas);
  11051. var lumaBufferCtx = lumaBuffer.getContext('2d');
  11052. lumaBufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11053. this.clearCanvas(this.canvasContext);
  11054. // we repaint the context with the mask applied to it
  11055. this.canvasContext.drawImage(lumaBuffer, 0, 0);
  11056. }
  11057. this.canvasContext.globalCompositeOperation = operationsMap[this.data.tt];
  11058. this.canvasContext.drawImage(buffer, 0, 0);
  11059. // We finally draw the first buffer (that contains the content of the global drawing)
  11060. // We use destination-over to draw the global drawing below the current layer
  11061. this.canvasContext.globalCompositeOperation = 'destination-over';
  11062. this.canvasContext.drawImage(this.buffers[0], 0, 0);
  11063. this.canvasContext.setTransform(this.currentTransform);
  11064. // We reset the globalCompositeOperation to source-over, the standard type of operation
  11065. this.canvasContext.globalCompositeOperation = 'source-over';
  11066. }
  11067. },
  11068. renderFrame: function renderFrame(forceRender) {
  11069. if (this.hidden || this.data.hd) {
  11070. return;
  11071. }
  11072. if (this.data.td === 1 && !forceRender) {
  11073. return;
  11074. }
  11075. this.renderTransform();
  11076. this.renderRenderable();
  11077. this.renderLocalTransform();
  11078. this.setBlendMode();
  11079. var forceRealStack = this.data.ty === 0;
  11080. this.prepareLayer();
  11081. this.globalData.renderer.save(forceRealStack);
  11082. this.globalData.renderer.ctxTransform(this.finalTransform.localMat.props);
  11083. this.globalData.renderer.ctxOpacity(this.finalTransform.localOpacity);
  11084. this.renderInnerContent();
  11085. this.globalData.renderer.restore(forceRealStack);
  11086. this.exitLayer();
  11087. if (this.maskManager.hasMasks) {
  11088. this.globalData.renderer.restore(true);
  11089. }
  11090. if (this._isFirstFrame) {
  11091. this._isFirstFrame = false;
  11092. }
  11093. },
  11094. destroy: function destroy() {
  11095. this.canvasContext = null;
  11096. this.data = null;
  11097. this.globalData = null;
  11098. this.maskManager.destroy();
  11099. },
  11100. mHelper: new Matrix()
  11101. };
  11102. CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement;
  11103. CVBaseElement.prototype.show = CVBaseElement.prototype.showElement;
  11104. function CVShapeData(element, data, styles, transformsManager) {
  11105. this.styledShapes = [];
  11106. this.tr = [0, 0, 0, 0, 0, 0];
  11107. var ty = 4;
  11108. if (data.ty === 'rc') {
  11109. ty = 5;
  11110. } else if (data.ty === 'el') {
  11111. ty = 6;
  11112. } else if (data.ty === 'sr') {
  11113. ty = 7;
  11114. }
  11115. this.sh = ShapePropertyFactory.getShapeProp(element, data, ty, element);
  11116. var i;
  11117. var len = styles.length;
  11118. var styledShape;
  11119. for (i = 0; i < len; i += 1) {
  11120. if (!styles[i].closed) {
  11121. styledShape = {
  11122. transforms: transformsManager.addTransformSequence(styles[i].transforms),
  11123. trNodes: []
  11124. };
  11125. this.styledShapes.push(styledShape);
  11126. styles[i].elements.push(styledShape);
  11127. }
  11128. }
  11129. }
  11130. CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated;
  11131. function CVShapeElement(data, globalData, comp) {
  11132. this.shapes = [];
  11133. this.shapesData = data.shapes;
  11134. this.stylesList = [];
  11135. this.itemsData = [];
  11136. this.prevViewData = [];
  11137. this.shapeModifiers = [];
  11138. this.processedElements = [];
  11139. this.transformsManager = new ShapeTransformManager();
  11140. this.initElement(data, globalData, comp);
  11141. }
  11142. extendPrototype([BaseElement, TransformElement, CVBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableElement], CVShapeElement);
  11143. CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement;
  11144. CVShapeElement.prototype.transformHelper = {
  11145. opacity: 1,
  11146. _opMdf: false
  11147. };
  11148. CVShapeElement.prototype.dashResetter = [];
  11149. CVShapeElement.prototype.createContent = function () {
  11150. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11151. };
  11152. CVShapeElement.prototype.createStyleElement = function (data, transforms) {
  11153. var styleElem = {
  11154. data: data,
  11155. type: data.ty,
  11156. preTransforms: this.transformsManager.addTransformSequence(transforms),
  11157. transforms: [],
  11158. elements: [],
  11159. closed: data.hd === true
  11160. };
  11161. var elementData = {};
  11162. if (data.ty === 'fl' || data.ty === 'st') {
  11163. elementData.c = PropertyFactory.getProp(this, data.c, 1, 255, this);
  11164. if (!elementData.c.k) {
  11165. styleElem.co = 'rgb(' + bmFloor(elementData.c.v[0]) + ',' + bmFloor(elementData.c.v[1]) + ',' + bmFloor(elementData.c.v[2]) + ')';
  11166. }
  11167. } else if (data.ty === 'gf' || data.ty === 'gs') {
  11168. elementData.s = PropertyFactory.getProp(this, data.s, 1, null, this);
  11169. elementData.e = PropertyFactory.getProp(this, data.e, 1, null, this);
  11170. elementData.h = PropertyFactory.getProp(this, data.h || {
  11171. k: 0
  11172. }, 0, 0.01, this);
  11173. elementData.a = PropertyFactory.getProp(this, data.a || {
  11174. k: 0
  11175. }, 0, degToRads, this);
  11176. elementData.g = new GradientProperty(this, data.g, this);
  11177. }
  11178. elementData.o = PropertyFactory.getProp(this, data.o, 0, 0.01, this);
  11179. if (data.ty === 'st' || data.ty === 'gs') {
  11180. styleElem.lc = lineCapEnum[data.lc || 2];
  11181. styleElem.lj = lineJoinEnum[data.lj || 2];
  11182. if (data.lj == 1) {
  11183. // eslint-disable-line eqeqeq
  11184. styleElem.ml = data.ml;
  11185. }
  11186. elementData.w = PropertyFactory.getProp(this, data.w, 0, null, this);
  11187. if (!elementData.w.k) {
  11188. styleElem.wi = elementData.w.v;
  11189. }
  11190. if (data.d) {
  11191. var d = new DashProperty(this, data.d, 'canvas', this);
  11192. elementData.d = d;
  11193. if (!elementData.d.k) {
  11194. styleElem.da = elementData.d.dashArray;
  11195. styleElem["do"] = elementData.d.dashoffset[0];
  11196. }
  11197. }
  11198. } else {
  11199. styleElem.r = data.r === 2 ? 'evenodd' : 'nonzero';
  11200. }
  11201. this.stylesList.push(styleElem);
  11202. elementData.style = styleElem;
  11203. return elementData;
  11204. };
  11205. CVShapeElement.prototype.createGroupElement = function () {
  11206. var elementData = {
  11207. it: [],
  11208. prevViewData: []
  11209. };
  11210. return elementData;
  11211. };
  11212. CVShapeElement.prototype.createTransformElement = function (data) {
  11213. var elementData = {
  11214. transform: {
  11215. opacity: 1,
  11216. _opMdf: false,
  11217. key: this.transformsManager.getNewKey(),
  11218. op: PropertyFactory.getProp(this, data.o, 0, 0.01, this),
  11219. mProps: TransformPropertyFactory.getTransformProperty(this, data, this)
  11220. }
  11221. };
  11222. return elementData;
  11223. };
  11224. CVShapeElement.prototype.createShapeElement = function (data) {
  11225. var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager);
  11226. this.shapes.push(elementData);
  11227. this.addShapeToModifiers(elementData);
  11228. return elementData;
  11229. };
  11230. CVShapeElement.prototype.reloadShapes = function () {
  11231. this._isFirstFrame = true;
  11232. var i;
  11233. var len = this.itemsData.length;
  11234. for (i = 0; i < len; i += 1) {
  11235. this.prevViewData[i] = this.itemsData[i];
  11236. }
  11237. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11238. len = this.dynamicProperties.length;
  11239. for (i = 0; i < len; i += 1) {
  11240. this.dynamicProperties[i].getValue();
  11241. }
  11242. this.renderModifiers();
  11243. this.transformsManager.processSequences(this._isFirstFrame);
  11244. };
  11245. CVShapeElement.prototype.addTransformToStyleList = function (transform) {
  11246. var i;
  11247. var len = this.stylesList.length;
  11248. for (i = 0; i < len; i += 1) {
  11249. if (!this.stylesList[i].closed) {
  11250. this.stylesList[i].transforms.push(transform);
  11251. }
  11252. }
  11253. };
  11254. CVShapeElement.prototype.removeTransformFromStyleList = function () {
  11255. var i;
  11256. var len = this.stylesList.length;
  11257. for (i = 0; i < len; i += 1) {
  11258. if (!this.stylesList[i].closed) {
  11259. this.stylesList[i].transforms.pop();
  11260. }
  11261. }
  11262. };
  11263. CVShapeElement.prototype.closeStyles = function (styles) {
  11264. var i;
  11265. var len = styles.length;
  11266. for (i = 0; i < len; i += 1) {
  11267. styles[i].closed = true;
  11268. }
  11269. };
  11270. CVShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, shouldRender, transforms) {
  11271. var i;
  11272. var len = arr.length - 1;
  11273. var j;
  11274. var jLen;
  11275. var ownStyles = [];
  11276. var ownModifiers = [];
  11277. var processedPos;
  11278. var modifier;
  11279. var currentTransform;
  11280. var ownTransforms = [].concat(transforms);
  11281. for (i = len; i >= 0; i -= 1) {
  11282. processedPos = this.searchProcessedElement(arr[i]);
  11283. if (!processedPos) {
  11284. arr[i]._shouldRender = shouldRender;
  11285. } else {
  11286. itemsData[i] = prevViewData[processedPos - 1];
  11287. }
  11288. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs') {
  11289. if (!processedPos) {
  11290. itemsData[i] = this.createStyleElement(arr[i], ownTransforms);
  11291. } else {
  11292. itemsData[i].style.closed = false;
  11293. }
  11294. ownStyles.push(itemsData[i].style);
  11295. } else if (arr[i].ty === 'gr') {
  11296. if (!processedPos) {
  11297. itemsData[i] = this.createGroupElement(arr[i]);
  11298. } else {
  11299. jLen = itemsData[i].it.length;
  11300. for (j = 0; j < jLen; j += 1) {
  11301. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  11302. }
  11303. }
  11304. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, shouldRender, ownTransforms);
  11305. } else if (arr[i].ty === 'tr') {
  11306. if (!processedPos) {
  11307. currentTransform = this.createTransformElement(arr[i]);
  11308. itemsData[i] = currentTransform;
  11309. }
  11310. ownTransforms.push(itemsData[i]);
  11311. this.addTransformToStyleList(itemsData[i]);
  11312. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  11313. if (!processedPos) {
  11314. itemsData[i] = this.createShapeElement(arr[i]);
  11315. }
  11316. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  11317. if (!processedPos) {
  11318. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11319. modifier.init(this, arr[i]);
  11320. itemsData[i] = modifier;
  11321. this.shapeModifiers.push(modifier);
  11322. } else {
  11323. modifier = itemsData[i];
  11324. modifier.closed = false;
  11325. }
  11326. ownModifiers.push(modifier);
  11327. } else if (arr[i].ty === 'rp') {
  11328. if (!processedPos) {
  11329. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11330. itemsData[i] = modifier;
  11331. modifier.init(this, arr, i, itemsData);
  11332. this.shapeModifiers.push(modifier);
  11333. shouldRender = false;
  11334. } else {
  11335. modifier = itemsData[i];
  11336. modifier.closed = true;
  11337. }
  11338. ownModifiers.push(modifier);
  11339. }
  11340. this.addProcessedElement(arr[i], i + 1);
  11341. }
  11342. this.removeTransformFromStyleList();
  11343. this.closeStyles(ownStyles);
  11344. len = ownModifiers.length;
  11345. for (i = 0; i < len; i += 1) {
  11346. ownModifiers[i].closed = true;
  11347. }
  11348. };
  11349. CVShapeElement.prototype.renderInnerContent = function () {
  11350. this.transformHelper.opacity = 1;
  11351. this.transformHelper._opMdf = false;
  11352. this.renderModifiers();
  11353. this.transformsManager.processSequences(this._isFirstFrame);
  11354. this.renderShape(this.transformHelper, this.shapesData, this.itemsData, true);
  11355. };
  11356. CVShapeElement.prototype.renderShapeTransform = function (parentTransform, groupTransform) {
  11357. if (parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) {
  11358. groupTransform.opacity = parentTransform.opacity;
  11359. groupTransform.opacity *= groupTransform.op.v;
  11360. groupTransform._opMdf = true;
  11361. }
  11362. };
  11363. CVShapeElement.prototype.drawLayer = function () {
  11364. var i;
  11365. var len = this.stylesList.length;
  11366. var j;
  11367. var jLen;
  11368. var k;
  11369. var kLen;
  11370. var elems;
  11371. var nodes;
  11372. var renderer = this.globalData.renderer;
  11373. var ctx = this.globalData.canvasContext;
  11374. var type;
  11375. var currentStyle;
  11376. for (i = 0; i < len; i += 1) {
  11377. currentStyle = this.stylesList[i];
  11378. type = currentStyle.type;
  11379. // Skipping style when
  11380. // Stroke width equals 0
  11381. // style should not be rendered (extra unused repeaters)
  11382. // current opacity equals 0
  11383. // global opacity equals 0
  11384. if (!((type === 'st' || type === 'gs') && currentStyle.wi === 0 || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0)) {
  11385. renderer.save();
  11386. elems = currentStyle.elements;
  11387. if (type === 'st' || type === 'gs') {
  11388. renderer.ctxStrokeStyle(type === 'st' ? currentStyle.co : currentStyle.grd);
  11389. // ctx.strokeStyle = type === 'st' ? currentStyle.co : currentStyle.grd;
  11390. renderer.ctxLineWidth(currentStyle.wi);
  11391. // ctx.lineWidth = currentStyle.wi;
  11392. renderer.ctxLineCap(currentStyle.lc);
  11393. // ctx.lineCap = currentStyle.lc;
  11394. renderer.ctxLineJoin(currentStyle.lj);
  11395. // ctx.lineJoin = currentStyle.lj;
  11396. renderer.ctxMiterLimit(currentStyle.ml || 0);
  11397. // ctx.miterLimit = currentStyle.ml || 0;
  11398. } else {
  11399. renderer.ctxFillStyle(type === 'fl' ? currentStyle.co : currentStyle.grd);
  11400. // ctx.fillStyle = type === 'fl' ? currentStyle.co : currentStyle.grd;
  11401. }
  11402. renderer.ctxOpacity(currentStyle.coOp);
  11403. if (type !== 'st' && type !== 'gs') {
  11404. ctx.beginPath();
  11405. }
  11406. renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props);
  11407. jLen = elems.length;
  11408. for (j = 0; j < jLen; j += 1) {
  11409. if (type === 'st' || type === 'gs') {
  11410. ctx.beginPath();
  11411. if (currentStyle.da) {
  11412. ctx.setLineDash(currentStyle.da);
  11413. ctx.lineDashOffset = currentStyle["do"];
  11414. }
  11415. }
  11416. nodes = elems[j].trNodes;
  11417. kLen = nodes.length;
  11418. for (k = 0; k < kLen; k += 1) {
  11419. if (nodes[k].t === 'm') {
  11420. ctx.moveTo(nodes[k].p[0], nodes[k].p[1]);
  11421. } else if (nodes[k].t === 'c') {
  11422. 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]);
  11423. } else {
  11424. ctx.closePath();
  11425. }
  11426. }
  11427. if (type === 'st' || type === 'gs') {
  11428. // ctx.stroke();
  11429. renderer.ctxStroke();
  11430. if (currentStyle.da) {
  11431. ctx.setLineDash(this.dashResetter);
  11432. }
  11433. }
  11434. }
  11435. if (type !== 'st' && type !== 'gs') {
  11436. // ctx.fill(currentStyle.r);
  11437. this.globalData.renderer.ctxFill(currentStyle.r);
  11438. }
  11439. renderer.restore();
  11440. }
  11441. }
  11442. };
  11443. CVShapeElement.prototype.renderShape = function (parentTransform, items, data, isMain) {
  11444. var i;
  11445. var len = items.length - 1;
  11446. var groupTransform;
  11447. groupTransform = parentTransform;
  11448. for (i = len; i >= 0; i -= 1) {
  11449. if (items[i].ty === 'tr') {
  11450. groupTransform = data[i].transform;
  11451. this.renderShapeTransform(parentTransform, groupTransform);
  11452. } else if (items[i].ty === 'sh' || items[i].ty === 'el' || items[i].ty === 'rc' || items[i].ty === 'sr') {
  11453. this.renderPath(items[i], data[i]);
  11454. } else if (items[i].ty === 'fl') {
  11455. this.renderFill(items[i], data[i], groupTransform);
  11456. } else if (items[i].ty === 'st') {
  11457. this.renderStroke(items[i], data[i], groupTransform);
  11458. } else if (items[i].ty === 'gf' || items[i].ty === 'gs') {
  11459. this.renderGradientFill(items[i], data[i], groupTransform);
  11460. } else if (items[i].ty === 'gr') {
  11461. this.renderShape(groupTransform, items[i].it, data[i].it);
  11462. } else if (items[i].ty === 'tm') {
  11463. //
  11464. }
  11465. }
  11466. if (isMain) {
  11467. this.drawLayer();
  11468. }
  11469. };
  11470. CVShapeElement.prototype.renderStyledShape = function (styledShape, shape) {
  11471. if (this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) {
  11472. var shapeNodes = styledShape.trNodes;
  11473. var paths = shape.paths;
  11474. var i;
  11475. var len;
  11476. var j;
  11477. var jLen = paths._length;
  11478. shapeNodes.length = 0;
  11479. var groupTransformMat = styledShape.transforms.finalTransform;
  11480. for (j = 0; j < jLen; j += 1) {
  11481. var pathNodes = paths.shapes[j];
  11482. if (pathNodes && pathNodes.v) {
  11483. len = pathNodes._length;
  11484. for (i = 1; i < len; i += 1) {
  11485. if (i === 1) {
  11486. shapeNodes.push({
  11487. t: 'm',
  11488. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0)
  11489. });
  11490. }
  11491. shapeNodes.push({
  11492. t: 'c',
  11493. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i])
  11494. });
  11495. }
  11496. if (len === 1) {
  11497. shapeNodes.push({
  11498. t: 'm',
  11499. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0)
  11500. });
  11501. }
  11502. if (pathNodes.c && len) {
  11503. shapeNodes.push({
  11504. t: 'c',
  11505. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0])
  11506. });
  11507. shapeNodes.push({
  11508. t: 'z'
  11509. });
  11510. }
  11511. }
  11512. }
  11513. styledShape.trNodes = shapeNodes;
  11514. }
  11515. };
  11516. CVShapeElement.prototype.renderPath = function (pathData, itemData) {
  11517. if (pathData.hd !== true && pathData._shouldRender) {
  11518. var i;
  11519. var len = itemData.styledShapes.length;
  11520. for (i = 0; i < len; i += 1) {
  11521. this.renderStyledShape(itemData.styledShapes[i], itemData.sh);
  11522. }
  11523. }
  11524. };
  11525. CVShapeElement.prototype.renderFill = function (styleData, itemData, groupTransform) {
  11526. var styleElem = itemData.style;
  11527. if (itemData.c._mdf || this._isFirstFrame) {
  11528. styleElem.co = 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')';
  11529. }
  11530. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11531. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11532. }
  11533. };
  11534. CVShapeElement.prototype.renderGradientFill = function (styleData, itemData, groupTransform) {
  11535. var styleElem = itemData.style;
  11536. var grd;
  11537. if (!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf)) {
  11538. var ctx = this.globalData.canvasContext;
  11539. var pt1 = itemData.s.v;
  11540. var pt2 = itemData.e.v;
  11541. if (styleData.t === 1) {
  11542. grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]);
  11543. } else {
  11544. var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  11545. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  11546. var percent = itemData.h.v;
  11547. if (percent >= 1) {
  11548. percent = 0.99;
  11549. } else if (percent <= -1) {
  11550. percent = -0.99;
  11551. }
  11552. var dist = rad * percent;
  11553. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  11554. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  11555. grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad);
  11556. }
  11557. var i;
  11558. var len = styleData.g.p;
  11559. var cValues = itemData.g.c;
  11560. var opacity = 1;
  11561. for (i = 0; i < len; i += 1) {
  11562. if (itemData.g._hasOpacity && itemData.g._collapsable) {
  11563. opacity = itemData.g.o[i * 2 + 1];
  11564. }
  11565. grd.addColorStop(cValues[i * 4] / 100, 'rgba(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ',' + opacity + ')');
  11566. }
  11567. styleElem.grd = grd;
  11568. }
  11569. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11570. };
  11571. CVShapeElement.prototype.renderStroke = function (styleData, itemData, groupTransform) {
  11572. var styleElem = itemData.style;
  11573. var d = itemData.d;
  11574. if (d && (d._mdf || this._isFirstFrame)) {
  11575. styleElem.da = d.dashArray;
  11576. styleElem["do"] = d.dashoffset[0];
  11577. }
  11578. if (itemData.c._mdf || this._isFirstFrame) {
  11579. styleElem.co = 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')';
  11580. }
  11581. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11582. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11583. }
  11584. if (itemData.w._mdf || this._isFirstFrame) {
  11585. styleElem.wi = itemData.w.v;
  11586. }
  11587. };
  11588. CVShapeElement.prototype.destroy = function () {
  11589. this.shapesData = null;
  11590. this.globalData = null;
  11591. this.canvasContext = null;
  11592. this.stylesList.length = 0;
  11593. this.itemsData.length = 0;
  11594. };
  11595. function CVTextElement(data, globalData, comp) {
  11596. this.textSpans = [];
  11597. this.yOffset = 0;
  11598. this.fillColorAnim = false;
  11599. this.strokeColorAnim = false;
  11600. this.strokeWidthAnim = false;
  11601. this.stroke = false;
  11602. this.fill = false;
  11603. this.justifyOffset = 0;
  11604. this.currentRender = null;
  11605. this.renderType = 'canvas';
  11606. this.values = {
  11607. fill: 'rgba(0,0,0,0)',
  11608. stroke: 'rgba(0,0,0,0)',
  11609. sWidth: 0,
  11610. fValue: ''
  11611. };
  11612. this.initElement(data, globalData, comp);
  11613. }
  11614. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement, ITextElement], CVTextElement);
  11615. CVTextElement.prototype.tHelper = createTag('canvas').getContext('2d');
  11616. CVTextElement.prototype.buildNewText = function () {
  11617. var documentData = this.textProperty.currentData;
  11618. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  11619. var hasFill = false;
  11620. if (documentData.fc) {
  11621. hasFill = true;
  11622. this.values.fill = this.buildColor(documentData.fc);
  11623. } else {
  11624. this.values.fill = 'rgba(0,0,0,0)';
  11625. }
  11626. this.fill = hasFill;
  11627. var hasStroke = false;
  11628. if (documentData.sc) {
  11629. hasStroke = true;
  11630. this.values.stroke = this.buildColor(documentData.sc);
  11631. this.values.sWidth = documentData.sw;
  11632. }
  11633. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  11634. var i;
  11635. var len;
  11636. var letters = documentData.l;
  11637. var matrixHelper = this.mHelper;
  11638. this.stroke = hasStroke;
  11639. this.values.fValue = documentData.finalSize + 'px ' + this.globalData.fontManager.getFontByName(documentData.f).fFamily;
  11640. len = documentData.finalText.length;
  11641. // this.tHelper.font = this.values.fValue;
  11642. var charData;
  11643. var shapeData;
  11644. var k;
  11645. var kLen;
  11646. var shapes;
  11647. var j;
  11648. var jLen;
  11649. var pathNodes;
  11650. var commands;
  11651. var pathArr;
  11652. var singleShape = this.data.singleShape;
  11653. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  11654. var xPos = 0;
  11655. var yPos = 0;
  11656. var firstLine = true;
  11657. var cnt = 0;
  11658. for (i = 0; i < len; i += 1) {
  11659. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  11660. shapeData = charData && charData.data || {};
  11661. matrixHelper.reset();
  11662. if (singleShape && letters[i].n) {
  11663. xPos = -trackingOffset;
  11664. yPos += documentData.yOffset;
  11665. yPos += firstLine ? 1 : 0;
  11666. firstLine = false;
  11667. }
  11668. shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
  11669. jLen = shapes.length;
  11670. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  11671. if (singleShape) {
  11672. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  11673. }
  11674. commands = createSizedArray(jLen - 1);
  11675. var commandsCounter = 0;
  11676. for (j = 0; j < jLen; j += 1) {
  11677. if (shapes[j].ty === 'sh') {
  11678. kLen = shapes[j].ks.k.i.length;
  11679. pathNodes = shapes[j].ks.k;
  11680. pathArr = [];
  11681. for (k = 1; k < kLen; k += 1) {
  11682. if (k === 1) {
  11683. pathArr.push(matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
  11684. }
  11685. 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));
  11686. }
  11687. 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));
  11688. commands[commandsCounter] = pathArr;
  11689. commandsCounter += 1;
  11690. }
  11691. }
  11692. if (singleShape) {
  11693. xPos += letters[i].l;
  11694. xPos += trackingOffset;
  11695. }
  11696. if (this.textSpans[cnt]) {
  11697. this.textSpans[cnt].elem = commands;
  11698. } else {
  11699. this.textSpans[cnt] = {
  11700. elem: commands
  11701. };
  11702. }
  11703. cnt += 1;
  11704. }
  11705. };
  11706. CVTextElement.prototype.renderInnerContent = function () {
  11707. this.validateText();
  11708. var ctx = this.canvasContext;
  11709. ctx.font = this.values.fValue;
  11710. this.globalData.renderer.ctxLineCap('butt');
  11711. // ctx.lineCap = 'butt';
  11712. this.globalData.renderer.ctxLineJoin('miter');
  11713. // ctx.lineJoin = 'miter';
  11714. this.globalData.renderer.ctxMiterLimit(4);
  11715. // ctx.miterLimit = 4;
  11716. if (!this.data.singleShape) {
  11717. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  11718. }
  11719. var i;
  11720. var len;
  11721. var j;
  11722. var jLen;
  11723. var k;
  11724. var kLen;
  11725. var renderedLetters = this.textAnimator.renderedLetters;
  11726. var letters = this.textProperty.currentData.l;
  11727. len = letters.length;
  11728. var renderedLetter;
  11729. var lastFill = null;
  11730. var lastStroke = null;
  11731. var lastStrokeW = null;
  11732. var commands;
  11733. var pathArr;
  11734. var renderer = this.globalData.renderer;
  11735. for (i = 0; i < len; i += 1) {
  11736. if (!letters[i].n) {
  11737. renderedLetter = renderedLetters[i];
  11738. if (renderedLetter) {
  11739. renderer.save();
  11740. renderer.ctxTransform(renderedLetter.p);
  11741. renderer.ctxOpacity(renderedLetter.o);
  11742. }
  11743. if (this.fill) {
  11744. if (renderedLetter && renderedLetter.fc) {
  11745. if (lastFill !== renderedLetter.fc) {
  11746. renderer.ctxFillStyle(renderedLetter.fc);
  11747. lastFill = renderedLetter.fc;
  11748. // ctx.fillStyle = renderedLetter.fc;
  11749. }
  11750. } else if (lastFill !== this.values.fill) {
  11751. lastFill = this.values.fill;
  11752. renderer.ctxFillStyle(this.values.fill);
  11753. // ctx.fillStyle = this.values.fill;
  11754. }
  11755. commands = this.textSpans[i].elem;
  11756. jLen = commands.length;
  11757. this.globalData.canvasContext.beginPath();
  11758. for (j = 0; j < jLen; j += 1) {
  11759. pathArr = commands[j];
  11760. kLen = pathArr.length;
  11761. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11762. for (k = 2; k < kLen; k += 6) {
  11763. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11764. }
  11765. }
  11766. this.globalData.canvasContext.closePath();
  11767. renderer.ctxFill();
  11768. // this.globalData.canvasContext.fill();
  11769. /// ctx.fillText(this.textSpans[i].val,0,0);
  11770. }
  11771. if (this.stroke) {
  11772. if (renderedLetter && renderedLetter.sw) {
  11773. if (lastStrokeW !== renderedLetter.sw) {
  11774. lastStrokeW = renderedLetter.sw;
  11775. renderer.ctxLineWidth(renderedLetter.sw);
  11776. // ctx.lineWidth = renderedLetter.sw;
  11777. }
  11778. } else if (lastStrokeW !== this.values.sWidth) {
  11779. lastStrokeW = this.values.sWidth;
  11780. renderer.ctxLineWidth(this.values.sWidth);
  11781. // ctx.lineWidth = this.values.sWidth;
  11782. }
  11783. if (renderedLetter && renderedLetter.sc) {
  11784. if (lastStroke !== renderedLetter.sc) {
  11785. lastStroke = renderedLetter.sc;
  11786. renderer.ctxStrokeStyle(renderedLetter.sc);
  11787. // ctx.strokeStyle = renderedLetter.sc;
  11788. }
  11789. } else if (lastStroke !== this.values.stroke) {
  11790. lastStroke = this.values.stroke;
  11791. renderer.ctxStrokeStyle(this.values.stroke);
  11792. // ctx.strokeStyle = this.values.stroke;
  11793. }
  11794. commands = this.textSpans[i].elem;
  11795. jLen = commands.length;
  11796. this.globalData.canvasContext.beginPath();
  11797. for (j = 0; j < jLen; j += 1) {
  11798. pathArr = commands[j];
  11799. kLen = pathArr.length;
  11800. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11801. for (k = 2; k < kLen; k += 6) {
  11802. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11803. }
  11804. }
  11805. this.globalData.canvasContext.closePath();
  11806. renderer.ctxStroke();
  11807. // this.globalData.canvasContext.stroke();
  11808. /// ctx.strokeText(letters[i].val,0,0);
  11809. }
  11810. if (renderedLetter) {
  11811. this.globalData.renderer.restore();
  11812. }
  11813. }
  11814. }
  11815. };
  11816. function CVImageElement(data, globalData, comp) {
  11817. this.assetData = globalData.getAssetData(data.refId);
  11818. this.img = globalData.imageLoader.getAsset(this.assetData);
  11819. this.initElement(data, globalData, comp);
  11820. }
  11821. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVImageElement);
  11822. CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11823. CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11824. CVImageElement.prototype.createContent = function () {
  11825. if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) {
  11826. var canvas = createTag('canvas');
  11827. canvas.width = this.assetData.w;
  11828. canvas.height = this.assetData.h;
  11829. var ctx = canvas.getContext('2d');
  11830. var imgW = this.img.width;
  11831. var imgH = this.img.height;
  11832. var imgRel = imgW / imgH;
  11833. var canvasRel = this.assetData.w / this.assetData.h;
  11834. var widthCrop;
  11835. var heightCrop;
  11836. var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio;
  11837. if (imgRel > canvasRel && par === 'xMidYMid slice' || imgRel < canvasRel && par !== 'xMidYMid slice') {
  11838. heightCrop = imgH;
  11839. widthCrop = heightCrop * canvasRel;
  11840. } else {
  11841. widthCrop = imgW;
  11842. heightCrop = widthCrop / canvasRel;
  11843. }
  11844. ctx.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h);
  11845. this.img = canvas;
  11846. }
  11847. };
  11848. CVImageElement.prototype.renderInnerContent = function () {
  11849. this.canvasContext.drawImage(this.img, 0, 0);
  11850. };
  11851. CVImageElement.prototype.destroy = function () {
  11852. this.img = null;
  11853. };
  11854. function CVSolidElement(data, globalData, comp) {
  11855. this.initElement(data, globalData, comp);
  11856. }
  11857. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVSolidElement);
  11858. CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11859. CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11860. CVSolidElement.prototype.renderInnerContent = function () {
  11861. // var ctx = this.canvasContext;
  11862. this.globalData.renderer.ctxFillStyle(this.data.sc);
  11863. // ctx.fillStyle = this.data.sc;
  11864. this.globalData.renderer.ctxFillRect(0, 0, this.data.sw, this.data.sh);
  11865. // ctx.fillRect(0, 0, this.data.sw, this.data.sh);
  11866. //
  11867. };
  11868. function CanvasRendererBase() {}
  11869. extendPrototype([BaseRenderer], CanvasRendererBase);
  11870. CanvasRendererBase.prototype.createShape = function (data) {
  11871. return new CVShapeElement(data, this.globalData, this);
  11872. };
  11873. CanvasRendererBase.prototype.createText = function (data) {
  11874. return new CVTextElement(data, this.globalData, this);
  11875. };
  11876. CanvasRendererBase.prototype.createImage = function (data) {
  11877. return new CVImageElement(data, this.globalData, this);
  11878. };
  11879. CanvasRendererBase.prototype.createSolid = function (data) {
  11880. return new CVSolidElement(data, this.globalData, this);
  11881. };
  11882. CanvasRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  11883. CanvasRendererBase.prototype.ctxTransform = function (props) {
  11884. if (props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0) {
  11885. return;
  11886. }
  11887. this.canvasContext.transform(props[0], props[1], props[4], props[5], props[12], props[13]);
  11888. };
  11889. CanvasRendererBase.prototype.ctxOpacity = function (op) {
  11890. this.canvasContext.globalAlpha *= op < 0 ? 0 : op;
  11891. };
  11892. CanvasRendererBase.prototype.ctxFillStyle = function (value) {
  11893. this.canvasContext.fillStyle = value;
  11894. };
  11895. CanvasRendererBase.prototype.ctxStrokeStyle = function (value) {
  11896. this.canvasContext.strokeStyle = value;
  11897. };
  11898. CanvasRendererBase.prototype.ctxLineWidth = function (value) {
  11899. this.canvasContext.lineWidth = value;
  11900. };
  11901. CanvasRendererBase.prototype.ctxLineCap = function (value) {
  11902. this.canvasContext.lineCap = value;
  11903. };
  11904. CanvasRendererBase.prototype.ctxLineJoin = function (value) {
  11905. this.canvasContext.lineJoin = value;
  11906. };
  11907. CanvasRendererBase.prototype.ctxMiterLimit = function (value) {
  11908. this.canvasContext.miterLimit = value;
  11909. };
  11910. CanvasRendererBase.prototype.ctxFill = function (rule) {
  11911. this.canvasContext.fill(rule);
  11912. };
  11913. CanvasRendererBase.prototype.ctxFillRect = function (x, y, w, h) {
  11914. this.canvasContext.fillRect(x, y, w, h);
  11915. };
  11916. CanvasRendererBase.prototype.ctxStroke = function () {
  11917. this.canvasContext.stroke();
  11918. };
  11919. CanvasRendererBase.prototype.reset = function () {
  11920. if (!this.renderConfig.clearCanvas) {
  11921. this.canvasContext.restore();
  11922. return;
  11923. }
  11924. this.contextData.reset();
  11925. };
  11926. CanvasRendererBase.prototype.save = function () {
  11927. this.canvasContext.save();
  11928. };
  11929. CanvasRendererBase.prototype.restore = function (actionFlag) {
  11930. if (!this.renderConfig.clearCanvas) {
  11931. this.canvasContext.restore();
  11932. return;
  11933. }
  11934. if (actionFlag) {
  11935. this.globalData.blendMode = 'source-over';
  11936. }
  11937. this.contextData.restore(actionFlag);
  11938. };
  11939. CanvasRendererBase.prototype.configAnimation = function (animData) {
  11940. if (this.animationItem.wrapper) {
  11941. this.animationItem.container = createTag('canvas');
  11942. var containerStyle = this.animationItem.container.style;
  11943. containerStyle.width = '100%';
  11944. containerStyle.height = '100%';
  11945. var origin = '0px 0px 0px';
  11946. containerStyle.transformOrigin = origin;
  11947. containerStyle.mozTransformOrigin = origin;
  11948. containerStyle.webkitTransformOrigin = origin;
  11949. containerStyle['-webkit-transform'] = origin;
  11950. containerStyle.contentVisibility = this.renderConfig.contentVisibility;
  11951. this.animationItem.wrapper.appendChild(this.animationItem.container);
  11952. this.canvasContext = this.animationItem.container.getContext('2d');
  11953. if (this.renderConfig.className) {
  11954. this.animationItem.container.setAttribute('class', this.renderConfig.className);
  11955. }
  11956. if (this.renderConfig.id) {
  11957. this.animationItem.container.setAttribute('id', this.renderConfig.id);
  11958. }
  11959. } else {
  11960. this.canvasContext = this.renderConfig.context;
  11961. }
  11962. this.contextData.setContext(this.canvasContext);
  11963. this.data = animData;
  11964. this.layers = animData.layers;
  11965. this.transformCanvas = {
  11966. w: animData.w,
  11967. h: animData.h,
  11968. sx: 0,
  11969. sy: 0,
  11970. tx: 0,
  11971. ty: 0
  11972. };
  11973. this.setupGlobalData(animData, document.body);
  11974. this.globalData.canvasContext = this.canvasContext;
  11975. this.globalData.renderer = this;
  11976. this.globalData.isDashed = false;
  11977. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  11978. this.globalData.transformCanvas = this.transformCanvas;
  11979. this.elements = createSizedArray(animData.layers.length);
  11980. this.updateContainerSize();
  11981. };
  11982. CanvasRendererBase.prototype.updateContainerSize = function (width, height) {
  11983. this.reset();
  11984. var elementWidth;
  11985. var elementHeight;
  11986. if (width) {
  11987. elementWidth = width;
  11988. elementHeight = height;
  11989. this.canvasContext.canvas.width = elementWidth;
  11990. this.canvasContext.canvas.height = elementHeight;
  11991. } else {
  11992. if (this.animationItem.wrapper && this.animationItem.container) {
  11993. elementWidth = this.animationItem.wrapper.offsetWidth;
  11994. elementHeight = this.animationItem.wrapper.offsetHeight;
  11995. } else {
  11996. elementWidth = this.canvasContext.canvas.width;
  11997. elementHeight = this.canvasContext.canvas.height;
  11998. }
  11999. this.canvasContext.canvas.width = elementWidth * this.renderConfig.dpr;
  12000. this.canvasContext.canvas.height = elementHeight * this.renderConfig.dpr;
  12001. }
  12002. var elementRel;
  12003. var animationRel;
  12004. if (this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1) {
  12005. var par = this.renderConfig.preserveAspectRatio.split(' ');
  12006. var fillType = par[1] || 'meet';
  12007. var pos = par[0] || 'xMidYMid';
  12008. var xPos = pos.substr(0, 4);
  12009. var yPos = pos.substr(4);
  12010. elementRel = elementWidth / elementHeight;
  12011. animationRel = this.transformCanvas.w / this.transformCanvas.h;
  12012. if (animationRel > elementRel && fillType === 'meet' || animationRel < elementRel && fillType === 'slice') {
  12013. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12014. this.transformCanvas.sy = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12015. } else {
  12016. this.transformCanvas.sx = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12017. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12018. }
  12019. if (xPos === 'xMid' && (animationRel < elementRel && fillType === 'meet' || animationRel > elementRel && fillType === 'slice')) {
  12020. this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) / 2 * this.renderConfig.dpr;
  12021. } else if (xPos === 'xMax' && (animationRel < elementRel && fillType === 'meet' || animationRel > elementRel && fillType === 'slice')) {
  12022. this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) * this.renderConfig.dpr;
  12023. } else {
  12024. this.transformCanvas.tx = 0;
  12025. }
  12026. if (yPos === 'YMid' && (animationRel > elementRel && fillType === 'meet' || animationRel < elementRel && fillType === 'slice')) {
  12027. this.transformCanvas.ty = (elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) / 2 * this.renderConfig.dpr;
  12028. } else if (yPos === 'YMax' && (animationRel > elementRel && fillType === 'meet' || animationRel < elementRel && fillType === 'slice')) {
  12029. this.transformCanvas.ty = (elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) * this.renderConfig.dpr;
  12030. } else {
  12031. this.transformCanvas.ty = 0;
  12032. }
  12033. } else if (this.renderConfig.preserveAspectRatio === 'none') {
  12034. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12035. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12036. this.transformCanvas.tx = 0;
  12037. this.transformCanvas.ty = 0;
  12038. } else {
  12039. this.transformCanvas.sx = this.renderConfig.dpr;
  12040. this.transformCanvas.sy = this.renderConfig.dpr;
  12041. this.transformCanvas.tx = 0;
  12042. this.transformCanvas.ty = 0;
  12043. }
  12044. 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];
  12045. /* var i, len = this.elements.length;
  12046. for(i=0;i<len;i+=1){
  12047. if(this.elements[i] && this.elements[i].data.ty === 0){
  12048. this.elements[i].resize(this.globalData.transformCanvas);
  12049. }
  12050. } */
  12051. this.ctxTransform(this.transformCanvas.props);
  12052. this.canvasContext.beginPath();
  12053. this.canvasContext.rect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12054. this.canvasContext.closePath();
  12055. this.canvasContext.clip();
  12056. this.renderFrame(this.renderedFrame, true);
  12057. };
  12058. CanvasRendererBase.prototype.destroy = function () {
  12059. if (this.renderConfig.clearCanvas && this.animationItem.wrapper) {
  12060. this.animationItem.wrapper.innerText = '';
  12061. }
  12062. var i;
  12063. var len = this.layers ? this.layers.length : 0;
  12064. for (i = len - 1; i >= 0; i -= 1) {
  12065. if (this.elements[i] && this.elements[i].destroy) {
  12066. this.elements[i].destroy();
  12067. }
  12068. }
  12069. this.elements.length = 0;
  12070. this.globalData.canvasContext = null;
  12071. this.animationItem.container = null;
  12072. this.destroyed = true;
  12073. };
  12074. CanvasRendererBase.prototype.renderFrame = function (num, forceRender) {
  12075. if (this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender || this.destroyed || num === -1) {
  12076. return;
  12077. }
  12078. this.renderedFrame = num;
  12079. this.globalData.frameNum = num - this.animationItem._isFirstFrame;
  12080. this.globalData.frameId += 1;
  12081. this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender;
  12082. this.globalData.projectInterface.currentFrame = num;
  12083. // console.log('--------');
  12084. // console.log('NEW: ',num);
  12085. var i;
  12086. var len = this.layers.length;
  12087. if (!this.completeLayers) {
  12088. this.checkLayers(num);
  12089. }
  12090. for (i = len - 1; i >= 0; i -= 1) {
  12091. if (this.completeLayers || this.elements[i]) {
  12092. this.elements[i].prepareFrame(num - this.layers[i].st);
  12093. }
  12094. }
  12095. if (this.globalData._mdf) {
  12096. if (this.renderConfig.clearCanvas === true) {
  12097. this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12098. } else {
  12099. this.save();
  12100. }
  12101. for (i = len - 1; i >= 0; i -= 1) {
  12102. if (this.completeLayers || this.elements[i]) {
  12103. this.elements[i].renderFrame();
  12104. }
  12105. }
  12106. if (this.renderConfig.clearCanvas !== true) {
  12107. this.restore();
  12108. }
  12109. }
  12110. };
  12111. CanvasRendererBase.prototype.buildItem = function (pos) {
  12112. var elements = this.elements;
  12113. if (elements[pos] || this.layers[pos].ty === 99) {
  12114. return;
  12115. }
  12116. var element = this.createItem(this.layers[pos], this, this.globalData);
  12117. elements[pos] = element;
  12118. element.initExpressions();
  12119. /* if(this.layers[pos].ty === 0){
  12120. element.resize(this.globalData.transformCanvas);
  12121. } */
  12122. };
  12123. CanvasRendererBase.prototype.checkPendingElements = function () {
  12124. while (this.pendingElements.length) {
  12125. var element = this.pendingElements.pop();
  12126. element.checkParenting();
  12127. }
  12128. };
  12129. CanvasRendererBase.prototype.hide = function () {
  12130. this.animationItem.container.style.display = 'none';
  12131. };
  12132. CanvasRendererBase.prototype.show = function () {
  12133. this.animationItem.container.style.display = 'block';
  12134. };
  12135. function CanvasContext() {
  12136. this.opacity = -1;
  12137. this.transform = createTypedArray('float32', 16);
  12138. this.fillStyle = '';
  12139. this.strokeStyle = '';
  12140. this.lineWidth = '';
  12141. this.lineCap = '';
  12142. this.lineJoin = '';
  12143. this.miterLimit = '';
  12144. this.id = Math.random();
  12145. }
  12146. function CVContextData() {
  12147. this.stack = [];
  12148. this.cArrPos = 0;
  12149. this.cTr = new Matrix();
  12150. var i;
  12151. var len = 15;
  12152. for (i = 0; i < len; i += 1) {
  12153. var canvasContext = new CanvasContext();
  12154. this.stack[i] = canvasContext;
  12155. }
  12156. this._length = len;
  12157. this.nativeContext = null;
  12158. this.transformMat = new Matrix();
  12159. this.currentOpacity = 1;
  12160. //
  12161. this.currentFillStyle = '';
  12162. this.appliedFillStyle = '';
  12163. //
  12164. this.currentStrokeStyle = '';
  12165. this.appliedStrokeStyle = '';
  12166. //
  12167. this.currentLineWidth = '';
  12168. this.appliedLineWidth = '';
  12169. //
  12170. this.currentLineCap = '';
  12171. this.appliedLineCap = '';
  12172. //
  12173. this.currentLineJoin = '';
  12174. this.appliedLineJoin = '';
  12175. //
  12176. this.appliedMiterLimit = '';
  12177. this.currentMiterLimit = '';
  12178. }
  12179. CVContextData.prototype.duplicate = function () {
  12180. var newLength = this._length * 2;
  12181. var i = 0;
  12182. for (i = this._length; i < newLength; i += 1) {
  12183. this.stack[i] = new CanvasContext();
  12184. }
  12185. this._length = newLength;
  12186. };
  12187. CVContextData.prototype.reset = function () {
  12188. this.cArrPos = 0;
  12189. this.cTr.reset();
  12190. this.stack[this.cArrPos].opacity = 1;
  12191. };
  12192. CVContextData.prototype.restore = function (forceRestore) {
  12193. this.cArrPos -= 1;
  12194. var currentContext = this.stack[this.cArrPos];
  12195. var transform = currentContext.transform;
  12196. var i;
  12197. var arr = this.cTr.props;
  12198. for (i = 0; i < 16; i += 1) {
  12199. arr[i] = transform[i];
  12200. }
  12201. if (forceRestore) {
  12202. this.nativeContext.restore();
  12203. var prevStack = this.stack[this.cArrPos + 1];
  12204. this.appliedFillStyle = prevStack.fillStyle;
  12205. this.appliedStrokeStyle = prevStack.strokeStyle;
  12206. this.appliedLineWidth = prevStack.lineWidth;
  12207. this.appliedLineCap = prevStack.lineCap;
  12208. this.appliedLineJoin = prevStack.lineJoin;
  12209. this.appliedMiterLimit = prevStack.miterLimit;
  12210. }
  12211. this.nativeContext.setTransform(transform[0], transform[1], transform[4], transform[5], transform[12], transform[13]);
  12212. if (forceRestore || currentContext.opacity !== -1 && this.currentOpacity !== currentContext.opacity) {
  12213. this.nativeContext.globalAlpha = currentContext.opacity;
  12214. this.currentOpacity = currentContext.opacity;
  12215. }
  12216. this.currentFillStyle = currentContext.fillStyle;
  12217. this.currentStrokeStyle = currentContext.strokeStyle;
  12218. this.currentLineWidth = currentContext.lineWidth;
  12219. this.currentLineCap = currentContext.lineCap;
  12220. this.currentLineJoin = currentContext.lineJoin;
  12221. this.currentMiterLimit = currentContext.miterLimit;
  12222. };
  12223. CVContextData.prototype.save = function (saveOnNativeFlag) {
  12224. if (saveOnNativeFlag) {
  12225. this.nativeContext.save();
  12226. }
  12227. var props = this.cTr.props;
  12228. if (this._length <= this.cArrPos) {
  12229. this.duplicate();
  12230. }
  12231. var currentStack = this.stack[this.cArrPos];
  12232. var i;
  12233. for (i = 0; i < 16; i += 1) {
  12234. currentStack.transform[i] = props[i];
  12235. }
  12236. this.cArrPos += 1;
  12237. var newStack = this.stack[this.cArrPos];
  12238. newStack.opacity = currentStack.opacity;
  12239. newStack.fillStyle = currentStack.fillStyle;
  12240. newStack.strokeStyle = currentStack.strokeStyle;
  12241. newStack.lineWidth = currentStack.lineWidth;
  12242. newStack.lineCap = currentStack.lineCap;
  12243. newStack.lineJoin = currentStack.lineJoin;
  12244. newStack.miterLimit = currentStack.miterLimit;
  12245. };
  12246. CVContextData.prototype.setOpacity = function (value) {
  12247. this.stack[this.cArrPos].opacity = value;
  12248. };
  12249. CVContextData.prototype.setContext = function (value) {
  12250. this.nativeContext = value;
  12251. };
  12252. CVContextData.prototype.fillStyle = function (value) {
  12253. if (this.stack[this.cArrPos].fillStyle !== value) {
  12254. this.currentFillStyle = value;
  12255. this.stack[this.cArrPos].fillStyle = value;
  12256. }
  12257. };
  12258. CVContextData.prototype.strokeStyle = function (value) {
  12259. if (this.stack[this.cArrPos].strokeStyle !== value) {
  12260. this.currentStrokeStyle = value;
  12261. this.stack[this.cArrPos].strokeStyle = value;
  12262. }
  12263. };
  12264. CVContextData.prototype.lineWidth = function (value) {
  12265. if (this.stack[this.cArrPos].lineWidth !== value) {
  12266. this.currentLineWidth = value;
  12267. this.stack[this.cArrPos].lineWidth = value;
  12268. }
  12269. };
  12270. CVContextData.prototype.lineCap = function (value) {
  12271. if (this.stack[this.cArrPos].lineCap !== value) {
  12272. this.currentLineCap = value;
  12273. this.stack[this.cArrPos].lineCap = value;
  12274. }
  12275. };
  12276. CVContextData.prototype.lineJoin = function (value) {
  12277. if (this.stack[this.cArrPos].lineJoin !== value) {
  12278. this.currentLineJoin = value;
  12279. this.stack[this.cArrPos].lineJoin = value;
  12280. }
  12281. };
  12282. CVContextData.prototype.miterLimit = function (value) {
  12283. if (this.stack[this.cArrPos].miterLimit !== value) {
  12284. this.currentMiterLimit = value;
  12285. this.stack[this.cArrPos].miterLimit = value;
  12286. }
  12287. };
  12288. CVContextData.prototype.transform = function (props) {
  12289. this.transformMat.cloneFromProps(props);
  12290. // Taking the last transform value from the stored stack of transforms
  12291. var currentTransform = this.cTr;
  12292. // Applying the last transform value after the new transform to respect the order of transformations
  12293. this.transformMat.multiply(currentTransform);
  12294. // Storing the new transformed value in the stored transform
  12295. currentTransform.cloneFromProps(this.transformMat.props);
  12296. var trProps = currentTransform.props;
  12297. // Applying the new transform to the canvas
  12298. this.nativeContext.setTransform(trProps[0], trProps[1], trProps[4], trProps[5], trProps[12], trProps[13]);
  12299. };
  12300. CVContextData.prototype.opacity = function (op) {
  12301. var currentOpacity = this.stack[this.cArrPos].opacity;
  12302. currentOpacity *= op < 0 ? 0 : op;
  12303. if (this.stack[this.cArrPos].opacity !== currentOpacity) {
  12304. if (this.currentOpacity !== op) {
  12305. this.nativeContext.globalAlpha = op;
  12306. this.currentOpacity = op;
  12307. }
  12308. this.stack[this.cArrPos].opacity = currentOpacity;
  12309. }
  12310. };
  12311. CVContextData.prototype.fill = function (rule) {
  12312. if (this.appliedFillStyle !== this.currentFillStyle) {
  12313. this.appliedFillStyle = this.currentFillStyle;
  12314. this.nativeContext.fillStyle = this.appliedFillStyle;
  12315. }
  12316. this.nativeContext.fill(rule);
  12317. };
  12318. CVContextData.prototype.fillRect = function (x, y, w, h) {
  12319. if (this.appliedFillStyle !== this.currentFillStyle) {
  12320. this.appliedFillStyle = this.currentFillStyle;
  12321. this.nativeContext.fillStyle = this.appliedFillStyle;
  12322. }
  12323. this.nativeContext.fillRect(x, y, w, h);
  12324. };
  12325. CVContextData.prototype.stroke = function () {
  12326. if (this.appliedStrokeStyle !== this.currentStrokeStyle) {
  12327. this.appliedStrokeStyle = this.currentStrokeStyle;
  12328. this.nativeContext.strokeStyle = this.appliedStrokeStyle;
  12329. }
  12330. if (this.appliedLineWidth !== this.currentLineWidth) {
  12331. this.appliedLineWidth = this.currentLineWidth;
  12332. this.nativeContext.lineWidth = this.appliedLineWidth;
  12333. }
  12334. if (this.appliedLineCap !== this.currentLineCap) {
  12335. this.appliedLineCap = this.currentLineCap;
  12336. this.nativeContext.lineCap = this.appliedLineCap;
  12337. }
  12338. if (this.appliedLineJoin !== this.currentLineJoin) {
  12339. this.appliedLineJoin = this.currentLineJoin;
  12340. this.nativeContext.lineJoin = this.appliedLineJoin;
  12341. }
  12342. if (this.appliedMiterLimit !== this.currentMiterLimit) {
  12343. this.appliedMiterLimit = this.currentMiterLimit;
  12344. this.nativeContext.miterLimit = this.appliedMiterLimit;
  12345. }
  12346. this.nativeContext.stroke();
  12347. };
  12348. function CVCompElement(data, globalData, comp) {
  12349. this.completeLayers = false;
  12350. this.layers = data.layers;
  12351. this.pendingElements = [];
  12352. this.elements = createSizedArray(this.layers.length);
  12353. this.initElement(data, globalData, comp);
  12354. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : {
  12355. _placeholder: true
  12356. };
  12357. }
  12358. extendPrototype([CanvasRendererBase, ICompElement, CVBaseElement], CVCompElement);
  12359. CVCompElement.prototype.renderInnerContent = function () {
  12360. var ctx = this.canvasContext;
  12361. ctx.beginPath();
  12362. ctx.moveTo(0, 0);
  12363. ctx.lineTo(this.data.w, 0);
  12364. ctx.lineTo(this.data.w, this.data.h);
  12365. ctx.lineTo(0, this.data.h);
  12366. ctx.lineTo(0, 0);
  12367. ctx.clip();
  12368. var i;
  12369. var len = this.layers.length;
  12370. for (i = len - 1; i >= 0; i -= 1) {
  12371. if (this.completeLayers || this.elements[i]) {
  12372. this.elements[i].renderFrame();
  12373. }
  12374. }
  12375. };
  12376. CVCompElement.prototype.destroy = function () {
  12377. var i;
  12378. var len = this.layers.length;
  12379. for (i = len - 1; i >= 0; i -= 1) {
  12380. if (this.elements[i]) {
  12381. this.elements[i].destroy();
  12382. }
  12383. }
  12384. this.layers = null;
  12385. this.elements = null;
  12386. };
  12387. CVCompElement.prototype.createComp = function (data) {
  12388. return new CVCompElement(data, this.globalData, this);
  12389. };
  12390. function CanvasRenderer(animationItem, config) {
  12391. this.animationItem = animationItem;
  12392. this.renderConfig = {
  12393. clearCanvas: config && config.clearCanvas !== undefined ? config.clearCanvas : true,
  12394. context: config && config.context || null,
  12395. progressiveLoad: config && config.progressiveLoad || false,
  12396. preserveAspectRatio: config && config.preserveAspectRatio || 'xMidYMid meet',
  12397. imagePreserveAspectRatio: config && config.imagePreserveAspectRatio || 'xMidYMid slice',
  12398. contentVisibility: config && config.contentVisibility || 'visible',
  12399. className: config && config.className || '',
  12400. id: config && config.id || '',
  12401. runExpressions: !config || config.runExpressions === undefined || config.runExpressions
  12402. };
  12403. this.renderConfig.dpr = config && config.dpr || 1;
  12404. if (this.animationItem.wrapper) {
  12405. this.renderConfig.dpr = config && config.dpr || window.devicePixelRatio || 1;
  12406. }
  12407. this.renderedFrame = -1;
  12408. this.globalData = {
  12409. frameNum: -1,
  12410. _mdf: false,
  12411. renderConfig: this.renderConfig,
  12412. currentGlobalAlpha: -1
  12413. };
  12414. this.contextData = new CVContextData();
  12415. this.elements = [];
  12416. this.pendingElements = [];
  12417. this.transformMat = new Matrix();
  12418. this.completeLayers = false;
  12419. this.rendererType = 'canvas';
  12420. if (this.renderConfig.clearCanvas) {
  12421. this.ctxTransform = this.contextData.transform.bind(this.contextData);
  12422. this.ctxOpacity = this.contextData.opacity.bind(this.contextData);
  12423. this.ctxFillStyle = this.contextData.fillStyle.bind(this.contextData);
  12424. this.ctxStrokeStyle = this.contextData.strokeStyle.bind(this.contextData);
  12425. this.ctxLineWidth = this.contextData.lineWidth.bind(this.contextData);
  12426. this.ctxLineCap = this.contextData.lineCap.bind(this.contextData);
  12427. this.ctxLineJoin = this.contextData.lineJoin.bind(this.contextData);
  12428. this.ctxMiterLimit = this.contextData.miterLimit.bind(this.contextData);
  12429. this.ctxFill = this.contextData.fill.bind(this.contextData);
  12430. this.ctxFillRect = this.contextData.fillRect.bind(this.contextData);
  12431. this.ctxStroke = this.contextData.stroke.bind(this.contextData);
  12432. this.save = this.contextData.save.bind(this.contextData);
  12433. }
  12434. }
  12435. extendPrototype([CanvasRendererBase], CanvasRenderer);
  12436. CanvasRenderer.prototype.createComp = function (data) {
  12437. return new CVCompElement(data, this.globalData, this);
  12438. };
  12439. // Registering renderers
  12440. registerRenderer('canvas', CanvasRenderer);
  12441. // Registering shape modifiers
  12442. ShapeModifiers.registerModifier('tm', TrimModifier);
  12443. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  12444. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  12445. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  12446. ShapeModifiers.registerModifier('zz', ZigZagModifier);
  12447. ShapeModifiers.registerModifier('op', OffsetPathModifier);
  12448. return lottie;
  12449. }));