lottie_light_canvas.min.js 420 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445
  1. const svgNS = 'http://www.w3.org/2000/svg';
  2. let locationHref = '';
  3. let _useWebWorker = false;
  4. const initialDefaultFrame = -999999;
  5. const setWebWorker = (flag) => { _useWebWorker = !!flag; };
  6. const getWebWorker = () => _useWebWorker;
  7. const setLocationHref = (value) => { locationHref = value; };
  8. const getLocationHref = () => locationHref;
  9. function createTag(type) {
  10. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  11. return document.createElement(type);
  12. }
  13. function extendPrototype(sources, destination) {
  14. var i;
  15. var len = sources.length;
  16. var sourcePrototype;
  17. for (i = 0; i < len; i += 1) {
  18. sourcePrototype = sources[i].prototype;
  19. for (var attr in sourcePrototype) {
  20. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  21. }
  22. }
  23. }
  24. function getDescriptor(object, prop) {
  25. return Object.getOwnPropertyDescriptor(object, prop);
  26. }
  27. function createProxyFunction(prototype) {
  28. function ProxyFunction() {}
  29. ProxyFunction.prototype = prototype;
  30. return ProxyFunction;
  31. }
  32. // import Howl from '../../3rd_party/howler';
  33. const audioControllerFactory = (function () {
  34. function AudioController(audioFactory) {
  35. this.audios = [];
  36. this.audioFactory = audioFactory;
  37. this._volume = 1;
  38. this._isMuted = false;
  39. }
  40. AudioController.prototype = {
  41. addAudio: function (audio) {
  42. this.audios.push(audio);
  43. },
  44. pause: function () {
  45. var i;
  46. var len = this.audios.length;
  47. for (i = 0; i < len; i += 1) {
  48. this.audios[i].pause();
  49. }
  50. },
  51. resume: function () {
  52. var i;
  53. var len = this.audios.length;
  54. for (i = 0; i < len; i += 1) {
  55. this.audios[i].resume();
  56. }
  57. },
  58. setRate: function (rateValue) {
  59. var i;
  60. var len = this.audios.length;
  61. for (i = 0; i < len; i += 1) {
  62. this.audios[i].setRate(rateValue);
  63. }
  64. },
  65. createAudio: function (assetPath) {
  66. if (this.audioFactory) {
  67. return this.audioFactory(assetPath);
  68. } if (window.Howl) {
  69. return new window.Howl({
  70. src: [assetPath],
  71. });
  72. }
  73. return {
  74. isPlaying: false,
  75. play: function () { this.isPlaying = true; },
  76. seek: function () { this.isPlaying = false; },
  77. playing: function () {},
  78. rate: function () {},
  79. setVolume: function () {},
  80. };
  81. },
  82. setAudioFactory: function (audioFactory) {
  83. this.audioFactory = audioFactory;
  84. },
  85. setVolume: function (value) {
  86. this._volume = value;
  87. this._updateVolume();
  88. },
  89. mute: function () {
  90. this._isMuted = true;
  91. this._updateVolume();
  92. },
  93. unmute: function () {
  94. this._isMuted = false;
  95. this._updateVolume();
  96. },
  97. getVolume: function () {
  98. return this._volume;
  99. },
  100. _updateVolume: function () {
  101. var i;
  102. var len = this.audios.length;
  103. for (i = 0; i < len; i += 1) {
  104. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  105. }
  106. },
  107. };
  108. return function () {
  109. return new AudioController();
  110. };
  111. }());
  112. const createTypedArray = (function () {
  113. function createRegularArray(type, len) {
  114. var i = 0;
  115. var arr = [];
  116. var value;
  117. switch (type) {
  118. case 'int16':
  119. case 'uint8c':
  120. value = 1;
  121. break;
  122. default:
  123. value = 1.1;
  124. break;
  125. }
  126. for (i = 0; i < len; i += 1) {
  127. arr.push(value);
  128. }
  129. return arr;
  130. }
  131. function createTypedArrayFactory(type, len) {
  132. if (type === 'float32') {
  133. return new Float32Array(len);
  134. } if (type === 'int16') {
  135. return new Int16Array(len);
  136. } if (type === 'uint8c') {
  137. return new Uint8ClampedArray(len);
  138. }
  139. return createRegularArray(type, len);
  140. }
  141. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  142. return createTypedArrayFactory;
  143. }
  144. return createRegularArray;
  145. }());
  146. function createSizedArray(len) {
  147. return Array.apply(null, { length: len });
  148. }
  149. let subframeEnabled = true;
  150. let expressionsPlugin = null;
  151. let expressionsInterfaces = null;
  152. let idPrefix$1 = '';
  153. const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  154. let _shouldRoundValues = false;
  155. const bmPow = Math.pow;
  156. const bmSqrt = Math.sqrt;
  157. const bmFloor = Math.floor;
  158. const bmMax = Math.max;
  159. const bmMin = Math.min;
  160. const BMMath = {};
  161. (function () {
  162. var propertyNames = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'atan2', 'ceil', 'cbrt', 'expm1', 'clz32', 'cos', 'cosh', 'exp', 'floor', 'fround', 'hypot', 'imul', 'log', 'log1p', 'log2', 'log10', 'max', 'min', 'pow', 'random', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', 'E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2'];
  163. var i;
  164. var len = propertyNames.length;
  165. for (i = 0; i < len; i += 1) {
  166. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  167. }
  168. }());
  169. function ProjectInterface$1() { return {}; }
  170. BMMath.random = Math.random;
  171. BMMath.abs = function (val) {
  172. var tOfVal = typeof val;
  173. if (tOfVal === 'object' && val.length) {
  174. var absArr = createSizedArray(val.length);
  175. var i;
  176. var len = val.length;
  177. for (i = 0; i < len; i += 1) {
  178. absArr[i] = Math.abs(val[i]);
  179. }
  180. return absArr;
  181. }
  182. return Math.abs(val);
  183. };
  184. let defaultCurveSegments = 150;
  185. const degToRads = Math.PI / 180;
  186. const roundCorner = 0.5519;
  187. function roundValues(flag) {
  188. _shouldRoundValues = !!flag;
  189. }
  190. function bmRnd(value) {
  191. if (_shouldRoundValues) {
  192. return Math.round(value);
  193. }
  194. return value;
  195. }
  196. function styleDiv(element) {
  197. element.style.position = 'absolute';
  198. element.style.top = 0;
  199. element.style.left = 0;
  200. element.style.display = 'block';
  201. element.style.transformOrigin = '0 0';
  202. element.style.webkitTransformOrigin = '0 0';
  203. element.style.backfaceVisibility = 'visible';
  204. element.style.webkitBackfaceVisibility = 'visible';
  205. element.style.transformStyle = 'preserve-3d';
  206. element.style.webkitTransformStyle = 'preserve-3d';
  207. element.style.mozTransformStyle = 'preserve-3d';
  208. }
  209. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  210. this.type = type;
  211. this.currentTime = currentTime;
  212. this.totalTime = totalTime;
  213. this.direction = frameMultiplier < 0 ? -1 : 1;
  214. }
  215. function BMCompleteEvent(type, frameMultiplier) {
  216. this.type = type;
  217. this.direction = frameMultiplier < 0 ? -1 : 1;
  218. }
  219. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  220. this.type = type;
  221. this.currentLoop = currentLoop;
  222. this.totalLoops = totalLoops;
  223. this.direction = frameMultiplier < 0 ? -1 : 1;
  224. }
  225. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  226. this.type = type;
  227. this.firstFrame = firstFrame;
  228. this.totalFrames = totalFrames;
  229. }
  230. function BMDestroyEvent(type, target) {
  231. this.type = type;
  232. this.target = target;
  233. }
  234. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  235. this.type = 'renderFrameError';
  236. this.nativeError = nativeError;
  237. this.currentTime = currentTime;
  238. }
  239. function BMConfigErrorEvent(nativeError) {
  240. this.type = 'configError';
  241. this.nativeError = nativeError;
  242. }
  243. function BMAnimationConfigErrorEvent(type, nativeError) {
  244. this.type = type;
  245. this.nativeError = nativeError;
  246. }
  247. const createElementID = (function () {
  248. var _count = 0;
  249. return function createID() {
  250. _count += 1;
  251. return idPrefix$1 + '__lottie_element_' + _count;
  252. };
  253. }());
  254. function HSVtoRGB(h, s, v) {
  255. var r;
  256. var g;
  257. var b;
  258. var i;
  259. var f;
  260. var p;
  261. var q;
  262. var t;
  263. i = Math.floor(h * 6);
  264. f = h * 6 - i;
  265. p = v * (1 - s);
  266. q = v * (1 - f * s);
  267. t = v * (1 - (1 - f) * s);
  268. switch (i % 6) {
  269. case 0: r = v; g = t; b = p; break;
  270. case 1: r = q; g = v; b = p; break;
  271. case 2: r = p; g = v; b = t; break;
  272. case 3: r = p; g = q; b = v; break;
  273. case 4: r = t; g = p; b = v; break;
  274. case 5: r = v; g = p; b = q; break;
  275. default: break;
  276. }
  277. return [r,
  278. g,
  279. b];
  280. }
  281. function RGBtoHSV(r, g, b) {
  282. var max = Math.max(r, g, b);
  283. var min = Math.min(r, g, b);
  284. var d = max - min;
  285. var h;
  286. var s = (max === 0 ? 0 : d / max);
  287. var v = max / 255;
  288. switch (max) {
  289. case min: h = 0; break;
  290. case r: h = (g - b) + d * (g < b ? 6 : 0); h /= 6 * d; break;
  291. case g: h = (b - r) + d * 2; h /= 6 * d; break;
  292. case b: h = (r - g) + d * 4; h /= 6 * d; break;
  293. default: break;
  294. }
  295. return [
  296. h,
  297. s,
  298. v,
  299. ];
  300. }
  301. function addSaturationToRGB(color, offset) {
  302. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  303. hsv[1] += offset;
  304. if (hsv[1] > 1) {
  305. hsv[1] = 1;
  306. } else if (hsv[1] <= 0) {
  307. hsv[1] = 0;
  308. }
  309. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  310. }
  311. function addBrightnessToRGB(color, offset) {
  312. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  313. hsv[2] += offset;
  314. if (hsv[2] > 1) {
  315. hsv[2] = 1;
  316. } else if (hsv[2] < 0) {
  317. hsv[2] = 0;
  318. }
  319. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  320. }
  321. function addHueToRGB(color, offset) {
  322. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  323. hsv[0] += offset / 360;
  324. if (hsv[0] > 1) {
  325. hsv[0] -= 1;
  326. } else if (hsv[0] < 0) {
  327. hsv[0] += 1;
  328. }
  329. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  330. }
  331. const rgbToHex = (function () {
  332. var colorMap = [];
  333. var i;
  334. var hex;
  335. for (i = 0; i < 256; i += 1) {
  336. hex = i.toString(16);
  337. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  338. }
  339. return function (r, g, b) {
  340. if (r < 0) {
  341. r = 0;
  342. }
  343. if (g < 0) {
  344. g = 0;
  345. }
  346. if (b < 0) {
  347. b = 0;
  348. }
  349. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  350. };
  351. }());
  352. const setSubframeEnabled = (flag) => { subframeEnabled = !!flag; };
  353. const getSubframeEnabled = () => subframeEnabled;
  354. const setExpressionsPlugin = (value) => { expressionsPlugin = value; };
  355. const getExpressionsPlugin = () => expressionsPlugin;
  356. const setExpressionInterfaces = (value) => { expressionsInterfaces = value; };
  357. const getExpressionInterfaces = () => expressionsInterfaces;
  358. const setDefaultCurveSegments = (value) => { defaultCurveSegments = value; };
  359. const getDefaultCurveSegments = () => defaultCurveSegments;
  360. const setIdPrefix = (value) => { idPrefix$1 = value; };
  361. const getIdPrefix = () => idPrefix$1;
  362. function createNS(type) {
  363. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  364. return document.createElementNS(svgNS, type);
  365. }
  366. const dataManager = (function () {
  367. var _counterId = 1;
  368. var processes = [];
  369. var workerFn;
  370. var workerInstance;
  371. var workerProxy = {
  372. onmessage: function () {
  373. },
  374. postMessage: function (path) {
  375. workerFn({
  376. data: path,
  377. });
  378. },
  379. };
  380. var _workerSelf = {
  381. postMessage: function (data) {
  382. workerProxy.onmessage({
  383. data: data,
  384. });
  385. },
  386. };
  387. function createWorker(fn) {
  388. if (window.Worker && window.Blob && getWebWorker()) {
  389. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  390. // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  391. var url = URL.createObjectURL(blob);
  392. return new Worker(url);
  393. }
  394. workerFn = fn;
  395. return workerProxy;
  396. }
  397. function setupWorker() {
  398. if (!workerInstance) {
  399. workerInstance = createWorker(function workerStart(e) {
  400. function dataFunctionManager() {
  401. function completeLayers(layers, comps) {
  402. var layerData;
  403. var i;
  404. var len = layers.length;
  405. var j;
  406. var jLen;
  407. var k;
  408. var kLen;
  409. for (i = 0; i < len; i += 1) {
  410. layerData = layers[i];
  411. if (('ks' in layerData) && !layerData.completed) {
  412. layerData.completed = true;
  413. if (layerData.hasMask) {
  414. var maskProps = layerData.masksProperties;
  415. jLen = maskProps.length;
  416. for (j = 0; j < jLen; j += 1) {
  417. if (maskProps[j].pt.k.i) {
  418. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  419. } else {
  420. kLen = maskProps[j].pt.k.length;
  421. for (k = 0; k < kLen; k += 1) {
  422. if (maskProps[j].pt.k[k].s) {
  423. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  424. }
  425. if (maskProps[j].pt.k[k].e) {
  426. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  427. }
  428. }
  429. }
  430. }
  431. }
  432. if (layerData.ty === 0) {
  433. layerData.layers = findCompLayers(layerData.refId, comps);
  434. completeLayers(layerData.layers, comps);
  435. } else if (layerData.ty === 4) {
  436. completeShapes(layerData.shapes);
  437. } else if (layerData.ty === 5) {
  438. completeText(layerData);
  439. }
  440. }
  441. }
  442. }
  443. function completeChars(chars, assets) {
  444. if (chars) {
  445. var i = 0;
  446. var len = chars.length;
  447. for (i = 0; i < len; i += 1) {
  448. if (chars[i].t === 1) {
  449. // var compData = findComp(chars[i].data.refId, assets);
  450. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
  451. // chars[i].data.ip = 0;
  452. // chars[i].data.op = 99999;
  453. // chars[i].data.st = 0;
  454. // chars[i].data.sr = 1;
  455. // chars[i].w = compData.w;
  456. // chars[i].data.ks = {
  457. // a: { k: [0, 0, 0], a: 0 },
  458. // p: { k: [0, -compData.h, 0], a: 0 },
  459. // r: { k: 0, a: 0 },
  460. // s: { k: [100, 100], a: 0 },
  461. // o: { k: 100, a: 0 },
  462. // };
  463. completeLayers(chars[i].data.layers, assets);
  464. }
  465. }
  466. }
  467. }
  468. function findComp(id, comps) {
  469. var i = 0;
  470. var len = comps.length;
  471. while (i < len) {
  472. if (comps[i].id === id) {
  473. return comps[i];
  474. }
  475. i += 1;
  476. }
  477. return null;
  478. }
  479. function findCompLayers(id, comps) {
  480. var comp = findComp(id, comps);
  481. if (comp) {
  482. if (!comp.layers.__used) {
  483. comp.layers.__used = true;
  484. return comp.layers;
  485. }
  486. return JSON.parse(JSON.stringify(comp.layers));
  487. }
  488. return null;
  489. }
  490. function completeShapes(arr) {
  491. var i;
  492. var len = arr.length;
  493. var j;
  494. var jLen;
  495. for (i = len - 1; i >= 0; i -= 1) {
  496. if (arr[i].ty === 'sh') {
  497. if (arr[i].ks.k.i) {
  498. convertPathsToAbsoluteValues(arr[i].ks.k);
  499. } else {
  500. jLen = arr[i].ks.k.length;
  501. for (j = 0; j < jLen; j += 1) {
  502. if (arr[i].ks.k[j].s) {
  503. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  504. }
  505. if (arr[i].ks.k[j].e) {
  506. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  507. }
  508. }
  509. }
  510. } else if (arr[i].ty === 'gr') {
  511. completeShapes(arr[i].it);
  512. }
  513. }
  514. }
  515. function convertPathsToAbsoluteValues(path) {
  516. var i;
  517. var len = path.i.length;
  518. for (i = 0; i < len; i += 1) {
  519. path.i[i][0] += path.v[i][0];
  520. path.i[i][1] += path.v[i][1];
  521. path.o[i][0] += path.v[i][0];
  522. path.o[i][1] += path.v[i][1];
  523. }
  524. }
  525. function checkVersion(minimum, animVersionString) {
  526. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  527. if (minimum[0] > animVersion[0]) {
  528. return true;
  529. } if (animVersion[0] > minimum[0]) {
  530. return false;
  531. }
  532. if (minimum[1] > animVersion[1]) {
  533. return true;
  534. } if (animVersion[1] > minimum[1]) {
  535. return false;
  536. }
  537. if (minimum[2] > animVersion[2]) {
  538. return true;
  539. } if (animVersion[2] > minimum[2]) {
  540. return false;
  541. }
  542. return null;
  543. }
  544. var checkText = (function () {
  545. var minimumVersion = [4, 4, 14];
  546. function updateTextLayer(textLayer) {
  547. var documentData = textLayer.t.d;
  548. textLayer.t.d = {
  549. k: [
  550. {
  551. s: documentData,
  552. t: 0,
  553. },
  554. ],
  555. };
  556. }
  557. function iterateLayers(layers) {
  558. var i;
  559. var len = layers.length;
  560. for (i = 0; i < len; i += 1) {
  561. if (layers[i].ty === 5) {
  562. updateTextLayer(layers[i]);
  563. }
  564. }
  565. }
  566. return function (animationData) {
  567. if (checkVersion(minimumVersion, animationData.v)) {
  568. iterateLayers(animationData.layers);
  569. if (animationData.assets) {
  570. var i;
  571. var len = animationData.assets.length;
  572. for (i = 0; i < len; i += 1) {
  573. if (animationData.assets[i].layers) {
  574. iterateLayers(animationData.assets[i].layers);
  575. }
  576. }
  577. }
  578. }
  579. };
  580. }());
  581. var checkChars = (function () {
  582. var minimumVersion = [4, 7, 99];
  583. return function (animationData) {
  584. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  585. var i;
  586. var len = animationData.chars.length;
  587. for (i = 0; i < len; i += 1) {
  588. var charData = animationData.chars[i];
  589. if (charData.data && charData.data.shapes) {
  590. completeShapes(charData.data.shapes);
  591. charData.data.ip = 0;
  592. charData.data.op = 99999;
  593. charData.data.st = 0;
  594. charData.data.sr = 1;
  595. charData.data.ks = {
  596. p: { k: [0, 0], a: 0 },
  597. s: { k: [100, 100], a: 0 },
  598. a: { k: [0, 0], a: 0 },
  599. r: { k: 0, a: 0 },
  600. o: { k: 100, a: 0 },
  601. };
  602. if (!animationData.chars[i].t) {
  603. charData.data.shapes.push(
  604. {
  605. ty: 'no',
  606. }
  607. );
  608. charData.data.shapes[0].it.push(
  609. {
  610. p: { k: [0, 0], a: 0 },
  611. s: { k: [100, 100], a: 0 },
  612. a: { k: [0, 0], a: 0 },
  613. r: { k: 0, a: 0 },
  614. o: { k: 100, a: 0 },
  615. sk: { k: 0, a: 0 },
  616. sa: { k: 0, a: 0 },
  617. ty: 'tr',
  618. }
  619. );
  620. }
  621. }
  622. }
  623. }
  624. };
  625. }());
  626. var checkPathProperties = (function () {
  627. var minimumVersion = [5, 7, 15];
  628. function updateTextLayer(textLayer) {
  629. var pathData = textLayer.t.p;
  630. if (typeof pathData.a === 'number') {
  631. pathData.a = {
  632. a: 0,
  633. k: pathData.a,
  634. };
  635. }
  636. if (typeof pathData.p === 'number') {
  637. pathData.p = {
  638. a: 0,
  639. k: pathData.p,
  640. };
  641. }
  642. if (typeof pathData.r === 'number') {
  643. pathData.r = {
  644. a: 0,
  645. k: pathData.r,
  646. };
  647. }
  648. }
  649. function iterateLayers(layers) {
  650. var i;
  651. var len = layers.length;
  652. for (i = 0; i < len; i += 1) {
  653. if (layers[i].ty === 5) {
  654. updateTextLayer(layers[i]);
  655. }
  656. }
  657. }
  658. return function (animationData) {
  659. if (checkVersion(minimumVersion, animationData.v)) {
  660. iterateLayers(animationData.layers);
  661. if (animationData.assets) {
  662. var i;
  663. var len = animationData.assets.length;
  664. for (i = 0; i < len; i += 1) {
  665. if (animationData.assets[i].layers) {
  666. iterateLayers(animationData.assets[i].layers);
  667. }
  668. }
  669. }
  670. }
  671. };
  672. }());
  673. var checkColors = (function () {
  674. var minimumVersion = [4, 1, 9];
  675. function iterateShapes(shapes) {
  676. var i;
  677. var len = shapes.length;
  678. var j;
  679. var jLen;
  680. for (i = 0; i < len; i += 1) {
  681. if (shapes[i].ty === 'gr') {
  682. iterateShapes(shapes[i].it);
  683. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  684. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  685. jLen = shapes[i].c.k.length;
  686. for (j = 0; j < jLen; j += 1) {
  687. if (shapes[i].c.k[j].s) {
  688. shapes[i].c.k[j].s[0] /= 255;
  689. shapes[i].c.k[j].s[1] /= 255;
  690. shapes[i].c.k[j].s[2] /= 255;
  691. shapes[i].c.k[j].s[3] /= 255;
  692. }
  693. if (shapes[i].c.k[j].e) {
  694. shapes[i].c.k[j].e[0] /= 255;
  695. shapes[i].c.k[j].e[1] /= 255;
  696. shapes[i].c.k[j].e[2] /= 255;
  697. shapes[i].c.k[j].e[3] /= 255;
  698. }
  699. }
  700. } else {
  701. shapes[i].c.k[0] /= 255;
  702. shapes[i].c.k[1] /= 255;
  703. shapes[i].c.k[2] /= 255;
  704. shapes[i].c.k[3] /= 255;
  705. }
  706. }
  707. }
  708. }
  709. function iterateLayers(layers) {
  710. var i;
  711. var len = layers.length;
  712. for (i = 0; i < len; i += 1) {
  713. if (layers[i].ty === 4) {
  714. iterateShapes(layers[i].shapes);
  715. }
  716. }
  717. }
  718. return function (animationData) {
  719. if (checkVersion(minimumVersion, animationData.v)) {
  720. iterateLayers(animationData.layers);
  721. if (animationData.assets) {
  722. var i;
  723. var len = animationData.assets.length;
  724. for (i = 0; i < len; i += 1) {
  725. if (animationData.assets[i].layers) {
  726. iterateLayers(animationData.assets[i].layers);
  727. }
  728. }
  729. }
  730. }
  731. };
  732. }());
  733. var checkShapes = (function () {
  734. var minimumVersion = [4, 4, 18];
  735. function completeClosingShapes(arr) {
  736. var i;
  737. var len = arr.length;
  738. var j;
  739. var jLen;
  740. for (i = len - 1; i >= 0; i -= 1) {
  741. if (arr[i].ty === 'sh') {
  742. if (arr[i].ks.k.i) {
  743. arr[i].ks.k.c = arr[i].closed;
  744. } else {
  745. jLen = arr[i].ks.k.length;
  746. for (j = 0; j < jLen; j += 1) {
  747. if (arr[i].ks.k[j].s) {
  748. arr[i].ks.k[j].s[0].c = arr[i].closed;
  749. }
  750. if (arr[i].ks.k[j].e) {
  751. arr[i].ks.k[j].e[0].c = arr[i].closed;
  752. }
  753. }
  754. }
  755. } else if (arr[i].ty === 'gr') {
  756. completeClosingShapes(arr[i].it);
  757. }
  758. }
  759. }
  760. function iterateLayers(layers) {
  761. var layerData;
  762. var i;
  763. var len = layers.length;
  764. var j;
  765. var jLen;
  766. var k;
  767. var kLen;
  768. for (i = 0; i < len; i += 1) {
  769. layerData = layers[i];
  770. if (layerData.hasMask) {
  771. var maskProps = layerData.masksProperties;
  772. jLen = maskProps.length;
  773. for (j = 0; j < jLen; j += 1) {
  774. if (maskProps[j].pt.k.i) {
  775. maskProps[j].pt.k.c = maskProps[j].cl;
  776. } else {
  777. kLen = maskProps[j].pt.k.length;
  778. for (k = 0; k < kLen; k += 1) {
  779. if (maskProps[j].pt.k[k].s) {
  780. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  781. }
  782. if (maskProps[j].pt.k[k].e) {
  783. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  784. }
  785. }
  786. }
  787. }
  788. }
  789. if (layerData.ty === 4) {
  790. completeClosingShapes(layerData.shapes);
  791. }
  792. }
  793. }
  794. return function (animationData) {
  795. if (checkVersion(minimumVersion, animationData.v)) {
  796. iterateLayers(animationData.layers);
  797. if (animationData.assets) {
  798. var i;
  799. var len = animationData.assets.length;
  800. for (i = 0; i < len; i += 1) {
  801. if (animationData.assets[i].layers) {
  802. iterateLayers(animationData.assets[i].layers);
  803. }
  804. }
  805. }
  806. }
  807. };
  808. }());
  809. function completeData(animationData) {
  810. if (animationData.__complete) {
  811. return;
  812. }
  813. checkColors(animationData);
  814. checkText(animationData);
  815. checkChars(animationData);
  816. checkPathProperties(animationData);
  817. checkShapes(animationData);
  818. completeLayers(animationData.layers, animationData.assets);
  819. completeChars(animationData.chars, animationData.assets);
  820. animationData.__complete = true;
  821. }
  822. function completeText(data) {
  823. if (data.t.a.length === 0 && !('m' in data.t.p)) {
  824. // data.singleShape = true;
  825. }
  826. }
  827. var moduleOb = {};
  828. moduleOb.completeData = completeData;
  829. moduleOb.checkColors = checkColors;
  830. moduleOb.checkChars = checkChars;
  831. moduleOb.checkPathProperties = checkPathProperties;
  832. moduleOb.checkShapes = checkShapes;
  833. moduleOb.completeLayers = completeLayers;
  834. return moduleOb;
  835. }
  836. if (!_workerSelf.dataManager) {
  837. _workerSelf.dataManager = dataFunctionManager();
  838. }
  839. if (!_workerSelf.assetLoader) {
  840. _workerSelf.assetLoader = (function () {
  841. function formatResponse(xhr) {
  842. // using typeof doubles the time of execution of this method,
  843. // so if available, it's better to use the header to validate the type
  844. var contentTypeHeader = xhr.getResponseHeader('content-type');
  845. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  846. return xhr.response;
  847. }
  848. if (xhr.response && typeof xhr.response === 'object') {
  849. return xhr.response;
  850. } if (xhr.response && typeof xhr.response === 'string') {
  851. return JSON.parse(xhr.response);
  852. } if (xhr.responseText) {
  853. return JSON.parse(xhr.responseText);
  854. }
  855. return null;
  856. }
  857. function loadAsset(path, fullPath, callback, errorCallback) {
  858. var response;
  859. var xhr = new XMLHttpRequest();
  860. // set responseType after calling open or IE will break.
  861. try {
  862. // This crashes on Android WebView prior to KitKat
  863. xhr.responseType = 'json';
  864. } catch (err) {} // eslint-disable-line no-empty
  865. xhr.onreadystatechange = function () {
  866. if (xhr.readyState === 4) {
  867. if (xhr.status === 200) {
  868. response = formatResponse(xhr);
  869. callback(response);
  870. } else {
  871. try {
  872. response = formatResponse(xhr);
  873. callback(response);
  874. } catch (err) {
  875. if (errorCallback) {
  876. errorCallback(err);
  877. }
  878. }
  879. }
  880. }
  881. };
  882. try {
  883. // Hack to workaround banner validation
  884. xhr.open(['G', 'E', 'T'].join(''), path, true);
  885. } catch (error) {
  886. // Hack to workaround banner validation
  887. xhr.open(['G', 'E', 'T'].join(''), fullPath + '/' + path, true);
  888. }
  889. xhr.send();
  890. }
  891. return {
  892. load: loadAsset,
  893. };
  894. }());
  895. }
  896. if (e.data.type === 'loadAnimation') {
  897. _workerSelf.assetLoader.load(
  898. e.data.path,
  899. e.data.fullPath,
  900. function (data) {
  901. _workerSelf.dataManager.completeData(data);
  902. _workerSelf.postMessage({
  903. id: e.data.id,
  904. payload: data,
  905. status: 'success',
  906. });
  907. },
  908. function () {
  909. _workerSelf.postMessage({
  910. id: e.data.id,
  911. status: 'error',
  912. });
  913. }
  914. );
  915. } else if (e.data.type === 'complete') {
  916. var animation = e.data.animation;
  917. _workerSelf.dataManager.completeData(animation);
  918. _workerSelf.postMessage({
  919. id: e.data.id,
  920. payload: animation,
  921. status: 'success',
  922. });
  923. } else if (e.data.type === 'loadData') {
  924. _workerSelf.assetLoader.load(
  925. e.data.path,
  926. e.data.fullPath,
  927. function (data) {
  928. _workerSelf.postMessage({
  929. id: e.data.id,
  930. payload: data,
  931. status: 'success',
  932. });
  933. },
  934. function () {
  935. _workerSelf.postMessage({
  936. id: e.data.id,
  937. status: 'error',
  938. });
  939. }
  940. );
  941. }
  942. });
  943. workerInstance.onmessage = function (event) {
  944. var data = event.data;
  945. var id = data.id;
  946. var process = processes[id];
  947. processes[id] = null;
  948. if (data.status === 'success') {
  949. process.onComplete(data.payload);
  950. } else if (process.onError) {
  951. process.onError();
  952. }
  953. };
  954. }
  955. }
  956. function createProcess(onComplete, onError) {
  957. _counterId += 1;
  958. var id = 'processId_' + _counterId;
  959. processes[id] = {
  960. onComplete: onComplete,
  961. onError: onError,
  962. };
  963. return id;
  964. }
  965. function loadAnimation(path, onComplete, onError) {
  966. setupWorker();
  967. var processId = createProcess(onComplete, onError);
  968. workerInstance.postMessage({
  969. type: 'loadAnimation',
  970. path: path,
  971. fullPath: window.location.origin + window.location.pathname,
  972. id: processId,
  973. });
  974. }
  975. function loadData(path, onComplete, onError) {
  976. setupWorker();
  977. var processId = createProcess(onComplete, onError);
  978. workerInstance.postMessage({
  979. type: 'loadData',
  980. path: path,
  981. fullPath: window.location.origin + window.location.pathname,
  982. id: processId,
  983. });
  984. }
  985. function completeAnimation(anim, onComplete, onError) {
  986. setupWorker();
  987. var processId = createProcess(onComplete, onError);
  988. workerInstance.postMessage({
  989. type: 'complete',
  990. animation: anim,
  991. id: processId,
  992. });
  993. }
  994. return {
  995. loadAnimation: loadAnimation,
  996. loadData: loadData,
  997. completeAnimation: completeAnimation,
  998. };
  999. }());
  1000. const ImagePreloader = (function () {
  1001. var proxyImage = (function () {
  1002. var canvas = createTag('canvas');
  1003. canvas.width = 1;
  1004. canvas.height = 1;
  1005. var ctx = canvas.getContext('2d');
  1006. ctx.fillStyle = 'rgba(0,0,0,0)';
  1007. ctx.fillRect(0, 0, 1, 1);
  1008. return canvas;
  1009. }());
  1010. function imageLoaded() {
  1011. this.loadedAssets += 1;
  1012. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1013. if (this.imagesLoadedCb) {
  1014. this.imagesLoadedCb(null);
  1015. }
  1016. }
  1017. }
  1018. function footageLoaded() {
  1019. this.loadedFootagesCount += 1;
  1020. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1021. if (this.imagesLoadedCb) {
  1022. this.imagesLoadedCb(null);
  1023. }
  1024. }
  1025. }
  1026. function getAssetsPath(assetData, assetsPath, originalPath) {
  1027. var path = '';
  1028. if (assetData.e) {
  1029. path = assetData.p;
  1030. } else if (assetsPath) {
  1031. var imagePath = assetData.p;
  1032. if (imagePath.indexOf('images/') !== -1) {
  1033. imagePath = imagePath.split('/')[1];
  1034. }
  1035. path = assetsPath + imagePath;
  1036. } else {
  1037. path = originalPath;
  1038. path += assetData.u ? assetData.u : '';
  1039. path += assetData.p;
  1040. }
  1041. return path;
  1042. }
  1043. function testImageLoaded(img) {
  1044. var _count = 0;
  1045. var intervalId = setInterval(function () {
  1046. var box = img.getBBox();
  1047. if (box.width || _count > 500) {
  1048. this._imageLoaded();
  1049. clearInterval(intervalId);
  1050. }
  1051. _count += 1;
  1052. }.bind(this), 50);
  1053. }
  1054. function createImageData(assetData) {
  1055. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1056. var img = createNS('image');
  1057. if (isSafari) {
  1058. this.testImageLoaded(img);
  1059. } else {
  1060. img.addEventListener('load', this._imageLoaded, false);
  1061. }
  1062. img.addEventListener('error', function () {
  1063. ob.img = proxyImage;
  1064. this._imageLoaded();
  1065. }.bind(this), false);
  1066. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1067. if (this._elementHelper.append) {
  1068. this._elementHelper.append(img);
  1069. } else {
  1070. this._elementHelper.appendChild(img);
  1071. }
  1072. var ob = {
  1073. img: img,
  1074. assetData: assetData,
  1075. };
  1076. return ob;
  1077. }
  1078. function createImgData(assetData) {
  1079. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1080. var img = createTag('img');
  1081. img.crossOrigin = 'anonymous';
  1082. img.addEventListener('load', this._imageLoaded, false);
  1083. img.addEventListener('error', function () {
  1084. ob.img = proxyImage;
  1085. this._imageLoaded();
  1086. }.bind(this), false);
  1087. img.src = path;
  1088. var ob = {
  1089. img: img,
  1090. assetData: assetData,
  1091. };
  1092. return ob;
  1093. }
  1094. function createFootageData(data) {
  1095. var ob = {
  1096. assetData: data,
  1097. };
  1098. var path = getAssetsPath(data, this.assetsPath, this.path);
  1099. dataManager.loadData(path, function (footageData) {
  1100. ob.img = footageData;
  1101. this._footageLoaded();
  1102. }.bind(this), function () {
  1103. ob.img = {};
  1104. this._footageLoaded();
  1105. }.bind(this));
  1106. return ob;
  1107. }
  1108. function loadAssets(assets, cb) {
  1109. this.imagesLoadedCb = cb;
  1110. var i;
  1111. var len = assets.length;
  1112. for (i = 0; i < len; i += 1) {
  1113. if (!assets[i].layers) {
  1114. if (!assets[i].t || assets[i].t === 'seq') {
  1115. this.totalImages += 1;
  1116. this.images.push(this._createImageData(assets[i]));
  1117. } else if (assets[i].t === 3) {
  1118. this.totalFootages += 1;
  1119. this.images.push(this.createFootageData(assets[i]));
  1120. }
  1121. }
  1122. }
  1123. }
  1124. function setPath(path) {
  1125. this.path = path || '';
  1126. }
  1127. function setAssetsPath(path) {
  1128. this.assetsPath = path || '';
  1129. }
  1130. function getAsset(assetData) {
  1131. var i = 0;
  1132. var len = this.images.length;
  1133. while (i < len) {
  1134. if (this.images[i].assetData === assetData) {
  1135. return this.images[i].img;
  1136. }
  1137. i += 1;
  1138. }
  1139. return null;
  1140. }
  1141. function destroy() {
  1142. this.imagesLoadedCb = null;
  1143. this.images.length = 0;
  1144. }
  1145. function loadedImages() {
  1146. return this.totalImages === this.loadedAssets;
  1147. }
  1148. function loadedFootages() {
  1149. return this.totalFootages === this.loadedFootagesCount;
  1150. }
  1151. function setCacheType(type, elementHelper) {
  1152. if (type === 'svg') {
  1153. this._elementHelper = elementHelper;
  1154. this._createImageData = this.createImageData.bind(this);
  1155. } else {
  1156. this._createImageData = this.createImgData.bind(this);
  1157. }
  1158. }
  1159. function ImagePreloaderFactory() {
  1160. this._imageLoaded = imageLoaded.bind(this);
  1161. this._footageLoaded = footageLoaded.bind(this);
  1162. this.testImageLoaded = testImageLoaded.bind(this);
  1163. this.createFootageData = createFootageData.bind(this);
  1164. this.assetsPath = '';
  1165. this.path = '';
  1166. this.totalImages = 0;
  1167. this.totalFootages = 0;
  1168. this.loadedAssets = 0;
  1169. this.loadedFootagesCount = 0;
  1170. this.imagesLoadedCb = null;
  1171. this.images = [];
  1172. }
  1173. ImagePreloaderFactory.prototype = {
  1174. loadAssets: loadAssets,
  1175. setAssetsPath: setAssetsPath,
  1176. setPath: setPath,
  1177. loadedImages: loadedImages,
  1178. loadedFootages: loadedFootages,
  1179. destroy: destroy,
  1180. getAsset: getAsset,
  1181. createImgData: createImgData,
  1182. createImageData: createImageData,
  1183. imageLoaded: imageLoaded,
  1184. footageLoaded: footageLoaded,
  1185. setCacheType: setCacheType,
  1186. };
  1187. return ImagePreloaderFactory;
  1188. }());
  1189. function BaseEvent() {}
  1190. BaseEvent.prototype = {
  1191. triggerEvent: function (eventName, args) {
  1192. if (this._cbs[eventName]) {
  1193. var callbacks = this._cbs[eventName];
  1194. for (var i = 0; i < callbacks.length; i += 1) {
  1195. callbacks[i](args);
  1196. }
  1197. }
  1198. },
  1199. addEventListener: function (eventName, callback) {
  1200. if (!this._cbs[eventName]) {
  1201. this._cbs[eventName] = [];
  1202. }
  1203. this._cbs[eventName].push(callback);
  1204. return function () {
  1205. this.removeEventListener(eventName, callback);
  1206. }.bind(this);
  1207. },
  1208. removeEventListener: function (eventName, callback) {
  1209. if (!callback) {
  1210. this._cbs[eventName] = null;
  1211. } else if (this._cbs[eventName]) {
  1212. var i = 0;
  1213. var len = this._cbs[eventName].length;
  1214. while (i < len) {
  1215. if (this._cbs[eventName][i] === callback) {
  1216. this._cbs[eventName].splice(i, 1);
  1217. i -= 1;
  1218. len -= 1;
  1219. }
  1220. i += 1;
  1221. }
  1222. if (!this._cbs[eventName].length) {
  1223. this._cbs[eventName] = null;
  1224. }
  1225. }
  1226. },
  1227. };
  1228. const markerParser = (
  1229. function () {
  1230. function parsePayloadLines(payload) {
  1231. var lines = payload.split('\r\n');
  1232. var keys = {};
  1233. var line;
  1234. var keysCount = 0;
  1235. for (var i = 0; i < lines.length; i += 1) {
  1236. line = lines[i].split(':');
  1237. if (line.length === 2) {
  1238. keys[line[0]] = line[1].trim();
  1239. keysCount += 1;
  1240. }
  1241. }
  1242. if (keysCount === 0) {
  1243. throw new Error();
  1244. }
  1245. return keys;
  1246. }
  1247. return function (_markers) {
  1248. var markers = [];
  1249. for (var i = 0; i < _markers.length; i += 1) {
  1250. var _marker = _markers[i];
  1251. var markerData = {
  1252. time: _marker.tm,
  1253. duration: _marker.dr,
  1254. };
  1255. try {
  1256. markerData.payload = JSON.parse(_markers[i].cm);
  1257. } catch (_) {
  1258. try {
  1259. markerData.payload = parsePayloadLines(_markers[i].cm);
  1260. } catch (__) {
  1261. markerData.payload = {
  1262. name: _markers[i].cm,
  1263. };
  1264. }
  1265. }
  1266. markers.push(markerData);
  1267. }
  1268. return markers;
  1269. };
  1270. }());
  1271. const ProjectInterface = (function () {
  1272. function registerComposition(comp) {
  1273. this.compositions.push(comp);
  1274. }
  1275. return function () {
  1276. function _thisProjectFunction(name) {
  1277. var i = 0;
  1278. var len = this.compositions.length;
  1279. while (i < len) {
  1280. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1281. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1282. this.compositions[i].prepareFrame(this.currentFrame);
  1283. }
  1284. return this.compositions[i].compInterface;
  1285. }
  1286. i += 1;
  1287. }
  1288. return null;
  1289. }
  1290. _thisProjectFunction.compositions = [];
  1291. _thisProjectFunction.currentFrame = 0;
  1292. _thisProjectFunction.registerComposition = registerComposition;
  1293. return _thisProjectFunction;
  1294. };
  1295. }());
  1296. const renderers = {};
  1297. const registerRenderer = (key, value) => {
  1298. renderers[key] = value;
  1299. };
  1300. function getRenderer(key) {
  1301. return renderers[key];
  1302. }
  1303. function getRegisteredRenderer() {
  1304. // Returns canvas by default for compatibility
  1305. if (renderers.canvas) {
  1306. return 'canvas';
  1307. }
  1308. // Returns any renderer that is registered
  1309. for (const key in renderers) {
  1310. if (renderers[key]) {
  1311. return key;
  1312. }
  1313. }
  1314. return '';
  1315. }
  1316. const AnimationItem = function () {
  1317. this._cbs = [];
  1318. this.name = '';
  1319. this.path = '';
  1320. this.isLoaded = false;
  1321. this.currentFrame = 0;
  1322. this.currentRawFrame = 0;
  1323. this.firstFrame = 0;
  1324. this.totalFrames = 0;
  1325. this.frameRate = 0;
  1326. this.frameMult = 0;
  1327. this.playSpeed = 1;
  1328. this.playDirection = 1;
  1329. this.playCount = 0;
  1330. this.animationData = {};
  1331. this.assets = [];
  1332. this.isPaused = true;
  1333. this.autoplay = false;
  1334. this.loop = true;
  1335. this.renderer = null;
  1336. this.animationID = createElementID();
  1337. this.assetsPath = '';
  1338. this.timeCompleted = 0;
  1339. this.segmentPos = 0;
  1340. this.isSubframeEnabled = getSubframeEnabled();
  1341. this.segments = [];
  1342. this._idle = true;
  1343. this._completedLoop = false;
  1344. this.projectInterface = ProjectInterface();
  1345. this.imagePreloader = new ImagePreloader();
  1346. this.audioController = audioControllerFactory();
  1347. this.markers = [];
  1348. this.configAnimation = this.configAnimation.bind(this);
  1349. this.onSetupError = this.onSetupError.bind(this);
  1350. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1351. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1352. this.expressionsPlugin = getExpressionsPlugin();
  1353. };
  1354. extendPrototype([BaseEvent], AnimationItem);
  1355. AnimationItem.prototype.setParams = function (params) {
  1356. if (params.wrapper || params.container) {
  1357. this.wrapper = params.wrapper || params.container;
  1358. }
  1359. var animType = 'svg';
  1360. if (params.animType) {
  1361. animType = params.animType;
  1362. } else if (params.renderer) {
  1363. animType = params.renderer;
  1364. }
  1365. const RendererClass = getRenderer(animType);
  1366. this.renderer = new RendererClass(this, params.rendererSettings);
  1367. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1368. this.renderer.setProjectInterface(this.projectInterface);
  1369. this.animType = animType;
  1370. if (params.loop === ''
  1371. || params.loop === null
  1372. || params.loop === undefined
  1373. || params.loop === true) {
  1374. this.loop = true;
  1375. } else if (params.loop === false) {
  1376. this.loop = false;
  1377. } else {
  1378. this.loop = parseInt(params.loop, 10);
  1379. }
  1380. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1381. this.name = params.name ? params.name : '';
  1382. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1383. this.assetsPath = params.assetsPath;
  1384. this.initialSegment = params.initialSegment;
  1385. if (params.audioFactory) {
  1386. this.audioController.setAudioFactory(params.audioFactory);
  1387. }
  1388. if (params.animationData) {
  1389. this.setupAnimation(params.animationData);
  1390. } else if (params.path) {
  1391. if (params.path.lastIndexOf('\\') !== -1) {
  1392. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1393. } else {
  1394. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1395. }
  1396. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1397. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1398. dataManager.loadAnimation(
  1399. params.path,
  1400. this.configAnimation,
  1401. this.onSetupError
  1402. );
  1403. }
  1404. };
  1405. AnimationItem.prototype.onSetupError = function () {
  1406. this.trigger('data_failed');
  1407. };
  1408. AnimationItem.prototype.setupAnimation = function (data) {
  1409. dataManager.completeAnimation(
  1410. data,
  1411. this.configAnimation
  1412. );
  1413. };
  1414. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1415. if (animationData) {
  1416. if (typeof animationData !== 'object') {
  1417. animationData = JSON.parse(animationData);
  1418. }
  1419. }
  1420. var params = {
  1421. wrapper: wrapper,
  1422. animationData: animationData,
  1423. };
  1424. var wrapperAttributes = wrapper.attributes;
  1425. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1426. ? wrapperAttributes.getNamedItem('data-animation-path').value
  1427. : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1428. ? wrapperAttributes.getNamedItem('data-bm-path').value
  1429. : wrapperAttributes.getNamedItem('bm-path')
  1430. ? wrapperAttributes.getNamedItem('bm-path').value
  1431. : '';
  1432. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1433. ? wrapperAttributes.getNamedItem('data-anim-type').value
  1434. : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1435. ? wrapperAttributes.getNamedItem('data-bm-type').value
  1436. : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1437. ? wrapperAttributes.getNamedItem('bm-type').value
  1438. : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1439. ? wrapperAttributes.getNamedItem('data-bm-renderer').value
  1440. : wrapperAttributes.getNamedItem('bm-renderer')
  1441. ? wrapperAttributes.getNamedItem('bm-renderer').value
  1442. : getRegisteredRenderer() || 'canvas';
  1443. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1444. ? wrapperAttributes.getNamedItem('data-anim-loop').value
  1445. : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1446. ? wrapperAttributes.getNamedItem('data-bm-loop').value
  1447. : wrapperAttributes.getNamedItem('bm-loop')
  1448. ? wrapperAttributes.getNamedItem('bm-loop').value
  1449. : '';
  1450. if (loop === 'false') {
  1451. params.loop = false;
  1452. } else if (loop === 'true') {
  1453. params.loop = true;
  1454. } else if (loop !== '') {
  1455. params.loop = parseInt(loop, 10);
  1456. }
  1457. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1458. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value
  1459. : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1460. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value
  1461. : wrapperAttributes.getNamedItem('bm-autoplay')
  1462. ? wrapperAttributes.getNamedItem('bm-autoplay').value
  1463. : true;
  1464. params.autoplay = autoplay !== 'false';
  1465. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1466. ? wrapperAttributes.getNamedItem('data-name').value
  1467. : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1468. ? wrapperAttributes.getNamedItem('data-bm-name').value
  1469. : wrapperAttributes.getNamedItem('bm-name')
  1470. ? wrapperAttributes.getNamedItem('bm-name').value
  1471. : '';
  1472. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1473. ? wrapperAttributes.getNamedItem('data-anim-prerender').value
  1474. : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1475. ? wrapperAttributes.getNamedItem('data-bm-prerender').value
  1476. : wrapperAttributes.getNamedItem('bm-prerender')
  1477. ? wrapperAttributes.getNamedItem('bm-prerender').value
  1478. : '';
  1479. if (prerender === 'false') {
  1480. params.prerender = false;
  1481. }
  1482. if (!params.path) {
  1483. this.trigger('destroy');
  1484. } else {
  1485. this.setParams(params);
  1486. }
  1487. };
  1488. AnimationItem.prototype.includeLayers = function (data) {
  1489. if (data.op > this.animationData.op) {
  1490. this.animationData.op = data.op;
  1491. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1492. }
  1493. var layers = this.animationData.layers;
  1494. var i;
  1495. var len = layers.length;
  1496. var newLayers = data.layers;
  1497. var j;
  1498. var jLen = newLayers.length;
  1499. for (j = 0; j < jLen; j += 1) {
  1500. i = 0;
  1501. while (i < len) {
  1502. if (layers[i].id === newLayers[j].id) {
  1503. layers[i] = newLayers[j];
  1504. break;
  1505. }
  1506. i += 1;
  1507. }
  1508. }
  1509. if (data.chars || data.fonts) {
  1510. this.renderer.globalData.fontManager.addChars(data.chars);
  1511. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1512. }
  1513. if (data.assets) {
  1514. len = data.assets.length;
  1515. for (i = 0; i < len; i += 1) {
  1516. this.animationData.assets.push(data.assets[i]);
  1517. }
  1518. }
  1519. this.animationData.__complete = false;
  1520. dataManager.completeAnimation(
  1521. this.animationData,
  1522. this.onSegmentComplete
  1523. );
  1524. };
  1525. AnimationItem.prototype.onSegmentComplete = function (data) {
  1526. this.animationData = data;
  1527. var expressionsPlugin = getExpressionsPlugin();
  1528. if (expressionsPlugin) {
  1529. expressionsPlugin.initExpressions(this);
  1530. }
  1531. this.loadNextSegment();
  1532. };
  1533. AnimationItem.prototype.loadNextSegment = function () {
  1534. var segments = this.animationData.segments;
  1535. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1536. this.trigger('data_ready');
  1537. this.timeCompleted = this.totalFrames;
  1538. return;
  1539. }
  1540. var segment = segments.shift();
  1541. this.timeCompleted = segment.time * this.frameRate;
  1542. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1543. this.segmentPos += 1;
  1544. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1545. this.trigger('data_failed');
  1546. }.bind(this));
  1547. };
  1548. AnimationItem.prototype.loadSegments = function () {
  1549. var segments = this.animationData.segments;
  1550. if (!segments) {
  1551. this.timeCompleted = this.totalFrames;
  1552. }
  1553. this.loadNextSegment();
  1554. };
  1555. AnimationItem.prototype.imagesLoaded = function () {
  1556. this.trigger('loaded_images');
  1557. this.checkLoaded();
  1558. };
  1559. AnimationItem.prototype.preloadImages = function () {
  1560. this.imagePreloader.setAssetsPath(this.assetsPath);
  1561. this.imagePreloader.setPath(this.path);
  1562. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1563. };
  1564. AnimationItem.prototype.configAnimation = function (animData) {
  1565. if (!this.renderer) {
  1566. return;
  1567. }
  1568. try {
  1569. this.animationData = animData;
  1570. if (this.initialSegment) {
  1571. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1572. this.firstFrame = Math.round(this.initialSegment[0]);
  1573. } else {
  1574. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1575. this.firstFrame = Math.round(this.animationData.ip);
  1576. }
  1577. this.renderer.configAnimation(animData);
  1578. if (!animData.assets) {
  1579. animData.assets = [];
  1580. }
  1581. this.assets = this.animationData.assets;
  1582. this.frameRate = this.animationData.fr;
  1583. this.frameMult = this.animationData.fr / 1000;
  1584. this.renderer.searchExtraCompositions(animData.assets);
  1585. this.markers = markerParser(animData.markers || []);
  1586. this.trigger('config_ready');
  1587. this.preloadImages();
  1588. this.loadSegments();
  1589. this.updaFrameModifier();
  1590. this.waitForFontsLoaded();
  1591. if (this.isPaused) {
  1592. this.audioController.pause();
  1593. }
  1594. } catch (error) {
  1595. this.triggerConfigError(error);
  1596. }
  1597. };
  1598. AnimationItem.prototype.waitForFontsLoaded = function () {
  1599. if (!this.renderer) {
  1600. return;
  1601. }
  1602. if (this.renderer.globalData.fontManager.isLoaded) {
  1603. this.checkLoaded();
  1604. } else {
  1605. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1606. }
  1607. };
  1608. AnimationItem.prototype.checkLoaded = function () {
  1609. if (!this.isLoaded
  1610. && this.renderer.globalData.fontManager.isLoaded
  1611. && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas')
  1612. && (this.imagePreloader.loadedFootages())
  1613. ) {
  1614. this.isLoaded = true;
  1615. var expressionsPlugin = getExpressionsPlugin();
  1616. if (expressionsPlugin) {
  1617. expressionsPlugin.initExpressions(this);
  1618. }
  1619. this.renderer.initItems();
  1620. setTimeout(function () {
  1621. this.trigger('DOMLoaded');
  1622. }.bind(this), 0);
  1623. this.gotoFrame();
  1624. if (this.autoplay) {
  1625. this.play();
  1626. }
  1627. }
  1628. };
  1629. AnimationItem.prototype.resize = function (width, height) {
  1630. // Adding this validation for backwards compatibility in case an event object was being passed down
  1631. var _width = typeof width === 'number' ? width : undefined;
  1632. var _height = typeof height === 'number' ? height : undefined;
  1633. this.renderer.updateContainerSize(_width, _height);
  1634. };
  1635. AnimationItem.prototype.setSubframe = function (flag) {
  1636. this.isSubframeEnabled = !!flag;
  1637. };
  1638. AnimationItem.prototype.gotoFrame = function () {
  1639. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1640. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1641. this.currentFrame = this.timeCompleted;
  1642. }
  1643. this.trigger('enterFrame');
  1644. this.renderFrame();
  1645. this.trigger('drawnFrame');
  1646. };
  1647. AnimationItem.prototype.renderFrame = function () {
  1648. if (this.isLoaded === false || !this.renderer) {
  1649. return;
  1650. }
  1651. try {
  1652. if (this.expressionsPlugin) {
  1653. this.expressionsPlugin.resetFrame();
  1654. }
  1655. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1656. } catch (error) {
  1657. this.triggerRenderFrameError(error);
  1658. }
  1659. };
  1660. AnimationItem.prototype.play = function (name) {
  1661. if (name && this.name !== name) {
  1662. return;
  1663. }
  1664. if (this.isPaused === true) {
  1665. this.isPaused = false;
  1666. this.trigger('_play');
  1667. this.audioController.resume();
  1668. if (this._idle) {
  1669. this._idle = false;
  1670. this.trigger('_active');
  1671. }
  1672. }
  1673. };
  1674. AnimationItem.prototype.pause = function (name) {
  1675. if (name && this.name !== name) {
  1676. return;
  1677. }
  1678. if (this.isPaused === false) {
  1679. this.isPaused = true;
  1680. this.trigger('_pause');
  1681. this._idle = true;
  1682. this.trigger('_idle');
  1683. this.audioController.pause();
  1684. }
  1685. };
  1686. AnimationItem.prototype.togglePause = function (name) {
  1687. if (name && this.name !== name) {
  1688. return;
  1689. }
  1690. if (this.isPaused === true) {
  1691. this.play();
  1692. } else {
  1693. this.pause();
  1694. }
  1695. };
  1696. AnimationItem.prototype.stop = function (name) {
  1697. if (name && this.name !== name) {
  1698. return;
  1699. }
  1700. this.pause();
  1701. this.playCount = 0;
  1702. this._completedLoop = false;
  1703. this.setCurrentRawFrameValue(0);
  1704. };
  1705. AnimationItem.prototype.getMarkerData = function (markerName) {
  1706. var marker;
  1707. for (var i = 0; i < this.markers.length; i += 1) {
  1708. marker = this.markers[i];
  1709. if (marker.payload && marker.payload.name === markerName) {
  1710. return marker;
  1711. }
  1712. }
  1713. return null;
  1714. };
  1715. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1716. if (name && this.name !== name) {
  1717. return;
  1718. }
  1719. var numValue = Number(value);
  1720. if (isNaN(numValue)) {
  1721. var marker = this.getMarkerData(value);
  1722. if (marker) {
  1723. this.goToAndStop(marker.time, true);
  1724. }
  1725. } else if (isFrame) {
  1726. this.setCurrentRawFrameValue(value);
  1727. } else {
  1728. this.setCurrentRawFrameValue(value * this.frameModifier);
  1729. }
  1730. this.pause();
  1731. };
  1732. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1733. if (name && this.name !== name) {
  1734. return;
  1735. }
  1736. var numValue = Number(value);
  1737. if (isNaN(numValue)) {
  1738. var marker = this.getMarkerData(value);
  1739. if (marker) {
  1740. if (!marker.duration) {
  1741. this.goToAndStop(marker.time, true);
  1742. } else {
  1743. this.playSegments([marker.time, marker.time + marker.duration], true);
  1744. }
  1745. }
  1746. } else {
  1747. this.goToAndStop(numValue, isFrame, name);
  1748. }
  1749. this.play();
  1750. };
  1751. AnimationItem.prototype.advanceTime = function (value) {
  1752. if (this.isPaused === true || this.isLoaded === false) {
  1753. return;
  1754. }
  1755. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1756. var _isComplete = false;
  1757. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1758. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1759. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1760. if (!this.loop || this.playCount === this.loop) {
  1761. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1762. _isComplete = true;
  1763. nextValue = this.totalFrames - 1;
  1764. }
  1765. } else if (nextValue >= this.totalFrames) {
  1766. this.playCount += 1;
  1767. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1768. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1769. this._completedLoop = true;
  1770. this.trigger('loopComplete');
  1771. }
  1772. } else {
  1773. this.setCurrentRawFrameValue(nextValue);
  1774. }
  1775. } else if (nextValue < 0) {
  1776. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1777. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) { // eslint-disable-line no-plusplus
  1778. this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames));
  1779. if (!this._completedLoop) {
  1780. this._completedLoop = true;
  1781. } else {
  1782. this.trigger('loopComplete');
  1783. }
  1784. } else {
  1785. _isComplete = true;
  1786. nextValue = 0;
  1787. }
  1788. }
  1789. } else {
  1790. this.setCurrentRawFrameValue(nextValue);
  1791. }
  1792. if (_isComplete) {
  1793. this.setCurrentRawFrameValue(nextValue);
  1794. this.pause();
  1795. this.trigger('complete');
  1796. }
  1797. };
  1798. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1799. this.playCount = 0;
  1800. if (arr[1] < arr[0]) {
  1801. if (this.frameModifier > 0) {
  1802. if (this.playSpeed < 0) {
  1803. this.setSpeed(-this.playSpeed);
  1804. } else {
  1805. this.setDirection(-1);
  1806. }
  1807. }
  1808. this.totalFrames = arr[0] - arr[1];
  1809. this.timeCompleted = this.totalFrames;
  1810. this.firstFrame = arr[1];
  1811. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1812. } else if (arr[1] > arr[0]) {
  1813. if (this.frameModifier < 0) {
  1814. if (this.playSpeed < 0) {
  1815. this.setSpeed(-this.playSpeed);
  1816. } else {
  1817. this.setDirection(1);
  1818. }
  1819. }
  1820. this.totalFrames = arr[1] - arr[0];
  1821. this.timeCompleted = this.totalFrames;
  1822. this.firstFrame = arr[0];
  1823. this.setCurrentRawFrameValue(0.001 + offset);
  1824. }
  1825. this.trigger('segmentStart');
  1826. };
  1827. AnimationItem.prototype.setSegment = function (init, end) {
  1828. var pendingFrame = -1;
  1829. if (this.isPaused) {
  1830. if (this.currentRawFrame + this.firstFrame < init) {
  1831. pendingFrame = init;
  1832. } else if (this.currentRawFrame + this.firstFrame > end) {
  1833. pendingFrame = end - init;
  1834. }
  1835. }
  1836. this.firstFrame = init;
  1837. this.totalFrames = end - init;
  1838. this.timeCompleted = this.totalFrames;
  1839. if (pendingFrame !== -1) {
  1840. this.goToAndStop(pendingFrame, true);
  1841. }
  1842. };
  1843. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1844. if (forceFlag) {
  1845. this.segments.length = 0;
  1846. }
  1847. if (typeof arr[0] === 'object') {
  1848. var i;
  1849. var len = arr.length;
  1850. for (i = 0; i < len; i += 1) {
  1851. this.segments.push(arr[i]);
  1852. }
  1853. } else {
  1854. this.segments.push(arr);
  1855. }
  1856. if (this.segments.length && forceFlag) {
  1857. this.adjustSegment(this.segments.shift(), 0);
  1858. }
  1859. if (this.isPaused) {
  1860. this.play();
  1861. }
  1862. };
  1863. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1864. this.segments.length = 0;
  1865. this.segments.push([this.animationData.ip, this.animationData.op]);
  1866. if (forceFlag) {
  1867. this.checkSegments(0);
  1868. }
  1869. };
  1870. AnimationItem.prototype.checkSegments = function (offset) {
  1871. if (this.segments.length) {
  1872. this.adjustSegment(this.segments.shift(), offset);
  1873. return true;
  1874. }
  1875. return false;
  1876. };
  1877. AnimationItem.prototype.destroy = function (name) {
  1878. if ((name && this.name !== name) || !this.renderer) {
  1879. return;
  1880. }
  1881. this.renderer.destroy();
  1882. this.imagePreloader.destroy();
  1883. this.trigger('destroy');
  1884. this._cbs = null;
  1885. this.onEnterFrame = null;
  1886. this.onLoopComplete = null;
  1887. this.onComplete = null;
  1888. this.onSegmentStart = null;
  1889. this.onDestroy = null;
  1890. this.renderer = null;
  1891. this.expressionsPlugin = null;
  1892. this.imagePreloader = null;
  1893. this.projectInterface = null;
  1894. };
  1895. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1896. this.currentRawFrame = value;
  1897. this.gotoFrame();
  1898. };
  1899. AnimationItem.prototype.setSpeed = function (val) {
  1900. this.playSpeed = val;
  1901. this.updaFrameModifier();
  1902. };
  1903. AnimationItem.prototype.setDirection = function (val) {
  1904. this.playDirection = val < 0 ? -1 : 1;
  1905. this.updaFrameModifier();
  1906. };
  1907. AnimationItem.prototype.setLoop = function (isLooping) {
  1908. this.loop = isLooping;
  1909. };
  1910. AnimationItem.prototype.setVolume = function (val, name) {
  1911. if (name && this.name !== name) {
  1912. return;
  1913. }
  1914. this.audioController.setVolume(val);
  1915. };
  1916. AnimationItem.prototype.getVolume = function () {
  1917. return this.audioController.getVolume();
  1918. };
  1919. AnimationItem.prototype.mute = function (name) {
  1920. if (name && this.name !== name) {
  1921. return;
  1922. }
  1923. this.audioController.mute();
  1924. };
  1925. AnimationItem.prototype.unmute = function (name) {
  1926. if (name && this.name !== name) {
  1927. return;
  1928. }
  1929. this.audioController.unmute();
  1930. };
  1931. AnimationItem.prototype.updaFrameModifier = function () {
  1932. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1933. this.audioController.setRate(this.playSpeed * this.playDirection);
  1934. };
  1935. AnimationItem.prototype.getPath = function () {
  1936. return this.path;
  1937. };
  1938. AnimationItem.prototype.getAssetsPath = function (assetData) {
  1939. var path = '';
  1940. if (assetData.e) {
  1941. path = assetData.p;
  1942. } else if (this.assetsPath) {
  1943. var imagePath = assetData.p;
  1944. if (imagePath.indexOf('images/') !== -1) {
  1945. imagePath = imagePath.split('/')[1];
  1946. }
  1947. path = this.assetsPath + imagePath;
  1948. } else {
  1949. path = this.path;
  1950. path += assetData.u ? assetData.u : '';
  1951. path += assetData.p;
  1952. }
  1953. return path;
  1954. };
  1955. AnimationItem.prototype.getAssetData = function (id) {
  1956. var i = 0;
  1957. var len = this.assets.length;
  1958. while (i < len) {
  1959. if (id === this.assets[i].id) {
  1960. return this.assets[i];
  1961. }
  1962. i += 1;
  1963. }
  1964. return null;
  1965. };
  1966. AnimationItem.prototype.hide = function () {
  1967. this.renderer.hide();
  1968. };
  1969. AnimationItem.prototype.show = function () {
  1970. this.renderer.show();
  1971. };
  1972. AnimationItem.prototype.getDuration = function (isFrame) {
  1973. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  1974. };
  1975. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  1976. try {
  1977. var element = this.renderer.getElementByPath(path);
  1978. element.updateDocumentData(documentData, index);
  1979. } catch (error) {
  1980. // TODO: decide how to handle catch case
  1981. }
  1982. };
  1983. AnimationItem.prototype.trigger = function (name) {
  1984. if (this._cbs && this._cbs[name]) {
  1985. switch (name) {
  1986. case 'enterFrame':
  1987. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  1988. break;
  1989. case 'drawnFrame':
  1990. this.drawnFrameEvent.currentTime = this.currentFrame;
  1991. this.drawnFrameEvent.totalTime = this.totalFrames;
  1992. this.drawnFrameEvent.direction = this.frameModifier;
  1993. this.triggerEvent(name, this.drawnFrameEvent);
  1994. break;
  1995. case 'loopComplete':
  1996. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  1997. break;
  1998. case 'complete':
  1999. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  2000. break;
  2001. case 'segmentStart':
  2002. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2003. break;
  2004. case 'destroy':
  2005. this.triggerEvent(name, new BMDestroyEvent(name, this));
  2006. break;
  2007. default:
  2008. this.triggerEvent(name);
  2009. }
  2010. }
  2011. if (name === 'enterFrame' && this.onEnterFrame) {
  2012. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  2013. }
  2014. if (name === 'loopComplete' && this.onLoopComplete) {
  2015. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2016. }
  2017. if (name === 'complete' && this.onComplete) {
  2018. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  2019. }
  2020. if (name === 'segmentStart' && this.onSegmentStart) {
  2021. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2022. }
  2023. if (name === 'destroy' && this.onDestroy) {
  2024. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  2025. }
  2026. };
  2027. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  2028. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2029. this.triggerEvent('error', error);
  2030. if (this.onError) {
  2031. this.onError.call(this, error);
  2032. }
  2033. };
  2034. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2035. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2036. this.triggerEvent('error', error);
  2037. if (this.onError) {
  2038. this.onError.call(this, error);
  2039. }
  2040. };
  2041. const animationManager = (function () {
  2042. var moduleOb = {};
  2043. var registeredAnimations = [];
  2044. var initTime = 0;
  2045. var len = 0;
  2046. var playingAnimationsNum = 0;
  2047. var _stopped = true;
  2048. var _isFrozen = false;
  2049. function removeElement(ev) {
  2050. var i = 0;
  2051. var animItem = ev.target;
  2052. while (i < len) {
  2053. if (registeredAnimations[i].animation === animItem) {
  2054. registeredAnimations.splice(i, 1);
  2055. i -= 1;
  2056. len -= 1;
  2057. if (!animItem.isPaused) {
  2058. subtractPlayingCount();
  2059. }
  2060. }
  2061. i += 1;
  2062. }
  2063. }
  2064. function registerAnimation(element, animationData) {
  2065. if (!element) {
  2066. return null;
  2067. }
  2068. var i = 0;
  2069. while (i < len) {
  2070. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2071. return registeredAnimations[i].animation;
  2072. }
  2073. i += 1;
  2074. }
  2075. var animItem = new AnimationItem();
  2076. setupAnimation(animItem, element);
  2077. animItem.setData(element, animationData);
  2078. return animItem;
  2079. }
  2080. function getRegisteredAnimations() {
  2081. var i;
  2082. var lenAnims = registeredAnimations.length;
  2083. var animations = [];
  2084. for (i = 0; i < lenAnims; i += 1) {
  2085. animations.push(registeredAnimations[i].animation);
  2086. }
  2087. return animations;
  2088. }
  2089. function addPlayingCount() {
  2090. playingAnimationsNum += 1;
  2091. activate();
  2092. }
  2093. function subtractPlayingCount() {
  2094. playingAnimationsNum -= 1;
  2095. }
  2096. function setupAnimation(animItem, element) {
  2097. animItem.addEventListener('destroy', removeElement);
  2098. animItem.addEventListener('_active', addPlayingCount);
  2099. animItem.addEventListener('_idle', subtractPlayingCount);
  2100. registeredAnimations.push({ elem: element, animation: animItem });
  2101. len += 1;
  2102. }
  2103. function loadAnimation(params) {
  2104. var animItem = new AnimationItem();
  2105. setupAnimation(animItem, null);
  2106. animItem.setParams(params);
  2107. return animItem;
  2108. }
  2109. function setSpeed(val, animation) {
  2110. var i;
  2111. for (i = 0; i < len; i += 1) {
  2112. registeredAnimations[i].animation.setSpeed(val, animation);
  2113. }
  2114. }
  2115. function setDirection(val, animation) {
  2116. var i;
  2117. for (i = 0; i < len; i += 1) {
  2118. registeredAnimations[i].animation.setDirection(val, animation);
  2119. }
  2120. }
  2121. function play(animation) {
  2122. var i;
  2123. for (i = 0; i < len; i += 1) {
  2124. registeredAnimations[i].animation.play(animation);
  2125. }
  2126. }
  2127. function resume(nowTime) {
  2128. var elapsedTime = nowTime - initTime;
  2129. var i;
  2130. for (i = 0; i < len; i += 1) {
  2131. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2132. }
  2133. initTime = nowTime;
  2134. if (playingAnimationsNum && !_isFrozen) {
  2135. window.requestAnimationFrame(resume);
  2136. } else {
  2137. _stopped = true;
  2138. }
  2139. }
  2140. function first(nowTime) {
  2141. initTime = nowTime;
  2142. window.requestAnimationFrame(resume);
  2143. }
  2144. function pause(animation) {
  2145. var i;
  2146. for (i = 0; i < len; i += 1) {
  2147. registeredAnimations[i].animation.pause(animation);
  2148. }
  2149. }
  2150. function goToAndStop(value, isFrame, animation) {
  2151. var i;
  2152. for (i = 0; i < len; i += 1) {
  2153. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2154. }
  2155. }
  2156. function stop(animation) {
  2157. var i;
  2158. for (i = 0; i < len; i += 1) {
  2159. registeredAnimations[i].animation.stop(animation);
  2160. }
  2161. }
  2162. function togglePause(animation) {
  2163. var i;
  2164. for (i = 0; i < len; i += 1) {
  2165. registeredAnimations[i].animation.togglePause(animation);
  2166. }
  2167. }
  2168. function destroy(animation) {
  2169. var i;
  2170. for (i = (len - 1); i >= 0; i -= 1) {
  2171. registeredAnimations[i].animation.destroy(animation);
  2172. }
  2173. }
  2174. function searchAnimations(animationData, standalone, renderer) {
  2175. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')),
  2176. [].slice.call(document.getElementsByClassName('bodymovin')));
  2177. var i;
  2178. var lenAnims = animElements.length;
  2179. for (i = 0; i < lenAnims; i += 1) {
  2180. if (renderer) {
  2181. animElements[i].setAttribute('data-bm-type', renderer);
  2182. }
  2183. registerAnimation(animElements[i], animationData);
  2184. }
  2185. if (standalone && lenAnims === 0) {
  2186. if (!renderer) {
  2187. renderer = 'svg';
  2188. }
  2189. var body = document.getElementsByTagName('body')[0];
  2190. body.innerText = '';
  2191. var div = createTag('div');
  2192. div.style.width = '100%';
  2193. div.style.height = '100%';
  2194. div.setAttribute('data-bm-type', renderer);
  2195. body.appendChild(div);
  2196. registerAnimation(div, animationData);
  2197. }
  2198. }
  2199. function resize() {
  2200. var i;
  2201. for (i = 0; i < len; i += 1) {
  2202. registeredAnimations[i].animation.resize();
  2203. }
  2204. }
  2205. function activate() {
  2206. if (!_isFrozen && playingAnimationsNum) {
  2207. if (_stopped) {
  2208. window.requestAnimationFrame(first);
  2209. _stopped = false;
  2210. }
  2211. }
  2212. }
  2213. function freeze() {
  2214. _isFrozen = true;
  2215. }
  2216. function unfreeze() {
  2217. _isFrozen = false;
  2218. activate();
  2219. }
  2220. function setVolume(val, animation) {
  2221. var i;
  2222. for (i = 0; i < len; i += 1) {
  2223. registeredAnimations[i].animation.setVolume(val, animation);
  2224. }
  2225. }
  2226. function mute(animation) {
  2227. var i;
  2228. for (i = 0; i < len; i += 1) {
  2229. registeredAnimations[i].animation.mute(animation);
  2230. }
  2231. }
  2232. function unmute(animation) {
  2233. var i;
  2234. for (i = 0; i < len; i += 1) {
  2235. registeredAnimations[i].animation.unmute(animation);
  2236. }
  2237. }
  2238. moduleOb.registerAnimation = registerAnimation;
  2239. moduleOb.loadAnimation = loadAnimation;
  2240. moduleOb.setSpeed = setSpeed;
  2241. moduleOb.setDirection = setDirection;
  2242. moduleOb.play = play;
  2243. moduleOb.pause = pause;
  2244. moduleOb.stop = stop;
  2245. moduleOb.togglePause = togglePause;
  2246. moduleOb.searchAnimations = searchAnimations;
  2247. moduleOb.resize = resize;
  2248. // moduleOb.start = start;
  2249. moduleOb.goToAndStop = goToAndStop;
  2250. moduleOb.destroy = destroy;
  2251. moduleOb.freeze = freeze;
  2252. moduleOb.unfreeze = unfreeze;
  2253. moduleOb.setVolume = setVolume;
  2254. moduleOb.mute = mute;
  2255. moduleOb.unmute = unmute;
  2256. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2257. return moduleOb;
  2258. }());
  2259. /* eslint-disable */
  2260. const BezierFactory = (function () {
  2261. /**
  2262. * BezierEasing - use bezier curve for transition easing function
  2263. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2264. *
  2265. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2266. * Usage:
  2267. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2268. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2269. *
  2270. */
  2271. var ob = {};
  2272. ob.getBezierEasing = getBezierEasing;
  2273. var beziers = {};
  2274. function getBezierEasing(a, b, c, d, nm) {
  2275. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2276. if (beziers[str]) {
  2277. return beziers[str];
  2278. }
  2279. var bezEasing = new BezierEasing([a, b, c, d]);
  2280. beziers[str] = bezEasing;
  2281. return bezEasing;
  2282. }
  2283. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2284. var NEWTON_ITERATIONS = 4;
  2285. var NEWTON_MIN_SLOPE = 0.001;
  2286. var SUBDIVISION_PRECISION = 0.0000001;
  2287. var SUBDIVISION_MAX_ITERATIONS = 10;
  2288. var kSplineTableSize = 11;
  2289. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2290. var float32ArraySupported = typeof Float32Array === 'function';
  2291. function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
  2292. function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
  2293. function C(aA1) { return 3.0 * aA1; }
  2294. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2295. function calcBezier(aT, aA1, aA2) {
  2296. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2297. }
  2298. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2299. function getSlope(aT, aA1, aA2) {
  2300. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2301. }
  2302. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2303. var currentX,
  2304. currentT,
  2305. i = 0;
  2306. do {
  2307. currentT = aA + (aB - aA) / 2.0;
  2308. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2309. if (currentX > 0.0) {
  2310. aB = currentT;
  2311. } else {
  2312. aA = currentT;
  2313. }
  2314. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2315. return currentT;
  2316. }
  2317. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2318. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2319. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2320. if (currentSlope === 0.0) return aGuessT;
  2321. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2322. aGuessT -= currentX / currentSlope;
  2323. }
  2324. return aGuessT;
  2325. }
  2326. /**
  2327. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2328. */
  2329. function BezierEasing(points) {
  2330. this._p = points;
  2331. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2332. this._precomputed = false;
  2333. this.get = this.get.bind(this);
  2334. }
  2335. BezierEasing.prototype = {
  2336. get: function (x) {
  2337. var mX1 = this._p[0],
  2338. mY1 = this._p[1],
  2339. mX2 = this._p[2],
  2340. mY2 = this._p[3];
  2341. if (!this._precomputed) this._precompute();
  2342. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2343. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2344. if (x === 0) return 0;
  2345. if (x === 1) return 1;
  2346. return calcBezier(this._getTForX(x), mY1, mY2);
  2347. },
  2348. // Private part
  2349. _precompute: function () {
  2350. var mX1 = this._p[0],
  2351. mY1 = this._p[1],
  2352. mX2 = this._p[2],
  2353. mY2 = this._p[3];
  2354. this._precomputed = true;
  2355. if (mX1 !== mY1 || mX2 !== mY2) { this._calcSampleValues(); }
  2356. },
  2357. _calcSampleValues: function () {
  2358. var mX1 = this._p[0],
  2359. mX2 = this._p[2];
  2360. for (var i = 0; i < kSplineTableSize; ++i) {
  2361. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2362. }
  2363. },
  2364. /**
  2365. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2366. */
  2367. _getTForX: function (aX) {
  2368. var mX1 = this._p[0],
  2369. mX2 = this._p[2],
  2370. mSampleValues = this._mSampleValues;
  2371. var intervalStart = 0.0;
  2372. var currentSample = 1;
  2373. var lastSample = kSplineTableSize - 1;
  2374. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2375. intervalStart += kSampleStepSize;
  2376. }
  2377. --currentSample;
  2378. // Interpolate to provide an initial guess for t
  2379. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2380. var guessForT = intervalStart + dist * kSampleStepSize;
  2381. var initialSlope = getSlope(guessForT, mX1, mX2);
  2382. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2383. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2384. } if (initialSlope === 0.0) {
  2385. return guessForT;
  2386. }
  2387. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2388. },
  2389. };
  2390. return ob;
  2391. }());
  2392. const pooling = (function () {
  2393. function double(arr) {
  2394. return arr.concat(createSizedArray(arr.length));
  2395. }
  2396. return {
  2397. double: double,
  2398. };
  2399. }());
  2400. const poolFactory = (function () {
  2401. return function (initialLength, _create, _release) {
  2402. var _length = 0;
  2403. var _maxLength = initialLength;
  2404. var pool = createSizedArray(_maxLength);
  2405. var ob = {
  2406. newElement: newElement,
  2407. release: release,
  2408. };
  2409. function newElement() {
  2410. var element;
  2411. if (_length) {
  2412. _length -= 1;
  2413. element = pool[_length];
  2414. } else {
  2415. element = _create();
  2416. }
  2417. return element;
  2418. }
  2419. function release(element) {
  2420. if (_length === _maxLength) {
  2421. pool = pooling.double(pool);
  2422. _maxLength *= 2;
  2423. }
  2424. if (_release) {
  2425. _release(element);
  2426. }
  2427. pool[_length] = element;
  2428. _length += 1;
  2429. }
  2430. return ob;
  2431. };
  2432. }());
  2433. const bezierLengthPool = (function () {
  2434. function create() {
  2435. return {
  2436. addedLength: 0,
  2437. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2438. lengths: createTypedArray('float32', getDefaultCurveSegments()),
  2439. };
  2440. }
  2441. return poolFactory(8, create);
  2442. }());
  2443. const segmentsLengthPool = (function () {
  2444. function create() {
  2445. return {
  2446. lengths: [],
  2447. totalLength: 0,
  2448. };
  2449. }
  2450. function release(element) {
  2451. var i;
  2452. var len = element.lengths.length;
  2453. for (i = 0; i < len; i += 1) {
  2454. bezierLengthPool.release(element.lengths[i]);
  2455. }
  2456. element.lengths.length = 0;
  2457. }
  2458. return poolFactory(8, create, release);
  2459. }());
  2460. function bezFunction() {
  2461. var math = Math;
  2462. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2463. var det1 = (x1 * y2) + (y1 * x3) + (x2 * y3) - (x3 * y2) - (y3 * x1) - (x2 * y1);
  2464. return det1 > -0.001 && det1 < 0.001;
  2465. }
  2466. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2467. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2468. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2469. }
  2470. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2471. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2472. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2473. var diffDist;
  2474. if (dist1 > dist2) {
  2475. if (dist1 > dist3) {
  2476. diffDist = dist1 - dist2 - dist3;
  2477. } else {
  2478. diffDist = dist3 - dist2 - dist1;
  2479. }
  2480. } else if (dist3 > dist2) {
  2481. diffDist = dist3 - dist2 - dist1;
  2482. } else {
  2483. diffDist = dist2 - dist1 - dist3;
  2484. }
  2485. return diffDist > -0.0001 && diffDist < 0.0001;
  2486. }
  2487. var getBezierLength = (function () {
  2488. return function (pt1, pt2, pt3, pt4) {
  2489. var curveSegments = getDefaultCurveSegments();
  2490. var k;
  2491. var i;
  2492. var len;
  2493. var ptCoord;
  2494. var perc;
  2495. var addedLength = 0;
  2496. var ptDistance;
  2497. var point = [];
  2498. var lastPoint = [];
  2499. var lengthData = bezierLengthPool.newElement();
  2500. len = pt3.length;
  2501. for (k = 0; k < curveSegments; k += 1) {
  2502. perc = k / (curveSegments - 1);
  2503. ptDistance = 0;
  2504. for (i = 0; i < len; i += 1) {
  2505. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * pt3[i] + 3 * (1 - perc) * bmPow(perc, 2) * pt4[i] + bmPow(perc, 3) * pt2[i];
  2506. point[i] = ptCoord;
  2507. if (lastPoint[i] !== null) {
  2508. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2509. }
  2510. lastPoint[i] = point[i];
  2511. }
  2512. if (ptDistance) {
  2513. ptDistance = bmSqrt(ptDistance);
  2514. addedLength += ptDistance;
  2515. }
  2516. lengthData.percents[k] = perc;
  2517. lengthData.lengths[k] = addedLength;
  2518. }
  2519. lengthData.addedLength = addedLength;
  2520. return lengthData;
  2521. };
  2522. }());
  2523. function getSegmentsLength(shapeData) {
  2524. var segmentsLength = segmentsLengthPool.newElement();
  2525. var closed = shapeData.c;
  2526. var pathV = shapeData.v;
  2527. var pathO = shapeData.o;
  2528. var pathI = shapeData.i;
  2529. var i;
  2530. var len = shapeData._length;
  2531. var lengths = segmentsLength.lengths;
  2532. var totalLength = 0;
  2533. for (i = 0; i < len - 1; i += 1) {
  2534. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2535. totalLength += lengths[i].addedLength;
  2536. }
  2537. if (closed && len) {
  2538. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2539. totalLength += lengths[i].addedLength;
  2540. }
  2541. segmentsLength.totalLength = totalLength;
  2542. return segmentsLength;
  2543. }
  2544. function BezierData(length) {
  2545. this.segmentLength = 0;
  2546. this.points = new Array(length);
  2547. }
  2548. function PointData(partial, point) {
  2549. this.partialLength = partial;
  2550. this.point = point;
  2551. }
  2552. var buildBezierData = (function () {
  2553. var storedData = {};
  2554. return function (pt1, pt2, pt3, pt4) {
  2555. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2556. if (!storedData[bezierName]) {
  2557. var curveSegments = getDefaultCurveSegments();
  2558. var k;
  2559. var i;
  2560. var len;
  2561. var ptCoord;
  2562. var perc;
  2563. var addedLength = 0;
  2564. var ptDistance;
  2565. var point;
  2566. var lastPoint = null;
  2567. if (pt1.length === 2 && (pt1[0] !== pt2[0] || pt1[1] !== pt2[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt1[0] + pt3[0], pt1[1] + pt3[1]) && pointOnLine2D(pt1[0], pt1[1], pt2[0], pt2[1], pt2[0] + pt4[0], pt2[1] + pt4[1])) {
  2568. curveSegments = 2;
  2569. }
  2570. var bezierData = new BezierData(curveSegments);
  2571. len = pt3.length;
  2572. for (k = 0; k < curveSegments; k += 1) {
  2573. point = createSizedArray(len);
  2574. perc = k / (curveSegments - 1);
  2575. ptDistance = 0;
  2576. for (i = 0; i < len; i += 1) {
  2577. ptCoord = bmPow(1 - perc, 3) * pt1[i] + 3 * bmPow(1 - perc, 2) * perc * (pt1[i] + pt3[i]) + 3 * (1 - perc) * bmPow(perc, 2) * (pt2[i] + pt4[i]) + bmPow(perc, 3) * pt2[i];
  2578. point[i] = ptCoord;
  2579. if (lastPoint !== null) {
  2580. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2581. }
  2582. }
  2583. ptDistance = bmSqrt(ptDistance);
  2584. addedLength += ptDistance;
  2585. bezierData.points[k] = new PointData(ptDistance, point);
  2586. lastPoint = point;
  2587. }
  2588. bezierData.segmentLength = addedLength;
  2589. storedData[bezierName] = bezierData;
  2590. }
  2591. return storedData[bezierName];
  2592. };
  2593. }());
  2594. function getDistancePerc(perc, bezierData) {
  2595. var percents = bezierData.percents;
  2596. var lengths = bezierData.lengths;
  2597. var len = percents.length;
  2598. var initPos = bmFloor((len - 1) * perc);
  2599. var lengthPos = perc * bezierData.addedLength;
  2600. var lPerc = 0;
  2601. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2602. return percents[initPos];
  2603. }
  2604. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2605. var flag = true;
  2606. while (flag) {
  2607. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2608. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2609. flag = false;
  2610. } else {
  2611. initPos += dir;
  2612. }
  2613. if (initPos < 0 || initPos >= len - 1) {
  2614. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2615. if (initPos === len - 1) {
  2616. return percents[initPos];
  2617. }
  2618. flag = false;
  2619. }
  2620. }
  2621. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2622. }
  2623. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2624. var t1 = getDistancePerc(percent, bezierData);
  2625. var u1 = 1 - t1;
  2626. var ptX = math.round((u1 * u1 * u1 * pt1[0] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[0] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[0] + t1 * t1 * t1 * pt2[0]) * 1000) / 1000;
  2627. var ptY = math.round((u1 * u1 * u1 * pt1[1] + (t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1) * pt3[1] + (t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1) * pt4[1] + t1 * t1 * t1 * pt2[1]) * 1000) / 1000;
  2628. return [ptX, ptY];
  2629. }
  2630. var bezierSegmentPoints = createTypedArray('float32', 8);
  2631. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2632. if (startPerc < 0) {
  2633. startPerc = 0;
  2634. } else if (startPerc > 1) {
  2635. startPerc = 1;
  2636. }
  2637. var t0 = getDistancePerc(startPerc, bezierData);
  2638. endPerc = endPerc > 1 ? 1 : endPerc;
  2639. var t1 = getDistancePerc(endPerc, bezierData);
  2640. var i;
  2641. var len = pt1.length;
  2642. var u0 = 1 - t0;
  2643. var u1 = 1 - t1;
  2644. var u0u0u0 = u0 * u0 * u0;
  2645. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2646. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2647. var t0t0t0 = t0 * t0 * t0;
  2648. //
  2649. var u0u0u1 = u0 * u0 * u1;
  2650. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2651. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2652. var t0t0t1 = t0 * t0 * t1;
  2653. //
  2654. var u0u1u1 = u0 * u1 * u1;
  2655. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2656. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2657. var t0t1t1 = t0 * t1 * t1;
  2658. //
  2659. var u1u1u1 = u1 * u1 * u1;
  2660. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2661. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2662. var t1t1t1 = t1 * t1 * t1;
  2663. for (i = 0; i < len; i += 1) {
  2664. bezierSegmentPoints[i * 4] = math.round((u0u0u0 * pt1[i] + t0u0u0_3 * pt3[i] + t0t0u0_3 * pt4[i] + t0t0t0 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2665. bezierSegmentPoints[i * 4 + 1] = math.round((u0u0u1 * pt1[i] + t0u0u1_3 * pt3[i] + t0t0u1_3 * pt4[i] + t0t0t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2666. bezierSegmentPoints[i * 4 + 2] = math.round((u0u1u1 * pt1[i] + t0u1u1_3 * pt3[i] + t0t1u1_3 * pt4[i] + t0t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2667. bezierSegmentPoints[i * 4 + 3] = math.round((u1u1u1 * pt1[i] + t1u1u1_3 * pt3[i] + t1t1u1_3 * pt4[i] + t1t1t1 * pt2[i]) * 1000) / 1000; // eslint-disable-line camelcase
  2668. }
  2669. return bezierSegmentPoints;
  2670. }
  2671. return {
  2672. getSegmentsLength: getSegmentsLength,
  2673. getNewSegment: getNewSegment,
  2674. getPointInSegment: getPointInSegment,
  2675. buildBezierData: buildBezierData,
  2676. pointOnLine2D: pointOnLine2D,
  2677. pointOnLine3D: pointOnLine3D,
  2678. };
  2679. }
  2680. const bez = bezFunction();
  2681. var initFrame = initialDefaultFrame;
  2682. var mathAbs = Math.abs;
  2683. function interpolateValue(frameNum, caching) {
  2684. var offsetTime = this.offsetTime;
  2685. var newValue;
  2686. if (this.propType === 'multidimensional') {
  2687. newValue = createTypedArray('float32', this.pv.length);
  2688. }
  2689. var iterationIndex = caching.lastIndex;
  2690. var i = iterationIndex;
  2691. var len = this.keyframes.length - 1;
  2692. var flag = true;
  2693. var keyData;
  2694. var nextKeyData;
  2695. var keyframeMetadata;
  2696. while (flag) {
  2697. keyData = this.keyframes[i];
  2698. nextKeyData = this.keyframes[i + 1];
  2699. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2700. if (keyData.h) {
  2701. keyData = nextKeyData;
  2702. }
  2703. iterationIndex = 0;
  2704. break;
  2705. }
  2706. if ((nextKeyData.t - offsetTime) > frameNum) {
  2707. iterationIndex = i;
  2708. break;
  2709. }
  2710. if (i < len - 1) {
  2711. i += 1;
  2712. } else {
  2713. iterationIndex = 0;
  2714. flag = false;
  2715. }
  2716. }
  2717. keyframeMetadata = this.keyframesMetadata[i] || {};
  2718. var k;
  2719. var kLen;
  2720. var perc;
  2721. var jLen;
  2722. var j;
  2723. var fnc;
  2724. var nextKeyTime = nextKeyData.t - offsetTime;
  2725. var keyTime = keyData.t - offsetTime;
  2726. var endValue;
  2727. if (keyData.to) {
  2728. if (!keyframeMetadata.bezierData) {
  2729. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2730. }
  2731. var bezierData = keyframeMetadata.bezierData;
  2732. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2733. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2734. kLen = bezierData.points[ind].point.length;
  2735. for (k = 0; k < kLen; k += 1) {
  2736. newValue[k] = bezierData.points[ind].point[k];
  2737. }
  2738. // caching._lastKeyframeIndex = -1;
  2739. } else {
  2740. if (keyframeMetadata.__fnct) {
  2741. fnc = keyframeMetadata.__fnct;
  2742. } else {
  2743. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2744. keyframeMetadata.__fnct = fnc;
  2745. }
  2746. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2747. var distanceInLine = bezierData.segmentLength * perc;
  2748. var segmentPerc;
  2749. var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0;
  2750. j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0;
  2751. flag = true;
  2752. jLen = bezierData.points.length;
  2753. while (flag) {
  2754. addedLength += bezierData.points[j].partialLength;
  2755. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2756. kLen = bezierData.points[j].point.length;
  2757. for (k = 0; k < kLen; k += 1) {
  2758. newValue[k] = bezierData.points[j].point[k];
  2759. }
  2760. break;
  2761. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2762. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2763. kLen = bezierData.points[j].point.length;
  2764. for (k = 0; k < kLen; k += 1) {
  2765. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2766. }
  2767. break;
  2768. }
  2769. if (j < jLen - 1) {
  2770. j += 1;
  2771. } else {
  2772. flag = false;
  2773. }
  2774. }
  2775. caching._lastPoint = j;
  2776. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2777. caching._lastKeyframeIndex = i;
  2778. }
  2779. } else {
  2780. var outX;
  2781. var outY;
  2782. var inX;
  2783. var inY;
  2784. var keyValue;
  2785. len = keyData.s.length;
  2786. endValue = nextKeyData.s || keyData.e;
  2787. if (this.sh && keyData.h !== 1) {
  2788. if (frameNum >= nextKeyTime) {
  2789. newValue[0] = endValue[0];
  2790. newValue[1] = endValue[1];
  2791. newValue[2] = endValue[2];
  2792. } else if (frameNum <= keyTime) {
  2793. newValue[0] = keyData.s[0];
  2794. newValue[1] = keyData.s[1];
  2795. newValue[2] = keyData.s[2];
  2796. } else {
  2797. var quatStart = createQuaternion(keyData.s);
  2798. var quatEnd = createQuaternion(endValue);
  2799. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2800. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2801. }
  2802. } else {
  2803. for (i = 0; i < len; i += 1) {
  2804. if (keyData.h !== 1) {
  2805. if (frameNum >= nextKeyTime) {
  2806. perc = 1;
  2807. } else if (frameNum < keyTime) {
  2808. perc = 0;
  2809. } else {
  2810. if (keyData.o.x.constructor === Array) {
  2811. if (!keyframeMetadata.__fnct) {
  2812. keyframeMetadata.__fnct = [];
  2813. }
  2814. if (!keyframeMetadata.__fnct[i]) {
  2815. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2816. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2817. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2818. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2819. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2820. keyframeMetadata.__fnct[i] = fnc;
  2821. } else {
  2822. fnc = keyframeMetadata.__fnct[i];
  2823. }
  2824. } else if (!keyframeMetadata.__fnct) {
  2825. outX = keyData.o.x;
  2826. outY = keyData.o.y;
  2827. inX = keyData.i.x;
  2828. inY = keyData.i.y;
  2829. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2830. keyData.keyframeMetadata = fnc;
  2831. } else {
  2832. fnc = keyframeMetadata.__fnct;
  2833. }
  2834. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2835. }
  2836. }
  2837. endValue = nextKeyData.s || keyData.e;
  2838. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2839. if (this.propType === 'multidimensional') {
  2840. newValue[i] = keyValue;
  2841. } else {
  2842. newValue = keyValue;
  2843. }
  2844. }
  2845. }
  2846. }
  2847. caching.lastIndex = iterationIndex;
  2848. return newValue;
  2849. }
  2850. // based on @Toji's https://github.com/toji/gl-matrix/
  2851. function slerp(a, b, t) {
  2852. var out = [];
  2853. var ax = a[0];
  2854. var ay = a[1];
  2855. var az = a[2];
  2856. var aw = a[3];
  2857. var bx = b[0];
  2858. var by = b[1];
  2859. var bz = b[2];
  2860. var bw = b[3];
  2861. var omega;
  2862. var cosom;
  2863. var sinom;
  2864. var scale0;
  2865. var scale1;
  2866. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2867. if (cosom < 0.0) {
  2868. cosom = -cosom;
  2869. bx = -bx;
  2870. by = -by;
  2871. bz = -bz;
  2872. bw = -bw;
  2873. }
  2874. if ((1.0 - cosom) > 0.000001) {
  2875. omega = Math.acos(cosom);
  2876. sinom = Math.sin(omega);
  2877. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2878. scale1 = Math.sin(t * omega) / sinom;
  2879. } else {
  2880. scale0 = 1.0 - t;
  2881. scale1 = t;
  2882. }
  2883. out[0] = scale0 * ax + scale1 * bx;
  2884. out[1] = scale0 * ay + scale1 * by;
  2885. out[2] = scale0 * az + scale1 * bz;
  2886. out[3] = scale0 * aw + scale1 * bw;
  2887. return out;
  2888. }
  2889. function quaternionToEuler(out, quat) {
  2890. var qx = quat[0];
  2891. var qy = quat[1];
  2892. var qz = quat[2];
  2893. var qw = quat[3];
  2894. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2895. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2896. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2897. out[0] = heading / degToRads;
  2898. out[1] = attitude / degToRads;
  2899. out[2] = bank / degToRads;
  2900. }
  2901. function createQuaternion(values) {
  2902. var heading = values[0] * degToRads;
  2903. var attitude = values[1] * degToRads;
  2904. var bank = values[2] * degToRads;
  2905. var c1 = Math.cos(heading / 2);
  2906. var c2 = Math.cos(attitude / 2);
  2907. var c3 = Math.cos(bank / 2);
  2908. var s1 = Math.sin(heading / 2);
  2909. var s2 = Math.sin(attitude / 2);
  2910. var s3 = Math.sin(bank / 2);
  2911. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2912. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2913. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2914. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2915. return [x, y, z, w];
  2916. }
  2917. function getValueAtCurrentTime() {
  2918. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2919. var initTime = this.keyframes[0].t - this.offsetTime;
  2920. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2921. if (!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))) {
  2922. if (this._caching.lastFrame >= frameNum) {
  2923. this._caching._lastKeyframeIndex = -1;
  2924. this._caching.lastIndex = 0;
  2925. }
  2926. var renderResult = this.interpolateValue(frameNum, this._caching);
  2927. this.pv = renderResult;
  2928. }
  2929. this._caching.lastFrame = frameNum;
  2930. return this.pv;
  2931. }
  2932. function setVValue(val) {
  2933. var multipliedValue;
  2934. if (this.propType === 'unidimensional') {
  2935. multipliedValue = val * this.mult;
  2936. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  2937. this.v = multipliedValue;
  2938. this._mdf = true;
  2939. }
  2940. } else {
  2941. var i = 0;
  2942. var len = this.v.length;
  2943. while (i < len) {
  2944. multipliedValue = val[i] * this.mult;
  2945. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  2946. this.v[i] = multipliedValue;
  2947. this._mdf = true;
  2948. }
  2949. i += 1;
  2950. }
  2951. }
  2952. }
  2953. function processEffectsSequence() {
  2954. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  2955. return;
  2956. }
  2957. if (this.lock) {
  2958. this.setVValue(this.pv);
  2959. return;
  2960. }
  2961. this.lock = true;
  2962. this._mdf = this._isFirstFrame;
  2963. var i;
  2964. var len = this.effectsSequence.length;
  2965. var finalValue = this.kf ? this.pv : this.data.k;
  2966. for (i = 0; i < len; i += 1) {
  2967. finalValue = this.effectsSequence[i](finalValue);
  2968. }
  2969. this.setVValue(finalValue);
  2970. this._isFirstFrame = false;
  2971. this.lock = false;
  2972. this.frameId = this.elem.globalData.frameId;
  2973. }
  2974. function addEffect(effectFunction) {
  2975. this.effectsSequence.push(effectFunction);
  2976. this.container.addDynamicProperty(this);
  2977. }
  2978. function ValueProperty(elem, data, mult, container) {
  2979. this.propType = 'unidimensional';
  2980. this.mult = mult || 1;
  2981. this.data = data;
  2982. this.v = mult ? data.k * mult : data.k;
  2983. this.pv = data.k;
  2984. this._mdf = false;
  2985. this.elem = elem;
  2986. this.container = container;
  2987. this.comp = elem.comp;
  2988. this.k = false;
  2989. this.kf = false;
  2990. this.vel = 0;
  2991. this.effectsSequence = [];
  2992. this._isFirstFrame = true;
  2993. this.getValue = processEffectsSequence;
  2994. this.setVValue = setVValue;
  2995. this.addEffect = addEffect;
  2996. }
  2997. function MultiDimensionalProperty(elem, data, mult, container) {
  2998. this.propType = 'multidimensional';
  2999. this.mult = mult || 1;
  3000. this.data = data;
  3001. this._mdf = false;
  3002. this.elem = elem;
  3003. this.container = container;
  3004. this.comp = elem.comp;
  3005. this.k = false;
  3006. this.kf = false;
  3007. this.frameId = -1;
  3008. var i;
  3009. var len = data.k.length;
  3010. this.v = createTypedArray('float32', len);
  3011. this.pv = createTypedArray('float32', len);
  3012. this.vel = createTypedArray('float32', len);
  3013. for (i = 0; i < len; i += 1) {
  3014. this.v[i] = data.k[i] * this.mult;
  3015. this.pv[i] = data.k[i];
  3016. }
  3017. this._isFirstFrame = true;
  3018. this.effectsSequence = [];
  3019. this.getValue = processEffectsSequence;
  3020. this.setVValue = setVValue;
  3021. this.addEffect = addEffect;
  3022. }
  3023. function KeyframedValueProperty(elem, data, mult, container) {
  3024. this.propType = 'unidimensional';
  3025. this.keyframes = data.k;
  3026. this.keyframesMetadata = [];
  3027. this.offsetTime = elem.data.st;
  3028. this.frameId = -1;
  3029. this._caching = {
  3030. lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1,
  3031. };
  3032. this.k = true;
  3033. this.kf = true;
  3034. this.data = data;
  3035. this.mult = mult || 1;
  3036. this.elem = elem;
  3037. this.container = container;
  3038. this.comp = elem.comp;
  3039. this.v = initFrame;
  3040. this.pv = initFrame;
  3041. this._isFirstFrame = true;
  3042. this.getValue = processEffectsSequence;
  3043. this.setVValue = setVValue;
  3044. this.interpolateValue = interpolateValue;
  3045. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3046. this.addEffect = addEffect;
  3047. }
  3048. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3049. this.propType = 'multidimensional';
  3050. var i;
  3051. var len = data.k.length;
  3052. var s;
  3053. var e;
  3054. var to;
  3055. var ti;
  3056. for (i = 0; i < len - 1; i += 1) {
  3057. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3058. s = data.k[i].s;
  3059. e = data.k[i + 1].s;
  3060. to = data.k[i].to;
  3061. ti = data.k[i].ti;
  3062. if ((s.length === 2 && !(s[0] === e[0] && s[1] === e[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], s[0] + to[0], s[1] + to[1]) && bez.pointOnLine2D(s[0], s[1], e[0], e[1], e[0] + ti[0], e[1] + ti[1])) || (s.length === 3 && !(s[0] === e[0] && s[1] === e[1] && s[2] === e[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], s[0] + to[0], s[1] + to[1], s[2] + to[2]) && bez.pointOnLine3D(s[0], s[1], s[2], e[0], e[1], e[2], e[0] + ti[0], e[1] + ti[1], e[2] + ti[2]))) {
  3063. data.k[i].to = null;
  3064. data.k[i].ti = null;
  3065. }
  3066. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3067. if (s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) {
  3068. data.k[i].to = null;
  3069. data.k[i].ti = null;
  3070. }
  3071. }
  3072. }
  3073. }
  3074. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3075. this.data = data;
  3076. this.keyframes = data.k;
  3077. this.keyframesMetadata = [];
  3078. this.offsetTime = elem.data.st;
  3079. this.k = true;
  3080. this.kf = true;
  3081. this._isFirstFrame = true;
  3082. this.mult = mult || 1;
  3083. this.elem = elem;
  3084. this.container = container;
  3085. this.comp = elem.comp;
  3086. this.getValue = processEffectsSequence;
  3087. this.setVValue = setVValue;
  3088. this.interpolateValue = interpolateValue;
  3089. this.frameId = -1;
  3090. var arrLen = data.k[0].s.length;
  3091. this.v = createTypedArray('float32', arrLen);
  3092. this.pv = createTypedArray('float32', arrLen);
  3093. for (i = 0; i < arrLen; i += 1) {
  3094. this.v[i] = initFrame;
  3095. this.pv[i] = initFrame;
  3096. }
  3097. this._caching = { lastFrame: initFrame, lastIndex: 0, value: createTypedArray('float32', arrLen) };
  3098. this.addEffect = addEffect;
  3099. }
  3100. const PropertyFactory = (function () {
  3101. function getProp(elem, data, type, mult, container) {
  3102. if (data.sid) {
  3103. data = elem.globalData.slotManager.getProp(data);
  3104. }
  3105. var p;
  3106. if (!data.k.length) {
  3107. p = new ValueProperty(elem, data, mult, container);
  3108. } else if (typeof (data.k[0]) === 'number') {
  3109. p = new MultiDimensionalProperty(elem, data, mult, container);
  3110. } else {
  3111. switch (type) {
  3112. case 0:
  3113. p = new KeyframedValueProperty(elem, data, mult, container);
  3114. break;
  3115. case 1:
  3116. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3117. break;
  3118. default:
  3119. break;
  3120. }
  3121. }
  3122. if (p.effectsSequence.length) {
  3123. container.addDynamicProperty(p);
  3124. }
  3125. return p;
  3126. }
  3127. var ob = {
  3128. getProp: getProp,
  3129. };
  3130. return ob;
  3131. }());
  3132. function DynamicPropertyContainer() {}
  3133. DynamicPropertyContainer.prototype = {
  3134. addDynamicProperty: function (prop) {
  3135. if (this.dynamicProperties.indexOf(prop) === -1) {
  3136. this.dynamicProperties.push(prop);
  3137. this.container.addDynamicProperty(this);
  3138. this._isAnimated = true;
  3139. }
  3140. },
  3141. iterateDynamicProperties: function () {
  3142. this._mdf = false;
  3143. var i;
  3144. var len = this.dynamicProperties.length;
  3145. for (i = 0; i < len; i += 1) {
  3146. this.dynamicProperties[i].getValue();
  3147. if (this.dynamicProperties[i]._mdf) {
  3148. this._mdf = true;
  3149. }
  3150. }
  3151. },
  3152. initDynamicPropertyContainer: function (container) {
  3153. this.container = container;
  3154. this.dynamicProperties = [];
  3155. this._mdf = false;
  3156. this._isAnimated = false;
  3157. },
  3158. };
  3159. const pointPool = (function () {
  3160. function create() {
  3161. return createTypedArray('float32', 2);
  3162. }
  3163. return poolFactory(8, create);
  3164. }());
  3165. function ShapePath() {
  3166. this.c = false;
  3167. this._length = 0;
  3168. this._maxLength = 8;
  3169. this.v = createSizedArray(this._maxLength);
  3170. this.o = createSizedArray(this._maxLength);
  3171. this.i = createSizedArray(this._maxLength);
  3172. }
  3173. ShapePath.prototype.setPathData = function (closed, len) {
  3174. this.c = closed;
  3175. this.setLength(len);
  3176. var i = 0;
  3177. while (i < len) {
  3178. this.v[i] = pointPool.newElement();
  3179. this.o[i] = pointPool.newElement();
  3180. this.i[i] = pointPool.newElement();
  3181. i += 1;
  3182. }
  3183. };
  3184. ShapePath.prototype.setLength = function (len) {
  3185. while (this._maxLength < len) {
  3186. this.doubleArrayLength();
  3187. }
  3188. this._length = len;
  3189. };
  3190. ShapePath.prototype.doubleArrayLength = function () {
  3191. this.v = this.v.concat(createSizedArray(this._maxLength));
  3192. this.i = this.i.concat(createSizedArray(this._maxLength));
  3193. this.o = this.o.concat(createSizedArray(this._maxLength));
  3194. this._maxLength *= 2;
  3195. };
  3196. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3197. var arr;
  3198. this._length = Math.max(this._length, pos + 1);
  3199. if (this._length >= this._maxLength) {
  3200. this.doubleArrayLength();
  3201. }
  3202. switch (type) {
  3203. case 'v':
  3204. arr = this.v;
  3205. break;
  3206. case 'i':
  3207. arr = this.i;
  3208. break;
  3209. case 'o':
  3210. arr = this.o;
  3211. break;
  3212. default:
  3213. arr = [];
  3214. break;
  3215. }
  3216. if (!arr[pos] || (arr[pos] && !replace)) {
  3217. arr[pos] = pointPool.newElement();
  3218. }
  3219. arr[pos][0] = x;
  3220. arr[pos][1] = y;
  3221. };
  3222. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3223. this.setXYAt(vX, vY, 'v', pos, replace);
  3224. this.setXYAt(oX, oY, 'o', pos, replace);
  3225. this.setXYAt(iX, iY, 'i', pos, replace);
  3226. };
  3227. ShapePath.prototype.reverse = function () {
  3228. var newPath = new ShapePath();
  3229. newPath.setPathData(this.c, this._length);
  3230. var vertices = this.v;
  3231. var outPoints = this.o;
  3232. var inPoints = this.i;
  3233. var init = 0;
  3234. if (this.c) {
  3235. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3236. init = 1;
  3237. }
  3238. var cnt = this._length - 1;
  3239. var len = this._length;
  3240. var i;
  3241. for (i = init; i < len; i += 1) {
  3242. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3243. cnt -= 1;
  3244. }
  3245. return newPath;
  3246. };
  3247. ShapePath.prototype.length = function () {
  3248. return this._length;
  3249. };
  3250. const shapePool = (function () {
  3251. function create() {
  3252. return new ShapePath();
  3253. }
  3254. function release(shapePath) {
  3255. var len = shapePath._length;
  3256. var i;
  3257. for (i = 0; i < len; i += 1) {
  3258. pointPool.release(shapePath.v[i]);
  3259. pointPool.release(shapePath.i[i]);
  3260. pointPool.release(shapePath.o[i]);
  3261. shapePath.v[i] = null;
  3262. shapePath.i[i] = null;
  3263. shapePath.o[i] = null;
  3264. }
  3265. shapePath._length = 0;
  3266. shapePath.c = false;
  3267. }
  3268. function clone(shape) {
  3269. var cloned = factory.newElement();
  3270. var i;
  3271. var len = shape._length === undefined ? shape.v.length : shape._length;
  3272. cloned.setLength(len);
  3273. cloned.c = shape.c;
  3274. for (i = 0; i < len; i += 1) {
  3275. cloned.setTripleAt(shape.v[i][0], shape.v[i][1], shape.o[i][0], shape.o[i][1], shape.i[i][0], shape.i[i][1], i);
  3276. }
  3277. return cloned;
  3278. }
  3279. var factory = poolFactory(4, create, release);
  3280. factory.clone = clone;
  3281. return factory;
  3282. }());
  3283. function ShapeCollection() {
  3284. this._length = 0;
  3285. this._maxLength = 4;
  3286. this.shapes = createSizedArray(this._maxLength);
  3287. }
  3288. ShapeCollection.prototype.addShape = function (shapeData) {
  3289. if (this._length === this._maxLength) {
  3290. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3291. this._maxLength *= 2;
  3292. }
  3293. this.shapes[this._length] = shapeData;
  3294. this._length += 1;
  3295. };
  3296. ShapeCollection.prototype.releaseShapes = function () {
  3297. var i;
  3298. for (i = 0; i < this._length; i += 1) {
  3299. shapePool.release(this.shapes[i]);
  3300. }
  3301. this._length = 0;
  3302. };
  3303. const shapeCollectionPool = (function () {
  3304. var ob = {
  3305. newShapeCollection: newShapeCollection,
  3306. release: release,
  3307. };
  3308. var _length = 0;
  3309. var _maxLength = 4;
  3310. var pool = createSizedArray(_maxLength);
  3311. function newShapeCollection() {
  3312. var shapeCollection;
  3313. if (_length) {
  3314. _length -= 1;
  3315. shapeCollection = pool[_length];
  3316. } else {
  3317. shapeCollection = new ShapeCollection();
  3318. }
  3319. return shapeCollection;
  3320. }
  3321. function release(shapeCollection) {
  3322. var i;
  3323. var len = shapeCollection._length;
  3324. for (i = 0; i < len; i += 1) {
  3325. shapePool.release(shapeCollection.shapes[i]);
  3326. }
  3327. shapeCollection._length = 0;
  3328. if (_length === _maxLength) {
  3329. pool = pooling.double(pool);
  3330. _maxLength *= 2;
  3331. }
  3332. pool[_length] = shapeCollection;
  3333. _length += 1;
  3334. }
  3335. return ob;
  3336. }());
  3337. const ShapePropertyFactory = (function () {
  3338. var initFrame = -999999;
  3339. function interpolateShape(frameNum, previousValue, caching) {
  3340. var iterationIndex = caching.lastIndex;
  3341. var keyPropS;
  3342. var keyPropE;
  3343. var isHold;
  3344. var j;
  3345. var k;
  3346. var jLen;
  3347. var kLen;
  3348. var perc;
  3349. var vertexValue;
  3350. var kf = this.keyframes;
  3351. if (frameNum < kf[0].t - this.offsetTime) {
  3352. keyPropS = kf[0].s[0];
  3353. isHold = true;
  3354. iterationIndex = 0;
  3355. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3356. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3357. /* if(kf[kf.length - 1].s){
  3358. keyPropS = kf[kf.length - 1].s[0];
  3359. }else{
  3360. keyPropS = kf[kf.length - 2].e[0];
  3361. } */
  3362. isHold = true;
  3363. } else {
  3364. var i = iterationIndex;
  3365. var len = kf.length - 1;
  3366. var flag = true;
  3367. var keyData;
  3368. var nextKeyData;
  3369. var keyframeMetadata;
  3370. while (flag) {
  3371. keyData = kf[i];
  3372. nextKeyData = kf[i + 1];
  3373. if ((nextKeyData.t - this.offsetTime) > frameNum) {
  3374. break;
  3375. }
  3376. if (i < len - 1) {
  3377. i += 1;
  3378. } else {
  3379. flag = false;
  3380. }
  3381. }
  3382. keyframeMetadata = this.keyframesMetadata[i] || {};
  3383. isHold = keyData.h === 1;
  3384. iterationIndex = i;
  3385. if (!isHold) {
  3386. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3387. perc = 1;
  3388. } else if (frameNum < keyData.t - this.offsetTime) {
  3389. perc = 0;
  3390. } else {
  3391. var fnc;
  3392. if (keyframeMetadata.__fnct) {
  3393. fnc = keyframeMetadata.__fnct;
  3394. } else {
  3395. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3396. keyframeMetadata.__fnct = fnc;
  3397. }
  3398. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / ((nextKeyData.t - this.offsetTime) - (keyData.t - this.offsetTime)));
  3399. }
  3400. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3401. }
  3402. keyPropS = keyData.s[0];
  3403. }
  3404. jLen = previousValue._length;
  3405. kLen = keyPropS.i[0].length;
  3406. caching.lastIndex = iterationIndex;
  3407. for (j = 0; j < jLen; j += 1) {
  3408. for (k = 0; k < kLen; k += 1) {
  3409. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3410. previousValue.i[j][k] = vertexValue;
  3411. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3412. previousValue.o[j][k] = vertexValue;
  3413. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3414. previousValue.v[j][k] = vertexValue;
  3415. }
  3416. }
  3417. }
  3418. function interpolateShapeCurrentTime() {
  3419. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3420. var initTime = this.keyframes[0].t - this.offsetTime;
  3421. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3422. var lastFrame = this._caching.lastFrame;
  3423. if (!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))) {
  3424. /// /
  3425. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3426. this.interpolateShape(frameNum, this.pv, this._caching);
  3427. /// /
  3428. }
  3429. this._caching.lastFrame = frameNum;
  3430. return this.pv;
  3431. }
  3432. function resetShape() {
  3433. this.paths = this.localShapeCollection;
  3434. }
  3435. function shapesEqual(shape1, shape2) {
  3436. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3437. return false;
  3438. }
  3439. var i;
  3440. var len = shape1._length;
  3441. for (i = 0; i < len; i += 1) {
  3442. if (shape1.v[i][0] !== shape2.v[i][0]
  3443. || shape1.v[i][1] !== shape2.v[i][1]
  3444. || shape1.o[i][0] !== shape2.o[i][0]
  3445. || shape1.o[i][1] !== shape2.o[i][1]
  3446. || shape1.i[i][0] !== shape2.i[i][0]
  3447. || shape1.i[i][1] !== shape2.i[i][1]) {
  3448. return false;
  3449. }
  3450. }
  3451. return true;
  3452. }
  3453. function setVValue(newPath) {
  3454. if (!shapesEqual(this.v, newPath)) {
  3455. this.v = shapePool.clone(newPath);
  3456. this.localShapeCollection.releaseShapes();
  3457. this.localShapeCollection.addShape(this.v);
  3458. this._mdf = true;
  3459. this.paths = this.localShapeCollection;
  3460. }
  3461. }
  3462. function processEffectsSequence() {
  3463. if (this.elem.globalData.frameId === this.frameId) {
  3464. return;
  3465. } if (!this.effectsSequence.length) {
  3466. this._mdf = false;
  3467. return;
  3468. }
  3469. if (this.lock) {
  3470. this.setVValue(this.pv);
  3471. return;
  3472. }
  3473. this.lock = true;
  3474. this._mdf = false;
  3475. var finalValue;
  3476. if (this.kf) {
  3477. finalValue = this.pv;
  3478. } else if (this.data.ks) {
  3479. finalValue = this.data.ks.k;
  3480. } else {
  3481. finalValue = this.data.pt.k;
  3482. }
  3483. var i;
  3484. var len = this.effectsSequence.length;
  3485. for (i = 0; i < len; i += 1) {
  3486. finalValue = this.effectsSequence[i](finalValue);
  3487. }
  3488. this.setVValue(finalValue);
  3489. this.lock = false;
  3490. this.frameId = this.elem.globalData.frameId;
  3491. }
  3492. function ShapeProperty(elem, data, type) {
  3493. this.propType = 'shape';
  3494. this.comp = elem.comp;
  3495. this.container = elem;
  3496. this.elem = elem;
  3497. this.data = data;
  3498. this.k = false;
  3499. this.kf = false;
  3500. this._mdf = false;
  3501. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3502. this.v = shapePool.clone(pathData);
  3503. this.pv = shapePool.clone(this.v);
  3504. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3505. this.paths = this.localShapeCollection;
  3506. this.paths.addShape(this.v);
  3507. this.reset = resetShape;
  3508. this.effectsSequence = [];
  3509. }
  3510. function addEffect(effectFunction) {
  3511. this.effectsSequence.push(effectFunction);
  3512. this.container.addDynamicProperty(this);
  3513. }
  3514. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3515. ShapeProperty.prototype.getValue = processEffectsSequence;
  3516. ShapeProperty.prototype.setVValue = setVValue;
  3517. ShapeProperty.prototype.addEffect = addEffect;
  3518. function KeyframedShapeProperty(elem, data, type) {
  3519. this.propType = 'shape';
  3520. this.comp = elem.comp;
  3521. this.elem = elem;
  3522. this.container = elem;
  3523. this.offsetTime = elem.data.st;
  3524. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3525. this.keyframesMetadata = [];
  3526. this.k = true;
  3527. this.kf = true;
  3528. var len = this.keyframes[0].s[0].i.length;
  3529. this.v = shapePool.newElement();
  3530. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3531. this.pv = shapePool.clone(this.v);
  3532. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3533. this.paths = this.localShapeCollection;
  3534. this.paths.addShape(this.v);
  3535. this.lastFrame = initFrame;
  3536. this.reset = resetShape;
  3537. this._caching = { lastFrame: initFrame, lastIndex: 0 };
  3538. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3539. }
  3540. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3541. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3542. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3543. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3544. var EllShapeProperty = (function () {
  3545. var cPoint = roundCorner;
  3546. function EllShapePropertyFactory(elem, data) {
  3547. this.v = shapePool.newElement();
  3548. this.v.setPathData(true, 4);
  3549. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3550. this.paths = this.localShapeCollection;
  3551. this.localShapeCollection.addShape(this.v);
  3552. this.d = data.d;
  3553. this.elem = elem;
  3554. this.comp = elem.comp;
  3555. this.frameId = -1;
  3556. this.initDynamicPropertyContainer(elem);
  3557. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3558. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3559. if (this.dynamicProperties.length) {
  3560. this.k = true;
  3561. } else {
  3562. this.k = false;
  3563. this.convertEllToPath();
  3564. }
  3565. }
  3566. EllShapePropertyFactory.prototype = {
  3567. reset: resetShape,
  3568. getValue: function () {
  3569. if (this.elem.globalData.frameId === this.frameId) {
  3570. return;
  3571. }
  3572. this.frameId = this.elem.globalData.frameId;
  3573. this.iterateDynamicProperties();
  3574. if (this._mdf) {
  3575. this.convertEllToPath();
  3576. }
  3577. },
  3578. convertEllToPath: function () {
  3579. var p0 = this.p.v[0];
  3580. var p1 = this.p.v[1];
  3581. var s0 = this.s.v[0] / 2;
  3582. var s1 = this.s.v[1] / 2;
  3583. var _cw = this.d !== 3;
  3584. var _v = this.v;
  3585. _v.v[0][0] = p0;
  3586. _v.v[0][1] = p1 - s1;
  3587. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3588. _v.v[1][1] = p1;
  3589. _v.v[2][0] = p0;
  3590. _v.v[2][1] = p1 + s1;
  3591. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3592. _v.v[3][1] = p1;
  3593. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3594. _v.i[0][1] = p1 - s1;
  3595. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3596. _v.i[1][1] = p1 - s1 * cPoint;
  3597. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3598. _v.i[2][1] = p1 + s1;
  3599. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3600. _v.i[3][1] = p1 + s1 * cPoint;
  3601. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3602. _v.o[0][1] = p1 - s1;
  3603. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3604. _v.o[1][1] = p1 + s1 * cPoint;
  3605. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3606. _v.o[2][1] = p1 + s1;
  3607. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3608. _v.o[3][1] = p1 - s1 * cPoint;
  3609. },
  3610. };
  3611. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3612. return EllShapePropertyFactory;
  3613. }());
  3614. var StarShapeProperty = (function () {
  3615. function StarShapePropertyFactory(elem, data) {
  3616. this.v = shapePool.newElement();
  3617. this.v.setPathData(true, 0);
  3618. this.elem = elem;
  3619. this.comp = elem.comp;
  3620. this.data = data;
  3621. this.frameId = -1;
  3622. this.d = data.d;
  3623. this.initDynamicPropertyContainer(elem);
  3624. if (data.sy === 1) {
  3625. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3626. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3627. this.convertToPath = this.convertStarToPath;
  3628. } else {
  3629. this.convertToPath = this.convertPolygonToPath;
  3630. }
  3631. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3632. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3633. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3634. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3635. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3636. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3637. this.localShapeCollection.addShape(this.v);
  3638. this.paths = this.localShapeCollection;
  3639. if (this.dynamicProperties.length) {
  3640. this.k = true;
  3641. } else {
  3642. this.k = false;
  3643. this.convertToPath();
  3644. }
  3645. }
  3646. StarShapePropertyFactory.prototype = {
  3647. reset: resetShape,
  3648. getValue: function () {
  3649. if (this.elem.globalData.frameId === this.frameId) {
  3650. return;
  3651. }
  3652. this.frameId = this.elem.globalData.frameId;
  3653. this.iterateDynamicProperties();
  3654. if (this._mdf) {
  3655. this.convertToPath();
  3656. }
  3657. },
  3658. convertStarToPath: function () {
  3659. var numPts = Math.floor(this.pt.v) * 2;
  3660. var angle = (Math.PI * 2) / numPts;
  3661. /* this.v.v.length = numPts;
  3662. this.v.i.length = numPts;
  3663. this.v.o.length = numPts; */
  3664. var longFlag = true;
  3665. var longRad = this.or.v;
  3666. var shortRad = this.ir.v;
  3667. var longRound = this.os.v;
  3668. var shortRound = this.is.v;
  3669. var longPerimSegment = (2 * Math.PI * longRad) / (numPts * 2);
  3670. var shortPerimSegment = (2 * Math.PI * shortRad) / (numPts * 2);
  3671. var i;
  3672. var rad;
  3673. var roundness;
  3674. var perimSegment;
  3675. var currentAng = -Math.PI / 2;
  3676. currentAng += this.r.v;
  3677. var dir = this.data.d === 3 ? -1 : 1;
  3678. this.v._length = 0;
  3679. for (i = 0; i < numPts; i += 1) {
  3680. rad = longFlag ? longRad : shortRad;
  3681. roundness = longFlag ? longRound : shortRound;
  3682. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3683. var x = rad * Math.cos(currentAng);
  3684. var y = rad * Math.sin(currentAng);
  3685. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3686. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3687. x += +this.p.v[0];
  3688. y += +this.p.v[1];
  3689. this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
  3690. /* this.v.v[i] = [x,y];
  3691. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3692. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3693. this.v._length = numPts; */
  3694. longFlag = !longFlag;
  3695. currentAng += angle * dir;
  3696. }
  3697. },
  3698. convertPolygonToPath: function () {
  3699. var numPts = Math.floor(this.pt.v);
  3700. var angle = (Math.PI * 2) / numPts;
  3701. var rad = this.or.v;
  3702. var roundness = this.os.v;
  3703. var perimSegment = (2 * Math.PI * rad) / (numPts * 4);
  3704. var i;
  3705. var currentAng = -Math.PI * 0.5;
  3706. var dir = this.data.d === 3 ? -1 : 1;
  3707. currentAng += this.r.v;
  3708. this.v._length = 0;
  3709. for (i = 0; i < numPts; i += 1) {
  3710. var x = rad * Math.cos(currentAng);
  3711. var y = rad * Math.sin(currentAng);
  3712. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3713. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3714. x += +this.p.v[0];
  3715. y += +this.p.v[1];
  3716. this.v.setTripleAt(x, y, x - ox * perimSegment * roundness * dir, y - oy * perimSegment * roundness * dir, x + ox * perimSegment * roundness * dir, y + oy * perimSegment * roundness * dir, i, true);
  3717. currentAng += angle * dir;
  3718. }
  3719. this.paths.length = 0;
  3720. this.paths[0] = this.v;
  3721. },
  3722. };
  3723. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3724. return StarShapePropertyFactory;
  3725. }());
  3726. var RectShapeProperty = (function () {
  3727. function RectShapePropertyFactory(elem, data) {
  3728. this.v = shapePool.newElement();
  3729. this.v.c = true;
  3730. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3731. this.localShapeCollection.addShape(this.v);
  3732. this.paths = this.localShapeCollection;
  3733. this.elem = elem;
  3734. this.comp = elem.comp;
  3735. this.frameId = -1;
  3736. this.d = data.d;
  3737. this.initDynamicPropertyContainer(elem);
  3738. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3739. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3740. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3741. if (this.dynamicProperties.length) {
  3742. this.k = true;
  3743. } else {
  3744. this.k = false;
  3745. this.convertRectToPath();
  3746. }
  3747. }
  3748. RectShapePropertyFactory.prototype = {
  3749. convertRectToPath: function () {
  3750. var p0 = this.p.v[0];
  3751. var p1 = this.p.v[1];
  3752. var v0 = this.s.v[0] / 2;
  3753. var v1 = this.s.v[1] / 2;
  3754. var round = bmMin(v0, v1, this.r.v);
  3755. var cPoint = round * (1 - roundCorner);
  3756. this.v._length = 0;
  3757. if (this.d === 2 || this.d === 1) {
  3758. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3759. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3760. if (round !== 0) {
  3761. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3762. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3763. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3764. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3765. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3766. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3767. } else {
  3768. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3769. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3770. }
  3771. } else {
  3772. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3773. if (round !== 0) {
  3774. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3775. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3776. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3777. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3778. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3779. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3780. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3781. } else {
  3782. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3783. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3784. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3785. }
  3786. }
  3787. },
  3788. getValue: function () {
  3789. if (this.elem.globalData.frameId === this.frameId) {
  3790. return;
  3791. }
  3792. this.frameId = this.elem.globalData.frameId;
  3793. this.iterateDynamicProperties();
  3794. if (this._mdf) {
  3795. this.convertRectToPath();
  3796. }
  3797. },
  3798. reset: resetShape,
  3799. };
  3800. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3801. return RectShapePropertyFactory;
  3802. }());
  3803. function getShapeProp(elem, data, type) {
  3804. var prop;
  3805. if (type === 3 || type === 4) {
  3806. var dataProp = type === 3 ? data.pt : data.ks;
  3807. var keys = dataProp.k;
  3808. if (keys.length) {
  3809. prop = new KeyframedShapeProperty(elem, data, type);
  3810. } else {
  3811. prop = new ShapeProperty(elem, data, type);
  3812. }
  3813. } else if (type === 5) {
  3814. prop = new RectShapeProperty(elem, data);
  3815. } else if (type === 6) {
  3816. prop = new EllShapeProperty(elem, data);
  3817. } else if (type === 7) {
  3818. prop = new StarShapeProperty(elem, data);
  3819. }
  3820. if (prop.k) {
  3821. elem.addDynamicProperty(prop);
  3822. }
  3823. return prop;
  3824. }
  3825. function getConstructorFunction() {
  3826. return ShapeProperty;
  3827. }
  3828. function getKeyframedConstructorFunction() {
  3829. return KeyframedShapeProperty;
  3830. }
  3831. var ob = {};
  3832. ob.getShapeProp = getShapeProp;
  3833. ob.getConstructorFunction = getConstructorFunction;
  3834. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3835. return ob;
  3836. }());
  3837. /*!
  3838. Transformation Matrix v2.0
  3839. (c) Epistemex 2014-2015
  3840. www.epistemex.com
  3841. By Ken Fyrstenberg
  3842. Contributions by leeoniya.
  3843. License: MIT, header required.
  3844. */
  3845. /**
  3846. * 2D transformation matrix object initialized with identity matrix.
  3847. *
  3848. * The matrix can synchronize a canvas context by supplying the context
  3849. * as an argument, or later apply current absolute transform to an
  3850. * existing context.
  3851. *
  3852. * All values are handled as floating point values.
  3853. *
  3854. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3855. * @prop {number} a - scale x
  3856. * @prop {number} b - shear y
  3857. * @prop {number} c - shear x
  3858. * @prop {number} d - scale y
  3859. * @prop {number} e - translate x
  3860. * @prop {number} f - translate y
  3861. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3862. * @constructor
  3863. */
  3864. const Matrix = (function () {
  3865. var _cos = Math.cos;
  3866. var _sin = Math.sin;
  3867. var _tan = Math.tan;
  3868. var _rnd = Math.round;
  3869. function reset() {
  3870. this.props[0] = 1;
  3871. this.props[1] = 0;
  3872. this.props[2] = 0;
  3873. this.props[3] = 0;
  3874. this.props[4] = 0;
  3875. this.props[5] = 1;
  3876. this.props[6] = 0;
  3877. this.props[7] = 0;
  3878. this.props[8] = 0;
  3879. this.props[9] = 0;
  3880. this.props[10] = 1;
  3881. this.props[11] = 0;
  3882. this.props[12] = 0;
  3883. this.props[13] = 0;
  3884. this.props[14] = 0;
  3885. this.props[15] = 1;
  3886. return this;
  3887. }
  3888. function rotate(angle) {
  3889. if (angle === 0) {
  3890. return this;
  3891. }
  3892. var mCos = _cos(angle);
  3893. var mSin = _sin(angle);
  3894. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3895. }
  3896. function rotateX(angle) {
  3897. if (angle === 0) {
  3898. return this;
  3899. }
  3900. var mCos = _cos(angle);
  3901. var mSin = _sin(angle);
  3902. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3903. }
  3904. function rotateY(angle) {
  3905. if (angle === 0) {
  3906. return this;
  3907. }
  3908. var mCos = _cos(angle);
  3909. var mSin = _sin(angle);
  3910. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3911. }
  3912. function rotateZ(angle) {
  3913. if (angle === 0) {
  3914. return this;
  3915. }
  3916. var mCos = _cos(angle);
  3917. var mSin = _sin(angle);
  3918. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3919. }
  3920. function shear(sx, sy) {
  3921. return this._t(1, sy, sx, 1, 0, 0);
  3922. }
  3923. function skew(ax, ay) {
  3924. return this.shear(_tan(ax), _tan(ay));
  3925. }
  3926. function skewFromAxis(ax, angle) {
  3927. var mCos = _cos(angle);
  3928. var mSin = _sin(angle);
  3929. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3930. ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3931. ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3932. // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  3933. }
  3934. function scale(sx, sy, sz) {
  3935. if (!sz && sz !== 0) {
  3936. sz = 1;
  3937. }
  3938. if (sx === 1 && sy === 1 && sz === 1) {
  3939. return this;
  3940. }
  3941. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  3942. }
  3943. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  3944. this.props[0] = a;
  3945. this.props[1] = b;
  3946. this.props[2] = c;
  3947. this.props[3] = d;
  3948. this.props[4] = e;
  3949. this.props[5] = f;
  3950. this.props[6] = g;
  3951. this.props[7] = h;
  3952. this.props[8] = i;
  3953. this.props[9] = j;
  3954. this.props[10] = k;
  3955. this.props[11] = l;
  3956. this.props[12] = m;
  3957. this.props[13] = n;
  3958. this.props[14] = o;
  3959. this.props[15] = p;
  3960. return this;
  3961. }
  3962. function translate(tx, ty, tz) {
  3963. tz = tz || 0;
  3964. if (tx !== 0 || ty !== 0 || tz !== 0) {
  3965. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  3966. }
  3967. return this;
  3968. }
  3969. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  3970. var _p = this.props;
  3971. if (a2 === 1 && b2 === 0 && c2 === 0 && d2 === 0 && e2 === 0 && f2 === 1 && g2 === 0 && h2 === 0 && i2 === 0 && j2 === 0 && k2 === 1 && l2 === 0) {
  3972. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  3973. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  3974. _p[12] = _p[12] * a2 + _p[15] * m2;
  3975. _p[13] = _p[13] * f2 + _p[15] * n2;
  3976. _p[14] = _p[14] * k2 + _p[15] * o2;
  3977. _p[15] *= p2;
  3978. // }
  3979. this._identityCalculated = false;
  3980. return this;
  3981. }
  3982. var a1 = _p[0];
  3983. var b1 = _p[1];
  3984. var c1 = _p[2];
  3985. var d1 = _p[3];
  3986. var e1 = _p[4];
  3987. var f1 = _p[5];
  3988. var g1 = _p[6];
  3989. var h1 = _p[7];
  3990. var i1 = _p[8];
  3991. var j1 = _p[9];
  3992. var k1 = _p[10];
  3993. var l1 = _p[11];
  3994. var m1 = _p[12];
  3995. var n1 = _p[13];
  3996. var o1 = _p[14];
  3997. var p1 = _p[15];
  3998. /* matrix order (canvas compatible):
  3999. * ace
  4000. * bdf
  4001. * 001
  4002. */
  4003. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  4004. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  4005. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  4006. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  4007. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  4008. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  4009. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  4010. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  4011. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  4012. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  4013. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  4014. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  4015. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  4016. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  4017. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  4018. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  4019. this._identityCalculated = false;
  4020. return this;
  4021. }
  4022. function multiply(matrix) {
  4023. var matrixProps = matrix.props;
  4024. return this.transform(
  4025. matrixProps[0],
  4026. matrixProps[1],
  4027. matrixProps[2],
  4028. matrixProps[3],
  4029. matrixProps[4],
  4030. matrixProps[5],
  4031. matrixProps[6],
  4032. matrixProps[7],
  4033. matrixProps[8],
  4034. matrixProps[9],
  4035. matrixProps[10],
  4036. matrixProps[11],
  4037. matrixProps[12],
  4038. matrixProps[13],
  4039. matrixProps[14],
  4040. matrixProps[15]
  4041. );
  4042. }
  4043. function isIdentity() {
  4044. if (!this._identityCalculated) {
  4045. this._identity = !(this.props[0] !== 1 || this.props[1] !== 0 || this.props[2] !== 0 || this.props[3] !== 0 || this.props[4] !== 0 || this.props[5] !== 1 || this.props[6] !== 0 || this.props[7] !== 0 || this.props[8] !== 0 || this.props[9] !== 0 || this.props[10] !== 1 || this.props[11] !== 0 || this.props[12] !== 0 || this.props[13] !== 0 || this.props[14] !== 0 || this.props[15] !== 1);
  4046. this._identityCalculated = true;
  4047. }
  4048. return this._identity;
  4049. }
  4050. function equals(matr) {
  4051. var i = 0;
  4052. while (i < 16) {
  4053. if (matr.props[i] !== this.props[i]) {
  4054. return false;
  4055. }
  4056. i += 1;
  4057. }
  4058. return true;
  4059. }
  4060. function clone(matr) {
  4061. var i;
  4062. for (i = 0; i < 16; i += 1) {
  4063. matr.props[i] = this.props[i];
  4064. }
  4065. return matr;
  4066. }
  4067. function cloneFromProps(props) {
  4068. var i;
  4069. for (i = 0; i < 16; i += 1) {
  4070. this.props[i] = props[i];
  4071. }
  4072. }
  4073. function applyToPoint(x, y, z) {
  4074. return {
  4075. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4076. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4077. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4078. };
  4079. /* return {
  4080. x: x * me.a + y * me.c + me.e,
  4081. y: x * me.b + y * me.d + me.f
  4082. }; */
  4083. }
  4084. function applyToX(x, y, z) {
  4085. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4086. }
  4087. function applyToY(x, y, z) {
  4088. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4089. }
  4090. function applyToZ(x, y, z) {
  4091. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4092. }
  4093. function getInverseMatrix() {
  4094. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4095. var a = this.props[5] / determinant;
  4096. var b = -this.props[1] / determinant;
  4097. var c = -this.props[4] / determinant;
  4098. var d = this.props[0] / determinant;
  4099. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4100. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4101. var inverseMatrix = new Matrix();
  4102. inverseMatrix.props[0] = a;
  4103. inverseMatrix.props[1] = b;
  4104. inverseMatrix.props[4] = c;
  4105. inverseMatrix.props[5] = d;
  4106. inverseMatrix.props[12] = e;
  4107. inverseMatrix.props[13] = f;
  4108. return inverseMatrix;
  4109. }
  4110. function inversePoint(pt) {
  4111. var inverseMatrix = this.getInverseMatrix();
  4112. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4113. }
  4114. function inversePoints(pts) {
  4115. var i;
  4116. var len = pts.length;
  4117. var retPts = [];
  4118. for (i = 0; i < len; i += 1) {
  4119. retPts[i] = inversePoint(pts[i]);
  4120. }
  4121. return retPts;
  4122. }
  4123. function applyToTriplePoints(pt1, pt2, pt3) {
  4124. var arr = createTypedArray('float32', 6);
  4125. if (this.isIdentity()) {
  4126. arr[0] = pt1[0];
  4127. arr[1] = pt1[1];
  4128. arr[2] = pt2[0];
  4129. arr[3] = pt2[1];
  4130. arr[4] = pt3[0];
  4131. arr[5] = pt3[1];
  4132. } else {
  4133. var p0 = this.props[0];
  4134. var p1 = this.props[1];
  4135. var p4 = this.props[4];
  4136. var p5 = this.props[5];
  4137. var p12 = this.props[12];
  4138. var p13 = this.props[13];
  4139. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4140. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4141. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4142. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4143. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4144. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4145. }
  4146. return arr;
  4147. }
  4148. function applyToPointArray(x, y, z) {
  4149. var arr;
  4150. if (this.isIdentity()) {
  4151. arr = [x, y, z];
  4152. } else {
  4153. arr = [
  4154. x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4155. x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4156. x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4157. ];
  4158. }
  4159. return arr;
  4160. }
  4161. function applyToPointStringified(x, y) {
  4162. if (this.isIdentity()) {
  4163. return x + ',' + y;
  4164. }
  4165. var _p = this.props;
  4166. return Math.round((x * _p[0] + y * _p[4] + _p[12]) * 100) / 100 + ',' + Math.round((x * _p[1] + y * _p[5] + _p[13]) * 100) / 100;
  4167. }
  4168. function toCSS() {
  4169. // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed.
  4170. /* if(this.isIdentity()) {
  4171. return '';
  4172. } */
  4173. var i = 0;
  4174. var props = this.props;
  4175. var cssValue = 'matrix3d(';
  4176. var v = 10000;
  4177. while (i < 16) {
  4178. cssValue += _rnd(props[i] * v) / v;
  4179. cssValue += i === 15 ? ')' : ',';
  4180. i += 1;
  4181. }
  4182. return cssValue;
  4183. }
  4184. function roundMatrixProperty(val) {
  4185. var v = 10000;
  4186. if ((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
  4187. return _rnd(val * v) / v;
  4188. }
  4189. return val;
  4190. }
  4191. function to2dCSS() {
  4192. // Doesn't make much sense to add this optimization. If it is an identity matrix, it's very likely this will get called only once since it won't be keyframed.
  4193. /* if(this.isIdentity()) {
  4194. return '';
  4195. } */
  4196. var props = this.props;
  4197. var _a = roundMatrixProperty(props[0]);
  4198. var _b = roundMatrixProperty(props[1]);
  4199. var _c = roundMatrixProperty(props[4]);
  4200. var _d = roundMatrixProperty(props[5]);
  4201. var _e = roundMatrixProperty(props[12]);
  4202. var _f = roundMatrixProperty(props[13]);
  4203. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4204. }
  4205. return function () {
  4206. this.reset = reset;
  4207. this.rotate = rotate;
  4208. this.rotateX = rotateX;
  4209. this.rotateY = rotateY;
  4210. this.rotateZ = rotateZ;
  4211. this.skew = skew;
  4212. this.skewFromAxis = skewFromAxis;
  4213. this.shear = shear;
  4214. this.scale = scale;
  4215. this.setTransform = setTransform;
  4216. this.translate = translate;
  4217. this.transform = transform;
  4218. this.multiply = multiply;
  4219. this.applyToPoint = applyToPoint;
  4220. this.applyToX = applyToX;
  4221. this.applyToY = applyToY;
  4222. this.applyToZ = applyToZ;
  4223. this.applyToPointArray = applyToPointArray;
  4224. this.applyToTriplePoints = applyToTriplePoints;
  4225. this.applyToPointStringified = applyToPointStringified;
  4226. this.toCSS = toCSS;
  4227. this.to2dCSS = to2dCSS;
  4228. this.clone = clone;
  4229. this.cloneFromProps = cloneFromProps;
  4230. this.equals = equals;
  4231. this.inversePoints = inversePoints;
  4232. this.inversePoint = inversePoint;
  4233. this.getInverseMatrix = getInverseMatrix;
  4234. this._t = this.transform;
  4235. this.isIdentity = isIdentity;
  4236. this._identity = true;
  4237. this._identityCalculated = false;
  4238. this.props = createTypedArray('float32', 16);
  4239. this.reset();
  4240. };
  4241. }());
  4242. const lottie = {};
  4243. var standalone = '__[STANDALONE]__';
  4244. var animationData = '__[ANIMATIONDATA]__';
  4245. var renderer = '';
  4246. function setLocation(href) {
  4247. setLocationHref(href);
  4248. }
  4249. function searchAnimations() {
  4250. if (standalone === true) {
  4251. animationManager.searchAnimations(animationData, standalone, renderer);
  4252. } else {
  4253. animationManager.searchAnimations();
  4254. }
  4255. }
  4256. function setSubframeRendering(flag) {
  4257. setSubframeEnabled(flag);
  4258. }
  4259. function setPrefix(prefix) {
  4260. setIdPrefix(prefix);
  4261. }
  4262. function loadAnimation(params) {
  4263. if (standalone === true) {
  4264. params.animationData = JSON.parse(animationData);
  4265. }
  4266. return animationManager.loadAnimation(params);
  4267. }
  4268. function setQuality(value) {
  4269. if (typeof value === 'string') {
  4270. switch (value) {
  4271. case 'high':
  4272. setDefaultCurveSegments(200);
  4273. break;
  4274. default:
  4275. case 'medium':
  4276. setDefaultCurveSegments(50);
  4277. break;
  4278. case 'low':
  4279. setDefaultCurveSegments(10);
  4280. break;
  4281. }
  4282. } else if (!isNaN(value) && value > 1) {
  4283. setDefaultCurveSegments(value);
  4284. }
  4285. if (getDefaultCurveSegments() >= 50) {
  4286. roundValues(false);
  4287. } else {
  4288. roundValues(true);
  4289. }
  4290. }
  4291. function inBrowser() {
  4292. return typeof navigator !== 'undefined';
  4293. }
  4294. function installPlugin(type, plugin) {
  4295. if (type === 'expressions') {
  4296. setExpressionsPlugin(plugin);
  4297. }
  4298. }
  4299. function getFactory(name) {
  4300. switch (name) {
  4301. case 'propertyFactory':
  4302. return PropertyFactory;
  4303. case 'shapePropertyFactory':
  4304. return ShapePropertyFactory;
  4305. case 'matrix':
  4306. return Matrix;
  4307. default:
  4308. return null;
  4309. }
  4310. }
  4311. lottie.play = animationManager.play;
  4312. lottie.pause = animationManager.pause;
  4313. lottie.setLocationHref = setLocation;
  4314. lottie.togglePause = animationManager.togglePause;
  4315. lottie.setSpeed = animationManager.setSpeed;
  4316. lottie.setDirection = animationManager.setDirection;
  4317. lottie.stop = animationManager.stop;
  4318. lottie.searchAnimations = searchAnimations;
  4319. lottie.registerAnimation = animationManager.registerAnimation;
  4320. lottie.loadAnimation = loadAnimation;
  4321. lottie.setSubframeRendering = setSubframeRendering;
  4322. lottie.resize = animationManager.resize;
  4323. // lottie.start = start;
  4324. lottie.goToAndStop = animationManager.goToAndStop;
  4325. lottie.destroy = animationManager.destroy;
  4326. lottie.setQuality = setQuality;
  4327. lottie.inBrowser = inBrowser;
  4328. lottie.installPlugin = installPlugin;
  4329. lottie.freeze = animationManager.freeze;
  4330. lottie.unfreeze = animationManager.unfreeze;
  4331. lottie.setVolume = animationManager.setVolume;
  4332. lottie.mute = animationManager.mute;
  4333. lottie.unmute = animationManager.unmute;
  4334. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4335. lottie.useWebWorker = setWebWorker;
  4336. lottie.setIDPrefix = setPrefix;
  4337. lottie.__getFactory = getFactory;
  4338. lottie.version = '[[BM_VERSION]]';
  4339. function checkReady() {
  4340. if (document.readyState === 'complete') {
  4341. clearInterval(readyStateCheckInterval);
  4342. searchAnimations();
  4343. }
  4344. }
  4345. function getQueryVariable(variable) {
  4346. var vars = queryString.split('&');
  4347. for (var i = 0; i < vars.length; i += 1) {
  4348. var pair = vars[i].split('=');
  4349. if (decodeURIComponent(pair[0]) == variable) { // eslint-disable-line eqeqeq
  4350. return decodeURIComponent(pair[1]);
  4351. }
  4352. }
  4353. return null;
  4354. }
  4355. var queryString = '';
  4356. if (standalone) {
  4357. var scripts = document.getElementsByTagName('script');
  4358. var index = scripts.length - 1;
  4359. var myScript = scripts[index] || {
  4360. src: '',
  4361. };
  4362. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4363. renderer = getQueryVariable('renderer');
  4364. }
  4365. var readyStateCheckInterval = setInterval(checkReady, 100);
  4366. // this adds bodymovin to the window object for backwards compatibility
  4367. try {
  4368. if (!(typeof exports === 'object' && typeof module !== 'undefined')
  4369. && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4370. ) {
  4371. window.bodymovin = lottie;
  4372. }
  4373. } catch (err) {
  4374. //
  4375. }
  4376. const ShapeModifiers = (function () {
  4377. var ob = {};
  4378. var modifiers = {};
  4379. ob.registerModifier = registerModifier;
  4380. ob.getModifier = getModifier;
  4381. function registerModifier(nm, factory) {
  4382. if (!modifiers[nm]) {
  4383. modifiers[nm] = factory;
  4384. }
  4385. }
  4386. function getModifier(nm, elem, data) {
  4387. return new modifiers[nm](elem, data);
  4388. }
  4389. return ob;
  4390. }());
  4391. function ShapeModifier() {}
  4392. ShapeModifier.prototype.initModifierProperties = function () {};
  4393. ShapeModifier.prototype.addShapeToModifier = function () {};
  4394. ShapeModifier.prototype.addShape = function (data) {
  4395. if (!this.closed) {
  4396. // Adding shape to dynamic properties. It covers the case where a shape has no effects applied, to reset it's _mdf state on every tick.
  4397. data.sh.container.addDynamicProperty(data.sh);
  4398. var shapeData = { shape: data.sh, data: data, localShapeCollection: shapeCollectionPool.newShapeCollection() };
  4399. this.shapes.push(shapeData);
  4400. this.addShapeToModifier(shapeData);
  4401. if (this._isAnimated) {
  4402. data.setAsAnimated();
  4403. }
  4404. }
  4405. };
  4406. ShapeModifier.prototype.init = function (elem, data) {
  4407. this.shapes = [];
  4408. this.elem = elem;
  4409. this.initDynamicPropertyContainer(elem);
  4410. this.initModifierProperties(elem, data);
  4411. this.frameId = initialDefaultFrame;
  4412. this.closed = false;
  4413. this.k = false;
  4414. if (this.dynamicProperties.length) {
  4415. this.k = true;
  4416. } else {
  4417. this.getValue(true);
  4418. }
  4419. };
  4420. ShapeModifier.prototype.processKeys = function () {
  4421. if (this.elem.globalData.frameId === this.frameId) {
  4422. return;
  4423. }
  4424. this.frameId = this.elem.globalData.frameId;
  4425. this.iterateDynamicProperties();
  4426. };
  4427. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4428. function TrimModifier() {
  4429. }
  4430. extendPrototype([ShapeModifier], TrimModifier);
  4431. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4432. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4433. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4434. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4435. this.sValue = 0;
  4436. this.eValue = 0;
  4437. this.getValue = this.processKeys;
  4438. this.m = data.m;
  4439. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4440. };
  4441. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4442. shapeData.pathsData = [];
  4443. };
  4444. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4445. var segments = [];
  4446. if (e <= 1) {
  4447. segments.push({
  4448. s: s,
  4449. e: e,
  4450. });
  4451. } else if (s >= 1) {
  4452. segments.push({
  4453. s: s - 1,
  4454. e: e - 1,
  4455. });
  4456. } else {
  4457. segments.push({
  4458. s: s,
  4459. e: 1,
  4460. });
  4461. segments.push({
  4462. s: 0,
  4463. e: e - 1,
  4464. });
  4465. }
  4466. var shapeSegments = [];
  4467. var i;
  4468. var len = segments.length;
  4469. var segmentOb;
  4470. for (i = 0; i < len; i += 1) {
  4471. segmentOb = segments[i];
  4472. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4473. var shapeS;
  4474. var shapeE;
  4475. if (segmentOb.s * totalModifierLength <= addedLength) {
  4476. shapeS = 0;
  4477. } else {
  4478. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4479. }
  4480. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4481. shapeE = 1;
  4482. } else {
  4483. shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength);
  4484. }
  4485. shapeSegments.push([shapeS, shapeE]);
  4486. }
  4487. }
  4488. if (!shapeSegments.length) {
  4489. shapeSegments.push([0, 0]);
  4490. }
  4491. return shapeSegments;
  4492. };
  4493. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4494. var i;
  4495. var len = pathsData.length;
  4496. for (i = 0; i < len; i += 1) {
  4497. segmentsLengthPool.release(pathsData[i]);
  4498. }
  4499. pathsData.length = 0;
  4500. return pathsData;
  4501. };
  4502. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4503. var s;
  4504. var e;
  4505. if (this._mdf || _isFirstFrame) {
  4506. var o = (this.o.v % 360) / 360;
  4507. if (o < 0) {
  4508. o += 1;
  4509. }
  4510. if (this.s.v > 1) {
  4511. s = 1 + o;
  4512. } else if (this.s.v < 0) {
  4513. s = 0 + o;
  4514. } else {
  4515. s = this.s.v + o;
  4516. }
  4517. if (this.e.v > 1) {
  4518. e = 1 + o;
  4519. } else if (this.e.v < 0) {
  4520. e = 0 + o;
  4521. } else {
  4522. e = this.e.v + o;
  4523. }
  4524. if (s > e) {
  4525. var _s = s;
  4526. s = e;
  4527. e = _s;
  4528. }
  4529. s = Math.round(s * 10000) * 0.0001;
  4530. e = Math.round(e * 10000) * 0.0001;
  4531. this.sValue = s;
  4532. this.eValue = e;
  4533. } else {
  4534. s = this.sValue;
  4535. e = this.eValue;
  4536. }
  4537. var shapePaths;
  4538. var i;
  4539. var len = this.shapes.length;
  4540. var j;
  4541. var jLen;
  4542. var pathsData;
  4543. var pathData;
  4544. var totalShapeLength;
  4545. var totalModifierLength = 0;
  4546. if (e === s) {
  4547. for (i = 0; i < len; i += 1) {
  4548. this.shapes[i].localShapeCollection.releaseShapes();
  4549. this.shapes[i].shape._mdf = true;
  4550. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4551. if (this._mdf) {
  4552. this.shapes[i].pathsData.length = 0;
  4553. }
  4554. }
  4555. } else if (!((e === 1 && s === 0) || (e === 0 && s === 1))) {
  4556. var segments = [];
  4557. var shapeData;
  4558. var localShapeCollection;
  4559. for (i = 0; i < len; i += 1) {
  4560. shapeData = this.shapes[i];
  4561. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4562. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4563. shapeData.shape.paths = shapeData.localShapeCollection;
  4564. } else {
  4565. shapePaths = shapeData.shape.paths;
  4566. jLen = shapePaths._length;
  4567. totalShapeLength = 0;
  4568. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4569. totalShapeLength = shapeData.totalShapeLength;
  4570. } else {
  4571. pathsData = this.releasePathsData(shapeData.pathsData);
  4572. for (j = 0; j < jLen; j += 1) {
  4573. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4574. pathsData.push(pathData);
  4575. totalShapeLength += pathData.totalLength;
  4576. }
  4577. shapeData.totalShapeLength = totalShapeLength;
  4578. shapeData.pathsData = pathsData;
  4579. }
  4580. totalModifierLength += totalShapeLength;
  4581. shapeData.shape._mdf = true;
  4582. }
  4583. }
  4584. var shapeS = s;
  4585. var shapeE = e;
  4586. var addedLength = 0;
  4587. var edges;
  4588. for (i = len - 1; i >= 0; i -= 1) {
  4589. shapeData = this.shapes[i];
  4590. if (shapeData.shape._mdf) {
  4591. localShapeCollection = shapeData.localShapeCollection;
  4592. localShapeCollection.releaseShapes();
  4593. // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4594. if (this.m === 2 && len > 1) {
  4595. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4596. addedLength += shapeData.totalShapeLength;
  4597. } else {
  4598. edges = [[shapeS, shapeE]];
  4599. }
  4600. jLen = edges.length;
  4601. for (j = 0; j < jLen; j += 1) {
  4602. shapeS = edges[j][0];
  4603. shapeE = edges[j][1];
  4604. segments.length = 0;
  4605. if (shapeE <= 1) {
  4606. segments.push({
  4607. s: shapeData.totalShapeLength * shapeS,
  4608. e: shapeData.totalShapeLength * shapeE,
  4609. });
  4610. } else if (shapeS >= 1) {
  4611. segments.push({
  4612. s: shapeData.totalShapeLength * (shapeS - 1),
  4613. e: shapeData.totalShapeLength * (shapeE - 1),
  4614. });
  4615. } else {
  4616. segments.push({
  4617. s: shapeData.totalShapeLength * shapeS,
  4618. e: shapeData.totalShapeLength,
  4619. });
  4620. segments.push({
  4621. s: 0,
  4622. e: shapeData.totalShapeLength * (shapeE - 1),
  4623. });
  4624. }
  4625. var newShapesData = this.addShapes(shapeData, segments[0]);
  4626. if (segments[0].s !== segments[0].e) {
  4627. if (segments.length > 1) {
  4628. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4629. if (lastShapeInCollection.c) {
  4630. var lastShape = newShapesData.pop();
  4631. this.addPaths(newShapesData, localShapeCollection);
  4632. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4633. } else {
  4634. this.addPaths(newShapesData, localShapeCollection);
  4635. newShapesData = this.addShapes(shapeData, segments[1]);
  4636. }
  4637. }
  4638. this.addPaths(newShapesData, localShapeCollection);
  4639. }
  4640. }
  4641. shapeData.shape.paths = localShapeCollection;
  4642. }
  4643. }
  4644. } else if (this._mdf) {
  4645. for (i = 0; i < len; i += 1) {
  4646. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4647. // Don't remove this even if it's losing cached info.
  4648. this.shapes[i].pathsData.length = 0;
  4649. this.shapes[i].shape._mdf = true;
  4650. }
  4651. }
  4652. };
  4653. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4654. var i;
  4655. var len = newPaths.length;
  4656. for (i = 0; i < len; i += 1) {
  4657. localShapeCollection.addShape(newPaths[i]);
  4658. }
  4659. };
  4660. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4661. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4662. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4663. if (newShape) {
  4664. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4665. }
  4666. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4667. };
  4668. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4669. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4670. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4671. if (newShape) {
  4672. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4673. }
  4674. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4675. };
  4676. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4677. var pathsData = shapeData.pathsData;
  4678. var shapePaths = shapeData.shape.paths.shapes;
  4679. var i;
  4680. var len = shapeData.shape.paths._length;
  4681. var j;
  4682. var jLen;
  4683. var addedLength = 0;
  4684. var currentLengthData;
  4685. var segmentCount;
  4686. var lengths;
  4687. var segment;
  4688. var shapes = [];
  4689. var initPos;
  4690. var newShape = true;
  4691. if (!shapePath) {
  4692. shapePath = shapePool.newElement();
  4693. segmentCount = 0;
  4694. initPos = 0;
  4695. } else {
  4696. segmentCount = shapePath._length;
  4697. initPos = shapePath._length;
  4698. }
  4699. shapes.push(shapePath);
  4700. for (i = 0; i < len; i += 1) {
  4701. lengths = pathsData[i].lengths;
  4702. shapePath.c = shapePaths[i].c;
  4703. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4704. for (j = 1; j < jLen; j += 1) {
  4705. currentLengthData = lengths[j - 1];
  4706. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4707. addedLength += currentLengthData.addedLength;
  4708. shapePath.c = false;
  4709. } else if (addedLength > shapeSegment.e) {
  4710. shapePath.c = false;
  4711. break;
  4712. } else {
  4713. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4714. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4715. newShape = false;
  4716. } else {
  4717. segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[j], shapePaths[i].o[j - 1], shapePaths[i].i[j], (shapeSegment.s - addedLength) / currentLengthData.addedLength, (shapeSegment.e - addedLength) / currentLengthData.addedLength, lengths[j - 1]);
  4718. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4719. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4720. newShape = false;
  4721. shapePath.c = false;
  4722. }
  4723. addedLength += currentLengthData.addedLength;
  4724. segmentCount += 1;
  4725. }
  4726. }
  4727. if (shapePaths[i].c && lengths.length) {
  4728. currentLengthData = lengths[j - 1];
  4729. if (addedLength <= shapeSegment.e) {
  4730. var segmentLength = lengths[j - 1].addedLength;
  4731. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4732. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4733. newShape = false;
  4734. } else {
  4735. segment = bez.getNewSegment(shapePaths[i].v[j - 1], shapePaths[i].v[0], shapePaths[i].o[j - 1], shapePaths[i].i[0], (shapeSegment.s - addedLength) / segmentLength, (shapeSegment.e - addedLength) / segmentLength, lengths[j - 1]);
  4736. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4737. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4738. newShape = false;
  4739. shapePath.c = false;
  4740. }
  4741. } else {
  4742. shapePath.c = false;
  4743. }
  4744. addedLength += currentLengthData.addedLength;
  4745. segmentCount += 1;
  4746. }
  4747. if (shapePath._length) {
  4748. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4749. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4750. }
  4751. if (addedLength > shapeSegment.e) {
  4752. break;
  4753. }
  4754. if (i < len - 1) {
  4755. shapePath = shapePool.newElement();
  4756. newShape = true;
  4757. shapes.push(shapePath);
  4758. segmentCount = 0;
  4759. }
  4760. }
  4761. return shapes;
  4762. };
  4763. function PuckerAndBloatModifier() {}
  4764. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4765. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4766. this.getValue = this.processKeys;
  4767. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4768. this._isAnimated = !!this.amount.effectsSequence.length;
  4769. };
  4770. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4771. var percent = amount / 100;
  4772. var centerPoint = [0, 0];
  4773. var pathLength = path._length;
  4774. var i = 0;
  4775. for (i = 0; i < pathLength; i += 1) {
  4776. centerPoint[0] += path.v[i][0];
  4777. centerPoint[1] += path.v[i][1];
  4778. }
  4779. centerPoint[0] /= pathLength;
  4780. centerPoint[1] /= pathLength;
  4781. var clonedPath = shapePool.newElement();
  4782. clonedPath.c = path.c;
  4783. var vX;
  4784. var vY;
  4785. var oX;
  4786. var oY;
  4787. var iX;
  4788. var iY;
  4789. for (i = 0; i < pathLength; i += 1) {
  4790. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4791. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4792. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4793. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4794. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4795. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4796. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4797. }
  4798. return clonedPath;
  4799. };
  4800. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4801. var shapePaths;
  4802. var i;
  4803. var len = this.shapes.length;
  4804. var j;
  4805. var jLen;
  4806. var amount = this.amount.v;
  4807. if (amount !== 0) {
  4808. var shapeData;
  4809. var localShapeCollection;
  4810. for (i = 0; i < len; i += 1) {
  4811. shapeData = this.shapes[i];
  4812. localShapeCollection = shapeData.localShapeCollection;
  4813. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4814. localShapeCollection.releaseShapes();
  4815. shapeData.shape._mdf = true;
  4816. shapePaths = shapeData.shape.paths.shapes;
  4817. jLen = shapeData.shape.paths._length;
  4818. for (j = 0; j < jLen; j += 1) {
  4819. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4820. }
  4821. }
  4822. shapeData.shape.paths = shapeData.localShapeCollection;
  4823. }
  4824. }
  4825. if (!this.dynamicProperties.length) {
  4826. this._mdf = false;
  4827. }
  4828. };
  4829. const TransformPropertyFactory = (function () {
  4830. var defaultVector = [0, 0];
  4831. function applyToMatrix(mat) {
  4832. var _mdf = this._mdf;
  4833. this.iterateDynamicProperties();
  4834. this._mdf = this._mdf || _mdf;
  4835. if (this.a) {
  4836. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4837. }
  4838. if (this.s) {
  4839. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4840. }
  4841. if (this.sk) {
  4842. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4843. }
  4844. if (this.r) {
  4845. mat.rotate(-this.r.v);
  4846. } else {
  4847. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4848. .rotateY(this.or.v[1])
  4849. .rotateX(this.or.v[0]);
  4850. }
  4851. if (this.data.p.s) {
  4852. if (this.data.p.z) {
  4853. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4854. } else {
  4855. mat.translate(this.px.v, this.py.v, 0);
  4856. }
  4857. } else {
  4858. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4859. }
  4860. }
  4861. function processKeys(forceRender) {
  4862. if (this.elem.globalData.frameId === this.frameId) {
  4863. return;
  4864. }
  4865. if (this._isDirty) {
  4866. this.precalculateMatrix();
  4867. this._isDirty = false;
  4868. }
  4869. this.iterateDynamicProperties();
  4870. if (this._mdf || forceRender) {
  4871. var frameRate;
  4872. this.v.cloneFromProps(this.pre.props);
  4873. if (this.appliedTransformations < 1) {
  4874. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4875. }
  4876. if (this.appliedTransformations < 2) {
  4877. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4878. }
  4879. if (this.sk && this.appliedTransformations < 3) {
  4880. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4881. }
  4882. if (this.r && this.appliedTransformations < 4) {
  4883. this.v.rotate(-this.r.v);
  4884. } else if (!this.r && this.appliedTransformations < 4) {
  4885. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4886. .rotateY(this.or.v[1])
  4887. .rotateX(this.or.v[0]);
  4888. }
  4889. if (this.autoOriented) {
  4890. var v1;
  4891. var v2;
  4892. frameRate = this.elem.globalData.frameRate;
  4893. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4894. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4895. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4896. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4897. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4898. v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0);
  4899. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4900. } else {
  4901. v1 = this.p.pv;
  4902. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4903. }
  4904. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4905. v1 = [];
  4906. v2 = [];
  4907. var px = this.px;
  4908. var py = this.py;
  4909. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4910. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4911. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4912. v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate, 0);
  4913. v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate, 0);
  4914. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4915. v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate), 0);
  4916. v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate), 0);
  4917. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4918. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4919. } else {
  4920. v1 = [px.pv, py.pv];
  4921. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4922. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4923. }
  4924. } else {
  4925. v2 = defaultVector;
  4926. v1 = v2;
  4927. }
  4928. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4929. }
  4930. if (this.data.p && this.data.p.s) {
  4931. if (this.data.p.z) {
  4932. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4933. } else {
  4934. this.v.translate(this.px.v, this.py.v, 0);
  4935. }
  4936. } else {
  4937. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4938. }
  4939. }
  4940. this.frameId = this.elem.globalData.frameId;
  4941. }
  4942. function precalculateMatrix() {
  4943. this.appliedTransformations = 0;
  4944. this.pre.reset();
  4945. if (!this.a.effectsSequence.length) {
  4946. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4947. this.appliedTransformations = 1;
  4948. } else {
  4949. return;
  4950. }
  4951. if (!this.s.effectsSequence.length) {
  4952. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4953. this.appliedTransformations = 2;
  4954. } else {
  4955. return;
  4956. }
  4957. if (this.sk) {
  4958. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  4959. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  4960. this.appliedTransformations = 3;
  4961. } else {
  4962. return;
  4963. }
  4964. }
  4965. if (this.r) {
  4966. if (!this.r.effectsSequence.length) {
  4967. this.pre.rotate(-this.r.v);
  4968. this.appliedTransformations = 4;
  4969. }
  4970. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  4971. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4972. .rotateY(this.or.v[1])
  4973. .rotateX(this.or.v[0]);
  4974. this.appliedTransformations = 4;
  4975. }
  4976. }
  4977. function autoOrient() {
  4978. //
  4979. // var prevP = this.getValueAtTime();
  4980. }
  4981. function addDynamicProperty(prop) {
  4982. this._addDynamicProperty(prop);
  4983. this.elem.addDynamicProperty(prop);
  4984. this._isDirty = true;
  4985. }
  4986. function TransformProperty(elem, data, container) {
  4987. this.elem = elem;
  4988. this.frameId = -1;
  4989. this.propType = 'transform';
  4990. this.data = data;
  4991. this.v = new Matrix();
  4992. // Precalculated matrix with non animated properties
  4993. this.pre = new Matrix();
  4994. this.appliedTransformations = 0;
  4995. this.initDynamicPropertyContainer(container || elem);
  4996. if (data.p && data.p.s) {
  4997. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  4998. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  4999. if (data.p.z) {
  5000. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  5001. }
  5002. } else {
  5003. this.p = PropertyFactory.getProp(elem, data.p || { k: [0, 0, 0] }, 1, 0, this);
  5004. }
  5005. if (data.rx) {
  5006. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  5007. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  5008. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  5009. if (data.or.k[0].ti) {
  5010. var i;
  5011. var len = data.or.k.length;
  5012. for (i = 0; i < len; i += 1) {
  5013. data.or.k[i].to = null;
  5014. data.or.k[i].ti = null;
  5015. }
  5016. }
  5017. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  5018. // sh Indicates it needs to be capped between -180 and 180
  5019. this.or.sh = true;
  5020. } else {
  5021. this.r = PropertyFactory.getProp(elem, data.r || { k: 0 }, 0, degToRads, this);
  5022. }
  5023. if (data.sk) {
  5024. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  5025. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  5026. }
  5027. this.a = PropertyFactory.getProp(elem, data.a || { k: [0, 0, 0] }, 1, 0, this);
  5028. this.s = PropertyFactory.getProp(elem, data.s || { k: [100, 100, 100] }, 1, 0.01, this);
  5029. // Opacity is not part of the transform properties, that's why it won't use this.dynamicProperties. That way transforms won't get updated if opacity changes.
  5030. if (data.o) {
  5031. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  5032. } else {
  5033. this.o = { _mdf: false, v: 1 };
  5034. }
  5035. this._isDirty = true;
  5036. if (!this.dynamicProperties.length) {
  5037. this.getValue(true);
  5038. }
  5039. }
  5040. TransformProperty.prototype = {
  5041. applyToMatrix: applyToMatrix,
  5042. getValue: processKeys,
  5043. precalculateMatrix: precalculateMatrix,
  5044. autoOrient: autoOrient,
  5045. };
  5046. extendPrototype([DynamicPropertyContainer], TransformProperty);
  5047. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  5048. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  5049. function getTransformProperty(elem, data, container) {
  5050. return new TransformProperty(elem, data, container);
  5051. }
  5052. return {
  5053. getTransformProperty: getTransformProperty,
  5054. };
  5055. }());
  5056. function RepeaterModifier() {}
  5057. extendPrototype([ShapeModifier], RepeaterModifier);
  5058. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5059. this.getValue = this.processKeys;
  5060. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5061. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5062. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5063. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5064. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5065. this.data = data;
  5066. if (!this.dynamicProperties.length) {
  5067. this.getValue(true);
  5068. }
  5069. this._isAnimated = !!this.dynamicProperties.length;
  5070. this.pMatrix = new Matrix();
  5071. this.rMatrix = new Matrix();
  5072. this.sMatrix = new Matrix();
  5073. this.tMatrix = new Matrix();
  5074. this.matrix = new Matrix();
  5075. };
  5076. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5077. var dir = inv ? -1 : 1;
  5078. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5079. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5080. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5081. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5082. rMatrix.rotate(-transform.r.v * dir * perc);
  5083. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5084. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5085. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5086. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5087. };
  5088. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5089. this.elem = elem;
  5090. this.arr = arr;
  5091. this.pos = pos;
  5092. this.elemsData = elemsData;
  5093. this._currentCopies = 0;
  5094. this._elements = [];
  5095. this._groups = [];
  5096. this.frameId = -1;
  5097. this.initDynamicPropertyContainer(elem);
  5098. this.initModifierProperties(elem, arr[pos]);
  5099. while (pos > 0) {
  5100. pos -= 1;
  5101. // this._elements.unshift(arr.splice(pos,1)[0]);
  5102. this._elements.unshift(arr[pos]);
  5103. }
  5104. if (this.dynamicProperties.length) {
  5105. this.k = true;
  5106. } else {
  5107. this.getValue(true);
  5108. }
  5109. };
  5110. RepeaterModifier.prototype.resetElements = function (elements) {
  5111. var i;
  5112. var len = elements.length;
  5113. for (i = 0; i < len; i += 1) {
  5114. elements[i]._processed = false;
  5115. if (elements[i].ty === 'gr') {
  5116. this.resetElements(elements[i].it);
  5117. }
  5118. }
  5119. };
  5120. RepeaterModifier.prototype.cloneElements = function (elements) {
  5121. var newElements = JSON.parse(JSON.stringify(elements));
  5122. this.resetElements(newElements);
  5123. return newElements;
  5124. };
  5125. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5126. var i;
  5127. var len = elements.length;
  5128. for (i = 0; i < len; i += 1) {
  5129. elements[i]._render = renderFlag;
  5130. if (elements[i].ty === 'gr') {
  5131. this.changeGroupRender(elements[i].it, renderFlag);
  5132. }
  5133. }
  5134. };
  5135. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5136. var items;
  5137. var itemsTransform;
  5138. var i;
  5139. var dir;
  5140. var cont;
  5141. var hasReloaded = false;
  5142. if (this._mdf || _isFirstFrame) {
  5143. var copies = Math.ceil(this.c.v);
  5144. if (this._groups.length < copies) {
  5145. while (this._groups.length < copies) {
  5146. var group = {
  5147. it: this.cloneElements(this._elements),
  5148. ty: 'gr',
  5149. };
  5150. group.it.push({
  5151. a: { a: 0, ix: 1, k: [0, 0] }, nm: 'Transform', o: { a: 0, ix: 7, k: 100 }, p: { a: 0, ix: 2, k: [0, 0] }, r: { a: 1, ix: 6, k: [{ s: 0, e: 0, t: 0 }, { s: 0, e: 0, t: 1 }] }, s: { a: 0, ix: 3, k: [100, 100] }, sa: { a: 0, ix: 5, k: 0 }, sk: { a: 0, ix: 4, k: 0 }, ty: 'tr',
  5152. });
  5153. this.arr.splice(0, 0, group);
  5154. this._groups.splice(0, 0, group);
  5155. this._currentCopies += 1;
  5156. }
  5157. this.elem.reloadShapes();
  5158. hasReloaded = true;
  5159. }
  5160. cont = 0;
  5161. var renderFlag;
  5162. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5163. renderFlag = cont < copies;
  5164. this._groups[i]._render = renderFlag;
  5165. this.changeGroupRender(this._groups[i].it, renderFlag);
  5166. if (!renderFlag) {
  5167. var elems = this.elemsData[i].it;
  5168. var transformData = elems[elems.length - 1];
  5169. if (transformData.transform.op.v !== 0) {
  5170. transformData.transform.op._mdf = true;
  5171. transformData.transform.op.v = 0;
  5172. } else {
  5173. transformData.transform.op._mdf = false;
  5174. }
  5175. }
  5176. cont += 1;
  5177. }
  5178. this._currentCopies = copies;
  5179. /// /
  5180. var offset = this.o.v;
  5181. var offsetModulo = offset % 1;
  5182. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5183. var pProps = this.pMatrix.props;
  5184. var rProps = this.rMatrix.props;
  5185. var sProps = this.sMatrix.props;
  5186. this.pMatrix.reset();
  5187. this.rMatrix.reset();
  5188. this.sMatrix.reset();
  5189. this.tMatrix.reset();
  5190. this.matrix.reset();
  5191. var iteration = 0;
  5192. if (offset > 0) {
  5193. while (iteration < roundOffset) {
  5194. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5195. iteration += 1;
  5196. }
  5197. if (offsetModulo) {
  5198. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5199. iteration += offsetModulo;
  5200. }
  5201. } else if (offset < 0) {
  5202. while (iteration > roundOffset) {
  5203. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5204. iteration -= 1;
  5205. }
  5206. if (offsetModulo) {
  5207. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5208. iteration -= offsetModulo;
  5209. }
  5210. }
  5211. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5212. dir = this.data.m === 1 ? 1 : -1;
  5213. cont = this._currentCopies;
  5214. var j;
  5215. var jLen;
  5216. while (cont) {
  5217. items = this.elemsData[i].it;
  5218. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5219. jLen = itemsTransform.length;
  5220. items[items.length - 1].transform.mProps._mdf = true;
  5221. items[items.length - 1].transform.op._mdf = true;
  5222. items[items.length - 1].transform.op.v = this._currentCopies === 1
  5223. ? this.so.v
  5224. : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5225. if (iteration !== 0) {
  5226. if ((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)) {
  5227. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5228. }
  5229. this.matrix.transform(rProps[0], rProps[1], rProps[2], rProps[3], rProps[4], rProps[5], rProps[6], rProps[7], rProps[8], rProps[9], rProps[10], rProps[11], rProps[12], rProps[13], rProps[14], rProps[15]);
  5230. this.matrix.transform(sProps[0], sProps[1], sProps[2], sProps[3], sProps[4], sProps[5], sProps[6], sProps[7], sProps[8], sProps[9], sProps[10], sProps[11], sProps[12], sProps[13], sProps[14], sProps[15]);
  5231. this.matrix.transform(pProps[0], pProps[1], pProps[2], pProps[3], pProps[4], pProps[5], pProps[6], pProps[7], pProps[8], pProps[9], pProps[10], pProps[11], pProps[12], pProps[13], pProps[14], pProps[15]);
  5232. for (j = 0; j < jLen; j += 1) {
  5233. itemsTransform[j] = this.matrix.props[j];
  5234. }
  5235. this.matrix.reset();
  5236. } else {
  5237. this.matrix.reset();
  5238. for (j = 0; j < jLen; j += 1) {
  5239. itemsTransform[j] = this.matrix.props[j];
  5240. }
  5241. }
  5242. iteration += 1;
  5243. cont -= 1;
  5244. i += dir;
  5245. }
  5246. } else {
  5247. cont = this._currentCopies;
  5248. i = 0;
  5249. dir = 1;
  5250. while (cont) {
  5251. items = this.elemsData[i].it;
  5252. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5253. items[items.length - 1].transform.mProps._mdf = false;
  5254. items[items.length - 1].transform.op._mdf = false;
  5255. cont -= 1;
  5256. i += dir;
  5257. }
  5258. }
  5259. return hasReloaded;
  5260. };
  5261. RepeaterModifier.prototype.addShape = function () {};
  5262. function RoundCornersModifier() {}
  5263. extendPrototype([ShapeModifier], RoundCornersModifier);
  5264. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5265. this.getValue = this.processKeys;
  5266. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5267. this._isAnimated = !!this.rd.effectsSequence.length;
  5268. };
  5269. RoundCornersModifier.prototype.processPath = function (path, round) {
  5270. var clonedPath = shapePool.newElement();
  5271. clonedPath.c = path.c;
  5272. var i;
  5273. var len = path._length;
  5274. var currentV;
  5275. var currentI;
  5276. var currentO;
  5277. var closerV;
  5278. var distance;
  5279. var newPosPerc;
  5280. var index = 0;
  5281. var vX;
  5282. var vY;
  5283. var oX;
  5284. var oY;
  5285. var iX;
  5286. var iY;
  5287. for (i = 0; i < len; i += 1) {
  5288. currentV = path.v[i];
  5289. currentO = path.o[i];
  5290. currentI = path.i[i];
  5291. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5292. if ((i === 0 || i === len - 1) && !path.c) {
  5293. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5294. /* clonedPath.v[index] = currentV;
  5295. clonedPath.o[index] = currentO;
  5296. clonedPath.i[index] = currentI; */
  5297. index += 1;
  5298. } else {
  5299. if (i === 0) {
  5300. closerV = path.v[len - 1];
  5301. } else {
  5302. closerV = path.v[i - 1];
  5303. }
  5304. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5305. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5306. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5307. vX = iX;
  5308. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5309. vY = iY;
  5310. oX = vX - (vX - currentV[0]) * roundCorner;
  5311. oY = vY - (vY - currentV[1]) * roundCorner;
  5312. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5313. index += 1;
  5314. if (i === len - 1) {
  5315. closerV = path.v[0];
  5316. } else {
  5317. closerV = path.v[i + 1];
  5318. }
  5319. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5320. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5321. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5322. vX = oX;
  5323. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5324. vY = oY;
  5325. iX = vX - (vX - currentV[0]) * roundCorner;
  5326. iY = vY - (vY - currentV[1]) * roundCorner;
  5327. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5328. index += 1;
  5329. }
  5330. } else {
  5331. clonedPath.setTripleAt(path.v[i][0], path.v[i][1], path.o[i][0], path.o[i][1], path.i[i][0], path.i[i][1], index);
  5332. index += 1;
  5333. }
  5334. }
  5335. return clonedPath;
  5336. };
  5337. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5338. var shapePaths;
  5339. var i;
  5340. var len = this.shapes.length;
  5341. var j;
  5342. var jLen;
  5343. var rd = this.rd.v;
  5344. if (rd !== 0) {
  5345. var shapeData;
  5346. var localShapeCollection;
  5347. for (i = 0; i < len; i += 1) {
  5348. shapeData = this.shapes[i];
  5349. localShapeCollection = shapeData.localShapeCollection;
  5350. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5351. localShapeCollection.releaseShapes();
  5352. shapeData.shape._mdf = true;
  5353. shapePaths = shapeData.shape.paths.shapes;
  5354. jLen = shapeData.shape.paths._length;
  5355. for (j = 0; j < jLen; j += 1) {
  5356. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5357. }
  5358. }
  5359. shapeData.shape.paths = shapeData.localShapeCollection;
  5360. }
  5361. }
  5362. if (!this.dynamicProperties.length) {
  5363. this._mdf = false;
  5364. }
  5365. };
  5366. function floatEqual(a, b) {
  5367. return Math.abs(a - b) * 100000 <= Math.min(Math.abs(a), Math.abs(b));
  5368. }
  5369. function floatZero(f) {
  5370. return Math.abs(f) <= 0.00001;
  5371. }
  5372. function lerp(p0, p1, amount) {
  5373. return p0 * (1 - amount) + p1 * amount;
  5374. }
  5375. function lerpPoint(p0, p1, amount) {
  5376. return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
  5377. }
  5378. function quadRoots(a, b, c) {
  5379. // no root
  5380. if (a === 0) return [];
  5381. var s = b * b - 4 * a * c;
  5382. // Complex roots
  5383. if (s < 0) return [];
  5384. var singleRoot = -b / (2 * a);
  5385. // 1 root
  5386. if (s === 0) return [singleRoot];
  5387. var delta = Math.sqrt(s) / (2 * a);
  5388. // 2 roots
  5389. return [singleRoot - delta, singleRoot + delta];
  5390. }
  5391. function polynomialCoefficients(p0, p1, p2, p3) {
  5392. return [
  5393. -p0 + 3 * p1 - 3 * p2 + p3,
  5394. 3 * p0 - 6 * p1 + 3 * p2,
  5395. -3 * p0 + 3 * p1,
  5396. p0,
  5397. ];
  5398. }
  5399. function singlePoint(p) {
  5400. return new PolynomialBezier(p, p, p, p, false);
  5401. }
  5402. function PolynomialBezier(p0, p1, p2, p3, linearize) {
  5403. if (linearize && pointEqual(p0, p1)) {
  5404. p1 = lerpPoint(p0, p3, 1 / 3);
  5405. }
  5406. if (linearize && pointEqual(p2, p3)) {
  5407. p2 = lerpPoint(p0, p3, 2 / 3);
  5408. }
  5409. var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
  5410. var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
  5411. this.a = [coeffx[0], coeffy[0]];
  5412. this.b = [coeffx[1], coeffy[1]];
  5413. this.c = [coeffx[2], coeffy[2]];
  5414. this.d = [coeffx[3], coeffy[3]];
  5415. this.points = [p0, p1, p2, p3];
  5416. }
  5417. PolynomialBezier.prototype.point = function (t) {
  5418. return [
  5419. (((this.a[0] * t) + this.b[0]) * t + this.c[0]) * t + this.d[0],
  5420. (((this.a[1] * t) + this.b[1]) * t + this.c[1]) * t + this.d[1],
  5421. ];
  5422. };
  5423. PolynomialBezier.prototype.derivative = function (t) {
  5424. return [
  5425. (3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0],
  5426. (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1],
  5427. ];
  5428. };
  5429. PolynomialBezier.prototype.tangentAngle = function (t) {
  5430. var p = this.derivative(t);
  5431. return Math.atan2(p[1], p[0]);
  5432. };
  5433. PolynomialBezier.prototype.normalAngle = function (t) {
  5434. var p = this.derivative(t);
  5435. return Math.atan2(p[0], p[1]);
  5436. };
  5437. PolynomialBezier.prototype.inflectionPoints = function () {
  5438. var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
  5439. if (floatZero(denom)) return [];
  5440. var tcusp = (-0.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1])) / denom;
  5441. var square = tcusp * tcusp - ((1 / 3) * (this.b[1] * this.c[0] - this.b[0] * this.c[1])) / denom;
  5442. if (square < 0) return [];
  5443. var root = Math.sqrt(square);
  5444. if (floatZero(root)) {
  5445. if (root > 0 && root < 1) return [tcusp];
  5446. return [];
  5447. }
  5448. return [tcusp - root, tcusp + root].filter(function (r) { return r > 0 && r < 1; });
  5449. };
  5450. PolynomialBezier.prototype.split = function (t) {
  5451. if (t <= 0) return [singlePoint(this.points[0]), this];
  5452. if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
  5453. var p10 = lerpPoint(this.points[0], this.points[1], t);
  5454. var p11 = lerpPoint(this.points[1], this.points[2], t);
  5455. var p12 = lerpPoint(this.points[2], this.points[3], t);
  5456. var p20 = lerpPoint(p10, p11, t);
  5457. var p21 = lerpPoint(p11, p12, t);
  5458. var p3 = lerpPoint(p20, p21, t);
  5459. return [
  5460. new PolynomialBezier(this.points[0], p10, p20, p3, true),
  5461. new PolynomialBezier(p3, p21, p12, this.points[3], true),
  5462. ];
  5463. };
  5464. function extrema(bez, comp) {
  5465. var min = bez.points[0][comp];
  5466. var max = bez.points[bez.points.length - 1][comp];
  5467. if (min > max) {
  5468. var e = max;
  5469. max = min;
  5470. min = e;
  5471. }
  5472. // Derivative roots to find min/max
  5473. var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
  5474. for (var i = 0; i < f.length; i += 1) {
  5475. if (f[i] > 0 && f[i] < 1) {
  5476. var val = bez.point(f[i])[comp];
  5477. if (val < min) min = val;
  5478. else if (val > max) max = val;
  5479. }
  5480. }
  5481. return {
  5482. min: min,
  5483. max: max,
  5484. };
  5485. }
  5486. PolynomialBezier.prototype.bounds = function () {
  5487. return {
  5488. x: extrema(this, 0),
  5489. y: extrema(this, 1),
  5490. };
  5491. };
  5492. PolynomialBezier.prototype.boundingBox = function () {
  5493. var bounds = this.bounds();
  5494. return {
  5495. left: bounds.x.min,
  5496. right: bounds.x.max,
  5497. top: bounds.y.min,
  5498. bottom: bounds.y.max,
  5499. width: bounds.x.max - bounds.x.min,
  5500. height: bounds.y.max - bounds.y.min,
  5501. cx: (bounds.x.max + bounds.x.min) / 2,
  5502. cy: (bounds.y.max + bounds.y.min) / 2,
  5503. };
  5504. };
  5505. function intersectData(bez, t1, t2) {
  5506. var box = bez.boundingBox();
  5507. return {
  5508. cx: box.cx,
  5509. cy: box.cy,
  5510. width: box.width,
  5511. height: box.height,
  5512. bez: bez,
  5513. t: (t1 + t2) / 2,
  5514. t1: t1,
  5515. t2: t2,
  5516. };
  5517. }
  5518. function splitData(data) {
  5519. var split = data.bez.split(0.5);
  5520. return [
  5521. intersectData(split[0], data.t1, data.t),
  5522. intersectData(split[1], data.t, data.t2),
  5523. ];
  5524. }
  5525. function boxIntersect(b1, b2) {
  5526. return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width
  5527. && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
  5528. }
  5529. function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
  5530. if (!boxIntersect(d1, d2)) return;
  5531. if (depth >= maxRecursion || (d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance)) {
  5532. intersections.push([d1.t, d2.t]);
  5533. return;
  5534. }
  5535. var d1s = splitData(d1);
  5536. var d2s = splitData(d2);
  5537. intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5538. intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5539. intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5540. intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5541. }
  5542. PolynomialBezier.prototype.intersections = function (other, tolerance, maxRecursion) {
  5543. if (tolerance === undefined) tolerance = 2;
  5544. if (maxRecursion === undefined) maxRecursion = 7;
  5545. var intersections = [];
  5546. intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
  5547. return intersections;
  5548. };
  5549. PolynomialBezier.shapeSegment = function (shapePath, index) {
  5550. var nextIndex = (index + 1) % shapePath.length();
  5551. return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
  5552. };
  5553. PolynomialBezier.shapeSegmentInverted = function (shapePath, index) {
  5554. var nextIndex = (index + 1) % shapePath.length();
  5555. return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
  5556. };
  5557. function crossProduct(a, b) {
  5558. return [
  5559. a[1] * b[2] - a[2] * b[1],
  5560. a[2] * b[0] - a[0] * b[2],
  5561. a[0] * b[1] - a[1] * b[0],
  5562. ];
  5563. }
  5564. function lineIntersection(start1, end1, start2, end2) {
  5565. var v1 = [start1[0], start1[1], 1];
  5566. var v2 = [end1[0], end1[1], 1];
  5567. var v3 = [start2[0], start2[1], 1];
  5568. var v4 = [end2[0], end2[1], 1];
  5569. var r = crossProduct(
  5570. crossProduct(v1, v2),
  5571. crossProduct(v3, v4)
  5572. );
  5573. if (floatZero(r[2])) return null;
  5574. return [r[0] / r[2], r[1] / r[2]];
  5575. }
  5576. function polarOffset(p, angle, length) {
  5577. return [
  5578. p[0] + Math.cos(angle) * length,
  5579. p[1] - Math.sin(angle) * length,
  5580. ];
  5581. }
  5582. function pointDistance(p1, p2) {
  5583. return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
  5584. }
  5585. function pointEqual(p1, p2) {
  5586. return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
  5587. }
  5588. function ZigZagModifier() {}
  5589. extendPrototype([ShapeModifier], ZigZagModifier);
  5590. ZigZagModifier.prototype.initModifierProperties = function (elem, data) {
  5591. this.getValue = this.processKeys;
  5592. this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
  5593. this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5594. this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
  5595. this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
  5596. };
  5597. function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
  5598. var angO = angle - Math.PI / 2;
  5599. var angI = angle + Math.PI / 2;
  5600. var px = point[0] + Math.cos(angle) * direction * amplitude;
  5601. var py = point[1] - Math.sin(angle) * direction * amplitude;
  5602. outputBezier.setTripleAt(
  5603. px,
  5604. py,
  5605. px + Math.cos(angO) * outAmplitude,
  5606. py - Math.sin(angO) * outAmplitude,
  5607. px + Math.cos(angI) * inAmplitude,
  5608. py - Math.sin(angI) * inAmplitude,
  5609. outputBezier.length()
  5610. );
  5611. }
  5612. function getPerpendicularVector(pt1, pt2) {
  5613. var vector = [
  5614. pt2[0] - pt1[0],
  5615. pt2[1] - pt1[1],
  5616. ];
  5617. var rot = -Math.PI * 0.5;
  5618. var rotatedVector = [
  5619. Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1],
  5620. Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1],
  5621. ];
  5622. return rotatedVector;
  5623. }
  5624. function getProjectingAngle(path, cur) {
  5625. var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
  5626. var nextIndex = (cur + 1) % path.length();
  5627. var prevPoint = path.v[prevIndex];
  5628. var nextPoint = path.v[nextIndex];
  5629. var pVector = getPerpendicularVector(prevPoint, nextPoint);
  5630. return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
  5631. }
  5632. function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
  5633. var angle = getProjectingAngle(path, cur);
  5634. var point = path.v[cur % path._length];
  5635. var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
  5636. var nextPoint = path.v[(cur + 1) % path._length];
  5637. var prevDist = pointType === 2
  5638. ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2))
  5639. : 0;
  5640. var nextDist = pointType === 2
  5641. ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2))
  5642. : 0;
  5643. setPoint(
  5644. outputBezier,
  5645. path.v[cur % path._length],
  5646. angle,
  5647. direction,
  5648. amplitude,
  5649. nextDist / ((frequency + 1) * 2),
  5650. prevDist / ((frequency + 1) * 2),
  5651. pointType
  5652. );
  5653. }
  5654. function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
  5655. for (var i = 0; i < frequency; i += 1) {
  5656. var t = (i + 1) / (frequency + 1);
  5657. var dist = pointType === 2
  5658. ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2))
  5659. : 0;
  5660. var angle = segment.normalAngle(t);
  5661. var point = segment.point(t);
  5662. setPoint(
  5663. outputBezier,
  5664. point,
  5665. angle,
  5666. direction,
  5667. amplitude,
  5668. dist / ((frequency + 1) * 2),
  5669. dist / ((frequency + 1) * 2),
  5670. pointType
  5671. );
  5672. direction = -direction;
  5673. }
  5674. return direction;
  5675. }
  5676. ZigZagModifier.prototype.processPath = function (path, amplitude, frequency, pointType) {
  5677. var count = path._length;
  5678. var clonedPath = shapePool.newElement();
  5679. clonedPath.c = path.c;
  5680. if (!path.c) {
  5681. count -= 1;
  5682. }
  5683. if (count === 0) return clonedPath;
  5684. var direction = -1;
  5685. var segment = PolynomialBezier.shapeSegment(path, 0);
  5686. zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
  5687. for (var i = 0; i < count; i += 1) {
  5688. direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
  5689. if (i === count - 1 && !path.c) {
  5690. segment = null;
  5691. } else {
  5692. segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
  5693. }
  5694. zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
  5695. }
  5696. return clonedPath;
  5697. };
  5698. ZigZagModifier.prototype.processShapes = function (_isFirstFrame) {
  5699. var shapePaths;
  5700. var i;
  5701. var len = this.shapes.length;
  5702. var j;
  5703. var jLen;
  5704. var amplitude = this.amplitude.v;
  5705. var frequency = Math.max(0, Math.round(this.frequency.v));
  5706. var pointType = this.pointsType.v;
  5707. if (amplitude !== 0) {
  5708. var shapeData;
  5709. var localShapeCollection;
  5710. for (i = 0; i < len; i += 1) {
  5711. shapeData = this.shapes[i];
  5712. localShapeCollection = shapeData.localShapeCollection;
  5713. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5714. localShapeCollection.releaseShapes();
  5715. shapeData.shape._mdf = true;
  5716. shapePaths = shapeData.shape.paths.shapes;
  5717. jLen = shapeData.shape.paths._length;
  5718. for (j = 0; j < jLen; j += 1) {
  5719. localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
  5720. }
  5721. }
  5722. shapeData.shape.paths = shapeData.localShapeCollection;
  5723. }
  5724. }
  5725. if (!this.dynamicProperties.length) {
  5726. this._mdf = false;
  5727. }
  5728. };
  5729. function linearOffset(p1, p2, amount) {
  5730. var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
  5731. return [
  5732. polarOffset(p1, angle, amount),
  5733. polarOffset(p2, angle, amount),
  5734. ];
  5735. }
  5736. function offsetSegment(segment, amount) {
  5737. var p0; var p1a; var p1b; var p2b; var p2a; var
  5738. p3;
  5739. var e;
  5740. e = linearOffset(segment.points[0], segment.points[1], amount);
  5741. p0 = e[0];
  5742. p1a = e[1];
  5743. e = linearOffset(segment.points[1], segment.points[2], amount);
  5744. p1b = e[0];
  5745. p2b = e[1];
  5746. e = linearOffset(segment.points[2], segment.points[3], amount);
  5747. p2a = e[0];
  5748. p3 = e[1];
  5749. var p1 = lineIntersection(p0, p1a, p1b, p2b);
  5750. if (p1 === null) p1 = p1a;
  5751. var p2 = lineIntersection(p2a, p3, p1b, p2b);
  5752. if (p2 === null) p2 = p2a;
  5753. return new PolynomialBezier(p0, p1, p2, p3);
  5754. }
  5755. function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
  5756. var p0 = seg1.points[3];
  5757. var p1 = seg2.points[0];
  5758. // Bevel
  5759. if (lineJoin === 3) return p0;
  5760. // Connected, they don't need a joint
  5761. if (pointEqual(p0, p1)) return p0;
  5762. // Round
  5763. if (lineJoin === 2) {
  5764. var angleOut = -seg1.tangentAngle(1);
  5765. var angleIn = -seg2.tangentAngle(0) + Math.PI;
  5766. var center = lineIntersection(
  5767. p0,
  5768. polarOffset(p0, angleOut + Math.PI / 2, 100),
  5769. p1,
  5770. polarOffset(p1, angleOut + Math.PI / 2, 100)
  5771. );
  5772. var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
  5773. var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
  5774. outputBezier.setXYAt(tan[0], tan[1], 'o', outputBezier.length() - 1);
  5775. tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
  5776. outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
  5777. return p1;
  5778. }
  5779. // Miter
  5780. var t0 = pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2];
  5781. var t1 = pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1];
  5782. var intersection = lineIntersection(t0, p0, p1, t1);
  5783. if (intersection && pointDistance(intersection, p0) < miterLimit) {
  5784. outputBezier.setTripleAt(
  5785. intersection[0],
  5786. intersection[1],
  5787. intersection[0],
  5788. intersection[1],
  5789. intersection[0],
  5790. intersection[1],
  5791. outputBezier.length()
  5792. );
  5793. return intersection;
  5794. }
  5795. return p0;
  5796. }
  5797. function getIntersection(a, b) {
  5798. const intersect = a.intersections(b);
  5799. if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
  5800. if (intersect.length) return intersect[0];
  5801. return null;
  5802. }
  5803. function pruneSegmentIntersection(a, b) {
  5804. var outa = a.slice();
  5805. var outb = b.slice();
  5806. var intersect = getIntersection(a[a.length - 1], b[0]);
  5807. if (intersect) {
  5808. outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
  5809. outb[0] = b[0].split(intersect[1])[1];
  5810. }
  5811. if (a.length > 1 && b.length > 1) {
  5812. intersect = getIntersection(a[0], b[b.length - 1]);
  5813. if (intersect) {
  5814. return [
  5815. [a[0].split(intersect[0])[0]],
  5816. [b[b.length - 1].split(intersect[1])[1]],
  5817. ];
  5818. }
  5819. }
  5820. return [outa, outb];
  5821. }
  5822. function pruneIntersections(segments) {
  5823. var e;
  5824. for (var i = 1; i < segments.length; i += 1) {
  5825. e = pruneSegmentIntersection(segments[i - 1], segments[i]);
  5826. segments[i - 1] = e[0];
  5827. segments[i] = e[1];
  5828. }
  5829. if (segments.length > 1) {
  5830. e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
  5831. segments[segments.length - 1] = e[0];
  5832. segments[0] = e[1];
  5833. }
  5834. return segments;
  5835. }
  5836. function offsetSegmentSplit(segment, amount) {
  5837. /*
  5838. We split each bezier segment into smaller pieces based
  5839. on inflection points, this ensures the control point
  5840. polygon is convex.
  5841. (A cubic bezier can have none, one, or two inflection points)
  5842. */
  5843. var flex = segment.inflectionPoints();
  5844. var left;
  5845. var right;
  5846. var split;
  5847. var mid;
  5848. if (flex.length === 0) {
  5849. return [offsetSegment(segment, amount)];
  5850. }
  5851. if (flex.length === 1 || floatEqual(flex[1], 1)) {
  5852. split = segment.split(flex[0]);
  5853. left = split[0];
  5854. right = split[1];
  5855. return [
  5856. offsetSegment(left, amount),
  5857. offsetSegment(right, amount),
  5858. ];
  5859. }
  5860. split = segment.split(flex[0]);
  5861. left = split[0];
  5862. var t = (flex[1] - flex[0]) / (1 - flex[0]);
  5863. split = split[1].split(t);
  5864. mid = split[0];
  5865. right = split[1];
  5866. return [
  5867. offsetSegment(left, amount),
  5868. offsetSegment(mid, amount),
  5869. offsetSegment(right, amount),
  5870. ];
  5871. }
  5872. function OffsetPathModifier() {}
  5873. extendPrototype([ShapeModifier], OffsetPathModifier);
  5874. OffsetPathModifier.prototype.initModifierProperties = function (elem, data) {
  5875. this.getValue = this.processKeys;
  5876. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  5877. this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
  5878. this.lineJoin = data.lj;
  5879. this._isAnimated = this.amount.effectsSequence.length !== 0;
  5880. };
  5881. OffsetPathModifier.prototype.processPath = function (inputBezier, amount, lineJoin, miterLimit) {
  5882. var outputBezier = shapePool.newElement();
  5883. outputBezier.c = inputBezier.c;
  5884. var count = inputBezier.length();
  5885. if (!inputBezier.c) {
  5886. count -= 1;
  5887. }
  5888. var i; var j; var segment;
  5889. var multiSegments = [];
  5890. for (i = 0; i < count; i += 1) {
  5891. segment = PolynomialBezier.shapeSegment(inputBezier, i);
  5892. multiSegments.push(offsetSegmentSplit(segment, amount));
  5893. }
  5894. if (!inputBezier.c) {
  5895. for (i = count - 1; i >= 0; i -= 1) {
  5896. segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
  5897. multiSegments.push(offsetSegmentSplit(segment, amount));
  5898. }
  5899. }
  5900. multiSegments = pruneIntersections(multiSegments);
  5901. // Add bezier segments to the output and apply line joints
  5902. var lastPoint = null;
  5903. var lastSeg = null;
  5904. for (i = 0; i < multiSegments.length; i += 1) {
  5905. var multiSegment = multiSegments[i];
  5906. if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
  5907. lastSeg = multiSegment[multiSegment.length - 1];
  5908. for (j = 0; j < multiSegment.length; j += 1) {
  5909. segment = multiSegment[j];
  5910. if (lastPoint && pointEqual(segment.points[0], lastPoint)) {
  5911. outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], 'o', outputBezier.length() - 1);
  5912. } else {
  5913. outputBezier.setTripleAt(
  5914. segment.points[0][0],
  5915. segment.points[0][1],
  5916. segment.points[1][0],
  5917. segment.points[1][1],
  5918. segment.points[0][0],
  5919. segment.points[0][1],
  5920. outputBezier.length()
  5921. );
  5922. }
  5923. outputBezier.setTripleAt(
  5924. segment.points[3][0],
  5925. segment.points[3][1],
  5926. segment.points[3][0],
  5927. segment.points[3][1],
  5928. segment.points[2][0],
  5929. segment.points[2][1],
  5930. outputBezier.length()
  5931. );
  5932. lastPoint = segment.points[3];
  5933. }
  5934. }
  5935. if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
  5936. return outputBezier;
  5937. };
  5938. OffsetPathModifier.prototype.processShapes = function (_isFirstFrame) {
  5939. var shapePaths;
  5940. var i;
  5941. var len = this.shapes.length;
  5942. var j;
  5943. var jLen;
  5944. var amount = this.amount.v;
  5945. var miterLimit = this.miterLimit.v;
  5946. var lineJoin = this.lineJoin;
  5947. if (amount !== 0) {
  5948. var shapeData;
  5949. var localShapeCollection;
  5950. for (i = 0; i < len; i += 1) {
  5951. shapeData = this.shapes[i];
  5952. localShapeCollection = shapeData.localShapeCollection;
  5953. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5954. localShapeCollection.releaseShapes();
  5955. shapeData.shape._mdf = true;
  5956. shapePaths = shapeData.shape.paths.shapes;
  5957. jLen = shapeData.shape.paths._length;
  5958. for (j = 0; j < jLen; j += 1) {
  5959. localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
  5960. }
  5961. }
  5962. shapeData.shape.paths = shapeData.localShapeCollection;
  5963. }
  5964. }
  5965. if (!this.dynamicProperties.length) {
  5966. this._mdf = false;
  5967. }
  5968. };
  5969. function getFontProperties(fontData) {
  5970. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5971. var fWeight = 'normal'; var
  5972. fStyle = 'normal';
  5973. var len = styles.length;
  5974. var styleName;
  5975. for (var i = 0; i < len; i += 1) {
  5976. styleName = styles[i].toLowerCase();
  5977. switch (styleName) {
  5978. case 'italic':
  5979. fStyle = 'italic';
  5980. break;
  5981. case 'bold':
  5982. fWeight = '700';
  5983. break;
  5984. case 'black':
  5985. fWeight = '900';
  5986. break;
  5987. case 'medium':
  5988. fWeight = '500';
  5989. break;
  5990. case 'regular':
  5991. case 'normal':
  5992. fWeight = '400';
  5993. break;
  5994. case 'light':
  5995. case 'thin':
  5996. fWeight = '200';
  5997. break;
  5998. default:
  5999. break;
  6000. }
  6001. }
  6002. return {
  6003. style: fStyle,
  6004. weight: fontData.fWeight || fWeight,
  6005. };
  6006. }
  6007. const FontManager = (function () {
  6008. var maxWaitingTime = 5000;
  6009. var emptyChar = {
  6010. w: 0,
  6011. size: 0,
  6012. shapes: [],
  6013. data: {
  6014. shapes: [],
  6015. },
  6016. };
  6017. var combinedCharacters = [];
  6018. // Hindi characters
  6019. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366,
  6020. 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379,
  6021. 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  6022. var BLACK_FLAG_CODE_POINT = 127988;
  6023. var CANCEL_TAG_CODE_POINT = 917631;
  6024. var A_TAG_CODE_POINT = 917601;
  6025. var Z_TAG_CODE_POINT = 917626;
  6026. var VARIATION_SELECTOR_16_CODE_POINT = 65039;
  6027. var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
  6028. var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
  6029. var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
  6030. var surrogateModifiers = [
  6031. 'd83cdffb',
  6032. 'd83cdffc',
  6033. 'd83cdffd',
  6034. 'd83cdffe',
  6035. 'd83cdfff',
  6036. ];
  6037. function trimFontOptions(font) {
  6038. var familyArray = font.split(',');
  6039. var i;
  6040. var len = familyArray.length;
  6041. var enabledFamilies = [];
  6042. for (i = 0; i < len; i += 1) {
  6043. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  6044. enabledFamilies.push(familyArray[i]);
  6045. }
  6046. }
  6047. return enabledFamilies.join(',');
  6048. }
  6049. function setUpNode(font, family) {
  6050. var parentNode = createTag('span');
  6051. // Node is invisible to screen readers.
  6052. parentNode.setAttribute('aria-hidden', true);
  6053. parentNode.style.fontFamily = family;
  6054. var node = createTag('span');
  6055. // Characters that vary significantly among different fonts
  6056. node.innerText = 'giItT1WQy@!-/#';
  6057. // Visible - so we can measure it - but not on the screen
  6058. parentNode.style.position = 'absolute';
  6059. parentNode.style.left = '-10000px';
  6060. parentNode.style.top = '-10000px';
  6061. // Large font size makes even subtle changes obvious
  6062. parentNode.style.fontSize = '300px';
  6063. // Reset any font properties
  6064. parentNode.style.fontVariant = 'normal';
  6065. parentNode.style.fontStyle = 'normal';
  6066. parentNode.style.fontWeight = 'normal';
  6067. parentNode.style.letterSpacing = '0';
  6068. parentNode.appendChild(node);
  6069. document.body.appendChild(parentNode);
  6070. // Remember width with no applied web font
  6071. var width = node.offsetWidth;
  6072. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  6073. return { node: node, w: width, parent: parentNode };
  6074. }
  6075. function checkLoadedFonts() {
  6076. var i;
  6077. var len = this.fonts.length;
  6078. var node;
  6079. var w;
  6080. var loadedCount = len;
  6081. for (i = 0; i < len; i += 1) {
  6082. if (this.fonts[i].loaded) {
  6083. loadedCount -= 1;
  6084. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  6085. this.fonts[i].loaded = true;
  6086. } else {
  6087. node = this.fonts[i].monoCase.node;
  6088. w = this.fonts[i].monoCase.w;
  6089. if (node.offsetWidth !== w) {
  6090. loadedCount -= 1;
  6091. this.fonts[i].loaded = true;
  6092. } else {
  6093. node = this.fonts[i].sansCase.node;
  6094. w = this.fonts[i].sansCase.w;
  6095. if (node.offsetWidth !== w) {
  6096. loadedCount -= 1;
  6097. this.fonts[i].loaded = true;
  6098. }
  6099. }
  6100. if (this.fonts[i].loaded) {
  6101. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  6102. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  6103. }
  6104. }
  6105. }
  6106. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  6107. setTimeout(this.checkLoadedFontsBinded, 20);
  6108. } else {
  6109. setTimeout(this.setIsLoadedBinded, 10);
  6110. }
  6111. }
  6112. function createHelper(fontData, def) {
  6113. var engine = (document.body && def) ? 'svg' : 'canvas';
  6114. var helper;
  6115. var fontProps = getFontProperties(fontData);
  6116. if (engine === 'svg') {
  6117. var tHelper = createNS('text');
  6118. tHelper.style.fontSize = '100px';
  6119. // tHelper.style.fontFamily = fontData.fFamily;
  6120. tHelper.setAttribute('font-family', fontData.fFamily);
  6121. tHelper.setAttribute('font-style', fontProps.style);
  6122. tHelper.setAttribute('font-weight', fontProps.weight);
  6123. tHelper.textContent = '1';
  6124. if (fontData.fClass) {
  6125. tHelper.style.fontFamily = 'inherit';
  6126. tHelper.setAttribute('class', fontData.fClass);
  6127. } else {
  6128. tHelper.style.fontFamily = fontData.fFamily;
  6129. }
  6130. def.appendChild(tHelper);
  6131. helper = tHelper;
  6132. } else {
  6133. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  6134. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  6135. helper = tCanvasHelper;
  6136. }
  6137. function measure(text) {
  6138. if (engine === 'svg') {
  6139. helper.textContent = text;
  6140. return helper.getComputedTextLength();
  6141. }
  6142. return helper.measureText(text).width;
  6143. }
  6144. return {
  6145. measureText: measure,
  6146. };
  6147. }
  6148. function addFonts(fontData, defs) {
  6149. if (!fontData) {
  6150. this.isLoaded = true;
  6151. return;
  6152. }
  6153. if (this.chars) {
  6154. this.isLoaded = true;
  6155. this.fonts = fontData.list;
  6156. return;
  6157. }
  6158. if (!document.body) {
  6159. this.isLoaded = true;
  6160. fontData.list.forEach((data) => {
  6161. data.helper = createHelper(data);
  6162. data.cache = {};
  6163. });
  6164. this.fonts = fontData.list;
  6165. return;
  6166. }
  6167. var fontArr = fontData.list;
  6168. var i;
  6169. var len = fontArr.length;
  6170. var _pendingFonts = len;
  6171. for (i = 0; i < len; i += 1) {
  6172. var shouldLoadFont = true;
  6173. var loadedSelector;
  6174. var j;
  6175. fontArr[i].loaded = false;
  6176. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  6177. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  6178. if (!fontArr[i].fPath) {
  6179. fontArr[i].loaded = true;
  6180. _pendingFonts -= 1;
  6181. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  6182. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  6183. if (loadedSelector.length > 0) {
  6184. shouldLoadFont = false;
  6185. }
  6186. if (shouldLoadFont) {
  6187. var s = createTag('style');
  6188. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  6189. s.setAttribute('f-origin', fontArr[i].origin);
  6190. s.setAttribute('f-family', fontArr[i].fFamily);
  6191. s.type = 'text/css';
  6192. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  6193. defs.appendChild(s);
  6194. }
  6195. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  6196. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  6197. for (j = 0; j < loadedSelector.length; j += 1) {
  6198. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  6199. // Font is already loaded
  6200. shouldLoadFont = false;
  6201. }
  6202. }
  6203. if (shouldLoadFont) {
  6204. var l = createTag('link');
  6205. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  6206. l.setAttribute('f-origin', fontArr[i].origin);
  6207. l.type = 'text/css';
  6208. l.rel = 'stylesheet';
  6209. l.href = fontArr[i].fPath;
  6210. document.body.appendChild(l);
  6211. }
  6212. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  6213. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  6214. for (j = 0; j < loadedSelector.length; j += 1) {
  6215. if (fontArr[i].fPath === loadedSelector[j].src) {
  6216. // Font is already loaded
  6217. shouldLoadFont = false;
  6218. }
  6219. }
  6220. if (shouldLoadFont) {
  6221. var sc = createTag('link');
  6222. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  6223. sc.setAttribute('f-origin', fontArr[i].origin);
  6224. sc.setAttribute('rel', 'stylesheet');
  6225. sc.setAttribute('href', fontArr[i].fPath);
  6226. defs.appendChild(sc);
  6227. }
  6228. }
  6229. fontArr[i].helper = createHelper(fontArr[i], defs);
  6230. fontArr[i].cache = {};
  6231. this.fonts.push(fontArr[i]);
  6232. }
  6233. if (_pendingFonts === 0) {
  6234. this.isLoaded = true;
  6235. } else {
  6236. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  6237. // Adding this timeout seems to fix it
  6238. setTimeout(this.checkLoadedFonts.bind(this), 100);
  6239. }
  6240. }
  6241. function addChars(chars) {
  6242. if (!chars) {
  6243. return;
  6244. }
  6245. if (!this.chars) {
  6246. this.chars = [];
  6247. }
  6248. var i;
  6249. var len = chars.length;
  6250. var j;
  6251. var jLen = this.chars.length;
  6252. var found;
  6253. for (i = 0; i < len; i += 1) {
  6254. j = 0;
  6255. found = false;
  6256. while (j < jLen) {
  6257. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  6258. found = true;
  6259. }
  6260. j += 1;
  6261. }
  6262. if (!found) {
  6263. this.chars.push(chars[i]);
  6264. jLen += 1;
  6265. }
  6266. }
  6267. }
  6268. function getCharData(char, style, font) {
  6269. var i = 0;
  6270. var len = this.chars.length;
  6271. while (i < len) {
  6272. if (this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  6273. return this.chars[i];
  6274. }
  6275. i += 1;
  6276. }
  6277. if (((typeof char === 'string' && char.charCodeAt(0) !== 13) || !char)
  6278. && console
  6279. && console.warn // eslint-disable-line no-console
  6280. && !this._warned
  6281. ) {
  6282. this._warned = true;
  6283. console.warn('Missing character from exported characters list: ', char, style, font); // eslint-disable-line no-console
  6284. }
  6285. return emptyChar;
  6286. }
  6287. function measureText(char, fontName, size) {
  6288. var fontData = this.getFontByName(fontName);
  6289. // Using the char instead of char.charCodeAt(0)
  6290. // to avoid collisions between equal chars
  6291. var index = char;
  6292. if (!fontData.cache[index]) {
  6293. var tHelper = fontData.helper;
  6294. if (char === ' ') {
  6295. var doubleSize = tHelper.measureText('|' + char + '|');
  6296. var singleSize = tHelper.measureText('||');
  6297. fontData.cache[index] = (doubleSize - singleSize) / 100;
  6298. } else {
  6299. fontData.cache[index] = tHelper.measureText(char) / 100;
  6300. }
  6301. }
  6302. return fontData.cache[index] * size;
  6303. }
  6304. function getFontByName(name) {
  6305. var i = 0;
  6306. var len = this.fonts.length;
  6307. while (i < len) {
  6308. if (this.fonts[i].fName === name) {
  6309. return this.fonts[i];
  6310. }
  6311. i += 1;
  6312. }
  6313. return this.fonts[0];
  6314. }
  6315. function getCodePoint(string) {
  6316. var codePoint = 0;
  6317. var first = string.charCodeAt(0);
  6318. if (first >= 0xD800 && first <= 0xDBFF) {
  6319. var second = string.charCodeAt(1);
  6320. if (second >= 0xDC00 && second <= 0xDFFF) {
  6321. codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  6322. }
  6323. }
  6324. return codePoint;
  6325. }
  6326. // Skin tone modifiers
  6327. function isModifier(firstCharCode, secondCharCode) {
  6328. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  6329. return surrogateModifiers.indexOf(sum) !== -1;
  6330. }
  6331. function isZeroWidthJoiner(charCode) {
  6332. return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
  6333. }
  6334. // This codepoint may change the appearance of the preceding character.
  6335. // If that is a symbol, dingbat or emoji, U+FE0F forces it to be rendered
  6336. // as a colorful image as compared to a monochrome text variant.
  6337. function isVariationSelector(charCode) {
  6338. return charCode === VARIATION_SELECTOR_16_CODE_POINT;
  6339. }
  6340. // The regional indicator symbols are a set of 26 alphabetic Unicode
  6341. /// characters (A–Z) intended to be used to encode ISO 3166-1 alpha-2
  6342. // two-letter country codes in a way that allows optional special treatment.
  6343. function isRegionalCode(string) {
  6344. var codePoint = getCodePoint(string);
  6345. if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) {
  6346. return true;
  6347. }
  6348. return false;
  6349. }
  6350. // Some Emoji implementations represent combinations of
  6351. // two “regional indicator” letters as a single flag symbol.
  6352. function isFlagEmoji(string) {
  6353. return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
  6354. }
  6355. function isCombinedCharacter(char) {
  6356. return combinedCharacters.indexOf(char) !== -1;
  6357. }
  6358. // Regional flags start with a BLACK_FLAG_CODE_POINT
  6359. // folowed by 5 chars in the TAG range
  6360. // and end with a CANCEL_TAG_CODE_POINT
  6361. function isRegionalFlag(text, index) {
  6362. var codePoint = getCodePoint(text.substr(index, 2));
  6363. if (codePoint !== BLACK_FLAG_CODE_POINT) {
  6364. return false;
  6365. }
  6366. var count = 0;
  6367. index += 2;
  6368. while (count < 5) {
  6369. codePoint = getCodePoint(text.substr(index, 2));
  6370. if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) {
  6371. return false;
  6372. }
  6373. count += 1;
  6374. index += 2;
  6375. }
  6376. return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
  6377. }
  6378. function setIsLoaded() {
  6379. this.isLoaded = true;
  6380. }
  6381. var Font = function () {
  6382. this.fonts = [];
  6383. this.chars = null;
  6384. this.typekitLoaded = 0;
  6385. this.isLoaded = false;
  6386. this._warned = false;
  6387. this.initTime = Date.now();
  6388. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  6389. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  6390. };
  6391. Font.isModifier = isModifier;
  6392. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  6393. Font.isFlagEmoji = isFlagEmoji;
  6394. Font.isRegionalCode = isRegionalCode;
  6395. Font.isCombinedCharacter = isCombinedCharacter;
  6396. Font.isRegionalFlag = isRegionalFlag;
  6397. Font.isVariationSelector = isVariationSelector;
  6398. Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
  6399. var fontPrototype = {
  6400. addChars: addChars,
  6401. addFonts: addFonts,
  6402. getCharData: getCharData,
  6403. getFontByName: getFontByName,
  6404. measureText: measureText,
  6405. checkLoadedFonts: checkLoadedFonts,
  6406. setIsLoaded: setIsLoaded,
  6407. };
  6408. Font.prototype = fontPrototype;
  6409. return Font;
  6410. }());
  6411. function SlotManager(animationData) {
  6412. this.animationData = animationData;
  6413. }
  6414. SlotManager.prototype.getProp = function (data) {
  6415. if (this.animationData.slots
  6416. && this.animationData.slots[data.sid]
  6417. ) {
  6418. return Object.assign(data, this.animationData.slots[data.sid].p);
  6419. }
  6420. return data;
  6421. };
  6422. function slotFactory(animationData) {
  6423. return new SlotManager(animationData);
  6424. }
  6425. function RenderableElement() {
  6426. }
  6427. RenderableElement.prototype = {
  6428. initRenderable: function () {
  6429. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6430. this.isInRange = false;
  6431. // layer's display state
  6432. this.hidden = false;
  6433. // If layer's transparency equals 0, it can be hidden
  6434. this.isTransparent = false;
  6435. // list of animated components
  6436. this.renderableComponents = [];
  6437. },
  6438. addRenderableComponent: function (component) {
  6439. if (this.renderableComponents.indexOf(component) === -1) {
  6440. this.renderableComponents.push(component);
  6441. }
  6442. },
  6443. removeRenderableComponent: function (component) {
  6444. if (this.renderableComponents.indexOf(component) !== -1) {
  6445. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6446. }
  6447. },
  6448. prepareRenderableFrame: function (num) {
  6449. this.checkLayerLimits(num);
  6450. },
  6451. checkTransparency: function () {
  6452. if (this.finalTransform.mProp.o.v <= 0) {
  6453. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  6454. this.isTransparent = true;
  6455. this.hide();
  6456. }
  6457. } else if (this.isTransparent) {
  6458. this.isTransparent = false;
  6459. this.show();
  6460. }
  6461. },
  6462. /**
  6463. * @function
  6464. * Initializes frame related properties.
  6465. *
  6466. * @param {number} num
  6467. * current frame number in Layer's time
  6468. *
  6469. */
  6470. checkLayerLimits: function (num) {
  6471. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  6472. if (this.isInRange !== true) {
  6473. this.globalData._mdf = true;
  6474. this._mdf = true;
  6475. this.isInRange = true;
  6476. this.show();
  6477. }
  6478. } else if (this.isInRange !== false) {
  6479. this.globalData._mdf = true;
  6480. this.isInRange = false;
  6481. this.hide();
  6482. }
  6483. },
  6484. renderRenderable: function () {
  6485. var i;
  6486. var len = this.renderableComponents.length;
  6487. for (i = 0; i < len; i += 1) {
  6488. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6489. }
  6490. /* this.maskManager.renderFrame(this.finalTransform.mat);
  6491. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  6492. },
  6493. sourceRectAtTime: function () {
  6494. return {
  6495. top: 0,
  6496. left: 0,
  6497. width: 100,
  6498. height: 100,
  6499. };
  6500. },
  6501. getLayerSize: function () {
  6502. if (this.data.ty === 5) {
  6503. return { w: this.data.textData.width, h: this.data.textData.height };
  6504. }
  6505. return { w: this.data.width, h: this.data.height };
  6506. },
  6507. };
  6508. const getBlendMode = (function () {
  6509. var blendModeEnums = {
  6510. 0: 'source-over',
  6511. 1: 'multiply',
  6512. 2: 'screen',
  6513. 3: 'overlay',
  6514. 4: 'darken',
  6515. 5: 'lighten',
  6516. 6: 'color-dodge',
  6517. 7: 'color-burn',
  6518. 8: 'hard-light',
  6519. 9: 'soft-light',
  6520. 10: 'difference',
  6521. 11: 'exclusion',
  6522. 12: 'hue',
  6523. 13: 'saturation',
  6524. 14: 'color',
  6525. 15: 'luminosity',
  6526. };
  6527. return function (mode) {
  6528. return blendModeEnums[mode] || '';
  6529. };
  6530. }());
  6531. function SliderEffect(data, elem, container) {
  6532. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6533. }
  6534. function AngleEffect(data, elem, container) {
  6535. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6536. }
  6537. function ColorEffect(data, elem, container) {
  6538. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6539. }
  6540. function PointEffect(data, elem, container) {
  6541. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6542. }
  6543. function LayerIndexEffect(data, elem, container) {
  6544. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6545. }
  6546. function MaskIndexEffect(data, elem, container) {
  6547. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6548. }
  6549. function CheckboxEffect(data, elem, container) {
  6550. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6551. }
  6552. function NoValueEffect() {
  6553. this.p = {};
  6554. }
  6555. function EffectsManager(data, element) {
  6556. var effects = data.ef || [];
  6557. this.effectElements = [];
  6558. var i;
  6559. var len = effects.length;
  6560. var effectItem;
  6561. for (i = 0; i < len; i += 1) {
  6562. effectItem = new GroupEffect(effects[i], element);
  6563. this.effectElements.push(effectItem);
  6564. }
  6565. }
  6566. function GroupEffect(data, element) {
  6567. this.init(data, element);
  6568. }
  6569. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6570. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6571. GroupEffect.prototype.init = function (data, element) {
  6572. this.data = data;
  6573. this.effectElements = [];
  6574. this.initDynamicPropertyContainer(element);
  6575. var i;
  6576. var len = this.data.ef.length;
  6577. var eff;
  6578. var effects = this.data.ef;
  6579. for (i = 0; i < len; i += 1) {
  6580. eff = null;
  6581. switch (effects[i].ty) {
  6582. case 0:
  6583. eff = new SliderEffect(effects[i], element, this);
  6584. break;
  6585. case 1:
  6586. eff = new AngleEffect(effects[i], element, this);
  6587. break;
  6588. case 2:
  6589. eff = new ColorEffect(effects[i], element, this);
  6590. break;
  6591. case 3:
  6592. eff = new PointEffect(effects[i], element, this);
  6593. break;
  6594. case 4:
  6595. case 7:
  6596. eff = new CheckboxEffect(effects[i], element, this);
  6597. break;
  6598. case 10:
  6599. eff = new LayerIndexEffect(effects[i], element, this);
  6600. break;
  6601. case 11:
  6602. eff = new MaskIndexEffect(effects[i], element, this);
  6603. break;
  6604. case 5:
  6605. eff = new EffectsManager(effects[i], element, this);
  6606. break;
  6607. // case 6:
  6608. default:
  6609. eff = new NoValueEffect(effects[i], element, this);
  6610. break;
  6611. }
  6612. if (eff) {
  6613. this.effectElements.push(eff);
  6614. }
  6615. }
  6616. };
  6617. function BaseElement() {
  6618. }
  6619. BaseElement.prototype = {
  6620. checkMasks: function () {
  6621. if (!this.data.hasMask) {
  6622. return false;
  6623. }
  6624. var i = 0;
  6625. var len = this.data.masksProperties.length;
  6626. while (i < len) {
  6627. if ((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) {
  6628. return true;
  6629. }
  6630. i += 1;
  6631. }
  6632. return false;
  6633. },
  6634. initExpressions: function () {
  6635. const expressionsInterfaces = getExpressionInterfaces();
  6636. if (!expressionsInterfaces) {
  6637. return;
  6638. }
  6639. const LayerExpressionInterface = expressionsInterfaces('layer');
  6640. const EffectsExpressionInterface = expressionsInterfaces('effects');
  6641. const ShapeExpressionInterface = expressionsInterfaces('shape');
  6642. const TextExpressionInterface = expressionsInterfaces('text');
  6643. const CompExpressionInterface = expressionsInterfaces('comp');
  6644. this.layerInterface = LayerExpressionInterface(this);
  6645. if (this.data.hasMask && this.maskManager) {
  6646. this.layerInterface.registerMaskInterface(this.maskManager);
  6647. }
  6648. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
  6649. this.layerInterface.registerEffectsInterface(effectsInterface);
  6650. if (this.data.ty === 0 || this.data.xt) {
  6651. this.compInterface = CompExpressionInterface(this);
  6652. } else if (this.data.ty === 4) {
  6653. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
  6654. this.layerInterface.content = this.layerInterface.shapeInterface;
  6655. } else if (this.data.ty === 5) {
  6656. this.layerInterface.textInterface = TextExpressionInterface(this);
  6657. this.layerInterface.text = this.layerInterface.textInterface;
  6658. }
  6659. },
  6660. setBlendMode: function () {
  6661. var blendModeValue = getBlendMode(this.data.bm);
  6662. var elem = this.baseElement || this.layerElement;
  6663. elem.style['mix-blend-mode'] = blendModeValue;
  6664. },
  6665. initBaseData: function (data, globalData, comp) {
  6666. this.globalData = globalData;
  6667. this.comp = comp;
  6668. this.data = data;
  6669. this.layerId = createElementID();
  6670. // Stretch factor for old animations missing this property.
  6671. if (!this.data.sr) {
  6672. this.data.sr = 1;
  6673. }
  6674. // effects manager
  6675. this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
  6676. },
  6677. getType: function () {
  6678. return this.type;
  6679. },
  6680. sourceRectAtTime: function () {},
  6681. };
  6682. /**
  6683. * @file
  6684. * Handles element's layer frame update.
  6685. * Checks layer in point and out point
  6686. *
  6687. */
  6688. function FrameElement() {}
  6689. FrameElement.prototype = {
  6690. /**
  6691. * @function
  6692. * Initializes frame related properties.
  6693. *
  6694. */
  6695. initFrame: function () {
  6696. // set to true when inpoint is rendered
  6697. this._isFirstFrame = false;
  6698. // list of animated properties
  6699. this.dynamicProperties = [];
  6700. // If layer has been modified in current tick this will be true
  6701. this._mdf = false;
  6702. },
  6703. /**
  6704. * @function
  6705. * Calculates all dynamic values
  6706. *
  6707. * @param {number} num
  6708. * current frame number in Layer's time
  6709. * @param {boolean} isVisible
  6710. * if layers is currently in range
  6711. *
  6712. */
  6713. prepareProperties: function (num, isVisible) {
  6714. var i;
  6715. var len = this.dynamicProperties.length;
  6716. for (i = 0; i < len; i += 1) {
  6717. if (isVisible || (this._isParent && this.dynamicProperties[i].propType === 'transform')) {
  6718. this.dynamicProperties[i].getValue();
  6719. if (this.dynamicProperties[i]._mdf) {
  6720. this.globalData._mdf = true;
  6721. this._mdf = true;
  6722. }
  6723. }
  6724. }
  6725. },
  6726. addDynamicProperty: function (prop) {
  6727. if (this.dynamicProperties.indexOf(prop) === -1) {
  6728. this.dynamicProperties.push(prop);
  6729. }
  6730. },
  6731. };
  6732. function FootageElement(data, globalData, comp) {
  6733. this.initFrame();
  6734. this.initRenderable();
  6735. this.assetData = globalData.getAssetData(data.refId);
  6736. this.footageData = globalData.imageLoader.getAsset(this.assetData);
  6737. this.initBaseData(data, globalData, comp);
  6738. }
  6739. FootageElement.prototype.prepareFrame = function () {
  6740. };
  6741. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  6742. FootageElement.prototype.getBaseElement = function () {
  6743. return null;
  6744. };
  6745. FootageElement.prototype.renderFrame = function () {
  6746. };
  6747. FootageElement.prototype.destroy = function () {
  6748. };
  6749. FootageElement.prototype.initExpressions = function () {
  6750. const expressionsInterfaces = getExpressionInterfaces();
  6751. if (!expressionsInterfaces) {
  6752. return;
  6753. }
  6754. const FootageInterface = expressionsInterfaces('footage');
  6755. this.layerInterface = FootageInterface(this);
  6756. };
  6757. FootageElement.prototype.getFootageData = function () {
  6758. return this.footageData;
  6759. };
  6760. function AudioElement(data, globalData, comp) {
  6761. this.initFrame();
  6762. this.initRenderable();
  6763. this.assetData = globalData.getAssetData(data.refId);
  6764. this.initBaseData(data, globalData, comp);
  6765. this._isPlaying = false;
  6766. this._canPlay = false;
  6767. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6768. this.audio = this.globalData.audioController.createAudio(assetPath);
  6769. this._currentTime = 0;
  6770. this.globalData.audioController.addAudio(this);
  6771. this._volumeMultiplier = 1;
  6772. this._volume = 1;
  6773. this._previousVolume = null;
  6774. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  6775. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : { k: [100] }, 1, 0.01, this);
  6776. }
  6777. AudioElement.prototype.prepareFrame = function (num) {
  6778. this.prepareRenderableFrame(num, true);
  6779. this.prepareProperties(num, true);
  6780. if (!this.tm._placeholder) {
  6781. var timeRemapped = this.tm.v;
  6782. this._currentTime = timeRemapped;
  6783. } else {
  6784. this._currentTime = num / this.data.sr;
  6785. }
  6786. this._volume = this.lv.v[0];
  6787. var totalVolume = this._volume * this._volumeMultiplier;
  6788. if (this._previousVolume !== totalVolume) {
  6789. this._previousVolume = totalVolume;
  6790. this.audio.volume(totalVolume);
  6791. }
  6792. };
  6793. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  6794. AudioElement.prototype.renderFrame = function () {
  6795. if (this.isInRange && this._canPlay) {
  6796. if (!this._isPlaying) {
  6797. this.audio.play();
  6798. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6799. this._isPlaying = true;
  6800. } else if (!this.audio.playing()
  6801. || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1
  6802. ) {
  6803. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6804. }
  6805. }
  6806. };
  6807. AudioElement.prototype.show = function () {
  6808. // this.audio.play()
  6809. };
  6810. AudioElement.prototype.hide = function () {
  6811. this.audio.pause();
  6812. this._isPlaying = false;
  6813. };
  6814. AudioElement.prototype.pause = function () {
  6815. this.audio.pause();
  6816. this._isPlaying = false;
  6817. this._canPlay = false;
  6818. };
  6819. AudioElement.prototype.resume = function () {
  6820. this._canPlay = true;
  6821. };
  6822. AudioElement.prototype.setRate = function (rateValue) {
  6823. this.audio.rate(rateValue);
  6824. };
  6825. AudioElement.prototype.volume = function (volumeValue) {
  6826. this._volumeMultiplier = volumeValue;
  6827. this._previousVolume = volumeValue * this._volume;
  6828. this.audio.volume(this._previousVolume);
  6829. };
  6830. AudioElement.prototype.getBaseElement = function () {
  6831. return null;
  6832. };
  6833. AudioElement.prototype.destroy = function () {
  6834. };
  6835. AudioElement.prototype.sourceRectAtTime = function () {
  6836. };
  6837. AudioElement.prototype.initExpressions = function () {
  6838. };
  6839. function BaseRenderer() {}
  6840. BaseRenderer.prototype.checkLayers = function (num) {
  6841. var i;
  6842. var len = this.layers.length;
  6843. var data;
  6844. this.completeLayers = true;
  6845. for (i = len - 1; i >= 0; i -= 1) {
  6846. if (!this.elements[i]) {
  6847. data = this.layers[i];
  6848. if (data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st)) {
  6849. this.buildItem(i);
  6850. }
  6851. }
  6852. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  6853. }
  6854. this.checkPendingElements();
  6855. };
  6856. BaseRenderer.prototype.createItem = function (layer) {
  6857. switch (layer.ty) {
  6858. case 2:
  6859. return this.createImage(layer);
  6860. case 0:
  6861. return this.createComp(layer);
  6862. case 1:
  6863. return this.createSolid(layer);
  6864. case 3:
  6865. return this.createNull(layer);
  6866. case 4:
  6867. return this.createShape(layer);
  6868. case 5:
  6869. return this.createText(layer);
  6870. case 6:
  6871. return this.createAudio(layer);
  6872. case 13:
  6873. return this.createCamera(layer);
  6874. case 15:
  6875. return this.createFootage(layer);
  6876. default:
  6877. return this.createNull(layer);
  6878. }
  6879. };
  6880. BaseRenderer.prototype.createCamera = function () {
  6881. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  6882. };
  6883. BaseRenderer.prototype.createAudio = function (data) {
  6884. return new AudioElement(data, this.globalData, this);
  6885. };
  6886. BaseRenderer.prototype.createFootage = function (data) {
  6887. return new FootageElement(data, this.globalData, this);
  6888. };
  6889. BaseRenderer.prototype.buildAllItems = function () {
  6890. var i;
  6891. var len = this.layers.length;
  6892. for (i = 0; i < len; i += 1) {
  6893. this.buildItem(i);
  6894. }
  6895. this.checkPendingElements();
  6896. };
  6897. BaseRenderer.prototype.includeLayers = function (newLayers) {
  6898. this.completeLayers = false;
  6899. var i;
  6900. var len = newLayers.length;
  6901. var j;
  6902. var jLen = this.layers.length;
  6903. for (i = 0; i < len; i += 1) {
  6904. j = 0;
  6905. while (j < jLen) {
  6906. if (this.layers[j].id === newLayers[i].id) {
  6907. this.layers[j] = newLayers[i];
  6908. break;
  6909. }
  6910. j += 1;
  6911. }
  6912. }
  6913. };
  6914. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  6915. this.globalData.projectInterface = pInterface;
  6916. };
  6917. BaseRenderer.prototype.initItems = function () {
  6918. if (!this.globalData.progressiveLoad) {
  6919. this.buildAllItems();
  6920. }
  6921. };
  6922. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  6923. var elements = this.elements;
  6924. var layers = this.layers;
  6925. var i = 0;
  6926. var len = layers.length;
  6927. while (i < len) {
  6928. if (layers[i].ind == parentName) { // eslint-disable-line eqeqeq
  6929. if (!elements[i] || elements[i] === true) {
  6930. this.buildItem(i);
  6931. this.addPendingElement(element);
  6932. } else {
  6933. hierarchy.push(elements[i]);
  6934. elements[i].setAsParent();
  6935. if (layers[i].parent !== undefined) {
  6936. this.buildElementParenting(element, layers[i].parent, hierarchy);
  6937. } else {
  6938. element.setHierarchy(hierarchy);
  6939. }
  6940. }
  6941. }
  6942. i += 1;
  6943. }
  6944. };
  6945. BaseRenderer.prototype.addPendingElement = function (element) {
  6946. this.pendingElements.push(element);
  6947. };
  6948. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  6949. var i;
  6950. var len = assets.length;
  6951. for (i = 0; i < len; i += 1) {
  6952. if (assets[i].xt) {
  6953. var comp = this.createComp(assets[i]);
  6954. comp.initExpressions();
  6955. this.globalData.projectInterface.registerComposition(comp);
  6956. }
  6957. }
  6958. };
  6959. BaseRenderer.prototype.getElementById = function (ind) {
  6960. var i;
  6961. var len = this.elements.length;
  6962. for (i = 0; i < len; i += 1) {
  6963. if (this.elements[i].data.ind === ind) {
  6964. return this.elements[i];
  6965. }
  6966. }
  6967. return null;
  6968. };
  6969. BaseRenderer.prototype.getElementByPath = function (path) {
  6970. var pathValue = path.shift();
  6971. var element;
  6972. if (typeof pathValue === 'number') {
  6973. element = this.elements[pathValue];
  6974. } else {
  6975. var i;
  6976. var len = this.elements.length;
  6977. for (i = 0; i < len; i += 1) {
  6978. if (this.elements[i].data.nm === pathValue) {
  6979. element = this.elements[i];
  6980. break;
  6981. }
  6982. }
  6983. }
  6984. if (path.length === 0) {
  6985. return element;
  6986. }
  6987. return element.getElementByPath(path);
  6988. };
  6989. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  6990. this.globalData.fontManager = new FontManager();
  6991. this.globalData.slotManager = slotFactory(animData);
  6992. this.globalData.fontManager.addChars(animData.chars);
  6993. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  6994. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  6995. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  6996. this.globalData.imageLoader = this.animationItem.imagePreloader;
  6997. this.globalData.audioController = this.animationItem.audioController;
  6998. this.globalData.frameId = 0;
  6999. this.globalData.frameRate = animData.fr;
  7000. this.globalData.nm = animData.nm;
  7001. this.globalData.compSize = {
  7002. w: animData.w,
  7003. h: animData.h,
  7004. };
  7005. };
  7006. var effectTypes = {
  7007. TRANSFORM_EFFECT: 'transformEFfect',
  7008. };
  7009. function TransformElement() {}
  7010. TransformElement.prototype = {
  7011. initTransform: function () {
  7012. var mat = new Matrix();
  7013. this.finalTransform = {
  7014. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : { o: 0 },
  7015. _matMdf: false,
  7016. _localMatMdf: false,
  7017. _opMdf: false,
  7018. mat: mat,
  7019. localMat: mat,
  7020. localOpacity: 1,
  7021. };
  7022. if (this.data.ao) {
  7023. this.finalTransform.mProp.autoOriented = true;
  7024. }
  7025. // TODO: check TYPE 11: Guided elements
  7026. if (this.data.ty !== 11) {
  7027. // this.createElements();
  7028. }
  7029. },
  7030. renderTransform: function () {
  7031. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  7032. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  7033. if (this.hierarchy) {
  7034. var mat;
  7035. var finalMat = this.finalTransform.mat;
  7036. var i = 0;
  7037. var len = this.hierarchy.length;
  7038. // Checking if any of the transformation matrices in the hierarchy chain has changed.
  7039. if (!this.finalTransform._matMdf) {
  7040. while (i < len) {
  7041. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  7042. this.finalTransform._matMdf = true;
  7043. break;
  7044. }
  7045. i += 1;
  7046. }
  7047. }
  7048. if (this.finalTransform._matMdf) {
  7049. mat = this.finalTransform.mProp.v.props;
  7050. finalMat.cloneFromProps(mat);
  7051. for (i = 0; i < len; i += 1) {
  7052. finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
  7053. }
  7054. }
  7055. }
  7056. if (!this.localTransforms || this.finalTransform._matMdf) {
  7057. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7058. }
  7059. if (this.finalTransform._opMdf) {
  7060. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7061. }
  7062. },
  7063. renderLocalTransform: function () {
  7064. if (this.localTransforms) {
  7065. var i = 0;
  7066. var len = this.localTransforms.length;
  7067. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7068. if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) {
  7069. while (i < len) {
  7070. if (this.localTransforms[i]._mdf) {
  7071. this.finalTransform._localMatMdf = true;
  7072. }
  7073. if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
  7074. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7075. this.finalTransform._opMdf = true;
  7076. }
  7077. i += 1;
  7078. }
  7079. }
  7080. if (this.finalTransform._localMatMdf) {
  7081. var localMat = this.finalTransform.localMat;
  7082. this.localTransforms[0].matrix.clone(localMat);
  7083. for (i = 1; i < len; i += 1) {
  7084. var lmat = this.localTransforms[i].matrix;
  7085. localMat.multiply(lmat);
  7086. }
  7087. localMat.multiply(this.finalTransform.mat);
  7088. }
  7089. if (this.finalTransform._opMdf) {
  7090. var localOp = this.finalTransform.localOpacity;
  7091. for (i = 0; i < len; i += 1) {
  7092. localOp *= this.localTransforms[i].opacity * 0.01;
  7093. }
  7094. this.finalTransform.localOpacity = localOp;
  7095. }
  7096. }
  7097. },
  7098. searchEffectTransforms: function () {
  7099. if (this.renderableEffectsManager) {
  7100. var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  7101. if (transformEffects.length) {
  7102. this.localTransforms = [];
  7103. this.finalTransform.localMat = new Matrix();
  7104. var i = 0;
  7105. var len = transformEffects.length;
  7106. for (i = 0; i < len; i += 1) {
  7107. this.localTransforms.push(transformEffects[i]);
  7108. }
  7109. }
  7110. }
  7111. },
  7112. globalToLocal: function (pt) {
  7113. var transforms = [];
  7114. transforms.push(this.finalTransform);
  7115. var flag = true;
  7116. var comp = this.comp;
  7117. while (flag) {
  7118. if (comp.finalTransform) {
  7119. if (comp.data.hasMask) {
  7120. transforms.splice(0, 0, comp.finalTransform);
  7121. }
  7122. comp = comp.comp;
  7123. } else {
  7124. flag = false;
  7125. }
  7126. }
  7127. var i;
  7128. var len = transforms.length;
  7129. var ptNew;
  7130. for (i = 0; i < len; i += 1) {
  7131. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  7132. // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7133. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7134. }
  7135. return pt;
  7136. },
  7137. mHelper: new Matrix(),
  7138. };
  7139. function MaskElement(data, element, globalData) {
  7140. this.data = data;
  7141. this.element = element;
  7142. this.globalData = globalData;
  7143. this.storedData = [];
  7144. this.masksProperties = this.data.masksProperties || [];
  7145. this.maskElement = null;
  7146. var defs = this.globalData.defs;
  7147. var i;
  7148. var len = this.masksProperties ? this.masksProperties.length : 0;
  7149. this.viewData = createSizedArray(len);
  7150. this.solidPath = '';
  7151. var path;
  7152. var properties = this.masksProperties;
  7153. var count = 0;
  7154. var currentMasks = [];
  7155. var j;
  7156. var jLen;
  7157. var layerId = createElementID();
  7158. var rect;
  7159. var expansor;
  7160. var feMorph;
  7161. var x;
  7162. var maskType = 'clipPath';
  7163. var maskRef = 'clip-path';
  7164. for (i = 0; i < len; i += 1) {
  7165. if ((properties[i].mode !== 'a' && properties[i].mode !== 'n') || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7166. maskType = 'mask';
  7167. maskRef = 'mask';
  7168. }
  7169. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7170. rect = createNS('rect');
  7171. rect.setAttribute('fill', '#ffffff');
  7172. rect.setAttribute('width', this.element.comp.data.w || 0);
  7173. rect.setAttribute('height', this.element.comp.data.h || 0);
  7174. currentMasks.push(rect);
  7175. } else {
  7176. rect = null;
  7177. }
  7178. path = createNS('path');
  7179. if (properties[i].mode === 'n') {
  7180. // TODO move this to a factory or to a constructor
  7181. this.viewData[i] = {
  7182. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7183. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7184. elem: path,
  7185. lastPath: '',
  7186. };
  7187. defs.appendChild(path);
  7188. } else {
  7189. count += 1;
  7190. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7191. path.setAttribute('clip-rule', 'nonzero');
  7192. var filterID;
  7193. if (properties[i].x.k !== 0) {
  7194. maskType = 'mask';
  7195. maskRef = 'mask';
  7196. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7197. filterID = createElementID();
  7198. expansor = createNS('filter');
  7199. expansor.setAttribute('id', filterID);
  7200. feMorph = createNS('feMorphology');
  7201. feMorph.setAttribute('operator', 'erode');
  7202. feMorph.setAttribute('in', 'SourceGraphic');
  7203. feMorph.setAttribute('radius', '0');
  7204. expansor.appendChild(feMorph);
  7205. defs.appendChild(expansor);
  7206. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7207. } else {
  7208. feMorph = null;
  7209. x = null;
  7210. }
  7211. // TODO move this to a factory or to a constructor
  7212. this.storedData[i] = {
  7213. elem: path,
  7214. x: x,
  7215. expan: feMorph,
  7216. lastPath: '',
  7217. lastOperator: '',
  7218. filterId: filterID,
  7219. lastRadius: 0,
  7220. };
  7221. if (properties[i].mode === 'i') {
  7222. jLen = currentMasks.length;
  7223. var g = createNS('g');
  7224. for (j = 0; j < jLen; j += 1) {
  7225. g.appendChild(currentMasks[j]);
  7226. }
  7227. var mask = createNS('mask');
  7228. mask.setAttribute('mask-type', 'alpha');
  7229. mask.setAttribute('id', layerId + '_' + count);
  7230. mask.appendChild(path);
  7231. defs.appendChild(mask);
  7232. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7233. currentMasks.length = 0;
  7234. currentMasks.push(g);
  7235. } else {
  7236. currentMasks.push(path);
  7237. }
  7238. if (properties[i].inv && !this.solidPath) {
  7239. this.solidPath = this.createLayerSolidPath();
  7240. }
  7241. // TODO move this to a factory or to a constructor
  7242. this.viewData[i] = {
  7243. elem: path,
  7244. lastPath: '',
  7245. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7246. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7247. invRect: rect,
  7248. };
  7249. if (!this.viewData[i].prop.k) {
  7250. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7251. }
  7252. }
  7253. }
  7254. this.maskElement = createNS(maskType);
  7255. len = currentMasks.length;
  7256. for (i = 0; i < len; i += 1) {
  7257. this.maskElement.appendChild(currentMasks[i]);
  7258. }
  7259. if (count > 0) {
  7260. this.maskElement.setAttribute('id', layerId);
  7261. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7262. defs.appendChild(this.maskElement);
  7263. }
  7264. if (this.viewData.length) {
  7265. this.element.addRenderableComponent(this);
  7266. }
  7267. }
  7268. MaskElement.prototype.getMaskProperty = function (pos) {
  7269. return this.viewData[pos].prop;
  7270. };
  7271. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7272. var finalMat = this.element.finalTransform.mat;
  7273. var i;
  7274. var len = this.masksProperties.length;
  7275. for (i = 0; i < len; i += 1) {
  7276. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7277. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7278. }
  7279. if (this.viewData[i].op._mdf || isFirstFrame) {
  7280. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7281. }
  7282. if (this.masksProperties[i].mode !== 'n') {
  7283. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7284. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7285. }
  7286. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7287. var feMorph = this.storedData[i].expan;
  7288. if (this.storedData[i].x.v < 0) {
  7289. if (this.storedData[i].lastOperator !== 'erode') {
  7290. this.storedData[i].lastOperator = 'erode';
  7291. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7292. }
  7293. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7294. } else {
  7295. if (this.storedData[i].lastOperator !== 'dilate') {
  7296. this.storedData[i].lastOperator = 'dilate';
  7297. this.storedData[i].elem.setAttribute('filter', null);
  7298. }
  7299. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7300. }
  7301. }
  7302. }
  7303. }
  7304. };
  7305. MaskElement.prototype.getMaskelement = function () {
  7306. return this.maskElement;
  7307. };
  7308. MaskElement.prototype.createLayerSolidPath = function () {
  7309. var path = 'M0,0 ';
  7310. path += ' h' + this.globalData.compSize.w;
  7311. path += ' v' + this.globalData.compSize.h;
  7312. path += ' h-' + this.globalData.compSize.w;
  7313. path += ' v-' + this.globalData.compSize.h + ' ';
  7314. return path;
  7315. };
  7316. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7317. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7318. var i;
  7319. var len;
  7320. len = pathNodes._length;
  7321. for (i = 1; i < len; i += 1) {
  7322. // pathString += " C"+pathNodes.o[i-1][0]+','+pathNodes.o[i-1][1] + " "+pathNodes.i[i][0]+','+pathNodes.i[i][1] + " "+pathNodes.v[i][0]+','+pathNodes.v[i][1];
  7323. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[i][0] + ',' + pathNodes.i[i][1] + ' ' + pathNodes.v[i][0] + ',' + pathNodes.v[i][1];
  7324. }
  7325. // pathString += " C"+pathNodes.o[i-1][0]+','+pathNodes.o[i-1][1] + " "+pathNodes.i[0][0]+','+pathNodes.i[0][1] + " "+pathNodes.v[0][0]+','+pathNodes.v[0][1];
  7326. if (pathNodes.c && len > 1) {
  7327. pathString += ' C' + pathNodes.o[i - 1][0] + ',' + pathNodes.o[i - 1][1] + ' ' + pathNodes.i[0][0] + ',' + pathNodes.i[0][1] + ' ' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7328. }
  7329. // pathNodes.__renderedString = pathString;
  7330. if (viewData.lastPath !== pathString) {
  7331. var pathShapeValue = '';
  7332. if (viewData.elem) {
  7333. if (pathNodes.c) {
  7334. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7335. }
  7336. viewData.elem.setAttribute('d', pathShapeValue);
  7337. }
  7338. viewData.lastPath = pathString;
  7339. }
  7340. };
  7341. MaskElement.prototype.destroy = function () {
  7342. this.element = null;
  7343. this.globalData = null;
  7344. this.maskElement = null;
  7345. this.data = null;
  7346. this.masksProperties = null;
  7347. };
  7348. const filtersFactory = (function () {
  7349. var ob = {};
  7350. ob.createFilter = createFilter;
  7351. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7352. function createFilter(filId, skipCoordinates) {
  7353. var fil = createNS('filter');
  7354. fil.setAttribute('id', filId);
  7355. if (skipCoordinates !== true) {
  7356. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7357. fil.setAttribute('x', '0%');
  7358. fil.setAttribute('y', '0%');
  7359. fil.setAttribute('width', '100%');
  7360. fil.setAttribute('height', '100%');
  7361. }
  7362. return fil;
  7363. }
  7364. function createAlphaToLuminanceFilter() {
  7365. var feColorMatrix = createNS('feColorMatrix');
  7366. feColorMatrix.setAttribute('type', 'matrix');
  7367. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7368. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7369. return feColorMatrix;
  7370. }
  7371. return ob;
  7372. }());
  7373. const featureSupport = (function () {
  7374. var ob = {
  7375. maskType: true,
  7376. svgLumaHidden: true,
  7377. offscreenCanvas: typeof OffscreenCanvas !== 'undefined',
  7378. };
  7379. if (/MSIE 10/i.test(navigator.userAgent) || /MSIE 9/i.test(navigator.userAgent) || /rv:11.0/i.test(navigator.userAgent) || /Edge\/\d./i.test(navigator.userAgent)) {
  7380. ob.maskType = false;
  7381. }
  7382. if (/firefox/i.test(navigator.userAgent)) {
  7383. ob.svgLumaHidden = false;
  7384. }
  7385. return ob;
  7386. }());
  7387. var registeredEffects$1 = {};
  7388. var idPrefix = 'filter_result_';
  7389. function SVGEffects(elem) {
  7390. var i;
  7391. var source = 'SourceGraphic';
  7392. var len = elem.data.ef ? elem.data.ef.length : 0;
  7393. var filId = createElementID();
  7394. var fil = filtersFactory.createFilter(filId, true);
  7395. var count = 0;
  7396. this.filters = [];
  7397. var filterManager;
  7398. for (i = 0; i < len; i += 1) {
  7399. filterManager = null;
  7400. var type = elem.data.ef[i].ty;
  7401. if (registeredEffects$1[type]) {
  7402. var Effect = registeredEffects$1[type].effect;
  7403. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7404. source = idPrefix + count;
  7405. if (registeredEffects$1[type].countsAsEffect) {
  7406. count += 1;
  7407. }
  7408. }
  7409. if (filterManager) {
  7410. this.filters.push(filterManager);
  7411. }
  7412. }
  7413. if (count) {
  7414. elem.globalData.defs.appendChild(fil);
  7415. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7416. }
  7417. if (this.filters.length) {
  7418. elem.addRenderableComponent(this);
  7419. }
  7420. }
  7421. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7422. var i;
  7423. var len = this.filters.length;
  7424. for (i = 0; i < len; i += 1) {
  7425. this.filters[i].renderFrame(_isFirstFrame);
  7426. }
  7427. };
  7428. SVGEffects.prototype.getEffects = function (type) {
  7429. var i;
  7430. var len = this.filters.length;
  7431. var effects = [];
  7432. for (i = 0; i < len; i += 1) {
  7433. if (this.filters[i].type === type) {
  7434. effects.push(this.filters[i]);
  7435. }
  7436. }
  7437. return effects;
  7438. };
  7439. function registerEffect$1(id, effect, countsAsEffect) {
  7440. registeredEffects$1[id] = {
  7441. effect,
  7442. countsAsEffect,
  7443. };
  7444. }
  7445. function SVGBaseElement() {
  7446. }
  7447. SVGBaseElement.prototype = {
  7448. initRendererElement: function () {
  7449. this.layerElement = createNS('g');
  7450. },
  7451. createContainerElements: function () {
  7452. this.matteElement = createNS('g');
  7453. this.transformedElement = this.layerElement;
  7454. this.maskedElement = this.layerElement;
  7455. this._sizeChanged = false;
  7456. var layerElementParent = null;
  7457. // If this layer acts as a mask for the following layer
  7458. if (this.data.td) {
  7459. this.matteMasks = {};
  7460. var gg = createNS('g');
  7461. gg.setAttribute('id', this.layerId);
  7462. gg.appendChild(this.layerElement);
  7463. layerElementParent = gg;
  7464. this.globalData.defs.appendChild(gg);
  7465. } else if (this.data.tt) {
  7466. this.matteElement.appendChild(this.layerElement);
  7467. layerElementParent = this.matteElement;
  7468. this.baseElement = this.matteElement;
  7469. } else {
  7470. this.baseElement = this.layerElement;
  7471. }
  7472. if (this.data.ln) {
  7473. this.layerElement.setAttribute('id', this.data.ln);
  7474. }
  7475. if (this.data.cl) {
  7476. this.layerElement.setAttribute('class', this.data.cl);
  7477. }
  7478. // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7479. if (this.data.ty === 0 && !this.data.hd) {
  7480. var cp = createNS('clipPath');
  7481. var pt = createNS('path');
  7482. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7483. var clipId = createElementID();
  7484. cp.setAttribute('id', clipId);
  7485. cp.appendChild(pt);
  7486. this.globalData.defs.appendChild(cp);
  7487. if (this.checkMasks()) {
  7488. var cpGroup = createNS('g');
  7489. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7490. cpGroup.appendChild(this.layerElement);
  7491. this.transformedElement = cpGroup;
  7492. if (layerElementParent) {
  7493. layerElementParent.appendChild(this.transformedElement);
  7494. } else {
  7495. this.baseElement = this.transformedElement;
  7496. }
  7497. } else {
  7498. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7499. }
  7500. }
  7501. if (this.data.bm !== 0) {
  7502. this.setBlendMode();
  7503. }
  7504. },
  7505. renderElement: function () {
  7506. if (this.finalTransform._localMatMdf) {
  7507. this.transformedElement.setAttribute('transform', this.finalTransform.localMat.to2dCSS());
  7508. }
  7509. if (this.finalTransform._opMdf) {
  7510. this.transformedElement.setAttribute('opacity', this.finalTransform.localOpacity);
  7511. }
  7512. },
  7513. destroyBaseElement: function () {
  7514. this.layerElement = null;
  7515. this.matteElement = null;
  7516. this.maskManager.destroy();
  7517. },
  7518. getBaseElement: function () {
  7519. if (this.data.hd) {
  7520. return null;
  7521. }
  7522. return this.baseElement;
  7523. },
  7524. createRenderableComponents: function () {
  7525. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7526. this.renderableEffectsManager = new SVGEffects(this);
  7527. this.searchEffectTransforms();
  7528. },
  7529. getMatte: function (matteType) {
  7530. // This should not be a common case. But for backward compatibility, we'll create the matte object.
  7531. // It solves animations that have two consecutive layers marked as matte masks.
  7532. // Which is an undefined behavior in AE.
  7533. if (!this.matteMasks) {
  7534. this.matteMasks = {};
  7535. }
  7536. if (!this.matteMasks[matteType]) {
  7537. var id = this.layerId + '_' + matteType;
  7538. var filId;
  7539. var fil;
  7540. var useElement;
  7541. var gg;
  7542. if (matteType === 1 || matteType === 3) {
  7543. var masker = createNS('mask');
  7544. masker.setAttribute('id', id);
  7545. masker.setAttribute('mask-type', matteType === 3 ? 'luminance' : 'alpha');
  7546. useElement = createNS('use');
  7547. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7548. masker.appendChild(useElement);
  7549. this.globalData.defs.appendChild(masker);
  7550. if (!featureSupport.maskType && matteType === 1) {
  7551. masker.setAttribute('mask-type', 'luminance');
  7552. filId = createElementID();
  7553. fil = filtersFactory.createFilter(filId);
  7554. this.globalData.defs.appendChild(fil);
  7555. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7556. gg = createNS('g');
  7557. gg.appendChild(useElement);
  7558. masker.appendChild(gg);
  7559. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7560. }
  7561. } else if (matteType === 2) {
  7562. var maskGroup = createNS('mask');
  7563. maskGroup.setAttribute('id', id);
  7564. maskGroup.setAttribute('mask-type', 'alpha');
  7565. var maskGrouper = createNS('g');
  7566. maskGroup.appendChild(maskGrouper);
  7567. filId = createElementID();
  7568. fil = filtersFactory.createFilter(filId);
  7569. /// /
  7570. var feCTr = createNS('feComponentTransfer');
  7571. feCTr.setAttribute('in', 'SourceGraphic');
  7572. fil.appendChild(feCTr);
  7573. var feFunc = createNS('feFuncA');
  7574. feFunc.setAttribute('type', 'table');
  7575. feFunc.setAttribute('tableValues', '1.0 0.0');
  7576. feCTr.appendChild(feFunc);
  7577. /// /
  7578. this.globalData.defs.appendChild(fil);
  7579. var alphaRect = createNS('rect');
  7580. alphaRect.setAttribute('width', this.comp.data.w);
  7581. alphaRect.setAttribute('height', this.comp.data.h);
  7582. alphaRect.setAttribute('x', '0');
  7583. alphaRect.setAttribute('y', '0');
  7584. alphaRect.setAttribute('fill', '#ffffff');
  7585. alphaRect.setAttribute('opacity', '0');
  7586. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7587. maskGrouper.appendChild(alphaRect);
  7588. useElement = createNS('use');
  7589. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7590. maskGrouper.appendChild(useElement);
  7591. if (!featureSupport.maskType) {
  7592. maskGroup.setAttribute('mask-type', 'luminance');
  7593. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7594. gg = createNS('g');
  7595. maskGrouper.appendChild(alphaRect);
  7596. gg.appendChild(this.layerElement);
  7597. maskGrouper.appendChild(gg);
  7598. }
  7599. this.globalData.defs.appendChild(maskGroup);
  7600. }
  7601. this.matteMasks[matteType] = id;
  7602. }
  7603. return this.matteMasks[matteType];
  7604. },
  7605. setMatte: function (id) {
  7606. if (!this.matteElement) {
  7607. return;
  7608. }
  7609. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7610. },
  7611. };
  7612. /**
  7613. * @file
  7614. * Handles AE's layer parenting property.
  7615. *
  7616. */
  7617. function HierarchyElement() {}
  7618. HierarchyElement.prototype = {
  7619. /**
  7620. * @function
  7621. * Initializes hierarchy properties
  7622. *
  7623. */
  7624. initHierarchy: function () {
  7625. // element's parent list
  7626. this.hierarchy = [];
  7627. // if element is parent of another layer _isParent will be true
  7628. this._isParent = false;
  7629. this.checkParenting();
  7630. },
  7631. /**
  7632. * @function
  7633. * Sets layer's hierarchy.
  7634. * @param {array} hierarch
  7635. * layer's parent list
  7636. *
  7637. */
  7638. setHierarchy: function (hierarchy) {
  7639. this.hierarchy = hierarchy;
  7640. },
  7641. /**
  7642. * @function
  7643. * Sets layer as parent.
  7644. *
  7645. */
  7646. setAsParent: function () {
  7647. this._isParent = true;
  7648. },
  7649. /**
  7650. * @function
  7651. * Searches layer's parenting chain
  7652. *
  7653. */
  7654. checkParenting: function () {
  7655. if (this.data.parent !== undefined) {
  7656. this.comp.buildElementParenting(this, this.data.parent, []);
  7657. }
  7658. },
  7659. };
  7660. function RenderableDOMElement() {}
  7661. (function () {
  7662. var _prototype = {
  7663. initElement: function (data, globalData, comp) {
  7664. this.initFrame();
  7665. this.initBaseData(data, globalData, comp);
  7666. this.initTransform(data, globalData, comp);
  7667. this.initHierarchy();
  7668. this.initRenderable();
  7669. this.initRendererElement();
  7670. this.createContainerElements();
  7671. this.createRenderableComponents();
  7672. this.createContent();
  7673. this.hide();
  7674. },
  7675. hide: function () {
  7676. // console.log('HIDE', this);
  7677. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7678. var elem = this.baseElement || this.layerElement;
  7679. elem.style.display = 'none';
  7680. this.hidden = true;
  7681. }
  7682. },
  7683. show: function () {
  7684. // console.log('SHOW', this);
  7685. if (this.isInRange && !this.isTransparent) {
  7686. if (!this.data.hd) {
  7687. var elem = this.baseElement || this.layerElement;
  7688. elem.style.display = 'block';
  7689. }
  7690. this.hidden = false;
  7691. this._isFirstFrame = true;
  7692. }
  7693. },
  7694. renderFrame: function () {
  7695. // If it is exported as hidden (data.hd === true) no need to render
  7696. // If it is not visible no need to render
  7697. if (this.data.hd || this.hidden) {
  7698. return;
  7699. }
  7700. this.renderTransform();
  7701. this.renderRenderable();
  7702. this.renderLocalTransform();
  7703. this.renderElement();
  7704. this.renderInnerContent();
  7705. if (this._isFirstFrame) {
  7706. this._isFirstFrame = false;
  7707. }
  7708. },
  7709. renderInnerContent: function () {},
  7710. prepareFrame: function (num) {
  7711. this._mdf = false;
  7712. this.prepareRenderableFrame(num);
  7713. this.prepareProperties(num, this.isInRange);
  7714. this.checkTransparency();
  7715. },
  7716. destroy: function () {
  7717. this.innerElem = null;
  7718. this.destroyBaseElement();
  7719. },
  7720. };
  7721. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  7722. }());
  7723. function IImageElement(data, globalData, comp) {
  7724. this.assetData = globalData.getAssetData(data.refId);
  7725. if (this.assetData && this.assetData.sid) {
  7726. this.assetData = globalData.slotManager.getProp(this.assetData);
  7727. }
  7728. this.initElement(data, globalData, comp);
  7729. this.sourceRect = {
  7730. top: 0, left: 0, width: this.assetData.w, height: this.assetData.h,
  7731. };
  7732. }
  7733. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  7734. IImageElement.prototype.createContent = function () {
  7735. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7736. this.innerElem = createNS('image');
  7737. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  7738. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  7739. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7740. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  7741. this.layerElement.appendChild(this.innerElem);
  7742. };
  7743. IImageElement.prototype.sourceRectAtTime = function () {
  7744. return this.sourceRect;
  7745. };
  7746. function ProcessedElement(element, position) {
  7747. this.elem = element;
  7748. this.pos = position;
  7749. }
  7750. function IShapeElement() {
  7751. }
  7752. IShapeElement.prototype = {
  7753. addShapeToModifiers: function (data) {
  7754. var i;
  7755. var len = this.shapeModifiers.length;
  7756. for (i = 0; i < len; i += 1) {
  7757. this.shapeModifiers[i].addShape(data);
  7758. }
  7759. },
  7760. isShapeInAnimatedModifiers: function (data) {
  7761. var i = 0;
  7762. var len = this.shapeModifiers.length;
  7763. while (i < len) {
  7764. if (this.shapeModifiers[i].isAnimatedWithShape(data)) {
  7765. return true;
  7766. }
  7767. }
  7768. return false;
  7769. },
  7770. renderModifiers: function () {
  7771. if (!this.shapeModifiers.length) {
  7772. return;
  7773. }
  7774. var i;
  7775. var len = this.shapes.length;
  7776. for (i = 0; i < len; i += 1) {
  7777. this.shapes[i].sh.reset();
  7778. }
  7779. len = this.shapeModifiers.length;
  7780. var shouldBreakProcess;
  7781. for (i = len - 1; i >= 0; i -= 1) {
  7782. shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame);
  7783. // workaround to fix cases where a repeater resets the shape so the following processes get called twice
  7784. // TODO: find a better solution for this
  7785. if (shouldBreakProcess) {
  7786. break;
  7787. }
  7788. }
  7789. },
  7790. searchProcessedElement: function (elem) {
  7791. var elements = this.processedElements;
  7792. var i = 0;
  7793. var len = elements.length;
  7794. while (i < len) {
  7795. if (elements[i].elem === elem) {
  7796. return elements[i].pos;
  7797. }
  7798. i += 1;
  7799. }
  7800. return 0;
  7801. },
  7802. addProcessedElement: function (elem, pos) {
  7803. var elements = this.processedElements;
  7804. var i = elements.length;
  7805. while (i) {
  7806. i -= 1;
  7807. if (elements[i].elem === elem) {
  7808. elements[i].pos = pos;
  7809. return;
  7810. }
  7811. }
  7812. elements.push(new ProcessedElement(elem, pos));
  7813. },
  7814. prepareFrame: function (num) {
  7815. this.prepareRenderableFrame(num);
  7816. this.prepareProperties(num, this.isInRange);
  7817. },
  7818. };
  7819. const lineCapEnum = {
  7820. 1: 'butt',
  7821. 2: 'round',
  7822. 3: 'square',
  7823. };
  7824. const lineJoinEnum = {
  7825. 1: 'miter',
  7826. 2: 'round',
  7827. 3: 'bevel',
  7828. };
  7829. function SVGShapeData(transformers, level, shape) {
  7830. this.caches = [];
  7831. this.styles = [];
  7832. this.transformers = transformers;
  7833. this.lStr = '';
  7834. this.sh = shape;
  7835. this.lvl = level;
  7836. // TODO find if there are some cases where _isAnimated can be false.
  7837. // For now, since shapes add up with other shapes. They have to be calculated every time.
  7838. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  7839. this._isAnimated = !!shape.k;
  7840. // TODO: commenting this for now since all shapes are animated
  7841. var i = 0;
  7842. var len = transformers.length;
  7843. while (i < len) {
  7844. if (transformers[i].mProps.dynamicProperties.length) {
  7845. this._isAnimated = true;
  7846. break;
  7847. }
  7848. i += 1;
  7849. }
  7850. }
  7851. SVGShapeData.prototype.setAsAnimated = function () {
  7852. this._isAnimated = true;
  7853. };
  7854. function SVGStyleData(data, level) {
  7855. this.data = data;
  7856. this.type = data.ty;
  7857. this.d = '';
  7858. this.lvl = level;
  7859. this._mdf = false;
  7860. this.closed = data.hd === true;
  7861. this.pElem = createNS('path');
  7862. this.msElem = null;
  7863. }
  7864. SVGStyleData.prototype.reset = function () {
  7865. this.d = '';
  7866. this._mdf = false;
  7867. };
  7868. function DashProperty(elem, data, renderer, container) {
  7869. this.elem = elem;
  7870. this.frameId = -1;
  7871. this.dataProps = createSizedArray(data.length);
  7872. this.renderer = renderer;
  7873. this.k = false;
  7874. this.dashStr = '';
  7875. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  7876. this.dashoffset = createTypedArray('float32', 1);
  7877. this.initDynamicPropertyContainer(container);
  7878. var i;
  7879. var len = data.length || 0;
  7880. var prop;
  7881. for (i = 0; i < len; i += 1) {
  7882. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  7883. this.k = prop.k || this.k;
  7884. this.dataProps[i] = { n: data[i].n, p: prop };
  7885. }
  7886. if (!this.k) {
  7887. this.getValue(true);
  7888. }
  7889. this._isAnimated = this.k;
  7890. }
  7891. DashProperty.prototype.getValue = function (forceRender) {
  7892. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  7893. return;
  7894. }
  7895. this.frameId = this.elem.globalData.frameId;
  7896. this.iterateDynamicProperties();
  7897. this._mdf = this._mdf || forceRender;
  7898. if (this._mdf) {
  7899. var i = 0;
  7900. var len = this.dataProps.length;
  7901. if (this.renderer === 'svg') {
  7902. this.dashStr = '';
  7903. }
  7904. for (i = 0; i < len; i += 1) {
  7905. if (this.dataProps[i].n !== 'o') {
  7906. if (this.renderer === 'svg') {
  7907. this.dashStr += ' ' + this.dataProps[i].p.v;
  7908. } else {
  7909. this.dashArray[i] = this.dataProps[i].p.v;
  7910. }
  7911. } else {
  7912. this.dashoffset[0] = this.dataProps[i].p.v;
  7913. }
  7914. }
  7915. }
  7916. };
  7917. extendPrototype([DynamicPropertyContainer], DashProperty);
  7918. function SVGStrokeStyleData(elem, data, styleOb) {
  7919. this.initDynamicPropertyContainer(elem);
  7920. this.getValue = this.iterateDynamicProperties;
  7921. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7922. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  7923. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  7924. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7925. this.style = styleOb;
  7926. this._isAnimated = !!this._isAnimated;
  7927. }
  7928. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  7929. function SVGFillStyleData(elem, data, styleOb) {
  7930. this.initDynamicPropertyContainer(elem);
  7931. this.getValue = this.iterateDynamicProperties;
  7932. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7933. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7934. this.style = styleOb;
  7935. }
  7936. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  7937. function SVGNoStyleData(elem, data, styleOb) {
  7938. this.initDynamicPropertyContainer(elem);
  7939. this.getValue = this.iterateDynamicProperties;
  7940. this.style = styleOb;
  7941. }
  7942. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  7943. function GradientProperty(elem, data, container) {
  7944. this.data = data;
  7945. this.c = createTypedArray('uint8c', data.p * 4);
  7946. var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p * 4) : data.k.k.length - data.p * 4;
  7947. this.o = createTypedArray('float32', cLength);
  7948. this._cmdf = false;
  7949. this._omdf = false;
  7950. this._collapsable = this.checkCollapsable();
  7951. this._hasOpacity = cLength;
  7952. this.initDynamicPropertyContainer(container);
  7953. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  7954. this.k = this.prop.k;
  7955. this.getValue(true);
  7956. }
  7957. GradientProperty.prototype.comparePoints = function (values, points) {
  7958. var i = 0;
  7959. var len = this.o.length / 2;
  7960. var diff;
  7961. while (i < len) {
  7962. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  7963. if (diff > 0.01) {
  7964. return false;
  7965. }
  7966. i += 1;
  7967. }
  7968. return true;
  7969. };
  7970. GradientProperty.prototype.checkCollapsable = function () {
  7971. if (this.o.length / 2 !== this.c.length / 4) {
  7972. return false;
  7973. }
  7974. if (this.data.k.k[0].s) {
  7975. var i = 0;
  7976. var len = this.data.k.k.length;
  7977. while (i < len) {
  7978. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  7979. return false;
  7980. }
  7981. i += 1;
  7982. }
  7983. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  7984. return false;
  7985. }
  7986. return true;
  7987. };
  7988. GradientProperty.prototype.getValue = function (forceRender) {
  7989. this.prop.getValue();
  7990. this._mdf = false;
  7991. this._cmdf = false;
  7992. this._omdf = false;
  7993. if (this.prop._mdf || forceRender) {
  7994. var i;
  7995. var len = this.data.p * 4;
  7996. var mult;
  7997. var val;
  7998. for (i = 0; i < len; i += 1) {
  7999. mult = i % 4 === 0 ? 100 : 255;
  8000. val = Math.round(this.prop.v[i] * mult);
  8001. if (this.c[i] !== val) {
  8002. this.c[i] = val;
  8003. this._cmdf = !forceRender;
  8004. }
  8005. }
  8006. if (this.o.length) {
  8007. len = this.prop.v.length;
  8008. for (i = this.data.p * 4; i < len; i += 1) {
  8009. mult = i % 2 === 0 ? 100 : 1;
  8010. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  8011. if (this.o[i - this.data.p * 4] !== val) {
  8012. this.o[i - this.data.p * 4] = val;
  8013. this._omdf = !forceRender;
  8014. }
  8015. }
  8016. }
  8017. this._mdf = !forceRender;
  8018. }
  8019. };
  8020. extendPrototype([DynamicPropertyContainer], GradientProperty);
  8021. function SVGGradientFillStyleData(elem, data, styleOb) {
  8022. this.initDynamicPropertyContainer(elem);
  8023. this.getValue = this.iterateDynamicProperties;
  8024. this.initGradientData(elem, data, styleOb);
  8025. }
  8026. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  8027. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8028. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  8029. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  8030. this.h = PropertyFactory.getProp(elem, data.h || { k: 0 }, 0, 0.01, this);
  8031. this.a = PropertyFactory.getProp(elem, data.a || { k: 0 }, 0, degToRads, this);
  8032. this.g = new GradientProperty(elem, data.g, this);
  8033. this.style = styleOb;
  8034. this.stops = [];
  8035. this.setGradientData(styleOb.pElem, data);
  8036. this.setGradientOpacity(data, styleOb);
  8037. this._isAnimated = !!this._isAnimated;
  8038. };
  8039. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  8040. var gradientId = createElementID();
  8041. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8042. gfill.setAttribute('id', gradientId);
  8043. gfill.setAttribute('spreadMethod', 'pad');
  8044. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8045. var stops = [];
  8046. var stop;
  8047. var j;
  8048. var jLen;
  8049. jLen = data.g.p * 4;
  8050. for (j = 0; j < jLen; j += 4) {
  8051. stop = createNS('stop');
  8052. gfill.appendChild(stop);
  8053. stops.push(stop);
  8054. }
  8055. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  8056. this.gf = gfill;
  8057. this.cst = stops;
  8058. };
  8059. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  8060. if (this.g._hasOpacity && !this.g._collapsable) {
  8061. var stop;
  8062. var j;
  8063. var jLen;
  8064. var mask = createNS('mask');
  8065. var maskElement = createNS('path');
  8066. mask.appendChild(maskElement);
  8067. var opacityId = createElementID();
  8068. var maskId = createElementID();
  8069. mask.setAttribute('id', maskId);
  8070. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8071. opFill.setAttribute('id', opacityId);
  8072. opFill.setAttribute('spreadMethod', 'pad');
  8073. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8074. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8075. var stops = this.stops;
  8076. for (j = data.g.p * 4; j < jLen; j += 2) {
  8077. stop = createNS('stop');
  8078. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8079. opFill.appendChild(stop);
  8080. stops.push(stop);
  8081. }
  8082. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8083. if (data.ty === 'gs') {
  8084. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8085. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8086. if (data.lj === 1) {
  8087. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8088. }
  8089. }
  8090. this.of = opFill;
  8091. this.ms = mask;
  8092. this.ost = stops;
  8093. this.maskId = maskId;
  8094. styleOb.msElem = maskElement;
  8095. }
  8096. };
  8097. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8098. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8099. this.initDynamicPropertyContainer(elem);
  8100. this.getValue = this.iterateDynamicProperties;
  8101. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8102. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8103. this.initGradientData(elem, data, styleOb);
  8104. this._isAnimated = !!this._isAnimated;
  8105. }
  8106. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8107. function ShapeGroupData() {
  8108. this.it = [];
  8109. this.prevViewData = [];
  8110. this.gr = createNS('g');
  8111. }
  8112. function SVGTransformData(mProps, op, container) {
  8113. this.transform = {
  8114. mProps: mProps,
  8115. op: op,
  8116. container: container,
  8117. };
  8118. this.elements = [];
  8119. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8120. }
  8121. const buildShapeString = function (pathNodes, length, closed, mat) {
  8122. if (length === 0) {
  8123. return '';
  8124. }
  8125. var _o = pathNodes.o;
  8126. var _i = pathNodes.i;
  8127. var _v = pathNodes.v;
  8128. var i;
  8129. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8130. for (i = 1; i < length; i += 1) {
  8131. shapeString += ' C' + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + ' ' + mat.applyToPointStringified(_i[i][0], _i[i][1]) + ' ' + mat.applyToPointStringified(_v[i][0], _v[i][1]);
  8132. }
  8133. if (closed && length) {
  8134. shapeString += ' C' + mat.applyToPointStringified(_o[i - 1][0], _o[i - 1][1]) + ' ' + mat.applyToPointStringified(_i[0][0], _i[0][1]) + ' ' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8135. shapeString += 'z';
  8136. }
  8137. return shapeString;
  8138. };
  8139. const SVGElementsRenderer = (function () {
  8140. var _identityMatrix = new Matrix();
  8141. var _matrixHelper = new Matrix();
  8142. var ob = {
  8143. createRenderFunction: createRenderFunction,
  8144. };
  8145. function createRenderFunction(data) {
  8146. switch (data.ty) {
  8147. case 'fl':
  8148. return renderFill;
  8149. case 'gf':
  8150. return renderGradient;
  8151. case 'gs':
  8152. return renderGradientStroke;
  8153. case 'st':
  8154. return renderStroke;
  8155. case 'sh':
  8156. case 'el':
  8157. case 'rc':
  8158. case 'sr':
  8159. return renderPath;
  8160. case 'tr':
  8161. return renderContentTransform;
  8162. case 'no':
  8163. return renderNoop;
  8164. default:
  8165. return null;
  8166. }
  8167. }
  8168. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8169. if (isFirstFrame || itemData.transform.op._mdf) {
  8170. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8171. }
  8172. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8173. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8174. }
  8175. }
  8176. function renderNoop() {
  8177. }
  8178. function renderPath(styleData, itemData, isFirstFrame) {
  8179. var j;
  8180. var jLen;
  8181. var pathStringTransformed;
  8182. var redraw;
  8183. var pathNodes;
  8184. var l;
  8185. var lLen = itemData.styles.length;
  8186. var lvl = itemData.lvl;
  8187. var paths;
  8188. var mat;
  8189. var iterations;
  8190. var k;
  8191. for (l = 0; l < lLen; l += 1) {
  8192. redraw = itemData.sh._mdf || isFirstFrame;
  8193. if (itemData.styles[l].lvl < lvl) {
  8194. mat = _matrixHelper.reset();
  8195. iterations = lvl - itemData.styles[l].lvl;
  8196. k = itemData.transformers.length - 1;
  8197. while (!redraw && iterations > 0) {
  8198. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8199. iterations -= 1;
  8200. k -= 1;
  8201. }
  8202. if (redraw) {
  8203. iterations = lvl - itemData.styles[l].lvl;
  8204. k = itemData.transformers.length - 1;
  8205. while (iterations > 0) {
  8206. mat.multiply(itemData.transformers[k].mProps.v);
  8207. iterations -= 1;
  8208. k -= 1;
  8209. }
  8210. }
  8211. } else {
  8212. mat = _identityMatrix;
  8213. }
  8214. paths = itemData.sh.paths;
  8215. jLen = paths._length;
  8216. if (redraw) {
  8217. pathStringTransformed = '';
  8218. for (j = 0; j < jLen; j += 1) {
  8219. pathNodes = paths.shapes[j];
  8220. if (pathNodes && pathNodes._length) {
  8221. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8222. }
  8223. }
  8224. itemData.caches[l] = pathStringTransformed;
  8225. } else {
  8226. pathStringTransformed = itemData.caches[l];
  8227. }
  8228. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8229. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8230. }
  8231. }
  8232. function renderFill(styleData, itemData, isFirstFrame) {
  8233. var styleElem = itemData.style;
  8234. if (itemData.c._mdf || isFirstFrame) {
  8235. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8236. }
  8237. if (itemData.o._mdf || isFirstFrame) {
  8238. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8239. }
  8240. }
  8241. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8242. renderGradient(styleData, itemData, isFirstFrame);
  8243. renderStroke(styleData, itemData, isFirstFrame);
  8244. }
  8245. function renderGradient(styleData, itemData, isFirstFrame) {
  8246. var gfill = itemData.gf;
  8247. var hasOpacity = itemData.g._hasOpacity;
  8248. var pt1 = itemData.s.v;
  8249. var pt2 = itemData.e.v;
  8250. if (itemData.o._mdf || isFirstFrame) {
  8251. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8252. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8253. }
  8254. if (itemData.s._mdf || isFirstFrame) {
  8255. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8256. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8257. gfill.setAttribute(attr1, pt1[0]);
  8258. gfill.setAttribute(attr2, pt1[1]);
  8259. if (hasOpacity && !itemData.g._collapsable) {
  8260. itemData.of.setAttribute(attr1, pt1[0]);
  8261. itemData.of.setAttribute(attr2, pt1[1]);
  8262. }
  8263. }
  8264. var stops;
  8265. var i;
  8266. var len;
  8267. var stop;
  8268. if (itemData.g._cmdf || isFirstFrame) {
  8269. stops = itemData.cst;
  8270. var cValues = itemData.g.c;
  8271. len = stops.length;
  8272. for (i = 0; i < len; i += 1) {
  8273. stop = stops[i];
  8274. stop.setAttribute('offset', cValues[i * 4] + '%');
  8275. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8276. }
  8277. }
  8278. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8279. var oValues = itemData.g.o;
  8280. if (itemData.g._collapsable) {
  8281. stops = itemData.cst;
  8282. } else {
  8283. stops = itemData.ost;
  8284. }
  8285. len = stops.length;
  8286. for (i = 0; i < len; i += 1) {
  8287. stop = stops[i];
  8288. if (!itemData.g._collapsable) {
  8289. stop.setAttribute('offset', oValues[i * 2] + '%');
  8290. }
  8291. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8292. }
  8293. }
  8294. if (styleData.t === 1) {
  8295. if (itemData.e._mdf || isFirstFrame) {
  8296. gfill.setAttribute('x2', pt2[0]);
  8297. gfill.setAttribute('y2', pt2[1]);
  8298. if (hasOpacity && !itemData.g._collapsable) {
  8299. itemData.of.setAttribute('x2', pt2[0]);
  8300. itemData.of.setAttribute('y2', pt2[1]);
  8301. }
  8302. }
  8303. } else {
  8304. var rad;
  8305. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8306. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8307. gfill.setAttribute('r', rad);
  8308. if (hasOpacity && !itemData.g._collapsable) {
  8309. itemData.of.setAttribute('r', rad);
  8310. }
  8311. }
  8312. if (itemData.s._mdf || itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8313. if (!rad) {
  8314. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8315. }
  8316. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8317. var percent = itemData.h.v;
  8318. if (percent >= 1) {
  8319. percent = 0.99;
  8320. } else if (percent <= -1) {
  8321. percent = -0.99;
  8322. }
  8323. var dist = rad * percent;
  8324. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8325. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8326. gfill.setAttribute('fx', x);
  8327. gfill.setAttribute('fy', y);
  8328. if (hasOpacity && !itemData.g._collapsable) {
  8329. itemData.of.setAttribute('fx', x);
  8330. itemData.of.setAttribute('fy', y);
  8331. }
  8332. }
  8333. // gfill.setAttribute('fy','200');
  8334. }
  8335. }
  8336. function renderStroke(styleData, itemData, isFirstFrame) {
  8337. var styleElem = itemData.style;
  8338. var d = itemData.d;
  8339. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8340. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8341. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8342. }
  8343. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8344. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8345. }
  8346. if (itemData.o._mdf || isFirstFrame) {
  8347. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8348. }
  8349. if (itemData.w._mdf || isFirstFrame) {
  8350. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8351. if (styleElem.msElem) {
  8352. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8353. }
  8354. }
  8355. }
  8356. return ob;
  8357. }());
  8358. function SVGShapeElement(data, globalData, comp) {
  8359. // List of drawable elements
  8360. this.shapes = [];
  8361. // Full shape data
  8362. this.shapesData = data.shapes;
  8363. // List of styles that will be applied to shapes
  8364. this.stylesList = [];
  8365. // List of modifiers that will be applied to shapes
  8366. this.shapeModifiers = [];
  8367. // List of items in shape tree
  8368. this.itemsData = [];
  8369. // List of items in previous shape tree
  8370. this.processedElements = [];
  8371. // List of animated components
  8372. this.animatedContents = [];
  8373. this.initElement(data, globalData, comp);
  8374. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8375. // List of elements that have been created
  8376. this.prevViewData = [];
  8377. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8378. }
  8379. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8380. SVGShapeElement.prototype.initSecondaryElement = function () {
  8381. };
  8382. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8383. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8384. SVGShapeElement.prototype.createContent = function () {
  8385. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8386. this.filterUniqueShapes();
  8387. };
  8388. /*
  8389. This method searches for multiple shapes that affect a single element and one of them is animated
  8390. */
  8391. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8392. var i;
  8393. var len = this.shapes.length;
  8394. var shape;
  8395. var j;
  8396. var jLen = this.stylesList.length;
  8397. var style;
  8398. var tempShapes = [];
  8399. var areAnimated = false;
  8400. for (j = 0; j < jLen; j += 1) {
  8401. style = this.stylesList[j];
  8402. areAnimated = false;
  8403. tempShapes.length = 0;
  8404. for (i = 0; i < len; i += 1) {
  8405. shape = this.shapes[i];
  8406. if (shape.styles.indexOf(style) !== -1) {
  8407. tempShapes.push(shape);
  8408. areAnimated = shape._isAnimated || areAnimated;
  8409. }
  8410. }
  8411. if (tempShapes.length > 1 && areAnimated) {
  8412. this.setShapesAsAnimated(tempShapes);
  8413. }
  8414. }
  8415. };
  8416. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8417. var i;
  8418. var len = shapes.length;
  8419. for (i = 0; i < len; i += 1) {
  8420. shapes[i].setAsAnimated();
  8421. }
  8422. };
  8423. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8424. // TODO: prevent drawing of hidden styles
  8425. var elementData;
  8426. var styleOb = new SVGStyleData(data, level);
  8427. var pathElement = styleOb.pElem;
  8428. if (data.ty === 'st') {
  8429. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8430. } else if (data.ty === 'fl') {
  8431. elementData = new SVGFillStyleData(this, data, styleOb);
  8432. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8433. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8434. elementData = new GradientConstructor(this, data, styleOb);
  8435. this.globalData.defs.appendChild(elementData.gf);
  8436. if (elementData.maskId) {
  8437. this.globalData.defs.appendChild(elementData.ms);
  8438. this.globalData.defs.appendChild(elementData.of);
  8439. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8440. }
  8441. } else if (data.ty === 'no') {
  8442. elementData = new SVGNoStyleData(this, data, styleOb);
  8443. }
  8444. if (data.ty === 'st' || data.ty === 'gs') {
  8445. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8446. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8447. pathElement.setAttribute('fill-opacity', '0');
  8448. if (data.lj === 1) {
  8449. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8450. }
  8451. }
  8452. if (data.r === 2) {
  8453. pathElement.setAttribute('fill-rule', 'evenodd');
  8454. }
  8455. if (data.ln) {
  8456. pathElement.setAttribute('id', data.ln);
  8457. }
  8458. if (data.cl) {
  8459. pathElement.setAttribute('class', data.cl);
  8460. }
  8461. if (data.bm) {
  8462. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8463. }
  8464. this.stylesList.push(styleOb);
  8465. this.addToAnimatedContents(data, elementData);
  8466. return elementData;
  8467. };
  8468. SVGShapeElement.prototype.createGroupElement = function (data) {
  8469. var elementData = new ShapeGroupData();
  8470. if (data.ln) {
  8471. elementData.gr.setAttribute('id', data.ln);
  8472. }
  8473. if (data.cl) {
  8474. elementData.gr.setAttribute('class', data.cl);
  8475. }
  8476. if (data.bm) {
  8477. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8478. }
  8479. return elementData;
  8480. };
  8481. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8482. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8483. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8484. this.addToAnimatedContents(data, elementData);
  8485. return elementData;
  8486. };
  8487. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8488. var ty = 4;
  8489. if (data.ty === 'rc') {
  8490. ty = 5;
  8491. } else if (data.ty === 'el') {
  8492. ty = 6;
  8493. } else if (data.ty === 'sr') {
  8494. ty = 7;
  8495. }
  8496. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8497. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8498. this.shapes.push(elementData);
  8499. this.addShapeToModifiers(elementData);
  8500. this.addToAnimatedContents(data, elementData);
  8501. return elementData;
  8502. };
  8503. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8504. var i = 0;
  8505. var len = this.animatedContents.length;
  8506. while (i < len) {
  8507. if (this.animatedContents[i].element === element) {
  8508. return;
  8509. }
  8510. i += 1;
  8511. }
  8512. this.animatedContents.push({
  8513. fn: SVGElementsRenderer.createRenderFunction(data),
  8514. element: element,
  8515. data: data,
  8516. });
  8517. };
  8518. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8519. var arr = elementData.styles;
  8520. var j;
  8521. var jLen = this.stylesList.length;
  8522. for (j = 0; j < jLen; j += 1) {
  8523. if (arr.indexOf(this.stylesList[j]) === -1 && !this.stylesList[j].closed) {
  8524. arr.push(this.stylesList[j]);
  8525. }
  8526. }
  8527. };
  8528. SVGShapeElement.prototype.reloadShapes = function () {
  8529. this._isFirstFrame = true;
  8530. var i;
  8531. var len = this.itemsData.length;
  8532. for (i = 0; i < len; i += 1) {
  8533. this.prevViewData[i] = this.itemsData[i];
  8534. }
  8535. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8536. this.filterUniqueShapes();
  8537. len = this.dynamicProperties.length;
  8538. for (i = 0; i < len; i += 1) {
  8539. this.dynamicProperties[i].getValue();
  8540. }
  8541. this.renderModifiers();
  8542. };
  8543. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8544. var ownTransformers = [].concat(transformers);
  8545. var i;
  8546. var len = arr.length - 1;
  8547. var j;
  8548. var jLen;
  8549. var ownStyles = [];
  8550. var ownModifiers = [];
  8551. var currentTransform;
  8552. var modifier;
  8553. var processedPos;
  8554. for (i = len; i >= 0; i -= 1) {
  8555. processedPos = this.searchProcessedElement(arr[i]);
  8556. if (!processedPos) {
  8557. arr[i]._render = render;
  8558. } else {
  8559. itemsData[i] = prevViewData[processedPos - 1];
  8560. }
  8561. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8562. if (!processedPos) {
  8563. itemsData[i] = this.createStyleElement(arr[i], level);
  8564. } else {
  8565. itemsData[i].style.closed = arr[i].hd;
  8566. }
  8567. if (arr[i]._render) {
  8568. if (itemsData[i].style.pElem.parentNode !== container) {
  8569. container.appendChild(itemsData[i].style.pElem);
  8570. }
  8571. }
  8572. ownStyles.push(itemsData[i].style);
  8573. } else if (arr[i].ty === 'gr') {
  8574. if (!processedPos) {
  8575. itemsData[i] = this.createGroupElement(arr[i]);
  8576. } else {
  8577. jLen = itemsData[i].it.length;
  8578. for (j = 0; j < jLen; j += 1) {
  8579. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8580. }
  8581. }
  8582. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8583. if (arr[i]._render) {
  8584. if (itemsData[i].gr.parentNode !== container) {
  8585. container.appendChild(itemsData[i].gr);
  8586. }
  8587. }
  8588. } else if (arr[i].ty === 'tr') {
  8589. if (!processedPos) {
  8590. itemsData[i] = this.createTransformElement(arr[i], container);
  8591. }
  8592. currentTransform = itemsData[i].transform;
  8593. ownTransformers.push(currentTransform);
  8594. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8595. if (!processedPos) {
  8596. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8597. }
  8598. this.setElementStyles(itemsData[i]);
  8599. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'ms' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  8600. if (!processedPos) {
  8601. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8602. modifier.init(this, arr[i]);
  8603. itemsData[i] = modifier;
  8604. this.shapeModifiers.push(modifier);
  8605. } else {
  8606. modifier = itemsData[i];
  8607. modifier.closed = false;
  8608. }
  8609. ownModifiers.push(modifier);
  8610. } else if (arr[i].ty === 'rp') {
  8611. if (!processedPos) {
  8612. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8613. itemsData[i] = modifier;
  8614. modifier.init(this, arr, i, itemsData);
  8615. this.shapeModifiers.push(modifier);
  8616. render = false;
  8617. } else {
  8618. modifier = itemsData[i];
  8619. modifier.closed = true;
  8620. }
  8621. ownModifiers.push(modifier);
  8622. }
  8623. this.addProcessedElement(arr[i], i + 1);
  8624. }
  8625. len = ownStyles.length;
  8626. for (i = 0; i < len; i += 1) {
  8627. ownStyles[i].closed = true;
  8628. }
  8629. len = ownModifiers.length;
  8630. for (i = 0; i < len; i += 1) {
  8631. ownModifiers[i].closed = true;
  8632. }
  8633. };
  8634. SVGShapeElement.prototype.renderInnerContent = function () {
  8635. this.renderModifiers();
  8636. var i;
  8637. var len = this.stylesList.length;
  8638. for (i = 0; i < len; i += 1) {
  8639. this.stylesList[i].reset();
  8640. }
  8641. this.renderShape();
  8642. for (i = 0; i < len; i += 1) {
  8643. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8644. if (this.stylesList[i].msElem) {
  8645. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  8646. // Adding M0 0 fixes same mask bug on all browsers
  8647. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8648. }
  8649. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8650. }
  8651. }
  8652. };
  8653. SVGShapeElement.prototype.renderShape = function () {
  8654. var i;
  8655. var len = this.animatedContents.length;
  8656. var animatedContent;
  8657. for (i = 0; i < len; i += 1) {
  8658. animatedContent = this.animatedContents[i];
  8659. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8660. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8661. }
  8662. }
  8663. };
  8664. SVGShapeElement.prototype.destroy = function () {
  8665. this.destroyBaseElement();
  8666. this.shapesData = null;
  8667. this.itemsData = null;
  8668. };
  8669. function LetterProps(o, sw, sc, fc, m, p) {
  8670. this.o = o;
  8671. this.sw = sw;
  8672. this.sc = sc;
  8673. this.fc = fc;
  8674. this.m = m;
  8675. this.p = p;
  8676. this._mdf = {
  8677. o: true,
  8678. sw: !!sw,
  8679. sc: !!sc,
  8680. fc: !!fc,
  8681. m: true,
  8682. p: true,
  8683. };
  8684. }
  8685. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  8686. this._mdf.o = false;
  8687. this._mdf.sw = false;
  8688. this._mdf.sc = false;
  8689. this._mdf.fc = false;
  8690. this._mdf.m = false;
  8691. this._mdf.p = false;
  8692. var updated = false;
  8693. if (this.o !== o) {
  8694. this.o = o;
  8695. this._mdf.o = true;
  8696. updated = true;
  8697. }
  8698. if (this.sw !== sw) {
  8699. this.sw = sw;
  8700. this._mdf.sw = true;
  8701. updated = true;
  8702. }
  8703. if (this.sc !== sc) {
  8704. this.sc = sc;
  8705. this._mdf.sc = true;
  8706. updated = true;
  8707. }
  8708. if (this.fc !== fc) {
  8709. this.fc = fc;
  8710. this._mdf.fc = true;
  8711. updated = true;
  8712. }
  8713. if (this.m !== m) {
  8714. this.m = m;
  8715. this._mdf.m = true;
  8716. updated = true;
  8717. }
  8718. if (p.length && (this.p[0] !== p[0] || this.p[1] !== p[1] || this.p[4] !== p[4] || this.p[5] !== p[5] || this.p[12] !== p[12] || this.p[13] !== p[13])) {
  8719. this.p = p;
  8720. this._mdf.p = true;
  8721. updated = true;
  8722. }
  8723. return updated;
  8724. };
  8725. function TextProperty(elem, data) {
  8726. this._frameId = initialDefaultFrame;
  8727. this.pv = '';
  8728. this.v = '';
  8729. this.kf = false;
  8730. this._isFirstFrame = true;
  8731. this._mdf = false;
  8732. if (data.d && data.d.sid) {
  8733. data.d = elem.globalData.slotManager.getProp(data.d);
  8734. }
  8735. this.data = data;
  8736. this.elem = elem;
  8737. this.comp = this.elem.comp;
  8738. this.keysIndex = 0;
  8739. this.canResize = false;
  8740. this.minimumFontSize = 1;
  8741. this.effectsSequence = [];
  8742. this.currentData = {
  8743. ascent: 0,
  8744. boxWidth: this.defaultBoxWidth,
  8745. f: '',
  8746. fStyle: '',
  8747. fWeight: '',
  8748. fc: '',
  8749. j: '',
  8750. justifyOffset: '',
  8751. l: [],
  8752. lh: 0,
  8753. lineWidths: [],
  8754. ls: '',
  8755. of: '',
  8756. s: '',
  8757. sc: '',
  8758. sw: 0,
  8759. t: 0,
  8760. tr: 0,
  8761. sz: 0,
  8762. ps: null,
  8763. fillColorAnim: false,
  8764. strokeColorAnim: false,
  8765. strokeWidthAnim: false,
  8766. yOffset: 0,
  8767. finalSize: 0,
  8768. finalText: [],
  8769. finalLineHeight: 0,
  8770. __complete: false,
  8771. };
  8772. this.copyData(this.currentData, this.data.d.k[0].s);
  8773. if (!this.searchProperty()) {
  8774. this.completeTextData(this.currentData);
  8775. }
  8776. }
  8777. TextProperty.prototype.defaultBoxWidth = [0, 0];
  8778. TextProperty.prototype.copyData = function (obj, data) {
  8779. for (var s in data) {
  8780. if (Object.prototype.hasOwnProperty.call(data, s)) {
  8781. obj[s] = data[s];
  8782. }
  8783. }
  8784. return obj;
  8785. };
  8786. TextProperty.prototype.setCurrentData = function (data) {
  8787. if (!data.__complete) {
  8788. this.completeTextData(data);
  8789. }
  8790. this.currentData = data;
  8791. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  8792. this._mdf = true;
  8793. };
  8794. TextProperty.prototype.searchProperty = function () {
  8795. return this.searchKeyframes();
  8796. };
  8797. TextProperty.prototype.searchKeyframes = function () {
  8798. this.kf = this.data.d.k.length > 1;
  8799. if (this.kf) {
  8800. this.addEffect(this.getKeyframeValue.bind(this));
  8801. }
  8802. return this.kf;
  8803. };
  8804. TextProperty.prototype.addEffect = function (effectFunction) {
  8805. this.effectsSequence.push(effectFunction);
  8806. this.elem.addDynamicProperty(this);
  8807. };
  8808. TextProperty.prototype.getValue = function (_finalValue) {
  8809. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  8810. return;
  8811. }
  8812. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  8813. var currentValue = this.currentData;
  8814. var currentIndex = this.keysIndex;
  8815. if (this.lock) {
  8816. this.setCurrentData(this.currentData);
  8817. return;
  8818. }
  8819. this.lock = true;
  8820. this._mdf = false;
  8821. var i; var
  8822. len = this.effectsSequence.length;
  8823. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  8824. for (i = 0; i < len; i += 1) {
  8825. // Checking if index changed to prevent creating a new object every time the expression updates.
  8826. if (currentIndex !== this.keysIndex) {
  8827. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  8828. } else {
  8829. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  8830. }
  8831. }
  8832. if (currentValue !== finalValue) {
  8833. this.setCurrentData(finalValue);
  8834. }
  8835. this.v = this.currentData;
  8836. this.pv = this.v;
  8837. this.lock = false;
  8838. this.frameId = this.elem.globalData.frameId;
  8839. };
  8840. TextProperty.prototype.getKeyframeValue = function () {
  8841. var textKeys = this.data.d.k;
  8842. var frameNum = this.elem.comp.renderedFrame;
  8843. var i = 0; var
  8844. len = textKeys.length;
  8845. while (i <= len - 1) {
  8846. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  8847. break;
  8848. }
  8849. i += 1;
  8850. }
  8851. if (this.keysIndex !== i) {
  8852. this.keysIndex = i;
  8853. }
  8854. return this.data.d.k[this.keysIndex].s;
  8855. };
  8856. TextProperty.prototype.buildFinalText = function (text) {
  8857. var charactersArray = [];
  8858. var i = 0;
  8859. var len = text.length;
  8860. var charCode;
  8861. var secondCharCode;
  8862. var shouldCombine = false;
  8863. var shouldCombineNext = false;
  8864. var currentChars = '';
  8865. while (i < len) {
  8866. shouldCombine = shouldCombineNext;
  8867. shouldCombineNext = false;
  8868. charCode = text.charCodeAt(i);
  8869. currentChars = text.charAt(i);
  8870. if (FontManager.isCombinedCharacter(charCode)) {
  8871. shouldCombine = true;
  8872. // It's a potential surrogate pair (this is the High surrogate)
  8873. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  8874. if (FontManager.isRegionalFlag(text, i)) {
  8875. currentChars = text.substr(i, 14);
  8876. } else {
  8877. secondCharCode = text.charCodeAt(i + 1);
  8878. // It's a surrogate pair (this is the Low surrogate)
  8879. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  8880. if (FontManager.isModifier(charCode, secondCharCode)) {
  8881. currentChars = text.substr(i, 2);
  8882. shouldCombine = true;
  8883. } else if (FontManager.isFlagEmoji(text.substr(i, 4))) {
  8884. currentChars = text.substr(i, 4);
  8885. } else {
  8886. currentChars = text.substr(i, 2);
  8887. }
  8888. }
  8889. }
  8890. } else if (charCode > 0xDBFF) {
  8891. secondCharCode = text.charCodeAt(i + 1);
  8892. if (FontManager.isVariationSelector(charCode)) {
  8893. shouldCombine = true;
  8894. }
  8895. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  8896. shouldCombine = true;
  8897. shouldCombineNext = true;
  8898. }
  8899. if (shouldCombine) {
  8900. charactersArray[charactersArray.length - 1] += currentChars;
  8901. shouldCombine = false;
  8902. } else {
  8903. charactersArray.push(currentChars);
  8904. }
  8905. i += currentChars.length;
  8906. }
  8907. return charactersArray;
  8908. };
  8909. TextProperty.prototype.completeTextData = function (documentData) {
  8910. documentData.__complete = true;
  8911. var fontManager = this.elem.globalData.fontManager;
  8912. var data = this.data;
  8913. var letters = [];
  8914. var i; var
  8915. len;
  8916. var newLineFlag; var index = 0; var
  8917. val;
  8918. var anchorGrouping = data.m.g;
  8919. var currentSize = 0; var currentPos = 0; var currentLine = 0; var
  8920. lineWidths = [];
  8921. var lineWidth = 0;
  8922. var maxLineWidth = 0;
  8923. var j; var
  8924. jLen;
  8925. var fontData = fontManager.getFontByName(documentData.f);
  8926. var charData; var
  8927. cLength = 0;
  8928. var fontProps = getFontProperties(fontData);
  8929. documentData.fWeight = fontProps.weight;
  8930. documentData.fStyle = fontProps.style;
  8931. documentData.finalSize = documentData.s;
  8932. documentData.finalText = this.buildFinalText(documentData.t);
  8933. len = documentData.finalText.length;
  8934. documentData.finalLineHeight = documentData.lh;
  8935. var trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8936. var charCode;
  8937. if (documentData.sz) {
  8938. var flag = true;
  8939. var boxWidth = documentData.sz[0];
  8940. var boxHeight = documentData.sz[1];
  8941. var currentHeight; var
  8942. finalText;
  8943. while (flag) {
  8944. finalText = this.buildFinalText(documentData.t);
  8945. currentHeight = 0;
  8946. lineWidth = 0;
  8947. len = finalText.length;
  8948. trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8949. var lastSpaceIndex = -1;
  8950. for (i = 0; i < len; i += 1) {
  8951. charCode = finalText[i].charCodeAt(0);
  8952. newLineFlag = false;
  8953. if (finalText[i] === ' ') {
  8954. lastSpaceIndex = i;
  8955. } else if (charCode === 13 || charCode === 3) {
  8956. lineWidth = 0;
  8957. newLineFlag = true;
  8958. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8959. }
  8960. if (fontManager.chars) {
  8961. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  8962. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  8963. } else {
  8964. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  8965. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  8966. }
  8967. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  8968. if (lastSpaceIndex === -1) {
  8969. len += 1;
  8970. } else {
  8971. i = lastSpaceIndex;
  8972. }
  8973. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8974. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r');
  8975. // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  8976. lastSpaceIndex = -1;
  8977. lineWidth = 0;
  8978. } else {
  8979. lineWidth += cLength;
  8980. lineWidth += trackingOffset;
  8981. }
  8982. }
  8983. currentHeight += (fontData.ascent * documentData.finalSize) / 100;
  8984. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  8985. documentData.finalSize -= 1;
  8986. documentData.finalLineHeight = (documentData.finalSize * documentData.lh) / documentData.s;
  8987. } else {
  8988. documentData.finalText = finalText;
  8989. len = documentData.finalText.length;
  8990. flag = false;
  8991. }
  8992. }
  8993. }
  8994. lineWidth = -trackingOffset;
  8995. cLength = 0;
  8996. var uncollapsedSpaces = 0;
  8997. var currentChar;
  8998. for (i = 0; i < len; i += 1) {
  8999. newLineFlag = false;
  9000. currentChar = documentData.finalText[i];
  9001. charCode = currentChar.charCodeAt(0);
  9002. if (charCode === 13 || charCode === 3) {
  9003. uncollapsedSpaces = 0;
  9004. lineWidths.push(lineWidth);
  9005. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9006. lineWidth = -2 * trackingOffset;
  9007. val = '';
  9008. newLineFlag = true;
  9009. currentLine += 1;
  9010. } else {
  9011. val = currentChar;
  9012. }
  9013. if (fontManager.chars) {
  9014. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  9015. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  9016. } else {
  9017. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9018. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  9019. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9020. }
  9021. //
  9022. if (currentChar === ' ') {
  9023. uncollapsedSpaces += cLength + trackingOffset;
  9024. } else {
  9025. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  9026. uncollapsedSpaces = 0;
  9027. }
  9028. letters.push({
  9029. l: cLength, an: cLength, add: currentSize, n: newLineFlag, anIndexes: [], val: val, line: currentLine, animatorJustifyOffset: 0,
  9030. });
  9031. if (anchorGrouping == 2) { // eslint-disable-line eqeqeq
  9032. currentSize += cLength;
  9033. if (val === '' || val === ' ' || i === len - 1) {
  9034. if (val === '' || val === ' ') {
  9035. currentSize -= cLength;
  9036. }
  9037. while (currentPos <= i) {
  9038. letters[currentPos].an = currentSize;
  9039. letters[currentPos].ind = index;
  9040. letters[currentPos].extra = cLength;
  9041. currentPos += 1;
  9042. }
  9043. index += 1;
  9044. currentSize = 0;
  9045. }
  9046. } else if (anchorGrouping == 3) { // eslint-disable-line eqeqeq
  9047. currentSize += cLength;
  9048. if (val === '' || i === len - 1) {
  9049. if (val === '') {
  9050. currentSize -= cLength;
  9051. }
  9052. while (currentPos <= i) {
  9053. letters[currentPos].an = currentSize;
  9054. letters[currentPos].ind = index;
  9055. letters[currentPos].extra = cLength;
  9056. currentPos += 1;
  9057. }
  9058. currentSize = 0;
  9059. index += 1;
  9060. }
  9061. } else {
  9062. letters[index].ind = index;
  9063. letters[index].extra = 0;
  9064. index += 1;
  9065. }
  9066. }
  9067. documentData.l = letters;
  9068. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9069. lineWidths.push(lineWidth);
  9070. if (documentData.sz) {
  9071. documentData.boxWidth = documentData.sz[0];
  9072. documentData.justifyOffset = 0;
  9073. } else {
  9074. documentData.boxWidth = maxLineWidth;
  9075. switch (documentData.j) {
  9076. case 1:
  9077. documentData.justifyOffset = -documentData.boxWidth;
  9078. break;
  9079. case 2:
  9080. documentData.justifyOffset = -documentData.boxWidth / 2;
  9081. break;
  9082. default:
  9083. documentData.justifyOffset = 0;
  9084. }
  9085. }
  9086. documentData.lineWidths = lineWidths;
  9087. var animators = data.a; var animatorData; var
  9088. letterData;
  9089. jLen = animators.length;
  9090. var based; var ind; var
  9091. indexes = [];
  9092. for (j = 0; j < jLen; j += 1) {
  9093. animatorData = animators[j];
  9094. if (animatorData.a.sc) {
  9095. documentData.strokeColorAnim = true;
  9096. }
  9097. if (animatorData.a.sw) {
  9098. documentData.strokeWidthAnim = true;
  9099. }
  9100. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9101. documentData.fillColorAnim = true;
  9102. }
  9103. ind = 0;
  9104. based = animatorData.s.b;
  9105. for (i = 0; i < len; i += 1) {
  9106. letterData = letters[i];
  9107. letterData.anIndexes[j] = ind;
  9108. if ((based == 1 && letterData.val !== '') || (based == 2 && letterData.val !== '' && letterData.val !== ' ') || (based == 3 && (letterData.n || letterData.val == ' ' || i == len - 1)) || (based == 4 && (letterData.n || i == len - 1))) { // eslint-disable-line eqeqeq
  9109. if (animatorData.s.rn === 1) {
  9110. indexes.push(ind);
  9111. }
  9112. ind += 1;
  9113. }
  9114. }
  9115. data.a[j].s.totalChars = ind;
  9116. var currentInd = -1; var
  9117. newInd;
  9118. if (animatorData.s.rn === 1) {
  9119. for (i = 0; i < len; i += 1) {
  9120. letterData = letters[i];
  9121. if (currentInd != letterData.anIndexes[j]) { // eslint-disable-line eqeqeq
  9122. currentInd = letterData.anIndexes[j];
  9123. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9124. }
  9125. letterData.anIndexes[j] = newInd;
  9126. }
  9127. }
  9128. }
  9129. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9130. documentData.ls = documentData.ls || 0;
  9131. documentData.ascent = (fontData.ascent * documentData.finalSize) / 100;
  9132. };
  9133. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9134. index = index === undefined ? this.keysIndex : index;
  9135. var dData = this.copyData({}, this.data.d.k[index].s);
  9136. dData = this.copyData(dData, newData);
  9137. this.data.d.k[index].s = dData;
  9138. this.recalculate(index);
  9139. this.setCurrentData(dData);
  9140. this.elem.addDynamicProperty(this);
  9141. };
  9142. TextProperty.prototype.recalculate = function (index) {
  9143. var dData = this.data.d.k[index].s;
  9144. dData.__complete = false;
  9145. this.keysIndex = 0;
  9146. this._isFirstFrame = true;
  9147. this.getValue(dData);
  9148. };
  9149. TextProperty.prototype.canResizeFont = function (_canResize) {
  9150. this.canResize = _canResize;
  9151. this.recalculate(this.keysIndex);
  9152. this.elem.addDynamicProperty(this);
  9153. };
  9154. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9155. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9156. this.recalculate(this.keysIndex);
  9157. this.elem.addDynamicProperty(this);
  9158. };
  9159. const TextSelectorProp = (function () {
  9160. var max = Math.max;
  9161. var min = Math.min;
  9162. var floor = Math.floor;
  9163. function TextSelectorPropFactory(elem, data) {
  9164. this._currentTextLength = -1;
  9165. this.k = false;
  9166. this.data = data;
  9167. this.elem = elem;
  9168. this.comp = elem.comp;
  9169. this.finalS = 0;
  9170. this.finalE = 0;
  9171. this.initDynamicPropertyContainer(elem);
  9172. this.s = PropertyFactory.getProp(elem, data.s || { k: 0 }, 0, 0, this);
  9173. if ('e' in data) {
  9174. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9175. } else {
  9176. this.e = { v: 100 };
  9177. }
  9178. this.o = PropertyFactory.getProp(elem, data.o || { k: 0 }, 0, 0, this);
  9179. this.xe = PropertyFactory.getProp(elem, data.xe || { k: 0 }, 0, 0, this);
  9180. this.ne = PropertyFactory.getProp(elem, data.ne || { k: 0 }, 0, 0, this);
  9181. this.sm = PropertyFactory.getProp(elem, data.sm || { k: 100 }, 0, 0, this);
  9182. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9183. if (!this.dynamicProperties.length) {
  9184. this.getValue();
  9185. }
  9186. }
  9187. TextSelectorPropFactory.prototype = {
  9188. getMult: function (ind) {
  9189. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9190. this.getValue();
  9191. }
  9192. var x1 = 0;
  9193. var y1 = 0;
  9194. var x2 = 1;
  9195. var y2 = 1;
  9196. if (this.ne.v > 0) {
  9197. x1 = this.ne.v / 100.0;
  9198. } else {
  9199. y1 = -this.ne.v / 100.0;
  9200. }
  9201. if (this.xe.v > 0) {
  9202. x2 = 1.0 - this.xe.v / 100.0;
  9203. } else {
  9204. y2 = 1.0 + this.xe.v / 100.0;
  9205. }
  9206. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9207. var mult = 0;
  9208. var s = this.finalS;
  9209. var e = this.finalE;
  9210. var type = this.data.sh;
  9211. if (type === 2) {
  9212. if (e === s) {
  9213. mult = ind >= e ? 1 : 0;
  9214. } else {
  9215. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9216. }
  9217. mult = easer(mult);
  9218. } else if (type === 3) {
  9219. if (e === s) {
  9220. mult = ind >= e ? 0 : 1;
  9221. } else {
  9222. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9223. }
  9224. mult = easer(mult);
  9225. } else if (type === 4) {
  9226. if (e === s) {
  9227. mult = 0;
  9228. } else {
  9229. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9230. if (mult < 0.5) {
  9231. mult *= 2;
  9232. } else {
  9233. mult = 1 - 2 * (mult - 0.5);
  9234. }
  9235. }
  9236. mult = easer(mult);
  9237. } else if (type === 5) {
  9238. if (e === s) {
  9239. mult = 0;
  9240. } else {
  9241. var tot = e - s;
  9242. /* ind += 0.5;
  9243. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9244. ind = min(max(0, ind + 0.5 - s), e - s);
  9245. var x = -tot / 2 + ind;
  9246. var a = tot / 2;
  9247. mult = Math.sqrt(1 - (x * x) / (a * a));
  9248. }
  9249. mult = easer(mult);
  9250. } else if (type === 6) {
  9251. if (e === s) {
  9252. mult = 0;
  9253. } else {
  9254. ind = min(max(0, ind + 0.5 - s), e - s);
  9255. mult = (1 + (Math.cos((Math.PI + Math.PI * 2 * (ind) / (e - s))))) / 2; // eslint-disable-line
  9256. }
  9257. mult = easer(mult);
  9258. } else {
  9259. if (ind >= floor(s)) {
  9260. if (ind - s < 0) {
  9261. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9262. } else {
  9263. mult = max(0, min(e - ind, 1));
  9264. }
  9265. }
  9266. mult = easer(mult);
  9267. }
  9268. // Smoothness implementation.
  9269. // The smoothness represents a reduced range of the original [0; 1] range.
  9270. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9271. // Steps are:
  9272. // - find the lower value of the new range (threshold)
  9273. // - if multiplier is smaller than that value, floor it to 0
  9274. // - if it is larger,
  9275. // - subtract the threshold
  9276. // - divide it by the smoothness (this will return the range to [0; 1])
  9277. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9278. if (this.sm.v !== 100) {
  9279. var smoothness = this.sm.v * 0.01;
  9280. if (smoothness === 0) {
  9281. smoothness = 0.00000001;
  9282. }
  9283. var threshold = 0.5 - smoothness * 0.5;
  9284. if (mult < threshold) {
  9285. mult = 0;
  9286. } else {
  9287. mult = (mult - threshold) / smoothness;
  9288. if (mult > 1) {
  9289. mult = 1;
  9290. }
  9291. }
  9292. }
  9293. return mult * this.a.v;
  9294. },
  9295. getValue: function (newCharsFlag) {
  9296. this.iterateDynamicProperties();
  9297. this._mdf = newCharsFlag || this._mdf;
  9298. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9299. if (newCharsFlag && this.data.r === 2) {
  9300. this.e.v = this._currentTextLength;
  9301. }
  9302. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9303. var o = this.o.v / divisor;
  9304. var s = this.s.v / divisor + o;
  9305. var e = (this.e.v / divisor) + o;
  9306. if (s > e) {
  9307. var _s = s;
  9308. s = e;
  9309. e = _s;
  9310. }
  9311. this.finalS = s;
  9312. this.finalE = e;
  9313. },
  9314. };
  9315. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9316. function getTextSelectorProp(elem, data, arr) {
  9317. return new TextSelectorPropFactory(elem, data, arr);
  9318. }
  9319. return {
  9320. getTextSelectorProp: getTextSelectorProp,
  9321. };
  9322. }());
  9323. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9324. var defaultData = { propType: false };
  9325. var getProp = PropertyFactory.getProp;
  9326. var textAnimatorAnimatables = animatorProps.a;
  9327. this.a = {
  9328. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9329. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9330. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9331. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9332. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9333. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9334. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9335. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9336. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9337. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9338. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9339. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9340. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9341. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9342. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9343. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData,
  9344. };
  9345. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9346. this.s.t = animatorProps.s.t;
  9347. }
  9348. function TextAnimatorProperty(textData, renderType, elem) {
  9349. this._isFirstFrame = true;
  9350. this._hasMaskedPath = false;
  9351. this._frameId = -1;
  9352. this._textData = textData;
  9353. this._renderType = renderType;
  9354. this._elem = elem;
  9355. this._animatorsData = createSizedArray(this._textData.a.length);
  9356. this._pathData = {};
  9357. this._moreOptions = {
  9358. alignment: {},
  9359. };
  9360. this.renderedLetters = [];
  9361. this.lettersChangedFlag = false;
  9362. this.initDynamicPropertyContainer(elem);
  9363. }
  9364. TextAnimatorProperty.prototype.searchProperties = function () {
  9365. var i;
  9366. var len = this._textData.a.length;
  9367. var animatorProps;
  9368. var getProp = PropertyFactory.getProp;
  9369. for (i = 0; i < len; i += 1) {
  9370. animatorProps = this._textData.a[i];
  9371. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9372. }
  9373. if (this._textData.p && 'm' in this._textData.p) {
  9374. this._pathData = {
  9375. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9376. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9377. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9378. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9379. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9380. m: this._elem.maskManager.getMaskProperty(this._textData.p.m),
  9381. };
  9382. this._hasMaskedPath = true;
  9383. } else {
  9384. this._hasMaskedPath = false;
  9385. }
  9386. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9387. };
  9388. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9389. this.lettersChangedFlag = lettersChangedFlag;
  9390. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9391. return;
  9392. }
  9393. this._isFirstFrame = false;
  9394. var alignment = this._moreOptions.alignment.v;
  9395. var animators = this._animatorsData;
  9396. var textData = this._textData;
  9397. var matrixHelper = this.mHelper;
  9398. var renderType = this._renderType;
  9399. var renderedLettersCount = this.renderedLetters.length;
  9400. var xPos;
  9401. var yPos;
  9402. var i;
  9403. var len;
  9404. var letters = documentData.l;
  9405. var pathInfo;
  9406. var currentLength;
  9407. var currentPoint;
  9408. var segmentLength;
  9409. var flag;
  9410. var pointInd;
  9411. var segmentInd;
  9412. var prevPoint;
  9413. var points;
  9414. var segments;
  9415. var partialLength;
  9416. var totalLength;
  9417. var perc;
  9418. var tanAngle;
  9419. var mask;
  9420. if (this._hasMaskedPath) {
  9421. mask = this._pathData.m;
  9422. if (!this._pathData.n || this._pathData._mdf) {
  9423. var paths = mask.v;
  9424. if (this._pathData.r.v) {
  9425. paths = paths.reverse();
  9426. }
  9427. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9428. pathInfo = {
  9429. tLength: 0,
  9430. segments: [],
  9431. };
  9432. len = paths._length - 1;
  9433. var bezierData;
  9434. totalLength = 0;
  9435. for (i = 0; i < len; i += 1) {
  9436. bezierData = bez.buildBezierData(paths.v[i],
  9437. paths.v[i + 1],
  9438. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9439. [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9440. pathInfo.tLength += bezierData.segmentLength;
  9441. pathInfo.segments.push(bezierData);
  9442. totalLength += bezierData.segmentLength;
  9443. }
  9444. i = len;
  9445. if (mask.v.c) {
  9446. bezierData = bez.buildBezierData(paths.v[i],
  9447. paths.v[0],
  9448. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9449. [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9450. pathInfo.tLength += bezierData.segmentLength;
  9451. pathInfo.segments.push(bezierData);
  9452. totalLength += bezierData.segmentLength;
  9453. }
  9454. this._pathData.pi = pathInfo;
  9455. }
  9456. pathInfo = this._pathData.pi;
  9457. currentLength = this._pathData.f.v;
  9458. segmentInd = 0;
  9459. pointInd = 1;
  9460. segmentLength = 0;
  9461. flag = true;
  9462. segments = pathInfo.segments;
  9463. if (currentLength < 0 && mask.v.c) {
  9464. if (pathInfo.tLength < Math.abs(currentLength)) {
  9465. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9466. }
  9467. segmentInd = segments.length - 1;
  9468. points = segments[segmentInd].points;
  9469. pointInd = points.length - 1;
  9470. while (currentLength < 0) {
  9471. currentLength += points[pointInd].partialLength;
  9472. pointInd -= 1;
  9473. if (pointInd < 0) {
  9474. segmentInd -= 1;
  9475. points = segments[segmentInd].points;
  9476. pointInd = points.length - 1;
  9477. }
  9478. }
  9479. }
  9480. points = segments[segmentInd].points;
  9481. prevPoint = points[pointInd - 1];
  9482. currentPoint = points[pointInd];
  9483. partialLength = currentPoint.partialLength;
  9484. }
  9485. len = letters.length;
  9486. xPos = 0;
  9487. yPos = 0;
  9488. var yOff = documentData.finalSize * 1.2 * 0.714;
  9489. var firstLine = true;
  9490. var animatorProps;
  9491. var animatorSelector;
  9492. var j;
  9493. var jLen;
  9494. var letterValue;
  9495. jLen = animators.length;
  9496. var mult;
  9497. var ind = -1;
  9498. var offf;
  9499. var xPathPos;
  9500. var yPathPos;
  9501. var initPathPos = currentLength;
  9502. var initSegmentInd = segmentInd;
  9503. var initPointInd = pointInd;
  9504. var currentLine = -1;
  9505. var elemOpacity;
  9506. var sc;
  9507. var sw;
  9508. var fc;
  9509. var k;
  9510. var letterSw;
  9511. var letterSc;
  9512. var letterFc;
  9513. var letterM = '';
  9514. var letterP = this.defaultPropsArray;
  9515. var letterO;
  9516. //
  9517. if (documentData.j === 2 || documentData.j === 1) {
  9518. var animatorJustifyOffset = 0;
  9519. var animatorFirstCharOffset = 0;
  9520. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9521. var lastIndex = 0;
  9522. var isNewLine = true;
  9523. for (i = 0; i < len; i += 1) {
  9524. if (letters[i].n) {
  9525. if (animatorJustifyOffset) {
  9526. animatorJustifyOffset += animatorFirstCharOffset;
  9527. }
  9528. while (lastIndex < i) {
  9529. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9530. lastIndex += 1;
  9531. }
  9532. animatorJustifyOffset = 0;
  9533. isNewLine = true;
  9534. } else {
  9535. for (j = 0; j < jLen; j += 1) {
  9536. animatorProps = animators[j].a;
  9537. if (animatorProps.t.propType) {
  9538. if (isNewLine && documentData.j === 2) {
  9539. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9540. }
  9541. animatorSelector = animators[j].s;
  9542. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9543. if (mult.length) {
  9544. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9545. } else {
  9546. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9547. }
  9548. }
  9549. }
  9550. isNewLine = false;
  9551. }
  9552. }
  9553. if (animatorJustifyOffset) {
  9554. animatorJustifyOffset += animatorFirstCharOffset;
  9555. }
  9556. while (lastIndex < i) {
  9557. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9558. lastIndex += 1;
  9559. }
  9560. }
  9561. //
  9562. for (i = 0; i < len; i += 1) {
  9563. matrixHelper.reset();
  9564. elemOpacity = 1;
  9565. if (letters[i].n) {
  9566. xPos = 0;
  9567. yPos += documentData.yOffset;
  9568. yPos += firstLine ? 1 : 0;
  9569. currentLength = initPathPos;
  9570. firstLine = false;
  9571. if (this._hasMaskedPath) {
  9572. segmentInd = initSegmentInd;
  9573. pointInd = initPointInd;
  9574. points = segments[segmentInd].points;
  9575. prevPoint = points[pointInd - 1];
  9576. currentPoint = points[pointInd];
  9577. partialLength = currentPoint.partialLength;
  9578. segmentLength = 0;
  9579. }
  9580. letterM = '';
  9581. letterFc = '';
  9582. letterSw = '';
  9583. letterO = '';
  9584. letterP = this.defaultPropsArray;
  9585. } else {
  9586. if (this._hasMaskedPath) {
  9587. if (currentLine !== letters[i].line) {
  9588. switch (documentData.j) {
  9589. case 1:
  9590. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9591. break;
  9592. case 2:
  9593. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9594. break;
  9595. default:
  9596. break;
  9597. }
  9598. currentLine = letters[i].line;
  9599. }
  9600. if (ind !== letters[i].ind) {
  9601. if (letters[ind]) {
  9602. currentLength += letters[ind].extra;
  9603. }
  9604. currentLength += letters[i].an / 2;
  9605. ind = letters[i].ind;
  9606. }
  9607. currentLength += (alignment[0] * letters[i].an) * 0.005;
  9608. var animatorOffset = 0;
  9609. for (j = 0; j < jLen; j += 1) {
  9610. animatorProps = animators[j].a;
  9611. if (animatorProps.p.propType) {
  9612. animatorSelector = animators[j].s;
  9613. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9614. if (mult.length) {
  9615. animatorOffset += animatorProps.p.v[0] * mult[0];
  9616. } else {
  9617. animatorOffset += animatorProps.p.v[0] * mult;
  9618. }
  9619. }
  9620. if (animatorProps.a.propType) {
  9621. animatorSelector = animators[j].s;
  9622. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9623. if (mult.length) {
  9624. animatorOffset += animatorProps.a.v[0] * mult[0];
  9625. } else {
  9626. animatorOffset += animatorProps.a.v[0] * mult;
  9627. }
  9628. }
  9629. }
  9630. flag = true;
  9631. // Force alignment only works with a single line for now
  9632. if (this._pathData.a.v) {
  9633. currentLength = letters[0].an * 0.5 + ((totalLength - this._pathData.f.v - letters[0].an * 0.5 - letters[letters.length - 1].an * 0.5) * ind) / (len - 1);
  9634. currentLength += this._pathData.f.v;
  9635. }
  9636. while (flag) {
  9637. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9638. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9639. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9640. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9641. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, -(alignment[1] * yOff) * 0.01);
  9642. flag = false;
  9643. } else if (points) {
  9644. segmentLength += currentPoint.partialLength;
  9645. pointInd += 1;
  9646. if (pointInd >= points.length) {
  9647. pointInd = 0;
  9648. segmentInd += 1;
  9649. if (!segments[segmentInd]) {
  9650. if (mask.v.c) {
  9651. pointInd = 0;
  9652. segmentInd = 0;
  9653. points = segments[segmentInd].points;
  9654. } else {
  9655. segmentLength -= currentPoint.partialLength;
  9656. points = null;
  9657. }
  9658. } else {
  9659. points = segments[segmentInd].points;
  9660. }
  9661. }
  9662. if (points) {
  9663. prevPoint = currentPoint;
  9664. currentPoint = points[pointInd];
  9665. partialLength = currentPoint.partialLength;
  9666. }
  9667. }
  9668. }
  9669. offf = letters[i].an / 2 - letters[i].add;
  9670. matrixHelper.translate(-offf, 0, 0);
  9671. } else {
  9672. offf = letters[i].an / 2 - letters[i].add;
  9673. matrixHelper.translate(-offf, 0, 0);
  9674. // Grouping alignment
  9675. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, (-alignment[1] * yOff) * 0.01, 0);
  9676. }
  9677. for (j = 0; j < jLen; j += 1) {
  9678. animatorProps = animators[j].a;
  9679. if (animatorProps.t.propType) {
  9680. animatorSelector = animators[j].s;
  9681. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9682. // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9683. if (xPos !== 0 || documentData.j !== 0) {
  9684. if (this._hasMaskedPath) {
  9685. if (mult.length) {
  9686. currentLength += animatorProps.t.v * mult[0];
  9687. } else {
  9688. currentLength += animatorProps.t.v * mult;
  9689. }
  9690. } else if (mult.length) {
  9691. xPos += animatorProps.t.v * mult[0];
  9692. } else {
  9693. xPos += animatorProps.t.v * mult;
  9694. }
  9695. }
  9696. }
  9697. }
  9698. if (documentData.strokeWidthAnim) {
  9699. sw = documentData.sw || 0;
  9700. }
  9701. if (documentData.strokeColorAnim) {
  9702. if (documentData.sc) {
  9703. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  9704. } else {
  9705. sc = [0, 0, 0];
  9706. }
  9707. }
  9708. if (documentData.fillColorAnim && documentData.fc) {
  9709. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  9710. }
  9711. for (j = 0; j < jLen; j += 1) {
  9712. animatorProps = animators[j].a;
  9713. if (animatorProps.a.propType) {
  9714. animatorSelector = animators[j].s;
  9715. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9716. if (mult.length) {
  9717. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  9718. } else {
  9719. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  9720. }
  9721. }
  9722. }
  9723. for (j = 0; j < jLen; j += 1) {
  9724. animatorProps = animators[j].a;
  9725. if (animatorProps.s.propType) {
  9726. animatorSelector = animators[j].s;
  9727. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9728. if (mult.length) {
  9729. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult[0]), 1 + ((animatorProps.s.v[1] - 1) * mult[1]), 1);
  9730. } else {
  9731. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult), 1 + ((animatorProps.s.v[1] - 1) * mult), 1);
  9732. }
  9733. }
  9734. }
  9735. for (j = 0; j < jLen; j += 1) {
  9736. animatorProps = animators[j].a;
  9737. animatorSelector = animators[j].s;
  9738. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9739. if (animatorProps.sk.propType) {
  9740. if (mult.length) {
  9741. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  9742. } else {
  9743. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  9744. }
  9745. }
  9746. if (animatorProps.r.propType) {
  9747. if (mult.length) {
  9748. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  9749. } else {
  9750. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  9751. }
  9752. }
  9753. if (animatorProps.ry.propType) {
  9754. if (mult.length) {
  9755. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  9756. } else {
  9757. matrixHelper.rotateY(animatorProps.ry.v * mult);
  9758. }
  9759. }
  9760. if (animatorProps.rx.propType) {
  9761. if (mult.length) {
  9762. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  9763. } else {
  9764. matrixHelper.rotateX(animatorProps.rx.v * mult);
  9765. }
  9766. }
  9767. if (animatorProps.o.propType) {
  9768. if (mult.length) {
  9769. elemOpacity += ((animatorProps.o.v) * mult[0] - elemOpacity) * mult[0];
  9770. } else {
  9771. elemOpacity += ((animatorProps.o.v) * mult - elemOpacity) * mult;
  9772. }
  9773. }
  9774. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  9775. if (mult.length) {
  9776. sw += animatorProps.sw.v * mult[0];
  9777. } else {
  9778. sw += animatorProps.sw.v * mult;
  9779. }
  9780. }
  9781. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  9782. for (k = 0; k < 3; k += 1) {
  9783. if (mult.length) {
  9784. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  9785. } else {
  9786. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  9787. }
  9788. }
  9789. }
  9790. if (documentData.fillColorAnim && documentData.fc) {
  9791. if (animatorProps.fc.propType) {
  9792. for (k = 0; k < 3; k += 1) {
  9793. if (mult.length) {
  9794. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  9795. } else {
  9796. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  9797. }
  9798. }
  9799. }
  9800. if (animatorProps.fh.propType) {
  9801. if (mult.length) {
  9802. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  9803. } else {
  9804. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  9805. }
  9806. }
  9807. if (animatorProps.fs.propType) {
  9808. if (mult.length) {
  9809. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  9810. } else {
  9811. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  9812. }
  9813. }
  9814. if (animatorProps.fb.propType) {
  9815. if (mult.length) {
  9816. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  9817. } else {
  9818. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  9819. }
  9820. }
  9821. }
  9822. }
  9823. for (j = 0; j < jLen; j += 1) {
  9824. animatorProps = animators[j].a;
  9825. if (animatorProps.p.propType) {
  9826. animatorSelector = animators[j].s;
  9827. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9828. if (this._hasMaskedPath) {
  9829. if (mult.length) {
  9830. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  9831. } else {
  9832. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9833. }
  9834. } else if (mult.length) {
  9835. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  9836. } else {
  9837. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9838. }
  9839. }
  9840. }
  9841. if (documentData.strokeWidthAnim) {
  9842. letterSw = sw < 0 ? 0 : sw;
  9843. }
  9844. if (documentData.strokeColorAnim) {
  9845. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  9846. }
  9847. if (documentData.fillColorAnim && documentData.fc) {
  9848. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  9849. }
  9850. if (this._hasMaskedPath) {
  9851. matrixHelper.translate(0, -documentData.ls);
  9852. matrixHelper.translate(0, (alignment[1] * yOff) * 0.01 + yPos, 0);
  9853. if (this._pathData.p.v) {
  9854. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  9855. var rot = (Math.atan(tanAngle) * 180) / Math.PI;
  9856. if (currentPoint.point[0] < prevPoint.point[0]) {
  9857. rot += 180;
  9858. }
  9859. matrixHelper.rotate((-rot * Math.PI) / 180);
  9860. }
  9861. matrixHelper.translate(xPathPos, yPathPos, 0);
  9862. currentLength -= (alignment[0] * letters[i].an) * 0.005;
  9863. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  9864. currentLength += letters[i].an / 2;
  9865. currentLength += (documentData.tr * 0.001) * documentData.finalSize;
  9866. }
  9867. } else {
  9868. matrixHelper.translate(xPos, yPos, 0);
  9869. if (documentData.ps) {
  9870. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  9871. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9872. }
  9873. switch (documentData.j) {
  9874. case 1:
  9875. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  9876. break;
  9877. case 2:
  9878. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  9879. break;
  9880. default:
  9881. break;
  9882. }
  9883. matrixHelper.translate(0, -documentData.ls);
  9884. matrixHelper.translate(offf, 0, 0);
  9885. matrixHelper.translate((alignment[0] * letters[i].an) * 0.005, (alignment[1] * yOff) * 0.01, 0);
  9886. xPos += letters[i].l + (documentData.tr * 0.001) * documentData.finalSize;
  9887. }
  9888. if (renderType === 'html') {
  9889. letterM = matrixHelper.toCSS();
  9890. } else if (renderType === 'svg') {
  9891. letterM = matrixHelper.to2dCSS();
  9892. } else {
  9893. letterP = [matrixHelper.props[0], matrixHelper.props[1], matrixHelper.props[2], matrixHelper.props[3], matrixHelper.props[4], matrixHelper.props[5], matrixHelper.props[6], matrixHelper.props[7], matrixHelper.props[8], matrixHelper.props[9], matrixHelper.props[10], matrixHelper.props[11], matrixHelper.props[12], matrixHelper.props[13], matrixHelper.props[14], matrixHelper.props[15]];
  9894. }
  9895. letterO = elemOpacity;
  9896. }
  9897. if (renderedLettersCount <= i) {
  9898. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  9899. this.renderedLetters.push(letterValue);
  9900. renderedLettersCount += 1;
  9901. this.lettersChangedFlag = true;
  9902. } else {
  9903. letterValue = this.renderedLetters[i];
  9904. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  9905. }
  9906. }
  9907. };
  9908. TextAnimatorProperty.prototype.getValue = function () {
  9909. if (this._elem.globalData.frameId === this._frameId) {
  9910. return;
  9911. }
  9912. this._frameId = this._elem.globalData.frameId;
  9913. this.iterateDynamicProperties();
  9914. };
  9915. TextAnimatorProperty.prototype.mHelper = new Matrix();
  9916. TextAnimatorProperty.prototype.defaultPropsArray = [];
  9917. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  9918. function ITextElement() {
  9919. }
  9920. ITextElement.prototype.initElement = function (data, globalData, comp) {
  9921. this.lettersChangedFlag = true;
  9922. this.initFrame();
  9923. this.initBaseData(data, globalData, comp);
  9924. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  9925. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  9926. this.initTransform(data, globalData, comp);
  9927. this.initHierarchy();
  9928. this.initRenderable();
  9929. this.initRendererElement();
  9930. this.createContainerElements();
  9931. this.createRenderableComponents();
  9932. this.createContent();
  9933. this.hide();
  9934. this.textAnimator.searchProperties(this.dynamicProperties);
  9935. };
  9936. ITextElement.prototype.prepareFrame = function (num) {
  9937. this._mdf = false;
  9938. this.prepareRenderableFrame(num);
  9939. this.prepareProperties(num, this.isInRange);
  9940. };
  9941. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  9942. var j;
  9943. var jLen = shapes.length;
  9944. var pathNodes;
  9945. var shapeStr = '';
  9946. for (j = 0; j < jLen; j += 1) {
  9947. if (shapes[j].ty === 'sh') {
  9948. pathNodes = shapes[j].ks.k;
  9949. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  9950. }
  9951. }
  9952. return shapeStr;
  9953. };
  9954. ITextElement.prototype.updateDocumentData = function (newData, index) {
  9955. this.textProperty.updateDocumentData(newData, index);
  9956. };
  9957. ITextElement.prototype.canResizeFont = function (_canResize) {
  9958. this.textProperty.canResizeFont(_canResize);
  9959. };
  9960. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  9961. this.textProperty.setMinimumFontSize(_fontSize);
  9962. };
  9963. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  9964. if (documentData.ps) {
  9965. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9966. }
  9967. matrixHelper.translate(0, -documentData.ls, 0);
  9968. switch (documentData.j) {
  9969. case 1:
  9970. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  9971. break;
  9972. case 2:
  9973. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  9974. break;
  9975. default:
  9976. break;
  9977. }
  9978. matrixHelper.translate(xPos, yPos, 0);
  9979. };
  9980. ITextElement.prototype.buildColor = function (colorData) {
  9981. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  9982. };
  9983. ITextElement.prototype.emptyProp = new LetterProps();
  9984. ITextElement.prototype.destroy = function () {
  9985. };
  9986. ITextElement.prototype.validateText = function () {
  9987. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  9988. this.buildNewText();
  9989. this.textProperty._isFirstFrame = false;
  9990. this.textProperty._mdf = false;
  9991. }
  9992. };
  9993. var emptyShapeData = {
  9994. shapes: [],
  9995. };
  9996. function SVGTextLottieElement(data, globalData, comp) {
  9997. this.textSpans = [];
  9998. this.renderType = 'svg';
  9999. this.initElement(data, globalData, comp);
  10000. }
  10001. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  10002. SVGTextLottieElement.prototype.createContent = function () {
  10003. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  10004. this.textContainer = createNS('text');
  10005. }
  10006. };
  10007. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  10008. var i = 0;
  10009. var len = textArray.length;
  10010. var textContents = [];
  10011. var currentTextContent = '';
  10012. while (i < len) {
  10013. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  10014. textContents.push(currentTextContent);
  10015. currentTextContent = '';
  10016. } else {
  10017. currentTextContent += textArray[i];
  10018. }
  10019. i += 1;
  10020. }
  10021. textContents.push(currentTextContent);
  10022. return textContents;
  10023. };
  10024. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  10025. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  10026. // but since text internal content gets only rendered once and then it's never rerendered,
  10027. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  10028. // Avoiding cloning is preferred since cloning each character shape data is expensive
  10029. if (data.shapes && data.shapes.length) {
  10030. var shape = data.shapes[0];
  10031. if (shape.it) {
  10032. var shapeItem = shape.it[shape.it.length - 1];
  10033. if (shapeItem.s) {
  10034. shapeItem.s.k[0] = scale;
  10035. shapeItem.s.k[1] = scale;
  10036. }
  10037. }
  10038. }
  10039. return data;
  10040. };
  10041. SVGTextLottieElement.prototype.buildNewText = function () {
  10042. this.addDynamicProperty(this);
  10043. var i;
  10044. var len;
  10045. var documentData = this.textProperty.currentData;
  10046. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  10047. if (documentData.fc) {
  10048. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  10049. } else {
  10050. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  10051. }
  10052. if (documentData.sc) {
  10053. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  10054. this.layerElement.setAttribute('stroke-width', documentData.sw);
  10055. }
  10056. this.layerElement.setAttribute('font-size', documentData.finalSize);
  10057. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10058. if (fontData.fClass) {
  10059. this.layerElement.setAttribute('class', fontData.fClass);
  10060. } else {
  10061. this.layerElement.setAttribute('font-family', fontData.fFamily);
  10062. var fWeight = documentData.fWeight;
  10063. var fStyle = documentData.fStyle;
  10064. this.layerElement.setAttribute('font-style', fStyle);
  10065. this.layerElement.setAttribute('font-weight', fWeight);
  10066. }
  10067. this.layerElement.setAttribute('aria-label', documentData.t);
  10068. var letters = documentData.l || [];
  10069. var usesGlyphs = !!this.globalData.fontManager.chars;
  10070. len = letters.length;
  10071. var tSpan;
  10072. var matrixHelper = this.mHelper;
  10073. var shapeStr = '';
  10074. var singleShape = this.data.singleShape;
  10075. var xPos = 0;
  10076. var yPos = 0;
  10077. var firstLine = true;
  10078. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10079. if (singleShape && !usesGlyphs && !documentData.sz) {
  10080. var tElement = this.textContainer;
  10081. var justify = 'start';
  10082. switch (documentData.j) {
  10083. case 1:
  10084. justify = 'end';
  10085. break;
  10086. case 2:
  10087. justify = 'middle';
  10088. break;
  10089. default:
  10090. justify = 'start';
  10091. break;
  10092. }
  10093. tElement.setAttribute('text-anchor', justify);
  10094. tElement.setAttribute('letter-spacing', trackingOffset);
  10095. var textContent = this.buildTextContents(documentData.finalText);
  10096. len = textContent.length;
  10097. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10098. for (i = 0; i < len; i += 1) {
  10099. tSpan = this.textSpans[i].span || createNS('tspan');
  10100. tSpan.textContent = textContent[i];
  10101. tSpan.setAttribute('x', 0);
  10102. tSpan.setAttribute('y', yPos);
  10103. tSpan.style.display = 'inherit';
  10104. tElement.appendChild(tSpan);
  10105. if (!this.textSpans[i]) {
  10106. this.textSpans[i] = {
  10107. span: null,
  10108. glyph: null,
  10109. };
  10110. }
  10111. this.textSpans[i].span = tSpan;
  10112. yPos += documentData.finalLineHeight;
  10113. }
  10114. this.layerElement.appendChild(tElement);
  10115. } else {
  10116. var cachedSpansLength = this.textSpans.length;
  10117. var charData;
  10118. for (i = 0; i < len; i += 1) {
  10119. if (!this.textSpans[i]) {
  10120. this.textSpans[i] = {
  10121. span: null,
  10122. childSpan: null,
  10123. glyph: null,
  10124. };
  10125. }
  10126. if (!usesGlyphs || !singleShape || i === 0) {
  10127. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10128. if (cachedSpansLength <= i) {
  10129. tSpan.setAttribute('stroke-linecap', 'butt');
  10130. tSpan.setAttribute('stroke-linejoin', 'round');
  10131. tSpan.setAttribute('stroke-miterlimit', '4');
  10132. this.textSpans[i].span = tSpan;
  10133. if (usesGlyphs) {
  10134. var childSpan = createNS('g');
  10135. tSpan.appendChild(childSpan);
  10136. this.textSpans[i].childSpan = childSpan;
  10137. }
  10138. this.textSpans[i].span = tSpan;
  10139. this.layerElement.appendChild(tSpan);
  10140. }
  10141. tSpan.style.display = 'inherit';
  10142. }
  10143. matrixHelper.reset();
  10144. if (singleShape) {
  10145. if (letters[i].n) {
  10146. xPos = -trackingOffset;
  10147. yPos += documentData.yOffset;
  10148. yPos += firstLine ? 1 : 0;
  10149. firstLine = false;
  10150. }
  10151. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10152. xPos += letters[i].l || 0;
  10153. // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10154. xPos += trackingOffset;
  10155. }
  10156. if (usesGlyphs) {
  10157. charData = this.globalData.fontManager.getCharData(
  10158. documentData.finalText[i],
  10159. fontData.fStyle,
  10160. this.globalData.fontManager.getFontByName(documentData.f).fFamily
  10161. );
  10162. var glyphElement;
  10163. // t === 1 means the character has been replaced with an animated shaped
  10164. if (charData.t === 1) {
  10165. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10166. } else {
  10167. var data = emptyShapeData;
  10168. if (charData.data && charData.data.shapes) {
  10169. data = this.buildShapeData(charData.data, documentData.finalSize);
  10170. }
  10171. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10172. }
  10173. if (this.textSpans[i].glyph) {
  10174. var glyph = this.textSpans[i].glyph;
  10175. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10176. glyph.destroy();
  10177. }
  10178. this.textSpans[i].glyph = glyphElement;
  10179. glyphElement._debug = true;
  10180. glyphElement.prepareFrame(0);
  10181. glyphElement.renderFrame();
  10182. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
  10183. // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10184. // this might have issues with strokes and might need a different solution
  10185. if (charData.t === 1) {
  10186. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10187. }
  10188. } else {
  10189. if (singleShape) {
  10190. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10191. }
  10192. tSpan.textContent = letters[i].val;
  10193. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10194. }
  10195. //
  10196. }
  10197. if (singleShape && tSpan) {
  10198. tSpan.setAttribute('d', shapeStr);
  10199. }
  10200. }
  10201. while (i < this.textSpans.length) {
  10202. this.textSpans[i].span.style.display = 'none';
  10203. i += 1;
  10204. }
  10205. this._sizeChanged = true;
  10206. };
  10207. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10208. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10209. this.renderInnerContent();
  10210. if (this._sizeChanged) {
  10211. this._sizeChanged = false;
  10212. var textBox = this.layerElement.getBBox();
  10213. this.bbox = {
  10214. top: textBox.y,
  10215. left: textBox.x,
  10216. width: textBox.width,
  10217. height: textBox.height,
  10218. };
  10219. }
  10220. return this.bbox;
  10221. };
  10222. SVGTextLottieElement.prototype.getValue = function () {
  10223. var i;
  10224. var len = this.textSpans.length;
  10225. var glyphElement;
  10226. this.renderedFrame = this.comp.renderedFrame;
  10227. for (i = 0; i < len; i += 1) {
  10228. glyphElement = this.textSpans[i].glyph;
  10229. if (glyphElement) {
  10230. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10231. if (glyphElement._mdf) {
  10232. this._mdf = true;
  10233. }
  10234. }
  10235. }
  10236. };
  10237. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10238. this.validateText();
  10239. if (!this.data.singleShape || this._mdf) {
  10240. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10241. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10242. this._sizeChanged = true;
  10243. var i;
  10244. var len;
  10245. var renderedLetters = this.textAnimator.renderedLetters;
  10246. var letters = this.textProperty.currentData.l;
  10247. len = letters.length;
  10248. var renderedLetter;
  10249. var textSpan;
  10250. var glyphElement;
  10251. for (i = 0; i < len; i += 1) {
  10252. if (!letters[i].n) {
  10253. renderedLetter = renderedLetters[i];
  10254. textSpan = this.textSpans[i].span;
  10255. glyphElement = this.textSpans[i].glyph;
  10256. if (glyphElement) {
  10257. glyphElement.renderFrame();
  10258. }
  10259. if (renderedLetter._mdf.m) {
  10260. textSpan.setAttribute('transform', renderedLetter.m);
  10261. }
  10262. if (renderedLetter._mdf.o) {
  10263. textSpan.setAttribute('opacity', renderedLetter.o);
  10264. }
  10265. if (renderedLetter._mdf.sw) {
  10266. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10267. }
  10268. if (renderedLetter._mdf.sc) {
  10269. textSpan.setAttribute('stroke', renderedLetter.sc);
  10270. }
  10271. if (renderedLetter._mdf.fc) {
  10272. textSpan.setAttribute('fill', renderedLetter.fc);
  10273. }
  10274. }
  10275. }
  10276. }
  10277. }
  10278. };
  10279. function ISolidElement(data, globalData, comp) {
  10280. this.initElement(data, globalData, comp);
  10281. }
  10282. extendPrototype([IImageElement], ISolidElement);
  10283. ISolidElement.prototype.createContent = function () {
  10284. var rect = createNS('rect');
  10285. /// /rect.style.width = this.data.sw;
  10286. /// /rect.style.height = this.data.sh;
  10287. /// /rect.style.fill = this.data.sc;
  10288. rect.setAttribute('width', this.data.sw);
  10289. rect.setAttribute('height', this.data.sh);
  10290. rect.setAttribute('fill', this.data.sc);
  10291. this.layerElement.appendChild(rect);
  10292. };
  10293. function NullElement(data, globalData, comp) {
  10294. this.initFrame();
  10295. this.initBaseData(data, globalData, comp);
  10296. this.initFrame();
  10297. this.initTransform(data, globalData, comp);
  10298. this.initHierarchy();
  10299. }
  10300. NullElement.prototype.prepareFrame = function (num) {
  10301. this.prepareProperties(num, true);
  10302. };
  10303. NullElement.prototype.renderFrame = function () {
  10304. };
  10305. NullElement.prototype.getBaseElement = function () {
  10306. return null;
  10307. };
  10308. NullElement.prototype.destroy = function () {
  10309. };
  10310. NullElement.prototype.sourceRectAtTime = function () {
  10311. };
  10312. NullElement.prototype.hide = function () {
  10313. };
  10314. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10315. function SVGRendererBase() {
  10316. }
  10317. extendPrototype([BaseRenderer], SVGRendererBase);
  10318. SVGRendererBase.prototype.createNull = function (data) {
  10319. return new NullElement(data, this.globalData, this);
  10320. };
  10321. SVGRendererBase.prototype.createShape = function (data) {
  10322. return new SVGShapeElement(data, this.globalData, this);
  10323. };
  10324. SVGRendererBase.prototype.createText = function (data) {
  10325. return new SVGTextLottieElement(data, this.globalData, this);
  10326. };
  10327. SVGRendererBase.prototype.createImage = function (data) {
  10328. return new IImageElement(data, this.globalData, this);
  10329. };
  10330. SVGRendererBase.prototype.createSolid = function (data) {
  10331. return new ISolidElement(data, this.globalData, this);
  10332. };
  10333. SVGRendererBase.prototype.configAnimation = function (animData) {
  10334. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10335. this.svgElement.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  10336. if (this.renderConfig.viewBoxSize) {
  10337. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10338. } else {
  10339. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10340. }
  10341. if (!this.renderConfig.viewBoxOnly) {
  10342. this.svgElement.setAttribute('width', animData.w);
  10343. this.svgElement.setAttribute('height', animData.h);
  10344. this.svgElement.style.width = '100%';
  10345. this.svgElement.style.height = '100%';
  10346. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10347. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10348. }
  10349. if (this.renderConfig.width) {
  10350. this.svgElement.setAttribute('width', this.renderConfig.width);
  10351. }
  10352. if (this.renderConfig.height) {
  10353. this.svgElement.setAttribute('height', this.renderConfig.height);
  10354. }
  10355. if (this.renderConfig.className) {
  10356. this.svgElement.setAttribute('class', this.renderConfig.className);
  10357. }
  10358. if (this.renderConfig.id) {
  10359. this.svgElement.setAttribute('id', this.renderConfig.id);
  10360. }
  10361. if (this.renderConfig.focusable !== undefined) {
  10362. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10363. }
  10364. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio);
  10365. // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10366. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10367. this.animationItem.wrapper.appendChild(this.svgElement);
  10368. // Mask animation
  10369. var defs = this.globalData.defs;
  10370. this.setupGlobalData(animData, defs);
  10371. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10372. this.data = animData;
  10373. var maskElement = createNS('clipPath');
  10374. var rect = createNS('rect');
  10375. rect.setAttribute('width', animData.w);
  10376. rect.setAttribute('height', animData.h);
  10377. rect.setAttribute('x', 0);
  10378. rect.setAttribute('y', 0);
  10379. var maskId = createElementID();
  10380. maskElement.setAttribute('id', maskId);
  10381. maskElement.appendChild(rect);
  10382. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10383. defs.appendChild(maskElement);
  10384. this.layers = animData.layers;
  10385. this.elements = createSizedArray(animData.layers.length);
  10386. };
  10387. SVGRendererBase.prototype.destroy = function () {
  10388. if (this.animationItem.wrapper) {
  10389. this.animationItem.wrapper.innerText = '';
  10390. }
  10391. this.layerElement = null;
  10392. this.globalData.defs = null;
  10393. var i;
  10394. var len = this.layers ? this.layers.length : 0;
  10395. for (i = 0; i < len; i += 1) {
  10396. if (this.elements[i] && this.elements[i].destroy) {
  10397. this.elements[i].destroy();
  10398. }
  10399. }
  10400. this.elements.length = 0;
  10401. this.destroyed = true;
  10402. this.animationItem = null;
  10403. };
  10404. SVGRendererBase.prototype.updateContainerSize = function () {
  10405. };
  10406. SVGRendererBase.prototype.findIndexByInd = function (ind) {
  10407. var i = 0;
  10408. var len = this.layers.length;
  10409. for (i = 0; i < len; i += 1) {
  10410. if (this.layers[i].ind === ind) {
  10411. return i;
  10412. }
  10413. }
  10414. return -1;
  10415. };
  10416. SVGRendererBase.prototype.buildItem = function (pos) {
  10417. var elements = this.elements;
  10418. if (elements[pos] || this.layers[pos].ty === 99) {
  10419. return;
  10420. }
  10421. elements[pos] = true;
  10422. var element = this.createItem(this.layers[pos]);
  10423. elements[pos] = element;
  10424. if (getExpressionsPlugin()) {
  10425. if (this.layers[pos].ty === 0) {
  10426. this.globalData.projectInterface.registerComposition(element);
  10427. }
  10428. element.initExpressions();
  10429. }
  10430. this.appendElementInPos(element, pos);
  10431. if (this.layers[pos].tt) {
  10432. var elementIndex = ('tp' in this.layers[pos])
  10433. ? this.findIndexByInd(this.layers[pos].tp)
  10434. : pos - 1;
  10435. if (elementIndex === -1) {
  10436. return;
  10437. }
  10438. if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
  10439. this.buildItem(elementIndex);
  10440. this.addPendingElement(element);
  10441. } else {
  10442. var matteElement = elements[elementIndex];
  10443. var matteMask = matteElement.getMatte(this.layers[pos].tt);
  10444. element.setMatte(matteMask);
  10445. }
  10446. }
  10447. };
  10448. SVGRendererBase.prototype.checkPendingElements = function () {
  10449. while (this.pendingElements.length) {
  10450. var element = this.pendingElements.pop();
  10451. element.checkParenting();
  10452. if (element.data.tt) {
  10453. var i = 0;
  10454. var len = this.elements.length;
  10455. while (i < len) {
  10456. if (this.elements[i] === element) {
  10457. var elementIndex = 'tp' in element.data
  10458. ? this.findIndexByInd(element.data.tp)
  10459. : i - 1;
  10460. var matteElement = this.elements[elementIndex];
  10461. var matteMask = matteElement.getMatte(this.layers[i].tt);
  10462. element.setMatte(matteMask);
  10463. break;
  10464. }
  10465. i += 1;
  10466. }
  10467. }
  10468. }
  10469. };
  10470. SVGRendererBase.prototype.renderFrame = function (num) {
  10471. if (this.renderedFrame === num || this.destroyed) {
  10472. return;
  10473. }
  10474. if (num === null) {
  10475. num = this.renderedFrame;
  10476. } else {
  10477. this.renderedFrame = num;
  10478. }
  10479. // console.log('-------');
  10480. // console.log('FRAME ',num);
  10481. this.globalData.frameNum = num;
  10482. this.globalData.frameId += 1;
  10483. this.globalData.projectInterface.currentFrame = num;
  10484. this.globalData._mdf = false;
  10485. var i;
  10486. var len = this.layers.length;
  10487. if (!this.completeLayers) {
  10488. this.checkLayers(num);
  10489. }
  10490. for (i = len - 1; i >= 0; i -= 1) {
  10491. if (this.completeLayers || this.elements[i]) {
  10492. this.elements[i].prepareFrame(num - this.layers[i].st);
  10493. }
  10494. }
  10495. if (this.globalData._mdf) {
  10496. for (i = 0; i < len; i += 1) {
  10497. if (this.completeLayers || this.elements[i]) {
  10498. this.elements[i].renderFrame();
  10499. }
  10500. }
  10501. }
  10502. };
  10503. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10504. var newElement = element.getBaseElement();
  10505. if (!newElement) {
  10506. return;
  10507. }
  10508. var i = 0;
  10509. var nextElement;
  10510. while (i < pos) {
  10511. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10512. nextElement = this.elements[i].getBaseElement();
  10513. }
  10514. i += 1;
  10515. }
  10516. if (nextElement) {
  10517. this.layerElement.insertBefore(newElement, nextElement);
  10518. } else {
  10519. this.layerElement.appendChild(newElement);
  10520. }
  10521. };
  10522. SVGRendererBase.prototype.hide = function () {
  10523. this.layerElement.style.display = 'none';
  10524. };
  10525. SVGRendererBase.prototype.show = function () {
  10526. this.layerElement.style.display = 'block';
  10527. };
  10528. function ICompElement() {}
  10529. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10530. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10531. this.initFrame();
  10532. this.initBaseData(data, globalData, comp);
  10533. this.initTransform(data, globalData, comp);
  10534. this.initRenderable();
  10535. this.initHierarchy();
  10536. this.initRendererElement();
  10537. this.createContainerElements();
  10538. this.createRenderableComponents();
  10539. if (this.data.xt || !globalData.progressiveLoad) {
  10540. this.buildAllItems();
  10541. }
  10542. this.hide();
  10543. };
  10544. /* ICompElement.prototype.hide = function(){
  10545. if(!this.hidden){
  10546. this.hideElement();
  10547. var i,len = this.elements.length;
  10548. for( i = 0; i < len; i+=1 ){
  10549. if(this.elements[i]){
  10550. this.elements[i].hide();
  10551. }
  10552. }
  10553. }
  10554. }; */
  10555. ICompElement.prototype.prepareFrame = function (num) {
  10556. this._mdf = false;
  10557. this.prepareRenderableFrame(num);
  10558. this.prepareProperties(num, this.isInRange);
  10559. if (!this.isInRange && !this.data.xt) {
  10560. return;
  10561. }
  10562. if (!this.tm._placeholder) {
  10563. var timeRemapped = this.tm.v;
  10564. if (timeRemapped === this.data.op) {
  10565. timeRemapped = this.data.op - 1;
  10566. }
  10567. this.renderedFrame = timeRemapped;
  10568. } else {
  10569. this.renderedFrame = num / this.data.sr;
  10570. }
  10571. var i;
  10572. var len = this.elements.length;
  10573. if (!this.completeLayers) {
  10574. this.checkLayers(this.renderedFrame);
  10575. }
  10576. // This iteration needs to be backwards because of how expressions connect between each other
  10577. for (i = len - 1; i >= 0; i -= 1) {
  10578. if (this.completeLayers || this.elements[i]) {
  10579. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10580. if (this.elements[i]._mdf) {
  10581. this._mdf = true;
  10582. }
  10583. }
  10584. }
  10585. };
  10586. ICompElement.prototype.renderInnerContent = function () {
  10587. var i;
  10588. var len = this.layers.length;
  10589. for (i = 0; i < len; i += 1) {
  10590. if (this.completeLayers || this.elements[i]) {
  10591. this.elements[i].renderFrame();
  10592. }
  10593. }
  10594. };
  10595. ICompElement.prototype.setElements = function (elems) {
  10596. this.elements = elems;
  10597. };
  10598. ICompElement.prototype.getElements = function () {
  10599. return this.elements;
  10600. };
  10601. ICompElement.prototype.destroyElements = function () {
  10602. var i;
  10603. var len = this.layers.length;
  10604. for (i = 0; i < len; i += 1) {
  10605. if (this.elements[i]) {
  10606. this.elements[i].destroy();
  10607. }
  10608. }
  10609. };
  10610. ICompElement.prototype.destroy = function () {
  10611. this.destroyElements();
  10612. this.destroyBaseElement();
  10613. };
  10614. function SVGCompElement(data, globalData, comp) {
  10615. this.layers = data.layers;
  10616. this.supports3d = true;
  10617. this.completeLayers = false;
  10618. this.pendingElements = [];
  10619. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10620. this.initElement(data, globalData, comp);
  10621. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  10622. }
  10623. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10624. SVGCompElement.prototype.createComp = function (data) {
  10625. return new SVGCompElement(data, this.globalData, this);
  10626. };
  10627. function SVGRenderer(animationItem, config) {
  10628. this.animationItem = animationItem;
  10629. this.layers = null;
  10630. this.renderedFrame = -1;
  10631. this.svgElement = createNS('svg');
  10632. var ariaLabel = '';
  10633. if (config && config.title) {
  10634. var titleElement = createNS('title');
  10635. var titleId = createElementID();
  10636. titleElement.setAttribute('id', titleId);
  10637. titleElement.textContent = config.title;
  10638. this.svgElement.appendChild(titleElement);
  10639. ariaLabel += titleId;
  10640. }
  10641. if (config && config.description) {
  10642. var descElement = createNS('desc');
  10643. var descId = createElementID();
  10644. descElement.setAttribute('id', descId);
  10645. descElement.textContent = config.description;
  10646. this.svgElement.appendChild(descElement);
  10647. ariaLabel += ' ' + descId;
  10648. }
  10649. if (ariaLabel) {
  10650. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10651. }
  10652. var defs = createNS('defs');
  10653. this.svgElement.appendChild(defs);
  10654. var maskElement = createNS('g');
  10655. this.svgElement.appendChild(maskElement);
  10656. this.layerElement = maskElement;
  10657. this.renderConfig = {
  10658. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  10659. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  10660. contentVisibility: (config && config.contentVisibility) || 'visible',
  10661. progressiveLoad: (config && config.progressiveLoad) || false,
  10662. hideOnTransparent: !((config && config.hideOnTransparent === false)),
  10663. viewBoxOnly: (config && config.viewBoxOnly) || false,
  10664. viewBoxSize: (config && config.viewBoxSize) || false,
  10665. className: (config && config.className) || '',
  10666. id: (config && config.id) || '',
  10667. focusable: config && config.focusable,
  10668. filterSize: {
  10669. width: (config && config.filterSize && config.filterSize.width) || '100%',
  10670. height: (config && config.filterSize && config.filterSize.height) || '100%',
  10671. x: (config && config.filterSize && config.filterSize.x) || '0%',
  10672. y: (config && config.filterSize && config.filterSize.y) || '0%',
  10673. },
  10674. width: (config && config.width),
  10675. height: (config && config.height),
  10676. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  10677. };
  10678. this.globalData = {
  10679. _mdf: false,
  10680. frameNum: -1,
  10681. defs: defs,
  10682. renderConfig: this.renderConfig,
  10683. };
  10684. this.elements = [];
  10685. this.pendingElements = [];
  10686. this.destroyed = false;
  10687. this.rendererType = 'svg';
  10688. }
  10689. extendPrototype([SVGRendererBase], SVGRenderer);
  10690. SVGRenderer.prototype.createComp = function (data) {
  10691. return new SVGCompElement(data, this.globalData, this);
  10692. };
  10693. function ShapeTransformManager() {
  10694. this.sequences = {};
  10695. this.sequenceList = [];
  10696. this.transform_key_count = 0;
  10697. }
  10698. ShapeTransformManager.prototype = {
  10699. addTransformSequence: function (transforms) {
  10700. var i;
  10701. var len = transforms.length;
  10702. var key = '_';
  10703. for (i = 0; i < len; i += 1) {
  10704. key += transforms[i].transform.key + '_';
  10705. }
  10706. var sequence = this.sequences[key];
  10707. if (!sequence) {
  10708. sequence = {
  10709. transforms: [].concat(transforms),
  10710. finalTransform: new Matrix(),
  10711. _mdf: false,
  10712. };
  10713. this.sequences[key] = sequence;
  10714. this.sequenceList.push(sequence);
  10715. }
  10716. return sequence;
  10717. },
  10718. processSequence: function (sequence, isFirstFrame) {
  10719. var i = 0;
  10720. var len = sequence.transforms.length;
  10721. var _mdf = isFirstFrame;
  10722. while (i < len && !isFirstFrame) {
  10723. if (sequence.transforms[i].transform.mProps._mdf) {
  10724. _mdf = true;
  10725. break;
  10726. }
  10727. i += 1;
  10728. }
  10729. if (_mdf) {
  10730. sequence.finalTransform.reset();
  10731. for (i = len - 1; i >= 0; i -= 1) {
  10732. sequence.finalTransform.multiply(sequence.transforms[i].transform.mProps.v);
  10733. }
  10734. }
  10735. sequence._mdf = _mdf;
  10736. },
  10737. processSequences: function (isFirstFrame) {
  10738. var i;
  10739. var len = this.sequenceList.length;
  10740. for (i = 0; i < len; i += 1) {
  10741. this.processSequence(this.sequenceList[i], isFirstFrame);
  10742. }
  10743. },
  10744. getNewKey: function () {
  10745. this.transform_key_count += 1;
  10746. return '_' + this.transform_key_count;
  10747. },
  10748. };
  10749. var lumaLoader = (function () {
  10750. var id = '__lottie_element_luma_buffer';
  10751. var lumaBuffer = null;
  10752. var lumaBufferCtx = null;
  10753. var svg = null;
  10754. // This alternate solution has a slight delay before the filter is applied, resulting in a flicker on the first frame.
  10755. // Keeping this here for reference, and in the future, if offscreen canvas supports url filters, this can be used.
  10756. // For now, neither of them work for offscreen canvas, so canvas workers can't support the luma track matte mask.
  10757. // Naming it solution 2 to mark the extra comment lines.
  10758. /*
  10759. var svgString = [
  10760. '<svg xmlns="http://www.w3.org/2000/svg">',
  10761. '<filter id="' + id + '">',
  10762. '<feColorMatrix type="matrix" color-interpolation-filters="sRGB" values="',
  10763. '0.3, 0.3, 0.3, 0, 0, ',
  10764. '0.3, 0.3, 0.3, 0, 0, ',
  10765. '0.3, 0.3, 0.3, 0, 0, ',
  10766. '0.3, 0.3, 0.3, 0, 0',
  10767. '"/>',
  10768. '</filter>',
  10769. '</svg>',
  10770. ].join('');
  10771. var blob = new Blob([svgString], { type: 'image/svg+xml' });
  10772. var url = URL.createObjectURL(blob);
  10773. */
  10774. function createLumaSvgFilter() {
  10775. var _svg = createNS('svg');
  10776. var fil = createNS('filter');
  10777. var matrix = createNS('feColorMatrix');
  10778. fil.setAttribute('id', id);
  10779. matrix.setAttribute('type', 'matrix');
  10780. matrix.setAttribute('color-interpolation-filters', 'sRGB');
  10781. matrix.setAttribute('values', '0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0, 0.3, 0.3, 0.3, 0, 0');
  10782. fil.appendChild(matrix);
  10783. _svg.appendChild(fil);
  10784. _svg.setAttribute('id', id + '_svg');
  10785. if (featureSupport.svgLumaHidden) {
  10786. _svg.style.display = 'none';
  10787. }
  10788. return _svg;
  10789. }
  10790. function loadLuma() {
  10791. if (!lumaBuffer) {
  10792. svg = createLumaSvgFilter();
  10793. document.body.appendChild(svg);
  10794. lumaBuffer = createTag('canvas');
  10795. lumaBufferCtx = lumaBuffer.getContext('2d');
  10796. // lumaBufferCtx.filter = `url('${url}#__lottie_element_luma_buffer')`; // part of solution 2
  10797. lumaBufferCtx.filter = 'url(#' + id + ')';
  10798. lumaBufferCtx.fillStyle = 'rgba(0,0,0,0)';
  10799. lumaBufferCtx.fillRect(0, 0, 1, 1);
  10800. }
  10801. }
  10802. function getLuma(canvas) {
  10803. if (!lumaBuffer) {
  10804. loadLuma();
  10805. }
  10806. lumaBuffer.width = canvas.width;
  10807. lumaBuffer.height = canvas.height;
  10808. // lumaBufferCtx.filter = `url('${url}#__lottie_element_luma_buffer')`; // part of solution 2
  10809. lumaBufferCtx.filter = 'url(#' + id + ')';
  10810. return lumaBuffer;
  10811. }
  10812. return {
  10813. load: loadLuma,
  10814. get: getLuma,
  10815. };
  10816. });
  10817. function createCanvas(width, height) {
  10818. if (featureSupport.offscreenCanvas) {
  10819. return new OffscreenCanvas(width, height);
  10820. }
  10821. var canvas = createTag('canvas');
  10822. canvas.width = width;
  10823. canvas.height = height;
  10824. return canvas;
  10825. }
  10826. const assetLoader = (function () {
  10827. return {
  10828. loadLumaCanvas: lumaLoader.load,
  10829. getLumaCanvas: lumaLoader.get,
  10830. createCanvas: createCanvas,
  10831. };
  10832. }());
  10833. var registeredEffects = {};
  10834. function CVEffects(elem) {
  10835. var i;
  10836. var len = elem.data.ef ? elem.data.ef.length : 0;
  10837. this.filters = [];
  10838. var filterManager;
  10839. for (i = 0; i < len; i += 1) {
  10840. filterManager = null;
  10841. var type = elem.data.ef[i].ty;
  10842. if (registeredEffects[type]) {
  10843. var Effect = registeredEffects[type].effect;
  10844. filterManager = new Effect(elem.effectsManager.effectElements[i], elem);
  10845. }
  10846. if (filterManager) {
  10847. this.filters.push(filterManager);
  10848. }
  10849. }
  10850. if (this.filters.length) {
  10851. elem.addRenderableComponent(this);
  10852. }
  10853. }
  10854. CVEffects.prototype.renderFrame = function (_isFirstFrame) {
  10855. var i;
  10856. var len = this.filters.length;
  10857. for (i = 0; i < len; i += 1) {
  10858. this.filters[i].renderFrame(_isFirstFrame);
  10859. }
  10860. };
  10861. CVEffects.prototype.getEffects = function (type) {
  10862. var i;
  10863. var len = this.filters.length;
  10864. var effects = [];
  10865. for (i = 0; i < len; i += 1) {
  10866. if (this.filters[i].type === type) {
  10867. effects.push(this.filters[i]);
  10868. }
  10869. }
  10870. return effects;
  10871. };
  10872. function registerEffect(id, effect) {
  10873. registeredEffects[id] = {
  10874. effect,
  10875. };
  10876. }
  10877. function CVMaskElement(data, element) {
  10878. this.data = data;
  10879. this.element = element;
  10880. this.masksProperties = this.data.masksProperties || [];
  10881. this.viewData = createSizedArray(this.masksProperties.length);
  10882. var i;
  10883. var len = this.masksProperties.length;
  10884. var hasMasks = false;
  10885. for (i = 0; i < len; i += 1) {
  10886. if (this.masksProperties[i].mode !== 'n') {
  10887. hasMasks = true;
  10888. }
  10889. this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element, this.masksProperties[i], 3);
  10890. }
  10891. this.hasMasks = hasMasks;
  10892. if (hasMasks) {
  10893. this.element.addRenderableComponent(this);
  10894. }
  10895. }
  10896. CVMaskElement.prototype.renderFrame = function () {
  10897. if (!this.hasMasks) {
  10898. return;
  10899. }
  10900. var transform = this.element.finalTransform.mat;
  10901. var ctx = this.element.canvasContext;
  10902. var i;
  10903. var len = this.masksProperties.length;
  10904. var pt;
  10905. var pts;
  10906. var data;
  10907. ctx.beginPath();
  10908. for (i = 0; i < len; i += 1) {
  10909. if (this.masksProperties[i].mode !== 'n') {
  10910. if (this.masksProperties[i].inv) {
  10911. ctx.moveTo(0, 0);
  10912. ctx.lineTo(this.element.globalData.compSize.w, 0);
  10913. ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h);
  10914. ctx.lineTo(0, this.element.globalData.compSize.h);
  10915. ctx.lineTo(0, 0);
  10916. }
  10917. data = this.viewData[i].v;
  10918. pt = transform.applyToPointArray(data.v[0][0], data.v[0][1], 0);
  10919. ctx.moveTo(pt[0], pt[1]);
  10920. var j;
  10921. var jLen = data._length;
  10922. for (j = 1; j < jLen; j += 1) {
  10923. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]);
  10924. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  10925. }
  10926. pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]);
  10927. ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
  10928. }
  10929. }
  10930. this.element.globalData.renderer.save(true);
  10931. ctx.clip();
  10932. };
  10933. CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty;
  10934. CVMaskElement.prototype.destroy = function () {
  10935. this.element = null;
  10936. };
  10937. function CVBaseElement() {
  10938. }
  10939. var operationsMap = {
  10940. 1: 'source-in',
  10941. 2: 'source-out',
  10942. 3: 'source-in',
  10943. 4: 'source-out',
  10944. };
  10945. CVBaseElement.prototype = {
  10946. createElements: function () {},
  10947. initRendererElement: function () {},
  10948. createContainerElements: function () {
  10949. // If the layer is masked we will use two buffers to store each different states of the drawing
  10950. // This solution is not ideal for several reason. But unfortunately, because of the recursive
  10951. // nature of the render tree, it's the only simple way to make sure one inner mask doesn't override an outer mask.
  10952. // TODO: try to reduce the size of these buffers to the size of the composition contaning the layer
  10953. // It might be challenging because the layer most likely is transformed in some way
  10954. if (this.data.tt >= 1) {
  10955. this.buffers = [];
  10956. var canvasContext = this.globalData.canvasContext;
  10957. var bufferCanvas = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
  10958. this.buffers.push(bufferCanvas);
  10959. var bufferCanvas2 = assetLoader.createCanvas(canvasContext.canvas.width, canvasContext.canvas.height);
  10960. this.buffers.push(bufferCanvas2);
  10961. if (this.data.tt >= 3 && !document._isProxy) {
  10962. assetLoader.loadLumaCanvas();
  10963. }
  10964. }
  10965. this.canvasContext = this.globalData.canvasContext;
  10966. this.transformCanvas = this.globalData.transformCanvas;
  10967. this.renderableEffectsManager = new CVEffects(this);
  10968. this.searchEffectTransforms();
  10969. },
  10970. createContent: function () {},
  10971. setBlendMode: function () {
  10972. var globalData = this.globalData;
  10973. if (globalData.blendMode !== this.data.bm) {
  10974. globalData.blendMode = this.data.bm;
  10975. var blendModeValue = getBlendMode(this.data.bm);
  10976. globalData.canvasContext.globalCompositeOperation = blendModeValue;
  10977. }
  10978. },
  10979. createRenderableComponents: function () {
  10980. this.maskManager = new CVMaskElement(this.data, this);
  10981. this.transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  10982. },
  10983. hideElement: function () {
  10984. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  10985. this.hidden = true;
  10986. }
  10987. },
  10988. showElement: function () {
  10989. if (this.isInRange && !this.isTransparent) {
  10990. this.hidden = false;
  10991. this._isFirstFrame = true;
  10992. this.maskManager._isFirstFrame = true;
  10993. }
  10994. },
  10995. clearCanvas: function (canvasContext) {
  10996. canvasContext.clearRect(
  10997. this.transformCanvas.tx,
  10998. this.transformCanvas.ty,
  10999. this.transformCanvas.w * this.transformCanvas.sx,
  11000. this.transformCanvas.h * this.transformCanvas.sy
  11001. );
  11002. },
  11003. prepareLayer: function () {
  11004. if (this.data.tt >= 1) {
  11005. var buffer = this.buffers[0];
  11006. var bufferCtx = buffer.getContext('2d');
  11007. this.clearCanvas(bufferCtx);
  11008. // on the first buffer we store the current state of the global drawing
  11009. bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11010. // The next four lines are to clear the canvas
  11011. // TODO: Check if there is a way to clear the canvas without resetting the transform
  11012. this.currentTransform = this.canvasContext.getTransform();
  11013. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11014. this.clearCanvas(this.canvasContext);
  11015. this.canvasContext.setTransform(this.currentTransform);
  11016. }
  11017. },
  11018. exitLayer: function () {
  11019. if (this.data.tt >= 1) {
  11020. var buffer = this.buffers[1];
  11021. // On the second buffer we store the current state of the global drawing
  11022. // that only contains the content of this layer
  11023. // (if it is a composition, it also includes the nested layers)
  11024. var bufferCtx = buffer.getContext('2d');
  11025. this.clearCanvas(bufferCtx);
  11026. bufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11027. // We clear the canvas again
  11028. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11029. this.clearCanvas(this.canvasContext);
  11030. this.canvasContext.setTransform(this.currentTransform);
  11031. // We draw the mask
  11032. const mask = this.comp.getElementById('tp' in this.data ? this.data.tp : this.data.ind - 1);
  11033. mask.renderFrame(true);
  11034. // We draw the second buffer (that contains the content of this layer)
  11035. this.canvasContext.setTransform(1, 0, 0, 1, 0, 0);
  11036. // If the mask is a Luma matte, we need to do two extra painting operations
  11037. // the _isProxy check is to avoid drawing a fake canvas in workers that will throw an error
  11038. if (this.data.tt >= 3 && !document._isProxy) {
  11039. // We copy the painted mask to a buffer that has a color matrix filter applied to it
  11040. // that applies the rgb values to the alpha channel
  11041. var lumaBuffer = assetLoader.getLumaCanvas(this.canvasContext.canvas);
  11042. var lumaBufferCtx = lumaBuffer.getContext('2d');
  11043. lumaBufferCtx.drawImage(this.canvasContext.canvas, 0, 0);
  11044. this.clearCanvas(this.canvasContext);
  11045. // we repaint the context with the mask applied to it
  11046. this.canvasContext.drawImage(lumaBuffer, 0, 0);
  11047. }
  11048. this.canvasContext.globalCompositeOperation = operationsMap[this.data.tt];
  11049. this.canvasContext.drawImage(buffer, 0, 0);
  11050. // We finally draw the first buffer (that contains the content of the global drawing)
  11051. // We use destination-over to draw the global drawing below the current layer
  11052. this.canvasContext.globalCompositeOperation = 'destination-over';
  11053. this.canvasContext.drawImage(this.buffers[0], 0, 0);
  11054. this.canvasContext.setTransform(this.currentTransform);
  11055. // We reset the globalCompositeOperation to source-over, the standard type of operation
  11056. this.canvasContext.globalCompositeOperation = 'source-over';
  11057. }
  11058. },
  11059. renderFrame: function (forceRender) {
  11060. if (this.hidden || this.data.hd) {
  11061. return;
  11062. }
  11063. if (this.data.td === 1 && !forceRender) {
  11064. return;
  11065. }
  11066. this.renderTransform();
  11067. this.renderRenderable();
  11068. this.renderLocalTransform();
  11069. this.setBlendMode();
  11070. var forceRealStack = this.data.ty === 0;
  11071. this.prepareLayer();
  11072. this.globalData.renderer.save(forceRealStack);
  11073. this.globalData.renderer.ctxTransform(this.finalTransform.localMat.props);
  11074. this.globalData.renderer.ctxOpacity(this.finalTransform.localOpacity);
  11075. this.renderInnerContent();
  11076. this.globalData.renderer.restore(forceRealStack);
  11077. this.exitLayer();
  11078. if (this.maskManager.hasMasks) {
  11079. this.globalData.renderer.restore(true);
  11080. }
  11081. if (this._isFirstFrame) {
  11082. this._isFirstFrame = false;
  11083. }
  11084. },
  11085. destroy: function () {
  11086. this.canvasContext = null;
  11087. this.data = null;
  11088. this.globalData = null;
  11089. this.maskManager.destroy();
  11090. },
  11091. mHelper: new Matrix(),
  11092. };
  11093. CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement;
  11094. CVBaseElement.prototype.show = CVBaseElement.prototype.showElement;
  11095. function CVShapeData(element, data, styles, transformsManager) {
  11096. this.styledShapes = [];
  11097. this.tr = [0, 0, 0, 0, 0, 0];
  11098. var ty = 4;
  11099. if (data.ty === 'rc') {
  11100. ty = 5;
  11101. } else if (data.ty === 'el') {
  11102. ty = 6;
  11103. } else if (data.ty === 'sr') {
  11104. ty = 7;
  11105. }
  11106. this.sh = ShapePropertyFactory.getShapeProp(element, data, ty, element);
  11107. var i;
  11108. var len = styles.length;
  11109. var styledShape;
  11110. for (i = 0; i < len; i += 1) {
  11111. if (!styles[i].closed) {
  11112. styledShape = {
  11113. transforms: transformsManager.addTransformSequence(styles[i].transforms),
  11114. trNodes: [],
  11115. };
  11116. this.styledShapes.push(styledShape);
  11117. styles[i].elements.push(styledShape);
  11118. }
  11119. }
  11120. }
  11121. CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated;
  11122. function CVShapeElement(data, globalData, comp) {
  11123. this.shapes = [];
  11124. this.shapesData = data.shapes;
  11125. this.stylesList = [];
  11126. this.itemsData = [];
  11127. this.prevViewData = [];
  11128. this.shapeModifiers = [];
  11129. this.processedElements = [];
  11130. this.transformsManager = new ShapeTransformManager();
  11131. this.initElement(data, globalData, comp);
  11132. }
  11133. extendPrototype([BaseElement, TransformElement, CVBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableElement], CVShapeElement);
  11134. CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement;
  11135. CVShapeElement.prototype.transformHelper = { opacity: 1, _opMdf: false };
  11136. CVShapeElement.prototype.dashResetter = [];
  11137. CVShapeElement.prototype.createContent = function () {
  11138. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11139. };
  11140. CVShapeElement.prototype.createStyleElement = function (data, transforms) {
  11141. var styleElem = {
  11142. data: data,
  11143. type: data.ty,
  11144. preTransforms: this.transformsManager.addTransformSequence(transforms),
  11145. transforms: [],
  11146. elements: [],
  11147. closed: data.hd === true,
  11148. };
  11149. var elementData = {};
  11150. if (data.ty === 'fl' || data.ty === 'st') {
  11151. elementData.c = PropertyFactory.getProp(this, data.c, 1, 255, this);
  11152. if (!elementData.c.k) {
  11153. styleElem.co = 'rgb(' + bmFloor(elementData.c.v[0]) + ',' + bmFloor(elementData.c.v[1]) + ',' + bmFloor(elementData.c.v[2]) + ')';
  11154. }
  11155. } else if (data.ty === 'gf' || data.ty === 'gs') {
  11156. elementData.s = PropertyFactory.getProp(this, data.s, 1, null, this);
  11157. elementData.e = PropertyFactory.getProp(this, data.e, 1, null, this);
  11158. elementData.h = PropertyFactory.getProp(this, data.h || { k: 0 }, 0, 0.01, this);
  11159. elementData.a = PropertyFactory.getProp(this, data.a || { k: 0 }, 0, degToRads, this);
  11160. elementData.g = new GradientProperty(this, data.g, this);
  11161. }
  11162. elementData.o = PropertyFactory.getProp(this, data.o, 0, 0.01, this);
  11163. if (data.ty === 'st' || data.ty === 'gs') {
  11164. styleElem.lc = lineCapEnum[data.lc || 2];
  11165. styleElem.lj = lineJoinEnum[data.lj || 2];
  11166. if (data.lj == 1) { // eslint-disable-line eqeqeq
  11167. styleElem.ml = data.ml;
  11168. }
  11169. elementData.w = PropertyFactory.getProp(this, data.w, 0, null, this);
  11170. if (!elementData.w.k) {
  11171. styleElem.wi = elementData.w.v;
  11172. }
  11173. if (data.d) {
  11174. var d = new DashProperty(this, data.d, 'canvas', this);
  11175. elementData.d = d;
  11176. if (!elementData.d.k) {
  11177. styleElem.da = elementData.d.dashArray;
  11178. styleElem.do = elementData.d.dashoffset[0];
  11179. }
  11180. }
  11181. } else {
  11182. styleElem.r = data.r === 2 ? 'evenodd' : 'nonzero';
  11183. }
  11184. this.stylesList.push(styleElem);
  11185. elementData.style = styleElem;
  11186. return elementData;
  11187. };
  11188. CVShapeElement.prototype.createGroupElement = function () {
  11189. var elementData = {
  11190. it: [],
  11191. prevViewData: [],
  11192. };
  11193. return elementData;
  11194. };
  11195. CVShapeElement.prototype.createTransformElement = function (data) {
  11196. var elementData = {
  11197. transform: {
  11198. opacity: 1,
  11199. _opMdf: false,
  11200. key: this.transformsManager.getNewKey(),
  11201. op: PropertyFactory.getProp(this, data.o, 0, 0.01, this),
  11202. mProps: TransformPropertyFactory.getTransformProperty(this, data, this),
  11203. },
  11204. };
  11205. return elementData;
  11206. };
  11207. CVShapeElement.prototype.createShapeElement = function (data) {
  11208. var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager);
  11209. this.shapes.push(elementData);
  11210. this.addShapeToModifiers(elementData);
  11211. return elementData;
  11212. };
  11213. CVShapeElement.prototype.reloadShapes = function () {
  11214. this._isFirstFrame = true;
  11215. var i;
  11216. var len = this.itemsData.length;
  11217. for (i = 0; i < len; i += 1) {
  11218. this.prevViewData[i] = this.itemsData[i];
  11219. }
  11220. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []);
  11221. len = this.dynamicProperties.length;
  11222. for (i = 0; i < len; i += 1) {
  11223. this.dynamicProperties[i].getValue();
  11224. }
  11225. this.renderModifiers();
  11226. this.transformsManager.processSequences(this._isFirstFrame);
  11227. };
  11228. CVShapeElement.prototype.addTransformToStyleList = function (transform) {
  11229. var i;
  11230. var len = this.stylesList.length;
  11231. for (i = 0; i < len; i += 1) {
  11232. if (!this.stylesList[i].closed) {
  11233. this.stylesList[i].transforms.push(transform);
  11234. }
  11235. }
  11236. };
  11237. CVShapeElement.prototype.removeTransformFromStyleList = function () {
  11238. var i;
  11239. var len = this.stylesList.length;
  11240. for (i = 0; i < len; i += 1) {
  11241. if (!this.stylesList[i].closed) {
  11242. this.stylesList[i].transforms.pop();
  11243. }
  11244. }
  11245. };
  11246. CVShapeElement.prototype.closeStyles = function (styles) {
  11247. var i;
  11248. var len = styles.length;
  11249. for (i = 0; i < len; i += 1) {
  11250. styles[i].closed = true;
  11251. }
  11252. };
  11253. CVShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, shouldRender, transforms) {
  11254. var i;
  11255. var len = arr.length - 1;
  11256. var j;
  11257. var jLen;
  11258. var ownStyles = [];
  11259. var ownModifiers = [];
  11260. var processedPos;
  11261. var modifier;
  11262. var currentTransform;
  11263. var ownTransforms = [].concat(transforms);
  11264. for (i = len; i >= 0; i -= 1) {
  11265. processedPos = this.searchProcessedElement(arr[i]);
  11266. if (!processedPos) {
  11267. arr[i]._shouldRender = shouldRender;
  11268. } else {
  11269. itemsData[i] = prevViewData[processedPos - 1];
  11270. }
  11271. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs') {
  11272. if (!processedPos) {
  11273. itemsData[i] = this.createStyleElement(arr[i], ownTransforms);
  11274. } else {
  11275. itemsData[i].style.closed = false;
  11276. }
  11277. ownStyles.push(itemsData[i].style);
  11278. } else if (arr[i].ty === 'gr') {
  11279. if (!processedPos) {
  11280. itemsData[i] = this.createGroupElement(arr[i]);
  11281. } else {
  11282. jLen = itemsData[i].it.length;
  11283. for (j = 0; j < jLen; j += 1) {
  11284. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  11285. }
  11286. }
  11287. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, shouldRender, ownTransforms);
  11288. } else if (arr[i].ty === 'tr') {
  11289. if (!processedPos) {
  11290. currentTransform = this.createTransformElement(arr[i]);
  11291. itemsData[i] = currentTransform;
  11292. }
  11293. ownTransforms.push(itemsData[i]);
  11294. this.addTransformToStyleList(itemsData[i]);
  11295. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  11296. if (!processedPos) {
  11297. itemsData[i] = this.createShapeElement(arr[i]);
  11298. }
  11299. } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'pb' || arr[i].ty === 'zz' || arr[i].ty === 'op') {
  11300. if (!processedPos) {
  11301. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11302. modifier.init(this, arr[i]);
  11303. itemsData[i] = modifier;
  11304. this.shapeModifiers.push(modifier);
  11305. } else {
  11306. modifier = itemsData[i];
  11307. modifier.closed = false;
  11308. }
  11309. ownModifiers.push(modifier);
  11310. } else if (arr[i].ty === 'rp') {
  11311. if (!processedPos) {
  11312. modifier = ShapeModifiers.getModifier(arr[i].ty);
  11313. itemsData[i] = modifier;
  11314. modifier.init(this, arr, i, itemsData);
  11315. this.shapeModifiers.push(modifier);
  11316. shouldRender = false;
  11317. } else {
  11318. modifier = itemsData[i];
  11319. modifier.closed = true;
  11320. }
  11321. ownModifiers.push(modifier);
  11322. }
  11323. this.addProcessedElement(arr[i], i + 1);
  11324. }
  11325. this.removeTransformFromStyleList();
  11326. this.closeStyles(ownStyles);
  11327. len = ownModifiers.length;
  11328. for (i = 0; i < len; i += 1) {
  11329. ownModifiers[i].closed = true;
  11330. }
  11331. };
  11332. CVShapeElement.prototype.renderInnerContent = function () {
  11333. this.transformHelper.opacity = 1;
  11334. this.transformHelper._opMdf = false;
  11335. this.renderModifiers();
  11336. this.transformsManager.processSequences(this._isFirstFrame);
  11337. this.renderShape(this.transformHelper, this.shapesData, this.itemsData, true);
  11338. };
  11339. CVShapeElement.prototype.renderShapeTransform = function (parentTransform, groupTransform) {
  11340. if (parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) {
  11341. groupTransform.opacity = parentTransform.opacity;
  11342. groupTransform.opacity *= groupTransform.op.v;
  11343. groupTransform._opMdf = true;
  11344. }
  11345. };
  11346. CVShapeElement.prototype.drawLayer = function () {
  11347. var i;
  11348. var len = this.stylesList.length;
  11349. var j;
  11350. var jLen;
  11351. var k;
  11352. var kLen;
  11353. var elems;
  11354. var nodes;
  11355. var renderer = this.globalData.renderer;
  11356. var ctx = this.globalData.canvasContext;
  11357. var type;
  11358. var currentStyle;
  11359. for (i = 0; i < len; i += 1) {
  11360. currentStyle = this.stylesList[i];
  11361. type = currentStyle.type;
  11362. // Skipping style when
  11363. // Stroke width equals 0
  11364. // style should not be rendered (extra unused repeaters)
  11365. // current opacity equals 0
  11366. // global opacity equals 0
  11367. if (!(((type === 'st' || type === 'gs') && currentStyle.wi === 0) || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0)) {
  11368. renderer.save();
  11369. elems = currentStyle.elements;
  11370. if (type === 'st' || type === 'gs') {
  11371. renderer.ctxStrokeStyle(type === 'st' ? currentStyle.co : currentStyle.grd);
  11372. // ctx.strokeStyle = type === 'st' ? currentStyle.co : currentStyle.grd;
  11373. renderer.ctxLineWidth(currentStyle.wi);
  11374. // ctx.lineWidth = currentStyle.wi;
  11375. renderer.ctxLineCap(currentStyle.lc);
  11376. // ctx.lineCap = currentStyle.lc;
  11377. renderer.ctxLineJoin(currentStyle.lj);
  11378. // ctx.lineJoin = currentStyle.lj;
  11379. renderer.ctxMiterLimit(currentStyle.ml || 0);
  11380. // ctx.miterLimit = currentStyle.ml || 0;
  11381. } else {
  11382. renderer.ctxFillStyle(type === 'fl' ? currentStyle.co : currentStyle.grd);
  11383. // ctx.fillStyle = type === 'fl' ? currentStyle.co : currentStyle.grd;
  11384. }
  11385. renderer.ctxOpacity(currentStyle.coOp);
  11386. if (type !== 'st' && type !== 'gs') {
  11387. ctx.beginPath();
  11388. }
  11389. renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props);
  11390. jLen = elems.length;
  11391. for (j = 0; j < jLen; j += 1) {
  11392. if (type === 'st' || type === 'gs') {
  11393. ctx.beginPath();
  11394. if (currentStyle.da) {
  11395. ctx.setLineDash(currentStyle.da);
  11396. ctx.lineDashOffset = currentStyle.do;
  11397. }
  11398. }
  11399. nodes = elems[j].trNodes;
  11400. kLen = nodes.length;
  11401. for (k = 0; k < kLen; k += 1) {
  11402. if (nodes[k].t === 'm') {
  11403. ctx.moveTo(nodes[k].p[0], nodes[k].p[1]);
  11404. } else if (nodes[k].t === 'c') {
  11405. ctx.bezierCurveTo(nodes[k].pts[0], nodes[k].pts[1], nodes[k].pts[2], nodes[k].pts[3], nodes[k].pts[4], nodes[k].pts[5]);
  11406. } else {
  11407. ctx.closePath();
  11408. }
  11409. }
  11410. if (type === 'st' || type === 'gs') {
  11411. // ctx.stroke();
  11412. renderer.ctxStroke();
  11413. if (currentStyle.da) {
  11414. ctx.setLineDash(this.dashResetter);
  11415. }
  11416. }
  11417. }
  11418. if (type !== 'st' && type !== 'gs') {
  11419. // ctx.fill(currentStyle.r);
  11420. this.globalData.renderer.ctxFill(currentStyle.r);
  11421. }
  11422. renderer.restore();
  11423. }
  11424. }
  11425. };
  11426. CVShapeElement.prototype.renderShape = function (parentTransform, items, data, isMain) {
  11427. var i;
  11428. var len = items.length - 1;
  11429. var groupTransform;
  11430. groupTransform = parentTransform;
  11431. for (i = len; i >= 0; i -= 1) {
  11432. if (items[i].ty === 'tr') {
  11433. groupTransform = data[i].transform;
  11434. this.renderShapeTransform(parentTransform, groupTransform);
  11435. } else if (items[i].ty === 'sh' || items[i].ty === 'el' || items[i].ty === 'rc' || items[i].ty === 'sr') {
  11436. this.renderPath(items[i], data[i]);
  11437. } else if (items[i].ty === 'fl') {
  11438. this.renderFill(items[i], data[i], groupTransform);
  11439. } else if (items[i].ty === 'st') {
  11440. this.renderStroke(items[i], data[i], groupTransform);
  11441. } else if (items[i].ty === 'gf' || items[i].ty === 'gs') {
  11442. this.renderGradientFill(items[i], data[i], groupTransform);
  11443. } else if (items[i].ty === 'gr') {
  11444. this.renderShape(groupTransform, items[i].it, data[i].it);
  11445. } else if (items[i].ty === 'tm') {
  11446. //
  11447. }
  11448. }
  11449. if (isMain) {
  11450. this.drawLayer();
  11451. }
  11452. };
  11453. CVShapeElement.prototype.renderStyledShape = function (styledShape, shape) {
  11454. if (this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) {
  11455. var shapeNodes = styledShape.trNodes;
  11456. var paths = shape.paths;
  11457. var i;
  11458. var len;
  11459. var j;
  11460. var jLen = paths._length;
  11461. shapeNodes.length = 0;
  11462. var groupTransformMat = styledShape.transforms.finalTransform;
  11463. for (j = 0; j < jLen; j += 1) {
  11464. var pathNodes = paths.shapes[j];
  11465. if (pathNodes && pathNodes.v) {
  11466. len = pathNodes._length;
  11467. for (i = 1; i < len; i += 1) {
  11468. if (i === 1) {
  11469. shapeNodes.push({
  11470. t: 'm',
  11471. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0),
  11472. });
  11473. }
  11474. shapeNodes.push({
  11475. t: 'c',
  11476. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i]),
  11477. });
  11478. }
  11479. if (len === 1) {
  11480. shapeNodes.push({
  11481. t: 'm',
  11482. p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0),
  11483. });
  11484. }
  11485. if (pathNodes.c && len) {
  11486. shapeNodes.push({
  11487. t: 'c',
  11488. pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0]),
  11489. });
  11490. shapeNodes.push({
  11491. t: 'z',
  11492. });
  11493. }
  11494. }
  11495. }
  11496. styledShape.trNodes = shapeNodes;
  11497. }
  11498. };
  11499. CVShapeElement.prototype.renderPath = function (pathData, itemData) {
  11500. if (pathData.hd !== true && pathData._shouldRender) {
  11501. var i;
  11502. var len = itemData.styledShapes.length;
  11503. for (i = 0; i < len; i += 1) {
  11504. this.renderStyledShape(itemData.styledShapes[i], itemData.sh);
  11505. }
  11506. }
  11507. };
  11508. CVShapeElement.prototype.renderFill = function (styleData, itemData, groupTransform) {
  11509. var styleElem = itemData.style;
  11510. if (itemData.c._mdf || this._isFirstFrame) {
  11511. styleElem.co = 'rgb('
  11512. + bmFloor(itemData.c.v[0]) + ','
  11513. + bmFloor(itemData.c.v[1]) + ','
  11514. + bmFloor(itemData.c.v[2]) + ')';
  11515. }
  11516. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11517. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11518. }
  11519. };
  11520. CVShapeElement.prototype.renderGradientFill = function (styleData, itemData, groupTransform) {
  11521. var styleElem = itemData.style;
  11522. var grd;
  11523. if (!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || (styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf))) {
  11524. var ctx = this.globalData.canvasContext;
  11525. var pt1 = itemData.s.v;
  11526. var pt2 = itemData.e.v;
  11527. if (styleData.t === 1) {
  11528. grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]);
  11529. } else {
  11530. var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  11531. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  11532. var percent = itemData.h.v;
  11533. if (percent >= 1) {
  11534. percent = 0.99;
  11535. } else if (percent <= -1) {
  11536. percent = -0.99;
  11537. }
  11538. var dist = rad * percent;
  11539. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  11540. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  11541. grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad);
  11542. }
  11543. var i;
  11544. var len = styleData.g.p;
  11545. var cValues = itemData.g.c;
  11546. var opacity = 1;
  11547. for (i = 0; i < len; i += 1) {
  11548. if (itemData.g._hasOpacity && itemData.g._collapsable) {
  11549. opacity = itemData.g.o[i * 2 + 1];
  11550. }
  11551. grd.addColorStop(cValues[i * 4] / 100, 'rgba(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ',' + opacity + ')');
  11552. }
  11553. styleElem.grd = grd;
  11554. }
  11555. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11556. };
  11557. CVShapeElement.prototype.renderStroke = function (styleData, itemData, groupTransform) {
  11558. var styleElem = itemData.style;
  11559. var d = itemData.d;
  11560. if (d && (d._mdf || this._isFirstFrame)) {
  11561. styleElem.da = d.dashArray;
  11562. styleElem.do = d.dashoffset[0];
  11563. }
  11564. if (itemData.c._mdf || this._isFirstFrame) {
  11565. styleElem.co = 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')';
  11566. }
  11567. if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) {
  11568. styleElem.coOp = itemData.o.v * groupTransform.opacity;
  11569. }
  11570. if (itemData.w._mdf || this._isFirstFrame) {
  11571. styleElem.wi = itemData.w.v;
  11572. }
  11573. };
  11574. CVShapeElement.prototype.destroy = function () {
  11575. this.shapesData = null;
  11576. this.globalData = null;
  11577. this.canvasContext = null;
  11578. this.stylesList.length = 0;
  11579. this.itemsData.length = 0;
  11580. };
  11581. function CVTextElement(data, globalData, comp) {
  11582. this.textSpans = [];
  11583. this.yOffset = 0;
  11584. this.fillColorAnim = false;
  11585. this.strokeColorAnim = false;
  11586. this.strokeWidthAnim = false;
  11587. this.stroke = false;
  11588. this.fill = false;
  11589. this.justifyOffset = 0;
  11590. this.currentRender = null;
  11591. this.renderType = 'canvas';
  11592. this.values = {
  11593. fill: 'rgba(0,0,0,0)',
  11594. stroke: 'rgba(0,0,0,0)',
  11595. sWidth: 0,
  11596. fValue: '',
  11597. };
  11598. this.initElement(data, globalData, comp);
  11599. }
  11600. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement, ITextElement], CVTextElement);
  11601. CVTextElement.prototype.tHelper = createTag('canvas').getContext('2d');
  11602. CVTextElement.prototype.buildNewText = function () {
  11603. var documentData = this.textProperty.currentData;
  11604. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  11605. var hasFill = false;
  11606. if (documentData.fc) {
  11607. hasFill = true;
  11608. this.values.fill = this.buildColor(documentData.fc);
  11609. } else {
  11610. this.values.fill = 'rgba(0,0,0,0)';
  11611. }
  11612. this.fill = hasFill;
  11613. var hasStroke = false;
  11614. if (documentData.sc) {
  11615. hasStroke = true;
  11616. this.values.stroke = this.buildColor(documentData.sc);
  11617. this.values.sWidth = documentData.sw;
  11618. }
  11619. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  11620. var i;
  11621. var len;
  11622. var letters = documentData.l;
  11623. var matrixHelper = this.mHelper;
  11624. this.stroke = hasStroke;
  11625. this.values.fValue = documentData.finalSize + 'px ' + this.globalData.fontManager.getFontByName(documentData.f).fFamily;
  11626. len = documentData.finalText.length;
  11627. // this.tHelper.font = this.values.fValue;
  11628. var charData;
  11629. var shapeData;
  11630. var k;
  11631. var kLen;
  11632. var shapes;
  11633. var j;
  11634. var jLen;
  11635. var pathNodes;
  11636. var commands;
  11637. var pathArr;
  11638. var singleShape = this.data.singleShape;
  11639. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  11640. var xPos = 0;
  11641. var yPos = 0;
  11642. var firstLine = true;
  11643. var cnt = 0;
  11644. for (i = 0; i < len; i += 1) {
  11645. charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  11646. shapeData = (charData && charData.data) || {};
  11647. matrixHelper.reset();
  11648. if (singleShape && letters[i].n) {
  11649. xPos = -trackingOffset;
  11650. yPos += documentData.yOffset;
  11651. yPos += firstLine ? 1 : 0;
  11652. firstLine = false;
  11653. }
  11654. shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
  11655. jLen = shapes.length;
  11656. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  11657. if (singleShape) {
  11658. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  11659. }
  11660. commands = createSizedArray(jLen - 1);
  11661. var commandsCounter = 0;
  11662. for (j = 0; j < jLen; j += 1) {
  11663. if (shapes[j].ty === 'sh') {
  11664. kLen = shapes[j].ks.k.i.length;
  11665. pathNodes = shapes[j].ks.k;
  11666. pathArr = [];
  11667. for (k = 1; k < kLen; k += 1) {
  11668. if (k === 1) {
  11669. pathArr.push(matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
  11670. }
  11671. pathArr.push(matrixHelper.applyToX(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToY(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToX(pathNodes.i[k][0], pathNodes.i[k][1], 0), matrixHelper.applyToY(pathNodes.i[k][0], pathNodes.i[k][1], 0), matrixHelper.applyToX(pathNodes.v[k][0], pathNodes.v[k][1], 0), matrixHelper.applyToY(pathNodes.v[k][0], pathNodes.v[k][1], 0));
  11672. }
  11673. pathArr.push(matrixHelper.applyToX(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToY(pathNodes.o[k - 1][0], pathNodes.o[k - 1][1], 0), matrixHelper.applyToX(pathNodes.i[0][0], pathNodes.i[0][1], 0), matrixHelper.applyToY(pathNodes.i[0][0], pathNodes.i[0][1], 0), matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0));
  11674. commands[commandsCounter] = pathArr;
  11675. commandsCounter += 1;
  11676. }
  11677. }
  11678. if (singleShape) {
  11679. xPos += letters[i].l;
  11680. xPos += trackingOffset;
  11681. }
  11682. if (this.textSpans[cnt]) {
  11683. this.textSpans[cnt].elem = commands;
  11684. } else {
  11685. this.textSpans[cnt] = { elem: commands };
  11686. }
  11687. cnt += 1;
  11688. }
  11689. };
  11690. CVTextElement.prototype.renderInnerContent = function () {
  11691. this.validateText();
  11692. var ctx = this.canvasContext;
  11693. ctx.font = this.values.fValue;
  11694. this.globalData.renderer.ctxLineCap('butt');
  11695. // ctx.lineCap = 'butt';
  11696. this.globalData.renderer.ctxLineJoin('miter');
  11697. // ctx.lineJoin = 'miter';
  11698. this.globalData.renderer.ctxMiterLimit(4);
  11699. // ctx.miterLimit = 4;
  11700. if (!this.data.singleShape) {
  11701. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  11702. }
  11703. var i;
  11704. var len;
  11705. var j;
  11706. var jLen;
  11707. var k;
  11708. var kLen;
  11709. var renderedLetters = this.textAnimator.renderedLetters;
  11710. var letters = this.textProperty.currentData.l;
  11711. len = letters.length;
  11712. var renderedLetter;
  11713. var lastFill = null;
  11714. var lastStroke = null;
  11715. var lastStrokeW = null;
  11716. var commands;
  11717. var pathArr;
  11718. var renderer = this.globalData.renderer;
  11719. for (i = 0; i < len; i += 1) {
  11720. if (!letters[i].n) {
  11721. renderedLetter = renderedLetters[i];
  11722. if (renderedLetter) {
  11723. renderer.save();
  11724. renderer.ctxTransform(renderedLetter.p);
  11725. renderer.ctxOpacity(renderedLetter.o);
  11726. }
  11727. if (this.fill) {
  11728. if (renderedLetter && renderedLetter.fc) {
  11729. if (lastFill !== renderedLetter.fc) {
  11730. renderer.ctxFillStyle(renderedLetter.fc);
  11731. lastFill = renderedLetter.fc;
  11732. // ctx.fillStyle = renderedLetter.fc;
  11733. }
  11734. } else if (lastFill !== this.values.fill) {
  11735. lastFill = this.values.fill;
  11736. renderer.ctxFillStyle(this.values.fill);
  11737. // ctx.fillStyle = this.values.fill;
  11738. }
  11739. commands = this.textSpans[i].elem;
  11740. jLen = commands.length;
  11741. this.globalData.canvasContext.beginPath();
  11742. for (j = 0; j < jLen; j += 1) {
  11743. pathArr = commands[j];
  11744. kLen = pathArr.length;
  11745. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11746. for (k = 2; k < kLen; k += 6) {
  11747. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11748. }
  11749. }
  11750. this.globalData.canvasContext.closePath();
  11751. renderer.ctxFill();
  11752. // this.globalData.canvasContext.fill();
  11753. /// ctx.fillText(this.textSpans[i].val,0,0);
  11754. }
  11755. if (this.stroke) {
  11756. if (renderedLetter && renderedLetter.sw) {
  11757. if (lastStrokeW !== renderedLetter.sw) {
  11758. lastStrokeW = renderedLetter.sw;
  11759. renderer.ctxLineWidth(renderedLetter.sw);
  11760. // ctx.lineWidth = renderedLetter.sw;
  11761. }
  11762. } else if (lastStrokeW !== this.values.sWidth) {
  11763. lastStrokeW = this.values.sWidth;
  11764. renderer.ctxLineWidth(this.values.sWidth);
  11765. // ctx.lineWidth = this.values.sWidth;
  11766. }
  11767. if (renderedLetter && renderedLetter.sc) {
  11768. if (lastStroke !== renderedLetter.sc) {
  11769. lastStroke = renderedLetter.sc;
  11770. renderer.ctxStrokeStyle(renderedLetter.sc);
  11771. // ctx.strokeStyle = renderedLetter.sc;
  11772. }
  11773. } else if (lastStroke !== this.values.stroke) {
  11774. lastStroke = this.values.stroke;
  11775. renderer.ctxStrokeStyle(this.values.stroke);
  11776. // ctx.strokeStyle = this.values.stroke;
  11777. }
  11778. commands = this.textSpans[i].elem;
  11779. jLen = commands.length;
  11780. this.globalData.canvasContext.beginPath();
  11781. for (j = 0; j < jLen; j += 1) {
  11782. pathArr = commands[j];
  11783. kLen = pathArr.length;
  11784. this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]);
  11785. for (k = 2; k < kLen; k += 6) {
  11786. this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]);
  11787. }
  11788. }
  11789. this.globalData.canvasContext.closePath();
  11790. renderer.ctxStroke();
  11791. // this.globalData.canvasContext.stroke();
  11792. /// ctx.strokeText(letters[i].val,0,0);
  11793. }
  11794. if (renderedLetter) {
  11795. this.globalData.renderer.restore();
  11796. }
  11797. }
  11798. }
  11799. };
  11800. function CVImageElement(data, globalData, comp) {
  11801. this.assetData = globalData.getAssetData(data.refId);
  11802. this.img = globalData.imageLoader.getAsset(this.assetData);
  11803. this.initElement(data, globalData, comp);
  11804. }
  11805. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVImageElement);
  11806. CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11807. CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11808. CVImageElement.prototype.createContent = function () {
  11809. if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) {
  11810. var canvas = createTag('canvas');
  11811. canvas.width = this.assetData.w;
  11812. canvas.height = this.assetData.h;
  11813. var ctx = canvas.getContext('2d');
  11814. var imgW = this.img.width;
  11815. var imgH = this.img.height;
  11816. var imgRel = imgW / imgH;
  11817. var canvasRel = this.assetData.w / this.assetData.h;
  11818. var widthCrop;
  11819. var heightCrop;
  11820. var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio;
  11821. if ((imgRel > canvasRel && par === 'xMidYMid slice') || (imgRel < canvasRel && par !== 'xMidYMid slice')) {
  11822. heightCrop = imgH;
  11823. widthCrop = heightCrop * canvasRel;
  11824. } else {
  11825. widthCrop = imgW;
  11826. heightCrop = widthCrop / canvasRel;
  11827. }
  11828. ctx.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h);
  11829. this.img = canvas;
  11830. }
  11831. };
  11832. CVImageElement.prototype.renderInnerContent = function () {
  11833. this.canvasContext.drawImage(this.img, 0, 0);
  11834. };
  11835. CVImageElement.prototype.destroy = function () {
  11836. this.img = null;
  11837. };
  11838. function CVSolidElement(data, globalData, comp) {
  11839. this.initElement(data, globalData, comp);
  11840. }
  11841. extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVSolidElement);
  11842. CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement;
  11843. CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;
  11844. CVSolidElement.prototype.renderInnerContent = function () {
  11845. // var ctx = this.canvasContext;
  11846. this.globalData.renderer.ctxFillStyle(this.data.sc);
  11847. // ctx.fillStyle = this.data.sc;
  11848. this.globalData.renderer.ctxFillRect(0, 0, this.data.sw, this.data.sh);
  11849. // ctx.fillRect(0, 0, this.data.sw, this.data.sh);
  11850. //
  11851. };
  11852. function CanvasRendererBase() {
  11853. }
  11854. extendPrototype([BaseRenderer], CanvasRendererBase);
  11855. CanvasRendererBase.prototype.createShape = function (data) {
  11856. return new CVShapeElement(data, this.globalData, this);
  11857. };
  11858. CanvasRendererBase.prototype.createText = function (data) {
  11859. return new CVTextElement(data, this.globalData, this);
  11860. };
  11861. CanvasRendererBase.prototype.createImage = function (data) {
  11862. return new CVImageElement(data, this.globalData, this);
  11863. };
  11864. CanvasRendererBase.prototype.createSolid = function (data) {
  11865. return new CVSolidElement(data, this.globalData, this);
  11866. };
  11867. CanvasRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  11868. CanvasRendererBase.prototype.ctxTransform = function (props) {
  11869. if (props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0) {
  11870. return;
  11871. }
  11872. this.canvasContext.transform(props[0], props[1], props[4], props[5], props[12], props[13]);
  11873. };
  11874. CanvasRendererBase.prototype.ctxOpacity = function (op) {
  11875. this.canvasContext.globalAlpha *= op < 0 ? 0 : op;
  11876. };
  11877. CanvasRendererBase.prototype.ctxFillStyle = function (value) {
  11878. this.canvasContext.fillStyle = value;
  11879. };
  11880. CanvasRendererBase.prototype.ctxStrokeStyle = function (value) {
  11881. this.canvasContext.strokeStyle = value;
  11882. };
  11883. CanvasRendererBase.prototype.ctxLineWidth = function (value) {
  11884. this.canvasContext.lineWidth = value;
  11885. };
  11886. CanvasRendererBase.prototype.ctxLineCap = function (value) {
  11887. this.canvasContext.lineCap = value;
  11888. };
  11889. CanvasRendererBase.prototype.ctxLineJoin = function (value) {
  11890. this.canvasContext.lineJoin = value;
  11891. };
  11892. CanvasRendererBase.prototype.ctxMiterLimit = function (value) {
  11893. this.canvasContext.miterLimit = value;
  11894. };
  11895. CanvasRendererBase.prototype.ctxFill = function (rule) {
  11896. this.canvasContext.fill(rule);
  11897. };
  11898. CanvasRendererBase.prototype.ctxFillRect = function (x, y, w, h) {
  11899. this.canvasContext.fillRect(x, y, w, h);
  11900. };
  11901. CanvasRendererBase.prototype.ctxStroke = function () {
  11902. this.canvasContext.stroke();
  11903. };
  11904. CanvasRendererBase.prototype.reset = function () {
  11905. if (!this.renderConfig.clearCanvas) {
  11906. this.canvasContext.restore();
  11907. return;
  11908. }
  11909. this.contextData.reset();
  11910. };
  11911. CanvasRendererBase.prototype.save = function () {
  11912. this.canvasContext.save();
  11913. };
  11914. CanvasRendererBase.prototype.restore = function (actionFlag) {
  11915. if (!this.renderConfig.clearCanvas) {
  11916. this.canvasContext.restore();
  11917. return;
  11918. }
  11919. if (actionFlag) {
  11920. this.globalData.blendMode = 'source-over';
  11921. }
  11922. this.contextData.restore(actionFlag);
  11923. };
  11924. CanvasRendererBase.prototype.configAnimation = function (animData) {
  11925. if (this.animationItem.wrapper) {
  11926. this.animationItem.container = createTag('canvas');
  11927. var containerStyle = this.animationItem.container.style;
  11928. containerStyle.width = '100%';
  11929. containerStyle.height = '100%';
  11930. var origin = '0px 0px 0px';
  11931. containerStyle.transformOrigin = origin;
  11932. containerStyle.mozTransformOrigin = origin;
  11933. containerStyle.webkitTransformOrigin = origin;
  11934. containerStyle['-webkit-transform'] = origin;
  11935. containerStyle.contentVisibility = this.renderConfig.contentVisibility;
  11936. this.animationItem.wrapper.appendChild(this.animationItem.container);
  11937. this.canvasContext = this.animationItem.container.getContext('2d');
  11938. if (this.renderConfig.className) {
  11939. this.animationItem.container.setAttribute('class', this.renderConfig.className);
  11940. }
  11941. if (this.renderConfig.id) {
  11942. this.animationItem.container.setAttribute('id', this.renderConfig.id);
  11943. }
  11944. } else {
  11945. this.canvasContext = this.renderConfig.context;
  11946. }
  11947. this.contextData.setContext(this.canvasContext);
  11948. this.data = animData;
  11949. this.layers = animData.layers;
  11950. this.transformCanvas = {
  11951. w: animData.w,
  11952. h: animData.h,
  11953. sx: 0,
  11954. sy: 0,
  11955. tx: 0,
  11956. ty: 0,
  11957. };
  11958. this.setupGlobalData(animData, document.body);
  11959. this.globalData.canvasContext = this.canvasContext;
  11960. this.globalData.renderer = this;
  11961. this.globalData.isDashed = false;
  11962. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  11963. this.globalData.transformCanvas = this.transformCanvas;
  11964. this.elements = createSizedArray(animData.layers.length);
  11965. this.updateContainerSize();
  11966. };
  11967. CanvasRendererBase.prototype.updateContainerSize = function (width, height) {
  11968. this.reset();
  11969. var elementWidth;
  11970. var elementHeight;
  11971. if (width) {
  11972. elementWidth = width;
  11973. elementHeight = height;
  11974. this.canvasContext.canvas.width = elementWidth;
  11975. this.canvasContext.canvas.height = elementHeight;
  11976. } else {
  11977. if (this.animationItem.wrapper && this.animationItem.container) {
  11978. elementWidth = this.animationItem.wrapper.offsetWidth;
  11979. elementHeight = this.animationItem.wrapper.offsetHeight;
  11980. } else {
  11981. elementWidth = this.canvasContext.canvas.width;
  11982. elementHeight = this.canvasContext.canvas.height;
  11983. }
  11984. this.canvasContext.canvas.width = elementWidth * this.renderConfig.dpr;
  11985. this.canvasContext.canvas.height = elementHeight * this.renderConfig.dpr;
  11986. }
  11987. var elementRel;
  11988. var animationRel;
  11989. if (this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1) {
  11990. var par = this.renderConfig.preserveAspectRatio.split(' ');
  11991. var fillType = par[1] || 'meet';
  11992. var pos = par[0] || 'xMidYMid';
  11993. var xPos = pos.substr(0, 4);
  11994. var yPos = pos.substr(4);
  11995. elementRel = elementWidth / elementHeight;
  11996. animationRel = this.transformCanvas.w / this.transformCanvas.h;
  11997. if ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice')) {
  11998. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  11999. this.transformCanvas.sy = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12000. } else {
  12001. this.transformCanvas.sx = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12002. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12003. }
  12004. if (xPos === 'xMid' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
  12005. this.transformCanvas.tx = ((elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) / 2) * this.renderConfig.dpr;
  12006. } else if (xPos === 'xMax' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
  12007. this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) * this.renderConfig.dpr;
  12008. } else {
  12009. this.transformCanvas.tx = 0;
  12010. }
  12011. if (yPos === 'YMid' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
  12012. this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) / 2) * this.renderConfig.dpr;
  12013. } else if (yPos === 'YMax' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
  12014. this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w))) * this.renderConfig.dpr;
  12015. } else {
  12016. this.transformCanvas.ty = 0;
  12017. }
  12018. } else if (this.renderConfig.preserveAspectRatio === 'none') {
  12019. this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr);
  12020. this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr);
  12021. this.transformCanvas.tx = 0;
  12022. this.transformCanvas.ty = 0;
  12023. } else {
  12024. this.transformCanvas.sx = this.renderConfig.dpr;
  12025. this.transformCanvas.sy = this.renderConfig.dpr;
  12026. this.transformCanvas.tx = 0;
  12027. this.transformCanvas.ty = 0;
  12028. }
  12029. this.transformCanvas.props = [this.transformCanvas.sx, 0, 0, 0, 0, this.transformCanvas.sy, 0, 0, 0, 0, 1, 0, this.transformCanvas.tx, this.transformCanvas.ty, 0, 1];
  12030. /* var i, len = this.elements.length;
  12031. for(i=0;i<len;i+=1){
  12032. if(this.elements[i] && this.elements[i].data.ty === 0){
  12033. this.elements[i].resize(this.globalData.transformCanvas);
  12034. }
  12035. } */
  12036. this.ctxTransform(this.transformCanvas.props);
  12037. this.canvasContext.beginPath();
  12038. this.canvasContext.rect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12039. this.canvasContext.closePath();
  12040. this.canvasContext.clip();
  12041. this.renderFrame(this.renderedFrame, true);
  12042. };
  12043. CanvasRendererBase.prototype.destroy = function () {
  12044. if (this.renderConfig.clearCanvas && this.animationItem.wrapper) {
  12045. this.animationItem.wrapper.innerText = '';
  12046. }
  12047. var i;
  12048. var len = this.layers ? this.layers.length : 0;
  12049. for (i = len - 1; i >= 0; i -= 1) {
  12050. if (this.elements[i] && this.elements[i].destroy) {
  12051. this.elements[i].destroy();
  12052. }
  12053. }
  12054. this.elements.length = 0;
  12055. this.globalData.canvasContext = null;
  12056. this.animationItem.container = null;
  12057. this.destroyed = true;
  12058. };
  12059. CanvasRendererBase.prototype.renderFrame = function (num, forceRender) {
  12060. if ((this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender) || this.destroyed || num === -1) {
  12061. return;
  12062. }
  12063. this.renderedFrame = num;
  12064. this.globalData.frameNum = num - this.animationItem._isFirstFrame;
  12065. this.globalData.frameId += 1;
  12066. this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender;
  12067. this.globalData.projectInterface.currentFrame = num;
  12068. // console.log('--------');
  12069. // console.log('NEW: ',num);
  12070. var i;
  12071. var len = this.layers.length;
  12072. if (!this.completeLayers) {
  12073. this.checkLayers(num);
  12074. }
  12075. for (i = len - 1; i >= 0; i -= 1) {
  12076. if (this.completeLayers || this.elements[i]) {
  12077. this.elements[i].prepareFrame(num - this.layers[i].st);
  12078. }
  12079. }
  12080. if (this.globalData._mdf) {
  12081. if (this.renderConfig.clearCanvas === true) {
  12082. this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
  12083. } else {
  12084. this.save();
  12085. }
  12086. for (i = len - 1; i >= 0; i -= 1) {
  12087. if (this.completeLayers || this.elements[i]) {
  12088. this.elements[i].renderFrame();
  12089. }
  12090. }
  12091. if (this.renderConfig.clearCanvas !== true) {
  12092. this.restore();
  12093. }
  12094. }
  12095. };
  12096. CanvasRendererBase.prototype.buildItem = function (pos) {
  12097. var elements = this.elements;
  12098. if (elements[pos] || this.layers[pos].ty === 99) {
  12099. return;
  12100. }
  12101. var element = this.createItem(this.layers[pos], this, this.globalData);
  12102. elements[pos] = element;
  12103. element.initExpressions();
  12104. /* if(this.layers[pos].ty === 0){
  12105. element.resize(this.globalData.transformCanvas);
  12106. } */
  12107. };
  12108. CanvasRendererBase.prototype.checkPendingElements = function () {
  12109. while (this.pendingElements.length) {
  12110. var element = this.pendingElements.pop();
  12111. element.checkParenting();
  12112. }
  12113. };
  12114. CanvasRendererBase.prototype.hide = function () {
  12115. this.animationItem.container.style.display = 'none';
  12116. };
  12117. CanvasRendererBase.prototype.show = function () {
  12118. this.animationItem.container.style.display = 'block';
  12119. };
  12120. function CanvasContext() {
  12121. this.opacity = -1;
  12122. this.transform = createTypedArray('float32', 16);
  12123. this.fillStyle = '';
  12124. this.strokeStyle = '';
  12125. this.lineWidth = '';
  12126. this.lineCap = '';
  12127. this.lineJoin = '';
  12128. this.miterLimit = '';
  12129. this.id = Math.random();
  12130. }
  12131. function CVContextData() {
  12132. this.stack = [];
  12133. this.cArrPos = 0;
  12134. this.cTr = new Matrix();
  12135. var i;
  12136. var len = 15;
  12137. for (i = 0; i < len; i += 1) {
  12138. var canvasContext = new CanvasContext();
  12139. this.stack[i] = canvasContext;
  12140. }
  12141. this._length = len;
  12142. this.nativeContext = null;
  12143. this.transformMat = new Matrix();
  12144. this.currentOpacity = 1;
  12145. //
  12146. this.currentFillStyle = '';
  12147. this.appliedFillStyle = '';
  12148. //
  12149. this.currentStrokeStyle = '';
  12150. this.appliedStrokeStyle = '';
  12151. //
  12152. this.currentLineWidth = '';
  12153. this.appliedLineWidth = '';
  12154. //
  12155. this.currentLineCap = '';
  12156. this.appliedLineCap = '';
  12157. //
  12158. this.currentLineJoin = '';
  12159. this.appliedLineJoin = '';
  12160. //
  12161. this.appliedMiterLimit = '';
  12162. this.currentMiterLimit = '';
  12163. }
  12164. CVContextData.prototype.duplicate = function () {
  12165. var newLength = this._length * 2;
  12166. var i = 0;
  12167. for (i = this._length; i < newLength; i += 1) {
  12168. this.stack[i] = new CanvasContext();
  12169. }
  12170. this._length = newLength;
  12171. };
  12172. CVContextData.prototype.reset = function () {
  12173. this.cArrPos = 0;
  12174. this.cTr.reset();
  12175. this.stack[this.cArrPos].opacity = 1;
  12176. };
  12177. CVContextData.prototype.restore = function (forceRestore) {
  12178. this.cArrPos -= 1;
  12179. var currentContext = this.stack[this.cArrPos];
  12180. var transform = currentContext.transform;
  12181. var i;
  12182. var arr = this.cTr.props;
  12183. for (i = 0; i < 16; i += 1) {
  12184. arr[i] = transform[i];
  12185. }
  12186. if (forceRestore) {
  12187. this.nativeContext.restore();
  12188. var prevStack = this.stack[this.cArrPos + 1];
  12189. this.appliedFillStyle = prevStack.fillStyle;
  12190. this.appliedStrokeStyle = prevStack.strokeStyle;
  12191. this.appliedLineWidth = prevStack.lineWidth;
  12192. this.appliedLineCap = prevStack.lineCap;
  12193. this.appliedLineJoin = prevStack.lineJoin;
  12194. this.appliedMiterLimit = prevStack.miterLimit;
  12195. }
  12196. this.nativeContext.setTransform(transform[0], transform[1], transform[4], transform[5], transform[12], transform[13]);
  12197. if (forceRestore || (currentContext.opacity !== -1 && this.currentOpacity !== currentContext.opacity)) {
  12198. this.nativeContext.globalAlpha = currentContext.opacity;
  12199. this.currentOpacity = currentContext.opacity;
  12200. }
  12201. this.currentFillStyle = currentContext.fillStyle;
  12202. this.currentStrokeStyle = currentContext.strokeStyle;
  12203. this.currentLineWidth = currentContext.lineWidth;
  12204. this.currentLineCap = currentContext.lineCap;
  12205. this.currentLineJoin = currentContext.lineJoin;
  12206. this.currentMiterLimit = currentContext.miterLimit;
  12207. };
  12208. CVContextData.prototype.save = function (saveOnNativeFlag) {
  12209. if (saveOnNativeFlag) {
  12210. this.nativeContext.save();
  12211. }
  12212. var props = this.cTr.props;
  12213. if (this._length <= this.cArrPos) {
  12214. this.duplicate();
  12215. }
  12216. var currentStack = this.stack[this.cArrPos];
  12217. var i;
  12218. for (i = 0; i < 16; i += 1) {
  12219. currentStack.transform[i] = props[i];
  12220. }
  12221. this.cArrPos += 1;
  12222. var newStack = this.stack[this.cArrPos];
  12223. newStack.opacity = currentStack.opacity;
  12224. newStack.fillStyle = currentStack.fillStyle;
  12225. newStack.strokeStyle = currentStack.strokeStyle;
  12226. newStack.lineWidth = currentStack.lineWidth;
  12227. newStack.lineCap = currentStack.lineCap;
  12228. newStack.lineJoin = currentStack.lineJoin;
  12229. newStack.miterLimit = currentStack.miterLimit;
  12230. };
  12231. CVContextData.prototype.setOpacity = function (value) {
  12232. this.stack[this.cArrPos].opacity = value;
  12233. };
  12234. CVContextData.prototype.setContext = function (value) {
  12235. this.nativeContext = value;
  12236. };
  12237. CVContextData.prototype.fillStyle = function (value) {
  12238. if (this.stack[this.cArrPos].fillStyle !== value) {
  12239. this.currentFillStyle = value;
  12240. this.stack[this.cArrPos].fillStyle = value;
  12241. }
  12242. };
  12243. CVContextData.prototype.strokeStyle = function (value) {
  12244. if (this.stack[this.cArrPos].strokeStyle !== value) {
  12245. this.currentStrokeStyle = value;
  12246. this.stack[this.cArrPos].strokeStyle = value;
  12247. }
  12248. };
  12249. CVContextData.prototype.lineWidth = function (value) {
  12250. if (this.stack[this.cArrPos].lineWidth !== value) {
  12251. this.currentLineWidth = value;
  12252. this.stack[this.cArrPos].lineWidth = value;
  12253. }
  12254. };
  12255. CVContextData.prototype.lineCap = function (value) {
  12256. if (this.stack[this.cArrPos].lineCap !== value) {
  12257. this.currentLineCap = value;
  12258. this.stack[this.cArrPos].lineCap = value;
  12259. }
  12260. };
  12261. CVContextData.prototype.lineJoin = function (value) {
  12262. if (this.stack[this.cArrPos].lineJoin !== value) {
  12263. this.currentLineJoin = value;
  12264. this.stack[this.cArrPos].lineJoin = value;
  12265. }
  12266. };
  12267. CVContextData.prototype.miterLimit = function (value) {
  12268. if (this.stack[this.cArrPos].miterLimit !== value) {
  12269. this.currentMiterLimit = value;
  12270. this.stack[this.cArrPos].miterLimit = value;
  12271. }
  12272. };
  12273. CVContextData.prototype.transform = function (props) {
  12274. this.transformMat.cloneFromProps(props);
  12275. // Taking the last transform value from the stored stack of transforms
  12276. var currentTransform = this.cTr;
  12277. // Applying the last transform value after the new transform to respect the order of transformations
  12278. this.transformMat.multiply(currentTransform);
  12279. // Storing the new transformed value in the stored transform
  12280. currentTransform.cloneFromProps(this.transformMat.props);
  12281. var trProps = currentTransform.props;
  12282. // Applying the new transform to the canvas
  12283. this.nativeContext.setTransform(trProps[0], trProps[1], trProps[4], trProps[5], trProps[12], trProps[13]);
  12284. };
  12285. CVContextData.prototype.opacity = function (op) {
  12286. var currentOpacity = this.stack[this.cArrPos].opacity;
  12287. currentOpacity *= op < 0 ? 0 : op;
  12288. if (this.stack[this.cArrPos].opacity !== currentOpacity) {
  12289. if (this.currentOpacity !== op) {
  12290. this.nativeContext.globalAlpha = op;
  12291. this.currentOpacity = op;
  12292. }
  12293. this.stack[this.cArrPos].opacity = currentOpacity;
  12294. }
  12295. };
  12296. CVContextData.prototype.fill = function (rule) {
  12297. if (this.appliedFillStyle !== this.currentFillStyle) {
  12298. this.appliedFillStyle = this.currentFillStyle;
  12299. this.nativeContext.fillStyle = this.appliedFillStyle;
  12300. }
  12301. this.nativeContext.fill(rule);
  12302. };
  12303. CVContextData.prototype.fillRect = function (x, y, w, h) {
  12304. if (this.appliedFillStyle !== this.currentFillStyle) {
  12305. this.appliedFillStyle = this.currentFillStyle;
  12306. this.nativeContext.fillStyle = this.appliedFillStyle;
  12307. }
  12308. this.nativeContext.fillRect(x, y, w, h);
  12309. };
  12310. CVContextData.prototype.stroke = function () {
  12311. if (this.appliedStrokeStyle !== this.currentStrokeStyle) {
  12312. this.appliedStrokeStyle = this.currentStrokeStyle;
  12313. this.nativeContext.strokeStyle = this.appliedStrokeStyle;
  12314. }
  12315. if (this.appliedLineWidth !== this.currentLineWidth) {
  12316. this.appliedLineWidth = this.currentLineWidth;
  12317. this.nativeContext.lineWidth = this.appliedLineWidth;
  12318. }
  12319. if (this.appliedLineCap !== this.currentLineCap) {
  12320. this.appliedLineCap = this.currentLineCap;
  12321. this.nativeContext.lineCap = this.appliedLineCap;
  12322. }
  12323. if (this.appliedLineJoin !== this.currentLineJoin) {
  12324. this.appliedLineJoin = this.currentLineJoin;
  12325. this.nativeContext.lineJoin = this.appliedLineJoin;
  12326. }
  12327. if (this.appliedMiterLimit !== this.currentMiterLimit) {
  12328. this.appliedMiterLimit = this.currentMiterLimit;
  12329. this.nativeContext.miterLimit = this.appliedMiterLimit;
  12330. }
  12331. this.nativeContext.stroke();
  12332. };
  12333. function CVCompElement(data, globalData, comp) {
  12334. this.completeLayers = false;
  12335. this.layers = data.layers;
  12336. this.pendingElements = [];
  12337. this.elements = createSizedArray(this.layers.length);
  12338. this.initElement(data, globalData, comp);
  12339. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  12340. }
  12341. extendPrototype([CanvasRendererBase, ICompElement, CVBaseElement], CVCompElement);
  12342. CVCompElement.prototype.renderInnerContent = function () {
  12343. var ctx = this.canvasContext;
  12344. ctx.beginPath();
  12345. ctx.moveTo(0, 0);
  12346. ctx.lineTo(this.data.w, 0);
  12347. ctx.lineTo(this.data.w, this.data.h);
  12348. ctx.lineTo(0, this.data.h);
  12349. ctx.lineTo(0, 0);
  12350. ctx.clip();
  12351. var i;
  12352. var len = this.layers.length;
  12353. for (i = len - 1; i >= 0; i -= 1) {
  12354. if (this.completeLayers || this.elements[i]) {
  12355. this.elements[i].renderFrame();
  12356. }
  12357. }
  12358. };
  12359. CVCompElement.prototype.destroy = function () {
  12360. var i;
  12361. var len = this.layers.length;
  12362. for (i = len - 1; i >= 0; i -= 1) {
  12363. if (this.elements[i]) {
  12364. this.elements[i].destroy();
  12365. }
  12366. }
  12367. this.layers = null;
  12368. this.elements = null;
  12369. };
  12370. CVCompElement.prototype.createComp = function (data) {
  12371. return new CVCompElement(data, this.globalData, this);
  12372. };
  12373. function CanvasRenderer(animationItem, config) {
  12374. this.animationItem = animationItem;
  12375. this.renderConfig = {
  12376. clearCanvas: (config && config.clearCanvas !== undefined) ? config.clearCanvas : true,
  12377. context: (config && config.context) || null,
  12378. progressiveLoad: (config && config.progressiveLoad) || false,
  12379. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  12380. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  12381. contentVisibility: (config && config.contentVisibility) || 'visible',
  12382. className: (config && config.className) || '',
  12383. id: (config && config.id) || '',
  12384. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  12385. };
  12386. this.renderConfig.dpr = (config && config.dpr) || 1;
  12387. if (this.animationItem.wrapper) {
  12388. this.renderConfig.dpr = (config && config.dpr) || window.devicePixelRatio || 1;
  12389. }
  12390. this.renderedFrame = -1;
  12391. this.globalData = {
  12392. frameNum: -1,
  12393. _mdf: false,
  12394. renderConfig: this.renderConfig,
  12395. currentGlobalAlpha: -1,
  12396. };
  12397. this.contextData = new CVContextData();
  12398. this.elements = [];
  12399. this.pendingElements = [];
  12400. this.transformMat = new Matrix();
  12401. this.completeLayers = false;
  12402. this.rendererType = 'canvas';
  12403. if (this.renderConfig.clearCanvas) {
  12404. this.ctxTransform = this.contextData.transform.bind(this.contextData);
  12405. this.ctxOpacity = this.contextData.opacity.bind(this.contextData);
  12406. this.ctxFillStyle = this.contextData.fillStyle.bind(this.contextData);
  12407. this.ctxStrokeStyle = this.contextData.strokeStyle.bind(this.contextData);
  12408. this.ctxLineWidth = this.contextData.lineWidth.bind(this.contextData);
  12409. this.ctxLineCap = this.contextData.lineCap.bind(this.contextData);
  12410. this.ctxLineJoin = this.contextData.lineJoin.bind(this.contextData);
  12411. this.ctxMiterLimit = this.contextData.miterLimit.bind(this.contextData);
  12412. this.ctxFill = this.contextData.fill.bind(this.contextData);
  12413. this.ctxFillRect = this.contextData.fillRect.bind(this.contextData);
  12414. this.ctxStroke = this.contextData.stroke.bind(this.contextData);
  12415. this.save = this.contextData.save.bind(this.contextData);
  12416. }
  12417. }
  12418. extendPrototype([CanvasRendererBase], CanvasRenderer);
  12419. CanvasRenderer.prototype.createComp = function (data) {
  12420. return new CVCompElement(data, this.globalData, this);
  12421. };
  12422. // Registering renderers
  12423. registerRenderer('canvas', CanvasRenderer);
  12424. // Registering shape modifiers
  12425. ShapeModifiers.registerModifier('tm', TrimModifier);
  12426. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  12427. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  12428. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  12429. ShapeModifiers.registerModifier('zz', ZigZagModifier);
  12430. ShapeModifiers.registerModifier('op', OffsetPathModifier);
  12431. export { lottie as default };