lottie_html.min.js 513 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. const svgNS = 'http://www.w3.org/2000/svg';
  4. let locationHref = '';
  5. let _useWebWorker = false;
  6. const initialDefaultFrame = -999999;
  7. const setWebWorker = (flag) => { _useWebWorker = !!flag; };
  8. const getWebWorker = () => _useWebWorker;
  9. const setLocationHref = (value) => { locationHref = value; };
  10. const getLocationHref = () => locationHref;
  11. function createTag(type) {
  12. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  13. return document.createElement(type);
  14. }
  15. function extendPrototype(sources, destination) {
  16. var i;
  17. var len = sources.length;
  18. var sourcePrototype;
  19. for (i = 0; i < len; i += 1) {
  20. sourcePrototype = sources[i].prototype;
  21. for (var attr in sourcePrototype) {
  22. if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr];
  23. }
  24. }
  25. }
  26. function getDescriptor(object, prop) {
  27. return Object.getOwnPropertyDescriptor(object, prop);
  28. }
  29. function createProxyFunction(prototype) {
  30. function ProxyFunction() {}
  31. ProxyFunction.prototype = prototype;
  32. return ProxyFunction;
  33. }
  34. // import Howl from '../../3rd_party/howler';
  35. const audioControllerFactory = (function () {
  36. function AudioController(audioFactory) {
  37. this.audios = [];
  38. this.audioFactory = audioFactory;
  39. this._volume = 1;
  40. this._isMuted = false;
  41. }
  42. AudioController.prototype = {
  43. addAudio: function (audio) {
  44. this.audios.push(audio);
  45. },
  46. pause: function () {
  47. var i;
  48. var len = this.audios.length;
  49. for (i = 0; i < len; i += 1) {
  50. this.audios[i].pause();
  51. }
  52. },
  53. resume: function () {
  54. var i;
  55. var len = this.audios.length;
  56. for (i = 0; i < len; i += 1) {
  57. this.audios[i].resume();
  58. }
  59. },
  60. setRate: function (rateValue) {
  61. var i;
  62. var len = this.audios.length;
  63. for (i = 0; i < len; i += 1) {
  64. this.audios[i].setRate(rateValue);
  65. }
  66. },
  67. createAudio: function (assetPath) {
  68. if (this.audioFactory) {
  69. return this.audioFactory(assetPath);
  70. } if (window.Howl) {
  71. return new window.Howl({
  72. src: [assetPath],
  73. });
  74. }
  75. return {
  76. isPlaying: false,
  77. play: function () { this.isPlaying = true; },
  78. seek: function () { this.isPlaying = false; },
  79. playing: function () {},
  80. rate: function () {},
  81. setVolume: function () {},
  82. };
  83. },
  84. setAudioFactory: function (audioFactory) {
  85. this.audioFactory = audioFactory;
  86. },
  87. setVolume: function (value) {
  88. this._volume = value;
  89. this._updateVolume();
  90. },
  91. mute: function () {
  92. this._isMuted = true;
  93. this._updateVolume();
  94. },
  95. unmute: function () {
  96. this._isMuted = false;
  97. this._updateVolume();
  98. },
  99. getVolume: function () {
  100. return this._volume;
  101. },
  102. _updateVolume: function () {
  103. var i;
  104. var len = this.audios.length;
  105. for (i = 0; i < len; i += 1) {
  106. this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1));
  107. }
  108. },
  109. };
  110. return function () {
  111. return new AudioController();
  112. };
  113. }());
  114. const createTypedArray = (function () {
  115. function createRegularArray(type, len) {
  116. var i = 0;
  117. var arr = [];
  118. var value;
  119. switch (type) {
  120. case 'int16':
  121. case 'uint8c':
  122. value = 1;
  123. break;
  124. default:
  125. value = 1.1;
  126. break;
  127. }
  128. for (i = 0; i < len; i += 1) {
  129. arr.push(value);
  130. }
  131. return arr;
  132. }
  133. function createTypedArrayFactory(type, len) {
  134. if (type === 'float32') {
  135. return new Float32Array(len);
  136. } if (type === 'int16') {
  137. return new Int16Array(len);
  138. } if (type === 'uint8c') {
  139. return new Uint8ClampedArray(len);
  140. }
  141. return createRegularArray(type, len);
  142. }
  143. if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') {
  144. return createTypedArrayFactory;
  145. }
  146. return createRegularArray;
  147. }());
  148. function createSizedArray(len) {
  149. return Array.apply(null, { length: len });
  150. }
  151. let subframeEnabled = true;
  152. let expressionsPlugin = null;
  153. let expressionsInterfaces = null;
  154. let idPrefix$1 = '';
  155. const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  156. let _shouldRoundValues = false;
  157. const bmPow = Math.pow;
  158. const bmSqrt = Math.sqrt;
  159. const bmFloor = Math.floor;
  160. const bmMax = Math.max;
  161. const bmMin = Math.min;
  162. const BMMath = {};
  163. (function () {
  164. 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'];
  165. var i;
  166. var len = propertyNames.length;
  167. for (i = 0; i < len; i += 1) {
  168. BMMath[propertyNames[i]] = Math[propertyNames[i]];
  169. }
  170. }());
  171. function ProjectInterface$1() { return {}; }
  172. BMMath.random = Math.random;
  173. BMMath.abs = function (val) {
  174. var tOfVal = typeof val;
  175. if (tOfVal === 'object' && val.length) {
  176. var absArr = createSizedArray(val.length);
  177. var i;
  178. var len = val.length;
  179. for (i = 0; i < len; i += 1) {
  180. absArr[i] = Math.abs(val[i]);
  181. }
  182. return absArr;
  183. }
  184. return Math.abs(val);
  185. };
  186. let defaultCurveSegments = 150;
  187. const degToRads = Math.PI / 180;
  188. const roundCorner = 0.5519;
  189. function roundValues(flag) {
  190. _shouldRoundValues = !!flag;
  191. }
  192. function bmRnd(value) {
  193. if (_shouldRoundValues) {
  194. return Math.round(value);
  195. }
  196. return value;
  197. }
  198. function styleDiv(element) {
  199. element.style.position = 'absolute';
  200. element.style.top = 0;
  201. element.style.left = 0;
  202. element.style.display = 'block';
  203. element.style.transformOrigin = '0 0';
  204. element.style.webkitTransformOrigin = '0 0';
  205. element.style.backfaceVisibility = 'visible';
  206. element.style.webkitBackfaceVisibility = 'visible';
  207. element.style.transformStyle = 'preserve-3d';
  208. element.style.webkitTransformStyle = 'preserve-3d';
  209. element.style.mozTransformStyle = 'preserve-3d';
  210. }
  211. function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) {
  212. this.type = type;
  213. this.currentTime = currentTime;
  214. this.totalTime = totalTime;
  215. this.direction = frameMultiplier < 0 ? -1 : 1;
  216. }
  217. function BMCompleteEvent(type, frameMultiplier) {
  218. this.type = type;
  219. this.direction = frameMultiplier < 0 ? -1 : 1;
  220. }
  221. function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) {
  222. this.type = type;
  223. this.currentLoop = currentLoop;
  224. this.totalLoops = totalLoops;
  225. this.direction = frameMultiplier < 0 ? -1 : 1;
  226. }
  227. function BMSegmentStartEvent(type, firstFrame, totalFrames) {
  228. this.type = type;
  229. this.firstFrame = firstFrame;
  230. this.totalFrames = totalFrames;
  231. }
  232. function BMDestroyEvent(type, target) {
  233. this.type = type;
  234. this.target = target;
  235. }
  236. function BMRenderFrameErrorEvent(nativeError, currentTime) {
  237. this.type = 'renderFrameError';
  238. this.nativeError = nativeError;
  239. this.currentTime = currentTime;
  240. }
  241. function BMConfigErrorEvent(nativeError) {
  242. this.type = 'configError';
  243. this.nativeError = nativeError;
  244. }
  245. function BMAnimationConfigErrorEvent(type, nativeError) {
  246. this.type = type;
  247. this.nativeError = nativeError;
  248. }
  249. const createElementID = (function () {
  250. var _count = 0;
  251. return function createID() {
  252. _count += 1;
  253. return idPrefix$1 + '__lottie_element_' + _count;
  254. };
  255. }());
  256. function HSVtoRGB(h, s, v) {
  257. var r;
  258. var g;
  259. var b;
  260. var i;
  261. var f;
  262. var p;
  263. var q;
  264. var t;
  265. i = Math.floor(h * 6);
  266. f = h * 6 - i;
  267. p = v * (1 - s);
  268. q = v * (1 - f * s);
  269. t = v * (1 - (1 - f) * s);
  270. switch (i % 6) {
  271. case 0: r = v; g = t; b = p; break;
  272. case 1: r = q; g = v; b = p; break;
  273. case 2: r = p; g = v; b = t; break;
  274. case 3: r = p; g = q; b = v; break;
  275. case 4: r = t; g = p; b = v; break;
  276. case 5: r = v; g = p; b = q; break;
  277. default: break;
  278. }
  279. return [r,
  280. g,
  281. b];
  282. }
  283. function RGBtoHSV(r, g, b) {
  284. var max = Math.max(r, g, b);
  285. var min = Math.min(r, g, b);
  286. var d = max - min;
  287. var h;
  288. var s = (max === 0 ? 0 : d / max);
  289. var v = max / 255;
  290. switch (max) {
  291. case min: h = 0; break;
  292. case r: h = (g - b) + d * (g < b ? 6 : 0); h /= 6 * d; break;
  293. case g: h = (b - r) + d * 2; h /= 6 * d; break;
  294. case b: h = (r - g) + d * 4; h /= 6 * d; break;
  295. default: break;
  296. }
  297. return [
  298. h,
  299. s,
  300. v,
  301. ];
  302. }
  303. function addSaturationToRGB(color, offset) {
  304. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  305. hsv[1] += offset;
  306. if (hsv[1] > 1) {
  307. hsv[1] = 1;
  308. } else if (hsv[1] <= 0) {
  309. hsv[1] = 0;
  310. }
  311. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  312. }
  313. function addBrightnessToRGB(color, offset) {
  314. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  315. hsv[2] += offset;
  316. if (hsv[2] > 1) {
  317. hsv[2] = 1;
  318. } else if (hsv[2] < 0) {
  319. hsv[2] = 0;
  320. }
  321. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  322. }
  323. function addHueToRGB(color, offset) {
  324. var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255);
  325. hsv[0] += offset / 360;
  326. if (hsv[0] > 1) {
  327. hsv[0] -= 1;
  328. } else if (hsv[0] < 0) {
  329. hsv[0] += 1;
  330. }
  331. return HSVtoRGB(hsv[0], hsv[1], hsv[2]);
  332. }
  333. const rgbToHex = (function () {
  334. var colorMap = [];
  335. var i;
  336. var hex;
  337. for (i = 0; i < 256; i += 1) {
  338. hex = i.toString(16);
  339. colorMap[i] = hex.length === 1 ? '0' + hex : hex;
  340. }
  341. return function (r, g, b) {
  342. if (r < 0) {
  343. r = 0;
  344. }
  345. if (g < 0) {
  346. g = 0;
  347. }
  348. if (b < 0) {
  349. b = 0;
  350. }
  351. return '#' + colorMap[r] + colorMap[g] + colorMap[b];
  352. };
  353. }());
  354. const setSubframeEnabled = (flag) => { subframeEnabled = !!flag; };
  355. const getSubframeEnabled = () => subframeEnabled;
  356. const setExpressionsPlugin = (value) => { expressionsPlugin = value; };
  357. const getExpressionsPlugin = () => expressionsPlugin;
  358. const setExpressionInterfaces = (value) => { expressionsInterfaces = value; };
  359. const getExpressionInterfaces = () => expressionsInterfaces;
  360. const setDefaultCurveSegments = (value) => { defaultCurveSegments = value; };
  361. const getDefaultCurveSegments = () => defaultCurveSegments;
  362. const setIdPrefix = (value) => { idPrefix$1 = value; };
  363. const getIdPrefix = () => idPrefix$1;
  364. function createNS(type) {
  365. // return {appendChild:function(){},setAttribute:function(){},style:{}}
  366. return document.createElementNS(svgNS, type);
  367. }
  368. const dataManager = (function () {
  369. var _counterId = 1;
  370. var processes = [];
  371. var workerFn;
  372. var workerInstance;
  373. var workerProxy = {
  374. onmessage: function () {
  375. },
  376. postMessage: function (path) {
  377. workerFn({
  378. data: path,
  379. });
  380. },
  381. };
  382. var _workerSelf = {
  383. postMessage: function (data) {
  384. workerProxy.onmessage({
  385. data: data,
  386. });
  387. },
  388. };
  389. function createWorker(fn) {
  390. if (window.Worker && window.Blob && getWebWorker()) {
  391. var blob = new Blob(['var _workerSelf = self; self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  392. // var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
  393. var url = URL.createObjectURL(blob);
  394. return new Worker(url);
  395. }
  396. workerFn = fn;
  397. return workerProxy;
  398. }
  399. function setupWorker() {
  400. if (!workerInstance) {
  401. workerInstance = createWorker(function workerStart(e) {
  402. function dataFunctionManager() {
  403. function completeLayers(layers, comps) {
  404. var layerData;
  405. var i;
  406. var len = layers.length;
  407. var j;
  408. var jLen;
  409. var k;
  410. var kLen;
  411. for (i = 0; i < len; i += 1) {
  412. layerData = layers[i];
  413. if (('ks' in layerData) && !layerData.completed) {
  414. layerData.completed = true;
  415. if (layerData.hasMask) {
  416. var maskProps = layerData.masksProperties;
  417. jLen = maskProps.length;
  418. for (j = 0; j < jLen; j += 1) {
  419. if (maskProps[j].pt.k.i) {
  420. convertPathsToAbsoluteValues(maskProps[j].pt.k);
  421. } else {
  422. kLen = maskProps[j].pt.k.length;
  423. for (k = 0; k < kLen; k += 1) {
  424. if (maskProps[j].pt.k[k].s) {
  425. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]);
  426. }
  427. if (maskProps[j].pt.k[k].e) {
  428. convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]);
  429. }
  430. }
  431. }
  432. }
  433. }
  434. if (layerData.ty === 0) {
  435. layerData.layers = findCompLayers(layerData.refId, comps);
  436. completeLayers(layerData.layers, comps);
  437. } else if (layerData.ty === 4) {
  438. completeShapes(layerData.shapes);
  439. } else if (layerData.ty === 5) {
  440. completeText(layerData);
  441. }
  442. }
  443. }
  444. }
  445. function completeChars(chars, assets) {
  446. if (chars) {
  447. var i = 0;
  448. var len = chars.length;
  449. for (i = 0; i < len; i += 1) {
  450. if (chars[i].t === 1) {
  451. // var compData = findComp(chars[i].data.refId, assets);
  452. chars[i].data.layers = findCompLayers(chars[i].data.refId, assets);
  453. // chars[i].data.ip = 0;
  454. // chars[i].data.op = 99999;
  455. // chars[i].data.st = 0;
  456. // chars[i].data.sr = 1;
  457. // chars[i].w = compData.w;
  458. // chars[i].data.ks = {
  459. // a: { k: [0, 0, 0], a: 0 },
  460. // p: { k: [0, -compData.h, 0], a: 0 },
  461. // r: { k: 0, a: 0 },
  462. // s: { k: [100, 100], a: 0 },
  463. // o: { k: 100, a: 0 },
  464. // };
  465. completeLayers(chars[i].data.layers, assets);
  466. }
  467. }
  468. }
  469. }
  470. function findComp(id, comps) {
  471. var i = 0;
  472. var len = comps.length;
  473. while (i < len) {
  474. if (comps[i].id === id) {
  475. return comps[i];
  476. }
  477. i += 1;
  478. }
  479. return null;
  480. }
  481. function findCompLayers(id, comps) {
  482. var comp = findComp(id, comps);
  483. if (comp) {
  484. if (!comp.layers.__used) {
  485. comp.layers.__used = true;
  486. return comp.layers;
  487. }
  488. return JSON.parse(JSON.stringify(comp.layers));
  489. }
  490. return null;
  491. }
  492. function completeShapes(arr) {
  493. var i;
  494. var len = arr.length;
  495. var j;
  496. var jLen;
  497. for (i = len - 1; i >= 0; i -= 1) {
  498. if (arr[i].ty === 'sh') {
  499. if (arr[i].ks.k.i) {
  500. convertPathsToAbsoluteValues(arr[i].ks.k);
  501. } else {
  502. jLen = arr[i].ks.k.length;
  503. for (j = 0; j < jLen; j += 1) {
  504. if (arr[i].ks.k[j].s) {
  505. convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]);
  506. }
  507. if (arr[i].ks.k[j].e) {
  508. convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]);
  509. }
  510. }
  511. }
  512. } else if (arr[i].ty === 'gr') {
  513. completeShapes(arr[i].it);
  514. }
  515. }
  516. }
  517. function convertPathsToAbsoluteValues(path) {
  518. var i;
  519. var len = path.i.length;
  520. for (i = 0; i < len; i += 1) {
  521. path.i[i][0] += path.v[i][0];
  522. path.i[i][1] += path.v[i][1];
  523. path.o[i][0] += path.v[i][0];
  524. path.o[i][1] += path.v[i][1];
  525. }
  526. }
  527. function checkVersion(minimum, animVersionString) {
  528. var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100];
  529. if (minimum[0] > animVersion[0]) {
  530. return true;
  531. } if (animVersion[0] > minimum[0]) {
  532. return false;
  533. }
  534. if (minimum[1] > animVersion[1]) {
  535. return true;
  536. } if (animVersion[1] > minimum[1]) {
  537. return false;
  538. }
  539. if (minimum[2] > animVersion[2]) {
  540. return true;
  541. } if (animVersion[2] > minimum[2]) {
  542. return false;
  543. }
  544. return null;
  545. }
  546. var checkText = (function () {
  547. var minimumVersion = [4, 4, 14];
  548. function updateTextLayer(textLayer) {
  549. var documentData = textLayer.t.d;
  550. textLayer.t.d = {
  551. k: [
  552. {
  553. s: documentData,
  554. t: 0,
  555. },
  556. ],
  557. };
  558. }
  559. function iterateLayers(layers) {
  560. var i;
  561. var len = layers.length;
  562. for (i = 0; i < len; i += 1) {
  563. if (layers[i].ty === 5) {
  564. updateTextLayer(layers[i]);
  565. }
  566. }
  567. }
  568. return function (animationData) {
  569. if (checkVersion(minimumVersion, animationData.v)) {
  570. iterateLayers(animationData.layers);
  571. if (animationData.assets) {
  572. var i;
  573. var len = animationData.assets.length;
  574. for (i = 0; i < len; i += 1) {
  575. if (animationData.assets[i].layers) {
  576. iterateLayers(animationData.assets[i].layers);
  577. }
  578. }
  579. }
  580. }
  581. };
  582. }());
  583. var checkChars = (function () {
  584. var minimumVersion = [4, 7, 99];
  585. return function (animationData) {
  586. if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) {
  587. var i;
  588. var len = animationData.chars.length;
  589. for (i = 0; i < len; i += 1) {
  590. var charData = animationData.chars[i];
  591. if (charData.data && charData.data.shapes) {
  592. completeShapes(charData.data.shapes);
  593. charData.data.ip = 0;
  594. charData.data.op = 99999;
  595. charData.data.st = 0;
  596. charData.data.sr = 1;
  597. charData.data.ks = {
  598. p: { k: [0, 0], a: 0 },
  599. s: { k: [100, 100], a: 0 },
  600. a: { k: [0, 0], a: 0 },
  601. r: { k: 0, a: 0 },
  602. o: { k: 100, a: 0 },
  603. };
  604. if (!animationData.chars[i].t) {
  605. charData.data.shapes.push(
  606. {
  607. ty: 'no',
  608. }
  609. );
  610. charData.data.shapes[0].it.push(
  611. {
  612. p: { k: [0, 0], a: 0 },
  613. s: { k: [100, 100], a: 0 },
  614. a: { k: [0, 0], a: 0 },
  615. r: { k: 0, a: 0 },
  616. o: { k: 100, a: 0 },
  617. sk: { k: 0, a: 0 },
  618. sa: { k: 0, a: 0 },
  619. ty: 'tr',
  620. }
  621. );
  622. }
  623. }
  624. }
  625. }
  626. };
  627. }());
  628. var checkPathProperties = (function () {
  629. var minimumVersion = [5, 7, 15];
  630. function updateTextLayer(textLayer) {
  631. var pathData = textLayer.t.p;
  632. if (typeof pathData.a === 'number') {
  633. pathData.a = {
  634. a: 0,
  635. k: pathData.a,
  636. };
  637. }
  638. if (typeof pathData.p === 'number') {
  639. pathData.p = {
  640. a: 0,
  641. k: pathData.p,
  642. };
  643. }
  644. if (typeof pathData.r === 'number') {
  645. pathData.r = {
  646. a: 0,
  647. k: pathData.r,
  648. };
  649. }
  650. }
  651. function iterateLayers(layers) {
  652. var i;
  653. var len = layers.length;
  654. for (i = 0; i < len; i += 1) {
  655. if (layers[i].ty === 5) {
  656. updateTextLayer(layers[i]);
  657. }
  658. }
  659. }
  660. return function (animationData) {
  661. if (checkVersion(minimumVersion, animationData.v)) {
  662. iterateLayers(animationData.layers);
  663. if (animationData.assets) {
  664. var i;
  665. var len = animationData.assets.length;
  666. for (i = 0; i < len; i += 1) {
  667. if (animationData.assets[i].layers) {
  668. iterateLayers(animationData.assets[i].layers);
  669. }
  670. }
  671. }
  672. }
  673. };
  674. }());
  675. var checkColors = (function () {
  676. var minimumVersion = [4, 1, 9];
  677. function iterateShapes(shapes) {
  678. var i;
  679. var len = shapes.length;
  680. var j;
  681. var jLen;
  682. for (i = 0; i < len; i += 1) {
  683. if (shapes[i].ty === 'gr') {
  684. iterateShapes(shapes[i].it);
  685. } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') {
  686. if (shapes[i].c.k && shapes[i].c.k[0].i) {
  687. jLen = shapes[i].c.k.length;
  688. for (j = 0; j < jLen; j += 1) {
  689. if (shapes[i].c.k[j].s) {
  690. shapes[i].c.k[j].s[0] /= 255;
  691. shapes[i].c.k[j].s[1] /= 255;
  692. shapes[i].c.k[j].s[2] /= 255;
  693. shapes[i].c.k[j].s[3] /= 255;
  694. }
  695. if (shapes[i].c.k[j].e) {
  696. shapes[i].c.k[j].e[0] /= 255;
  697. shapes[i].c.k[j].e[1] /= 255;
  698. shapes[i].c.k[j].e[2] /= 255;
  699. shapes[i].c.k[j].e[3] /= 255;
  700. }
  701. }
  702. } else {
  703. shapes[i].c.k[0] /= 255;
  704. shapes[i].c.k[1] /= 255;
  705. shapes[i].c.k[2] /= 255;
  706. shapes[i].c.k[3] /= 255;
  707. }
  708. }
  709. }
  710. }
  711. function iterateLayers(layers) {
  712. var i;
  713. var len = layers.length;
  714. for (i = 0; i < len; i += 1) {
  715. if (layers[i].ty === 4) {
  716. iterateShapes(layers[i].shapes);
  717. }
  718. }
  719. }
  720. return function (animationData) {
  721. if (checkVersion(minimumVersion, animationData.v)) {
  722. iterateLayers(animationData.layers);
  723. if (animationData.assets) {
  724. var i;
  725. var len = animationData.assets.length;
  726. for (i = 0; i < len; i += 1) {
  727. if (animationData.assets[i].layers) {
  728. iterateLayers(animationData.assets[i].layers);
  729. }
  730. }
  731. }
  732. }
  733. };
  734. }());
  735. var checkShapes = (function () {
  736. var minimumVersion = [4, 4, 18];
  737. function completeClosingShapes(arr) {
  738. var i;
  739. var len = arr.length;
  740. var j;
  741. var jLen;
  742. for (i = len - 1; i >= 0; i -= 1) {
  743. if (arr[i].ty === 'sh') {
  744. if (arr[i].ks.k.i) {
  745. arr[i].ks.k.c = arr[i].closed;
  746. } else {
  747. jLen = arr[i].ks.k.length;
  748. for (j = 0; j < jLen; j += 1) {
  749. if (arr[i].ks.k[j].s) {
  750. arr[i].ks.k[j].s[0].c = arr[i].closed;
  751. }
  752. if (arr[i].ks.k[j].e) {
  753. arr[i].ks.k[j].e[0].c = arr[i].closed;
  754. }
  755. }
  756. }
  757. } else if (arr[i].ty === 'gr') {
  758. completeClosingShapes(arr[i].it);
  759. }
  760. }
  761. }
  762. function iterateLayers(layers) {
  763. var layerData;
  764. var i;
  765. var len = layers.length;
  766. var j;
  767. var jLen;
  768. var k;
  769. var kLen;
  770. for (i = 0; i < len; i += 1) {
  771. layerData = layers[i];
  772. if (layerData.hasMask) {
  773. var maskProps = layerData.masksProperties;
  774. jLen = maskProps.length;
  775. for (j = 0; j < jLen; j += 1) {
  776. if (maskProps[j].pt.k.i) {
  777. maskProps[j].pt.k.c = maskProps[j].cl;
  778. } else {
  779. kLen = maskProps[j].pt.k.length;
  780. for (k = 0; k < kLen; k += 1) {
  781. if (maskProps[j].pt.k[k].s) {
  782. maskProps[j].pt.k[k].s[0].c = maskProps[j].cl;
  783. }
  784. if (maskProps[j].pt.k[k].e) {
  785. maskProps[j].pt.k[k].e[0].c = maskProps[j].cl;
  786. }
  787. }
  788. }
  789. }
  790. }
  791. if (layerData.ty === 4) {
  792. completeClosingShapes(layerData.shapes);
  793. }
  794. }
  795. }
  796. return function (animationData) {
  797. if (checkVersion(minimumVersion, animationData.v)) {
  798. iterateLayers(animationData.layers);
  799. if (animationData.assets) {
  800. var i;
  801. var len = animationData.assets.length;
  802. for (i = 0; i < len; i += 1) {
  803. if (animationData.assets[i].layers) {
  804. iterateLayers(animationData.assets[i].layers);
  805. }
  806. }
  807. }
  808. }
  809. };
  810. }());
  811. function completeData(animationData) {
  812. if (animationData.__complete) {
  813. return;
  814. }
  815. checkColors(animationData);
  816. checkText(animationData);
  817. checkChars(animationData);
  818. checkPathProperties(animationData);
  819. checkShapes(animationData);
  820. completeLayers(animationData.layers, animationData.assets);
  821. completeChars(animationData.chars, animationData.assets);
  822. animationData.__complete = true;
  823. }
  824. function completeText(data) {
  825. if (data.t.a.length === 0 && !('m' in data.t.p)) {
  826. // data.singleShape = true;
  827. }
  828. }
  829. var moduleOb = {};
  830. moduleOb.completeData = completeData;
  831. moduleOb.checkColors = checkColors;
  832. moduleOb.checkChars = checkChars;
  833. moduleOb.checkPathProperties = checkPathProperties;
  834. moduleOb.checkShapes = checkShapes;
  835. moduleOb.completeLayers = completeLayers;
  836. return moduleOb;
  837. }
  838. if (!_workerSelf.dataManager) {
  839. _workerSelf.dataManager = dataFunctionManager();
  840. }
  841. if (!_workerSelf.assetLoader) {
  842. _workerSelf.assetLoader = (function () {
  843. function formatResponse(xhr) {
  844. // using typeof doubles the time of execution of this method,
  845. // so if available, it's better to use the header to validate the type
  846. var contentTypeHeader = xhr.getResponseHeader('content-type');
  847. if (contentTypeHeader && xhr.responseType === 'json' && contentTypeHeader.indexOf('json') !== -1) {
  848. return xhr.response;
  849. }
  850. if (xhr.response && typeof xhr.response === 'object') {
  851. return xhr.response;
  852. } if (xhr.response && typeof xhr.response === 'string') {
  853. return JSON.parse(xhr.response);
  854. } if (xhr.responseText) {
  855. return JSON.parse(xhr.responseText);
  856. }
  857. return null;
  858. }
  859. function loadAsset(path, fullPath, callback, errorCallback) {
  860. var response;
  861. var xhr = new XMLHttpRequest();
  862. // set responseType after calling open or IE will break.
  863. try {
  864. // This crashes on Android WebView prior to KitKat
  865. xhr.responseType = 'json';
  866. } catch (err) {} // eslint-disable-line no-empty
  867. xhr.onreadystatechange = function () {
  868. if (xhr.readyState === 4) {
  869. if (xhr.status === 200) {
  870. response = formatResponse(xhr);
  871. callback(response);
  872. } else {
  873. try {
  874. response = formatResponse(xhr);
  875. callback(response);
  876. } catch (err) {
  877. if (errorCallback) {
  878. errorCallback(err);
  879. }
  880. }
  881. }
  882. }
  883. };
  884. try {
  885. // Hack to workaround banner validation
  886. xhr.open(['G', 'E', 'T'].join(''), path, true);
  887. } catch (error) {
  888. // Hack to workaround banner validation
  889. xhr.open(['G', 'E', 'T'].join(''), fullPath + '/' + path, true);
  890. }
  891. xhr.send();
  892. }
  893. return {
  894. load: loadAsset,
  895. };
  896. }());
  897. }
  898. if (e.data.type === 'loadAnimation') {
  899. _workerSelf.assetLoader.load(
  900. e.data.path,
  901. e.data.fullPath,
  902. function (data) {
  903. _workerSelf.dataManager.completeData(data);
  904. _workerSelf.postMessage({
  905. id: e.data.id,
  906. payload: data,
  907. status: 'success',
  908. });
  909. },
  910. function () {
  911. _workerSelf.postMessage({
  912. id: e.data.id,
  913. status: 'error',
  914. });
  915. }
  916. );
  917. } else if (e.data.type === 'complete') {
  918. var animation = e.data.animation;
  919. _workerSelf.dataManager.completeData(animation);
  920. _workerSelf.postMessage({
  921. id: e.data.id,
  922. payload: animation,
  923. status: 'success',
  924. });
  925. } else if (e.data.type === 'loadData') {
  926. _workerSelf.assetLoader.load(
  927. e.data.path,
  928. e.data.fullPath,
  929. function (data) {
  930. _workerSelf.postMessage({
  931. id: e.data.id,
  932. payload: data,
  933. status: 'success',
  934. });
  935. },
  936. function () {
  937. _workerSelf.postMessage({
  938. id: e.data.id,
  939. status: 'error',
  940. });
  941. }
  942. );
  943. }
  944. });
  945. workerInstance.onmessage = function (event) {
  946. var data = event.data;
  947. var id = data.id;
  948. var process = processes[id];
  949. processes[id] = null;
  950. if (data.status === 'success') {
  951. process.onComplete(data.payload);
  952. } else if (process.onError) {
  953. process.onError();
  954. }
  955. };
  956. }
  957. }
  958. function createProcess(onComplete, onError) {
  959. _counterId += 1;
  960. var id = 'processId_' + _counterId;
  961. processes[id] = {
  962. onComplete: onComplete,
  963. onError: onError,
  964. };
  965. return id;
  966. }
  967. function loadAnimation(path, onComplete, onError) {
  968. setupWorker();
  969. var processId = createProcess(onComplete, onError);
  970. workerInstance.postMessage({
  971. type: 'loadAnimation',
  972. path: path,
  973. fullPath: window.location.origin + window.location.pathname,
  974. id: processId,
  975. });
  976. }
  977. function loadData(path, onComplete, onError) {
  978. setupWorker();
  979. var processId = createProcess(onComplete, onError);
  980. workerInstance.postMessage({
  981. type: 'loadData',
  982. path: path,
  983. fullPath: window.location.origin + window.location.pathname,
  984. id: processId,
  985. });
  986. }
  987. function completeAnimation(anim, onComplete, onError) {
  988. setupWorker();
  989. var processId = createProcess(onComplete, onError);
  990. workerInstance.postMessage({
  991. type: 'complete',
  992. animation: anim,
  993. id: processId,
  994. });
  995. }
  996. return {
  997. loadAnimation: loadAnimation,
  998. loadData: loadData,
  999. completeAnimation: completeAnimation,
  1000. };
  1001. }());
  1002. const ImagePreloader = (function () {
  1003. var proxyImage = (function () {
  1004. var canvas = createTag('canvas');
  1005. canvas.width = 1;
  1006. canvas.height = 1;
  1007. var ctx = canvas.getContext('2d');
  1008. ctx.fillStyle = 'rgba(0,0,0,0)';
  1009. ctx.fillRect(0, 0, 1, 1);
  1010. return canvas;
  1011. }());
  1012. function imageLoaded() {
  1013. this.loadedAssets += 1;
  1014. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1015. if (this.imagesLoadedCb) {
  1016. this.imagesLoadedCb(null);
  1017. }
  1018. }
  1019. }
  1020. function footageLoaded() {
  1021. this.loadedFootagesCount += 1;
  1022. if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) {
  1023. if (this.imagesLoadedCb) {
  1024. this.imagesLoadedCb(null);
  1025. }
  1026. }
  1027. }
  1028. function getAssetsPath(assetData, assetsPath, originalPath) {
  1029. var path = '';
  1030. if (assetData.e) {
  1031. path = assetData.p;
  1032. } else if (assetsPath) {
  1033. var imagePath = assetData.p;
  1034. if (imagePath.indexOf('images/') !== -1) {
  1035. imagePath = imagePath.split('/')[1];
  1036. }
  1037. path = assetsPath + imagePath;
  1038. } else {
  1039. path = originalPath;
  1040. path += assetData.u ? assetData.u : '';
  1041. path += assetData.p;
  1042. }
  1043. return path;
  1044. }
  1045. function testImageLoaded(img) {
  1046. var _count = 0;
  1047. var intervalId = setInterval(function () {
  1048. var box = img.getBBox();
  1049. if (box.width || _count > 500) {
  1050. this._imageLoaded();
  1051. clearInterval(intervalId);
  1052. }
  1053. _count += 1;
  1054. }.bind(this), 50);
  1055. }
  1056. function createImageData(assetData) {
  1057. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1058. var img = createNS('image');
  1059. if (isSafari) {
  1060. this.testImageLoaded(img);
  1061. } else {
  1062. img.addEventListener('load', this._imageLoaded, false);
  1063. }
  1064. img.addEventListener('error', function () {
  1065. ob.img = proxyImage;
  1066. this._imageLoaded();
  1067. }.bind(this), false);
  1068. img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1069. if (this._elementHelper.append) {
  1070. this._elementHelper.append(img);
  1071. } else {
  1072. this._elementHelper.appendChild(img);
  1073. }
  1074. var ob = {
  1075. img: img,
  1076. assetData: assetData,
  1077. };
  1078. return ob;
  1079. }
  1080. function createImgData(assetData) {
  1081. var path = getAssetsPath(assetData, this.assetsPath, this.path);
  1082. var img = createTag('img');
  1083. img.crossOrigin = 'anonymous';
  1084. img.addEventListener('load', this._imageLoaded, false);
  1085. img.addEventListener('error', function () {
  1086. ob.img = proxyImage;
  1087. this._imageLoaded();
  1088. }.bind(this), false);
  1089. img.src = path;
  1090. var ob = {
  1091. img: img,
  1092. assetData: assetData,
  1093. };
  1094. return ob;
  1095. }
  1096. function createFootageData(data) {
  1097. var ob = {
  1098. assetData: data,
  1099. };
  1100. var path = getAssetsPath(data, this.assetsPath, this.path);
  1101. dataManager.loadData(path, function (footageData) {
  1102. ob.img = footageData;
  1103. this._footageLoaded();
  1104. }.bind(this), function () {
  1105. ob.img = {};
  1106. this._footageLoaded();
  1107. }.bind(this));
  1108. return ob;
  1109. }
  1110. function loadAssets(assets, cb) {
  1111. this.imagesLoadedCb = cb;
  1112. var i;
  1113. var len = assets.length;
  1114. for (i = 0; i < len; i += 1) {
  1115. if (!assets[i].layers) {
  1116. if (!assets[i].t || assets[i].t === 'seq') {
  1117. this.totalImages += 1;
  1118. this.images.push(this._createImageData(assets[i]));
  1119. } else if (assets[i].t === 3) {
  1120. this.totalFootages += 1;
  1121. this.images.push(this.createFootageData(assets[i]));
  1122. }
  1123. }
  1124. }
  1125. }
  1126. function setPath(path) {
  1127. this.path = path || '';
  1128. }
  1129. function setAssetsPath(path) {
  1130. this.assetsPath = path || '';
  1131. }
  1132. function getAsset(assetData) {
  1133. var i = 0;
  1134. var len = this.images.length;
  1135. while (i < len) {
  1136. if (this.images[i].assetData === assetData) {
  1137. return this.images[i].img;
  1138. }
  1139. i += 1;
  1140. }
  1141. return null;
  1142. }
  1143. function destroy() {
  1144. this.imagesLoadedCb = null;
  1145. this.images.length = 0;
  1146. }
  1147. function loadedImages() {
  1148. return this.totalImages === this.loadedAssets;
  1149. }
  1150. function loadedFootages() {
  1151. return this.totalFootages === this.loadedFootagesCount;
  1152. }
  1153. function setCacheType(type, elementHelper) {
  1154. if (type === 'svg') {
  1155. this._elementHelper = elementHelper;
  1156. this._createImageData = this.createImageData.bind(this);
  1157. } else {
  1158. this._createImageData = this.createImgData.bind(this);
  1159. }
  1160. }
  1161. function ImagePreloaderFactory() {
  1162. this._imageLoaded = imageLoaded.bind(this);
  1163. this._footageLoaded = footageLoaded.bind(this);
  1164. this.testImageLoaded = testImageLoaded.bind(this);
  1165. this.createFootageData = createFootageData.bind(this);
  1166. this.assetsPath = '';
  1167. this.path = '';
  1168. this.totalImages = 0;
  1169. this.totalFootages = 0;
  1170. this.loadedAssets = 0;
  1171. this.loadedFootagesCount = 0;
  1172. this.imagesLoadedCb = null;
  1173. this.images = [];
  1174. }
  1175. ImagePreloaderFactory.prototype = {
  1176. loadAssets: loadAssets,
  1177. setAssetsPath: setAssetsPath,
  1178. setPath: setPath,
  1179. loadedImages: loadedImages,
  1180. loadedFootages: loadedFootages,
  1181. destroy: destroy,
  1182. getAsset: getAsset,
  1183. createImgData: createImgData,
  1184. createImageData: createImageData,
  1185. imageLoaded: imageLoaded,
  1186. footageLoaded: footageLoaded,
  1187. setCacheType: setCacheType,
  1188. };
  1189. return ImagePreloaderFactory;
  1190. }());
  1191. function BaseEvent() {}
  1192. BaseEvent.prototype = {
  1193. triggerEvent: function (eventName, args) {
  1194. if (this._cbs[eventName]) {
  1195. var callbacks = this._cbs[eventName];
  1196. for (var i = 0; i < callbacks.length; i += 1) {
  1197. callbacks[i](args);
  1198. }
  1199. }
  1200. },
  1201. addEventListener: function (eventName, callback) {
  1202. if (!this._cbs[eventName]) {
  1203. this._cbs[eventName] = [];
  1204. }
  1205. this._cbs[eventName].push(callback);
  1206. return function () {
  1207. this.removeEventListener(eventName, callback);
  1208. }.bind(this);
  1209. },
  1210. removeEventListener: function (eventName, callback) {
  1211. if (!callback) {
  1212. this._cbs[eventName] = null;
  1213. } else if (this._cbs[eventName]) {
  1214. var i = 0;
  1215. var len = this._cbs[eventName].length;
  1216. while (i < len) {
  1217. if (this._cbs[eventName][i] === callback) {
  1218. this._cbs[eventName].splice(i, 1);
  1219. i -= 1;
  1220. len -= 1;
  1221. }
  1222. i += 1;
  1223. }
  1224. if (!this._cbs[eventName].length) {
  1225. this._cbs[eventName] = null;
  1226. }
  1227. }
  1228. },
  1229. };
  1230. const markerParser = (
  1231. function () {
  1232. function parsePayloadLines(payload) {
  1233. var lines = payload.split('\r\n');
  1234. var keys = {};
  1235. var line;
  1236. var keysCount = 0;
  1237. for (var i = 0; i < lines.length; i += 1) {
  1238. line = lines[i].split(':');
  1239. if (line.length === 2) {
  1240. keys[line[0]] = line[1].trim();
  1241. keysCount += 1;
  1242. }
  1243. }
  1244. if (keysCount === 0) {
  1245. throw new Error();
  1246. }
  1247. return keys;
  1248. }
  1249. return function (_markers) {
  1250. var markers = [];
  1251. for (var i = 0; i < _markers.length; i += 1) {
  1252. var _marker = _markers[i];
  1253. var markerData = {
  1254. time: _marker.tm,
  1255. duration: _marker.dr,
  1256. };
  1257. try {
  1258. markerData.payload = JSON.parse(_markers[i].cm);
  1259. } catch (_) {
  1260. try {
  1261. markerData.payload = parsePayloadLines(_markers[i].cm);
  1262. } catch (__) {
  1263. markerData.payload = {
  1264. name: _markers[i].cm,
  1265. };
  1266. }
  1267. }
  1268. markers.push(markerData);
  1269. }
  1270. return markers;
  1271. };
  1272. }());
  1273. const ProjectInterface = (function () {
  1274. function registerComposition(comp) {
  1275. this.compositions.push(comp);
  1276. }
  1277. return function () {
  1278. function _thisProjectFunction(name) {
  1279. var i = 0;
  1280. var len = this.compositions.length;
  1281. while (i < len) {
  1282. if (this.compositions[i].data && this.compositions[i].data.nm === name) {
  1283. if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) {
  1284. this.compositions[i].prepareFrame(this.currentFrame);
  1285. }
  1286. return this.compositions[i].compInterface;
  1287. }
  1288. i += 1;
  1289. }
  1290. return null;
  1291. }
  1292. _thisProjectFunction.compositions = [];
  1293. _thisProjectFunction.currentFrame = 0;
  1294. _thisProjectFunction.registerComposition = registerComposition;
  1295. return _thisProjectFunction;
  1296. };
  1297. }());
  1298. const renderers = {};
  1299. const registerRenderer = (key, value) => {
  1300. renderers[key] = value;
  1301. };
  1302. function getRenderer(key) {
  1303. return renderers[key];
  1304. }
  1305. function getRegisteredRenderer() {
  1306. // Returns canvas by default for compatibility
  1307. if (renderers.canvas) {
  1308. return 'canvas';
  1309. }
  1310. // Returns any renderer that is registered
  1311. for (const key in renderers) {
  1312. if (renderers[key]) {
  1313. return key;
  1314. }
  1315. }
  1316. return '';
  1317. }
  1318. const AnimationItem = function () {
  1319. this._cbs = [];
  1320. this.name = '';
  1321. this.path = '';
  1322. this.isLoaded = false;
  1323. this.currentFrame = 0;
  1324. this.currentRawFrame = 0;
  1325. this.firstFrame = 0;
  1326. this.totalFrames = 0;
  1327. this.frameRate = 0;
  1328. this.frameMult = 0;
  1329. this.playSpeed = 1;
  1330. this.playDirection = 1;
  1331. this.playCount = 0;
  1332. this.animationData = {};
  1333. this.assets = [];
  1334. this.isPaused = true;
  1335. this.autoplay = false;
  1336. this.loop = true;
  1337. this.renderer = null;
  1338. this.animationID = createElementID();
  1339. this.assetsPath = '';
  1340. this.timeCompleted = 0;
  1341. this.segmentPos = 0;
  1342. this.isSubframeEnabled = getSubframeEnabled();
  1343. this.segments = [];
  1344. this._idle = true;
  1345. this._completedLoop = false;
  1346. this.projectInterface = ProjectInterface();
  1347. this.imagePreloader = new ImagePreloader();
  1348. this.audioController = audioControllerFactory();
  1349. this.markers = [];
  1350. this.configAnimation = this.configAnimation.bind(this);
  1351. this.onSetupError = this.onSetupError.bind(this);
  1352. this.onSegmentComplete = this.onSegmentComplete.bind(this);
  1353. this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
  1354. this.expressionsPlugin = getExpressionsPlugin();
  1355. };
  1356. extendPrototype([BaseEvent], AnimationItem);
  1357. AnimationItem.prototype.setParams = function (params) {
  1358. if (params.wrapper || params.container) {
  1359. this.wrapper = params.wrapper || params.container;
  1360. }
  1361. var animType = 'svg';
  1362. if (params.animType) {
  1363. animType = params.animType;
  1364. } else if (params.renderer) {
  1365. animType = params.renderer;
  1366. }
  1367. const RendererClass = getRenderer(animType);
  1368. this.renderer = new RendererClass(this, params.rendererSettings);
  1369. this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs);
  1370. this.renderer.setProjectInterface(this.projectInterface);
  1371. this.animType = animType;
  1372. if (params.loop === ''
  1373. || params.loop === null
  1374. || params.loop === undefined
  1375. || params.loop === true) {
  1376. this.loop = true;
  1377. } else if (params.loop === false) {
  1378. this.loop = false;
  1379. } else {
  1380. this.loop = parseInt(params.loop, 10);
  1381. }
  1382. this.autoplay = 'autoplay' in params ? params.autoplay : true;
  1383. this.name = params.name ? params.name : '';
  1384. this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true;
  1385. this.assetsPath = params.assetsPath;
  1386. this.initialSegment = params.initialSegment;
  1387. if (params.audioFactory) {
  1388. this.audioController.setAudioFactory(params.audioFactory);
  1389. }
  1390. if (params.animationData) {
  1391. this.setupAnimation(params.animationData);
  1392. } else if (params.path) {
  1393. if (params.path.lastIndexOf('\\') !== -1) {
  1394. this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1);
  1395. } else {
  1396. this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1);
  1397. }
  1398. this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1);
  1399. this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json'));
  1400. dataManager.loadAnimation(
  1401. params.path,
  1402. this.configAnimation,
  1403. this.onSetupError
  1404. );
  1405. }
  1406. };
  1407. AnimationItem.prototype.onSetupError = function () {
  1408. this.trigger('data_failed');
  1409. };
  1410. AnimationItem.prototype.setupAnimation = function (data) {
  1411. dataManager.completeAnimation(
  1412. data,
  1413. this.configAnimation
  1414. );
  1415. };
  1416. AnimationItem.prototype.setData = function (wrapper, animationData) {
  1417. if (animationData) {
  1418. if (typeof animationData !== 'object') {
  1419. animationData = JSON.parse(animationData);
  1420. }
  1421. }
  1422. var params = {
  1423. wrapper: wrapper,
  1424. animationData: animationData,
  1425. };
  1426. var wrapperAttributes = wrapper.attributes;
  1427. params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary
  1428. ? wrapperAttributes.getNamedItem('data-animation-path').value
  1429. : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary
  1430. ? wrapperAttributes.getNamedItem('data-bm-path').value
  1431. : wrapperAttributes.getNamedItem('bm-path')
  1432. ? wrapperAttributes.getNamedItem('bm-path').value
  1433. : '';
  1434. params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary
  1435. ? wrapperAttributes.getNamedItem('data-anim-type').value
  1436. : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary
  1437. ? wrapperAttributes.getNamedItem('data-bm-type').value
  1438. : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary
  1439. ? wrapperAttributes.getNamedItem('bm-type').value
  1440. : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary
  1441. ? wrapperAttributes.getNamedItem('data-bm-renderer').value
  1442. : wrapperAttributes.getNamedItem('bm-renderer')
  1443. ? wrapperAttributes.getNamedItem('bm-renderer').value
  1444. : getRegisteredRenderer() || 'canvas';
  1445. var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary
  1446. ? wrapperAttributes.getNamedItem('data-anim-loop').value
  1447. : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary
  1448. ? wrapperAttributes.getNamedItem('data-bm-loop').value
  1449. : wrapperAttributes.getNamedItem('bm-loop')
  1450. ? wrapperAttributes.getNamedItem('bm-loop').value
  1451. : '';
  1452. if (loop === 'false') {
  1453. params.loop = false;
  1454. } else if (loop === 'true') {
  1455. params.loop = true;
  1456. } else if (loop !== '') {
  1457. params.loop = parseInt(loop, 10);
  1458. }
  1459. var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary
  1460. ? wrapperAttributes.getNamedItem('data-anim-autoplay').value
  1461. : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary
  1462. ? wrapperAttributes.getNamedItem('data-bm-autoplay').value
  1463. : wrapperAttributes.getNamedItem('bm-autoplay')
  1464. ? wrapperAttributes.getNamedItem('bm-autoplay').value
  1465. : true;
  1466. params.autoplay = autoplay !== 'false';
  1467. params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary
  1468. ? wrapperAttributes.getNamedItem('data-name').value
  1469. : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary
  1470. ? wrapperAttributes.getNamedItem('data-bm-name').value
  1471. : wrapperAttributes.getNamedItem('bm-name')
  1472. ? wrapperAttributes.getNamedItem('bm-name').value
  1473. : '';
  1474. var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary
  1475. ? wrapperAttributes.getNamedItem('data-anim-prerender').value
  1476. : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary
  1477. ? wrapperAttributes.getNamedItem('data-bm-prerender').value
  1478. : wrapperAttributes.getNamedItem('bm-prerender')
  1479. ? wrapperAttributes.getNamedItem('bm-prerender').value
  1480. : '';
  1481. if (prerender === 'false') {
  1482. params.prerender = false;
  1483. }
  1484. if (!params.path) {
  1485. this.trigger('destroy');
  1486. } else {
  1487. this.setParams(params);
  1488. }
  1489. };
  1490. AnimationItem.prototype.includeLayers = function (data) {
  1491. if (data.op > this.animationData.op) {
  1492. this.animationData.op = data.op;
  1493. this.totalFrames = Math.floor(data.op - this.animationData.ip);
  1494. }
  1495. var layers = this.animationData.layers;
  1496. var i;
  1497. var len = layers.length;
  1498. var newLayers = data.layers;
  1499. var j;
  1500. var jLen = newLayers.length;
  1501. for (j = 0; j < jLen; j += 1) {
  1502. i = 0;
  1503. while (i < len) {
  1504. if (layers[i].id === newLayers[j].id) {
  1505. layers[i] = newLayers[j];
  1506. break;
  1507. }
  1508. i += 1;
  1509. }
  1510. }
  1511. if (data.chars || data.fonts) {
  1512. this.renderer.globalData.fontManager.addChars(data.chars);
  1513. this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs);
  1514. }
  1515. if (data.assets) {
  1516. len = data.assets.length;
  1517. for (i = 0; i < len; i += 1) {
  1518. this.animationData.assets.push(data.assets[i]);
  1519. }
  1520. }
  1521. this.animationData.__complete = false;
  1522. dataManager.completeAnimation(
  1523. this.animationData,
  1524. this.onSegmentComplete
  1525. );
  1526. };
  1527. AnimationItem.prototype.onSegmentComplete = function (data) {
  1528. this.animationData = data;
  1529. var expressionsPlugin = getExpressionsPlugin();
  1530. if (expressionsPlugin) {
  1531. expressionsPlugin.initExpressions(this);
  1532. }
  1533. this.loadNextSegment();
  1534. };
  1535. AnimationItem.prototype.loadNextSegment = function () {
  1536. var segments = this.animationData.segments;
  1537. if (!segments || segments.length === 0 || !this.autoloadSegments) {
  1538. this.trigger('data_ready');
  1539. this.timeCompleted = this.totalFrames;
  1540. return;
  1541. }
  1542. var segment = segments.shift();
  1543. this.timeCompleted = segment.time * this.frameRate;
  1544. var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json';
  1545. this.segmentPos += 1;
  1546. dataManager.loadData(segmentPath, this.includeLayers.bind(this), function () {
  1547. this.trigger('data_failed');
  1548. }.bind(this));
  1549. };
  1550. AnimationItem.prototype.loadSegments = function () {
  1551. var segments = this.animationData.segments;
  1552. if (!segments) {
  1553. this.timeCompleted = this.totalFrames;
  1554. }
  1555. this.loadNextSegment();
  1556. };
  1557. AnimationItem.prototype.imagesLoaded = function () {
  1558. this.trigger('loaded_images');
  1559. this.checkLoaded();
  1560. };
  1561. AnimationItem.prototype.preloadImages = function () {
  1562. this.imagePreloader.setAssetsPath(this.assetsPath);
  1563. this.imagePreloader.setPath(this.path);
  1564. this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this));
  1565. };
  1566. AnimationItem.prototype.configAnimation = function (animData) {
  1567. if (!this.renderer) {
  1568. return;
  1569. }
  1570. try {
  1571. this.animationData = animData;
  1572. if (this.initialSegment) {
  1573. this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]);
  1574. this.firstFrame = Math.round(this.initialSegment[0]);
  1575. } else {
  1576. this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip);
  1577. this.firstFrame = Math.round(this.animationData.ip);
  1578. }
  1579. this.renderer.configAnimation(animData);
  1580. if (!animData.assets) {
  1581. animData.assets = [];
  1582. }
  1583. this.assets = this.animationData.assets;
  1584. this.frameRate = this.animationData.fr;
  1585. this.frameMult = this.animationData.fr / 1000;
  1586. this.renderer.searchExtraCompositions(animData.assets);
  1587. this.markers = markerParser(animData.markers || []);
  1588. this.trigger('config_ready');
  1589. this.preloadImages();
  1590. this.loadSegments();
  1591. this.updaFrameModifier();
  1592. this.waitForFontsLoaded();
  1593. if (this.isPaused) {
  1594. this.audioController.pause();
  1595. }
  1596. } catch (error) {
  1597. this.triggerConfigError(error);
  1598. }
  1599. };
  1600. AnimationItem.prototype.waitForFontsLoaded = function () {
  1601. if (!this.renderer) {
  1602. return;
  1603. }
  1604. if (this.renderer.globalData.fontManager.isLoaded) {
  1605. this.checkLoaded();
  1606. } else {
  1607. setTimeout(this.waitForFontsLoaded.bind(this), 20);
  1608. }
  1609. };
  1610. AnimationItem.prototype.checkLoaded = function () {
  1611. if (!this.isLoaded
  1612. && this.renderer.globalData.fontManager.isLoaded
  1613. && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas')
  1614. && (this.imagePreloader.loadedFootages())
  1615. ) {
  1616. this.isLoaded = true;
  1617. var expressionsPlugin = getExpressionsPlugin();
  1618. if (expressionsPlugin) {
  1619. expressionsPlugin.initExpressions(this);
  1620. }
  1621. this.renderer.initItems();
  1622. setTimeout(function () {
  1623. this.trigger('DOMLoaded');
  1624. }.bind(this), 0);
  1625. this.gotoFrame();
  1626. if (this.autoplay) {
  1627. this.play();
  1628. }
  1629. }
  1630. };
  1631. AnimationItem.prototype.resize = function (width, height) {
  1632. // Adding this validation for backwards compatibility in case an event object was being passed down
  1633. var _width = typeof width === 'number' ? width : undefined;
  1634. var _height = typeof height === 'number' ? height : undefined;
  1635. this.renderer.updateContainerSize(_width, _height);
  1636. };
  1637. AnimationItem.prototype.setSubframe = function (flag) {
  1638. this.isSubframeEnabled = !!flag;
  1639. };
  1640. AnimationItem.prototype.gotoFrame = function () {
  1641. this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise
  1642. if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) {
  1643. this.currentFrame = this.timeCompleted;
  1644. }
  1645. this.trigger('enterFrame');
  1646. this.renderFrame();
  1647. this.trigger('drawnFrame');
  1648. };
  1649. AnimationItem.prototype.renderFrame = function () {
  1650. if (this.isLoaded === false || !this.renderer) {
  1651. return;
  1652. }
  1653. try {
  1654. if (this.expressionsPlugin) {
  1655. this.expressionsPlugin.resetFrame();
  1656. }
  1657. this.renderer.renderFrame(this.currentFrame + this.firstFrame);
  1658. } catch (error) {
  1659. this.triggerRenderFrameError(error);
  1660. }
  1661. };
  1662. AnimationItem.prototype.play = function (name) {
  1663. if (name && this.name !== name) {
  1664. return;
  1665. }
  1666. if (this.isPaused === true) {
  1667. this.isPaused = false;
  1668. this.trigger('_play');
  1669. this.audioController.resume();
  1670. if (this._idle) {
  1671. this._idle = false;
  1672. this.trigger('_active');
  1673. }
  1674. }
  1675. };
  1676. AnimationItem.prototype.pause = function (name) {
  1677. if (name && this.name !== name) {
  1678. return;
  1679. }
  1680. if (this.isPaused === false) {
  1681. this.isPaused = true;
  1682. this.trigger('_pause');
  1683. this._idle = true;
  1684. this.trigger('_idle');
  1685. this.audioController.pause();
  1686. }
  1687. };
  1688. AnimationItem.prototype.togglePause = function (name) {
  1689. if (name && this.name !== name) {
  1690. return;
  1691. }
  1692. if (this.isPaused === true) {
  1693. this.play();
  1694. } else {
  1695. this.pause();
  1696. }
  1697. };
  1698. AnimationItem.prototype.stop = function (name) {
  1699. if (name && this.name !== name) {
  1700. return;
  1701. }
  1702. this.pause();
  1703. this.playCount = 0;
  1704. this._completedLoop = false;
  1705. this.setCurrentRawFrameValue(0);
  1706. };
  1707. AnimationItem.prototype.getMarkerData = function (markerName) {
  1708. var marker;
  1709. for (var i = 0; i < this.markers.length; i += 1) {
  1710. marker = this.markers[i];
  1711. if (marker.payload && marker.payload.name === markerName) {
  1712. return marker;
  1713. }
  1714. }
  1715. return null;
  1716. };
  1717. AnimationItem.prototype.goToAndStop = function (value, isFrame, name) {
  1718. if (name && this.name !== name) {
  1719. return;
  1720. }
  1721. var numValue = Number(value);
  1722. if (isNaN(numValue)) {
  1723. var marker = this.getMarkerData(value);
  1724. if (marker) {
  1725. this.goToAndStop(marker.time, true);
  1726. }
  1727. } else if (isFrame) {
  1728. this.setCurrentRawFrameValue(value);
  1729. } else {
  1730. this.setCurrentRawFrameValue(value * this.frameModifier);
  1731. }
  1732. this.pause();
  1733. };
  1734. AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) {
  1735. if (name && this.name !== name) {
  1736. return;
  1737. }
  1738. var numValue = Number(value);
  1739. if (isNaN(numValue)) {
  1740. var marker = this.getMarkerData(value);
  1741. if (marker) {
  1742. if (!marker.duration) {
  1743. this.goToAndStop(marker.time, true);
  1744. } else {
  1745. this.playSegments([marker.time, marker.time + marker.duration], true);
  1746. }
  1747. }
  1748. } else {
  1749. this.goToAndStop(numValue, isFrame, name);
  1750. }
  1751. this.play();
  1752. };
  1753. AnimationItem.prototype.advanceTime = function (value) {
  1754. if (this.isPaused === true || this.isLoaded === false) {
  1755. return;
  1756. }
  1757. var nextValue = this.currentRawFrame + value * this.frameModifier;
  1758. var _isComplete = false;
  1759. // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations.
  1760. // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop.
  1761. if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) {
  1762. if (!this.loop || this.playCount === this.loop) {
  1763. if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) {
  1764. _isComplete = true;
  1765. nextValue = this.totalFrames - 1;
  1766. }
  1767. } else if (nextValue >= this.totalFrames) {
  1768. this.playCount += 1;
  1769. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1770. this.setCurrentRawFrameValue(nextValue % this.totalFrames);
  1771. this._completedLoop = true;
  1772. this.trigger('loopComplete');
  1773. }
  1774. } else {
  1775. this.setCurrentRawFrameValue(nextValue);
  1776. }
  1777. } else if (nextValue < 0) {
  1778. if (!this.checkSegments(nextValue % this.totalFrames)) {
  1779. if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) { // eslint-disable-line no-plusplus
  1780. this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames));
  1781. if (!this._completedLoop) {
  1782. this._completedLoop = true;
  1783. } else {
  1784. this.trigger('loopComplete');
  1785. }
  1786. } else {
  1787. _isComplete = true;
  1788. nextValue = 0;
  1789. }
  1790. }
  1791. } else {
  1792. this.setCurrentRawFrameValue(nextValue);
  1793. }
  1794. if (_isComplete) {
  1795. this.setCurrentRawFrameValue(nextValue);
  1796. this.pause();
  1797. this.trigger('complete');
  1798. }
  1799. };
  1800. AnimationItem.prototype.adjustSegment = function (arr, offset) {
  1801. this.playCount = 0;
  1802. if (arr[1] < arr[0]) {
  1803. if (this.frameModifier > 0) {
  1804. if (this.playSpeed < 0) {
  1805. this.setSpeed(-this.playSpeed);
  1806. } else {
  1807. this.setDirection(-1);
  1808. }
  1809. }
  1810. this.totalFrames = arr[0] - arr[1];
  1811. this.timeCompleted = this.totalFrames;
  1812. this.firstFrame = arr[1];
  1813. this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset);
  1814. } else if (arr[1] > arr[0]) {
  1815. if (this.frameModifier < 0) {
  1816. if (this.playSpeed < 0) {
  1817. this.setSpeed(-this.playSpeed);
  1818. } else {
  1819. this.setDirection(1);
  1820. }
  1821. }
  1822. this.totalFrames = arr[1] - arr[0];
  1823. this.timeCompleted = this.totalFrames;
  1824. this.firstFrame = arr[0];
  1825. this.setCurrentRawFrameValue(0.001 + offset);
  1826. }
  1827. this.trigger('segmentStart');
  1828. };
  1829. AnimationItem.prototype.setSegment = function (init, end) {
  1830. var pendingFrame = -1;
  1831. if (this.isPaused) {
  1832. if (this.currentRawFrame + this.firstFrame < init) {
  1833. pendingFrame = init;
  1834. } else if (this.currentRawFrame + this.firstFrame > end) {
  1835. pendingFrame = end - init;
  1836. }
  1837. }
  1838. this.firstFrame = init;
  1839. this.totalFrames = end - init;
  1840. this.timeCompleted = this.totalFrames;
  1841. if (pendingFrame !== -1) {
  1842. this.goToAndStop(pendingFrame, true);
  1843. }
  1844. };
  1845. AnimationItem.prototype.playSegments = function (arr, forceFlag) {
  1846. if (forceFlag) {
  1847. this.segments.length = 0;
  1848. }
  1849. if (typeof arr[0] === 'object') {
  1850. var i;
  1851. var len = arr.length;
  1852. for (i = 0; i < len; i += 1) {
  1853. this.segments.push(arr[i]);
  1854. }
  1855. } else {
  1856. this.segments.push(arr);
  1857. }
  1858. if (this.segments.length && forceFlag) {
  1859. this.adjustSegment(this.segments.shift(), 0);
  1860. }
  1861. if (this.isPaused) {
  1862. this.play();
  1863. }
  1864. };
  1865. AnimationItem.prototype.resetSegments = function (forceFlag) {
  1866. this.segments.length = 0;
  1867. this.segments.push([this.animationData.ip, this.animationData.op]);
  1868. if (forceFlag) {
  1869. this.checkSegments(0);
  1870. }
  1871. };
  1872. AnimationItem.prototype.checkSegments = function (offset) {
  1873. if (this.segments.length) {
  1874. this.adjustSegment(this.segments.shift(), offset);
  1875. return true;
  1876. }
  1877. return false;
  1878. };
  1879. AnimationItem.prototype.destroy = function (name) {
  1880. if ((name && this.name !== name) || !this.renderer) {
  1881. return;
  1882. }
  1883. this.renderer.destroy();
  1884. this.imagePreloader.destroy();
  1885. this.trigger('destroy');
  1886. this._cbs = null;
  1887. this.onEnterFrame = null;
  1888. this.onLoopComplete = null;
  1889. this.onComplete = null;
  1890. this.onSegmentStart = null;
  1891. this.onDestroy = null;
  1892. this.renderer = null;
  1893. this.expressionsPlugin = null;
  1894. this.imagePreloader = null;
  1895. this.projectInterface = null;
  1896. };
  1897. AnimationItem.prototype.setCurrentRawFrameValue = function (value) {
  1898. this.currentRawFrame = value;
  1899. this.gotoFrame();
  1900. };
  1901. AnimationItem.prototype.setSpeed = function (val) {
  1902. this.playSpeed = val;
  1903. this.updaFrameModifier();
  1904. };
  1905. AnimationItem.prototype.setDirection = function (val) {
  1906. this.playDirection = val < 0 ? -1 : 1;
  1907. this.updaFrameModifier();
  1908. };
  1909. AnimationItem.prototype.setLoop = function (isLooping) {
  1910. this.loop = isLooping;
  1911. };
  1912. AnimationItem.prototype.setVolume = function (val, name) {
  1913. if (name && this.name !== name) {
  1914. return;
  1915. }
  1916. this.audioController.setVolume(val);
  1917. };
  1918. AnimationItem.prototype.getVolume = function () {
  1919. return this.audioController.getVolume();
  1920. };
  1921. AnimationItem.prototype.mute = function (name) {
  1922. if (name && this.name !== name) {
  1923. return;
  1924. }
  1925. this.audioController.mute();
  1926. };
  1927. AnimationItem.prototype.unmute = function (name) {
  1928. if (name && this.name !== name) {
  1929. return;
  1930. }
  1931. this.audioController.unmute();
  1932. };
  1933. AnimationItem.prototype.updaFrameModifier = function () {
  1934. this.frameModifier = this.frameMult * this.playSpeed * this.playDirection;
  1935. this.audioController.setRate(this.playSpeed * this.playDirection);
  1936. };
  1937. AnimationItem.prototype.getPath = function () {
  1938. return this.path;
  1939. };
  1940. AnimationItem.prototype.getAssetsPath = function (assetData) {
  1941. var path = '';
  1942. if (assetData.e) {
  1943. path = assetData.p;
  1944. } else if (this.assetsPath) {
  1945. var imagePath = assetData.p;
  1946. if (imagePath.indexOf('images/') !== -1) {
  1947. imagePath = imagePath.split('/')[1];
  1948. }
  1949. path = this.assetsPath + imagePath;
  1950. } else {
  1951. path = this.path;
  1952. path += assetData.u ? assetData.u : '';
  1953. path += assetData.p;
  1954. }
  1955. return path;
  1956. };
  1957. AnimationItem.prototype.getAssetData = function (id) {
  1958. var i = 0;
  1959. var len = this.assets.length;
  1960. while (i < len) {
  1961. if (id === this.assets[i].id) {
  1962. return this.assets[i];
  1963. }
  1964. i += 1;
  1965. }
  1966. return null;
  1967. };
  1968. AnimationItem.prototype.hide = function () {
  1969. this.renderer.hide();
  1970. };
  1971. AnimationItem.prototype.show = function () {
  1972. this.renderer.show();
  1973. };
  1974. AnimationItem.prototype.getDuration = function (isFrame) {
  1975. return isFrame ? this.totalFrames : this.totalFrames / this.frameRate;
  1976. };
  1977. AnimationItem.prototype.updateDocumentData = function (path, documentData, index) {
  1978. try {
  1979. var element = this.renderer.getElementByPath(path);
  1980. element.updateDocumentData(documentData, index);
  1981. } catch (error) {
  1982. // TODO: decide how to handle catch case
  1983. }
  1984. };
  1985. AnimationItem.prototype.trigger = function (name) {
  1986. if (this._cbs && this._cbs[name]) {
  1987. switch (name) {
  1988. case 'enterFrame':
  1989. this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
  1990. break;
  1991. case 'drawnFrame':
  1992. this.drawnFrameEvent.currentTime = this.currentFrame;
  1993. this.drawnFrameEvent.totalTime = this.totalFrames;
  1994. this.drawnFrameEvent.direction = this.frameModifier;
  1995. this.triggerEvent(name, this.drawnFrameEvent);
  1996. break;
  1997. case 'loopComplete':
  1998. this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  1999. break;
  2000. case 'complete':
  2001. this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult));
  2002. break;
  2003. case 'segmentStart':
  2004. this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2005. break;
  2006. case 'destroy':
  2007. this.triggerEvent(name, new BMDestroyEvent(name, this));
  2008. break;
  2009. default:
  2010. this.triggerEvent(name);
  2011. }
  2012. }
  2013. if (name === 'enterFrame' && this.onEnterFrame) {
  2014. this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult));
  2015. }
  2016. if (name === 'loopComplete' && this.onLoopComplete) {
  2017. this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
  2018. }
  2019. if (name === 'complete' && this.onComplete) {
  2020. this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult));
  2021. }
  2022. if (name === 'segmentStart' && this.onSegmentStart) {
  2023. this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames));
  2024. }
  2025. if (name === 'destroy' && this.onDestroy) {
  2026. this.onDestroy.call(this, new BMDestroyEvent(name, this));
  2027. }
  2028. };
  2029. AnimationItem.prototype.triggerRenderFrameError = function (nativeError) {
  2030. var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame);
  2031. this.triggerEvent('error', error);
  2032. if (this.onError) {
  2033. this.onError.call(this, error);
  2034. }
  2035. };
  2036. AnimationItem.prototype.triggerConfigError = function (nativeError) {
  2037. var error = new BMConfigErrorEvent(nativeError, this.currentFrame);
  2038. this.triggerEvent('error', error);
  2039. if (this.onError) {
  2040. this.onError.call(this, error);
  2041. }
  2042. };
  2043. const animationManager = (function () {
  2044. var moduleOb = {};
  2045. var registeredAnimations = [];
  2046. var initTime = 0;
  2047. var len = 0;
  2048. var playingAnimationsNum = 0;
  2049. var _stopped = true;
  2050. var _isFrozen = false;
  2051. function removeElement(ev) {
  2052. var i = 0;
  2053. var animItem = ev.target;
  2054. while (i < len) {
  2055. if (registeredAnimations[i].animation === animItem) {
  2056. registeredAnimations.splice(i, 1);
  2057. i -= 1;
  2058. len -= 1;
  2059. if (!animItem.isPaused) {
  2060. subtractPlayingCount();
  2061. }
  2062. }
  2063. i += 1;
  2064. }
  2065. }
  2066. function registerAnimation(element, animationData) {
  2067. if (!element) {
  2068. return null;
  2069. }
  2070. var i = 0;
  2071. while (i < len) {
  2072. if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) {
  2073. return registeredAnimations[i].animation;
  2074. }
  2075. i += 1;
  2076. }
  2077. var animItem = new AnimationItem();
  2078. setupAnimation(animItem, element);
  2079. animItem.setData(element, animationData);
  2080. return animItem;
  2081. }
  2082. function getRegisteredAnimations() {
  2083. var i;
  2084. var lenAnims = registeredAnimations.length;
  2085. var animations = [];
  2086. for (i = 0; i < lenAnims; i += 1) {
  2087. animations.push(registeredAnimations[i].animation);
  2088. }
  2089. return animations;
  2090. }
  2091. function addPlayingCount() {
  2092. playingAnimationsNum += 1;
  2093. activate();
  2094. }
  2095. function subtractPlayingCount() {
  2096. playingAnimationsNum -= 1;
  2097. }
  2098. function setupAnimation(animItem, element) {
  2099. animItem.addEventListener('destroy', removeElement);
  2100. animItem.addEventListener('_active', addPlayingCount);
  2101. animItem.addEventListener('_idle', subtractPlayingCount);
  2102. registeredAnimations.push({ elem: element, animation: animItem });
  2103. len += 1;
  2104. }
  2105. function loadAnimation(params) {
  2106. var animItem = new AnimationItem();
  2107. setupAnimation(animItem, null);
  2108. animItem.setParams(params);
  2109. return animItem;
  2110. }
  2111. function setSpeed(val, animation) {
  2112. var i;
  2113. for (i = 0; i < len; i += 1) {
  2114. registeredAnimations[i].animation.setSpeed(val, animation);
  2115. }
  2116. }
  2117. function setDirection(val, animation) {
  2118. var i;
  2119. for (i = 0; i < len; i += 1) {
  2120. registeredAnimations[i].animation.setDirection(val, animation);
  2121. }
  2122. }
  2123. function play(animation) {
  2124. var i;
  2125. for (i = 0; i < len; i += 1) {
  2126. registeredAnimations[i].animation.play(animation);
  2127. }
  2128. }
  2129. function resume(nowTime) {
  2130. var elapsedTime = nowTime - initTime;
  2131. var i;
  2132. for (i = 0; i < len; i += 1) {
  2133. registeredAnimations[i].animation.advanceTime(elapsedTime);
  2134. }
  2135. initTime = nowTime;
  2136. if (playingAnimationsNum && !_isFrozen) {
  2137. window.requestAnimationFrame(resume);
  2138. } else {
  2139. _stopped = true;
  2140. }
  2141. }
  2142. function first(nowTime) {
  2143. initTime = nowTime;
  2144. window.requestAnimationFrame(resume);
  2145. }
  2146. function pause(animation) {
  2147. var i;
  2148. for (i = 0; i < len; i += 1) {
  2149. registeredAnimations[i].animation.pause(animation);
  2150. }
  2151. }
  2152. function goToAndStop(value, isFrame, animation) {
  2153. var i;
  2154. for (i = 0; i < len; i += 1) {
  2155. registeredAnimations[i].animation.goToAndStop(value, isFrame, animation);
  2156. }
  2157. }
  2158. function stop(animation) {
  2159. var i;
  2160. for (i = 0; i < len; i += 1) {
  2161. registeredAnimations[i].animation.stop(animation);
  2162. }
  2163. }
  2164. function togglePause(animation) {
  2165. var i;
  2166. for (i = 0; i < len; i += 1) {
  2167. registeredAnimations[i].animation.togglePause(animation);
  2168. }
  2169. }
  2170. function destroy(animation) {
  2171. var i;
  2172. for (i = (len - 1); i >= 0; i -= 1) {
  2173. registeredAnimations[i].animation.destroy(animation);
  2174. }
  2175. }
  2176. function searchAnimations(animationData, standalone, renderer) {
  2177. var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')),
  2178. [].slice.call(document.getElementsByClassName('bodymovin')));
  2179. var i;
  2180. var lenAnims = animElements.length;
  2181. for (i = 0; i < lenAnims; i += 1) {
  2182. if (renderer) {
  2183. animElements[i].setAttribute('data-bm-type', renderer);
  2184. }
  2185. registerAnimation(animElements[i], animationData);
  2186. }
  2187. if (standalone && lenAnims === 0) {
  2188. if (!renderer) {
  2189. renderer = 'svg';
  2190. }
  2191. var body = document.getElementsByTagName('body')[0];
  2192. body.innerText = '';
  2193. var div = createTag('div');
  2194. div.style.width = '100%';
  2195. div.style.height = '100%';
  2196. div.setAttribute('data-bm-type', renderer);
  2197. body.appendChild(div);
  2198. registerAnimation(div, animationData);
  2199. }
  2200. }
  2201. function resize() {
  2202. var i;
  2203. for (i = 0; i < len; i += 1) {
  2204. registeredAnimations[i].animation.resize();
  2205. }
  2206. }
  2207. function activate() {
  2208. if (!_isFrozen && playingAnimationsNum) {
  2209. if (_stopped) {
  2210. window.requestAnimationFrame(first);
  2211. _stopped = false;
  2212. }
  2213. }
  2214. }
  2215. function freeze() {
  2216. _isFrozen = true;
  2217. }
  2218. function unfreeze() {
  2219. _isFrozen = false;
  2220. activate();
  2221. }
  2222. function setVolume(val, animation) {
  2223. var i;
  2224. for (i = 0; i < len; i += 1) {
  2225. registeredAnimations[i].animation.setVolume(val, animation);
  2226. }
  2227. }
  2228. function mute(animation) {
  2229. var i;
  2230. for (i = 0; i < len; i += 1) {
  2231. registeredAnimations[i].animation.mute(animation);
  2232. }
  2233. }
  2234. function unmute(animation) {
  2235. var i;
  2236. for (i = 0; i < len; i += 1) {
  2237. registeredAnimations[i].animation.unmute(animation);
  2238. }
  2239. }
  2240. moduleOb.registerAnimation = registerAnimation;
  2241. moduleOb.loadAnimation = loadAnimation;
  2242. moduleOb.setSpeed = setSpeed;
  2243. moduleOb.setDirection = setDirection;
  2244. moduleOb.play = play;
  2245. moduleOb.pause = pause;
  2246. moduleOb.stop = stop;
  2247. moduleOb.togglePause = togglePause;
  2248. moduleOb.searchAnimations = searchAnimations;
  2249. moduleOb.resize = resize;
  2250. // moduleOb.start = start;
  2251. moduleOb.goToAndStop = goToAndStop;
  2252. moduleOb.destroy = destroy;
  2253. moduleOb.freeze = freeze;
  2254. moduleOb.unfreeze = unfreeze;
  2255. moduleOb.setVolume = setVolume;
  2256. moduleOb.mute = mute;
  2257. moduleOb.unmute = unmute;
  2258. moduleOb.getRegisteredAnimations = getRegisteredAnimations;
  2259. return moduleOb;
  2260. }());
  2261. /* eslint-disable */
  2262. const BezierFactory = (function () {
  2263. /**
  2264. * BezierEasing - use bezier curve for transition easing function
  2265. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  2266. *
  2267. * Credits: is based on Firefox's nsSMILKeySpline.cpp
  2268. * Usage:
  2269. * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ])
  2270. * spline.get(x) => returns the easing value | x must be in [0, 1] range
  2271. *
  2272. */
  2273. var ob = {};
  2274. ob.getBezierEasing = getBezierEasing;
  2275. var beziers = {};
  2276. function getBezierEasing(a, b, c, d, nm) {
  2277. var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p');
  2278. if (beziers[str]) {
  2279. return beziers[str];
  2280. }
  2281. var bezEasing = new BezierEasing([a, b, c, d]);
  2282. beziers[str] = bezEasing;
  2283. return bezEasing;
  2284. }
  2285. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  2286. var NEWTON_ITERATIONS = 4;
  2287. var NEWTON_MIN_SLOPE = 0.001;
  2288. var SUBDIVISION_PRECISION = 0.0000001;
  2289. var SUBDIVISION_MAX_ITERATIONS = 10;
  2290. var kSplineTableSize = 11;
  2291. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  2292. var float32ArraySupported = typeof Float32Array === 'function';
  2293. function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
  2294. function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
  2295. function C(aA1) { return 3.0 * aA1; }
  2296. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  2297. function calcBezier(aT, aA1, aA2) {
  2298. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  2299. }
  2300. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  2301. function getSlope(aT, aA1, aA2) {
  2302. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  2303. }
  2304. function binarySubdivide(aX, aA, aB, mX1, mX2) {
  2305. var currentX,
  2306. currentT,
  2307. i = 0;
  2308. do {
  2309. currentT = aA + (aB - aA) / 2.0;
  2310. currentX = calcBezier(currentT, mX1, mX2) - aX;
  2311. if (currentX > 0.0) {
  2312. aB = currentT;
  2313. } else {
  2314. aA = currentT;
  2315. }
  2316. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  2317. return currentT;
  2318. }
  2319. function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  2320. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  2321. var currentSlope = getSlope(aGuessT, mX1, mX2);
  2322. if (currentSlope === 0.0) return aGuessT;
  2323. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  2324. aGuessT -= currentX / currentSlope;
  2325. }
  2326. return aGuessT;
  2327. }
  2328. /**
  2329. * points is an array of [ mX1, mY1, mX2, mY2 ]
  2330. */
  2331. function BezierEasing(points) {
  2332. this._p = points;
  2333. this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  2334. this._precomputed = false;
  2335. this.get = this.get.bind(this);
  2336. }
  2337. BezierEasing.prototype = {
  2338. get: function (x) {
  2339. var mX1 = this._p[0],
  2340. mY1 = this._p[1],
  2341. mX2 = this._p[2],
  2342. mY2 = this._p[3];
  2343. if (!this._precomputed) this._precompute();
  2344. if (mX1 === mY1 && mX2 === mY2) return x; // linear
  2345. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  2346. if (x === 0) return 0;
  2347. if (x === 1) return 1;
  2348. return calcBezier(this._getTForX(x), mY1, mY2);
  2349. },
  2350. // Private part
  2351. _precompute: function () {
  2352. var mX1 = this._p[0],
  2353. mY1 = this._p[1],
  2354. mX2 = this._p[2],
  2355. mY2 = this._p[3];
  2356. this._precomputed = true;
  2357. if (mX1 !== mY1 || mX2 !== mY2) { this._calcSampleValues(); }
  2358. },
  2359. _calcSampleValues: function () {
  2360. var mX1 = this._p[0],
  2361. mX2 = this._p[2];
  2362. for (var i = 0; i < kSplineTableSize; ++i) {
  2363. this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  2364. }
  2365. },
  2366. /**
  2367. * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection.
  2368. */
  2369. _getTForX: function (aX) {
  2370. var mX1 = this._p[0],
  2371. mX2 = this._p[2],
  2372. mSampleValues = this._mSampleValues;
  2373. var intervalStart = 0.0;
  2374. var currentSample = 1;
  2375. var lastSample = kSplineTableSize - 1;
  2376. for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
  2377. intervalStart += kSampleStepSize;
  2378. }
  2379. --currentSample;
  2380. // Interpolate to provide an initial guess for t
  2381. var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
  2382. var guessForT = intervalStart + dist * kSampleStepSize;
  2383. var initialSlope = getSlope(guessForT, mX1, mX2);
  2384. if (initialSlope >= NEWTON_MIN_SLOPE) {
  2385. return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
  2386. } if (initialSlope === 0.0) {
  2387. return guessForT;
  2388. }
  2389. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  2390. },
  2391. };
  2392. return ob;
  2393. }());
  2394. const pooling = (function () {
  2395. function double(arr) {
  2396. return arr.concat(createSizedArray(arr.length));
  2397. }
  2398. return {
  2399. double: double,
  2400. };
  2401. }());
  2402. const poolFactory = (function () {
  2403. return function (initialLength, _create, _release) {
  2404. var _length = 0;
  2405. var _maxLength = initialLength;
  2406. var pool = createSizedArray(_maxLength);
  2407. var ob = {
  2408. newElement: newElement,
  2409. release: release,
  2410. };
  2411. function newElement() {
  2412. var element;
  2413. if (_length) {
  2414. _length -= 1;
  2415. element = pool[_length];
  2416. } else {
  2417. element = _create();
  2418. }
  2419. return element;
  2420. }
  2421. function release(element) {
  2422. if (_length === _maxLength) {
  2423. pool = pooling.double(pool);
  2424. _maxLength *= 2;
  2425. }
  2426. if (_release) {
  2427. _release(element);
  2428. }
  2429. pool[_length] = element;
  2430. _length += 1;
  2431. }
  2432. return ob;
  2433. };
  2434. }());
  2435. const bezierLengthPool = (function () {
  2436. function create() {
  2437. return {
  2438. addedLength: 0,
  2439. percents: createTypedArray('float32', getDefaultCurveSegments()),
  2440. lengths: createTypedArray('float32', getDefaultCurveSegments()),
  2441. };
  2442. }
  2443. return poolFactory(8, create);
  2444. }());
  2445. const segmentsLengthPool = (function () {
  2446. function create() {
  2447. return {
  2448. lengths: [],
  2449. totalLength: 0,
  2450. };
  2451. }
  2452. function release(element) {
  2453. var i;
  2454. var len = element.lengths.length;
  2455. for (i = 0; i < len; i += 1) {
  2456. bezierLengthPool.release(element.lengths[i]);
  2457. }
  2458. element.lengths.length = 0;
  2459. }
  2460. return poolFactory(8, create, release);
  2461. }());
  2462. function bezFunction() {
  2463. var math = Math;
  2464. function pointOnLine2D(x1, y1, x2, y2, x3, y3) {
  2465. var det1 = (x1 * y2) + (y1 * x3) + (x2 * y3) - (x3 * y2) - (y3 * x1) - (x2 * y1);
  2466. return det1 > -0.001 && det1 < 0.001;
  2467. }
  2468. function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) {
  2469. if (z1 === 0 && z2 === 0 && z3 === 0) {
  2470. return pointOnLine2D(x1, y1, x2, y2, x3, y3);
  2471. }
  2472. var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2));
  2473. var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2));
  2474. var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2));
  2475. var diffDist;
  2476. if (dist1 > dist2) {
  2477. if (dist1 > dist3) {
  2478. diffDist = dist1 - dist2 - dist3;
  2479. } else {
  2480. diffDist = dist3 - dist2 - dist1;
  2481. }
  2482. } else if (dist3 > dist2) {
  2483. diffDist = dist3 - dist2 - dist1;
  2484. } else {
  2485. diffDist = dist2 - dist1 - dist3;
  2486. }
  2487. return diffDist > -0.0001 && diffDist < 0.0001;
  2488. }
  2489. var getBezierLength = (function () {
  2490. return function (pt1, pt2, pt3, pt4) {
  2491. var curveSegments = getDefaultCurveSegments();
  2492. var k;
  2493. var i;
  2494. var len;
  2495. var ptCoord;
  2496. var perc;
  2497. var addedLength = 0;
  2498. var ptDistance;
  2499. var point = [];
  2500. var lastPoint = [];
  2501. var lengthData = bezierLengthPool.newElement();
  2502. len = pt3.length;
  2503. for (k = 0; k < curveSegments; k += 1) {
  2504. perc = k / (curveSegments - 1);
  2505. ptDistance = 0;
  2506. for (i = 0; i < len; i += 1) {
  2507. 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];
  2508. point[i] = ptCoord;
  2509. if (lastPoint[i] !== null) {
  2510. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2511. }
  2512. lastPoint[i] = point[i];
  2513. }
  2514. if (ptDistance) {
  2515. ptDistance = bmSqrt(ptDistance);
  2516. addedLength += ptDistance;
  2517. }
  2518. lengthData.percents[k] = perc;
  2519. lengthData.lengths[k] = addedLength;
  2520. }
  2521. lengthData.addedLength = addedLength;
  2522. return lengthData;
  2523. };
  2524. }());
  2525. function getSegmentsLength(shapeData) {
  2526. var segmentsLength = segmentsLengthPool.newElement();
  2527. var closed = shapeData.c;
  2528. var pathV = shapeData.v;
  2529. var pathO = shapeData.o;
  2530. var pathI = shapeData.i;
  2531. var i;
  2532. var len = shapeData._length;
  2533. var lengths = segmentsLength.lengths;
  2534. var totalLength = 0;
  2535. for (i = 0; i < len - 1; i += 1) {
  2536. lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]);
  2537. totalLength += lengths[i].addedLength;
  2538. }
  2539. if (closed && len) {
  2540. lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]);
  2541. totalLength += lengths[i].addedLength;
  2542. }
  2543. segmentsLength.totalLength = totalLength;
  2544. return segmentsLength;
  2545. }
  2546. function BezierData(length) {
  2547. this.segmentLength = 0;
  2548. this.points = new Array(length);
  2549. }
  2550. function PointData(partial, point) {
  2551. this.partialLength = partial;
  2552. this.point = point;
  2553. }
  2554. var buildBezierData = (function () {
  2555. var storedData = {};
  2556. return function (pt1, pt2, pt3, pt4) {
  2557. var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p');
  2558. if (!storedData[bezierName]) {
  2559. var curveSegments = getDefaultCurveSegments();
  2560. var k;
  2561. var i;
  2562. var len;
  2563. var ptCoord;
  2564. var perc;
  2565. var addedLength = 0;
  2566. var ptDistance;
  2567. var point;
  2568. var lastPoint = null;
  2569. 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])) {
  2570. curveSegments = 2;
  2571. }
  2572. var bezierData = new BezierData(curveSegments);
  2573. len = pt3.length;
  2574. for (k = 0; k < curveSegments; k += 1) {
  2575. point = createSizedArray(len);
  2576. perc = k / (curveSegments - 1);
  2577. ptDistance = 0;
  2578. for (i = 0; i < len; i += 1) {
  2579. 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];
  2580. point[i] = ptCoord;
  2581. if (lastPoint !== null) {
  2582. ptDistance += bmPow(point[i] - lastPoint[i], 2);
  2583. }
  2584. }
  2585. ptDistance = bmSqrt(ptDistance);
  2586. addedLength += ptDistance;
  2587. bezierData.points[k] = new PointData(ptDistance, point);
  2588. lastPoint = point;
  2589. }
  2590. bezierData.segmentLength = addedLength;
  2591. storedData[bezierName] = bezierData;
  2592. }
  2593. return storedData[bezierName];
  2594. };
  2595. }());
  2596. function getDistancePerc(perc, bezierData) {
  2597. var percents = bezierData.percents;
  2598. var lengths = bezierData.lengths;
  2599. var len = percents.length;
  2600. var initPos = bmFloor((len - 1) * perc);
  2601. var lengthPos = perc * bezierData.addedLength;
  2602. var lPerc = 0;
  2603. if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) {
  2604. return percents[initPos];
  2605. }
  2606. var dir = lengths[initPos] > lengthPos ? -1 : 1;
  2607. var flag = true;
  2608. while (flag) {
  2609. if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) {
  2610. lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]);
  2611. flag = false;
  2612. } else {
  2613. initPos += dir;
  2614. }
  2615. if (initPos < 0 || initPos >= len - 1) {
  2616. // FIX for TypedArrays that don't store floating point values with enough accuracy
  2617. if (initPos === len - 1) {
  2618. return percents[initPos];
  2619. }
  2620. flag = false;
  2621. }
  2622. }
  2623. return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc;
  2624. }
  2625. function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) {
  2626. var t1 = getDistancePerc(percent, bezierData);
  2627. var u1 = 1 - t1;
  2628. 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;
  2629. 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;
  2630. return [ptX, ptY];
  2631. }
  2632. var bezierSegmentPoints = createTypedArray('float32', 8);
  2633. function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) {
  2634. if (startPerc < 0) {
  2635. startPerc = 0;
  2636. } else if (startPerc > 1) {
  2637. startPerc = 1;
  2638. }
  2639. var t0 = getDistancePerc(startPerc, bezierData);
  2640. endPerc = endPerc > 1 ? 1 : endPerc;
  2641. var t1 = getDistancePerc(endPerc, bezierData);
  2642. var i;
  2643. var len = pt1.length;
  2644. var u0 = 1 - t0;
  2645. var u1 = 1 - t1;
  2646. var u0u0u0 = u0 * u0 * u0;
  2647. var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase
  2648. var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase
  2649. var t0t0t0 = t0 * t0 * t0;
  2650. //
  2651. var u0u0u1 = u0 * u0 * u1;
  2652. var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase
  2653. var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase
  2654. var t0t0t1 = t0 * t0 * t1;
  2655. //
  2656. var u0u1u1 = u0 * u1 * u1;
  2657. var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase
  2658. var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase
  2659. var t0t1t1 = t0 * t1 * t1;
  2660. //
  2661. var u1u1u1 = u1 * u1 * u1;
  2662. var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase
  2663. var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase
  2664. var t1t1t1 = t1 * t1 * t1;
  2665. for (i = 0; i < len; i += 1) {
  2666. 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
  2667. 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
  2668. 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
  2669. 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
  2670. }
  2671. return bezierSegmentPoints;
  2672. }
  2673. return {
  2674. getSegmentsLength: getSegmentsLength,
  2675. getNewSegment: getNewSegment,
  2676. getPointInSegment: getPointInSegment,
  2677. buildBezierData: buildBezierData,
  2678. pointOnLine2D: pointOnLine2D,
  2679. pointOnLine3D: pointOnLine3D,
  2680. };
  2681. }
  2682. const bez = bezFunction();
  2683. var initFrame = initialDefaultFrame;
  2684. var mathAbs = Math.abs;
  2685. function interpolateValue(frameNum, caching) {
  2686. var offsetTime = this.offsetTime;
  2687. var newValue;
  2688. if (this.propType === 'multidimensional') {
  2689. newValue = createTypedArray('float32', this.pv.length);
  2690. }
  2691. var iterationIndex = caching.lastIndex;
  2692. var i = iterationIndex;
  2693. var len = this.keyframes.length - 1;
  2694. var flag = true;
  2695. var keyData;
  2696. var nextKeyData;
  2697. var keyframeMetadata;
  2698. while (flag) {
  2699. keyData = this.keyframes[i];
  2700. nextKeyData = this.keyframes[i + 1];
  2701. if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) {
  2702. if (keyData.h) {
  2703. keyData = nextKeyData;
  2704. }
  2705. iterationIndex = 0;
  2706. break;
  2707. }
  2708. if ((nextKeyData.t - offsetTime) > frameNum) {
  2709. iterationIndex = i;
  2710. break;
  2711. }
  2712. if (i < len - 1) {
  2713. i += 1;
  2714. } else {
  2715. iterationIndex = 0;
  2716. flag = false;
  2717. }
  2718. }
  2719. keyframeMetadata = this.keyframesMetadata[i] || {};
  2720. var k;
  2721. var kLen;
  2722. var perc;
  2723. var jLen;
  2724. var j;
  2725. var fnc;
  2726. var nextKeyTime = nextKeyData.t - offsetTime;
  2727. var keyTime = keyData.t - offsetTime;
  2728. var endValue;
  2729. if (keyData.to) {
  2730. if (!keyframeMetadata.bezierData) {
  2731. keyframeMetadata.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti);
  2732. }
  2733. var bezierData = keyframeMetadata.bezierData;
  2734. if (frameNum >= nextKeyTime || frameNum < keyTime) {
  2735. var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0;
  2736. kLen = bezierData.points[ind].point.length;
  2737. for (k = 0; k < kLen; k += 1) {
  2738. newValue[k] = bezierData.points[ind].point[k];
  2739. }
  2740. // caching._lastKeyframeIndex = -1;
  2741. } else {
  2742. if (keyframeMetadata.__fnct) {
  2743. fnc = keyframeMetadata.__fnct;
  2744. } else {
  2745. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get;
  2746. keyframeMetadata.__fnct = fnc;
  2747. }
  2748. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2749. var distanceInLine = bezierData.segmentLength * perc;
  2750. var segmentPerc;
  2751. var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0;
  2752. j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0;
  2753. flag = true;
  2754. jLen = bezierData.points.length;
  2755. while (flag) {
  2756. addedLength += bezierData.points[j].partialLength;
  2757. if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) {
  2758. kLen = bezierData.points[j].point.length;
  2759. for (k = 0; k < kLen; k += 1) {
  2760. newValue[k] = bezierData.points[j].point[k];
  2761. }
  2762. break;
  2763. } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) {
  2764. segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength;
  2765. kLen = bezierData.points[j].point.length;
  2766. for (k = 0; k < kLen; k += 1) {
  2767. newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc;
  2768. }
  2769. break;
  2770. }
  2771. if (j < jLen - 1) {
  2772. j += 1;
  2773. } else {
  2774. flag = false;
  2775. }
  2776. }
  2777. caching._lastPoint = j;
  2778. caching._lastAddedLength = addedLength - bezierData.points[j].partialLength;
  2779. caching._lastKeyframeIndex = i;
  2780. }
  2781. } else {
  2782. var outX;
  2783. var outY;
  2784. var inX;
  2785. var inY;
  2786. var keyValue;
  2787. len = keyData.s.length;
  2788. endValue = nextKeyData.s || keyData.e;
  2789. if (this.sh && keyData.h !== 1) {
  2790. if (frameNum >= nextKeyTime) {
  2791. newValue[0] = endValue[0];
  2792. newValue[1] = endValue[1];
  2793. newValue[2] = endValue[2];
  2794. } else if (frameNum <= keyTime) {
  2795. newValue[0] = keyData.s[0];
  2796. newValue[1] = keyData.s[1];
  2797. newValue[2] = keyData.s[2];
  2798. } else {
  2799. var quatStart = createQuaternion(keyData.s);
  2800. var quatEnd = createQuaternion(endValue);
  2801. var time = (frameNum - keyTime) / (nextKeyTime - keyTime);
  2802. quaternionToEuler(newValue, slerp(quatStart, quatEnd, time));
  2803. }
  2804. } else {
  2805. for (i = 0; i < len; i += 1) {
  2806. if (keyData.h !== 1) {
  2807. if (frameNum >= nextKeyTime) {
  2808. perc = 1;
  2809. } else if (frameNum < keyTime) {
  2810. perc = 0;
  2811. } else {
  2812. if (keyData.o.x.constructor === Array) {
  2813. if (!keyframeMetadata.__fnct) {
  2814. keyframeMetadata.__fnct = [];
  2815. }
  2816. if (!keyframeMetadata.__fnct[i]) {
  2817. outX = keyData.o.x[i] === undefined ? keyData.o.x[0] : keyData.o.x[i];
  2818. outY = keyData.o.y[i] === undefined ? keyData.o.y[0] : keyData.o.y[i];
  2819. inX = keyData.i.x[i] === undefined ? keyData.i.x[0] : keyData.i.x[i];
  2820. inY = keyData.i.y[i] === undefined ? keyData.i.y[0] : keyData.i.y[i];
  2821. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2822. keyframeMetadata.__fnct[i] = fnc;
  2823. } else {
  2824. fnc = keyframeMetadata.__fnct[i];
  2825. }
  2826. } else if (!keyframeMetadata.__fnct) {
  2827. outX = keyData.o.x;
  2828. outY = keyData.o.y;
  2829. inX = keyData.i.x;
  2830. inY = keyData.i.y;
  2831. fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get;
  2832. keyData.keyframeMetadata = fnc;
  2833. } else {
  2834. fnc = keyframeMetadata.__fnct;
  2835. }
  2836. perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime));
  2837. }
  2838. }
  2839. endValue = nextKeyData.s || keyData.e;
  2840. keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc;
  2841. if (this.propType === 'multidimensional') {
  2842. newValue[i] = keyValue;
  2843. } else {
  2844. newValue = keyValue;
  2845. }
  2846. }
  2847. }
  2848. }
  2849. caching.lastIndex = iterationIndex;
  2850. return newValue;
  2851. }
  2852. // based on @Toji's https://github.com/toji/gl-matrix/
  2853. function slerp(a, b, t) {
  2854. var out = [];
  2855. var ax = a[0];
  2856. var ay = a[1];
  2857. var az = a[2];
  2858. var aw = a[3];
  2859. var bx = b[0];
  2860. var by = b[1];
  2861. var bz = b[2];
  2862. var bw = b[3];
  2863. var omega;
  2864. var cosom;
  2865. var sinom;
  2866. var scale0;
  2867. var scale1;
  2868. cosom = ax * bx + ay * by + az * bz + aw * bw;
  2869. if (cosom < 0.0) {
  2870. cosom = -cosom;
  2871. bx = -bx;
  2872. by = -by;
  2873. bz = -bz;
  2874. bw = -bw;
  2875. }
  2876. if ((1.0 - cosom) > 0.000001) {
  2877. omega = Math.acos(cosom);
  2878. sinom = Math.sin(omega);
  2879. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  2880. scale1 = Math.sin(t * omega) / sinom;
  2881. } else {
  2882. scale0 = 1.0 - t;
  2883. scale1 = t;
  2884. }
  2885. out[0] = scale0 * ax + scale1 * bx;
  2886. out[1] = scale0 * ay + scale1 * by;
  2887. out[2] = scale0 * az + scale1 * bz;
  2888. out[3] = scale0 * aw + scale1 * bw;
  2889. return out;
  2890. }
  2891. function quaternionToEuler(out, quat) {
  2892. var qx = quat[0];
  2893. var qy = quat[1];
  2894. var qz = quat[2];
  2895. var qw = quat[3];
  2896. var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz);
  2897. var attitude = Math.asin(2 * qx * qy + 2 * qz * qw);
  2898. var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz);
  2899. out[0] = heading / degToRads;
  2900. out[1] = attitude / degToRads;
  2901. out[2] = bank / degToRads;
  2902. }
  2903. function createQuaternion(values) {
  2904. var heading = values[0] * degToRads;
  2905. var attitude = values[1] * degToRads;
  2906. var bank = values[2] * degToRads;
  2907. var c1 = Math.cos(heading / 2);
  2908. var c2 = Math.cos(attitude / 2);
  2909. var c3 = Math.cos(bank / 2);
  2910. var s1 = Math.sin(heading / 2);
  2911. var s2 = Math.sin(attitude / 2);
  2912. var s3 = Math.sin(bank / 2);
  2913. var w = c1 * c2 * c3 - s1 * s2 * s3;
  2914. var x = s1 * s2 * c3 + c1 * c2 * s3;
  2915. var y = s1 * c2 * c3 + c1 * s2 * s3;
  2916. var z = c1 * s2 * c3 - s1 * c2 * s3;
  2917. return [x, y, z, w];
  2918. }
  2919. function getValueAtCurrentTime() {
  2920. var frameNum = this.comp.renderedFrame - this.offsetTime;
  2921. var initTime = this.keyframes[0].t - this.offsetTime;
  2922. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  2923. if (!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))) {
  2924. if (this._caching.lastFrame >= frameNum) {
  2925. this._caching._lastKeyframeIndex = -1;
  2926. this._caching.lastIndex = 0;
  2927. }
  2928. var renderResult = this.interpolateValue(frameNum, this._caching);
  2929. this.pv = renderResult;
  2930. }
  2931. this._caching.lastFrame = frameNum;
  2932. return this.pv;
  2933. }
  2934. function setVValue(val) {
  2935. var multipliedValue;
  2936. if (this.propType === 'unidimensional') {
  2937. multipliedValue = val * this.mult;
  2938. if (mathAbs(this.v - multipliedValue) > 0.00001) {
  2939. this.v = multipliedValue;
  2940. this._mdf = true;
  2941. }
  2942. } else {
  2943. var i = 0;
  2944. var len = this.v.length;
  2945. while (i < len) {
  2946. multipliedValue = val[i] * this.mult;
  2947. if (mathAbs(this.v[i] - multipliedValue) > 0.00001) {
  2948. this.v[i] = multipliedValue;
  2949. this._mdf = true;
  2950. }
  2951. i += 1;
  2952. }
  2953. }
  2954. }
  2955. function processEffectsSequence() {
  2956. if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) {
  2957. return;
  2958. }
  2959. if (this.lock) {
  2960. this.setVValue(this.pv);
  2961. return;
  2962. }
  2963. this.lock = true;
  2964. this._mdf = this._isFirstFrame;
  2965. var i;
  2966. var len = this.effectsSequence.length;
  2967. var finalValue = this.kf ? this.pv : this.data.k;
  2968. for (i = 0; i < len; i += 1) {
  2969. finalValue = this.effectsSequence[i](finalValue);
  2970. }
  2971. this.setVValue(finalValue);
  2972. this._isFirstFrame = false;
  2973. this.lock = false;
  2974. this.frameId = this.elem.globalData.frameId;
  2975. }
  2976. function addEffect(effectFunction) {
  2977. this.effectsSequence.push(effectFunction);
  2978. this.container.addDynamicProperty(this);
  2979. }
  2980. function ValueProperty(elem, data, mult, container) {
  2981. this.propType = 'unidimensional';
  2982. this.mult = mult || 1;
  2983. this.data = data;
  2984. this.v = mult ? data.k * mult : data.k;
  2985. this.pv = data.k;
  2986. this._mdf = false;
  2987. this.elem = elem;
  2988. this.container = container;
  2989. this.comp = elem.comp;
  2990. this.k = false;
  2991. this.kf = false;
  2992. this.vel = 0;
  2993. this.effectsSequence = [];
  2994. this._isFirstFrame = true;
  2995. this.getValue = processEffectsSequence;
  2996. this.setVValue = setVValue;
  2997. this.addEffect = addEffect;
  2998. }
  2999. function MultiDimensionalProperty(elem, data, mult, container) {
  3000. this.propType = 'multidimensional';
  3001. this.mult = mult || 1;
  3002. this.data = data;
  3003. this._mdf = false;
  3004. this.elem = elem;
  3005. this.container = container;
  3006. this.comp = elem.comp;
  3007. this.k = false;
  3008. this.kf = false;
  3009. this.frameId = -1;
  3010. var i;
  3011. var len = data.k.length;
  3012. this.v = createTypedArray('float32', len);
  3013. this.pv = createTypedArray('float32', len);
  3014. this.vel = createTypedArray('float32', len);
  3015. for (i = 0; i < len; i += 1) {
  3016. this.v[i] = data.k[i] * this.mult;
  3017. this.pv[i] = data.k[i];
  3018. }
  3019. this._isFirstFrame = true;
  3020. this.effectsSequence = [];
  3021. this.getValue = processEffectsSequence;
  3022. this.setVValue = setVValue;
  3023. this.addEffect = addEffect;
  3024. }
  3025. function KeyframedValueProperty(elem, data, mult, container) {
  3026. this.propType = 'unidimensional';
  3027. this.keyframes = data.k;
  3028. this.keyframesMetadata = [];
  3029. this.offsetTime = elem.data.st;
  3030. this.frameId = -1;
  3031. this._caching = {
  3032. lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1,
  3033. };
  3034. this.k = true;
  3035. this.kf = true;
  3036. this.data = data;
  3037. this.mult = mult || 1;
  3038. this.elem = elem;
  3039. this.container = container;
  3040. this.comp = elem.comp;
  3041. this.v = initFrame;
  3042. this.pv = initFrame;
  3043. this._isFirstFrame = true;
  3044. this.getValue = processEffectsSequence;
  3045. this.setVValue = setVValue;
  3046. this.interpolateValue = interpolateValue;
  3047. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3048. this.addEffect = addEffect;
  3049. }
  3050. function KeyframedMultidimensionalProperty(elem, data, mult, container) {
  3051. this.propType = 'multidimensional';
  3052. var i;
  3053. var len = data.k.length;
  3054. var s;
  3055. var e;
  3056. var to;
  3057. var ti;
  3058. for (i = 0; i < len - 1; i += 1) {
  3059. if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) {
  3060. s = data.k[i].s;
  3061. e = data.k[i + 1].s;
  3062. to = data.k[i].to;
  3063. ti = data.k[i].ti;
  3064. 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]))) {
  3065. data.k[i].to = null;
  3066. data.k[i].ti = null;
  3067. }
  3068. if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) {
  3069. if (s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) {
  3070. data.k[i].to = null;
  3071. data.k[i].ti = null;
  3072. }
  3073. }
  3074. }
  3075. }
  3076. this.effectsSequence = [getValueAtCurrentTime.bind(this)];
  3077. this.data = data;
  3078. this.keyframes = data.k;
  3079. this.keyframesMetadata = [];
  3080. this.offsetTime = elem.data.st;
  3081. this.k = true;
  3082. this.kf = true;
  3083. this._isFirstFrame = true;
  3084. this.mult = mult || 1;
  3085. this.elem = elem;
  3086. this.container = container;
  3087. this.comp = elem.comp;
  3088. this.getValue = processEffectsSequence;
  3089. this.setVValue = setVValue;
  3090. this.interpolateValue = interpolateValue;
  3091. this.frameId = -1;
  3092. var arrLen = data.k[0].s.length;
  3093. this.v = createTypedArray('float32', arrLen);
  3094. this.pv = createTypedArray('float32', arrLen);
  3095. for (i = 0; i < arrLen; i += 1) {
  3096. this.v[i] = initFrame;
  3097. this.pv[i] = initFrame;
  3098. }
  3099. this._caching = { lastFrame: initFrame, lastIndex: 0, value: createTypedArray('float32', arrLen) };
  3100. this.addEffect = addEffect;
  3101. }
  3102. const PropertyFactory = (function () {
  3103. function getProp(elem, data, type, mult, container) {
  3104. if (data.sid) {
  3105. data = elem.globalData.slotManager.getProp(data);
  3106. }
  3107. var p;
  3108. if (!data.k.length) {
  3109. p = new ValueProperty(elem, data, mult, container);
  3110. } else if (typeof (data.k[0]) === 'number') {
  3111. p = new MultiDimensionalProperty(elem, data, mult, container);
  3112. } else {
  3113. switch (type) {
  3114. case 0:
  3115. p = new KeyframedValueProperty(elem, data, mult, container);
  3116. break;
  3117. case 1:
  3118. p = new KeyframedMultidimensionalProperty(elem, data, mult, container);
  3119. break;
  3120. default:
  3121. break;
  3122. }
  3123. }
  3124. if (p.effectsSequence.length) {
  3125. container.addDynamicProperty(p);
  3126. }
  3127. return p;
  3128. }
  3129. var ob = {
  3130. getProp: getProp,
  3131. };
  3132. return ob;
  3133. }());
  3134. function DynamicPropertyContainer() {}
  3135. DynamicPropertyContainer.prototype = {
  3136. addDynamicProperty: function (prop) {
  3137. if (this.dynamicProperties.indexOf(prop) === -1) {
  3138. this.dynamicProperties.push(prop);
  3139. this.container.addDynamicProperty(this);
  3140. this._isAnimated = true;
  3141. }
  3142. },
  3143. iterateDynamicProperties: function () {
  3144. this._mdf = false;
  3145. var i;
  3146. var len = this.dynamicProperties.length;
  3147. for (i = 0; i < len; i += 1) {
  3148. this.dynamicProperties[i].getValue();
  3149. if (this.dynamicProperties[i]._mdf) {
  3150. this._mdf = true;
  3151. }
  3152. }
  3153. },
  3154. initDynamicPropertyContainer: function (container) {
  3155. this.container = container;
  3156. this.dynamicProperties = [];
  3157. this._mdf = false;
  3158. this._isAnimated = false;
  3159. },
  3160. };
  3161. const pointPool = (function () {
  3162. function create() {
  3163. return createTypedArray('float32', 2);
  3164. }
  3165. return poolFactory(8, create);
  3166. }());
  3167. function ShapePath() {
  3168. this.c = false;
  3169. this._length = 0;
  3170. this._maxLength = 8;
  3171. this.v = createSizedArray(this._maxLength);
  3172. this.o = createSizedArray(this._maxLength);
  3173. this.i = createSizedArray(this._maxLength);
  3174. }
  3175. ShapePath.prototype.setPathData = function (closed, len) {
  3176. this.c = closed;
  3177. this.setLength(len);
  3178. var i = 0;
  3179. while (i < len) {
  3180. this.v[i] = pointPool.newElement();
  3181. this.o[i] = pointPool.newElement();
  3182. this.i[i] = pointPool.newElement();
  3183. i += 1;
  3184. }
  3185. };
  3186. ShapePath.prototype.setLength = function (len) {
  3187. while (this._maxLength < len) {
  3188. this.doubleArrayLength();
  3189. }
  3190. this._length = len;
  3191. };
  3192. ShapePath.prototype.doubleArrayLength = function () {
  3193. this.v = this.v.concat(createSizedArray(this._maxLength));
  3194. this.i = this.i.concat(createSizedArray(this._maxLength));
  3195. this.o = this.o.concat(createSizedArray(this._maxLength));
  3196. this._maxLength *= 2;
  3197. };
  3198. ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) {
  3199. var arr;
  3200. this._length = Math.max(this._length, pos + 1);
  3201. if (this._length >= this._maxLength) {
  3202. this.doubleArrayLength();
  3203. }
  3204. switch (type) {
  3205. case 'v':
  3206. arr = this.v;
  3207. break;
  3208. case 'i':
  3209. arr = this.i;
  3210. break;
  3211. case 'o':
  3212. arr = this.o;
  3213. break;
  3214. default:
  3215. arr = [];
  3216. break;
  3217. }
  3218. if (!arr[pos] || (arr[pos] && !replace)) {
  3219. arr[pos] = pointPool.newElement();
  3220. }
  3221. arr[pos][0] = x;
  3222. arr[pos][1] = y;
  3223. };
  3224. ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) {
  3225. this.setXYAt(vX, vY, 'v', pos, replace);
  3226. this.setXYAt(oX, oY, 'o', pos, replace);
  3227. this.setXYAt(iX, iY, 'i', pos, replace);
  3228. };
  3229. ShapePath.prototype.reverse = function () {
  3230. var newPath = new ShapePath();
  3231. newPath.setPathData(this.c, this._length);
  3232. var vertices = this.v;
  3233. var outPoints = this.o;
  3234. var inPoints = this.i;
  3235. var init = 0;
  3236. if (this.c) {
  3237. newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false);
  3238. init = 1;
  3239. }
  3240. var cnt = this._length - 1;
  3241. var len = this._length;
  3242. var i;
  3243. for (i = init; i < len; i += 1) {
  3244. newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false);
  3245. cnt -= 1;
  3246. }
  3247. return newPath;
  3248. };
  3249. ShapePath.prototype.length = function () {
  3250. return this._length;
  3251. };
  3252. const shapePool = (function () {
  3253. function create() {
  3254. return new ShapePath();
  3255. }
  3256. function release(shapePath) {
  3257. var len = shapePath._length;
  3258. var i;
  3259. for (i = 0; i < len; i += 1) {
  3260. pointPool.release(shapePath.v[i]);
  3261. pointPool.release(shapePath.i[i]);
  3262. pointPool.release(shapePath.o[i]);
  3263. shapePath.v[i] = null;
  3264. shapePath.i[i] = null;
  3265. shapePath.o[i] = null;
  3266. }
  3267. shapePath._length = 0;
  3268. shapePath.c = false;
  3269. }
  3270. function clone(shape) {
  3271. var cloned = factory.newElement();
  3272. var i;
  3273. var len = shape._length === undefined ? shape.v.length : shape._length;
  3274. cloned.setLength(len);
  3275. cloned.c = shape.c;
  3276. for (i = 0; i < len; i += 1) {
  3277. 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);
  3278. }
  3279. return cloned;
  3280. }
  3281. var factory = poolFactory(4, create, release);
  3282. factory.clone = clone;
  3283. return factory;
  3284. }());
  3285. function ShapeCollection() {
  3286. this._length = 0;
  3287. this._maxLength = 4;
  3288. this.shapes = createSizedArray(this._maxLength);
  3289. }
  3290. ShapeCollection.prototype.addShape = function (shapeData) {
  3291. if (this._length === this._maxLength) {
  3292. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  3293. this._maxLength *= 2;
  3294. }
  3295. this.shapes[this._length] = shapeData;
  3296. this._length += 1;
  3297. };
  3298. ShapeCollection.prototype.releaseShapes = function () {
  3299. var i;
  3300. for (i = 0; i < this._length; i += 1) {
  3301. shapePool.release(this.shapes[i]);
  3302. }
  3303. this._length = 0;
  3304. };
  3305. const shapeCollectionPool = (function () {
  3306. var ob = {
  3307. newShapeCollection: newShapeCollection,
  3308. release: release,
  3309. };
  3310. var _length = 0;
  3311. var _maxLength = 4;
  3312. var pool = createSizedArray(_maxLength);
  3313. function newShapeCollection() {
  3314. var shapeCollection;
  3315. if (_length) {
  3316. _length -= 1;
  3317. shapeCollection = pool[_length];
  3318. } else {
  3319. shapeCollection = new ShapeCollection();
  3320. }
  3321. return shapeCollection;
  3322. }
  3323. function release(shapeCollection) {
  3324. var i;
  3325. var len = shapeCollection._length;
  3326. for (i = 0; i < len; i += 1) {
  3327. shapePool.release(shapeCollection.shapes[i]);
  3328. }
  3329. shapeCollection._length = 0;
  3330. if (_length === _maxLength) {
  3331. pool = pooling.double(pool);
  3332. _maxLength *= 2;
  3333. }
  3334. pool[_length] = shapeCollection;
  3335. _length += 1;
  3336. }
  3337. return ob;
  3338. }());
  3339. const ShapePropertyFactory = (function () {
  3340. var initFrame = -999999;
  3341. function interpolateShape(frameNum, previousValue, caching) {
  3342. var iterationIndex = caching.lastIndex;
  3343. var keyPropS;
  3344. var keyPropE;
  3345. var isHold;
  3346. var j;
  3347. var k;
  3348. var jLen;
  3349. var kLen;
  3350. var perc;
  3351. var vertexValue;
  3352. var kf = this.keyframes;
  3353. if (frameNum < kf[0].t - this.offsetTime) {
  3354. keyPropS = kf[0].s[0];
  3355. isHold = true;
  3356. iterationIndex = 0;
  3357. } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) {
  3358. keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0];
  3359. /* if(kf[kf.length - 1].s){
  3360. keyPropS = kf[kf.length - 1].s[0];
  3361. }else{
  3362. keyPropS = kf[kf.length - 2].e[0];
  3363. } */
  3364. isHold = true;
  3365. } else {
  3366. var i = iterationIndex;
  3367. var len = kf.length - 1;
  3368. var flag = true;
  3369. var keyData;
  3370. var nextKeyData;
  3371. var keyframeMetadata;
  3372. while (flag) {
  3373. keyData = kf[i];
  3374. nextKeyData = kf[i + 1];
  3375. if ((nextKeyData.t - this.offsetTime) > frameNum) {
  3376. break;
  3377. }
  3378. if (i < len - 1) {
  3379. i += 1;
  3380. } else {
  3381. flag = false;
  3382. }
  3383. }
  3384. keyframeMetadata = this.keyframesMetadata[i] || {};
  3385. isHold = keyData.h === 1;
  3386. iterationIndex = i;
  3387. if (!isHold) {
  3388. if (frameNum >= nextKeyData.t - this.offsetTime) {
  3389. perc = 1;
  3390. } else if (frameNum < keyData.t - this.offsetTime) {
  3391. perc = 0;
  3392. } else {
  3393. var fnc;
  3394. if (keyframeMetadata.__fnct) {
  3395. fnc = keyframeMetadata.__fnct;
  3396. } else {
  3397. fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get;
  3398. keyframeMetadata.__fnct = fnc;
  3399. }
  3400. perc = fnc((frameNum - (keyData.t - this.offsetTime)) / ((nextKeyData.t - this.offsetTime) - (keyData.t - this.offsetTime)));
  3401. }
  3402. keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0];
  3403. }
  3404. keyPropS = keyData.s[0];
  3405. }
  3406. jLen = previousValue._length;
  3407. kLen = keyPropS.i[0].length;
  3408. caching.lastIndex = iterationIndex;
  3409. for (j = 0; j < jLen; j += 1) {
  3410. for (k = 0; k < kLen; k += 1) {
  3411. vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc;
  3412. previousValue.i[j][k] = vertexValue;
  3413. vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc;
  3414. previousValue.o[j][k] = vertexValue;
  3415. vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc;
  3416. previousValue.v[j][k] = vertexValue;
  3417. }
  3418. }
  3419. }
  3420. function interpolateShapeCurrentTime() {
  3421. var frameNum = this.comp.renderedFrame - this.offsetTime;
  3422. var initTime = this.keyframes[0].t - this.offsetTime;
  3423. var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime;
  3424. var lastFrame = this._caching.lastFrame;
  3425. if (!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))) {
  3426. /// /
  3427. this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0;
  3428. this.interpolateShape(frameNum, this.pv, this._caching);
  3429. /// /
  3430. }
  3431. this._caching.lastFrame = frameNum;
  3432. return this.pv;
  3433. }
  3434. function resetShape() {
  3435. this.paths = this.localShapeCollection;
  3436. }
  3437. function shapesEqual(shape1, shape2) {
  3438. if (shape1._length !== shape2._length || shape1.c !== shape2.c) {
  3439. return false;
  3440. }
  3441. var i;
  3442. var len = shape1._length;
  3443. for (i = 0; i < len; i += 1) {
  3444. if (shape1.v[i][0] !== shape2.v[i][0]
  3445. || shape1.v[i][1] !== shape2.v[i][1]
  3446. || shape1.o[i][0] !== shape2.o[i][0]
  3447. || shape1.o[i][1] !== shape2.o[i][1]
  3448. || shape1.i[i][0] !== shape2.i[i][0]
  3449. || shape1.i[i][1] !== shape2.i[i][1]) {
  3450. return false;
  3451. }
  3452. }
  3453. return true;
  3454. }
  3455. function setVValue(newPath) {
  3456. if (!shapesEqual(this.v, newPath)) {
  3457. this.v = shapePool.clone(newPath);
  3458. this.localShapeCollection.releaseShapes();
  3459. this.localShapeCollection.addShape(this.v);
  3460. this._mdf = true;
  3461. this.paths = this.localShapeCollection;
  3462. }
  3463. }
  3464. function processEffectsSequence() {
  3465. if (this.elem.globalData.frameId === this.frameId) {
  3466. return;
  3467. } if (!this.effectsSequence.length) {
  3468. this._mdf = false;
  3469. return;
  3470. }
  3471. if (this.lock) {
  3472. this.setVValue(this.pv);
  3473. return;
  3474. }
  3475. this.lock = true;
  3476. this._mdf = false;
  3477. var finalValue;
  3478. if (this.kf) {
  3479. finalValue = this.pv;
  3480. } else if (this.data.ks) {
  3481. finalValue = this.data.ks.k;
  3482. } else {
  3483. finalValue = this.data.pt.k;
  3484. }
  3485. var i;
  3486. var len = this.effectsSequence.length;
  3487. for (i = 0; i < len; i += 1) {
  3488. finalValue = this.effectsSequence[i](finalValue);
  3489. }
  3490. this.setVValue(finalValue);
  3491. this.lock = false;
  3492. this.frameId = this.elem.globalData.frameId;
  3493. }
  3494. function ShapeProperty(elem, data, type) {
  3495. this.propType = 'shape';
  3496. this.comp = elem.comp;
  3497. this.container = elem;
  3498. this.elem = elem;
  3499. this.data = data;
  3500. this.k = false;
  3501. this.kf = false;
  3502. this._mdf = false;
  3503. var pathData = type === 3 ? data.pt.k : data.ks.k;
  3504. this.v = shapePool.clone(pathData);
  3505. this.pv = shapePool.clone(this.v);
  3506. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3507. this.paths = this.localShapeCollection;
  3508. this.paths.addShape(this.v);
  3509. this.reset = resetShape;
  3510. this.effectsSequence = [];
  3511. }
  3512. function addEffect(effectFunction) {
  3513. this.effectsSequence.push(effectFunction);
  3514. this.container.addDynamicProperty(this);
  3515. }
  3516. ShapeProperty.prototype.interpolateShape = interpolateShape;
  3517. ShapeProperty.prototype.getValue = processEffectsSequence;
  3518. ShapeProperty.prototype.setVValue = setVValue;
  3519. ShapeProperty.prototype.addEffect = addEffect;
  3520. function KeyframedShapeProperty(elem, data, type) {
  3521. this.propType = 'shape';
  3522. this.comp = elem.comp;
  3523. this.elem = elem;
  3524. this.container = elem;
  3525. this.offsetTime = elem.data.st;
  3526. this.keyframes = type === 3 ? data.pt.k : data.ks.k;
  3527. this.keyframesMetadata = [];
  3528. this.k = true;
  3529. this.kf = true;
  3530. var len = this.keyframes[0].s[0].i.length;
  3531. this.v = shapePool.newElement();
  3532. this.v.setPathData(this.keyframes[0].s[0].c, len);
  3533. this.pv = shapePool.clone(this.v);
  3534. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3535. this.paths = this.localShapeCollection;
  3536. this.paths.addShape(this.v);
  3537. this.lastFrame = initFrame;
  3538. this.reset = resetShape;
  3539. this._caching = { lastFrame: initFrame, lastIndex: 0 };
  3540. this.effectsSequence = [interpolateShapeCurrentTime.bind(this)];
  3541. }
  3542. KeyframedShapeProperty.prototype.getValue = processEffectsSequence;
  3543. KeyframedShapeProperty.prototype.interpolateShape = interpolateShape;
  3544. KeyframedShapeProperty.prototype.setVValue = setVValue;
  3545. KeyframedShapeProperty.prototype.addEffect = addEffect;
  3546. var EllShapeProperty = (function () {
  3547. var cPoint = roundCorner;
  3548. function EllShapePropertyFactory(elem, data) {
  3549. this.v = shapePool.newElement();
  3550. this.v.setPathData(true, 4);
  3551. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3552. this.paths = this.localShapeCollection;
  3553. this.localShapeCollection.addShape(this.v);
  3554. this.d = data.d;
  3555. this.elem = elem;
  3556. this.comp = elem.comp;
  3557. this.frameId = -1;
  3558. this.initDynamicPropertyContainer(elem);
  3559. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3560. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3561. if (this.dynamicProperties.length) {
  3562. this.k = true;
  3563. } else {
  3564. this.k = false;
  3565. this.convertEllToPath();
  3566. }
  3567. }
  3568. EllShapePropertyFactory.prototype = {
  3569. reset: resetShape,
  3570. getValue: function () {
  3571. if (this.elem.globalData.frameId === this.frameId) {
  3572. return;
  3573. }
  3574. this.frameId = this.elem.globalData.frameId;
  3575. this.iterateDynamicProperties();
  3576. if (this._mdf) {
  3577. this.convertEllToPath();
  3578. }
  3579. },
  3580. convertEllToPath: function () {
  3581. var p0 = this.p.v[0];
  3582. var p1 = this.p.v[1];
  3583. var s0 = this.s.v[0] / 2;
  3584. var s1 = this.s.v[1] / 2;
  3585. var _cw = this.d !== 3;
  3586. var _v = this.v;
  3587. _v.v[0][0] = p0;
  3588. _v.v[0][1] = p1 - s1;
  3589. _v.v[1][0] = _cw ? p0 + s0 : p0 - s0;
  3590. _v.v[1][1] = p1;
  3591. _v.v[2][0] = p0;
  3592. _v.v[2][1] = p1 + s1;
  3593. _v.v[3][0] = _cw ? p0 - s0 : p0 + s0;
  3594. _v.v[3][1] = p1;
  3595. _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3596. _v.i[0][1] = p1 - s1;
  3597. _v.i[1][0] = _cw ? p0 + s0 : p0 - s0;
  3598. _v.i[1][1] = p1 - s1 * cPoint;
  3599. _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3600. _v.i[2][1] = p1 + s1;
  3601. _v.i[3][0] = _cw ? p0 - s0 : p0 + s0;
  3602. _v.i[3][1] = p1 + s1 * cPoint;
  3603. _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint;
  3604. _v.o[0][1] = p1 - s1;
  3605. _v.o[1][0] = _cw ? p0 + s0 : p0 - s0;
  3606. _v.o[1][1] = p1 + s1 * cPoint;
  3607. _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint;
  3608. _v.o[2][1] = p1 + s1;
  3609. _v.o[3][0] = _cw ? p0 - s0 : p0 + s0;
  3610. _v.o[3][1] = p1 - s1 * cPoint;
  3611. },
  3612. };
  3613. extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory);
  3614. return EllShapePropertyFactory;
  3615. }());
  3616. var StarShapeProperty = (function () {
  3617. function StarShapePropertyFactory(elem, data) {
  3618. this.v = shapePool.newElement();
  3619. this.v.setPathData(true, 0);
  3620. this.elem = elem;
  3621. this.comp = elem.comp;
  3622. this.data = data;
  3623. this.frameId = -1;
  3624. this.d = data.d;
  3625. this.initDynamicPropertyContainer(elem);
  3626. if (data.sy === 1) {
  3627. this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this);
  3628. this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this);
  3629. this.convertToPath = this.convertStarToPath;
  3630. } else {
  3631. this.convertToPath = this.convertPolygonToPath;
  3632. }
  3633. this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this);
  3634. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3635. this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this);
  3636. this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this);
  3637. this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this);
  3638. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3639. this.localShapeCollection.addShape(this.v);
  3640. this.paths = this.localShapeCollection;
  3641. if (this.dynamicProperties.length) {
  3642. this.k = true;
  3643. } else {
  3644. this.k = false;
  3645. this.convertToPath();
  3646. }
  3647. }
  3648. StarShapePropertyFactory.prototype = {
  3649. reset: resetShape,
  3650. getValue: function () {
  3651. if (this.elem.globalData.frameId === this.frameId) {
  3652. return;
  3653. }
  3654. this.frameId = this.elem.globalData.frameId;
  3655. this.iterateDynamicProperties();
  3656. if (this._mdf) {
  3657. this.convertToPath();
  3658. }
  3659. },
  3660. convertStarToPath: function () {
  3661. var numPts = Math.floor(this.pt.v) * 2;
  3662. var angle = (Math.PI * 2) / numPts;
  3663. /* this.v.v.length = numPts;
  3664. this.v.i.length = numPts;
  3665. this.v.o.length = numPts; */
  3666. var longFlag = true;
  3667. var longRad = this.or.v;
  3668. var shortRad = this.ir.v;
  3669. var longRound = this.os.v;
  3670. var shortRound = this.is.v;
  3671. var longPerimSegment = (2 * Math.PI * longRad) / (numPts * 2);
  3672. var shortPerimSegment = (2 * Math.PI * shortRad) / (numPts * 2);
  3673. var i;
  3674. var rad;
  3675. var roundness;
  3676. var perimSegment;
  3677. var currentAng = -Math.PI / 2;
  3678. currentAng += this.r.v;
  3679. var dir = this.data.d === 3 ? -1 : 1;
  3680. this.v._length = 0;
  3681. for (i = 0; i < numPts; i += 1) {
  3682. rad = longFlag ? longRad : shortRad;
  3683. roundness = longFlag ? longRound : shortRound;
  3684. perimSegment = longFlag ? longPerimSegment : shortPerimSegment;
  3685. var x = rad * Math.cos(currentAng);
  3686. var y = rad * Math.sin(currentAng);
  3687. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3688. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3689. x += +this.p.v[0];
  3690. y += +this.p.v[1];
  3691. 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);
  3692. /* this.v.v[i] = [x,y];
  3693. this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir];
  3694. this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir];
  3695. this.v._length = numPts; */
  3696. longFlag = !longFlag;
  3697. currentAng += angle * dir;
  3698. }
  3699. },
  3700. convertPolygonToPath: function () {
  3701. var numPts = Math.floor(this.pt.v);
  3702. var angle = (Math.PI * 2) / numPts;
  3703. var rad = this.or.v;
  3704. var roundness = this.os.v;
  3705. var perimSegment = (2 * Math.PI * rad) / (numPts * 4);
  3706. var i;
  3707. var currentAng = -Math.PI * 0.5;
  3708. var dir = this.data.d === 3 ? -1 : 1;
  3709. currentAng += this.r.v;
  3710. this.v._length = 0;
  3711. for (i = 0; i < numPts; i += 1) {
  3712. var x = rad * Math.cos(currentAng);
  3713. var y = rad * Math.sin(currentAng);
  3714. var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y);
  3715. var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y);
  3716. x += +this.p.v[0];
  3717. y += +this.p.v[1];
  3718. 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);
  3719. currentAng += angle * dir;
  3720. }
  3721. this.paths.length = 0;
  3722. this.paths[0] = this.v;
  3723. },
  3724. };
  3725. extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory);
  3726. return StarShapePropertyFactory;
  3727. }());
  3728. var RectShapeProperty = (function () {
  3729. function RectShapePropertyFactory(elem, data) {
  3730. this.v = shapePool.newElement();
  3731. this.v.c = true;
  3732. this.localShapeCollection = shapeCollectionPool.newShapeCollection();
  3733. this.localShapeCollection.addShape(this.v);
  3734. this.paths = this.localShapeCollection;
  3735. this.elem = elem;
  3736. this.comp = elem.comp;
  3737. this.frameId = -1;
  3738. this.d = data.d;
  3739. this.initDynamicPropertyContainer(elem);
  3740. this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this);
  3741. this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this);
  3742. this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this);
  3743. if (this.dynamicProperties.length) {
  3744. this.k = true;
  3745. } else {
  3746. this.k = false;
  3747. this.convertRectToPath();
  3748. }
  3749. }
  3750. RectShapePropertyFactory.prototype = {
  3751. convertRectToPath: function () {
  3752. var p0 = this.p.v[0];
  3753. var p1 = this.p.v[1];
  3754. var v0 = this.s.v[0] / 2;
  3755. var v1 = this.s.v[1] / 2;
  3756. var round = bmMin(v0, v1, this.r.v);
  3757. var cPoint = round * (1 - roundCorner);
  3758. this.v._length = 0;
  3759. if (this.d === 2 || this.d === 1) {
  3760. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true);
  3761. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true);
  3762. if (round !== 0) {
  3763. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true);
  3764. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true);
  3765. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true);
  3766. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true);
  3767. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true);
  3768. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true);
  3769. } else {
  3770. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2);
  3771. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3);
  3772. }
  3773. } else {
  3774. this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true);
  3775. if (round !== 0) {
  3776. this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true);
  3777. this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true);
  3778. this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true);
  3779. this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true);
  3780. this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true);
  3781. this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true);
  3782. this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true);
  3783. } else {
  3784. this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true);
  3785. this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true);
  3786. this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true);
  3787. }
  3788. }
  3789. },
  3790. getValue: function () {
  3791. if (this.elem.globalData.frameId === this.frameId) {
  3792. return;
  3793. }
  3794. this.frameId = this.elem.globalData.frameId;
  3795. this.iterateDynamicProperties();
  3796. if (this._mdf) {
  3797. this.convertRectToPath();
  3798. }
  3799. },
  3800. reset: resetShape,
  3801. };
  3802. extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory);
  3803. return RectShapePropertyFactory;
  3804. }());
  3805. function getShapeProp(elem, data, type) {
  3806. var prop;
  3807. if (type === 3 || type === 4) {
  3808. var dataProp = type === 3 ? data.pt : data.ks;
  3809. var keys = dataProp.k;
  3810. if (keys.length) {
  3811. prop = new KeyframedShapeProperty(elem, data, type);
  3812. } else {
  3813. prop = new ShapeProperty(elem, data, type);
  3814. }
  3815. } else if (type === 5) {
  3816. prop = new RectShapeProperty(elem, data);
  3817. } else if (type === 6) {
  3818. prop = new EllShapeProperty(elem, data);
  3819. } else if (type === 7) {
  3820. prop = new StarShapeProperty(elem, data);
  3821. }
  3822. if (prop.k) {
  3823. elem.addDynamicProperty(prop);
  3824. }
  3825. return prop;
  3826. }
  3827. function getConstructorFunction() {
  3828. return ShapeProperty;
  3829. }
  3830. function getKeyframedConstructorFunction() {
  3831. return KeyframedShapeProperty;
  3832. }
  3833. var ob = {};
  3834. ob.getShapeProp = getShapeProp;
  3835. ob.getConstructorFunction = getConstructorFunction;
  3836. ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction;
  3837. return ob;
  3838. }());
  3839. /*!
  3840. Transformation Matrix v2.0
  3841. (c) Epistemex 2014-2015
  3842. www.epistemex.com
  3843. By Ken Fyrstenberg
  3844. Contributions by leeoniya.
  3845. License: MIT, header required.
  3846. */
  3847. /**
  3848. * 2D transformation matrix object initialized with identity matrix.
  3849. *
  3850. * The matrix can synchronize a canvas context by supplying the context
  3851. * as an argument, or later apply current absolute transform to an
  3852. * existing context.
  3853. *
  3854. * All values are handled as floating point values.
  3855. *
  3856. * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix
  3857. * @prop {number} a - scale x
  3858. * @prop {number} b - shear y
  3859. * @prop {number} c - shear x
  3860. * @prop {number} d - scale y
  3861. * @prop {number} e - translate x
  3862. * @prop {number} f - translate y
  3863. * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context
  3864. * @constructor
  3865. */
  3866. const Matrix = (function () {
  3867. var _cos = Math.cos;
  3868. var _sin = Math.sin;
  3869. var _tan = Math.tan;
  3870. var _rnd = Math.round;
  3871. function reset() {
  3872. this.props[0] = 1;
  3873. this.props[1] = 0;
  3874. this.props[2] = 0;
  3875. this.props[3] = 0;
  3876. this.props[4] = 0;
  3877. this.props[5] = 1;
  3878. this.props[6] = 0;
  3879. this.props[7] = 0;
  3880. this.props[8] = 0;
  3881. this.props[9] = 0;
  3882. this.props[10] = 1;
  3883. this.props[11] = 0;
  3884. this.props[12] = 0;
  3885. this.props[13] = 0;
  3886. this.props[14] = 0;
  3887. this.props[15] = 1;
  3888. return this;
  3889. }
  3890. function rotate(angle) {
  3891. if (angle === 0) {
  3892. return this;
  3893. }
  3894. var mCos = _cos(angle);
  3895. var mSin = _sin(angle);
  3896. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3897. }
  3898. function rotateX(angle) {
  3899. if (angle === 0) {
  3900. return this;
  3901. }
  3902. var mCos = _cos(angle);
  3903. var mSin = _sin(angle);
  3904. return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1);
  3905. }
  3906. function rotateY(angle) {
  3907. if (angle === 0) {
  3908. return this;
  3909. }
  3910. var mCos = _cos(angle);
  3911. var mSin = _sin(angle);
  3912. return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1);
  3913. }
  3914. function rotateZ(angle) {
  3915. if (angle === 0) {
  3916. return this;
  3917. }
  3918. var mCos = _cos(angle);
  3919. var mSin = _sin(angle);
  3920. return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3921. }
  3922. function shear(sx, sy) {
  3923. return this._t(1, sy, sx, 1, 0, 0);
  3924. }
  3925. function skew(ax, ay) {
  3926. return this.shear(_tan(ax), _tan(ay));
  3927. }
  3928. function skewFromAxis(ax, angle) {
  3929. var mCos = _cos(angle);
  3930. var mSin = _sin(angle);
  3931. return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3932. ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  3933. ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3934. // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0);
  3935. }
  3936. function scale(sx, sy, sz) {
  3937. if (!sz && sz !== 0) {
  3938. sz = 1;
  3939. }
  3940. if (sx === 1 && sy === 1 && sz === 1) {
  3941. return this;
  3942. }
  3943. return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1);
  3944. }
  3945. function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {
  3946. this.props[0] = a;
  3947. this.props[1] = b;
  3948. this.props[2] = c;
  3949. this.props[3] = d;
  3950. this.props[4] = e;
  3951. this.props[5] = f;
  3952. this.props[6] = g;
  3953. this.props[7] = h;
  3954. this.props[8] = i;
  3955. this.props[9] = j;
  3956. this.props[10] = k;
  3957. this.props[11] = l;
  3958. this.props[12] = m;
  3959. this.props[13] = n;
  3960. this.props[14] = o;
  3961. this.props[15] = p;
  3962. return this;
  3963. }
  3964. function translate(tx, ty, tz) {
  3965. tz = tz || 0;
  3966. if (tx !== 0 || ty !== 0 || tz !== 0) {
  3967. return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1);
  3968. }
  3969. return this;
  3970. }
  3971. function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) {
  3972. var _p = this.props;
  3973. 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) {
  3974. // NOTE: commenting this condition because TurboFan deoptimizes code when present
  3975. // if(m2 !== 0 || n2 !== 0 || o2 !== 0){
  3976. _p[12] = _p[12] * a2 + _p[15] * m2;
  3977. _p[13] = _p[13] * f2 + _p[15] * n2;
  3978. _p[14] = _p[14] * k2 + _p[15] * o2;
  3979. _p[15] *= p2;
  3980. // }
  3981. this._identityCalculated = false;
  3982. return this;
  3983. }
  3984. var a1 = _p[0];
  3985. var b1 = _p[1];
  3986. var c1 = _p[2];
  3987. var d1 = _p[3];
  3988. var e1 = _p[4];
  3989. var f1 = _p[5];
  3990. var g1 = _p[6];
  3991. var h1 = _p[7];
  3992. var i1 = _p[8];
  3993. var j1 = _p[9];
  3994. var k1 = _p[10];
  3995. var l1 = _p[11];
  3996. var m1 = _p[12];
  3997. var n1 = _p[13];
  3998. var o1 = _p[14];
  3999. var p1 = _p[15];
  4000. /* matrix order (canvas compatible):
  4001. * ace
  4002. * bdf
  4003. * 001
  4004. */
  4005. _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2;
  4006. _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2;
  4007. _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2;
  4008. _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2;
  4009. _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2;
  4010. _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2;
  4011. _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2;
  4012. _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2;
  4013. _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2;
  4014. _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2;
  4015. _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2;
  4016. _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2;
  4017. _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2;
  4018. _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2;
  4019. _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2;
  4020. _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2;
  4021. this._identityCalculated = false;
  4022. return this;
  4023. }
  4024. function multiply(matrix) {
  4025. var matrixProps = matrix.props;
  4026. return this.transform(
  4027. matrixProps[0],
  4028. matrixProps[1],
  4029. matrixProps[2],
  4030. matrixProps[3],
  4031. matrixProps[4],
  4032. matrixProps[5],
  4033. matrixProps[6],
  4034. matrixProps[7],
  4035. matrixProps[8],
  4036. matrixProps[9],
  4037. matrixProps[10],
  4038. matrixProps[11],
  4039. matrixProps[12],
  4040. matrixProps[13],
  4041. matrixProps[14],
  4042. matrixProps[15]
  4043. );
  4044. }
  4045. function isIdentity() {
  4046. if (!this._identityCalculated) {
  4047. 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);
  4048. this._identityCalculated = true;
  4049. }
  4050. return this._identity;
  4051. }
  4052. function equals(matr) {
  4053. var i = 0;
  4054. while (i < 16) {
  4055. if (matr.props[i] !== this.props[i]) {
  4056. return false;
  4057. }
  4058. i += 1;
  4059. }
  4060. return true;
  4061. }
  4062. function clone(matr) {
  4063. var i;
  4064. for (i = 0; i < 16; i += 1) {
  4065. matr.props[i] = this.props[i];
  4066. }
  4067. return matr;
  4068. }
  4069. function cloneFromProps(props) {
  4070. var i;
  4071. for (i = 0; i < 16; i += 1) {
  4072. this.props[i] = props[i];
  4073. }
  4074. }
  4075. function applyToPoint(x, y, z) {
  4076. return {
  4077. x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4078. y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4079. z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4080. };
  4081. /* return {
  4082. x: x * me.a + y * me.c + me.e,
  4083. y: x * me.b + y * me.d + me.f
  4084. }; */
  4085. }
  4086. function applyToX(x, y, z) {
  4087. return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12];
  4088. }
  4089. function applyToY(x, y, z) {
  4090. return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13];
  4091. }
  4092. function applyToZ(x, y, z) {
  4093. return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14];
  4094. }
  4095. function getInverseMatrix() {
  4096. var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4];
  4097. var a = this.props[5] / determinant;
  4098. var b = -this.props[1] / determinant;
  4099. var c = -this.props[4] / determinant;
  4100. var d = this.props[0] / determinant;
  4101. var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant;
  4102. var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant;
  4103. var inverseMatrix = new Matrix();
  4104. inverseMatrix.props[0] = a;
  4105. inverseMatrix.props[1] = b;
  4106. inverseMatrix.props[4] = c;
  4107. inverseMatrix.props[5] = d;
  4108. inverseMatrix.props[12] = e;
  4109. inverseMatrix.props[13] = f;
  4110. return inverseMatrix;
  4111. }
  4112. function inversePoint(pt) {
  4113. var inverseMatrix = this.getInverseMatrix();
  4114. return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0);
  4115. }
  4116. function inversePoints(pts) {
  4117. var i;
  4118. var len = pts.length;
  4119. var retPts = [];
  4120. for (i = 0; i < len; i += 1) {
  4121. retPts[i] = inversePoint(pts[i]);
  4122. }
  4123. return retPts;
  4124. }
  4125. function applyToTriplePoints(pt1, pt2, pt3) {
  4126. var arr = createTypedArray('float32', 6);
  4127. if (this.isIdentity()) {
  4128. arr[0] = pt1[0];
  4129. arr[1] = pt1[1];
  4130. arr[2] = pt2[0];
  4131. arr[3] = pt2[1];
  4132. arr[4] = pt3[0];
  4133. arr[5] = pt3[1];
  4134. } else {
  4135. var p0 = this.props[0];
  4136. var p1 = this.props[1];
  4137. var p4 = this.props[4];
  4138. var p5 = this.props[5];
  4139. var p12 = this.props[12];
  4140. var p13 = this.props[13];
  4141. arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12;
  4142. arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13;
  4143. arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12;
  4144. arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13;
  4145. arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12;
  4146. arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13;
  4147. }
  4148. return arr;
  4149. }
  4150. function applyToPointArray(x, y, z) {
  4151. var arr;
  4152. if (this.isIdentity()) {
  4153. arr = [x, y, z];
  4154. } else {
  4155. arr = [
  4156. x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12],
  4157. x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13],
  4158. x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14],
  4159. ];
  4160. }
  4161. return arr;
  4162. }
  4163. function applyToPointStringified(x, y) {
  4164. if (this.isIdentity()) {
  4165. return x + ',' + y;
  4166. }
  4167. var _p = this.props;
  4168. 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;
  4169. }
  4170. function toCSS() {
  4171. // 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.
  4172. /* if(this.isIdentity()) {
  4173. return '';
  4174. } */
  4175. var i = 0;
  4176. var props = this.props;
  4177. var cssValue = 'matrix3d(';
  4178. var v = 10000;
  4179. while (i < 16) {
  4180. cssValue += _rnd(props[i] * v) / v;
  4181. cssValue += i === 15 ? ')' : ',';
  4182. i += 1;
  4183. }
  4184. return cssValue;
  4185. }
  4186. function roundMatrixProperty(val) {
  4187. var v = 10000;
  4188. if ((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
  4189. return _rnd(val * v) / v;
  4190. }
  4191. return val;
  4192. }
  4193. function to2dCSS() {
  4194. // 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.
  4195. /* if(this.isIdentity()) {
  4196. return '';
  4197. } */
  4198. var props = this.props;
  4199. var _a = roundMatrixProperty(props[0]);
  4200. var _b = roundMatrixProperty(props[1]);
  4201. var _c = roundMatrixProperty(props[4]);
  4202. var _d = roundMatrixProperty(props[5]);
  4203. var _e = roundMatrixProperty(props[12]);
  4204. var _f = roundMatrixProperty(props[13]);
  4205. return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')';
  4206. }
  4207. return function () {
  4208. this.reset = reset;
  4209. this.rotate = rotate;
  4210. this.rotateX = rotateX;
  4211. this.rotateY = rotateY;
  4212. this.rotateZ = rotateZ;
  4213. this.skew = skew;
  4214. this.skewFromAxis = skewFromAxis;
  4215. this.shear = shear;
  4216. this.scale = scale;
  4217. this.setTransform = setTransform;
  4218. this.translate = translate;
  4219. this.transform = transform;
  4220. this.multiply = multiply;
  4221. this.applyToPoint = applyToPoint;
  4222. this.applyToX = applyToX;
  4223. this.applyToY = applyToY;
  4224. this.applyToZ = applyToZ;
  4225. this.applyToPointArray = applyToPointArray;
  4226. this.applyToTriplePoints = applyToTriplePoints;
  4227. this.applyToPointStringified = applyToPointStringified;
  4228. this.toCSS = toCSS;
  4229. this.to2dCSS = to2dCSS;
  4230. this.clone = clone;
  4231. this.cloneFromProps = cloneFromProps;
  4232. this.equals = equals;
  4233. this.inversePoints = inversePoints;
  4234. this.inversePoint = inversePoint;
  4235. this.getInverseMatrix = getInverseMatrix;
  4236. this._t = this.transform;
  4237. this.isIdentity = isIdentity;
  4238. this._identity = true;
  4239. this._identityCalculated = false;
  4240. this.props = createTypedArray('float32', 16);
  4241. this.reset();
  4242. };
  4243. }());
  4244. const lottie = {};
  4245. var standalone = '__[STANDALONE]__';
  4246. var animationData = '__[ANIMATIONDATA]__';
  4247. var renderer = '';
  4248. function setLocation(href) {
  4249. setLocationHref(href);
  4250. }
  4251. function searchAnimations() {
  4252. if (standalone === true) {
  4253. animationManager.searchAnimations(animationData, standalone, renderer);
  4254. } else {
  4255. animationManager.searchAnimations();
  4256. }
  4257. }
  4258. function setSubframeRendering(flag) {
  4259. setSubframeEnabled(flag);
  4260. }
  4261. function setPrefix(prefix) {
  4262. setIdPrefix(prefix);
  4263. }
  4264. function loadAnimation(params) {
  4265. if (standalone === true) {
  4266. params.animationData = JSON.parse(animationData);
  4267. }
  4268. return animationManager.loadAnimation(params);
  4269. }
  4270. function setQuality(value) {
  4271. if (typeof value === 'string') {
  4272. switch (value) {
  4273. case 'high':
  4274. setDefaultCurveSegments(200);
  4275. break;
  4276. default:
  4277. case 'medium':
  4278. setDefaultCurveSegments(50);
  4279. break;
  4280. case 'low':
  4281. setDefaultCurveSegments(10);
  4282. break;
  4283. }
  4284. } else if (!isNaN(value) && value > 1) {
  4285. setDefaultCurveSegments(value);
  4286. }
  4287. if (getDefaultCurveSegments() >= 50) {
  4288. roundValues(false);
  4289. } else {
  4290. roundValues(true);
  4291. }
  4292. }
  4293. function inBrowser() {
  4294. return typeof navigator !== 'undefined';
  4295. }
  4296. function installPlugin(type, plugin) {
  4297. if (type === 'expressions') {
  4298. setExpressionsPlugin(plugin);
  4299. }
  4300. }
  4301. function getFactory(name) {
  4302. switch (name) {
  4303. case 'propertyFactory':
  4304. return PropertyFactory;
  4305. case 'shapePropertyFactory':
  4306. return ShapePropertyFactory;
  4307. case 'matrix':
  4308. return Matrix;
  4309. default:
  4310. return null;
  4311. }
  4312. }
  4313. lottie.play = animationManager.play;
  4314. lottie.pause = animationManager.pause;
  4315. lottie.setLocationHref = setLocation;
  4316. lottie.togglePause = animationManager.togglePause;
  4317. lottie.setSpeed = animationManager.setSpeed;
  4318. lottie.setDirection = animationManager.setDirection;
  4319. lottie.stop = animationManager.stop;
  4320. lottie.searchAnimations = searchAnimations;
  4321. lottie.registerAnimation = animationManager.registerAnimation;
  4322. lottie.loadAnimation = loadAnimation;
  4323. lottie.setSubframeRendering = setSubframeRendering;
  4324. lottie.resize = animationManager.resize;
  4325. // lottie.start = start;
  4326. lottie.goToAndStop = animationManager.goToAndStop;
  4327. lottie.destroy = animationManager.destroy;
  4328. lottie.setQuality = setQuality;
  4329. lottie.inBrowser = inBrowser;
  4330. lottie.installPlugin = installPlugin;
  4331. lottie.freeze = animationManager.freeze;
  4332. lottie.unfreeze = animationManager.unfreeze;
  4333. lottie.setVolume = animationManager.setVolume;
  4334. lottie.mute = animationManager.mute;
  4335. lottie.unmute = animationManager.unmute;
  4336. lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
  4337. lottie.useWebWorker = setWebWorker;
  4338. lottie.setIDPrefix = setPrefix;
  4339. lottie.__getFactory = getFactory;
  4340. lottie.version = '[[BM_VERSION]]';
  4341. function checkReady() {
  4342. if (document.readyState === 'complete') {
  4343. clearInterval(readyStateCheckInterval);
  4344. searchAnimations();
  4345. }
  4346. }
  4347. function getQueryVariable(variable) {
  4348. var vars = queryString.split('&');
  4349. for (var i = 0; i < vars.length; i += 1) {
  4350. var pair = vars[i].split('=');
  4351. if (decodeURIComponent(pair[0]) == variable) { // eslint-disable-line eqeqeq
  4352. return decodeURIComponent(pair[1]);
  4353. }
  4354. }
  4355. return null;
  4356. }
  4357. var queryString = '';
  4358. if (standalone) {
  4359. var scripts = document.getElementsByTagName('script');
  4360. var index = scripts.length - 1;
  4361. var myScript = scripts[index] || {
  4362. src: '',
  4363. };
  4364. queryString = myScript.src ? myScript.src.replace(/^[^\?]+\??/, '') : ''; // eslint-disable-line no-useless-escape
  4365. renderer = getQueryVariable('renderer');
  4366. }
  4367. var readyStateCheckInterval = setInterval(checkReady, 100);
  4368. // this adds bodymovin to the window object for backwards compatibility
  4369. try {
  4370. if (!(typeof exports === 'object' && typeof module !== 'undefined')
  4371. && !(typeof define === 'function' && define.amd) // eslint-disable-line no-undef
  4372. ) {
  4373. window.bodymovin = lottie;
  4374. }
  4375. } catch (err) {
  4376. //
  4377. }
  4378. const ShapeModifiers = (function () {
  4379. var ob = {};
  4380. var modifiers = {};
  4381. ob.registerModifier = registerModifier;
  4382. ob.getModifier = getModifier;
  4383. function registerModifier(nm, factory) {
  4384. if (!modifiers[nm]) {
  4385. modifiers[nm] = factory;
  4386. }
  4387. }
  4388. function getModifier(nm, elem, data) {
  4389. return new modifiers[nm](elem, data);
  4390. }
  4391. return ob;
  4392. }());
  4393. function ShapeModifier() {}
  4394. ShapeModifier.prototype.initModifierProperties = function () {};
  4395. ShapeModifier.prototype.addShapeToModifier = function () {};
  4396. ShapeModifier.prototype.addShape = function (data) {
  4397. if (!this.closed) {
  4398. // 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.
  4399. data.sh.container.addDynamicProperty(data.sh);
  4400. var shapeData = { shape: data.sh, data: data, localShapeCollection: shapeCollectionPool.newShapeCollection() };
  4401. this.shapes.push(shapeData);
  4402. this.addShapeToModifier(shapeData);
  4403. if (this._isAnimated) {
  4404. data.setAsAnimated();
  4405. }
  4406. }
  4407. };
  4408. ShapeModifier.prototype.init = function (elem, data) {
  4409. this.shapes = [];
  4410. this.elem = elem;
  4411. this.initDynamicPropertyContainer(elem);
  4412. this.initModifierProperties(elem, data);
  4413. this.frameId = initialDefaultFrame;
  4414. this.closed = false;
  4415. this.k = false;
  4416. if (this.dynamicProperties.length) {
  4417. this.k = true;
  4418. } else {
  4419. this.getValue(true);
  4420. }
  4421. };
  4422. ShapeModifier.prototype.processKeys = function () {
  4423. if (this.elem.globalData.frameId === this.frameId) {
  4424. return;
  4425. }
  4426. this.frameId = this.elem.globalData.frameId;
  4427. this.iterateDynamicProperties();
  4428. };
  4429. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  4430. function TrimModifier() {
  4431. }
  4432. extendPrototype([ShapeModifier], TrimModifier);
  4433. TrimModifier.prototype.initModifierProperties = function (elem, data) {
  4434. this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this);
  4435. this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this);
  4436. this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this);
  4437. this.sValue = 0;
  4438. this.eValue = 0;
  4439. this.getValue = this.processKeys;
  4440. this.m = data.m;
  4441. this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length;
  4442. };
  4443. TrimModifier.prototype.addShapeToModifier = function (shapeData) {
  4444. shapeData.pathsData = [];
  4445. };
  4446. TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) {
  4447. var segments = [];
  4448. if (e <= 1) {
  4449. segments.push({
  4450. s: s,
  4451. e: e,
  4452. });
  4453. } else if (s >= 1) {
  4454. segments.push({
  4455. s: s - 1,
  4456. e: e - 1,
  4457. });
  4458. } else {
  4459. segments.push({
  4460. s: s,
  4461. e: 1,
  4462. });
  4463. segments.push({
  4464. s: 0,
  4465. e: e - 1,
  4466. });
  4467. }
  4468. var shapeSegments = [];
  4469. var i;
  4470. var len = segments.length;
  4471. var segmentOb;
  4472. for (i = 0; i < len; i += 1) {
  4473. segmentOb = segments[i];
  4474. if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) {
  4475. var shapeS;
  4476. var shapeE;
  4477. if (segmentOb.s * totalModifierLength <= addedLength) {
  4478. shapeS = 0;
  4479. } else {
  4480. shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength;
  4481. }
  4482. if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) {
  4483. shapeE = 1;
  4484. } else {
  4485. shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength);
  4486. }
  4487. shapeSegments.push([shapeS, shapeE]);
  4488. }
  4489. }
  4490. if (!shapeSegments.length) {
  4491. shapeSegments.push([0, 0]);
  4492. }
  4493. return shapeSegments;
  4494. };
  4495. TrimModifier.prototype.releasePathsData = function (pathsData) {
  4496. var i;
  4497. var len = pathsData.length;
  4498. for (i = 0; i < len; i += 1) {
  4499. segmentsLengthPool.release(pathsData[i]);
  4500. }
  4501. pathsData.length = 0;
  4502. return pathsData;
  4503. };
  4504. TrimModifier.prototype.processShapes = function (_isFirstFrame) {
  4505. var s;
  4506. var e;
  4507. if (this._mdf || _isFirstFrame) {
  4508. var o = (this.o.v % 360) / 360;
  4509. if (o < 0) {
  4510. o += 1;
  4511. }
  4512. if (this.s.v > 1) {
  4513. s = 1 + o;
  4514. } else if (this.s.v < 0) {
  4515. s = 0 + o;
  4516. } else {
  4517. s = this.s.v + o;
  4518. }
  4519. if (this.e.v > 1) {
  4520. e = 1 + o;
  4521. } else if (this.e.v < 0) {
  4522. e = 0 + o;
  4523. } else {
  4524. e = this.e.v + o;
  4525. }
  4526. if (s > e) {
  4527. var _s = s;
  4528. s = e;
  4529. e = _s;
  4530. }
  4531. s = Math.round(s * 10000) * 0.0001;
  4532. e = Math.round(e * 10000) * 0.0001;
  4533. this.sValue = s;
  4534. this.eValue = e;
  4535. } else {
  4536. s = this.sValue;
  4537. e = this.eValue;
  4538. }
  4539. var shapePaths;
  4540. var i;
  4541. var len = this.shapes.length;
  4542. var j;
  4543. var jLen;
  4544. var pathsData;
  4545. var pathData;
  4546. var totalShapeLength;
  4547. var totalModifierLength = 0;
  4548. if (e === s) {
  4549. for (i = 0; i < len; i += 1) {
  4550. this.shapes[i].localShapeCollection.releaseShapes();
  4551. this.shapes[i].shape._mdf = true;
  4552. this.shapes[i].shape.paths = this.shapes[i].localShapeCollection;
  4553. if (this._mdf) {
  4554. this.shapes[i].pathsData.length = 0;
  4555. }
  4556. }
  4557. } else if (!((e === 1 && s === 0) || (e === 0 && s === 1))) {
  4558. var segments = [];
  4559. var shapeData;
  4560. var localShapeCollection;
  4561. for (i = 0; i < len; i += 1) {
  4562. shapeData = this.shapes[i];
  4563. // if shape hasn't changed and trim properties haven't changed, cached previous path can be used
  4564. if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) {
  4565. shapeData.shape.paths = shapeData.localShapeCollection;
  4566. } else {
  4567. shapePaths = shapeData.shape.paths;
  4568. jLen = shapePaths._length;
  4569. totalShapeLength = 0;
  4570. if (!shapeData.shape._mdf && shapeData.pathsData.length) {
  4571. totalShapeLength = shapeData.totalShapeLength;
  4572. } else {
  4573. pathsData = this.releasePathsData(shapeData.pathsData);
  4574. for (j = 0; j < jLen; j += 1) {
  4575. pathData = bez.getSegmentsLength(shapePaths.shapes[j]);
  4576. pathsData.push(pathData);
  4577. totalShapeLength += pathData.totalLength;
  4578. }
  4579. shapeData.totalShapeLength = totalShapeLength;
  4580. shapeData.pathsData = pathsData;
  4581. }
  4582. totalModifierLength += totalShapeLength;
  4583. shapeData.shape._mdf = true;
  4584. }
  4585. }
  4586. var shapeS = s;
  4587. var shapeE = e;
  4588. var addedLength = 0;
  4589. var edges;
  4590. for (i = len - 1; i >= 0; i -= 1) {
  4591. shapeData = this.shapes[i];
  4592. if (shapeData.shape._mdf) {
  4593. localShapeCollection = shapeData.localShapeCollection;
  4594. localShapeCollection.releaseShapes();
  4595. // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group
  4596. if (this.m === 2 && len > 1) {
  4597. edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength);
  4598. addedLength += shapeData.totalShapeLength;
  4599. } else {
  4600. edges = [[shapeS, shapeE]];
  4601. }
  4602. jLen = edges.length;
  4603. for (j = 0; j < jLen; j += 1) {
  4604. shapeS = edges[j][0];
  4605. shapeE = edges[j][1];
  4606. segments.length = 0;
  4607. if (shapeE <= 1) {
  4608. segments.push({
  4609. s: shapeData.totalShapeLength * shapeS,
  4610. e: shapeData.totalShapeLength * shapeE,
  4611. });
  4612. } else if (shapeS >= 1) {
  4613. segments.push({
  4614. s: shapeData.totalShapeLength * (shapeS - 1),
  4615. e: shapeData.totalShapeLength * (shapeE - 1),
  4616. });
  4617. } else {
  4618. segments.push({
  4619. s: shapeData.totalShapeLength * shapeS,
  4620. e: shapeData.totalShapeLength,
  4621. });
  4622. segments.push({
  4623. s: 0,
  4624. e: shapeData.totalShapeLength * (shapeE - 1),
  4625. });
  4626. }
  4627. var newShapesData = this.addShapes(shapeData, segments[0]);
  4628. if (segments[0].s !== segments[0].e) {
  4629. if (segments.length > 1) {
  4630. var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1];
  4631. if (lastShapeInCollection.c) {
  4632. var lastShape = newShapesData.pop();
  4633. this.addPaths(newShapesData, localShapeCollection);
  4634. newShapesData = this.addShapes(shapeData, segments[1], lastShape);
  4635. } else {
  4636. this.addPaths(newShapesData, localShapeCollection);
  4637. newShapesData = this.addShapes(shapeData, segments[1]);
  4638. }
  4639. }
  4640. this.addPaths(newShapesData, localShapeCollection);
  4641. }
  4642. }
  4643. shapeData.shape.paths = localShapeCollection;
  4644. }
  4645. }
  4646. } else if (this._mdf) {
  4647. for (i = 0; i < len; i += 1) {
  4648. // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween.
  4649. // Don't remove this even if it's losing cached info.
  4650. this.shapes[i].pathsData.length = 0;
  4651. this.shapes[i].shape._mdf = true;
  4652. }
  4653. }
  4654. };
  4655. TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) {
  4656. var i;
  4657. var len = newPaths.length;
  4658. for (i = 0; i < len; i += 1) {
  4659. localShapeCollection.addShape(newPaths[i]);
  4660. }
  4661. };
  4662. TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) {
  4663. shapePath.setXYAt(pt2[0], pt2[1], 'o', pos);
  4664. shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1);
  4665. if (newShape) {
  4666. shapePath.setXYAt(pt1[0], pt1[1], 'v', pos);
  4667. }
  4668. shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1);
  4669. };
  4670. TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) {
  4671. shapePath.setXYAt(points[1], points[5], 'o', pos);
  4672. shapePath.setXYAt(points[2], points[6], 'i', pos + 1);
  4673. if (newShape) {
  4674. shapePath.setXYAt(points[0], points[4], 'v', pos);
  4675. }
  4676. shapePath.setXYAt(points[3], points[7], 'v', pos + 1);
  4677. };
  4678. TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) {
  4679. var pathsData = shapeData.pathsData;
  4680. var shapePaths = shapeData.shape.paths.shapes;
  4681. var i;
  4682. var len = shapeData.shape.paths._length;
  4683. var j;
  4684. var jLen;
  4685. var addedLength = 0;
  4686. var currentLengthData;
  4687. var segmentCount;
  4688. var lengths;
  4689. var segment;
  4690. var shapes = [];
  4691. var initPos;
  4692. var newShape = true;
  4693. if (!shapePath) {
  4694. shapePath = shapePool.newElement();
  4695. segmentCount = 0;
  4696. initPos = 0;
  4697. } else {
  4698. segmentCount = shapePath._length;
  4699. initPos = shapePath._length;
  4700. }
  4701. shapes.push(shapePath);
  4702. for (i = 0; i < len; i += 1) {
  4703. lengths = pathsData[i].lengths;
  4704. shapePath.c = shapePaths[i].c;
  4705. jLen = shapePaths[i].c ? lengths.length : lengths.length + 1;
  4706. for (j = 1; j < jLen; j += 1) {
  4707. currentLengthData = lengths[j - 1];
  4708. if (addedLength + currentLengthData.addedLength < shapeSegment.s) {
  4709. addedLength += currentLengthData.addedLength;
  4710. shapePath.c = false;
  4711. } else if (addedLength > shapeSegment.e) {
  4712. shapePath.c = false;
  4713. break;
  4714. } else {
  4715. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) {
  4716. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape);
  4717. newShape = false;
  4718. } else {
  4719. 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]);
  4720. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4721. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4722. newShape = false;
  4723. shapePath.c = false;
  4724. }
  4725. addedLength += currentLengthData.addedLength;
  4726. segmentCount += 1;
  4727. }
  4728. }
  4729. if (shapePaths[i].c && lengths.length) {
  4730. currentLengthData = lengths[j - 1];
  4731. if (addedLength <= shapeSegment.e) {
  4732. var segmentLength = lengths[j - 1].addedLength;
  4733. if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) {
  4734. this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape);
  4735. newShape = false;
  4736. } else {
  4737. 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]);
  4738. this.addSegmentFromArray(segment, shapePath, segmentCount, newShape);
  4739. // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape);
  4740. newShape = false;
  4741. shapePath.c = false;
  4742. }
  4743. } else {
  4744. shapePath.c = false;
  4745. }
  4746. addedLength += currentLengthData.addedLength;
  4747. segmentCount += 1;
  4748. }
  4749. if (shapePath._length) {
  4750. shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos);
  4751. shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1);
  4752. }
  4753. if (addedLength > shapeSegment.e) {
  4754. break;
  4755. }
  4756. if (i < len - 1) {
  4757. shapePath = shapePool.newElement();
  4758. newShape = true;
  4759. shapes.push(shapePath);
  4760. segmentCount = 0;
  4761. }
  4762. }
  4763. return shapes;
  4764. };
  4765. function PuckerAndBloatModifier() {}
  4766. extendPrototype([ShapeModifier], PuckerAndBloatModifier);
  4767. PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) {
  4768. this.getValue = this.processKeys;
  4769. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  4770. this._isAnimated = !!this.amount.effectsSequence.length;
  4771. };
  4772. PuckerAndBloatModifier.prototype.processPath = function (path, amount) {
  4773. var percent = amount / 100;
  4774. var centerPoint = [0, 0];
  4775. var pathLength = path._length;
  4776. var i = 0;
  4777. for (i = 0; i < pathLength; i += 1) {
  4778. centerPoint[0] += path.v[i][0];
  4779. centerPoint[1] += path.v[i][1];
  4780. }
  4781. centerPoint[0] /= pathLength;
  4782. centerPoint[1] /= pathLength;
  4783. var clonedPath = shapePool.newElement();
  4784. clonedPath.c = path.c;
  4785. var vX;
  4786. var vY;
  4787. var oX;
  4788. var oY;
  4789. var iX;
  4790. var iY;
  4791. for (i = 0; i < pathLength; i += 1) {
  4792. vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent;
  4793. vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent;
  4794. oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent;
  4795. oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent;
  4796. iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent;
  4797. iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent;
  4798. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i);
  4799. }
  4800. return clonedPath;
  4801. };
  4802. PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) {
  4803. var shapePaths;
  4804. var i;
  4805. var len = this.shapes.length;
  4806. var j;
  4807. var jLen;
  4808. var amount = this.amount.v;
  4809. if (amount !== 0) {
  4810. var shapeData;
  4811. var localShapeCollection;
  4812. for (i = 0; i < len; i += 1) {
  4813. shapeData = this.shapes[i];
  4814. localShapeCollection = shapeData.localShapeCollection;
  4815. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  4816. localShapeCollection.releaseShapes();
  4817. shapeData.shape._mdf = true;
  4818. shapePaths = shapeData.shape.paths.shapes;
  4819. jLen = shapeData.shape.paths._length;
  4820. for (j = 0; j < jLen; j += 1) {
  4821. localShapeCollection.addShape(this.processPath(shapePaths[j], amount));
  4822. }
  4823. }
  4824. shapeData.shape.paths = shapeData.localShapeCollection;
  4825. }
  4826. }
  4827. if (!this.dynamicProperties.length) {
  4828. this._mdf = false;
  4829. }
  4830. };
  4831. const TransformPropertyFactory = (function () {
  4832. var defaultVector = [0, 0];
  4833. function applyToMatrix(mat) {
  4834. var _mdf = this._mdf;
  4835. this.iterateDynamicProperties();
  4836. this._mdf = this._mdf || _mdf;
  4837. if (this.a) {
  4838. mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4839. }
  4840. if (this.s) {
  4841. mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4842. }
  4843. if (this.sk) {
  4844. mat.skewFromAxis(-this.sk.v, this.sa.v);
  4845. }
  4846. if (this.r) {
  4847. mat.rotate(-this.r.v);
  4848. } else {
  4849. mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4850. .rotateY(this.or.v[1])
  4851. .rotateX(this.or.v[0]);
  4852. }
  4853. if (this.data.p.s) {
  4854. if (this.data.p.z) {
  4855. mat.translate(this.px.v, this.py.v, -this.pz.v);
  4856. } else {
  4857. mat.translate(this.px.v, this.py.v, 0);
  4858. }
  4859. } else {
  4860. mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4861. }
  4862. }
  4863. function processKeys(forceRender) {
  4864. if (this.elem.globalData.frameId === this.frameId) {
  4865. return;
  4866. }
  4867. if (this._isDirty) {
  4868. this.precalculateMatrix();
  4869. this._isDirty = false;
  4870. }
  4871. this.iterateDynamicProperties();
  4872. if (this._mdf || forceRender) {
  4873. var frameRate;
  4874. this.v.cloneFromProps(this.pre.props);
  4875. if (this.appliedTransformations < 1) {
  4876. this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4877. }
  4878. if (this.appliedTransformations < 2) {
  4879. this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4880. }
  4881. if (this.sk && this.appliedTransformations < 3) {
  4882. this.v.skewFromAxis(-this.sk.v, this.sa.v);
  4883. }
  4884. if (this.r && this.appliedTransformations < 4) {
  4885. this.v.rotate(-this.r.v);
  4886. } else if (!this.r && this.appliedTransformations < 4) {
  4887. this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4888. .rotateY(this.or.v[1])
  4889. .rotateX(this.or.v[0]);
  4890. }
  4891. if (this.autoOriented) {
  4892. var v1;
  4893. var v2;
  4894. frameRate = this.elem.globalData.frameRate;
  4895. if (this.p && this.p.keyframes && this.p.getValueAtTime) {
  4896. if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) {
  4897. v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0);
  4898. v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0);
  4899. } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) {
  4900. v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0);
  4901. v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0);
  4902. } else {
  4903. v1 = this.p.pv;
  4904. v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime);
  4905. }
  4906. } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) {
  4907. v1 = [];
  4908. v2 = [];
  4909. var px = this.px;
  4910. var py = this.py;
  4911. if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) {
  4912. v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0);
  4913. v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0);
  4914. v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate, 0);
  4915. v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate, 0);
  4916. } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) {
  4917. v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate), 0);
  4918. v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate), 0);
  4919. v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4920. v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0);
  4921. } else {
  4922. v1 = [px.pv, py.pv];
  4923. v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime);
  4924. v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime);
  4925. }
  4926. } else {
  4927. v2 = defaultVector;
  4928. v1 = v2;
  4929. }
  4930. this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0]));
  4931. }
  4932. if (this.data.p && this.data.p.s) {
  4933. if (this.data.p.z) {
  4934. this.v.translate(this.px.v, this.py.v, -this.pz.v);
  4935. } else {
  4936. this.v.translate(this.px.v, this.py.v, 0);
  4937. }
  4938. } else {
  4939. this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]);
  4940. }
  4941. }
  4942. this.frameId = this.elem.globalData.frameId;
  4943. }
  4944. function precalculateMatrix() {
  4945. this.appliedTransformations = 0;
  4946. this.pre.reset();
  4947. if (!this.a.effectsSequence.length) {
  4948. this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]);
  4949. this.appliedTransformations = 1;
  4950. } else {
  4951. return;
  4952. }
  4953. if (!this.s.effectsSequence.length) {
  4954. this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]);
  4955. this.appliedTransformations = 2;
  4956. } else {
  4957. return;
  4958. }
  4959. if (this.sk) {
  4960. if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) {
  4961. this.pre.skewFromAxis(-this.sk.v, this.sa.v);
  4962. this.appliedTransformations = 3;
  4963. } else {
  4964. return;
  4965. }
  4966. }
  4967. if (this.r) {
  4968. if (!this.r.effectsSequence.length) {
  4969. this.pre.rotate(-this.r.v);
  4970. this.appliedTransformations = 4;
  4971. }
  4972. } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) {
  4973. this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2])
  4974. .rotateY(this.or.v[1])
  4975. .rotateX(this.or.v[0]);
  4976. this.appliedTransformations = 4;
  4977. }
  4978. }
  4979. function autoOrient() {
  4980. //
  4981. // var prevP = this.getValueAtTime();
  4982. }
  4983. function addDynamicProperty(prop) {
  4984. this._addDynamicProperty(prop);
  4985. this.elem.addDynamicProperty(prop);
  4986. this._isDirty = true;
  4987. }
  4988. function TransformProperty(elem, data, container) {
  4989. this.elem = elem;
  4990. this.frameId = -1;
  4991. this.propType = 'transform';
  4992. this.data = data;
  4993. this.v = new Matrix();
  4994. // Precalculated matrix with non animated properties
  4995. this.pre = new Matrix();
  4996. this.appliedTransformations = 0;
  4997. this.initDynamicPropertyContainer(container || elem);
  4998. if (data.p && data.p.s) {
  4999. this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this);
  5000. this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this);
  5001. if (data.p.z) {
  5002. this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this);
  5003. }
  5004. } else {
  5005. this.p = PropertyFactory.getProp(elem, data.p || { k: [0, 0, 0] }, 1, 0, this);
  5006. }
  5007. if (data.rx) {
  5008. this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this);
  5009. this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this);
  5010. this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this);
  5011. if (data.or.k[0].ti) {
  5012. var i;
  5013. var len = data.or.k.length;
  5014. for (i = 0; i < len; i += 1) {
  5015. data.or.k[i].to = null;
  5016. data.or.k[i].ti = null;
  5017. }
  5018. }
  5019. this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this);
  5020. // sh Indicates it needs to be capped between -180 and 180
  5021. this.or.sh = true;
  5022. } else {
  5023. this.r = PropertyFactory.getProp(elem, data.r || { k: 0 }, 0, degToRads, this);
  5024. }
  5025. if (data.sk) {
  5026. this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this);
  5027. this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this);
  5028. }
  5029. this.a = PropertyFactory.getProp(elem, data.a || { k: [0, 0, 0] }, 1, 0, this);
  5030. this.s = PropertyFactory.getProp(elem, data.s || { k: [100, 100, 100] }, 1, 0.01, this);
  5031. // 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.
  5032. if (data.o) {
  5033. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem);
  5034. } else {
  5035. this.o = { _mdf: false, v: 1 };
  5036. }
  5037. this._isDirty = true;
  5038. if (!this.dynamicProperties.length) {
  5039. this.getValue(true);
  5040. }
  5041. }
  5042. TransformProperty.prototype = {
  5043. applyToMatrix: applyToMatrix,
  5044. getValue: processKeys,
  5045. precalculateMatrix: precalculateMatrix,
  5046. autoOrient: autoOrient,
  5047. };
  5048. extendPrototype([DynamicPropertyContainer], TransformProperty);
  5049. TransformProperty.prototype.addDynamicProperty = addDynamicProperty;
  5050. TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty;
  5051. function getTransformProperty(elem, data, container) {
  5052. return new TransformProperty(elem, data, container);
  5053. }
  5054. return {
  5055. getTransformProperty: getTransformProperty,
  5056. };
  5057. }());
  5058. function RepeaterModifier() {}
  5059. extendPrototype([ShapeModifier], RepeaterModifier);
  5060. RepeaterModifier.prototype.initModifierProperties = function (elem, data) {
  5061. this.getValue = this.processKeys;
  5062. this.c = PropertyFactory.getProp(elem, data.c, 0, null, this);
  5063. this.o = PropertyFactory.getProp(elem, data.o, 0, null, this);
  5064. this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this);
  5065. this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this);
  5066. this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this);
  5067. this.data = data;
  5068. if (!this.dynamicProperties.length) {
  5069. this.getValue(true);
  5070. }
  5071. this._isAnimated = !!this.dynamicProperties.length;
  5072. this.pMatrix = new Matrix();
  5073. this.rMatrix = new Matrix();
  5074. this.sMatrix = new Matrix();
  5075. this.tMatrix = new Matrix();
  5076. this.matrix = new Matrix();
  5077. };
  5078. RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) {
  5079. var dir = inv ? -1 : 1;
  5080. var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc);
  5081. var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc);
  5082. pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]);
  5083. rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5084. rMatrix.rotate(-transform.r.v * dir * perc);
  5085. rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5086. sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]);
  5087. sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY);
  5088. sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]);
  5089. };
  5090. RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) {
  5091. this.elem = elem;
  5092. this.arr = arr;
  5093. this.pos = pos;
  5094. this.elemsData = elemsData;
  5095. this._currentCopies = 0;
  5096. this._elements = [];
  5097. this._groups = [];
  5098. this.frameId = -1;
  5099. this.initDynamicPropertyContainer(elem);
  5100. this.initModifierProperties(elem, arr[pos]);
  5101. while (pos > 0) {
  5102. pos -= 1;
  5103. // this._elements.unshift(arr.splice(pos,1)[0]);
  5104. this._elements.unshift(arr[pos]);
  5105. }
  5106. if (this.dynamicProperties.length) {
  5107. this.k = true;
  5108. } else {
  5109. this.getValue(true);
  5110. }
  5111. };
  5112. RepeaterModifier.prototype.resetElements = function (elements) {
  5113. var i;
  5114. var len = elements.length;
  5115. for (i = 0; i < len; i += 1) {
  5116. elements[i]._processed = false;
  5117. if (elements[i].ty === 'gr') {
  5118. this.resetElements(elements[i].it);
  5119. }
  5120. }
  5121. };
  5122. RepeaterModifier.prototype.cloneElements = function (elements) {
  5123. var newElements = JSON.parse(JSON.stringify(elements));
  5124. this.resetElements(newElements);
  5125. return newElements;
  5126. };
  5127. RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) {
  5128. var i;
  5129. var len = elements.length;
  5130. for (i = 0; i < len; i += 1) {
  5131. elements[i]._render = renderFlag;
  5132. if (elements[i].ty === 'gr') {
  5133. this.changeGroupRender(elements[i].it, renderFlag);
  5134. }
  5135. }
  5136. };
  5137. RepeaterModifier.prototype.processShapes = function (_isFirstFrame) {
  5138. var items;
  5139. var itemsTransform;
  5140. var i;
  5141. var dir;
  5142. var cont;
  5143. var hasReloaded = false;
  5144. if (this._mdf || _isFirstFrame) {
  5145. var copies = Math.ceil(this.c.v);
  5146. if (this._groups.length < copies) {
  5147. while (this._groups.length < copies) {
  5148. var group = {
  5149. it: this.cloneElements(this._elements),
  5150. ty: 'gr',
  5151. };
  5152. group.it.push({
  5153. 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',
  5154. });
  5155. this.arr.splice(0, 0, group);
  5156. this._groups.splice(0, 0, group);
  5157. this._currentCopies += 1;
  5158. }
  5159. this.elem.reloadShapes();
  5160. hasReloaded = true;
  5161. }
  5162. cont = 0;
  5163. var renderFlag;
  5164. for (i = 0; i <= this._groups.length - 1; i += 1) {
  5165. renderFlag = cont < copies;
  5166. this._groups[i]._render = renderFlag;
  5167. this.changeGroupRender(this._groups[i].it, renderFlag);
  5168. if (!renderFlag) {
  5169. var elems = this.elemsData[i].it;
  5170. var transformData = elems[elems.length - 1];
  5171. if (transformData.transform.op.v !== 0) {
  5172. transformData.transform.op._mdf = true;
  5173. transformData.transform.op.v = 0;
  5174. } else {
  5175. transformData.transform.op._mdf = false;
  5176. }
  5177. }
  5178. cont += 1;
  5179. }
  5180. this._currentCopies = copies;
  5181. /// /
  5182. var offset = this.o.v;
  5183. var offsetModulo = offset % 1;
  5184. var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset);
  5185. var pProps = this.pMatrix.props;
  5186. var rProps = this.rMatrix.props;
  5187. var sProps = this.sMatrix.props;
  5188. this.pMatrix.reset();
  5189. this.rMatrix.reset();
  5190. this.sMatrix.reset();
  5191. this.tMatrix.reset();
  5192. this.matrix.reset();
  5193. var iteration = 0;
  5194. if (offset > 0) {
  5195. while (iteration < roundOffset) {
  5196. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5197. iteration += 1;
  5198. }
  5199. if (offsetModulo) {
  5200. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false);
  5201. iteration += offsetModulo;
  5202. }
  5203. } else if (offset < 0) {
  5204. while (iteration > roundOffset) {
  5205. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true);
  5206. iteration -= 1;
  5207. }
  5208. if (offsetModulo) {
  5209. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true);
  5210. iteration -= offsetModulo;
  5211. }
  5212. }
  5213. i = this.data.m === 1 ? 0 : this._currentCopies - 1;
  5214. dir = this.data.m === 1 ? 1 : -1;
  5215. cont = this._currentCopies;
  5216. var j;
  5217. var jLen;
  5218. while (cont) {
  5219. items = this.elemsData[i].it;
  5220. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5221. jLen = itemsTransform.length;
  5222. items[items.length - 1].transform.mProps._mdf = true;
  5223. items[items.length - 1].transform.op._mdf = true;
  5224. items[items.length - 1].transform.op.v = this._currentCopies === 1
  5225. ? this.so.v
  5226. : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1));
  5227. if (iteration !== 0) {
  5228. if ((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)) {
  5229. this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false);
  5230. }
  5231. 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]);
  5232. 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]);
  5233. 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]);
  5234. for (j = 0; j < jLen; j += 1) {
  5235. itemsTransform[j] = this.matrix.props[j];
  5236. }
  5237. this.matrix.reset();
  5238. } else {
  5239. this.matrix.reset();
  5240. for (j = 0; j < jLen; j += 1) {
  5241. itemsTransform[j] = this.matrix.props[j];
  5242. }
  5243. }
  5244. iteration += 1;
  5245. cont -= 1;
  5246. i += dir;
  5247. }
  5248. } else {
  5249. cont = this._currentCopies;
  5250. i = 0;
  5251. dir = 1;
  5252. while (cont) {
  5253. items = this.elemsData[i].it;
  5254. itemsTransform = items[items.length - 1].transform.mProps.v.props;
  5255. items[items.length - 1].transform.mProps._mdf = false;
  5256. items[items.length - 1].transform.op._mdf = false;
  5257. cont -= 1;
  5258. i += dir;
  5259. }
  5260. }
  5261. return hasReloaded;
  5262. };
  5263. RepeaterModifier.prototype.addShape = function () {};
  5264. function RoundCornersModifier() {}
  5265. extendPrototype([ShapeModifier], RoundCornersModifier);
  5266. RoundCornersModifier.prototype.initModifierProperties = function (elem, data) {
  5267. this.getValue = this.processKeys;
  5268. this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5269. this._isAnimated = !!this.rd.effectsSequence.length;
  5270. };
  5271. RoundCornersModifier.prototype.processPath = function (path, round) {
  5272. var clonedPath = shapePool.newElement();
  5273. clonedPath.c = path.c;
  5274. var i;
  5275. var len = path._length;
  5276. var currentV;
  5277. var currentI;
  5278. var currentO;
  5279. var closerV;
  5280. var distance;
  5281. var newPosPerc;
  5282. var index = 0;
  5283. var vX;
  5284. var vY;
  5285. var oX;
  5286. var oY;
  5287. var iX;
  5288. var iY;
  5289. for (i = 0; i < len; i += 1) {
  5290. currentV = path.v[i];
  5291. currentO = path.o[i];
  5292. currentI = path.i[i];
  5293. if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) {
  5294. if ((i === 0 || i === len - 1) && !path.c) {
  5295. clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index);
  5296. /* clonedPath.v[index] = currentV;
  5297. clonedPath.o[index] = currentO;
  5298. clonedPath.i[index] = currentI; */
  5299. index += 1;
  5300. } else {
  5301. if (i === 0) {
  5302. closerV = path.v[len - 1];
  5303. } else {
  5304. closerV = path.v[i - 1];
  5305. }
  5306. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5307. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5308. iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5309. vX = iX;
  5310. iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc;
  5311. vY = iY;
  5312. oX = vX - (vX - currentV[0]) * roundCorner;
  5313. oY = vY - (vY - currentV[1]) * roundCorner;
  5314. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5315. index += 1;
  5316. if (i === len - 1) {
  5317. closerV = path.v[0];
  5318. } else {
  5319. closerV = path.v[i + 1];
  5320. }
  5321. distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2));
  5322. newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0;
  5323. oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc;
  5324. vX = oX;
  5325. oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc;
  5326. vY = oY;
  5327. iX = vX - (vX - currentV[0]) * roundCorner;
  5328. iY = vY - (vY - currentV[1]) * roundCorner;
  5329. clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index);
  5330. index += 1;
  5331. }
  5332. } else {
  5333. 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);
  5334. index += 1;
  5335. }
  5336. }
  5337. return clonedPath;
  5338. };
  5339. RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) {
  5340. var shapePaths;
  5341. var i;
  5342. var len = this.shapes.length;
  5343. var j;
  5344. var jLen;
  5345. var rd = this.rd.v;
  5346. if (rd !== 0) {
  5347. var shapeData;
  5348. var localShapeCollection;
  5349. for (i = 0; i < len; i += 1) {
  5350. shapeData = this.shapes[i];
  5351. localShapeCollection = shapeData.localShapeCollection;
  5352. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5353. localShapeCollection.releaseShapes();
  5354. shapeData.shape._mdf = true;
  5355. shapePaths = shapeData.shape.paths.shapes;
  5356. jLen = shapeData.shape.paths._length;
  5357. for (j = 0; j < jLen; j += 1) {
  5358. localShapeCollection.addShape(this.processPath(shapePaths[j], rd));
  5359. }
  5360. }
  5361. shapeData.shape.paths = shapeData.localShapeCollection;
  5362. }
  5363. }
  5364. if (!this.dynamicProperties.length) {
  5365. this._mdf = false;
  5366. }
  5367. };
  5368. function floatEqual(a, b) {
  5369. return Math.abs(a - b) * 100000 <= Math.min(Math.abs(a), Math.abs(b));
  5370. }
  5371. function floatZero(f) {
  5372. return Math.abs(f) <= 0.00001;
  5373. }
  5374. function lerp(p0, p1, amount) {
  5375. return p0 * (1 - amount) + p1 * amount;
  5376. }
  5377. function lerpPoint(p0, p1, amount) {
  5378. return [lerp(p0[0], p1[0], amount), lerp(p0[1], p1[1], amount)];
  5379. }
  5380. function quadRoots(a, b, c) {
  5381. // no root
  5382. if (a === 0) return [];
  5383. var s = b * b - 4 * a * c;
  5384. // Complex roots
  5385. if (s < 0) return [];
  5386. var singleRoot = -b / (2 * a);
  5387. // 1 root
  5388. if (s === 0) return [singleRoot];
  5389. var delta = Math.sqrt(s) / (2 * a);
  5390. // 2 roots
  5391. return [singleRoot - delta, singleRoot + delta];
  5392. }
  5393. function polynomialCoefficients(p0, p1, p2, p3) {
  5394. return [
  5395. -p0 + 3 * p1 - 3 * p2 + p3,
  5396. 3 * p0 - 6 * p1 + 3 * p2,
  5397. -3 * p0 + 3 * p1,
  5398. p0,
  5399. ];
  5400. }
  5401. function singlePoint(p) {
  5402. return new PolynomialBezier(p, p, p, p, false);
  5403. }
  5404. function PolynomialBezier(p0, p1, p2, p3, linearize) {
  5405. if (linearize && pointEqual(p0, p1)) {
  5406. p1 = lerpPoint(p0, p3, 1 / 3);
  5407. }
  5408. if (linearize && pointEqual(p2, p3)) {
  5409. p2 = lerpPoint(p0, p3, 2 / 3);
  5410. }
  5411. var coeffx = polynomialCoefficients(p0[0], p1[0], p2[0], p3[0]);
  5412. var coeffy = polynomialCoefficients(p0[1], p1[1], p2[1], p3[1]);
  5413. this.a = [coeffx[0], coeffy[0]];
  5414. this.b = [coeffx[1], coeffy[1]];
  5415. this.c = [coeffx[2], coeffy[2]];
  5416. this.d = [coeffx[3], coeffy[3]];
  5417. this.points = [p0, p1, p2, p3];
  5418. }
  5419. PolynomialBezier.prototype.point = function (t) {
  5420. return [
  5421. (((this.a[0] * t) + this.b[0]) * t + this.c[0]) * t + this.d[0],
  5422. (((this.a[1] * t) + this.b[1]) * t + this.c[1]) * t + this.d[1],
  5423. ];
  5424. };
  5425. PolynomialBezier.prototype.derivative = function (t) {
  5426. return [
  5427. (3 * t * this.a[0] + 2 * this.b[0]) * t + this.c[0],
  5428. (3 * t * this.a[1] + 2 * this.b[1]) * t + this.c[1],
  5429. ];
  5430. };
  5431. PolynomialBezier.prototype.tangentAngle = function (t) {
  5432. var p = this.derivative(t);
  5433. return Math.atan2(p[1], p[0]);
  5434. };
  5435. PolynomialBezier.prototype.normalAngle = function (t) {
  5436. var p = this.derivative(t);
  5437. return Math.atan2(p[0], p[1]);
  5438. };
  5439. PolynomialBezier.prototype.inflectionPoints = function () {
  5440. var denom = this.a[1] * this.b[0] - this.a[0] * this.b[1];
  5441. if (floatZero(denom)) return [];
  5442. var tcusp = (-0.5 * (this.a[1] * this.c[0] - this.a[0] * this.c[1])) / denom;
  5443. var square = tcusp * tcusp - ((1 / 3) * (this.b[1] * this.c[0] - this.b[0] * this.c[1])) / denom;
  5444. if (square < 0) return [];
  5445. var root = Math.sqrt(square);
  5446. if (floatZero(root)) {
  5447. if (root > 0 && root < 1) return [tcusp];
  5448. return [];
  5449. }
  5450. return [tcusp - root, tcusp + root].filter(function (r) { return r > 0 && r < 1; });
  5451. };
  5452. PolynomialBezier.prototype.split = function (t) {
  5453. if (t <= 0) return [singlePoint(this.points[0]), this];
  5454. if (t >= 1) return [this, singlePoint(this.points[this.points.length - 1])];
  5455. var p10 = lerpPoint(this.points[0], this.points[1], t);
  5456. var p11 = lerpPoint(this.points[1], this.points[2], t);
  5457. var p12 = lerpPoint(this.points[2], this.points[3], t);
  5458. var p20 = lerpPoint(p10, p11, t);
  5459. var p21 = lerpPoint(p11, p12, t);
  5460. var p3 = lerpPoint(p20, p21, t);
  5461. return [
  5462. new PolynomialBezier(this.points[0], p10, p20, p3, true),
  5463. new PolynomialBezier(p3, p21, p12, this.points[3], true),
  5464. ];
  5465. };
  5466. function extrema(bez, comp) {
  5467. var min = bez.points[0][comp];
  5468. var max = bez.points[bez.points.length - 1][comp];
  5469. if (min > max) {
  5470. var e = max;
  5471. max = min;
  5472. min = e;
  5473. }
  5474. // Derivative roots to find min/max
  5475. var f = quadRoots(3 * bez.a[comp], 2 * bez.b[comp], bez.c[comp]);
  5476. for (var i = 0; i < f.length; i += 1) {
  5477. if (f[i] > 0 && f[i] < 1) {
  5478. var val = bez.point(f[i])[comp];
  5479. if (val < min) min = val;
  5480. else if (val > max) max = val;
  5481. }
  5482. }
  5483. return {
  5484. min: min,
  5485. max: max,
  5486. };
  5487. }
  5488. PolynomialBezier.prototype.bounds = function () {
  5489. return {
  5490. x: extrema(this, 0),
  5491. y: extrema(this, 1),
  5492. };
  5493. };
  5494. PolynomialBezier.prototype.boundingBox = function () {
  5495. var bounds = this.bounds();
  5496. return {
  5497. left: bounds.x.min,
  5498. right: bounds.x.max,
  5499. top: bounds.y.min,
  5500. bottom: bounds.y.max,
  5501. width: bounds.x.max - bounds.x.min,
  5502. height: bounds.y.max - bounds.y.min,
  5503. cx: (bounds.x.max + bounds.x.min) / 2,
  5504. cy: (bounds.y.max + bounds.y.min) / 2,
  5505. };
  5506. };
  5507. function intersectData(bez, t1, t2) {
  5508. var box = bez.boundingBox();
  5509. return {
  5510. cx: box.cx,
  5511. cy: box.cy,
  5512. width: box.width,
  5513. height: box.height,
  5514. bez: bez,
  5515. t: (t1 + t2) / 2,
  5516. t1: t1,
  5517. t2: t2,
  5518. };
  5519. }
  5520. function splitData(data) {
  5521. var split = data.bez.split(0.5);
  5522. return [
  5523. intersectData(split[0], data.t1, data.t),
  5524. intersectData(split[1], data.t, data.t2),
  5525. ];
  5526. }
  5527. function boxIntersect(b1, b2) {
  5528. return Math.abs(b1.cx - b2.cx) * 2 < b1.width + b2.width
  5529. && Math.abs(b1.cy - b2.cy) * 2 < b1.height + b2.height;
  5530. }
  5531. function intersectsImpl(d1, d2, depth, tolerance, intersections, maxRecursion) {
  5532. if (!boxIntersect(d1, d2)) return;
  5533. if (depth >= maxRecursion || (d1.width <= tolerance && d1.height <= tolerance && d2.width <= tolerance && d2.height <= tolerance)) {
  5534. intersections.push([d1.t, d2.t]);
  5535. return;
  5536. }
  5537. var d1s = splitData(d1);
  5538. var d2s = splitData(d2);
  5539. intersectsImpl(d1s[0], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5540. intersectsImpl(d1s[0], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5541. intersectsImpl(d1s[1], d2s[0], depth + 1, tolerance, intersections, maxRecursion);
  5542. intersectsImpl(d1s[1], d2s[1], depth + 1, tolerance, intersections, maxRecursion);
  5543. }
  5544. PolynomialBezier.prototype.intersections = function (other, tolerance, maxRecursion) {
  5545. if (tolerance === undefined) tolerance = 2;
  5546. if (maxRecursion === undefined) maxRecursion = 7;
  5547. var intersections = [];
  5548. intersectsImpl(intersectData(this, 0, 1), intersectData(other, 0, 1), 0, tolerance, intersections, maxRecursion);
  5549. return intersections;
  5550. };
  5551. PolynomialBezier.shapeSegment = function (shapePath, index) {
  5552. var nextIndex = (index + 1) % shapePath.length();
  5553. return new PolynomialBezier(shapePath.v[index], shapePath.o[index], shapePath.i[nextIndex], shapePath.v[nextIndex], true);
  5554. };
  5555. PolynomialBezier.shapeSegmentInverted = function (shapePath, index) {
  5556. var nextIndex = (index + 1) % shapePath.length();
  5557. return new PolynomialBezier(shapePath.v[nextIndex], shapePath.i[nextIndex], shapePath.o[index], shapePath.v[index], true);
  5558. };
  5559. function crossProduct(a, b) {
  5560. return [
  5561. a[1] * b[2] - a[2] * b[1],
  5562. a[2] * b[0] - a[0] * b[2],
  5563. a[0] * b[1] - a[1] * b[0],
  5564. ];
  5565. }
  5566. function lineIntersection(start1, end1, start2, end2) {
  5567. var v1 = [start1[0], start1[1], 1];
  5568. var v2 = [end1[0], end1[1], 1];
  5569. var v3 = [start2[0], start2[1], 1];
  5570. var v4 = [end2[0], end2[1], 1];
  5571. var r = crossProduct(
  5572. crossProduct(v1, v2),
  5573. crossProduct(v3, v4)
  5574. );
  5575. if (floatZero(r[2])) return null;
  5576. return [r[0] / r[2], r[1] / r[2]];
  5577. }
  5578. function polarOffset(p, angle, length) {
  5579. return [
  5580. p[0] + Math.cos(angle) * length,
  5581. p[1] - Math.sin(angle) * length,
  5582. ];
  5583. }
  5584. function pointDistance(p1, p2) {
  5585. return Math.hypot(p1[0] - p2[0], p1[1] - p2[1]);
  5586. }
  5587. function pointEqual(p1, p2) {
  5588. return floatEqual(p1[0], p2[0]) && floatEqual(p1[1], p2[1]);
  5589. }
  5590. function ZigZagModifier() {}
  5591. extendPrototype([ShapeModifier], ZigZagModifier);
  5592. ZigZagModifier.prototype.initModifierProperties = function (elem, data) {
  5593. this.getValue = this.processKeys;
  5594. this.amplitude = PropertyFactory.getProp(elem, data.s, 0, null, this);
  5595. this.frequency = PropertyFactory.getProp(elem, data.r, 0, null, this);
  5596. this.pointsType = PropertyFactory.getProp(elem, data.pt, 0, null, this);
  5597. this._isAnimated = this.amplitude.effectsSequence.length !== 0 || this.frequency.effectsSequence.length !== 0 || this.pointsType.effectsSequence.length !== 0;
  5598. };
  5599. function setPoint(outputBezier, point, angle, direction, amplitude, outAmplitude, inAmplitude) {
  5600. var angO = angle - Math.PI / 2;
  5601. var angI = angle + Math.PI / 2;
  5602. var px = point[0] + Math.cos(angle) * direction * amplitude;
  5603. var py = point[1] - Math.sin(angle) * direction * amplitude;
  5604. outputBezier.setTripleAt(
  5605. px,
  5606. py,
  5607. px + Math.cos(angO) * outAmplitude,
  5608. py - Math.sin(angO) * outAmplitude,
  5609. px + Math.cos(angI) * inAmplitude,
  5610. py - Math.sin(angI) * inAmplitude,
  5611. outputBezier.length()
  5612. );
  5613. }
  5614. function getPerpendicularVector(pt1, pt2) {
  5615. var vector = [
  5616. pt2[0] - pt1[0],
  5617. pt2[1] - pt1[1],
  5618. ];
  5619. var rot = -Math.PI * 0.5;
  5620. var rotatedVector = [
  5621. Math.cos(rot) * vector[0] - Math.sin(rot) * vector[1],
  5622. Math.sin(rot) * vector[0] + Math.cos(rot) * vector[1],
  5623. ];
  5624. return rotatedVector;
  5625. }
  5626. function getProjectingAngle(path, cur) {
  5627. var prevIndex = cur === 0 ? path.length() - 1 : cur - 1;
  5628. var nextIndex = (cur + 1) % path.length();
  5629. var prevPoint = path.v[prevIndex];
  5630. var nextPoint = path.v[nextIndex];
  5631. var pVector = getPerpendicularVector(prevPoint, nextPoint);
  5632. return Math.atan2(0, 1) - Math.atan2(pVector[1], pVector[0]);
  5633. }
  5634. function zigZagCorner(outputBezier, path, cur, amplitude, frequency, pointType, direction) {
  5635. var angle = getProjectingAngle(path, cur);
  5636. var point = path.v[cur % path._length];
  5637. var prevPoint = path.v[cur === 0 ? path._length - 1 : cur - 1];
  5638. var nextPoint = path.v[(cur + 1) % path._length];
  5639. var prevDist = pointType === 2
  5640. ? Math.sqrt(Math.pow(point[0] - prevPoint[0], 2) + Math.pow(point[1] - prevPoint[1], 2))
  5641. : 0;
  5642. var nextDist = pointType === 2
  5643. ? Math.sqrt(Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2))
  5644. : 0;
  5645. setPoint(
  5646. outputBezier,
  5647. path.v[cur % path._length],
  5648. angle,
  5649. direction,
  5650. amplitude,
  5651. nextDist / ((frequency + 1) * 2),
  5652. prevDist / ((frequency + 1) * 2),
  5653. pointType
  5654. );
  5655. }
  5656. function zigZagSegment(outputBezier, segment, amplitude, frequency, pointType, direction) {
  5657. for (var i = 0; i < frequency; i += 1) {
  5658. var t = (i + 1) / (frequency + 1);
  5659. var dist = pointType === 2
  5660. ? Math.sqrt(Math.pow(segment.points[3][0] - segment.points[0][0], 2) + Math.pow(segment.points[3][1] - segment.points[0][1], 2))
  5661. : 0;
  5662. var angle = segment.normalAngle(t);
  5663. var point = segment.point(t);
  5664. setPoint(
  5665. outputBezier,
  5666. point,
  5667. angle,
  5668. direction,
  5669. amplitude,
  5670. dist / ((frequency + 1) * 2),
  5671. dist / ((frequency + 1) * 2),
  5672. pointType
  5673. );
  5674. direction = -direction;
  5675. }
  5676. return direction;
  5677. }
  5678. ZigZagModifier.prototype.processPath = function (path, amplitude, frequency, pointType) {
  5679. var count = path._length;
  5680. var clonedPath = shapePool.newElement();
  5681. clonedPath.c = path.c;
  5682. if (!path.c) {
  5683. count -= 1;
  5684. }
  5685. if (count === 0) return clonedPath;
  5686. var direction = -1;
  5687. var segment = PolynomialBezier.shapeSegment(path, 0);
  5688. zigZagCorner(clonedPath, path, 0, amplitude, frequency, pointType, direction);
  5689. for (var i = 0; i < count; i += 1) {
  5690. direction = zigZagSegment(clonedPath, segment, amplitude, frequency, pointType, -direction);
  5691. if (i === count - 1 && !path.c) {
  5692. segment = null;
  5693. } else {
  5694. segment = PolynomialBezier.shapeSegment(path, (i + 1) % count);
  5695. }
  5696. zigZagCorner(clonedPath, path, i + 1, amplitude, frequency, pointType, direction);
  5697. }
  5698. return clonedPath;
  5699. };
  5700. ZigZagModifier.prototype.processShapes = function (_isFirstFrame) {
  5701. var shapePaths;
  5702. var i;
  5703. var len = this.shapes.length;
  5704. var j;
  5705. var jLen;
  5706. var amplitude = this.amplitude.v;
  5707. var frequency = Math.max(0, Math.round(this.frequency.v));
  5708. var pointType = this.pointsType.v;
  5709. if (amplitude !== 0) {
  5710. var shapeData;
  5711. var localShapeCollection;
  5712. for (i = 0; i < len; i += 1) {
  5713. shapeData = this.shapes[i];
  5714. localShapeCollection = shapeData.localShapeCollection;
  5715. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5716. localShapeCollection.releaseShapes();
  5717. shapeData.shape._mdf = true;
  5718. shapePaths = shapeData.shape.paths.shapes;
  5719. jLen = shapeData.shape.paths._length;
  5720. for (j = 0; j < jLen; j += 1) {
  5721. localShapeCollection.addShape(this.processPath(shapePaths[j], amplitude, frequency, pointType));
  5722. }
  5723. }
  5724. shapeData.shape.paths = shapeData.localShapeCollection;
  5725. }
  5726. }
  5727. if (!this.dynamicProperties.length) {
  5728. this._mdf = false;
  5729. }
  5730. };
  5731. function linearOffset(p1, p2, amount) {
  5732. var angle = Math.atan2(p2[0] - p1[0], p2[1] - p1[1]);
  5733. return [
  5734. polarOffset(p1, angle, amount),
  5735. polarOffset(p2, angle, amount),
  5736. ];
  5737. }
  5738. function offsetSegment(segment, amount) {
  5739. var p0; var p1a; var p1b; var p2b; var p2a; var
  5740. p3;
  5741. var e;
  5742. e = linearOffset(segment.points[0], segment.points[1], amount);
  5743. p0 = e[0];
  5744. p1a = e[1];
  5745. e = linearOffset(segment.points[1], segment.points[2], amount);
  5746. p1b = e[0];
  5747. p2b = e[1];
  5748. e = linearOffset(segment.points[2], segment.points[3], amount);
  5749. p2a = e[0];
  5750. p3 = e[1];
  5751. var p1 = lineIntersection(p0, p1a, p1b, p2b);
  5752. if (p1 === null) p1 = p1a;
  5753. var p2 = lineIntersection(p2a, p3, p1b, p2b);
  5754. if (p2 === null) p2 = p2a;
  5755. return new PolynomialBezier(p0, p1, p2, p3);
  5756. }
  5757. function joinLines(outputBezier, seg1, seg2, lineJoin, miterLimit) {
  5758. var p0 = seg1.points[3];
  5759. var p1 = seg2.points[0];
  5760. // Bevel
  5761. if (lineJoin === 3) return p0;
  5762. // Connected, they don't need a joint
  5763. if (pointEqual(p0, p1)) return p0;
  5764. // Round
  5765. if (lineJoin === 2) {
  5766. var angleOut = -seg1.tangentAngle(1);
  5767. var angleIn = -seg2.tangentAngle(0) + Math.PI;
  5768. var center = lineIntersection(
  5769. p0,
  5770. polarOffset(p0, angleOut + Math.PI / 2, 100),
  5771. p1,
  5772. polarOffset(p1, angleOut + Math.PI / 2, 100)
  5773. );
  5774. var radius = center ? pointDistance(center, p0) : pointDistance(p0, p1) / 2;
  5775. var tan = polarOffset(p0, angleOut, 2 * radius * roundCorner);
  5776. outputBezier.setXYAt(tan[0], tan[1], 'o', outputBezier.length() - 1);
  5777. tan = polarOffset(p1, angleIn, 2 * radius * roundCorner);
  5778. outputBezier.setTripleAt(p1[0], p1[1], p1[0], p1[1], tan[0], tan[1], outputBezier.length());
  5779. return p1;
  5780. }
  5781. // Miter
  5782. var t0 = pointEqual(p0, seg1.points[2]) ? seg1.points[0] : seg1.points[2];
  5783. var t1 = pointEqual(p1, seg2.points[1]) ? seg2.points[3] : seg2.points[1];
  5784. var intersection = lineIntersection(t0, p0, p1, t1);
  5785. if (intersection && pointDistance(intersection, p0) < miterLimit) {
  5786. outputBezier.setTripleAt(
  5787. intersection[0],
  5788. intersection[1],
  5789. intersection[0],
  5790. intersection[1],
  5791. intersection[0],
  5792. intersection[1],
  5793. outputBezier.length()
  5794. );
  5795. return intersection;
  5796. }
  5797. return p0;
  5798. }
  5799. function getIntersection(a, b) {
  5800. const intersect = a.intersections(b);
  5801. if (intersect.length && floatEqual(intersect[0][0], 1)) intersect.shift();
  5802. if (intersect.length) return intersect[0];
  5803. return null;
  5804. }
  5805. function pruneSegmentIntersection(a, b) {
  5806. var outa = a.slice();
  5807. var outb = b.slice();
  5808. var intersect = getIntersection(a[a.length - 1], b[0]);
  5809. if (intersect) {
  5810. outa[a.length - 1] = a[a.length - 1].split(intersect[0])[0];
  5811. outb[0] = b[0].split(intersect[1])[1];
  5812. }
  5813. if (a.length > 1 && b.length > 1) {
  5814. intersect = getIntersection(a[0], b[b.length - 1]);
  5815. if (intersect) {
  5816. return [
  5817. [a[0].split(intersect[0])[0]],
  5818. [b[b.length - 1].split(intersect[1])[1]],
  5819. ];
  5820. }
  5821. }
  5822. return [outa, outb];
  5823. }
  5824. function pruneIntersections(segments) {
  5825. var e;
  5826. for (var i = 1; i < segments.length; i += 1) {
  5827. e = pruneSegmentIntersection(segments[i - 1], segments[i]);
  5828. segments[i - 1] = e[0];
  5829. segments[i] = e[1];
  5830. }
  5831. if (segments.length > 1) {
  5832. e = pruneSegmentIntersection(segments[segments.length - 1], segments[0]);
  5833. segments[segments.length - 1] = e[0];
  5834. segments[0] = e[1];
  5835. }
  5836. return segments;
  5837. }
  5838. function offsetSegmentSplit(segment, amount) {
  5839. /*
  5840. We split each bezier segment into smaller pieces based
  5841. on inflection points, this ensures the control point
  5842. polygon is convex.
  5843. (A cubic bezier can have none, one, or two inflection points)
  5844. */
  5845. var flex = segment.inflectionPoints();
  5846. var left;
  5847. var right;
  5848. var split;
  5849. var mid;
  5850. if (flex.length === 0) {
  5851. return [offsetSegment(segment, amount)];
  5852. }
  5853. if (flex.length === 1 || floatEqual(flex[1], 1)) {
  5854. split = segment.split(flex[0]);
  5855. left = split[0];
  5856. right = split[1];
  5857. return [
  5858. offsetSegment(left, amount),
  5859. offsetSegment(right, amount),
  5860. ];
  5861. }
  5862. split = segment.split(flex[0]);
  5863. left = split[0];
  5864. var t = (flex[1] - flex[0]) / (1 - flex[0]);
  5865. split = split[1].split(t);
  5866. mid = split[0];
  5867. right = split[1];
  5868. return [
  5869. offsetSegment(left, amount),
  5870. offsetSegment(mid, amount),
  5871. offsetSegment(right, amount),
  5872. ];
  5873. }
  5874. function OffsetPathModifier() {}
  5875. extendPrototype([ShapeModifier], OffsetPathModifier);
  5876. OffsetPathModifier.prototype.initModifierProperties = function (elem, data) {
  5877. this.getValue = this.processKeys;
  5878. this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this);
  5879. this.miterLimit = PropertyFactory.getProp(elem, data.ml, 0, null, this);
  5880. this.lineJoin = data.lj;
  5881. this._isAnimated = this.amount.effectsSequence.length !== 0;
  5882. };
  5883. OffsetPathModifier.prototype.processPath = function (inputBezier, amount, lineJoin, miterLimit) {
  5884. var outputBezier = shapePool.newElement();
  5885. outputBezier.c = inputBezier.c;
  5886. var count = inputBezier.length();
  5887. if (!inputBezier.c) {
  5888. count -= 1;
  5889. }
  5890. var i; var j; var segment;
  5891. var multiSegments = [];
  5892. for (i = 0; i < count; i += 1) {
  5893. segment = PolynomialBezier.shapeSegment(inputBezier, i);
  5894. multiSegments.push(offsetSegmentSplit(segment, amount));
  5895. }
  5896. if (!inputBezier.c) {
  5897. for (i = count - 1; i >= 0; i -= 1) {
  5898. segment = PolynomialBezier.shapeSegmentInverted(inputBezier, i);
  5899. multiSegments.push(offsetSegmentSplit(segment, amount));
  5900. }
  5901. }
  5902. multiSegments = pruneIntersections(multiSegments);
  5903. // Add bezier segments to the output and apply line joints
  5904. var lastPoint = null;
  5905. var lastSeg = null;
  5906. for (i = 0; i < multiSegments.length; i += 1) {
  5907. var multiSegment = multiSegments[i];
  5908. if (lastSeg) lastPoint = joinLines(outputBezier, lastSeg, multiSegment[0], lineJoin, miterLimit);
  5909. lastSeg = multiSegment[multiSegment.length - 1];
  5910. for (j = 0; j < multiSegment.length; j += 1) {
  5911. segment = multiSegment[j];
  5912. if (lastPoint && pointEqual(segment.points[0], lastPoint)) {
  5913. outputBezier.setXYAt(segment.points[1][0], segment.points[1][1], 'o', outputBezier.length() - 1);
  5914. } else {
  5915. outputBezier.setTripleAt(
  5916. segment.points[0][0],
  5917. segment.points[0][1],
  5918. segment.points[1][0],
  5919. segment.points[1][1],
  5920. segment.points[0][0],
  5921. segment.points[0][1],
  5922. outputBezier.length()
  5923. );
  5924. }
  5925. outputBezier.setTripleAt(
  5926. segment.points[3][0],
  5927. segment.points[3][1],
  5928. segment.points[3][0],
  5929. segment.points[3][1],
  5930. segment.points[2][0],
  5931. segment.points[2][1],
  5932. outputBezier.length()
  5933. );
  5934. lastPoint = segment.points[3];
  5935. }
  5936. }
  5937. if (multiSegments.length) joinLines(outputBezier, lastSeg, multiSegments[0][0], lineJoin, miterLimit);
  5938. return outputBezier;
  5939. };
  5940. OffsetPathModifier.prototype.processShapes = function (_isFirstFrame) {
  5941. var shapePaths;
  5942. var i;
  5943. var len = this.shapes.length;
  5944. var j;
  5945. var jLen;
  5946. var amount = this.amount.v;
  5947. var miterLimit = this.miterLimit.v;
  5948. var lineJoin = this.lineJoin;
  5949. if (amount !== 0) {
  5950. var shapeData;
  5951. var localShapeCollection;
  5952. for (i = 0; i < len; i += 1) {
  5953. shapeData = this.shapes[i];
  5954. localShapeCollection = shapeData.localShapeCollection;
  5955. if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) {
  5956. localShapeCollection.releaseShapes();
  5957. shapeData.shape._mdf = true;
  5958. shapePaths = shapeData.shape.paths.shapes;
  5959. jLen = shapeData.shape.paths._length;
  5960. for (j = 0; j < jLen; j += 1) {
  5961. localShapeCollection.addShape(this.processPath(shapePaths[j], amount, lineJoin, miterLimit));
  5962. }
  5963. }
  5964. shapeData.shape.paths = shapeData.localShapeCollection;
  5965. }
  5966. }
  5967. if (!this.dynamicProperties.length) {
  5968. this._mdf = false;
  5969. }
  5970. };
  5971. function getFontProperties(fontData) {
  5972. var styles = fontData.fStyle ? fontData.fStyle.split(' ') : [];
  5973. var fWeight = 'normal'; var
  5974. fStyle = 'normal';
  5975. var len = styles.length;
  5976. var styleName;
  5977. for (var i = 0; i < len; i += 1) {
  5978. styleName = styles[i].toLowerCase();
  5979. switch (styleName) {
  5980. case 'italic':
  5981. fStyle = 'italic';
  5982. break;
  5983. case 'bold':
  5984. fWeight = '700';
  5985. break;
  5986. case 'black':
  5987. fWeight = '900';
  5988. break;
  5989. case 'medium':
  5990. fWeight = '500';
  5991. break;
  5992. case 'regular':
  5993. case 'normal':
  5994. fWeight = '400';
  5995. break;
  5996. case 'light':
  5997. case 'thin':
  5998. fWeight = '200';
  5999. break;
  6000. default:
  6001. break;
  6002. }
  6003. }
  6004. return {
  6005. style: fStyle,
  6006. weight: fontData.fWeight || fWeight,
  6007. };
  6008. }
  6009. const FontManager = (function () {
  6010. var maxWaitingTime = 5000;
  6011. var emptyChar = {
  6012. w: 0,
  6013. size: 0,
  6014. shapes: [],
  6015. data: {
  6016. shapes: [],
  6017. },
  6018. };
  6019. var combinedCharacters = [];
  6020. // Hindi characters
  6021. combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366,
  6022. 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379,
  6023. 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
  6024. var BLACK_FLAG_CODE_POINT = 127988;
  6025. var CANCEL_TAG_CODE_POINT = 917631;
  6026. var A_TAG_CODE_POINT = 917601;
  6027. var Z_TAG_CODE_POINT = 917626;
  6028. var VARIATION_SELECTOR_16_CODE_POINT = 65039;
  6029. var ZERO_WIDTH_JOINER_CODE_POINT = 8205;
  6030. var REGIONAL_CHARACTER_A_CODE_POINT = 127462;
  6031. var REGIONAL_CHARACTER_Z_CODE_POINT = 127487;
  6032. var surrogateModifiers = [
  6033. 'd83cdffb',
  6034. 'd83cdffc',
  6035. 'd83cdffd',
  6036. 'd83cdffe',
  6037. 'd83cdfff',
  6038. ];
  6039. function trimFontOptions(font) {
  6040. var familyArray = font.split(',');
  6041. var i;
  6042. var len = familyArray.length;
  6043. var enabledFamilies = [];
  6044. for (i = 0; i < len; i += 1) {
  6045. if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
  6046. enabledFamilies.push(familyArray[i]);
  6047. }
  6048. }
  6049. return enabledFamilies.join(',');
  6050. }
  6051. function setUpNode(font, family) {
  6052. var parentNode = createTag('span');
  6053. // Node is invisible to screen readers.
  6054. parentNode.setAttribute('aria-hidden', true);
  6055. parentNode.style.fontFamily = family;
  6056. var node = createTag('span');
  6057. // Characters that vary significantly among different fonts
  6058. node.innerText = 'giItT1WQy@!-/#';
  6059. // Visible - so we can measure it - but not on the screen
  6060. parentNode.style.position = 'absolute';
  6061. parentNode.style.left = '-10000px';
  6062. parentNode.style.top = '-10000px';
  6063. // Large font size makes even subtle changes obvious
  6064. parentNode.style.fontSize = '300px';
  6065. // Reset any font properties
  6066. parentNode.style.fontVariant = 'normal';
  6067. parentNode.style.fontStyle = 'normal';
  6068. parentNode.style.fontWeight = 'normal';
  6069. parentNode.style.letterSpacing = '0';
  6070. parentNode.appendChild(node);
  6071. document.body.appendChild(parentNode);
  6072. // Remember width with no applied web font
  6073. var width = node.offsetWidth;
  6074. node.style.fontFamily = trimFontOptions(font) + ', ' + family;
  6075. return { node: node, w: width, parent: parentNode };
  6076. }
  6077. function checkLoadedFonts() {
  6078. var i;
  6079. var len = this.fonts.length;
  6080. var node;
  6081. var w;
  6082. var loadedCount = len;
  6083. for (i = 0; i < len; i += 1) {
  6084. if (this.fonts[i].loaded) {
  6085. loadedCount -= 1;
  6086. } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) {
  6087. this.fonts[i].loaded = true;
  6088. } else {
  6089. node = this.fonts[i].monoCase.node;
  6090. w = this.fonts[i].monoCase.w;
  6091. if (node.offsetWidth !== w) {
  6092. loadedCount -= 1;
  6093. this.fonts[i].loaded = true;
  6094. } else {
  6095. node = this.fonts[i].sansCase.node;
  6096. w = this.fonts[i].sansCase.w;
  6097. if (node.offsetWidth !== w) {
  6098. loadedCount -= 1;
  6099. this.fonts[i].loaded = true;
  6100. }
  6101. }
  6102. if (this.fonts[i].loaded) {
  6103. this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent);
  6104. this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent);
  6105. }
  6106. }
  6107. }
  6108. if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) {
  6109. setTimeout(this.checkLoadedFontsBinded, 20);
  6110. } else {
  6111. setTimeout(this.setIsLoadedBinded, 10);
  6112. }
  6113. }
  6114. function createHelper(fontData, def) {
  6115. var engine = (document.body && def) ? 'svg' : 'canvas';
  6116. var helper;
  6117. var fontProps = getFontProperties(fontData);
  6118. if (engine === 'svg') {
  6119. var tHelper = createNS('text');
  6120. tHelper.style.fontSize = '100px';
  6121. // tHelper.style.fontFamily = fontData.fFamily;
  6122. tHelper.setAttribute('font-family', fontData.fFamily);
  6123. tHelper.setAttribute('font-style', fontProps.style);
  6124. tHelper.setAttribute('font-weight', fontProps.weight);
  6125. tHelper.textContent = '1';
  6126. if (fontData.fClass) {
  6127. tHelper.style.fontFamily = 'inherit';
  6128. tHelper.setAttribute('class', fontData.fClass);
  6129. } else {
  6130. tHelper.style.fontFamily = fontData.fFamily;
  6131. }
  6132. def.appendChild(tHelper);
  6133. helper = tHelper;
  6134. } else {
  6135. var tCanvasHelper = new OffscreenCanvas(500, 500).getContext('2d');
  6136. tCanvasHelper.font = fontProps.style + ' ' + fontProps.weight + ' 100px ' + fontData.fFamily;
  6137. helper = tCanvasHelper;
  6138. }
  6139. function measure(text) {
  6140. if (engine === 'svg') {
  6141. helper.textContent = text;
  6142. return helper.getComputedTextLength();
  6143. }
  6144. return helper.measureText(text).width;
  6145. }
  6146. return {
  6147. measureText: measure,
  6148. };
  6149. }
  6150. function addFonts(fontData, defs) {
  6151. if (!fontData) {
  6152. this.isLoaded = true;
  6153. return;
  6154. }
  6155. if (this.chars) {
  6156. this.isLoaded = true;
  6157. this.fonts = fontData.list;
  6158. return;
  6159. }
  6160. if (!document.body) {
  6161. this.isLoaded = true;
  6162. fontData.list.forEach((data) => {
  6163. data.helper = createHelper(data);
  6164. data.cache = {};
  6165. });
  6166. this.fonts = fontData.list;
  6167. return;
  6168. }
  6169. var fontArr = fontData.list;
  6170. var i;
  6171. var len = fontArr.length;
  6172. var _pendingFonts = len;
  6173. for (i = 0; i < len; i += 1) {
  6174. var shouldLoadFont = true;
  6175. var loadedSelector;
  6176. var j;
  6177. fontArr[i].loaded = false;
  6178. fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace');
  6179. fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif');
  6180. if (!fontArr[i].fPath) {
  6181. fontArr[i].loaded = true;
  6182. _pendingFonts -= 1;
  6183. } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) {
  6184. loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]');
  6185. if (loadedSelector.length > 0) {
  6186. shouldLoadFont = false;
  6187. }
  6188. if (shouldLoadFont) {
  6189. var s = createTag('style');
  6190. s.setAttribute('f-forigin', fontArr[i].fOrigin);
  6191. s.setAttribute('f-origin', fontArr[i].origin);
  6192. s.setAttribute('f-family', fontArr[i].fFamily);
  6193. s.type = 'text/css';
  6194. s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}";
  6195. defs.appendChild(s);
  6196. }
  6197. } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) {
  6198. loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]');
  6199. for (j = 0; j < loadedSelector.length; j += 1) {
  6200. if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) {
  6201. // Font is already loaded
  6202. shouldLoadFont = false;
  6203. }
  6204. }
  6205. if (shouldLoadFont) {
  6206. var l = createTag('link');
  6207. l.setAttribute('f-forigin', fontArr[i].fOrigin);
  6208. l.setAttribute('f-origin', fontArr[i].origin);
  6209. l.type = 'text/css';
  6210. l.rel = 'stylesheet';
  6211. l.href = fontArr[i].fPath;
  6212. document.body.appendChild(l);
  6213. }
  6214. } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) {
  6215. loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]');
  6216. for (j = 0; j < loadedSelector.length; j += 1) {
  6217. if (fontArr[i].fPath === loadedSelector[j].src) {
  6218. // Font is already loaded
  6219. shouldLoadFont = false;
  6220. }
  6221. }
  6222. if (shouldLoadFont) {
  6223. var sc = createTag('link');
  6224. sc.setAttribute('f-forigin', fontArr[i].fOrigin);
  6225. sc.setAttribute('f-origin', fontArr[i].origin);
  6226. sc.setAttribute('rel', 'stylesheet');
  6227. sc.setAttribute('href', fontArr[i].fPath);
  6228. defs.appendChild(sc);
  6229. }
  6230. }
  6231. fontArr[i].helper = createHelper(fontArr[i], defs);
  6232. fontArr[i].cache = {};
  6233. this.fonts.push(fontArr[i]);
  6234. }
  6235. if (_pendingFonts === 0) {
  6236. this.isLoaded = true;
  6237. } else {
  6238. // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas.
  6239. // Adding this timeout seems to fix it
  6240. setTimeout(this.checkLoadedFonts.bind(this), 100);
  6241. }
  6242. }
  6243. function addChars(chars) {
  6244. if (!chars) {
  6245. return;
  6246. }
  6247. if (!this.chars) {
  6248. this.chars = [];
  6249. }
  6250. var i;
  6251. var len = chars.length;
  6252. var j;
  6253. var jLen = this.chars.length;
  6254. var found;
  6255. for (i = 0; i < len; i += 1) {
  6256. j = 0;
  6257. found = false;
  6258. while (j < jLen) {
  6259. if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) {
  6260. found = true;
  6261. }
  6262. j += 1;
  6263. }
  6264. if (!found) {
  6265. this.chars.push(chars[i]);
  6266. jLen += 1;
  6267. }
  6268. }
  6269. }
  6270. function getCharData(char, style, font) {
  6271. var i = 0;
  6272. var len = this.chars.length;
  6273. while (i < len) {
  6274. if (this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font) {
  6275. return this.chars[i];
  6276. }
  6277. i += 1;
  6278. }
  6279. if (((typeof char === 'string' && char.charCodeAt(0) !== 13) || !char)
  6280. && console
  6281. && console.warn // eslint-disable-line no-console
  6282. && !this._warned
  6283. ) {
  6284. this._warned = true;
  6285. console.warn('Missing character from exported characters list: ', char, style, font); // eslint-disable-line no-console
  6286. }
  6287. return emptyChar;
  6288. }
  6289. function measureText(char, fontName, size) {
  6290. var fontData = this.getFontByName(fontName);
  6291. // Using the char instead of char.charCodeAt(0)
  6292. // to avoid collisions between equal chars
  6293. var index = char;
  6294. if (!fontData.cache[index]) {
  6295. var tHelper = fontData.helper;
  6296. if (char === ' ') {
  6297. var doubleSize = tHelper.measureText('|' + char + '|');
  6298. var singleSize = tHelper.measureText('||');
  6299. fontData.cache[index] = (doubleSize - singleSize) / 100;
  6300. } else {
  6301. fontData.cache[index] = tHelper.measureText(char) / 100;
  6302. }
  6303. }
  6304. return fontData.cache[index] * size;
  6305. }
  6306. function getFontByName(name) {
  6307. var i = 0;
  6308. var len = this.fonts.length;
  6309. while (i < len) {
  6310. if (this.fonts[i].fName === name) {
  6311. return this.fonts[i];
  6312. }
  6313. i += 1;
  6314. }
  6315. return this.fonts[0];
  6316. }
  6317. function getCodePoint(string) {
  6318. var codePoint = 0;
  6319. var first = string.charCodeAt(0);
  6320. if (first >= 0xD800 && first <= 0xDBFF) {
  6321. var second = string.charCodeAt(1);
  6322. if (second >= 0xDC00 && second <= 0xDFFF) {
  6323. codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  6324. }
  6325. }
  6326. return codePoint;
  6327. }
  6328. // Skin tone modifiers
  6329. function isModifier(firstCharCode, secondCharCode) {
  6330. var sum = firstCharCode.toString(16) + secondCharCode.toString(16);
  6331. return surrogateModifiers.indexOf(sum) !== -1;
  6332. }
  6333. function isZeroWidthJoiner(charCode) {
  6334. return charCode === ZERO_WIDTH_JOINER_CODE_POINT;
  6335. }
  6336. // This codepoint may change the appearance of the preceding character.
  6337. // If that is a symbol, dingbat or emoji, U+FE0F forces it to be rendered
  6338. // as a colorful image as compared to a monochrome text variant.
  6339. function isVariationSelector(charCode) {
  6340. return charCode === VARIATION_SELECTOR_16_CODE_POINT;
  6341. }
  6342. // The regional indicator symbols are a set of 26 alphabetic Unicode
  6343. /// characters (A–Z) intended to be used to encode ISO 3166-1 alpha-2
  6344. // two-letter country codes in a way that allows optional special treatment.
  6345. function isRegionalCode(string) {
  6346. var codePoint = getCodePoint(string);
  6347. if (codePoint >= REGIONAL_CHARACTER_A_CODE_POINT && codePoint <= REGIONAL_CHARACTER_Z_CODE_POINT) {
  6348. return true;
  6349. }
  6350. return false;
  6351. }
  6352. // Some Emoji implementations represent combinations of
  6353. // two “regional indicator” letters as a single flag symbol.
  6354. function isFlagEmoji(string) {
  6355. return isRegionalCode(string.substr(0, 2)) && isRegionalCode(string.substr(2, 2));
  6356. }
  6357. function isCombinedCharacter(char) {
  6358. return combinedCharacters.indexOf(char) !== -1;
  6359. }
  6360. // Regional flags start with a BLACK_FLAG_CODE_POINT
  6361. // folowed by 5 chars in the TAG range
  6362. // and end with a CANCEL_TAG_CODE_POINT
  6363. function isRegionalFlag(text, index) {
  6364. var codePoint = getCodePoint(text.substr(index, 2));
  6365. if (codePoint !== BLACK_FLAG_CODE_POINT) {
  6366. return false;
  6367. }
  6368. var count = 0;
  6369. index += 2;
  6370. while (count < 5) {
  6371. codePoint = getCodePoint(text.substr(index, 2));
  6372. if (codePoint < A_TAG_CODE_POINT || codePoint > Z_TAG_CODE_POINT) {
  6373. return false;
  6374. }
  6375. count += 1;
  6376. index += 2;
  6377. }
  6378. return getCodePoint(text.substr(index, 2)) === CANCEL_TAG_CODE_POINT;
  6379. }
  6380. function setIsLoaded() {
  6381. this.isLoaded = true;
  6382. }
  6383. var Font = function () {
  6384. this.fonts = [];
  6385. this.chars = null;
  6386. this.typekitLoaded = 0;
  6387. this.isLoaded = false;
  6388. this._warned = false;
  6389. this.initTime = Date.now();
  6390. this.setIsLoadedBinded = this.setIsLoaded.bind(this);
  6391. this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this);
  6392. };
  6393. Font.isModifier = isModifier;
  6394. Font.isZeroWidthJoiner = isZeroWidthJoiner;
  6395. Font.isFlagEmoji = isFlagEmoji;
  6396. Font.isRegionalCode = isRegionalCode;
  6397. Font.isCombinedCharacter = isCombinedCharacter;
  6398. Font.isRegionalFlag = isRegionalFlag;
  6399. Font.isVariationSelector = isVariationSelector;
  6400. Font.BLACK_FLAG_CODE_POINT = BLACK_FLAG_CODE_POINT;
  6401. var fontPrototype = {
  6402. addChars: addChars,
  6403. addFonts: addFonts,
  6404. getCharData: getCharData,
  6405. getFontByName: getFontByName,
  6406. measureText: measureText,
  6407. checkLoadedFonts: checkLoadedFonts,
  6408. setIsLoaded: setIsLoaded,
  6409. };
  6410. Font.prototype = fontPrototype;
  6411. return Font;
  6412. }());
  6413. function SlotManager(animationData) {
  6414. this.animationData = animationData;
  6415. }
  6416. SlotManager.prototype.getProp = function (data) {
  6417. if (this.animationData.slots
  6418. && this.animationData.slots[data.sid]
  6419. ) {
  6420. return Object.assign(data, this.animationData.slots[data.sid].p);
  6421. }
  6422. return data;
  6423. };
  6424. function slotFactory(animationData) {
  6425. return new SlotManager(animationData);
  6426. }
  6427. function RenderableElement() {
  6428. }
  6429. RenderableElement.prototype = {
  6430. initRenderable: function () {
  6431. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6432. this.isInRange = false;
  6433. // layer's display state
  6434. this.hidden = false;
  6435. // If layer's transparency equals 0, it can be hidden
  6436. this.isTransparent = false;
  6437. // list of animated components
  6438. this.renderableComponents = [];
  6439. },
  6440. addRenderableComponent: function (component) {
  6441. if (this.renderableComponents.indexOf(component) === -1) {
  6442. this.renderableComponents.push(component);
  6443. }
  6444. },
  6445. removeRenderableComponent: function (component) {
  6446. if (this.renderableComponents.indexOf(component) !== -1) {
  6447. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  6448. }
  6449. },
  6450. prepareRenderableFrame: function (num) {
  6451. this.checkLayerLimits(num);
  6452. },
  6453. checkTransparency: function () {
  6454. if (this.finalTransform.mProp.o.v <= 0) {
  6455. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  6456. this.isTransparent = true;
  6457. this.hide();
  6458. }
  6459. } else if (this.isTransparent) {
  6460. this.isTransparent = false;
  6461. this.show();
  6462. }
  6463. },
  6464. /**
  6465. * @function
  6466. * Initializes frame related properties.
  6467. *
  6468. * @param {number} num
  6469. * current frame number in Layer's time
  6470. *
  6471. */
  6472. checkLayerLimits: function (num) {
  6473. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  6474. if (this.isInRange !== true) {
  6475. this.globalData._mdf = true;
  6476. this._mdf = true;
  6477. this.isInRange = true;
  6478. this.show();
  6479. }
  6480. } else if (this.isInRange !== false) {
  6481. this.globalData._mdf = true;
  6482. this.isInRange = false;
  6483. this.hide();
  6484. }
  6485. },
  6486. renderRenderable: function () {
  6487. var i;
  6488. var len = this.renderableComponents.length;
  6489. for (i = 0; i < len; i += 1) {
  6490. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  6491. }
  6492. /* this.maskManager.renderFrame(this.finalTransform.mat);
  6493. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  6494. },
  6495. sourceRectAtTime: function () {
  6496. return {
  6497. top: 0,
  6498. left: 0,
  6499. width: 100,
  6500. height: 100,
  6501. };
  6502. },
  6503. getLayerSize: function () {
  6504. if (this.data.ty === 5) {
  6505. return { w: this.data.textData.width, h: this.data.textData.height };
  6506. }
  6507. return { w: this.data.width, h: this.data.height };
  6508. },
  6509. };
  6510. const getBlendMode = (function () {
  6511. var blendModeEnums = {
  6512. 0: 'source-over',
  6513. 1: 'multiply',
  6514. 2: 'screen',
  6515. 3: 'overlay',
  6516. 4: 'darken',
  6517. 5: 'lighten',
  6518. 6: 'color-dodge',
  6519. 7: 'color-burn',
  6520. 8: 'hard-light',
  6521. 9: 'soft-light',
  6522. 10: 'difference',
  6523. 11: 'exclusion',
  6524. 12: 'hue',
  6525. 13: 'saturation',
  6526. 14: 'color',
  6527. 15: 'luminosity',
  6528. };
  6529. return function (mode) {
  6530. return blendModeEnums[mode] || '';
  6531. };
  6532. }());
  6533. function SliderEffect(data, elem, container) {
  6534. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6535. }
  6536. function AngleEffect(data, elem, container) {
  6537. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6538. }
  6539. function ColorEffect(data, elem, container) {
  6540. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6541. }
  6542. function PointEffect(data, elem, container) {
  6543. this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container);
  6544. }
  6545. function LayerIndexEffect(data, elem, container) {
  6546. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6547. }
  6548. function MaskIndexEffect(data, elem, container) {
  6549. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6550. }
  6551. function CheckboxEffect(data, elem, container) {
  6552. this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container);
  6553. }
  6554. function NoValueEffect() {
  6555. this.p = {};
  6556. }
  6557. function EffectsManager(data, element) {
  6558. var effects = data.ef || [];
  6559. this.effectElements = [];
  6560. var i;
  6561. var len = effects.length;
  6562. var effectItem;
  6563. for (i = 0; i < len; i += 1) {
  6564. effectItem = new GroupEffect(effects[i], element);
  6565. this.effectElements.push(effectItem);
  6566. }
  6567. }
  6568. function GroupEffect(data, element) {
  6569. this.init(data, element);
  6570. }
  6571. extendPrototype([DynamicPropertyContainer], GroupEffect);
  6572. GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties;
  6573. GroupEffect.prototype.init = function (data, element) {
  6574. this.data = data;
  6575. this.effectElements = [];
  6576. this.initDynamicPropertyContainer(element);
  6577. var i;
  6578. var len = this.data.ef.length;
  6579. var eff;
  6580. var effects = this.data.ef;
  6581. for (i = 0; i < len; i += 1) {
  6582. eff = null;
  6583. switch (effects[i].ty) {
  6584. case 0:
  6585. eff = new SliderEffect(effects[i], element, this);
  6586. break;
  6587. case 1:
  6588. eff = new AngleEffect(effects[i], element, this);
  6589. break;
  6590. case 2:
  6591. eff = new ColorEffect(effects[i], element, this);
  6592. break;
  6593. case 3:
  6594. eff = new PointEffect(effects[i], element, this);
  6595. break;
  6596. case 4:
  6597. case 7:
  6598. eff = new CheckboxEffect(effects[i], element, this);
  6599. break;
  6600. case 10:
  6601. eff = new LayerIndexEffect(effects[i], element, this);
  6602. break;
  6603. case 11:
  6604. eff = new MaskIndexEffect(effects[i], element, this);
  6605. break;
  6606. case 5:
  6607. eff = new EffectsManager(effects[i], element, this);
  6608. break;
  6609. // case 6:
  6610. default:
  6611. eff = new NoValueEffect(effects[i], element, this);
  6612. break;
  6613. }
  6614. if (eff) {
  6615. this.effectElements.push(eff);
  6616. }
  6617. }
  6618. };
  6619. function BaseElement() {
  6620. }
  6621. BaseElement.prototype = {
  6622. checkMasks: function () {
  6623. if (!this.data.hasMask) {
  6624. return false;
  6625. }
  6626. var i = 0;
  6627. var len = this.data.masksProperties.length;
  6628. while (i < len) {
  6629. if ((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) {
  6630. return true;
  6631. }
  6632. i += 1;
  6633. }
  6634. return false;
  6635. },
  6636. initExpressions: function () {
  6637. const expressionsInterfaces = getExpressionInterfaces();
  6638. if (!expressionsInterfaces) {
  6639. return;
  6640. }
  6641. const LayerExpressionInterface = expressionsInterfaces('layer');
  6642. const EffectsExpressionInterface = expressionsInterfaces('effects');
  6643. const ShapeExpressionInterface = expressionsInterfaces('shape');
  6644. const TextExpressionInterface = expressionsInterfaces('text');
  6645. const CompExpressionInterface = expressionsInterfaces('comp');
  6646. this.layerInterface = LayerExpressionInterface(this);
  6647. if (this.data.hasMask && this.maskManager) {
  6648. this.layerInterface.registerMaskInterface(this.maskManager);
  6649. }
  6650. var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this, this.layerInterface);
  6651. this.layerInterface.registerEffectsInterface(effectsInterface);
  6652. if (this.data.ty === 0 || this.data.xt) {
  6653. this.compInterface = CompExpressionInterface(this);
  6654. } else if (this.data.ty === 4) {
  6655. this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface);
  6656. this.layerInterface.content = this.layerInterface.shapeInterface;
  6657. } else if (this.data.ty === 5) {
  6658. this.layerInterface.textInterface = TextExpressionInterface(this);
  6659. this.layerInterface.text = this.layerInterface.textInterface;
  6660. }
  6661. },
  6662. setBlendMode: function () {
  6663. var blendModeValue = getBlendMode(this.data.bm);
  6664. var elem = this.baseElement || this.layerElement;
  6665. elem.style['mix-blend-mode'] = blendModeValue;
  6666. },
  6667. initBaseData: function (data, globalData, comp) {
  6668. this.globalData = globalData;
  6669. this.comp = comp;
  6670. this.data = data;
  6671. this.layerId = createElementID();
  6672. // Stretch factor for old animations missing this property.
  6673. if (!this.data.sr) {
  6674. this.data.sr = 1;
  6675. }
  6676. // effects manager
  6677. this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties);
  6678. },
  6679. getType: function () {
  6680. return this.type;
  6681. },
  6682. sourceRectAtTime: function () {},
  6683. };
  6684. /**
  6685. * @file
  6686. * Handles element's layer frame update.
  6687. * Checks layer in point and out point
  6688. *
  6689. */
  6690. function FrameElement() {}
  6691. FrameElement.prototype = {
  6692. /**
  6693. * @function
  6694. * Initializes frame related properties.
  6695. *
  6696. */
  6697. initFrame: function () {
  6698. // set to true when inpoint is rendered
  6699. this._isFirstFrame = false;
  6700. // list of animated properties
  6701. this.dynamicProperties = [];
  6702. // If layer has been modified in current tick this will be true
  6703. this._mdf = false;
  6704. },
  6705. /**
  6706. * @function
  6707. * Calculates all dynamic values
  6708. *
  6709. * @param {number} num
  6710. * current frame number in Layer's time
  6711. * @param {boolean} isVisible
  6712. * if layers is currently in range
  6713. *
  6714. */
  6715. prepareProperties: function (num, isVisible) {
  6716. var i;
  6717. var len = this.dynamicProperties.length;
  6718. for (i = 0; i < len; i += 1) {
  6719. if (isVisible || (this._isParent && this.dynamicProperties[i].propType === 'transform')) {
  6720. this.dynamicProperties[i].getValue();
  6721. if (this.dynamicProperties[i]._mdf) {
  6722. this.globalData._mdf = true;
  6723. this._mdf = true;
  6724. }
  6725. }
  6726. }
  6727. },
  6728. addDynamicProperty: function (prop) {
  6729. if (this.dynamicProperties.indexOf(prop) === -1) {
  6730. this.dynamicProperties.push(prop);
  6731. }
  6732. },
  6733. };
  6734. function FootageElement(data, globalData, comp) {
  6735. this.initFrame();
  6736. this.initRenderable();
  6737. this.assetData = globalData.getAssetData(data.refId);
  6738. this.footageData = globalData.imageLoader.getAsset(this.assetData);
  6739. this.initBaseData(data, globalData, comp);
  6740. }
  6741. FootageElement.prototype.prepareFrame = function () {
  6742. };
  6743. extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement);
  6744. FootageElement.prototype.getBaseElement = function () {
  6745. return null;
  6746. };
  6747. FootageElement.prototype.renderFrame = function () {
  6748. };
  6749. FootageElement.prototype.destroy = function () {
  6750. };
  6751. FootageElement.prototype.initExpressions = function () {
  6752. const expressionsInterfaces = getExpressionInterfaces();
  6753. if (!expressionsInterfaces) {
  6754. return;
  6755. }
  6756. const FootageInterface = expressionsInterfaces('footage');
  6757. this.layerInterface = FootageInterface(this);
  6758. };
  6759. FootageElement.prototype.getFootageData = function () {
  6760. return this.footageData;
  6761. };
  6762. function AudioElement(data, globalData, comp) {
  6763. this.initFrame();
  6764. this.initRenderable();
  6765. this.assetData = globalData.getAssetData(data.refId);
  6766. this.initBaseData(data, globalData, comp);
  6767. this._isPlaying = false;
  6768. this._canPlay = false;
  6769. var assetPath = this.globalData.getAssetsPath(this.assetData);
  6770. this.audio = this.globalData.audioController.createAudio(assetPath);
  6771. this._currentTime = 0;
  6772. this.globalData.audioController.addAudio(this);
  6773. this._volumeMultiplier = 1;
  6774. this._volume = 1;
  6775. this._previousVolume = null;
  6776. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  6777. this.lv = PropertyFactory.getProp(this, data.au && data.au.lv ? data.au.lv : { k: [100] }, 1, 0.01, this);
  6778. }
  6779. AudioElement.prototype.prepareFrame = function (num) {
  6780. this.prepareRenderableFrame(num, true);
  6781. this.prepareProperties(num, true);
  6782. if (!this.tm._placeholder) {
  6783. var timeRemapped = this.tm.v;
  6784. this._currentTime = timeRemapped;
  6785. } else {
  6786. this._currentTime = num / this.data.sr;
  6787. }
  6788. this._volume = this.lv.v[0];
  6789. var totalVolume = this._volume * this._volumeMultiplier;
  6790. if (this._previousVolume !== totalVolume) {
  6791. this._previousVolume = totalVolume;
  6792. this.audio.volume(totalVolume);
  6793. }
  6794. };
  6795. extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement);
  6796. AudioElement.prototype.renderFrame = function () {
  6797. if (this.isInRange && this._canPlay) {
  6798. if (!this._isPlaying) {
  6799. this.audio.play();
  6800. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6801. this._isPlaying = true;
  6802. } else if (!this.audio.playing()
  6803. || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1
  6804. ) {
  6805. this.audio.seek(this._currentTime / this.globalData.frameRate);
  6806. }
  6807. }
  6808. };
  6809. AudioElement.prototype.show = function () {
  6810. // this.audio.play()
  6811. };
  6812. AudioElement.prototype.hide = function () {
  6813. this.audio.pause();
  6814. this._isPlaying = false;
  6815. };
  6816. AudioElement.prototype.pause = function () {
  6817. this.audio.pause();
  6818. this._isPlaying = false;
  6819. this._canPlay = false;
  6820. };
  6821. AudioElement.prototype.resume = function () {
  6822. this._canPlay = true;
  6823. };
  6824. AudioElement.prototype.setRate = function (rateValue) {
  6825. this.audio.rate(rateValue);
  6826. };
  6827. AudioElement.prototype.volume = function (volumeValue) {
  6828. this._volumeMultiplier = volumeValue;
  6829. this._previousVolume = volumeValue * this._volume;
  6830. this.audio.volume(this._previousVolume);
  6831. };
  6832. AudioElement.prototype.getBaseElement = function () {
  6833. return null;
  6834. };
  6835. AudioElement.prototype.destroy = function () {
  6836. };
  6837. AudioElement.prototype.sourceRectAtTime = function () {
  6838. };
  6839. AudioElement.prototype.initExpressions = function () {
  6840. };
  6841. function BaseRenderer() {}
  6842. BaseRenderer.prototype.checkLayers = function (num) {
  6843. var i;
  6844. var len = this.layers.length;
  6845. var data;
  6846. this.completeLayers = true;
  6847. for (i = len - 1; i >= 0; i -= 1) {
  6848. if (!this.elements[i]) {
  6849. data = this.layers[i];
  6850. if (data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st)) {
  6851. this.buildItem(i);
  6852. }
  6853. }
  6854. this.completeLayers = this.elements[i] ? this.completeLayers : false;
  6855. }
  6856. this.checkPendingElements();
  6857. };
  6858. BaseRenderer.prototype.createItem = function (layer) {
  6859. switch (layer.ty) {
  6860. case 2:
  6861. return this.createImage(layer);
  6862. case 0:
  6863. return this.createComp(layer);
  6864. case 1:
  6865. return this.createSolid(layer);
  6866. case 3:
  6867. return this.createNull(layer);
  6868. case 4:
  6869. return this.createShape(layer);
  6870. case 5:
  6871. return this.createText(layer);
  6872. case 6:
  6873. return this.createAudio(layer);
  6874. case 13:
  6875. return this.createCamera(layer);
  6876. case 15:
  6877. return this.createFootage(layer);
  6878. default:
  6879. return this.createNull(layer);
  6880. }
  6881. };
  6882. BaseRenderer.prototype.createCamera = function () {
  6883. throw new Error('You\'re using a 3d camera. Try the html renderer.');
  6884. };
  6885. BaseRenderer.prototype.createAudio = function (data) {
  6886. return new AudioElement(data, this.globalData, this);
  6887. };
  6888. BaseRenderer.prototype.createFootage = function (data) {
  6889. return new FootageElement(data, this.globalData, this);
  6890. };
  6891. BaseRenderer.prototype.buildAllItems = function () {
  6892. var i;
  6893. var len = this.layers.length;
  6894. for (i = 0; i < len; i += 1) {
  6895. this.buildItem(i);
  6896. }
  6897. this.checkPendingElements();
  6898. };
  6899. BaseRenderer.prototype.includeLayers = function (newLayers) {
  6900. this.completeLayers = false;
  6901. var i;
  6902. var len = newLayers.length;
  6903. var j;
  6904. var jLen = this.layers.length;
  6905. for (i = 0; i < len; i += 1) {
  6906. j = 0;
  6907. while (j < jLen) {
  6908. if (this.layers[j].id === newLayers[i].id) {
  6909. this.layers[j] = newLayers[i];
  6910. break;
  6911. }
  6912. j += 1;
  6913. }
  6914. }
  6915. };
  6916. BaseRenderer.prototype.setProjectInterface = function (pInterface) {
  6917. this.globalData.projectInterface = pInterface;
  6918. };
  6919. BaseRenderer.prototype.initItems = function () {
  6920. if (!this.globalData.progressiveLoad) {
  6921. this.buildAllItems();
  6922. }
  6923. };
  6924. BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) {
  6925. var elements = this.elements;
  6926. var layers = this.layers;
  6927. var i = 0;
  6928. var len = layers.length;
  6929. while (i < len) {
  6930. if (layers[i].ind == parentName) { // eslint-disable-line eqeqeq
  6931. if (!elements[i] || elements[i] === true) {
  6932. this.buildItem(i);
  6933. this.addPendingElement(element);
  6934. } else {
  6935. hierarchy.push(elements[i]);
  6936. elements[i].setAsParent();
  6937. if (layers[i].parent !== undefined) {
  6938. this.buildElementParenting(element, layers[i].parent, hierarchy);
  6939. } else {
  6940. element.setHierarchy(hierarchy);
  6941. }
  6942. }
  6943. }
  6944. i += 1;
  6945. }
  6946. };
  6947. BaseRenderer.prototype.addPendingElement = function (element) {
  6948. this.pendingElements.push(element);
  6949. };
  6950. BaseRenderer.prototype.searchExtraCompositions = function (assets) {
  6951. var i;
  6952. var len = assets.length;
  6953. for (i = 0; i < len; i += 1) {
  6954. if (assets[i].xt) {
  6955. var comp = this.createComp(assets[i]);
  6956. comp.initExpressions();
  6957. this.globalData.projectInterface.registerComposition(comp);
  6958. }
  6959. }
  6960. };
  6961. BaseRenderer.prototype.getElementById = function (ind) {
  6962. var i;
  6963. var len = this.elements.length;
  6964. for (i = 0; i < len; i += 1) {
  6965. if (this.elements[i].data.ind === ind) {
  6966. return this.elements[i];
  6967. }
  6968. }
  6969. return null;
  6970. };
  6971. BaseRenderer.prototype.getElementByPath = function (path) {
  6972. var pathValue = path.shift();
  6973. var element;
  6974. if (typeof pathValue === 'number') {
  6975. element = this.elements[pathValue];
  6976. } else {
  6977. var i;
  6978. var len = this.elements.length;
  6979. for (i = 0; i < len; i += 1) {
  6980. if (this.elements[i].data.nm === pathValue) {
  6981. element = this.elements[i];
  6982. break;
  6983. }
  6984. }
  6985. }
  6986. if (path.length === 0) {
  6987. return element;
  6988. }
  6989. return element.getElementByPath(path);
  6990. };
  6991. BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) {
  6992. this.globalData.fontManager = new FontManager();
  6993. this.globalData.slotManager = slotFactory(animData);
  6994. this.globalData.fontManager.addChars(animData.chars);
  6995. this.globalData.fontManager.addFonts(animData.fonts, fontsContainer);
  6996. this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem);
  6997. this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem);
  6998. this.globalData.imageLoader = this.animationItem.imagePreloader;
  6999. this.globalData.audioController = this.animationItem.audioController;
  7000. this.globalData.frameId = 0;
  7001. this.globalData.frameRate = animData.fr;
  7002. this.globalData.nm = animData.nm;
  7003. this.globalData.compSize = {
  7004. w: animData.w,
  7005. h: animData.h,
  7006. };
  7007. };
  7008. var effectTypes = {
  7009. TRANSFORM_EFFECT: 'transformEFfect',
  7010. };
  7011. function TransformElement() {}
  7012. TransformElement.prototype = {
  7013. initTransform: function () {
  7014. var mat = new Matrix();
  7015. this.finalTransform = {
  7016. mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : { o: 0 },
  7017. _matMdf: false,
  7018. _localMatMdf: false,
  7019. _opMdf: false,
  7020. mat: mat,
  7021. localMat: mat,
  7022. localOpacity: 1,
  7023. };
  7024. if (this.data.ao) {
  7025. this.finalTransform.mProp.autoOriented = true;
  7026. }
  7027. // TODO: check TYPE 11: Guided elements
  7028. if (this.data.ty !== 11) {
  7029. // this.createElements();
  7030. }
  7031. },
  7032. renderTransform: function () {
  7033. this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame;
  7034. this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame;
  7035. if (this.hierarchy) {
  7036. var mat;
  7037. var finalMat = this.finalTransform.mat;
  7038. var i = 0;
  7039. var len = this.hierarchy.length;
  7040. // Checking if any of the transformation matrices in the hierarchy chain has changed.
  7041. if (!this.finalTransform._matMdf) {
  7042. while (i < len) {
  7043. if (this.hierarchy[i].finalTransform.mProp._mdf) {
  7044. this.finalTransform._matMdf = true;
  7045. break;
  7046. }
  7047. i += 1;
  7048. }
  7049. }
  7050. if (this.finalTransform._matMdf) {
  7051. mat = this.finalTransform.mProp.v.props;
  7052. finalMat.cloneFromProps(mat);
  7053. for (i = 0; i < len; i += 1) {
  7054. finalMat.multiply(this.hierarchy[i].finalTransform.mProp.v);
  7055. }
  7056. }
  7057. }
  7058. if (!this.localTransforms || this.finalTransform._matMdf) {
  7059. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7060. }
  7061. if (this.finalTransform._opMdf) {
  7062. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7063. }
  7064. },
  7065. renderLocalTransform: function () {
  7066. if (this.localTransforms) {
  7067. var i = 0;
  7068. var len = this.localTransforms.length;
  7069. this.finalTransform._localMatMdf = this.finalTransform._matMdf;
  7070. if (!this.finalTransform._localMatMdf || !this.finalTransform._opMdf) {
  7071. while (i < len) {
  7072. if (this.localTransforms[i]._mdf) {
  7073. this.finalTransform._localMatMdf = true;
  7074. }
  7075. if (this.localTransforms[i]._opMdf && !this.finalTransform._opMdf) {
  7076. this.finalTransform.localOpacity = this.finalTransform.mProp.o.v;
  7077. this.finalTransform._opMdf = true;
  7078. }
  7079. i += 1;
  7080. }
  7081. }
  7082. if (this.finalTransform._localMatMdf) {
  7083. var localMat = this.finalTransform.localMat;
  7084. this.localTransforms[0].matrix.clone(localMat);
  7085. for (i = 1; i < len; i += 1) {
  7086. var lmat = this.localTransforms[i].matrix;
  7087. localMat.multiply(lmat);
  7088. }
  7089. localMat.multiply(this.finalTransform.mat);
  7090. }
  7091. if (this.finalTransform._opMdf) {
  7092. var localOp = this.finalTransform.localOpacity;
  7093. for (i = 0; i < len; i += 1) {
  7094. localOp *= this.localTransforms[i].opacity * 0.01;
  7095. }
  7096. this.finalTransform.localOpacity = localOp;
  7097. }
  7098. }
  7099. },
  7100. searchEffectTransforms: function () {
  7101. if (this.renderableEffectsManager) {
  7102. var transformEffects = this.renderableEffectsManager.getEffects(effectTypes.TRANSFORM_EFFECT);
  7103. if (transformEffects.length) {
  7104. this.localTransforms = [];
  7105. this.finalTransform.localMat = new Matrix();
  7106. var i = 0;
  7107. var len = transformEffects.length;
  7108. for (i = 0; i < len; i += 1) {
  7109. this.localTransforms.push(transformEffects[i]);
  7110. }
  7111. }
  7112. }
  7113. },
  7114. globalToLocal: function (pt) {
  7115. var transforms = [];
  7116. transforms.push(this.finalTransform);
  7117. var flag = true;
  7118. var comp = this.comp;
  7119. while (flag) {
  7120. if (comp.finalTransform) {
  7121. if (comp.data.hasMask) {
  7122. transforms.splice(0, 0, comp.finalTransform);
  7123. }
  7124. comp = comp.comp;
  7125. } else {
  7126. flag = false;
  7127. }
  7128. }
  7129. var i;
  7130. var len = transforms.length;
  7131. var ptNew;
  7132. for (i = 0; i < len; i += 1) {
  7133. ptNew = transforms[i].mat.applyToPointArray(0, 0, 0);
  7134. // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]);
  7135. pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0];
  7136. }
  7137. return pt;
  7138. },
  7139. mHelper: new Matrix(),
  7140. };
  7141. function MaskElement(data, element, globalData) {
  7142. this.data = data;
  7143. this.element = element;
  7144. this.globalData = globalData;
  7145. this.storedData = [];
  7146. this.masksProperties = this.data.masksProperties || [];
  7147. this.maskElement = null;
  7148. var defs = this.globalData.defs;
  7149. var i;
  7150. var len = this.masksProperties ? this.masksProperties.length : 0;
  7151. this.viewData = createSizedArray(len);
  7152. this.solidPath = '';
  7153. var path;
  7154. var properties = this.masksProperties;
  7155. var count = 0;
  7156. var currentMasks = [];
  7157. var j;
  7158. var jLen;
  7159. var layerId = createElementID();
  7160. var rect;
  7161. var expansor;
  7162. var feMorph;
  7163. var x;
  7164. var maskType = 'clipPath';
  7165. var maskRef = 'clip-path';
  7166. for (i = 0; i < len; i += 1) {
  7167. if ((properties[i].mode !== 'a' && properties[i].mode !== 'n') || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) {
  7168. maskType = 'mask';
  7169. maskRef = 'mask';
  7170. }
  7171. if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) {
  7172. rect = createNS('rect');
  7173. rect.setAttribute('fill', '#ffffff');
  7174. rect.setAttribute('width', this.element.comp.data.w || 0);
  7175. rect.setAttribute('height', this.element.comp.data.h || 0);
  7176. currentMasks.push(rect);
  7177. } else {
  7178. rect = null;
  7179. }
  7180. path = createNS('path');
  7181. if (properties[i].mode === 'n') {
  7182. // TODO move this to a factory or to a constructor
  7183. this.viewData[i] = {
  7184. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7185. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7186. elem: path,
  7187. lastPath: '',
  7188. };
  7189. defs.appendChild(path);
  7190. } else {
  7191. count += 1;
  7192. path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7193. path.setAttribute('clip-rule', 'nonzero');
  7194. var filterID;
  7195. if (properties[i].x.k !== 0) {
  7196. maskType = 'mask';
  7197. maskRef = 'mask';
  7198. x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element);
  7199. filterID = createElementID();
  7200. expansor = createNS('filter');
  7201. expansor.setAttribute('id', filterID);
  7202. feMorph = createNS('feMorphology');
  7203. feMorph.setAttribute('operator', 'erode');
  7204. feMorph.setAttribute('in', 'SourceGraphic');
  7205. feMorph.setAttribute('radius', '0');
  7206. expansor.appendChild(feMorph);
  7207. defs.appendChild(expansor);
  7208. path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff');
  7209. } else {
  7210. feMorph = null;
  7211. x = null;
  7212. }
  7213. // TODO move this to a factory or to a constructor
  7214. this.storedData[i] = {
  7215. elem: path,
  7216. x: x,
  7217. expan: feMorph,
  7218. lastPath: '',
  7219. lastOperator: '',
  7220. filterId: filterID,
  7221. lastRadius: 0,
  7222. };
  7223. if (properties[i].mode === 'i') {
  7224. jLen = currentMasks.length;
  7225. var g = createNS('g');
  7226. for (j = 0; j < jLen; j += 1) {
  7227. g.appendChild(currentMasks[j]);
  7228. }
  7229. var mask = createNS('mask');
  7230. mask.setAttribute('mask-type', 'alpha');
  7231. mask.setAttribute('id', layerId + '_' + count);
  7232. mask.appendChild(path);
  7233. defs.appendChild(mask);
  7234. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + layerId + '_' + count + ')');
  7235. currentMasks.length = 0;
  7236. currentMasks.push(g);
  7237. } else {
  7238. currentMasks.push(path);
  7239. }
  7240. if (properties[i].inv && !this.solidPath) {
  7241. this.solidPath = this.createLayerSolidPath();
  7242. }
  7243. // TODO move this to a factory or to a constructor
  7244. this.viewData[i] = {
  7245. elem: path,
  7246. lastPath: '',
  7247. op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element),
  7248. prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3),
  7249. invRect: rect,
  7250. };
  7251. if (!this.viewData[i].prop.k) {
  7252. this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]);
  7253. }
  7254. }
  7255. }
  7256. this.maskElement = createNS(maskType);
  7257. len = currentMasks.length;
  7258. for (i = 0; i < len; i += 1) {
  7259. this.maskElement.appendChild(currentMasks[i]);
  7260. }
  7261. if (count > 0) {
  7262. this.maskElement.setAttribute('id', layerId);
  7263. this.element.maskedElement.setAttribute(maskRef, 'url(' + getLocationHref() + '#' + layerId + ')');
  7264. defs.appendChild(this.maskElement);
  7265. }
  7266. if (this.viewData.length) {
  7267. this.element.addRenderableComponent(this);
  7268. }
  7269. }
  7270. MaskElement.prototype.getMaskProperty = function (pos) {
  7271. return this.viewData[pos].prop;
  7272. };
  7273. MaskElement.prototype.renderFrame = function (isFirstFrame) {
  7274. var finalMat = this.element.finalTransform.mat;
  7275. var i;
  7276. var len = this.masksProperties.length;
  7277. for (i = 0; i < len; i += 1) {
  7278. if (this.viewData[i].prop._mdf || isFirstFrame) {
  7279. this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]);
  7280. }
  7281. if (this.viewData[i].op._mdf || isFirstFrame) {
  7282. this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v);
  7283. }
  7284. if (this.masksProperties[i].mode !== 'n') {
  7285. if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) {
  7286. this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS());
  7287. }
  7288. if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) {
  7289. var feMorph = this.storedData[i].expan;
  7290. if (this.storedData[i].x.v < 0) {
  7291. if (this.storedData[i].lastOperator !== 'erode') {
  7292. this.storedData[i].lastOperator = 'erode';
  7293. this.storedData[i].elem.setAttribute('filter', 'url(' + getLocationHref() + '#' + this.storedData[i].filterId + ')');
  7294. }
  7295. feMorph.setAttribute('radius', -this.storedData[i].x.v);
  7296. } else {
  7297. if (this.storedData[i].lastOperator !== 'dilate') {
  7298. this.storedData[i].lastOperator = 'dilate';
  7299. this.storedData[i].elem.setAttribute('filter', null);
  7300. }
  7301. this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2);
  7302. }
  7303. }
  7304. }
  7305. }
  7306. };
  7307. MaskElement.prototype.getMaskelement = function () {
  7308. return this.maskElement;
  7309. };
  7310. MaskElement.prototype.createLayerSolidPath = function () {
  7311. var path = 'M0,0 ';
  7312. path += ' h' + this.globalData.compSize.w;
  7313. path += ' v' + this.globalData.compSize.h;
  7314. path += ' h-' + this.globalData.compSize.w;
  7315. path += ' v-' + this.globalData.compSize.h + ' ';
  7316. return path;
  7317. };
  7318. MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) {
  7319. var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1];
  7320. var i;
  7321. var len;
  7322. len = pathNodes._length;
  7323. for (i = 1; i < len; i += 1) {
  7324. // 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];
  7325. 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];
  7326. }
  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. if (pathNodes.c && len > 1) {
  7329. 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];
  7330. }
  7331. // pathNodes.__renderedString = pathString;
  7332. if (viewData.lastPath !== pathString) {
  7333. var pathShapeValue = '';
  7334. if (viewData.elem) {
  7335. if (pathNodes.c) {
  7336. pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString;
  7337. }
  7338. viewData.elem.setAttribute('d', pathShapeValue);
  7339. }
  7340. viewData.lastPath = pathString;
  7341. }
  7342. };
  7343. MaskElement.prototype.destroy = function () {
  7344. this.element = null;
  7345. this.globalData = null;
  7346. this.maskElement = null;
  7347. this.data = null;
  7348. this.masksProperties = null;
  7349. };
  7350. const filtersFactory = (function () {
  7351. var ob = {};
  7352. ob.createFilter = createFilter;
  7353. ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter;
  7354. function createFilter(filId, skipCoordinates) {
  7355. var fil = createNS('filter');
  7356. fil.setAttribute('id', filId);
  7357. if (skipCoordinates !== true) {
  7358. fil.setAttribute('filterUnits', 'objectBoundingBox');
  7359. fil.setAttribute('x', '0%');
  7360. fil.setAttribute('y', '0%');
  7361. fil.setAttribute('width', '100%');
  7362. fil.setAttribute('height', '100%');
  7363. }
  7364. return fil;
  7365. }
  7366. function createAlphaToLuminanceFilter() {
  7367. var feColorMatrix = createNS('feColorMatrix');
  7368. feColorMatrix.setAttribute('type', 'matrix');
  7369. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  7370. feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1');
  7371. return feColorMatrix;
  7372. }
  7373. return ob;
  7374. }());
  7375. const featureSupport = (function () {
  7376. var ob = {
  7377. maskType: true,
  7378. svgLumaHidden: true,
  7379. offscreenCanvas: typeof OffscreenCanvas !== 'undefined',
  7380. };
  7381. 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)) {
  7382. ob.maskType = false;
  7383. }
  7384. if (/firefox/i.test(navigator.userAgent)) {
  7385. ob.svgLumaHidden = false;
  7386. }
  7387. return ob;
  7388. }());
  7389. var registeredEffects$1 = {};
  7390. var idPrefix = 'filter_result_';
  7391. function SVGEffects(elem) {
  7392. var i;
  7393. var source = 'SourceGraphic';
  7394. var len = elem.data.ef ? elem.data.ef.length : 0;
  7395. var filId = createElementID();
  7396. var fil = filtersFactory.createFilter(filId, true);
  7397. var count = 0;
  7398. this.filters = [];
  7399. var filterManager;
  7400. for (i = 0; i < len; i += 1) {
  7401. filterManager = null;
  7402. var type = elem.data.ef[i].ty;
  7403. if (registeredEffects$1[type]) {
  7404. var Effect = registeredEffects$1[type].effect;
  7405. filterManager = new Effect(fil, elem.effectsManager.effectElements[i], elem, idPrefix + count, source);
  7406. source = idPrefix + count;
  7407. if (registeredEffects$1[type].countsAsEffect) {
  7408. count += 1;
  7409. }
  7410. }
  7411. if (filterManager) {
  7412. this.filters.push(filterManager);
  7413. }
  7414. }
  7415. if (count) {
  7416. elem.globalData.defs.appendChild(fil);
  7417. elem.layerElement.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7418. }
  7419. if (this.filters.length) {
  7420. elem.addRenderableComponent(this);
  7421. }
  7422. }
  7423. SVGEffects.prototype.renderFrame = function (_isFirstFrame) {
  7424. var i;
  7425. var len = this.filters.length;
  7426. for (i = 0; i < len; i += 1) {
  7427. this.filters[i].renderFrame(_isFirstFrame);
  7428. }
  7429. };
  7430. SVGEffects.prototype.getEffects = function (type) {
  7431. var i;
  7432. var len = this.filters.length;
  7433. var effects = [];
  7434. for (i = 0; i < len; i += 1) {
  7435. if (this.filters[i].type === type) {
  7436. effects.push(this.filters[i]);
  7437. }
  7438. }
  7439. return effects;
  7440. };
  7441. function registerEffect$1(id, effect, countsAsEffect) {
  7442. registeredEffects$1[id] = {
  7443. effect,
  7444. countsAsEffect,
  7445. };
  7446. }
  7447. function SVGBaseElement() {
  7448. }
  7449. SVGBaseElement.prototype = {
  7450. initRendererElement: function () {
  7451. this.layerElement = createNS('g');
  7452. },
  7453. createContainerElements: function () {
  7454. this.matteElement = createNS('g');
  7455. this.transformedElement = this.layerElement;
  7456. this.maskedElement = this.layerElement;
  7457. this._sizeChanged = false;
  7458. var layerElementParent = null;
  7459. // If this layer acts as a mask for the following layer
  7460. if (this.data.td) {
  7461. this.matteMasks = {};
  7462. var gg = createNS('g');
  7463. gg.setAttribute('id', this.layerId);
  7464. gg.appendChild(this.layerElement);
  7465. layerElementParent = gg;
  7466. this.globalData.defs.appendChild(gg);
  7467. } else if (this.data.tt) {
  7468. this.matteElement.appendChild(this.layerElement);
  7469. layerElementParent = this.matteElement;
  7470. this.baseElement = this.matteElement;
  7471. } else {
  7472. this.baseElement = this.layerElement;
  7473. }
  7474. if (this.data.ln) {
  7475. this.layerElement.setAttribute('id', this.data.ln);
  7476. }
  7477. if (this.data.cl) {
  7478. this.layerElement.setAttribute('class', this.data.cl);
  7479. }
  7480. // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped
  7481. if (this.data.ty === 0 && !this.data.hd) {
  7482. var cp = createNS('clipPath');
  7483. var pt = createNS('path');
  7484. pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z');
  7485. var clipId = createElementID();
  7486. cp.setAttribute('id', clipId);
  7487. cp.appendChild(pt);
  7488. this.globalData.defs.appendChild(cp);
  7489. if (this.checkMasks()) {
  7490. var cpGroup = createNS('g');
  7491. cpGroup.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7492. cpGroup.appendChild(this.layerElement);
  7493. this.transformedElement = cpGroup;
  7494. if (layerElementParent) {
  7495. layerElementParent.appendChild(this.transformedElement);
  7496. } else {
  7497. this.baseElement = this.transformedElement;
  7498. }
  7499. } else {
  7500. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + clipId + ')');
  7501. }
  7502. }
  7503. if (this.data.bm !== 0) {
  7504. this.setBlendMode();
  7505. }
  7506. },
  7507. renderElement: function () {
  7508. if (this.finalTransform._localMatMdf) {
  7509. this.transformedElement.setAttribute('transform', this.finalTransform.localMat.to2dCSS());
  7510. }
  7511. if (this.finalTransform._opMdf) {
  7512. this.transformedElement.setAttribute('opacity', this.finalTransform.localOpacity);
  7513. }
  7514. },
  7515. destroyBaseElement: function () {
  7516. this.layerElement = null;
  7517. this.matteElement = null;
  7518. this.maskManager.destroy();
  7519. },
  7520. getBaseElement: function () {
  7521. if (this.data.hd) {
  7522. return null;
  7523. }
  7524. return this.baseElement;
  7525. },
  7526. createRenderableComponents: function () {
  7527. this.maskManager = new MaskElement(this.data, this, this.globalData);
  7528. this.renderableEffectsManager = new SVGEffects(this);
  7529. this.searchEffectTransforms();
  7530. },
  7531. getMatte: function (matteType) {
  7532. // This should not be a common case. But for backward compatibility, we'll create the matte object.
  7533. // It solves animations that have two consecutive layers marked as matte masks.
  7534. // Which is an undefined behavior in AE.
  7535. if (!this.matteMasks) {
  7536. this.matteMasks = {};
  7537. }
  7538. if (!this.matteMasks[matteType]) {
  7539. var id = this.layerId + '_' + matteType;
  7540. var filId;
  7541. var fil;
  7542. var useElement;
  7543. var gg;
  7544. if (matteType === 1 || matteType === 3) {
  7545. var masker = createNS('mask');
  7546. masker.setAttribute('id', id);
  7547. masker.setAttribute('mask-type', matteType === 3 ? 'luminance' : 'alpha');
  7548. useElement = createNS('use');
  7549. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7550. masker.appendChild(useElement);
  7551. this.globalData.defs.appendChild(masker);
  7552. if (!featureSupport.maskType && matteType === 1) {
  7553. masker.setAttribute('mask-type', 'luminance');
  7554. filId = createElementID();
  7555. fil = filtersFactory.createFilter(filId);
  7556. this.globalData.defs.appendChild(fil);
  7557. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7558. gg = createNS('g');
  7559. gg.appendChild(useElement);
  7560. masker.appendChild(gg);
  7561. gg.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7562. }
  7563. } else if (matteType === 2) {
  7564. var maskGroup = createNS('mask');
  7565. maskGroup.setAttribute('id', id);
  7566. maskGroup.setAttribute('mask-type', 'alpha');
  7567. var maskGrouper = createNS('g');
  7568. maskGroup.appendChild(maskGrouper);
  7569. filId = createElementID();
  7570. fil = filtersFactory.createFilter(filId);
  7571. /// /
  7572. var feCTr = createNS('feComponentTransfer');
  7573. feCTr.setAttribute('in', 'SourceGraphic');
  7574. fil.appendChild(feCTr);
  7575. var feFunc = createNS('feFuncA');
  7576. feFunc.setAttribute('type', 'table');
  7577. feFunc.setAttribute('tableValues', '1.0 0.0');
  7578. feCTr.appendChild(feFunc);
  7579. /// /
  7580. this.globalData.defs.appendChild(fil);
  7581. var alphaRect = createNS('rect');
  7582. alphaRect.setAttribute('width', this.comp.data.w);
  7583. alphaRect.setAttribute('height', this.comp.data.h);
  7584. alphaRect.setAttribute('x', '0');
  7585. alphaRect.setAttribute('y', '0');
  7586. alphaRect.setAttribute('fill', '#ffffff');
  7587. alphaRect.setAttribute('opacity', '0');
  7588. maskGrouper.setAttribute('filter', 'url(' + getLocationHref() + '#' + filId + ')');
  7589. maskGrouper.appendChild(alphaRect);
  7590. useElement = createNS('use');
  7591. useElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#' + this.layerId);
  7592. maskGrouper.appendChild(useElement);
  7593. if (!featureSupport.maskType) {
  7594. maskGroup.setAttribute('mask-type', 'luminance');
  7595. fil.appendChild(filtersFactory.createAlphaToLuminanceFilter());
  7596. gg = createNS('g');
  7597. maskGrouper.appendChild(alphaRect);
  7598. gg.appendChild(this.layerElement);
  7599. maskGrouper.appendChild(gg);
  7600. }
  7601. this.globalData.defs.appendChild(maskGroup);
  7602. }
  7603. this.matteMasks[matteType] = id;
  7604. }
  7605. return this.matteMasks[matteType];
  7606. },
  7607. setMatte: function (id) {
  7608. if (!this.matteElement) {
  7609. return;
  7610. }
  7611. this.matteElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  7612. },
  7613. };
  7614. /**
  7615. * @file
  7616. * Handles AE's layer parenting property.
  7617. *
  7618. */
  7619. function HierarchyElement() {}
  7620. HierarchyElement.prototype = {
  7621. /**
  7622. * @function
  7623. * Initializes hierarchy properties
  7624. *
  7625. */
  7626. initHierarchy: function () {
  7627. // element's parent list
  7628. this.hierarchy = [];
  7629. // if element is parent of another layer _isParent will be true
  7630. this._isParent = false;
  7631. this.checkParenting();
  7632. },
  7633. /**
  7634. * @function
  7635. * Sets layer's hierarchy.
  7636. * @param {array} hierarch
  7637. * layer's parent list
  7638. *
  7639. */
  7640. setHierarchy: function (hierarchy) {
  7641. this.hierarchy = hierarchy;
  7642. },
  7643. /**
  7644. * @function
  7645. * Sets layer as parent.
  7646. *
  7647. */
  7648. setAsParent: function () {
  7649. this._isParent = true;
  7650. },
  7651. /**
  7652. * @function
  7653. * Searches layer's parenting chain
  7654. *
  7655. */
  7656. checkParenting: function () {
  7657. if (this.data.parent !== undefined) {
  7658. this.comp.buildElementParenting(this, this.data.parent, []);
  7659. }
  7660. },
  7661. };
  7662. function RenderableDOMElement() {}
  7663. (function () {
  7664. var _prototype = {
  7665. initElement: function (data, globalData, comp) {
  7666. this.initFrame();
  7667. this.initBaseData(data, globalData, comp);
  7668. this.initTransform(data, globalData, comp);
  7669. this.initHierarchy();
  7670. this.initRenderable();
  7671. this.initRendererElement();
  7672. this.createContainerElements();
  7673. this.createRenderableComponents();
  7674. this.createContent();
  7675. this.hide();
  7676. },
  7677. hide: function () {
  7678. // console.log('HIDE', this);
  7679. if (!this.hidden && (!this.isInRange || this.isTransparent)) {
  7680. var elem = this.baseElement || this.layerElement;
  7681. elem.style.display = 'none';
  7682. this.hidden = true;
  7683. }
  7684. },
  7685. show: function () {
  7686. // console.log('SHOW', this);
  7687. if (this.isInRange && !this.isTransparent) {
  7688. if (!this.data.hd) {
  7689. var elem = this.baseElement || this.layerElement;
  7690. elem.style.display = 'block';
  7691. }
  7692. this.hidden = false;
  7693. this._isFirstFrame = true;
  7694. }
  7695. },
  7696. renderFrame: function () {
  7697. // If it is exported as hidden (data.hd === true) no need to render
  7698. // If it is not visible no need to render
  7699. if (this.data.hd || this.hidden) {
  7700. return;
  7701. }
  7702. this.renderTransform();
  7703. this.renderRenderable();
  7704. this.renderLocalTransform();
  7705. this.renderElement();
  7706. this.renderInnerContent();
  7707. if (this._isFirstFrame) {
  7708. this._isFirstFrame = false;
  7709. }
  7710. },
  7711. renderInnerContent: function () {},
  7712. prepareFrame: function (num) {
  7713. this._mdf = false;
  7714. this.prepareRenderableFrame(num);
  7715. this.prepareProperties(num, this.isInRange);
  7716. this.checkTransparency();
  7717. },
  7718. destroy: function () {
  7719. this.innerElem = null;
  7720. this.destroyBaseElement();
  7721. },
  7722. };
  7723. extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement);
  7724. }());
  7725. function IImageElement(data, globalData, comp) {
  7726. this.assetData = globalData.getAssetData(data.refId);
  7727. if (this.assetData && this.assetData.sid) {
  7728. this.assetData = globalData.slotManager.getProp(this.assetData);
  7729. }
  7730. this.initElement(data, globalData, comp);
  7731. this.sourceRect = {
  7732. top: 0, left: 0, width: this.assetData.w, height: this.assetData.h,
  7733. };
  7734. }
  7735. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  7736. IImageElement.prototype.createContent = function () {
  7737. var assetPath = this.globalData.getAssetsPath(this.assetData);
  7738. this.innerElem = createNS('image');
  7739. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  7740. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  7741. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  7742. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  7743. this.layerElement.appendChild(this.innerElem);
  7744. };
  7745. IImageElement.prototype.sourceRectAtTime = function () {
  7746. return this.sourceRect;
  7747. };
  7748. function ProcessedElement(element, position) {
  7749. this.elem = element;
  7750. this.pos = position;
  7751. }
  7752. function IShapeElement() {
  7753. }
  7754. IShapeElement.prototype = {
  7755. addShapeToModifiers: function (data) {
  7756. var i;
  7757. var len = this.shapeModifiers.length;
  7758. for (i = 0; i < len; i += 1) {
  7759. this.shapeModifiers[i].addShape(data);
  7760. }
  7761. },
  7762. isShapeInAnimatedModifiers: function (data) {
  7763. var i = 0;
  7764. var len = this.shapeModifiers.length;
  7765. while (i < len) {
  7766. if (this.shapeModifiers[i].isAnimatedWithShape(data)) {
  7767. return true;
  7768. }
  7769. }
  7770. return false;
  7771. },
  7772. renderModifiers: function () {
  7773. if (!this.shapeModifiers.length) {
  7774. return;
  7775. }
  7776. var i;
  7777. var len = this.shapes.length;
  7778. for (i = 0; i < len; i += 1) {
  7779. this.shapes[i].sh.reset();
  7780. }
  7781. len = this.shapeModifiers.length;
  7782. var shouldBreakProcess;
  7783. for (i = len - 1; i >= 0; i -= 1) {
  7784. shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame);
  7785. // workaround to fix cases where a repeater resets the shape so the following processes get called twice
  7786. // TODO: find a better solution for this
  7787. if (shouldBreakProcess) {
  7788. break;
  7789. }
  7790. }
  7791. },
  7792. searchProcessedElement: function (elem) {
  7793. var elements = this.processedElements;
  7794. var i = 0;
  7795. var len = elements.length;
  7796. while (i < len) {
  7797. if (elements[i].elem === elem) {
  7798. return elements[i].pos;
  7799. }
  7800. i += 1;
  7801. }
  7802. return 0;
  7803. },
  7804. addProcessedElement: function (elem, pos) {
  7805. var elements = this.processedElements;
  7806. var i = elements.length;
  7807. while (i) {
  7808. i -= 1;
  7809. if (elements[i].elem === elem) {
  7810. elements[i].pos = pos;
  7811. return;
  7812. }
  7813. }
  7814. elements.push(new ProcessedElement(elem, pos));
  7815. },
  7816. prepareFrame: function (num) {
  7817. this.prepareRenderableFrame(num);
  7818. this.prepareProperties(num, this.isInRange);
  7819. },
  7820. };
  7821. const lineCapEnum = {
  7822. 1: 'butt',
  7823. 2: 'round',
  7824. 3: 'square',
  7825. };
  7826. const lineJoinEnum = {
  7827. 1: 'miter',
  7828. 2: 'round',
  7829. 3: 'bevel',
  7830. };
  7831. function SVGShapeData(transformers, level, shape) {
  7832. this.caches = [];
  7833. this.styles = [];
  7834. this.transformers = transformers;
  7835. this.lStr = '';
  7836. this.sh = shape;
  7837. this.lvl = level;
  7838. // TODO find if there are some cases where _isAnimated can be false.
  7839. // For now, since shapes add up with other shapes. They have to be calculated every time.
  7840. // One way of finding out is checking if all styles associated to this shape depend only of this shape
  7841. this._isAnimated = !!shape.k;
  7842. // TODO: commenting this for now since all shapes are animated
  7843. var i = 0;
  7844. var len = transformers.length;
  7845. while (i < len) {
  7846. if (transformers[i].mProps.dynamicProperties.length) {
  7847. this._isAnimated = true;
  7848. break;
  7849. }
  7850. i += 1;
  7851. }
  7852. }
  7853. SVGShapeData.prototype.setAsAnimated = function () {
  7854. this._isAnimated = true;
  7855. };
  7856. function SVGStyleData(data, level) {
  7857. this.data = data;
  7858. this.type = data.ty;
  7859. this.d = '';
  7860. this.lvl = level;
  7861. this._mdf = false;
  7862. this.closed = data.hd === true;
  7863. this.pElem = createNS('path');
  7864. this.msElem = null;
  7865. }
  7866. SVGStyleData.prototype.reset = function () {
  7867. this.d = '';
  7868. this._mdf = false;
  7869. };
  7870. function DashProperty(elem, data, renderer, container) {
  7871. this.elem = elem;
  7872. this.frameId = -1;
  7873. this.dataProps = createSizedArray(data.length);
  7874. this.renderer = renderer;
  7875. this.k = false;
  7876. this.dashStr = '';
  7877. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  7878. this.dashoffset = createTypedArray('float32', 1);
  7879. this.initDynamicPropertyContainer(container);
  7880. var i;
  7881. var len = data.length || 0;
  7882. var prop;
  7883. for (i = 0; i < len; i += 1) {
  7884. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  7885. this.k = prop.k || this.k;
  7886. this.dataProps[i] = { n: data[i].n, p: prop };
  7887. }
  7888. if (!this.k) {
  7889. this.getValue(true);
  7890. }
  7891. this._isAnimated = this.k;
  7892. }
  7893. DashProperty.prototype.getValue = function (forceRender) {
  7894. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  7895. return;
  7896. }
  7897. this.frameId = this.elem.globalData.frameId;
  7898. this.iterateDynamicProperties();
  7899. this._mdf = this._mdf || forceRender;
  7900. if (this._mdf) {
  7901. var i = 0;
  7902. var len = this.dataProps.length;
  7903. if (this.renderer === 'svg') {
  7904. this.dashStr = '';
  7905. }
  7906. for (i = 0; i < len; i += 1) {
  7907. if (this.dataProps[i].n !== 'o') {
  7908. if (this.renderer === 'svg') {
  7909. this.dashStr += ' ' + this.dataProps[i].p.v;
  7910. } else {
  7911. this.dashArray[i] = this.dataProps[i].p.v;
  7912. }
  7913. } else {
  7914. this.dashoffset[0] = this.dataProps[i].p.v;
  7915. }
  7916. }
  7917. }
  7918. };
  7919. extendPrototype([DynamicPropertyContainer], DashProperty);
  7920. function SVGStrokeStyleData(elem, data, styleOb) {
  7921. this.initDynamicPropertyContainer(elem);
  7922. this.getValue = this.iterateDynamicProperties;
  7923. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7924. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  7925. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  7926. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7927. this.style = styleOb;
  7928. this._isAnimated = !!this._isAnimated;
  7929. }
  7930. extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData);
  7931. function SVGFillStyleData(elem, data, styleOb) {
  7932. this.initDynamicPropertyContainer(elem);
  7933. this.getValue = this.iterateDynamicProperties;
  7934. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  7935. this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this);
  7936. this.style = styleOb;
  7937. }
  7938. extendPrototype([DynamicPropertyContainer], SVGFillStyleData);
  7939. function SVGNoStyleData(elem, data, styleOb) {
  7940. this.initDynamicPropertyContainer(elem);
  7941. this.getValue = this.iterateDynamicProperties;
  7942. this.style = styleOb;
  7943. }
  7944. extendPrototype([DynamicPropertyContainer], SVGNoStyleData);
  7945. function GradientProperty(elem, data, container) {
  7946. this.data = data;
  7947. this.c = createTypedArray('uint8c', data.p * 4);
  7948. var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p * 4) : data.k.k.length - data.p * 4;
  7949. this.o = createTypedArray('float32', cLength);
  7950. this._cmdf = false;
  7951. this._omdf = false;
  7952. this._collapsable = this.checkCollapsable();
  7953. this._hasOpacity = cLength;
  7954. this.initDynamicPropertyContainer(container);
  7955. this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this);
  7956. this.k = this.prop.k;
  7957. this.getValue(true);
  7958. }
  7959. GradientProperty.prototype.comparePoints = function (values, points) {
  7960. var i = 0;
  7961. var len = this.o.length / 2;
  7962. var diff;
  7963. while (i < len) {
  7964. diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]);
  7965. if (diff > 0.01) {
  7966. return false;
  7967. }
  7968. i += 1;
  7969. }
  7970. return true;
  7971. };
  7972. GradientProperty.prototype.checkCollapsable = function () {
  7973. if (this.o.length / 2 !== this.c.length / 4) {
  7974. return false;
  7975. }
  7976. if (this.data.k.k[0].s) {
  7977. var i = 0;
  7978. var len = this.data.k.k.length;
  7979. while (i < len) {
  7980. if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) {
  7981. return false;
  7982. }
  7983. i += 1;
  7984. }
  7985. } else if (!this.comparePoints(this.data.k.k, this.data.p)) {
  7986. return false;
  7987. }
  7988. return true;
  7989. };
  7990. GradientProperty.prototype.getValue = function (forceRender) {
  7991. this.prop.getValue();
  7992. this._mdf = false;
  7993. this._cmdf = false;
  7994. this._omdf = false;
  7995. if (this.prop._mdf || forceRender) {
  7996. var i;
  7997. var len = this.data.p * 4;
  7998. var mult;
  7999. var val;
  8000. for (i = 0; i < len; i += 1) {
  8001. mult = i % 4 === 0 ? 100 : 255;
  8002. val = Math.round(this.prop.v[i] * mult);
  8003. if (this.c[i] !== val) {
  8004. this.c[i] = val;
  8005. this._cmdf = !forceRender;
  8006. }
  8007. }
  8008. if (this.o.length) {
  8009. len = this.prop.v.length;
  8010. for (i = this.data.p * 4; i < len; i += 1) {
  8011. mult = i % 2 === 0 ? 100 : 1;
  8012. val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i];
  8013. if (this.o[i - this.data.p * 4] !== val) {
  8014. this.o[i - this.data.p * 4] = val;
  8015. this._omdf = !forceRender;
  8016. }
  8017. }
  8018. }
  8019. this._mdf = !forceRender;
  8020. }
  8021. };
  8022. extendPrototype([DynamicPropertyContainer], GradientProperty);
  8023. function SVGGradientFillStyleData(elem, data, styleOb) {
  8024. this.initDynamicPropertyContainer(elem);
  8025. this.getValue = this.iterateDynamicProperties;
  8026. this.initGradientData(elem, data, styleOb);
  8027. }
  8028. SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) {
  8029. this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this);
  8030. this.s = PropertyFactory.getProp(elem, data.s, 1, null, this);
  8031. this.e = PropertyFactory.getProp(elem, data.e, 1, null, this);
  8032. this.h = PropertyFactory.getProp(elem, data.h || { k: 0 }, 0, 0.01, this);
  8033. this.a = PropertyFactory.getProp(elem, data.a || { k: 0 }, 0, degToRads, this);
  8034. this.g = new GradientProperty(elem, data.g, this);
  8035. this.style = styleOb;
  8036. this.stops = [];
  8037. this.setGradientData(styleOb.pElem, data);
  8038. this.setGradientOpacity(data, styleOb);
  8039. this._isAnimated = !!this._isAnimated;
  8040. };
  8041. SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) {
  8042. var gradientId = createElementID();
  8043. var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8044. gfill.setAttribute('id', gradientId);
  8045. gfill.setAttribute('spreadMethod', 'pad');
  8046. gfill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8047. var stops = [];
  8048. var stop;
  8049. var j;
  8050. var jLen;
  8051. jLen = data.g.p * 4;
  8052. for (j = 0; j < jLen; j += 4) {
  8053. stop = createNS('stop');
  8054. gfill.appendChild(stop);
  8055. stops.push(stop);
  8056. }
  8057. pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + gradientId + ')');
  8058. this.gf = gfill;
  8059. this.cst = stops;
  8060. };
  8061. SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) {
  8062. if (this.g._hasOpacity && !this.g._collapsable) {
  8063. var stop;
  8064. var j;
  8065. var jLen;
  8066. var mask = createNS('mask');
  8067. var maskElement = createNS('path');
  8068. mask.appendChild(maskElement);
  8069. var opacityId = createElementID();
  8070. var maskId = createElementID();
  8071. mask.setAttribute('id', maskId);
  8072. var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient');
  8073. opFill.setAttribute('id', opacityId);
  8074. opFill.setAttribute('spreadMethod', 'pad');
  8075. opFill.setAttribute('gradientUnits', 'userSpaceOnUse');
  8076. jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length;
  8077. var stops = this.stops;
  8078. for (j = data.g.p * 4; j < jLen; j += 2) {
  8079. stop = createNS('stop');
  8080. stop.setAttribute('stop-color', 'rgb(255,255,255)');
  8081. opFill.appendChild(stop);
  8082. stops.push(stop);
  8083. }
  8084. maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + getLocationHref() + '#' + opacityId + ')');
  8085. if (data.ty === 'gs') {
  8086. maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8087. maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8088. if (data.lj === 1) {
  8089. maskElement.setAttribute('stroke-miterlimit', data.ml);
  8090. }
  8091. }
  8092. this.of = opFill;
  8093. this.ms = mask;
  8094. this.ost = stops;
  8095. this.maskId = maskId;
  8096. styleOb.msElem = maskElement;
  8097. }
  8098. };
  8099. extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData);
  8100. function SVGGradientStrokeStyleData(elem, data, styleOb) {
  8101. this.initDynamicPropertyContainer(elem);
  8102. this.getValue = this.iterateDynamicProperties;
  8103. this.w = PropertyFactory.getProp(elem, data.w, 0, null, this);
  8104. this.d = new DashProperty(elem, data.d || {}, 'svg', this);
  8105. this.initGradientData(elem, data, styleOb);
  8106. this._isAnimated = !!this._isAnimated;
  8107. }
  8108. extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData);
  8109. function ShapeGroupData() {
  8110. this.it = [];
  8111. this.prevViewData = [];
  8112. this.gr = createNS('g');
  8113. }
  8114. function SVGTransformData(mProps, op, container) {
  8115. this.transform = {
  8116. mProps: mProps,
  8117. op: op,
  8118. container: container,
  8119. };
  8120. this.elements = [];
  8121. this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length;
  8122. }
  8123. const buildShapeString = function (pathNodes, length, closed, mat) {
  8124. if (length === 0) {
  8125. return '';
  8126. }
  8127. var _o = pathNodes.o;
  8128. var _i = pathNodes.i;
  8129. var _v = pathNodes.v;
  8130. var i;
  8131. var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]);
  8132. for (i = 1; i < length; i += 1) {
  8133. 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]);
  8134. }
  8135. if (closed && length) {
  8136. 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]);
  8137. shapeString += 'z';
  8138. }
  8139. return shapeString;
  8140. };
  8141. const SVGElementsRenderer = (function () {
  8142. var _identityMatrix = new Matrix();
  8143. var _matrixHelper = new Matrix();
  8144. var ob = {
  8145. createRenderFunction: createRenderFunction,
  8146. };
  8147. function createRenderFunction(data) {
  8148. switch (data.ty) {
  8149. case 'fl':
  8150. return renderFill;
  8151. case 'gf':
  8152. return renderGradient;
  8153. case 'gs':
  8154. return renderGradientStroke;
  8155. case 'st':
  8156. return renderStroke;
  8157. case 'sh':
  8158. case 'el':
  8159. case 'rc':
  8160. case 'sr':
  8161. return renderPath;
  8162. case 'tr':
  8163. return renderContentTransform;
  8164. case 'no':
  8165. return renderNoop;
  8166. default:
  8167. return null;
  8168. }
  8169. }
  8170. function renderContentTransform(styleData, itemData, isFirstFrame) {
  8171. if (isFirstFrame || itemData.transform.op._mdf) {
  8172. itemData.transform.container.setAttribute('opacity', itemData.transform.op.v);
  8173. }
  8174. if (isFirstFrame || itemData.transform.mProps._mdf) {
  8175. itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS());
  8176. }
  8177. }
  8178. function renderNoop() {
  8179. }
  8180. function renderPath(styleData, itemData, isFirstFrame) {
  8181. var j;
  8182. var jLen;
  8183. var pathStringTransformed;
  8184. var redraw;
  8185. var pathNodes;
  8186. var l;
  8187. var lLen = itemData.styles.length;
  8188. var lvl = itemData.lvl;
  8189. var paths;
  8190. var mat;
  8191. var iterations;
  8192. var k;
  8193. for (l = 0; l < lLen; l += 1) {
  8194. redraw = itemData.sh._mdf || isFirstFrame;
  8195. if (itemData.styles[l].lvl < lvl) {
  8196. mat = _matrixHelper.reset();
  8197. iterations = lvl - itemData.styles[l].lvl;
  8198. k = itemData.transformers.length - 1;
  8199. while (!redraw && iterations > 0) {
  8200. redraw = itemData.transformers[k].mProps._mdf || redraw;
  8201. iterations -= 1;
  8202. k -= 1;
  8203. }
  8204. if (redraw) {
  8205. iterations = lvl - itemData.styles[l].lvl;
  8206. k = itemData.transformers.length - 1;
  8207. while (iterations > 0) {
  8208. mat.multiply(itemData.transformers[k].mProps.v);
  8209. iterations -= 1;
  8210. k -= 1;
  8211. }
  8212. }
  8213. } else {
  8214. mat = _identityMatrix;
  8215. }
  8216. paths = itemData.sh.paths;
  8217. jLen = paths._length;
  8218. if (redraw) {
  8219. pathStringTransformed = '';
  8220. for (j = 0; j < jLen; j += 1) {
  8221. pathNodes = paths.shapes[j];
  8222. if (pathNodes && pathNodes._length) {
  8223. pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat);
  8224. }
  8225. }
  8226. itemData.caches[l] = pathStringTransformed;
  8227. } else {
  8228. pathStringTransformed = itemData.caches[l];
  8229. }
  8230. itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed;
  8231. itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf;
  8232. }
  8233. }
  8234. function renderFill(styleData, itemData, isFirstFrame) {
  8235. var styleElem = itemData.style;
  8236. if (itemData.c._mdf || isFirstFrame) {
  8237. styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8238. }
  8239. if (itemData.o._mdf || isFirstFrame) {
  8240. styleElem.pElem.setAttribute('fill-opacity', itemData.o.v);
  8241. }
  8242. }
  8243. function renderGradientStroke(styleData, itemData, isFirstFrame) {
  8244. renderGradient(styleData, itemData, isFirstFrame);
  8245. renderStroke(styleData, itemData, isFirstFrame);
  8246. }
  8247. function renderGradient(styleData, itemData, isFirstFrame) {
  8248. var gfill = itemData.gf;
  8249. var hasOpacity = itemData.g._hasOpacity;
  8250. var pt1 = itemData.s.v;
  8251. var pt2 = itemData.e.v;
  8252. if (itemData.o._mdf || isFirstFrame) {
  8253. var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity';
  8254. itemData.style.pElem.setAttribute(attr, itemData.o.v);
  8255. }
  8256. if (itemData.s._mdf || isFirstFrame) {
  8257. var attr1 = styleData.t === 1 ? 'x1' : 'cx';
  8258. var attr2 = attr1 === 'x1' ? 'y1' : 'cy';
  8259. gfill.setAttribute(attr1, pt1[0]);
  8260. gfill.setAttribute(attr2, pt1[1]);
  8261. if (hasOpacity && !itemData.g._collapsable) {
  8262. itemData.of.setAttribute(attr1, pt1[0]);
  8263. itemData.of.setAttribute(attr2, pt1[1]);
  8264. }
  8265. }
  8266. var stops;
  8267. var i;
  8268. var len;
  8269. var stop;
  8270. if (itemData.g._cmdf || isFirstFrame) {
  8271. stops = itemData.cst;
  8272. var cValues = itemData.g.c;
  8273. len = stops.length;
  8274. for (i = 0; i < len; i += 1) {
  8275. stop = stops[i];
  8276. stop.setAttribute('offset', cValues[i * 4] + '%');
  8277. stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')');
  8278. }
  8279. }
  8280. if (hasOpacity && (itemData.g._omdf || isFirstFrame)) {
  8281. var oValues = itemData.g.o;
  8282. if (itemData.g._collapsable) {
  8283. stops = itemData.cst;
  8284. } else {
  8285. stops = itemData.ost;
  8286. }
  8287. len = stops.length;
  8288. for (i = 0; i < len; i += 1) {
  8289. stop = stops[i];
  8290. if (!itemData.g._collapsable) {
  8291. stop.setAttribute('offset', oValues[i * 2] + '%');
  8292. }
  8293. stop.setAttribute('stop-opacity', oValues[i * 2 + 1]);
  8294. }
  8295. }
  8296. if (styleData.t === 1) {
  8297. if (itemData.e._mdf || isFirstFrame) {
  8298. gfill.setAttribute('x2', pt2[0]);
  8299. gfill.setAttribute('y2', pt2[1]);
  8300. if (hasOpacity && !itemData.g._collapsable) {
  8301. itemData.of.setAttribute('x2', pt2[0]);
  8302. itemData.of.setAttribute('y2', pt2[1]);
  8303. }
  8304. }
  8305. } else {
  8306. var rad;
  8307. if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) {
  8308. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8309. gfill.setAttribute('r', rad);
  8310. if (hasOpacity && !itemData.g._collapsable) {
  8311. itemData.of.setAttribute('r', rad);
  8312. }
  8313. }
  8314. if (itemData.s._mdf || itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) {
  8315. if (!rad) {
  8316. rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2));
  8317. }
  8318. var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]);
  8319. var percent = itemData.h.v;
  8320. if (percent >= 1) {
  8321. percent = 0.99;
  8322. } else if (percent <= -1) {
  8323. percent = -0.99;
  8324. }
  8325. var dist = rad * percent;
  8326. var x = Math.cos(ang + itemData.a.v) * dist + pt1[0];
  8327. var y = Math.sin(ang + itemData.a.v) * dist + pt1[1];
  8328. gfill.setAttribute('fx', x);
  8329. gfill.setAttribute('fy', y);
  8330. if (hasOpacity && !itemData.g._collapsable) {
  8331. itemData.of.setAttribute('fx', x);
  8332. itemData.of.setAttribute('fy', y);
  8333. }
  8334. }
  8335. // gfill.setAttribute('fy','200');
  8336. }
  8337. }
  8338. function renderStroke(styleData, itemData, isFirstFrame) {
  8339. var styleElem = itemData.style;
  8340. var d = itemData.d;
  8341. if (d && (d._mdf || isFirstFrame) && d.dashStr) {
  8342. styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr);
  8343. styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]);
  8344. }
  8345. if (itemData.c && (itemData.c._mdf || isFirstFrame)) {
  8346. styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')');
  8347. }
  8348. if (itemData.o._mdf || isFirstFrame) {
  8349. styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v);
  8350. }
  8351. if (itemData.w._mdf || isFirstFrame) {
  8352. styleElem.pElem.setAttribute('stroke-width', itemData.w.v);
  8353. if (styleElem.msElem) {
  8354. styleElem.msElem.setAttribute('stroke-width', itemData.w.v);
  8355. }
  8356. }
  8357. }
  8358. return ob;
  8359. }());
  8360. function SVGShapeElement(data, globalData, comp) {
  8361. // List of drawable elements
  8362. this.shapes = [];
  8363. // Full shape data
  8364. this.shapesData = data.shapes;
  8365. // List of styles that will be applied to shapes
  8366. this.stylesList = [];
  8367. // List of modifiers that will be applied to shapes
  8368. this.shapeModifiers = [];
  8369. // List of items in shape tree
  8370. this.itemsData = [];
  8371. // List of items in previous shape tree
  8372. this.processedElements = [];
  8373. // List of animated components
  8374. this.animatedContents = [];
  8375. this.initElement(data, globalData, comp);
  8376. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8377. // List of elements that have been created
  8378. this.prevViewData = [];
  8379. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  8380. }
  8381. extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement);
  8382. SVGShapeElement.prototype.initSecondaryElement = function () {
  8383. };
  8384. SVGShapeElement.prototype.identityMatrix = new Matrix();
  8385. SVGShapeElement.prototype.buildExpressionInterface = function () {};
  8386. SVGShapeElement.prototype.createContent = function () {
  8387. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8388. this.filterUniqueShapes();
  8389. };
  8390. /*
  8391. This method searches for multiple shapes that affect a single element and one of them is animated
  8392. */
  8393. SVGShapeElement.prototype.filterUniqueShapes = function () {
  8394. var i;
  8395. var len = this.shapes.length;
  8396. var shape;
  8397. var j;
  8398. var jLen = this.stylesList.length;
  8399. var style;
  8400. var tempShapes = [];
  8401. var areAnimated = false;
  8402. for (j = 0; j < jLen; j += 1) {
  8403. style = this.stylesList[j];
  8404. areAnimated = false;
  8405. tempShapes.length = 0;
  8406. for (i = 0; i < len; i += 1) {
  8407. shape = this.shapes[i];
  8408. if (shape.styles.indexOf(style) !== -1) {
  8409. tempShapes.push(shape);
  8410. areAnimated = shape._isAnimated || areAnimated;
  8411. }
  8412. }
  8413. if (tempShapes.length > 1 && areAnimated) {
  8414. this.setShapesAsAnimated(tempShapes);
  8415. }
  8416. }
  8417. };
  8418. SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) {
  8419. var i;
  8420. var len = shapes.length;
  8421. for (i = 0; i < len; i += 1) {
  8422. shapes[i].setAsAnimated();
  8423. }
  8424. };
  8425. SVGShapeElement.prototype.createStyleElement = function (data, level) {
  8426. // TODO: prevent drawing of hidden styles
  8427. var elementData;
  8428. var styleOb = new SVGStyleData(data, level);
  8429. var pathElement = styleOb.pElem;
  8430. if (data.ty === 'st') {
  8431. elementData = new SVGStrokeStyleData(this, data, styleOb);
  8432. } else if (data.ty === 'fl') {
  8433. elementData = new SVGFillStyleData(this, data, styleOb);
  8434. } else if (data.ty === 'gf' || data.ty === 'gs') {
  8435. var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData;
  8436. elementData = new GradientConstructor(this, data, styleOb);
  8437. this.globalData.defs.appendChild(elementData.gf);
  8438. if (elementData.maskId) {
  8439. this.globalData.defs.appendChild(elementData.ms);
  8440. this.globalData.defs.appendChild(elementData.of);
  8441. pathElement.setAttribute('mask', 'url(' + getLocationHref() + '#' + elementData.maskId + ')');
  8442. }
  8443. } else if (data.ty === 'no') {
  8444. elementData = new SVGNoStyleData(this, data, styleOb);
  8445. }
  8446. if (data.ty === 'st' || data.ty === 'gs') {
  8447. pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]);
  8448. pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]);
  8449. pathElement.setAttribute('fill-opacity', '0');
  8450. if (data.lj === 1) {
  8451. pathElement.setAttribute('stroke-miterlimit', data.ml);
  8452. }
  8453. }
  8454. if (data.r === 2) {
  8455. pathElement.setAttribute('fill-rule', 'evenodd');
  8456. }
  8457. if (data.ln) {
  8458. pathElement.setAttribute('id', data.ln);
  8459. }
  8460. if (data.cl) {
  8461. pathElement.setAttribute('class', data.cl);
  8462. }
  8463. if (data.bm) {
  8464. pathElement.style['mix-blend-mode'] = getBlendMode(data.bm);
  8465. }
  8466. this.stylesList.push(styleOb);
  8467. this.addToAnimatedContents(data, elementData);
  8468. return elementData;
  8469. };
  8470. SVGShapeElement.prototype.createGroupElement = function (data) {
  8471. var elementData = new ShapeGroupData();
  8472. if (data.ln) {
  8473. elementData.gr.setAttribute('id', data.ln);
  8474. }
  8475. if (data.cl) {
  8476. elementData.gr.setAttribute('class', data.cl);
  8477. }
  8478. if (data.bm) {
  8479. elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm);
  8480. }
  8481. return elementData;
  8482. };
  8483. SVGShapeElement.prototype.createTransformElement = function (data, container) {
  8484. var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this);
  8485. var elementData = new SVGTransformData(transformProperty, transformProperty.o, container);
  8486. this.addToAnimatedContents(data, elementData);
  8487. return elementData;
  8488. };
  8489. SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) {
  8490. var ty = 4;
  8491. if (data.ty === 'rc') {
  8492. ty = 5;
  8493. } else if (data.ty === 'el') {
  8494. ty = 6;
  8495. } else if (data.ty === 'sr') {
  8496. ty = 7;
  8497. }
  8498. var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this);
  8499. var elementData = new SVGShapeData(ownTransformers, level, shapeProperty);
  8500. this.shapes.push(elementData);
  8501. this.addShapeToModifiers(elementData);
  8502. this.addToAnimatedContents(data, elementData);
  8503. return elementData;
  8504. };
  8505. SVGShapeElement.prototype.addToAnimatedContents = function (data, element) {
  8506. var i = 0;
  8507. var len = this.animatedContents.length;
  8508. while (i < len) {
  8509. if (this.animatedContents[i].element === element) {
  8510. return;
  8511. }
  8512. i += 1;
  8513. }
  8514. this.animatedContents.push({
  8515. fn: SVGElementsRenderer.createRenderFunction(data),
  8516. element: element,
  8517. data: data,
  8518. });
  8519. };
  8520. SVGShapeElement.prototype.setElementStyles = function (elementData) {
  8521. var arr = elementData.styles;
  8522. var j;
  8523. var jLen = this.stylesList.length;
  8524. for (j = 0; j < jLen; j += 1) {
  8525. if (arr.indexOf(this.stylesList[j]) === -1 && !this.stylesList[j].closed) {
  8526. arr.push(this.stylesList[j]);
  8527. }
  8528. }
  8529. };
  8530. SVGShapeElement.prototype.reloadShapes = function () {
  8531. this._isFirstFrame = true;
  8532. var i;
  8533. var len = this.itemsData.length;
  8534. for (i = 0; i < len; i += 1) {
  8535. this.prevViewData[i] = this.itemsData[i];
  8536. }
  8537. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true);
  8538. this.filterUniqueShapes();
  8539. len = this.dynamicProperties.length;
  8540. for (i = 0; i < len; i += 1) {
  8541. this.dynamicProperties[i].getValue();
  8542. }
  8543. this.renderModifiers();
  8544. };
  8545. SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) {
  8546. var ownTransformers = [].concat(transformers);
  8547. var i;
  8548. var len = arr.length - 1;
  8549. var j;
  8550. var jLen;
  8551. var ownStyles = [];
  8552. var ownModifiers = [];
  8553. var currentTransform;
  8554. var modifier;
  8555. var processedPos;
  8556. for (i = len; i >= 0; i -= 1) {
  8557. processedPos = this.searchProcessedElement(arr[i]);
  8558. if (!processedPos) {
  8559. arr[i]._render = render;
  8560. } else {
  8561. itemsData[i] = prevViewData[processedPos - 1];
  8562. }
  8563. if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs' || arr[i].ty === 'no') {
  8564. if (!processedPos) {
  8565. itemsData[i] = this.createStyleElement(arr[i], level);
  8566. } else {
  8567. itemsData[i].style.closed = arr[i].hd;
  8568. }
  8569. if (arr[i]._render) {
  8570. if (itemsData[i].style.pElem.parentNode !== container) {
  8571. container.appendChild(itemsData[i].style.pElem);
  8572. }
  8573. }
  8574. ownStyles.push(itemsData[i].style);
  8575. } else if (arr[i].ty === 'gr') {
  8576. if (!processedPos) {
  8577. itemsData[i] = this.createGroupElement(arr[i]);
  8578. } else {
  8579. jLen = itemsData[i].it.length;
  8580. for (j = 0; j < jLen; j += 1) {
  8581. itemsData[i].prevViewData[j] = itemsData[i].it[j];
  8582. }
  8583. }
  8584. this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render);
  8585. if (arr[i]._render) {
  8586. if (itemsData[i].gr.parentNode !== container) {
  8587. container.appendChild(itemsData[i].gr);
  8588. }
  8589. }
  8590. } else if (arr[i].ty === 'tr') {
  8591. if (!processedPos) {
  8592. itemsData[i] = this.createTransformElement(arr[i], container);
  8593. }
  8594. currentTransform = itemsData[i].transform;
  8595. ownTransformers.push(currentTransform);
  8596. } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') {
  8597. if (!processedPos) {
  8598. itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level);
  8599. }
  8600. this.setElementStyles(itemsData[i]);
  8601. } 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') {
  8602. if (!processedPos) {
  8603. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8604. modifier.init(this, arr[i]);
  8605. itemsData[i] = modifier;
  8606. this.shapeModifiers.push(modifier);
  8607. } else {
  8608. modifier = itemsData[i];
  8609. modifier.closed = false;
  8610. }
  8611. ownModifiers.push(modifier);
  8612. } else if (arr[i].ty === 'rp') {
  8613. if (!processedPos) {
  8614. modifier = ShapeModifiers.getModifier(arr[i].ty);
  8615. itemsData[i] = modifier;
  8616. modifier.init(this, arr, i, itemsData);
  8617. this.shapeModifiers.push(modifier);
  8618. render = false;
  8619. } else {
  8620. modifier = itemsData[i];
  8621. modifier.closed = true;
  8622. }
  8623. ownModifiers.push(modifier);
  8624. }
  8625. this.addProcessedElement(arr[i], i + 1);
  8626. }
  8627. len = ownStyles.length;
  8628. for (i = 0; i < len; i += 1) {
  8629. ownStyles[i].closed = true;
  8630. }
  8631. len = ownModifiers.length;
  8632. for (i = 0; i < len; i += 1) {
  8633. ownModifiers[i].closed = true;
  8634. }
  8635. };
  8636. SVGShapeElement.prototype.renderInnerContent = function () {
  8637. this.renderModifiers();
  8638. var i;
  8639. var len = this.stylesList.length;
  8640. for (i = 0; i < len; i += 1) {
  8641. this.stylesList[i].reset();
  8642. }
  8643. this.renderShape();
  8644. for (i = 0; i < len; i += 1) {
  8645. if (this.stylesList[i]._mdf || this._isFirstFrame) {
  8646. if (this.stylesList[i].msElem) {
  8647. this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d);
  8648. // Adding M0 0 fixes same mask bug on all browsers
  8649. this.stylesList[i].d = 'M0 0' + this.stylesList[i].d;
  8650. }
  8651. this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0');
  8652. }
  8653. }
  8654. };
  8655. SVGShapeElement.prototype.renderShape = function () {
  8656. var i;
  8657. var len = this.animatedContents.length;
  8658. var animatedContent;
  8659. for (i = 0; i < len; i += 1) {
  8660. animatedContent = this.animatedContents[i];
  8661. if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
  8662. animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
  8663. }
  8664. }
  8665. };
  8666. SVGShapeElement.prototype.destroy = function () {
  8667. this.destroyBaseElement();
  8668. this.shapesData = null;
  8669. this.itemsData = null;
  8670. };
  8671. function LetterProps(o, sw, sc, fc, m, p) {
  8672. this.o = o;
  8673. this.sw = sw;
  8674. this.sc = sc;
  8675. this.fc = fc;
  8676. this.m = m;
  8677. this.p = p;
  8678. this._mdf = {
  8679. o: true,
  8680. sw: !!sw,
  8681. sc: !!sc,
  8682. fc: !!fc,
  8683. m: true,
  8684. p: true,
  8685. };
  8686. }
  8687. LetterProps.prototype.update = function (o, sw, sc, fc, m, p) {
  8688. this._mdf.o = false;
  8689. this._mdf.sw = false;
  8690. this._mdf.sc = false;
  8691. this._mdf.fc = false;
  8692. this._mdf.m = false;
  8693. this._mdf.p = false;
  8694. var updated = false;
  8695. if (this.o !== o) {
  8696. this.o = o;
  8697. this._mdf.o = true;
  8698. updated = true;
  8699. }
  8700. if (this.sw !== sw) {
  8701. this.sw = sw;
  8702. this._mdf.sw = true;
  8703. updated = true;
  8704. }
  8705. if (this.sc !== sc) {
  8706. this.sc = sc;
  8707. this._mdf.sc = true;
  8708. updated = true;
  8709. }
  8710. if (this.fc !== fc) {
  8711. this.fc = fc;
  8712. this._mdf.fc = true;
  8713. updated = true;
  8714. }
  8715. if (this.m !== m) {
  8716. this.m = m;
  8717. this._mdf.m = true;
  8718. updated = true;
  8719. }
  8720. 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])) {
  8721. this.p = p;
  8722. this._mdf.p = true;
  8723. updated = true;
  8724. }
  8725. return updated;
  8726. };
  8727. function TextProperty(elem, data) {
  8728. this._frameId = initialDefaultFrame;
  8729. this.pv = '';
  8730. this.v = '';
  8731. this.kf = false;
  8732. this._isFirstFrame = true;
  8733. this._mdf = false;
  8734. if (data.d && data.d.sid) {
  8735. data.d = elem.globalData.slotManager.getProp(data.d);
  8736. }
  8737. this.data = data;
  8738. this.elem = elem;
  8739. this.comp = this.elem.comp;
  8740. this.keysIndex = 0;
  8741. this.canResize = false;
  8742. this.minimumFontSize = 1;
  8743. this.effectsSequence = [];
  8744. this.currentData = {
  8745. ascent: 0,
  8746. boxWidth: this.defaultBoxWidth,
  8747. f: '',
  8748. fStyle: '',
  8749. fWeight: '',
  8750. fc: '',
  8751. j: '',
  8752. justifyOffset: '',
  8753. l: [],
  8754. lh: 0,
  8755. lineWidths: [],
  8756. ls: '',
  8757. of: '',
  8758. s: '',
  8759. sc: '',
  8760. sw: 0,
  8761. t: 0,
  8762. tr: 0,
  8763. sz: 0,
  8764. ps: null,
  8765. fillColorAnim: false,
  8766. strokeColorAnim: false,
  8767. strokeWidthAnim: false,
  8768. yOffset: 0,
  8769. finalSize: 0,
  8770. finalText: [],
  8771. finalLineHeight: 0,
  8772. __complete: false,
  8773. };
  8774. this.copyData(this.currentData, this.data.d.k[0].s);
  8775. if (!this.searchProperty()) {
  8776. this.completeTextData(this.currentData);
  8777. }
  8778. }
  8779. TextProperty.prototype.defaultBoxWidth = [0, 0];
  8780. TextProperty.prototype.copyData = function (obj, data) {
  8781. for (var s in data) {
  8782. if (Object.prototype.hasOwnProperty.call(data, s)) {
  8783. obj[s] = data[s];
  8784. }
  8785. }
  8786. return obj;
  8787. };
  8788. TextProperty.prototype.setCurrentData = function (data) {
  8789. if (!data.__complete) {
  8790. this.completeTextData(data);
  8791. }
  8792. this.currentData = data;
  8793. this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth;
  8794. this._mdf = true;
  8795. };
  8796. TextProperty.prototype.searchProperty = function () {
  8797. return this.searchKeyframes();
  8798. };
  8799. TextProperty.prototype.searchKeyframes = function () {
  8800. this.kf = this.data.d.k.length > 1;
  8801. if (this.kf) {
  8802. this.addEffect(this.getKeyframeValue.bind(this));
  8803. }
  8804. return this.kf;
  8805. };
  8806. TextProperty.prototype.addEffect = function (effectFunction) {
  8807. this.effectsSequence.push(effectFunction);
  8808. this.elem.addDynamicProperty(this);
  8809. };
  8810. TextProperty.prototype.getValue = function (_finalValue) {
  8811. if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) {
  8812. return;
  8813. }
  8814. this.currentData.t = this.data.d.k[this.keysIndex].s.t;
  8815. var currentValue = this.currentData;
  8816. var currentIndex = this.keysIndex;
  8817. if (this.lock) {
  8818. this.setCurrentData(this.currentData);
  8819. return;
  8820. }
  8821. this.lock = true;
  8822. this._mdf = false;
  8823. var i; var
  8824. len = this.effectsSequence.length;
  8825. var finalValue = _finalValue || this.data.d.k[this.keysIndex].s;
  8826. for (i = 0; i < len; i += 1) {
  8827. // Checking if index changed to prevent creating a new object every time the expression updates.
  8828. if (currentIndex !== this.keysIndex) {
  8829. finalValue = this.effectsSequence[i](finalValue, finalValue.t);
  8830. } else {
  8831. finalValue = this.effectsSequence[i](this.currentData, finalValue.t);
  8832. }
  8833. }
  8834. if (currentValue !== finalValue) {
  8835. this.setCurrentData(finalValue);
  8836. }
  8837. this.v = this.currentData;
  8838. this.pv = this.v;
  8839. this.lock = false;
  8840. this.frameId = this.elem.globalData.frameId;
  8841. };
  8842. TextProperty.prototype.getKeyframeValue = function () {
  8843. var textKeys = this.data.d.k;
  8844. var frameNum = this.elem.comp.renderedFrame;
  8845. var i = 0; var
  8846. len = textKeys.length;
  8847. while (i <= len - 1) {
  8848. if (i === len - 1 || textKeys[i + 1].t > frameNum) {
  8849. break;
  8850. }
  8851. i += 1;
  8852. }
  8853. if (this.keysIndex !== i) {
  8854. this.keysIndex = i;
  8855. }
  8856. return this.data.d.k[this.keysIndex].s;
  8857. };
  8858. TextProperty.prototype.buildFinalText = function (text) {
  8859. var charactersArray = [];
  8860. var i = 0;
  8861. var len = text.length;
  8862. var charCode;
  8863. var secondCharCode;
  8864. var shouldCombine = false;
  8865. var shouldCombineNext = false;
  8866. var currentChars = '';
  8867. while (i < len) {
  8868. shouldCombine = shouldCombineNext;
  8869. shouldCombineNext = false;
  8870. charCode = text.charCodeAt(i);
  8871. currentChars = text.charAt(i);
  8872. if (FontManager.isCombinedCharacter(charCode)) {
  8873. shouldCombine = true;
  8874. // It's a potential surrogate pair (this is the High surrogate)
  8875. } else if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  8876. if (FontManager.isRegionalFlag(text, i)) {
  8877. currentChars = text.substr(i, 14);
  8878. } else {
  8879. secondCharCode = text.charCodeAt(i + 1);
  8880. // It's a surrogate pair (this is the Low surrogate)
  8881. if (secondCharCode >= 0xDC00 && secondCharCode <= 0xDFFF) {
  8882. if (FontManager.isModifier(charCode, secondCharCode)) {
  8883. currentChars = text.substr(i, 2);
  8884. shouldCombine = true;
  8885. } else if (FontManager.isFlagEmoji(text.substr(i, 4))) {
  8886. currentChars = text.substr(i, 4);
  8887. } else {
  8888. currentChars = text.substr(i, 2);
  8889. }
  8890. }
  8891. }
  8892. } else if (charCode > 0xDBFF) {
  8893. secondCharCode = text.charCodeAt(i + 1);
  8894. if (FontManager.isVariationSelector(charCode)) {
  8895. shouldCombine = true;
  8896. }
  8897. } else if (FontManager.isZeroWidthJoiner(charCode)) {
  8898. shouldCombine = true;
  8899. shouldCombineNext = true;
  8900. }
  8901. if (shouldCombine) {
  8902. charactersArray[charactersArray.length - 1] += currentChars;
  8903. shouldCombine = false;
  8904. } else {
  8905. charactersArray.push(currentChars);
  8906. }
  8907. i += currentChars.length;
  8908. }
  8909. return charactersArray;
  8910. };
  8911. TextProperty.prototype.completeTextData = function (documentData) {
  8912. documentData.__complete = true;
  8913. var fontManager = this.elem.globalData.fontManager;
  8914. var data = this.data;
  8915. var letters = [];
  8916. var i; var
  8917. len;
  8918. var newLineFlag; var index = 0; var
  8919. val;
  8920. var anchorGrouping = data.m.g;
  8921. var currentSize = 0; var currentPos = 0; var currentLine = 0; var
  8922. lineWidths = [];
  8923. var lineWidth = 0;
  8924. var maxLineWidth = 0;
  8925. var j; var
  8926. jLen;
  8927. var fontData = fontManager.getFontByName(documentData.f);
  8928. var charData; var
  8929. cLength = 0;
  8930. var fontProps = getFontProperties(fontData);
  8931. documentData.fWeight = fontProps.weight;
  8932. documentData.fStyle = fontProps.style;
  8933. documentData.finalSize = documentData.s;
  8934. documentData.finalText = this.buildFinalText(documentData.t);
  8935. len = documentData.finalText.length;
  8936. documentData.finalLineHeight = documentData.lh;
  8937. var trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8938. var charCode;
  8939. if (documentData.sz) {
  8940. var flag = true;
  8941. var boxWidth = documentData.sz[0];
  8942. var boxHeight = documentData.sz[1];
  8943. var currentHeight; var
  8944. finalText;
  8945. while (flag) {
  8946. finalText = this.buildFinalText(documentData.t);
  8947. currentHeight = 0;
  8948. lineWidth = 0;
  8949. len = finalText.length;
  8950. trackingOffset = (documentData.tr / 1000) * documentData.finalSize;
  8951. var lastSpaceIndex = -1;
  8952. for (i = 0; i < len; i += 1) {
  8953. charCode = finalText[i].charCodeAt(0);
  8954. newLineFlag = false;
  8955. if (finalText[i] === ' ') {
  8956. lastSpaceIndex = i;
  8957. } else if (charCode === 13 || charCode === 3) {
  8958. lineWidth = 0;
  8959. newLineFlag = true;
  8960. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8961. }
  8962. if (fontManager.chars) {
  8963. charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily);
  8964. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  8965. } else {
  8966. // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily;
  8967. cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize);
  8968. }
  8969. if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') {
  8970. if (lastSpaceIndex === -1) {
  8971. len += 1;
  8972. } else {
  8973. i = lastSpaceIndex;
  8974. }
  8975. currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2;
  8976. finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r');
  8977. // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i);
  8978. lastSpaceIndex = -1;
  8979. lineWidth = 0;
  8980. } else {
  8981. lineWidth += cLength;
  8982. lineWidth += trackingOffset;
  8983. }
  8984. }
  8985. currentHeight += (fontData.ascent * documentData.finalSize) / 100;
  8986. if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) {
  8987. documentData.finalSize -= 1;
  8988. documentData.finalLineHeight = (documentData.finalSize * documentData.lh) / documentData.s;
  8989. } else {
  8990. documentData.finalText = finalText;
  8991. len = documentData.finalText.length;
  8992. flag = false;
  8993. }
  8994. }
  8995. }
  8996. lineWidth = -trackingOffset;
  8997. cLength = 0;
  8998. var uncollapsedSpaces = 0;
  8999. var currentChar;
  9000. for (i = 0; i < len; i += 1) {
  9001. newLineFlag = false;
  9002. currentChar = documentData.finalText[i];
  9003. charCode = currentChar.charCodeAt(0);
  9004. if (charCode === 13 || charCode === 3) {
  9005. uncollapsedSpaces = 0;
  9006. lineWidths.push(lineWidth);
  9007. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9008. lineWidth = -2 * trackingOffset;
  9009. val = '';
  9010. newLineFlag = true;
  9011. currentLine += 1;
  9012. } else {
  9013. val = currentChar;
  9014. }
  9015. if (fontManager.chars) {
  9016. charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily);
  9017. cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100;
  9018. } else {
  9019. // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9020. // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily;
  9021. cLength = fontManager.measureText(val, documentData.f, documentData.finalSize);
  9022. }
  9023. //
  9024. if (currentChar === ' ') {
  9025. uncollapsedSpaces += cLength + trackingOffset;
  9026. } else {
  9027. lineWidth += cLength + trackingOffset + uncollapsedSpaces;
  9028. uncollapsedSpaces = 0;
  9029. }
  9030. letters.push({
  9031. l: cLength, an: cLength, add: currentSize, n: newLineFlag, anIndexes: [], val: val, line: currentLine, animatorJustifyOffset: 0,
  9032. });
  9033. if (anchorGrouping == 2) { // eslint-disable-line eqeqeq
  9034. currentSize += cLength;
  9035. if (val === '' || val === ' ' || i === len - 1) {
  9036. if (val === '' || val === ' ') {
  9037. currentSize -= cLength;
  9038. }
  9039. while (currentPos <= i) {
  9040. letters[currentPos].an = currentSize;
  9041. letters[currentPos].ind = index;
  9042. letters[currentPos].extra = cLength;
  9043. currentPos += 1;
  9044. }
  9045. index += 1;
  9046. currentSize = 0;
  9047. }
  9048. } else if (anchorGrouping == 3) { // eslint-disable-line eqeqeq
  9049. currentSize += cLength;
  9050. if (val === '' || i === len - 1) {
  9051. if (val === '') {
  9052. currentSize -= cLength;
  9053. }
  9054. while (currentPos <= i) {
  9055. letters[currentPos].an = currentSize;
  9056. letters[currentPos].ind = index;
  9057. letters[currentPos].extra = cLength;
  9058. currentPos += 1;
  9059. }
  9060. currentSize = 0;
  9061. index += 1;
  9062. }
  9063. } else {
  9064. letters[index].ind = index;
  9065. letters[index].extra = 0;
  9066. index += 1;
  9067. }
  9068. }
  9069. documentData.l = letters;
  9070. maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth;
  9071. lineWidths.push(lineWidth);
  9072. if (documentData.sz) {
  9073. documentData.boxWidth = documentData.sz[0];
  9074. documentData.justifyOffset = 0;
  9075. } else {
  9076. documentData.boxWidth = maxLineWidth;
  9077. switch (documentData.j) {
  9078. case 1:
  9079. documentData.justifyOffset = -documentData.boxWidth;
  9080. break;
  9081. case 2:
  9082. documentData.justifyOffset = -documentData.boxWidth / 2;
  9083. break;
  9084. default:
  9085. documentData.justifyOffset = 0;
  9086. }
  9087. }
  9088. documentData.lineWidths = lineWidths;
  9089. var animators = data.a; var animatorData; var
  9090. letterData;
  9091. jLen = animators.length;
  9092. var based; var ind; var
  9093. indexes = [];
  9094. for (j = 0; j < jLen; j += 1) {
  9095. animatorData = animators[j];
  9096. if (animatorData.a.sc) {
  9097. documentData.strokeColorAnim = true;
  9098. }
  9099. if (animatorData.a.sw) {
  9100. documentData.strokeWidthAnim = true;
  9101. }
  9102. if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) {
  9103. documentData.fillColorAnim = true;
  9104. }
  9105. ind = 0;
  9106. based = animatorData.s.b;
  9107. for (i = 0; i < len; i += 1) {
  9108. letterData = letters[i];
  9109. letterData.anIndexes[j] = ind;
  9110. 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
  9111. if (animatorData.s.rn === 1) {
  9112. indexes.push(ind);
  9113. }
  9114. ind += 1;
  9115. }
  9116. }
  9117. data.a[j].s.totalChars = ind;
  9118. var currentInd = -1; var
  9119. newInd;
  9120. if (animatorData.s.rn === 1) {
  9121. for (i = 0; i < len; i += 1) {
  9122. letterData = letters[i];
  9123. if (currentInd != letterData.anIndexes[j]) { // eslint-disable-line eqeqeq
  9124. currentInd = letterData.anIndexes[j];
  9125. newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0];
  9126. }
  9127. letterData.anIndexes[j] = newInd;
  9128. }
  9129. }
  9130. }
  9131. documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2;
  9132. documentData.ls = documentData.ls || 0;
  9133. documentData.ascent = (fontData.ascent * documentData.finalSize) / 100;
  9134. };
  9135. TextProperty.prototype.updateDocumentData = function (newData, index) {
  9136. index = index === undefined ? this.keysIndex : index;
  9137. var dData = this.copyData({}, this.data.d.k[index].s);
  9138. dData = this.copyData(dData, newData);
  9139. this.data.d.k[index].s = dData;
  9140. this.recalculate(index);
  9141. this.setCurrentData(dData);
  9142. this.elem.addDynamicProperty(this);
  9143. };
  9144. TextProperty.prototype.recalculate = function (index) {
  9145. var dData = this.data.d.k[index].s;
  9146. dData.__complete = false;
  9147. this.keysIndex = 0;
  9148. this._isFirstFrame = true;
  9149. this.getValue(dData);
  9150. };
  9151. TextProperty.prototype.canResizeFont = function (_canResize) {
  9152. this.canResize = _canResize;
  9153. this.recalculate(this.keysIndex);
  9154. this.elem.addDynamicProperty(this);
  9155. };
  9156. TextProperty.prototype.setMinimumFontSize = function (_fontValue) {
  9157. this.minimumFontSize = Math.floor(_fontValue) || 1;
  9158. this.recalculate(this.keysIndex);
  9159. this.elem.addDynamicProperty(this);
  9160. };
  9161. const TextSelectorProp = (function () {
  9162. var max = Math.max;
  9163. var min = Math.min;
  9164. var floor = Math.floor;
  9165. function TextSelectorPropFactory(elem, data) {
  9166. this._currentTextLength = -1;
  9167. this.k = false;
  9168. this.data = data;
  9169. this.elem = elem;
  9170. this.comp = elem.comp;
  9171. this.finalS = 0;
  9172. this.finalE = 0;
  9173. this.initDynamicPropertyContainer(elem);
  9174. this.s = PropertyFactory.getProp(elem, data.s || { k: 0 }, 0, 0, this);
  9175. if ('e' in data) {
  9176. this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this);
  9177. } else {
  9178. this.e = { v: 100 };
  9179. }
  9180. this.o = PropertyFactory.getProp(elem, data.o || { k: 0 }, 0, 0, this);
  9181. this.xe = PropertyFactory.getProp(elem, data.xe || { k: 0 }, 0, 0, this);
  9182. this.ne = PropertyFactory.getProp(elem, data.ne || { k: 0 }, 0, 0, this);
  9183. this.sm = PropertyFactory.getProp(elem, data.sm || { k: 100 }, 0, 0, this);
  9184. this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this);
  9185. if (!this.dynamicProperties.length) {
  9186. this.getValue();
  9187. }
  9188. }
  9189. TextSelectorPropFactory.prototype = {
  9190. getMult: function (ind) {
  9191. if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) {
  9192. this.getValue();
  9193. }
  9194. var x1 = 0;
  9195. var y1 = 0;
  9196. var x2 = 1;
  9197. var y2 = 1;
  9198. if (this.ne.v > 0) {
  9199. x1 = this.ne.v / 100.0;
  9200. } else {
  9201. y1 = -this.ne.v / 100.0;
  9202. }
  9203. if (this.xe.v > 0) {
  9204. x2 = 1.0 - this.xe.v / 100.0;
  9205. } else {
  9206. y2 = 1.0 + this.xe.v / 100.0;
  9207. }
  9208. var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get;
  9209. var mult = 0;
  9210. var s = this.finalS;
  9211. var e = this.finalE;
  9212. var type = this.data.sh;
  9213. if (type === 2) {
  9214. if (e === s) {
  9215. mult = ind >= e ? 1 : 0;
  9216. } else {
  9217. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9218. }
  9219. mult = easer(mult);
  9220. } else if (type === 3) {
  9221. if (e === s) {
  9222. mult = ind >= e ? 0 : 1;
  9223. } else {
  9224. mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9225. }
  9226. mult = easer(mult);
  9227. } else if (type === 4) {
  9228. if (e === s) {
  9229. mult = 0;
  9230. } else {
  9231. mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1));
  9232. if (mult < 0.5) {
  9233. mult *= 2;
  9234. } else {
  9235. mult = 1 - 2 * (mult - 0.5);
  9236. }
  9237. }
  9238. mult = easer(mult);
  9239. } else if (type === 5) {
  9240. if (e === s) {
  9241. mult = 0;
  9242. } else {
  9243. var tot = e - s;
  9244. /* ind += 0.5;
  9245. mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */
  9246. ind = min(max(0, ind + 0.5 - s), e - s);
  9247. var x = -tot / 2 + ind;
  9248. var a = tot / 2;
  9249. mult = Math.sqrt(1 - (x * x) / (a * a));
  9250. }
  9251. mult = easer(mult);
  9252. } else if (type === 6) {
  9253. if (e === s) {
  9254. mult = 0;
  9255. } else {
  9256. ind = min(max(0, ind + 0.5 - s), e - s);
  9257. mult = (1 + (Math.cos((Math.PI + Math.PI * 2 * (ind) / (e - s))))) / 2; // eslint-disable-line
  9258. }
  9259. mult = easer(mult);
  9260. } else {
  9261. if (ind >= floor(s)) {
  9262. if (ind - s < 0) {
  9263. mult = max(0, min(min(e, 1) - (s - ind), 1));
  9264. } else {
  9265. mult = max(0, min(e - ind, 1));
  9266. }
  9267. }
  9268. mult = easer(mult);
  9269. }
  9270. // Smoothness implementation.
  9271. // The smoothness represents a reduced range of the original [0; 1] range.
  9272. // if smoothness is 25%, the new range will be [0.375; 0.625]
  9273. // Steps are:
  9274. // - find the lower value of the new range (threshold)
  9275. // - if multiplier is smaller than that value, floor it to 0
  9276. // - if it is larger,
  9277. // - subtract the threshold
  9278. // - divide it by the smoothness (this will return the range to [0; 1])
  9279. // Note: If it doesn't work on some scenarios, consider applying it before the easer.
  9280. if (this.sm.v !== 100) {
  9281. var smoothness = this.sm.v * 0.01;
  9282. if (smoothness === 0) {
  9283. smoothness = 0.00000001;
  9284. }
  9285. var threshold = 0.5 - smoothness * 0.5;
  9286. if (mult < threshold) {
  9287. mult = 0;
  9288. } else {
  9289. mult = (mult - threshold) / smoothness;
  9290. if (mult > 1) {
  9291. mult = 1;
  9292. }
  9293. }
  9294. }
  9295. return mult * this.a.v;
  9296. },
  9297. getValue: function (newCharsFlag) {
  9298. this.iterateDynamicProperties();
  9299. this._mdf = newCharsFlag || this._mdf;
  9300. this._currentTextLength = this.elem.textProperty.currentData.l.length || 0;
  9301. if (newCharsFlag && this.data.r === 2) {
  9302. this.e.v = this._currentTextLength;
  9303. }
  9304. var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars;
  9305. var o = this.o.v / divisor;
  9306. var s = this.s.v / divisor + o;
  9307. var e = (this.e.v / divisor) + o;
  9308. if (s > e) {
  9309. var _s = s;
  9310. s = e;
  9311. e = _s;
  9312. }
  9313. this.finalS = s;
  9314. this.finalE = e;
  9315. },
  9316. };
  9317. extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory);
  9318. function getTextSelectorProp(elem, data, arr) {
  9319. return new TextSelectorPropFactory(elem, data, arr);
  9320. }
  9321. return {
  9322. getTextSelectorProp: getTextSelectorProp,
  9323. };
  9324. }());
  9325. function TextAnimatorDataProperty(elem, animatorProps, container) {
  9326. var defaultData = { propType: false };
  9327. var getProp = PropertyFactory.getProp;
  9328. var textAnimatorAnimatables = animatorProps.a;
  9329. this.a = {
  9330. r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData,
  9331. rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData,
  9332. ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData,
  9333. sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData,
  9334. sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData,
  9335. s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData,
  9336. a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData,
  9337. o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData,
  9338. p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData,
  9339. sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData,
  9340. sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData,
  9341. fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData,
  9342. fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData,
  9343. fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData,
  9344. fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData,
  9345. t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData,
  9346. };
  9347. this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container);
  9348. this.s.t = animatorProps.s.t;
  9349. }
  9350. function TextAnimatorProperty(textData, renderType, elem) {
  9351. this._isFirstFrame = true;
  9352. this._hasMaskedPath = false;
  9353. this._frameId = -1;
  9354. this._textData = textData;
  9355. this._renderType = renderType;
  9356. this._elem = elem;
  9357. this._animatorsData = createSizedArray(this._textData.a.length);
  9358. this._pathData = {};
  9359. this._moreOptions = {
  9360. alignment: {},
  9361. };
  9362. this.renderedLetters = [];
  9363. this.lettersChangedFlag = false;
  9364. this.initDynamicPropertyContainer(elem);
  9365. }
  9366. TextAnimatorProperty.prototype.searchProperties = function () {
  9367. var i;
  9368. var len = this._textData.a.length;
  9369. var animatorProps;
  9370. var getProp = PropertyFactory.getProp;
  9371. for (i = 0; i < len; i += 1) {
  9372. animatorProps = this._textData.a[i];
  9373. this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this);
  9374. }
  9375. if (this._textData.p && 'm' in this._textData.p) {
  9376. this._pathData = {
  9377. a: getProp(this._elem, this._textData.p.a, 0, 0, this),
  9378. f: getProp(this._elem, this._textData.p.f, 0, 0, this),
  9379. l: getProp(this._elem, this._textData.p.l, 0, 0, this),
  9380. r: getProp(this._elem, this._textData.p.r, 0, 0, this),
  9381. p: getProp(this._elem, this._textData.p.p, 0, 0, this),
  9382. m: this._elem.maskManager.getMaskProperty(this._textData.p.m),
  9383. };
  9384. this._hasMaskedPath = true;
  9385. } else {
  9386. this._hasMaskedPath = false;
  9387. }
  9388. this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this);
  9389. };
  9390. TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) {
  9391. this.lettersChangedFlag = lettersChangedFlag;
  9392. if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) {
  9393. return;
  9394. }
  9395. this._isFirstFrame = false;
  9396. var alignment = this._moreOptions.alignment.v;
  9397. var animators = this._animatorsData;
  9398. var textData = this._textData;
  9399. var matrixHelper = this.mHelper;
  9400. var renderType = this._renderType;
  9401. var renderedLettersCount = this.renderedLetters.length;
  9402. var xPos;
  9403. var yPos;
  9404. var i;
  9405. var len;
  9406. var letters = documentData.l;
  9407. var pathInfo;
  9408. var currentLength;
  9409. var currentPoint;
  9410. var segmentLength;
  9411. var flag;
  9412. var pointInd;
  9413. var segmentInd;
  9414. var prevPoint;
  9415. var points;
  9416. var segments;
  9417. var partialLength;
  9418. var totalLength;
  9419. var perc;
  9420. var tanAngle;
  9421. var mask;
  9422. if (this._hasMaskedPath) {
  9423. mask = this._pathData.m;
  9424. if (!this._pathData.n || this._pathData._mdf) {
  9425. var paths = mask.v;
  9426. if (this._pathData.r.v) {
  9427. paths = paths.reverse();
  9428. }
  9429. // TODO: release bezier data cached from previous pathInfo: this._pathData.pi
  9430. pathInfo = {
  9431. tLength: 0,
  9432. segments: [],
  9433. };
  9434. len = paths._length - 1;
  9435. var bezierData;
  9436. totalLength = 0;
  9437. for (i = 0; i < len; i += 1) {
  9438. bezierData = bez.buildBezierData(paths.v[i],
  9439. paths.v[i + 1],
  9440. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9441. [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]);
  9442. pathInfo.tLength += bezierData.segmentLength;
  9443. pathInfo.segments.push(bezierData);
  9444. totalLength += bezierData.segmentLength;
  9445. }
  9446. i = len;
  9447. if (mask.v.c) {
  9448. bezierData = bez.buildBezierData(paths.v[i],
  9449. paths.v[0],
  9450. [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]],
  9451. [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]);
  9452. pathInfo.tLength += bezierData.segmentLength;
  9453. pathInfo.segments.push(bezierData);
  9454. totalLength += bezierData.segmentLength;
  9455. }
  9456. this._pathData.pi = pathInfo;
  9457. }
  9458. pathInfo = this._pathData.pi;
  9459. currentLength = this._pathData.f.v;
  9460. segmentInd = 0;
  9461. pointInd = 1;
  9462. segmentLength = 0;
  9463. flag = true;
  9464. segments = pathInfo.segments;
  9465. if (currentLength < 0 && mask.v.c) {
  9466. if (pathInfo.tLength < Math.abs(currentLength)) {
  9467. currentLength = -Math.abs(currentLength) % pathInfo.tLength;
  9468. }
  9469. segmentInd = segments.length - 1;
  9470. points = segments[segmentInd].points;
  9471. pointInd = points.length - 1;
  9472. while (currentLength < 0) {
  9473. currentLength += points[pointInd].partialLength;
  9474. pointInd -= 1;
  9475. if (pointInd < 0) {
  9476. segmentInd -= 1;
  9477. points = segments[segmentInd].points;
  9478. pointInd = points.length - 1;
  9479. }
  9480. }
  9481. }
  9482. points = segments[segmentInd].points;
  9483. prevPoint = points[pointInd - 1];
  9484. currentPoint = points[pointInd];
  9485. partialLength = currentPoint.partialLength;
  9486. }
  9487. len = letters.length;
  9488. xPos = 0;
  9489. yPos = 0;
  9490. var yOff = documentData.finalSize * 1.2 * 0.714;
  9491. var firstLine = true;
  9492. var animatorProps;
  9493. var animatorSelector;
  9494. var j;
  9495. var jLen;
  9496. var letterValue;
  9497. jLen = animators.length;
  9498. var mult;
  9499. var ind = -1;
  9500. var offf;
  9501. var xPathPos;
  9502. var yPathPos;
  9503. var initPathPos = currentLength;
  9504. var initSegmentInd = segmentInd;
  9505. var initPointInd = pointInd;
  9506. var currentLine = -1;
  9507. var elemOpacity;
  9508. var sc;
  9509. var sw;
  9510. var fc;
  9511. var k;
  9512. var letterSw;
  9513. var letterSc;
  9514. var letterFc;
  9515. var letterM = '';
  9516. var letterP = this.defaultPropsArray;
  9517. var letterO;
  9518. //
  9519. if (documentData.j === 2 || documentData.j === 1) {
  9520. var animatorJustifyOffset = 0;
  9521. var animatorFirstCharOffset = 0;
  9522. var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1;
  9523. var lastIndex = 0;
  9524. var isNewLine = true;
  9525. for (i = 0; i < len; i += 1) {
  9526. if (letters[i].n) {
  9527. if (animatorJustifyOffset) {
  9528. animatorJustifyOffset += animatorFirstCharOffset;
  9529. }
  9530. while (lastIndex < i) {
  9531. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9532. lastIndex += 1;
  9533. }
  9534. animatorJustifyOffset = 0;
  9535. isNewLine = true;
  9536. } else {
  9537. for (j = 0; j < jLen; j += 1) {
  9538. animatorProps = animators[j].a;
  9539. if (animatorProps.t.propType) {
  9540. if (isNewLine && documentData.j === 2) {
  9541. animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult;
  9542. }
  9543. animatorSelector = animators[j].s;
  9544. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9545. if (mult.length) {
  9546. animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult;
  9547. } else {
  9548. animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult;
  9549. }
  9550. }
  9551. }
  9552. isNewLine = false;
  9553. }
  9554. }
  9555. if (animatorJustifyOffset) {
  9556. animatorJustifyOffset += animatorFirstCharOffset;
  9557. }
  9558. while (lastIndex < i) {
  9559. letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset;
  9560. lastIndex += 1;
  9561. }
  9562. }
  9563. //
  9564. for (i = 0; i < len; i += 1) {
  9565. matrixHelper.reset();
  9566. elemOpacity = 1;
  9567. if (letters[i].n) {
  9568. xPos = 0;
  9569. yPos += documentData.yOffset;
  9570. yPos += firstLine ? 1 : 0;
  9571. currentLength = initPathPos;
  9572. firstLine = false;
  9573. if (this._hasMaskedPath) {
  9574. segmentInd = initSegmentInd;
  9575. pointInd = initPointInd;
  9576. points = segments[segmentInd].points;
  9577. prevPoint = points[pointInd - 1];
  9578. currentPoint = points[pointInd];
  9579. partialLength = currentPoint.partialLength;
  9580. segmentLength = 0;
  9581. }
  9582. letterM = '';
  9583. letterFc = '';
  9584. letterSw = '';
  9585. letterO = '';
  9586. letterP = this.defaultPropsArray;
  9587. } else {
  9588. if (this._hasMaskedPath) {
  9589. if (currentLine !== letters[i].line) {
  9590. switch (documentData.j) {
  9591. case 1:
  9592. currentLength += totalLength - documentData.lineWidths[letters[i].line];
  9593. break;
  9594. case 2:
  9595. currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2;
  9596. break;
  9597. default:
  9598. break;
  9599. }
  9600. currentLine = letters[i].line;
  9601. }
  9602. if (ind !== letters[i].ind) {
  9603. if (letters[ind]) {
  9604. currentLength += letters[ind].extra;
  9605. }
  9606. currentLength += letters[i].an / 2;
  9607. ind = letters[i].ind;
  9608. }
  9609. currentLength += (alignment[0] * letters[i].an) * 0.005;
  9610. var animatorOffset = 0;
  9611. for (j = 0; j < jLen; j += 1) {
  9612. animatorProps = animators[j].a;
  9613. if (animatorProps.p.propType) {
  9614. animatorSelector = animators[j].s;
  9615. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9616. if (mult.length) {
  9617. animatorOffset += animatorProps.p.v[0] * mult[0];
  9618. } else {
  9619. animatorOffset += animatorProps.p.v[0] * mult;
  9620. }
  9621. }
  9622. if (animatorProps.a.propType) {
  9623. animatorSelector = animators[j].s;
  9624. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9625. if (mult.length) {
  9626. animatorOffset += animatorProps.a.v[0] * mult[0];
  9627. } else {
  9628. animatorOffset += animatorProps.a.v[0] * mult;
  9629. }
  9630. }
  9631. }
  9632. flag = true;
  9633. // Force alignment only works with a single line for now
  9634. if (this._pathData.a.v) {
  9635. 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);
  9636. currentLength += this._pathData.f.v;
  9637. }
  9638. while (flag) {
  9639. if (segmentLength + partialLength >= currentLength + animatorOffset || !points) {
  9640. perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength;
  9641. xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc;
  9642. yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc;
  9643. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, -(alignment[1] * yOff) * 0.01);
  9644. flag = false;
  9645. } else if (points) {
  9646. segmentLength += currentPoint.partialLength;
  9647. pointInd += 1;
  9648. if (pointInd >= points.length) {
  9649. pointInd = 0;
  9650. segmentInd += 1;
  9651. if (!segments[segmentInd]) {
  9652. if (mask.v.c) {
  9653. pointInd = 0;
  9654. segmentInd = 0;
  9655. points = segments[segmentInd].points;
  9656. } else {
  9657. segmentLength -= currentPoint.partialLength;
  9658. points = null;
  9659. }
  9660. } else {
  9661. points = segments[segmentInd].points;
  9662. }
  9663. }
  9664. if (points) {
  9665. prevPoint = currentPoint;
  9666. currentPoint = points[pointInd];
  9667. partialLength = currentPoint.partialLength;
  9668. }
  9669. }
  9670. }
  9671. offf = letters[i].an / 2 - letters[i].add;
  9672. matrixHelper.translate(-offf, 0, 0);
  9673. } else {
  9674. offf = letters[i].an / 2 - letters[i].add;
  9675. matrixHelper.translate(-offf, 0, 0);
  9676. // Grouping alignment
  9677. matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, (-alignment[1] * yOff) * 0.01, 0);
  9678. }
  9679. for (j = 0; j < jLen; j += 1) {
  9680. animatorProps = animators[j].a;
  9681. if (animatorProps.t.propType) {
  9682. animatorSelector = animators[j].s;
  9683. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9684. // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine"
  9685. if (xPos !== 0 || documentData.j !== 0) {
  9686. if (this._hasMaskedPath) {
  9687. if (mult.length) {
  9688. currentLength += animatorProps.t.v * mult[0];
  9689. } else {
  9690. currentLength += animatorProps.t.v * mult;
  9691. }
  9692. } else if (mult.length) {
  9693. xPos += animatorProps.t.v * mult[0];
  9694. } else {
  9695. xPos += animatorProps.t.v * mult;
  9696. }
  9697. }
  9698. }
  9699. }
  9700. if (documentData.strokeWidthAnim) {
  9701. sw = documentData.sw || 0;
  9702. }
  9703. if (documentData.strokeColorAnim) {
  9704. if (documentData.sc) {
  9705. sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]];
  9706. } else {
  9707. sc = [0, 0, 0];
  9708. }
  9709. }
  9710. if (documentData.fillColorAnim && documentData.fc) {
  9711. fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]];
  9712. }
  9713. for (j = 0; j < jLen; j += 1) {
  9714. animatorProps = animators[j].a;
  9715. if (animatorProps.a.propType) {
  9716. animatorSelector = animators[j].s;
  9717. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9718. if (mult.length) {
  9719. matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]);
  9720. } else {
  9721. matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult);
  9722. }
  9723. }
  9724. }
  9725. for (j = 0; j < jLen; j += 1) {
  9726. animatorProps = animators[j].a;
  9727. if (animatorProps.s.propType) {
  9728. animatorSelector = animators[j].s;
  9729. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9730. if (mult.length) {
  9731. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult[0]), 1 + ((animatorProps.s.v[1] - 1) * mult[1]), 1);
  9732. } else {
  9733. matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult), 1 + ((animatorProps.s.v[1] - 1) * mult), 1);
  9734. }
  9735. }
  9736. }
  9737. for (j = 0; j < jLen; j += 1) {
  9738. animatorProps = animators[j].a;
  9739. animatorSelector = animators[j].s;
  9740. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9741. if (animatorProps.sk.propType) {
  9742. if (mult.length) {
  9743. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]);
  9744. } else {
  9745. matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult);
  9746. }
  9747. }
  9748. if (animatorProps.r.propType) {
  9749. if (mult.length) {
  9750. matrixHelper.rotateZ(-animatorProps.r.v * mult[2]);
  9751. } else {
  9752. matrixHelper.rotateZ(-animatorProps.r.v * mult);
  9753. }
  9754. }
  9755. if (animatorProps.ry.propType) {
  9756. if (mult.length) {
  9757. matrixHelper.rotateY(animatorProps.ry.v * mult[1]);
  9758. } else {
  9759. matrixHelper.rotateY(animatorProps.ry.v * mult);
  9760. }
  9761. }
  9762. if (animatorProps.rx.propType) {
  9763. if (mult.length) {
  9764. matrixHelper.rotateX(animatorProps.rx.v * mult[0]);
  9765. } else {
  9766. matrixHelper.rotateX(animatorProps.rx.v * mult);
  9767. }
  9768. }
  9769. if (animatorProps.o.propType) {
  9770. if (mult.length) {
  9771. elemOpacity += ((animatorProps.o.v) * mult[0] - elemOpacity) * mult[0];
  9772. } else {
  9773. elemOpacity += ((animatorProps.o.v) * mult - elemOpacity) * mult;
  9774. }
  9775. }
  9776. if (documentData.strokeWidthAnim && animatorProps.sw.propType) {
  9777. if (mult.length) {
  9778. sw += animatorProps.sw.v * mult[0];
  9779. } else {
  9780. sw += animatorProps.sw.v * mult;
  9781. }
  9782. }
  9783. if (documentData.strokeColorAnim && animatorProps.sc.propType) {
  9784. for (k = 0; k < 3; k += 1) {
  9785. if (mult.length) {
  9786. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0];
  9787. } else {
  9788. sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult;
  9789. }
  9790. }
  9791. }
  9792. if (documentData.fillColorAnim && documentData.fc) {
  9793. if (animatorProps.fc.propType) {
  9794. for (k = 0; k < 3; k += 1) {
  9795. if (mult.length) {
  9796. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0];
  9797. } else {
  9798. fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult;
  9799. }
  9800. }
  9801. }
  9802. if (animatorProps.fh.propType) {
  9803. if (mult.length) {
  9804. fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]);
  9805. } else {
  9806. fc = addHueToRGB(fc, animatorProps.fh.v * mult);
  9807. }
  9808. }
  9809. if (animatorProps.fs.propType) {
  9810. if (mult.length) {
  9811. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]);
  9812. } else {
  9813. fc = addSaturationToRGB(fc, animatorProps.fs.v * mult);
  9814. }
  9815. }
  9816. if (animatorProps.fb.propType) {
  9817. if (mult.length) {
  9818. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]);
  9819. } else {
  9820. fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult);
  9821. }
  9822. }
  9823. }
  9824. }
  9825. for (j = 0; j < jLen; j += 1) {
  9826. animatorProps = animators[j].a;
  9827. if (animatorProps.p.propType) {
  9828. animatorSelector = animators[j].s;
  9829. mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars);
  9830. if (this._hasMaskedPath) {
  9831. if (mult.length) {
  9832. matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]);
  9833. } else {
  9834. matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9835. }
  9836. } else if (mult.length) {
  9837. matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]);
  9838. } else {
  9839. matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult);
  9840. }
  9841. }
  9842. }
  9843. if (documentData.strokeWidthAnim) {
  9844. letterSw = sw < 0 ? 0 : sw;
  9845. }
  9846. if (documentData.strokeColorAnim) {
  9847. letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')';
  9848. }
  9849. if (documentData.fillColorAnim && documentData.fc) {
  9850. letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')';
  9851. }
  9852. if (this._hasMaskedPath) {
  9853. matrixHelper.translate(0, -documentData.ls);
  9854. matrixHelper.translate(0, (alignment[1] * yOff) * 0.01 + yPos, 0);
  9855. if (this._pathData.p.v) {
  9856. tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]);
  9857. var rot = (Math.atan(tanAngle) * 180) / Math.PI;
  9858. if (currentPoint.point[0] < prevPoint.point[0]) {
  9859. rot += 180;
  9860. }
  9861. matrixHelper.rotate((-rot * Math.PI) / 180);
  9862. }
  9863. matrixHelper.translate(xPathPos, yPathPos, 0);
  9864. currentLength -= (alignment[0] * letters[i].an) * 0.005;
  9865. if (letters[i + 1] && ind !== letters[i + 1].ind) {
  9866. currentLength += letters[i].an / 2;
  9867. currentLength += (documentData.tr * 0.001) * documentData.finalSize;
  9868. }
  9869. } else {
  9870. matrixHelper.translate(xPos, yPos, 0);
  9871. if (documentData.ps) {
  9872. // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0);
  9873. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9874. }
  9875. switch (documentData.j) {
  9876. case 1:
  9877. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0);
  9878. break;
  9879. case 2:
  9880. matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0);
  9881. break;
  9882. default:
  9883. break;
  9884. }
  9885. matrixHelper.translate(0, -documentData.ls);
  9886. matrixHelper.translate(offf, 0, 0);
  9887. matrixHelper.translate((alignment[0] * letters[i].an) * 0.005, (alignment[1] * yOff) * 0.01, 0);
  9888. xPos += letters[i].l + (documentData.tr * 0.001) * documentData.finalSize;
  9889. }
  9890. if (renderType === 'html') {
  9891. letterM = matrixHelper.toCSS();
  9892. } else if (renderType === 'svg') {
  9893. letterM = matrixHelper.to2dCSS();
  9894. } else {
  9895. 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]];
  9896. }
  9897. letterO = elemOpacity;
  9898. }
  9899. if (renderedLettersCount <= i) {
  9900. letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP);
  9901. this.renderedLetters.push(letterValue);
  9902. renderedLettersCount += 1;
  9903. this.lettersChangedFlag = true;
  9904. } else {
  9905. letterValue = this.renderedLetters[i];
  9906. this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag;
  9907. }
  9908. }
  9909. };
  9910. TextAnimatorProperty.prototype.getValue = function () {
  9911. if (this._elem.globalData.frameId === this._frameId) {
  9912. return;
  9913. }
  9914. this._frameId = this._elem.globalData.frameId;
  9915. this.iterateDynamicProperties();
  9916. };
  9917. TextAnimatorProperty.prototype.mHelper = new Matrix();
  9918. TextAnimatorProperty.prototype.defaultPropsArray = [];
  9919. extendPrototype([DynamicPropertyContainer], TextAnimatorProperty);
  9920. function ITextElement() {
  9921. }
  9922. ITextElement.prototype.initElement = function (data, globalData, comp) {
  9923. this.lettersChangedFlag = true;
  9924. this.initFrame();
  9925. this.initBaseData(data, globalData, comp);
  9926. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  9927. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  9928. this.initTransform(data, globalData, comp);
  9929. this.initHierarchy();
  9930. this.initRenderable();
  9931. this.initRendererElement();
  9932. this.createContainerElements();
  9933. this.createRenderableComponents();
  9934. this.createContent();
  9935. this.hide();
  9936. this.textAnimator.searchProperties(this.dynamicProperties);
  9937. };
  9938. ITextElement.prototype.prepareFrame = function (num) {
  9939. this._mdf = false;
  9940. this.prepareRenderableFrame(num);
  9941. this.prepareProperties(num, this.isInRange);
  9942. };
  9943. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  9944. var j;
  9945. var jLen = shapes.length;
  9946. var pathNodes;
  9947. var shapeStr = '';
  9948. for (j = 0; j < jLen; j += 1) {
  9949. if (shapes[j].ty === 'sh') {
  9950. pathNodes = shapes[j].ks.k;
  9951. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  9952. }
  9953. }
  9954. return shapeStr;
  9955. };
  9956. ITextElement.prototype.updateDocumentData = function (newData, index) {
  9957. this.textProperty.updateDocumentData(newData, index);
  9958. };
  9959. ITextElement.prototype.canResizeFont = function (_canResize) {
  9960. this.textProperty.canResizeFont(_canResize);
  9961. };
  9962. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  9963. this.textProperty.setMinimumFontSize(_fontSize);
  9964. };
  9965. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  9966. if (documentData.ps) {
  9967. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  9968. }
  9969. matrixHelper.translate(0, -documentData.ls, 0);
  9970. switch (documentData.j) {
  9971. case 1:
  9972. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  9973. break;
  9974. case 2:
  9975. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  9976. break;
  9977. default:
  9978. break;
  9979. }
  9980. matrixHelper.translate(xPos, yPos, 0);
  9981. };
  9982. ITextElement.prototype.buildColor = function (colorData) {
  9983. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  9984. };
  9985. ITextElement.prototype.emptyProp = new LetterProps();
  9986. ITextElement.prototype.destroy = function () {
  9987. };
  9988. ITextElement.prototype.validateText = function () {
  9989. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  9990. this.buildNewText();
  9991. this.textProperty._isFirstFrame = false;
  9992. this.textProperty._mdf = false;
  9993. }
  9994. };
  9995. var emptyShapeData = {
  9996. shapes: [],
  9997. };
  9998. function SVGTextLottieElement(data, globalData, comp) {
  9999. this.textSpans = [];
  10000. this.renderType = 'svg';
  10001. this.initElement(data, globalData, comp);
  10002. }
  10003. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement);
  10004. SVGTextLottieElement.prototype.createContent = function () {
  10005. if (this.data.singleShape && !this.globalData.fontManager.chars) {
  10006. this.textContainer = createNS('text');
  10007. }
  10008. };
  10009. SVGTextLottieElement.prototype.buildTextContents = function (textArray) {
  10010. var i = 0;
  10011. var len = textArray.length;
  10012. var textContents = [];
  10013. var currentTextContent = '';
  10014. while (i < len) {
  10015. if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) {
  10016. textContents.push(currentTextContent);
  10017. currentTextContent = '';
  10018. } else {
  10019. currentTextContent += textArray[i];
  10020. }
  10021. i += 1;
  10022. }
  10023. textContents.push(currentTextContent);
  10024. return textContents;
  10025. };
  10026. SVGTextLottieElement.prototype.buildShapeData = function (data, scale) {
  10027. // data should probably be cloned to apply scale separately to each instance of a text on different layers
  10028. // but since text internal content gets only rendered once and then it's never rerendered,
  10029. // it's probably safe not to clone data and reuse always the same instance even if the object is mutated.
  10030. // Avoiding cloning is preferred since cloning each character shape data is expensive
  10031. if (data.shapes && data.shapes.length) {
  10032. var shape = data.shapes[0];
  10033. if (shape.it) {
  10034. var shapeItem = shape.it[shape.it.length - 1];
  10035. if (shapeItem.s) {
  10036. shapeItem.s.k[0] = scale;
  10037. shapeItem.s.k[1] = scale;
  10038. }
  10039. }
  10040. }
  10041. return data;
  10042. };
  10043. SVGTextLottieElement.prototype.buildNewText = function () {
  10044. this.addDynamicProperty(this);
  10045. var i;
  10046. var len;
  10047. var documentData = this.textProperty.currentData;
  10048. this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0);
  10049. if (documentData.fc) {
  10050. this.layerElement.setAttribute('fill', this.buildColor(documentData.fc));
  10051. } else {
  10052. this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)');
  10053. }
  10054. if (documentData.sc) {
  10055. this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc));
  10056. this.layerElement.setAttribute('stroke-width', documentData.sw);
  10057. }
  10058. this.layerElement.setAttribute('font-size', documentData.finalSize);
  10059. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  10060. if (fontData.fClass) {
  10061. this.layerElement.setAttribute('class', fontData.fClass);
  10062. } else {
  10063. this.layerElement.setAttribute('font-family', fontData.fFamily);
  10064. var fWeight = documentData.fWeight;
  10065. var fStyle = documentData.fStyle;
  10066. this.layerElement.setAttribute('font-style', fStyle);
  10067. this.layerElement.setAttribute('font-weight', fWeight);
  10068. }
  10069. this.layerElement.setAttribute('aria-label', documentData.t);
  10070. var letters = documentData.l || [];
  10071. var usesGlyphs = !!this.globalData.fontManager.chars;
  10072. len = letters.length;
  10073. var tSpan;
  10074. var matrixHelper = this.mHelper;
  10075. var shapeStr = '';
  10076. var singleShape = this.data.singleShape;
  10077. var xPos = 0;
  10078. var yPos = 0;
  10079. var firstLine = true;
  10080. var trackingOffset = documentData.tr * 0.001 * documentData.finalSize;
  10081. if (singleShape && !usesGlyphs && !documentData.sz) {
  10082. var tElement = this.textContainer;
  10083. var justify = 'start';
  10084. switch (documentData.j) {
  10085. case 1:
  10086. justify = 'end';
  10087. break;
  10088. case 2:
  10089. justify = 'middle';
  10090. break;
  10091. default:
  10092. justify = 'start';
  10093. break;
  10094. }
  10095. tElement.setAttribute('text-anchor', justify);
  10096. tElement.setAttribute('letter-spacing', trackingOffset);
  10097. var textContent = this.buildTextContents(documentData.finalText);
  10098. len = textContent.length;
  10099. yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0;
  10100. for (i = 0; i < len; i += 1) {
  10101. tSpan = this.textSpans[i].span || createNS('tspan');
  10102. tSpan.textContent = textContent[i];
  10103. tSpan.setAttribute('x', 0);
  10104. tSpan.setAttribute('y', yPos);
  10105. tSpan.style.display = 'inherit';
  10106. tElement.appendChild(tSpan);
  10107. if (!this.textSpans[i]) {
  10108. this.textSpans[i] = {
  10109. span: null,
  10110. glyph: null,
  10111. };
  10112. }
  10113. this.textSpans[i].span = tSpan;
  10114. yPos += documentData.finalLineHeight;
  10115. }
  10116. this.layerElement.appendChild(tElement);
  10117. } else {
  10118. var cachedSpansLength = this.textSpans.length;
  10119. var charData;
  10120. for (i = 0; i < len; i += 1) {
  10121. if (!this.textSpans[i]) {
  10122. this.textSpans[i] = {
  10123. span: null,
  10124. childSpan: null,
  10125. glyph: null,
  10126. };
  10127. }
  10128. if (!usesGlyphs || !singleShape || i === 0) {
  10129. tSpan = cachedSpansLength > i ? this.textSpans[i].span : createNS(usesGlyphs ? 'g' : 'text');
  10130. if (cachedSpansLength <= i) {
  10131. tSpan.setAttribute('stroke-linecap', 'butt');
  10132. tSpan.setAttribute('stroke-linejoin', 'round');
  10133. tSpan.setAttribute('stroke-miterlimit', '4');
  10134. this.textSpans[i].span = tSpan;
  10135. if (usesGlyphs) {
  10136. var childSpan = createNS('g');
  10137. tSpan.appendChild(childSpan);
  10138. this.textSpans[i].childSpan = childSpan;
  10139. }
  10140. this.textSpans[i].span = tSpan;
  10141. this.layerElement.appendChild(tSpan);
  10142. }
  10143. tSpan.style.display = 'inherit';
  10144. }
  10145. matrixHelper.reset();
  10146. if (singleShape) {
  10147. if (letters[i].n) {
  10148. xPos = -trackingOffset;
  10149. yPos += documentData.yOffset;
  10150. yPos += firstLine ? 1 : 0;
  10151. firstLine = false;
  10152. }
  10153. this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos);
  10154. xPos += letters[i].l || 0;
  10155. // xPos += letters[i].val === ' ' ? 0 : trackingOffset;
  10156. xPos += trackingOffset;
  10157. }
  10158. if (usesGlyphs) {
  10159. charData = this.globalData.fontManager.getCharData(
  10160. documentData.finalText[i],
  10161. fontData.fStyle,
  10162. this.globalData.fontManager.getFontByName(documentData.f).fFamily
  10163. );
  10164. var glyphElement;
  10165. // t === 1 means the character has been replaced with an animated shaped
  10166. if (charData.t === 1) {
  10167. glyphElement = new SVGCompElement(charData.data, this.globalData, this);
  10168. } else {
  10169. var data = emptyShapeData;
  10170. if (charData.data && charData.data.shapes) {
  10171. data = this.buildShapeData(charData.data, documentData.finalSize);
  10172. }
  10173. glyphElement = new SVGShapeElement(data, this.globalData, this);
  10174. }
  10175. if (this.textSpans[i].glyph) {
  10176. var glyph = this.textSpans[i].glyph;
  10177. this.textSpans[i].childSpan.removeChild(glyph.layerElement);
  10178. glyph.destroy();
  10179. }
  10180. this.textSpans[i].glyph = glyphElement;
  10181. glyphElement._debug = true;
  10182. glyphElement.prepareFrame(0);
  10183. glyphElement.renderFrame();
  10184. this.textSpans[i].childSpan.appendChild(glyphElement.layerElement);
  10185. // when using animated shapes, the layer will be scaled instead of replacing the internal scale
  10186. // this might have issues with strokes and might need a different solution
  10187. if (charData.t === 1) {
  10188. this.textSpans[i].childSpan.setAttribute('transform', 'scale(' + documentData.finalSize / 100 + ',' + documentData.finalSize / 100 + ')');
  10189. }
  10190. } else {
  10191. if (singleShape) {
  10192. tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')');
  10193. }
  10194. tSpan.textContent = letters[i].val;
  10195. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  10196. }
  10197. //
  10198. }
  10199. if (singleShape && tSpan) {
  10200. tSpan.setAttribute('d', shapeStr);
  10201. }
  10202. }
  10203. while (i < this.textSpans.length) {
  10204. this.textSpans[i].span.style.display = 'none';
  10205. i += 1;
  10206. }
  10207. this._sizeChanged = true;
  10208. };
  10209. SVGTextLottieElement.prototype.sourceRectAtTime = function () {
  10210. this.prepareFrame(this.comp.renderedFrame - this.data.st);
  10211. this.renderInnerContent();
  10212. if (this._sizeChanged) {
  10213. this._sizeChanged = false;
  10214. var textBox = this.layerElement.getBBox();
  10215. this.bbox = {
  10216. top: textBox.y,
  10217. left: textBox.x,
  10218. width: textBox.width,
  10219. height: textBox.height,
  10220. };
  10221. }
  10222. return this.bbox;
  10223. };
  10224. SVGTextLottieElement.prototype.getValue = function () {
  10225. var i;
  10226. var len = this.textSpans.length;
  10227. var glyphElement;
  10228. this.renderedFrame = this.comp.renderedFrame;
  10229. for (i = 0; i < len; i += 1) {
  10230. glyphElement = this.textSpans[i].glyph;
  10231. if (glyphElement) {
  10232. glyphElement.prepareFrame(this.comp.renderedFrame - this.data.st);
  10233. if (glyphElement._mdf) {
  10234. this._mdf = true;
  10235. }
  10236. }
  10237. }
  10238. };
  10239. SVGTextLottieElement.prototype.renderInnerContent = function () {
  10240. this.validateText();
  10241. if (!this.data.singleShape || this._mdf) {
  10242. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  10243. if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) {
  10244. this._sizeChanged = true;
  10245. var i;
  10246. var len;
  10247. var renderedLetters = this.textAnimator.renderedLetters;
  10248. var letters = this.textProperty.currentData.l;
  10249. len = letters.length;
  10250. var renderedLetter;
  10251. var textSpan;
  10252. var glyphElement;
  10253. for (i = 0; i < len; i += 1) {
  10254. if (!letters[i].n) {
  10255. renderedLetter = renderedLetters[i];
  10256. textSpan = this.textSpans[i].span;
  10257. glyphElement = this.textSpans[i].glyph;
  10258. if (glyphElement) {
  10259. glyphElement.renderFrame();
  10260. }
  10261. if (renderedLetter._mdf.m) {
  10262. textSpan.setAttribute('transform', renderedLetter.m);
  10263. }
  10264. if (renderedLetter._mdf.o) {
  10265. textSpan.setAttribute('opacity', renderedLetter.o);
  10266. }
  10267. if (renderedLetter._mdf.sw) {
  10268. textSpan.setAttribute('stroke-width', renderedLetter.sw);
  10269. }
  10270. if (renderedLetter._mdf.sc) {
  10271. textSpan.setAttribute('stroke', renderedLetter.sc);
  10272. }
  10273. if (renderedLetter._mdf.fc) {
  10274. textSpan.setAttribute('fill', renderedLetter.fc);
  10275. }
  10276. }
  10277. }
  10278. }
  10279. }
  10280. };
  10281. function ISolidElement(data, globalData, comp) {
  10282. this.initElement(data, globalData, comp);
  10283. }
  10284. extendPrototype([IImageElement], ISolidElement);
  10285. ISolidElement.prototype.createContent = function () {
  10286. var rect = createNS('rect');
  10287. /// /rect.style.width = this.data.sw;
  10288. /// /rect.style.height = this.data.sh;
  10289. /// /rect.style.fill = this.data.sc;
  10290. rect.setAttribute('width', this.data.sw);
  10291. rect.setAttribute('height', this.data.sh);
  10292. rect.setAttribute('fill', this.data.sc);
  10293. this.layerElement.appendChild(rect);
  10294. };
  10295. function NullElement(data, globalData, comp) {
  10296. this.initFrame();
  10297. this.initBaseData(data, globalData, comp);
  10298. this.initFrame();
  10299. this.initTransform(data, globalData, comp);
  10300. this.initHierarchy();
  10301. }
  10302. NullElement.prototype.prepareFrame = function (num) {
  10303. this.prepareProperties(num, true);
  10304. };
  10305. NullElement.prototype.renderFrame = function () {
  10306. };
  10307. NullElement.prototype.getBaseElement = function () {
  10308. return null;
  10309. };
  10310. NullElement.prototype.destroy = function () {
  10311. };
  10312. NullElement.prototype.sourceRectAtTime = function () {
  10313. };
  10314. NullElement.prototype.hide = function () {
  10315. };
  10316. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement);
  10317. function SVGRendererBase() {
  10318. }
  10319. extendPrototype([BaseRenderer], SVGRendererBase);
  10320. SVGRendererBase.prototype.createNull = function (data) {
  10321. return new NullElement(data, this.globalData, this);
  10322. };
  10323. SVGRendererBase.prototype.createShape = function (data) {
  10324. return new SVGShapeElement(data, this.globalData, this);
  10325. };
  10326. SVGRendererBase.prototype.createText = function (data) {
  10327. return new SVGTextLottieElement(data, this.globalData, this);
  10328. };
  10329. SVGRendererBase.prototype.createImage = function (data) {
  10330. return new IImageElement(data, this.globalData, this);
  10331. };
  10332. SVGRendererBase.prototype.createSolid = function (data) {
  10333. return new ISolidElement(data, this.globalData, this);
  10334. };
  10335. SVGRendererBase.prototype.configAnimation = function (animData) {
  10336. this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  10337. this.svgElement.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  10338. if (this.renderConfig.viewBoxSize) {
  10339. this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize);
  10340. } else {
  10341. this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h);
  10342. }
  10343. if (!this.renderConfig.viewBoxOnly) {
  10344. this.svgElement.setAttribute('width', animData.w);
  10345. this.svgElement.setAttribute('height', animData.h);
  10346. this.svgElement.style.width = '100%';
  10347. this.svgElement.style.height = '100%';
  10348. this.svgElement.style.transform = 'translate3d(0,0,0)';
  10349. this.svgElement.style.contentVisibility = this.renderConfig.contentVisibility;
  10350. }
  10351. if (this.renderConfig.width) {
  10352. this.svgElement.setAttribute('width', this.renderConfig.width);
  10353. }
  10354. if (this.renderConfig.height) {
  10355. this.svgElement.setAttribute('height', this.renderConfig.height);
  10356. }
  10357. if (this.renderConfig.className) {
  10358. this.svgElement.setAttribute('class', this.renderConfig.className);
  10359. }
  10360. if (this.renderConfig.id) {
  10361. this.svgElement.setAttribute('id', this.renderConfig.id);
  10362. }
  10363. if (this.renderConfig.focusable !== undefined) {
  10364. this.svgElement.setAttribute('focusable', this.renderConfig.focusable);
  10365. }
  10366. this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio);
  10367. // this.layerElement.style.transform = 'translate3d(0,0,0)';
  10368. // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px";
  10369. this.animationItem.wrapper.appendChild(this.svgElement);
  10370. // Mask animation
  10371. var defs = this.globalData.defs;
  10372. this.setupGlobalData(animData, defs);
  10373. this.globalData.progressiveLoad = this.renderConfig.progressiveLoad;
  10374. this.data = animData;
  10375. var maskElement = createNS('clipPath');
  10376. var rect = createNS('rect');
  10377. rect.setAttribute('width', animData.w);
  10378. rect.setAttribute('height', animData.h);
  10379. rect.setAttribute('x', 0);
  10380. rect.setAttribute('y', 0);
  10381. var maskId = createElementID();
  10382. maskElement.setAttribute('id', maskId);
  10383. maskElement.appendChild(rect);
  10384. this.layerElement.setAttribute('clip-path', 'url(' + getLocationHref() + '#' + maskId + ')');
  10385. defs.appendChild(maskElement);
  10386. this.layers = animData.layers;
  10387. this.elements = createSizedArray(animData.layers.length);
  10388. };
  10389. SVGRendererBase.prototype.destroy = function () {
  10390. if (this.animationItem.wrapper) {
  10391. this.animationItem.wrapper.innerText = '';
  10392. }
  10393. this.layerElement = null;
  10394. this.globalData.defs = null;
  10395. var i;
  10396. var len = this.layers ? this.layers.length : 0;
  10397. for (i = 0; i < len; i += 1) {
  10398. if (this.elements[i] && this.elements[i].destroy) {
  10399. this.elements[i].destroy();
  10400. }
  10401. }
  10402. this.elements.length = 0;
  10403. this.destroyed = true;
  10404. this.animationItem = null;
  10405. };
  10406. SVGRendererBase.prototype.updateContainerSize = function () {
  10407. };
  10408. SVGRendererBase.prototype.findIndexByInd = function (ind) {
  10409. var i = 0;
  10410. var len = this.layers.length;
  10411. for (i = 0; i < len; i += 1) {
  10412. if (this.layers[i].ind === ind) {
  10413. return i;
  10414. }
  10415. }
  10416. return -1;
  10417. };
  10418. SVGRendererBase.prototype.buildItem = function (pos) {
  10419. var elements = this.elements;
  10420. if (elements[pos] || this.layers[pos].ty === 99) {
  10421. return;
  10422. }
  10423. elements[pos] = true;
  10424. var element = this.createItem(this.layers[pos]);
  10425. elements[pos] = element;
  10426. if (getExpressionsPlugin()) {
  10427. if (this.layers[pos].ty === 0) {
  10428. this.globalData.projectInterface.registerComposition(element);
  10429. }
  10430. element.initExpressions();
  10431. }
  10432. this.appendElementInPos(element, pos);
  10433. if (this.layers[pos].tt) {
  10434. var elementIndex = ('tp' in this.layers[pos])
  10435. ? this.findIndexByInd(this.layers[pos].tp)
  10436. : pos - 1;
  10437. if (elementIndex === -1) {
  10438. return;
  10439. }
  10440. if (!this.elements[elementIndex] || this.elements[elementIndex] === true) {
  10441. this.buildItem(elementIndex);
  10442. this.addPendingElement(element);
  10443. } else {
  10444. var matteElement = elements[elementIndex];
  10445. var matteMask = matteElement.getMatte(this.layers[pos].tt);
  10446. element.setMatte(matteMask);
  10447. }
  10448. }
  10449. };
  10450. SVGRendererBase.prototype.checkPendingElements = function () {
  10451. while (this.pendingElements.length) {
  10452. var element = this.pendingElements.pop();
  10453. element.checkParenting();
  10454. if (element.data.tt) {
  10455. var i = 0;
  10456. var len = this.elements.length;
  10457. while (i < len) {
  10458. if (this.elements[i] === element) {
  10459. var elementIndex = 'tp' in element.data
  10460. ? this.findIndexByInd(element.data.tp)
  10461. : i - 1;
  10462. var matteElement = this.elements[elementIndex];
  10463. var matteMask = matteElement.getMatte(this.layers[i].tt);
  10464. element.setMatte(matteMask);
  10465. break;
  10466. }
  10467. i += 1;
  10468. }
  10469. }
  10470. }
  10471. };
  10472. SVGRendererBase.prototype.renderFrame = function (num) {
  10473. if (this.renderedFrame === num || this.destroyed) {
  10474. return;
  10475. }
  10476. if (num === null) {
  10477. num = this.renderedFrame;
  10478. } else {
  10479. this.renderedFrame = num;
  10480. }
  10481. // console.log('-------');
  10482. // console.log('FRAME ',num);
  10483. this.globalData.frameNum = num;
  10484. this.globalData.frameId += 1;
  10485. this.globalData.projectInterface.currentFrame = num;
  10486. this.globalData._mdf = false;
  10487. var i;
  10488. var len = this.layers.length;
  10489. if (!this.completeLayers) {
  10490. this.checkLayers(num);
  10491. }
  10492. for (i = len - 1; i >= 0; i -= 1) {
  10493. if (this.completeLayers || this.elements[i]) {
  10494. this.elements[i].prepareFrame(num - this.layers[i].st);
  10495. }
  10496. }
  10497. if (this.globalData._mdf) {
  10498. for (i = 0; i < len; i += 1) {
  10499. if (this.completeLayers || this.elements[i]) {
  10500. this.elements[i].renderFrame();
  10501. }
  10502. }
  10503. }
  10504. };
  10505. SVGRendererBase.prototype.appendElementInPos = function (element, pos) {
  10506. var newElement = element.getBaseElement();
  10507. if (!newElement) {
  10508. return;
  10509. }
  10510. var i = 0;
  10511. var nextElement;
  10512. while (i < pos) {
  10513. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) {
  10514. nextElement = this.elements[i].getBaseElement();
  10515. }
  10516. i += 1;
  10517. }
  10518. if (nextElement) {
  10519. this.layerElement.insertBefore(newElement, nextElement);
  10520. } else {
  10521. this.layerElement.appendChild(newElement);
  10522. }
  10523. };
  10524. SVGRendererBase.prototype.hide = function () {
  10525. this.layerElement.style.display = 'none';
  10526. };
  10527. SVGRendererBase.prototype.show = function () {
  10528. this.layerElement.style.display = 'block';
  10529. };
  10530. function ICompElement() {}
  10531. extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement);
  10532. ICompElement.prototype.initElement = function (data, globalData, comp) {
  10533. this.initFrame();
  10534. this.initBaseData(data, globalData, comp);
  10535. this.initTransform(data, globalData, comp);
  10536. this.initRenderable();
  10537. this.initHierarchy();
  10538. this.initRendererElement();
  10539. this.createContainerElements();
  10540. this.createRenderableComponents();
  10541. if (this.data.xt || !globalData.progressiveLoad) {
  10542. this.buildAllItems();
  10543. }
  10544. this.hide();
  10545. };
  10546. /* ICompElement.prototype.hide = function(){
  10547. if(!this.hidden){
  10548. this.hideElement();
  10549. var i,len = this.elements.length;
  10550. for( i = 0; i < len; i+=1 ){
  10551. if(this.elements[i]){
  10552. this.elements[i].hide();
  10553. }
  10554. }
  10555. }
  10556. }; */
  10557. ICompElement.prototype.prepareFrame = function (num) {
  10558. this._mdf = false;
  10559. this.prepareRenderableFrame(num);
  10560. this.prepareProperties(num, this.isInRange);
  10561. if (!this.isInRange && !this.data.xt) {
  10562. return;
  10563. }
  10564. if (!this.tm._placeholder) {
  10565. var timeRemapped = this.tm.v;
  10566. if (timeRemapped === this.data.op) {
  10567. timeRemapped = this.data.op - 1;
  10568. }
  10569. this.renderedFrame = timeRemapped;
  10570. } else {
  10571. this.renderedFrame = num / this.data.sr;
  10572. }
  10573. var i;
  10574. var len = this.elements.length;
  10575. if (!this.completeLayers) {
  10576. this.checkLayers(this.renderedFrame);
  10577. }
  10578. // This iteration needs to be backwards because of how expressions connect between each other
  10579. for (i = len - 1; i >= 0; i -= 1) {
  10580. if (this.completeLayers || this.elements[i]) {
  10581. this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st);
  10582. if (this.elements[i]._mdf) {
  10583. this._mdf = true;
  10584. }
  10585. }
  10586. }
  10587. };
  10588. ICompElement.prototype.renderInnerContent = function () {
  10589. var i;
  10590. var len = this.layers.length;
  10591. for (i = 0; i < len; i += 1) {
  10592. if (this.completeLayers || this.elements[i]) {
  10593. this.elements[i].renderFrame();
  10594. }
  10595. }
  10596. };
  10597. ICompElement.prototype.setElements = function (elems) {
  10598. this.elements = elems;
  10599. };
  10600. ICompElement.prototype.getElements = function () {
  10601. return this.elements;
  10602. };
  10603. ICompElement.prototype.destroyElements = function () {
  10604. var i;
  10605. var len = this.layers.length;
  10606. for (i = 0; i < len; i += 1) {
  10607. if (this.elements[i]) {
  10608. this.elements[i].destroy();
  10609. }
  10610. }
  10611. };
  10612. ICompElement.prototype.destroy = function () {
  10613. this.destroyElements();
  10614. this.destroyBaseElement();
  10615. };
  10616. function SVGCompElement(data, globalData, comp) {
  10617. this.layers = data.layers;
  10618. this.supports3d = true;
  10619. this.completeLayers = false;
  10620. this.pendingElements = [];
  10621. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  10622. this.initElement(data, globalData, comp);
  10623. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  10624. }
  10625. extendPrototype([SVGRendererBase, ICompElement, SVGBaseElement], SVGCompElement);
  10626. SVGCompElement.prototype.createComp = function (data) {
  10627. return new SVGCompElement(data, this.globalData, this);
  10628. };
  10629. function SVGRenderer(animationItem, config) {
  10630. this.animationItem = animationItem;
  10631. this.layers = null;
  10632. this.renderedFrame = -1;
  10633. this.svgElement = createNS('svg');
  10634. var ariaLabel = '';
  10635. if (config && config.title) {
  10636. var titleElement = createNS('title');
  10637. var titleId = createElementID();
  10638. titleElement.setAttribute('id', titleId);
  10639. titleElement.textContent = config.title;
  10640. this.svgElement.appendChild(titleElement);
  10641. ariaLabel += titleId;
  10642. }
  10643. if (config && config.description) {
  10644. var descElement = createNS('desc');
  10645. var descId = createElementID();
  10646. descElement.setAttribute('id', descId);
  10647. descElement.textContent = config.description;
  10648. this.svgElement.appendChild(descElement);
  10649. ariaLabel += ' ' + descId;
  10650. }
  10651. if (ariaLabel) {
  10652. this.svgElement.setAttribute('aria-labelledby', ariaLabel);
  10653. }
  10654. var defs = createNS('defs');
  10655. this.svgElement.appendChild(defs);
  10656. var maskElement = createNS('g');
  10657. this.svgElement.appendChild(maskElement);
  10658. this.layerElement = maskElement;
  10659. this.renderConfig = {
  10660. preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet',
  10661. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  10662. contentVisibility: (config && config.contentVisibility) || 'visible',
  10663. progressiveLoad: (config && config.progressiveLoad) || false,
  10664. hideOnTransparent: !((config && config.hideOnTransparent === false)),
  10665. viewBoxOnly: (config && config.viewBoxOnly) || false,
  10666. viewBoxSize: (config && config.viewBoxSize) || false,
  10667. className: (config && config.className) || '',
  10668. id: (config && config.id) || '',
  10669. focusable: config && config.focusable,
  10670. filterSize: {
  10671. width: (config && config.filterSize && config.filterSize.width) || '100%',
  10672. height: (config && config.filterSize && config.filterSize.height) || '100%',
  10673. x: (config && config.filterSize && config.filterSize.x) || '0%',
  10674. y: (config && config.filterSize && config.filterSize.y) || '0%',
  10675. },
  10676. width: (config && config.width),
  10677. height: (config && config.height),
  10678. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  10679. };
  10680. this.globalData = {
  10681. _mdf: false,
  10682. frameNum: -1,
  10683. defs: defs,
  10684. renderConfig: this.renderConfig,
  10685. };
  10686. this.elements = [];
  10687. this.pendingElements = [];
  10688. this.destroyed = false;
  10689. this.rendererType = 'svg';
  10690. }
  10691. extendPrototype([SVGRendererBase], SVGRenderer);
  10692. SVGRenderer.prototype.createComp = function (data) {
  10693. return new SVGCompElement(data, this.globalData, this);
  10694. };
  10695. var registeredEffects = {};
  10696. function CVEffects(elem) {
  10697. var i;
  10698. var len = elem.data.ef ? elem.data.ef.length : 0;
  10699. this.filters = [];
  10700. var filterManager;
  10701. for (i = 0; i < len; i += 1) {
  10702. filterManager = null;
  10703. var type = elem.data.ef[i].ty;
  10704. if (registeredEffects[type]) {
  10705. var Effect = registeredEffects[type].effect;
  10706. filterManager = new Effect(elem.effectsManager.effectElements[i], elem);
  10707. }
  10708. if (filterManager) {
  10709. this.filters.push(filterManager);
  10710. }
  10711. }
  10712. if (this.filters.length) {
  10713. elem.addRenderableComponent(this);
  10714. }
  10715. }
  10716. CVEffects.prototype.renderFrame = function (_isFirstFrame) {
  10717. var i;
  10718. var len = this.filters.length;
  10719. for (i = 0; i < len; i += 1) {
  10720. this.filters[i].renderFrame(_isFirstFrame);
  10721. }
  10722. };
  10723. CVEffects.prototype.getEffects = function (type) {
  10724. var i;
  10725. var len = this.filters.length;
  10726. var effects = [];
  10727. for (i = 0; i < len; i += 1) {
  10728. if (this.filters[i].type === type) {
  10729. effects.push(this.filters[i]);
  10730. }
  10731. }
  10732. return effects;
  10733. };
  10734. function registerEffect(id, effect) {
  10735. registeredEffects[id] = {
  10736. effect,
  10737. };
  10738. }
  10739. function HBaseElement() {}
  10740. HBaseElement.prototype = {
  10741. checkBlendMode: function () {},
  10742. initRendererElement: function () {
  10743. this.baseElement = createTag(this.data.tg || 'div');
  10744. if (this.data.hasMask) {
  10745. this.svgElement = createNS('svg');
  10746. this.layerElement = createNS('g');
  10747. this.maskedElement = this.layerElement;
  10748. this.svgElement.appendChild(this.layerElement);
  10749. this.baseElement.appendChild(this.svgElement);
  10750. } else {
  10751. this.layerElement = this.baseElement;
  10752. }
  10753. styleDiv(this.baseElement);
  10754. },
  10755. createContainerElements: function () {
  10756. this.renderableEffectsManager = new CVEffects(this);
  10757. this.transformedElement = this.baseElement;
  10758. this.maskedElement = this.layerElement;
  10759. if (this.data.ln) {
  10760. this.layerElement.setAttribute('id', this.data.ln);
  10761. }
  10762. if (this.data.cl) {
  10763. this.layerElement.setAttribute('class', this.data.cl);
  10764. }
  10765. if (this.data.bm !== 0) {
  10766. this.setBlendMode();
  10767. }
  10768. },
  10769. renderElement: function () {
  10770. var transformedElementStyle = this.transformedElement ? this.transformedElement.style : {};
  10771. if (this.finalTransform._matMdf) {
  10772. var matrixValue = this.finalTransform.mat.toCSS();
  10773. transformedElementStyle.transform = matrixValue;
  10774. transformedElementStyle.webkitTransform = matrixValue;
  10775. }
  10776. if (this.finalTransform._opMdf) {
  10777. transformedElementStyle.opacity = this.finalTransform.mProp.o.v;
  10778. }
  10779. },
  10780. renderFrame: function () {
  10781. // If it is exported as hidden (data.hd === true) no need to render
  10782. // If it is not visible no need to render
  10783. if (this.data.hd || this.hidden) {
  10784. return;
  10785. }
  10786. this.renderTransform();
  10787. this.renderRenderable();
  10788. this.renderElement();
  10789. this.renderInnerContent();
  10790. if (this._isFirstFrame) {
  10791. this._isFirstFrame = false;
  10792. }
  10793. },
  10794. destroy: function () {
  10795. this.layerElement = null;
  10796. this.transformedElement = null;
  10797. if (this.matteElement) {
  10798. this.matteElement = null;
  10799. }
  10800. if (this.maskManager) {
  10801. this.maskManager.destroy();
  10802. this.maskManager = null;
  10803. }
  10804. },
  10805. createRenderableComponents: function () {
  10806. this.maskManager = new MaskElement(this.data, this, this.globalData);
  10807. },
  10808. addEffects: function () {
  10809. },
  10810. setMatte: function () {},
  10811. };
  10812. HBaseElement.prototype.getBaseElement = SVGBaseElement.prototype.getBaseElement;
  10813. HBaseElement.prototype.destroyBaseElement = HBaseElement.prototype.destroy;
  10814. HBaseElement.prototype.buildElementParenting = BaseRenderer.prototype.buildElementParenting;
  10815. function HSolidElement(data, globalData, comp) {
  10816. this.initElement(data, globalData, comp);
  10817. }
  10818. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], HSolidElement);
  10819. HSolidElement.prototype.createContent = function () {
  10820. var rect;
  10821. if (this.data.hasMask) {
  10822. rect = createNS('rect');
  10823. rect.setAttribute('width', this.data.sw);
  10824. rect.setAttribute('height', this.data.sh);
  10825. rect.setAttribute('fill', this.data.sc);
  10826. this.svgElement.setAttribute('width', this.data.sw);
  10827. this.svgElement.setAttribute('height', this.data.sh);
  10828. } else {
  10829. rect = createTag('div');
  10830. rect.style.width = this.data.sw + 'px';
  10831. rect.style.height = this.data.sh + 'px';
  10832. rect.style.backgroundColor = this.data.sc;
  10833. }
  10834. this.layerElement.appendChild(rect);
  10835. };
  10836. function HShapeElement(data, globalData, comp) {
  10837. // List of drawable elements
  10838. this.shapes = [];
  10839. // Full shape data
  10840. this.shapesData = data.shapes;
  10841. // List of styles that will be applied to shapes
  10842. this.stylesList = [];
  10843. // List of modifiers that will be applied to shapes
  10844. this.shapeModifiers = [];
  10845. // List of items in shape tree
  10846. this.itemsData = [];
  10847. // List of items in previous shape tree
  10848. this.processedElements = [];
  10849. // List of animated components
  10850. this.animatedContents = [];
  10851. this.shapesContainer = createNS('g');
  10852. this.initElement(data, globalData, comp);
  10853. // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties.
  10854. // List of elements that have been created
  10855. this.prevViewData = [];
  10856. this.currentBBox = {
  10857. x: 999999,
  10858. y: -999999,
  10859. h: 0,
  10860. w: 0,
  10861. };
  10862. }
  10863. extendPrototype([BaseElement, TransformElement, HSolidElement, SVGShapeElement, HBaseElement, HierarchyElement, FrameElement, RenderableElement], HShapeElement);
  10864. HShapeElement.prototype._renderShapeFrame = HShapeElement.prototype.renderInnerContent;
  10865. HShapeElement.prototype.createContent = function () {
  10866. var cont;
  10867. this.baseElement.style.fontSize = 0;
  10868. if (this.data.hasMask) {
  10869. this.layerElement.appendChild(this.shapesContainer);
  10870. cont = this.svgElement;
  10871. } else {
  10872. cont = createNS('svg');
  10873. var size = this.comp.data ? this.comp.data : this.globalData.compSize;
  10874. cont.setAttribute('width', size.w);
  10875. cont.setAttribute('height', size.h);
  10876. cont.appendChild(this.shapesContainer);
  10877. this.layerElement.appendChild(cont);
  10878. }
  10879. this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.shapesContainer, 0, [], true);
  10880. this.filterUniqueShapes();
  10881. this.shapeCont = cont;
  10882. };
  10883. HShapeElement.prototype.getTransformedPoint = function (transformers, point) {
  10884. var i;
  10885. var len = transformers.length;
  10886. for (i = 0; i < len; i += 1) {
  10887. point = transformers[i].mProps.v.applyToPointArray(point[0], point[1], 0);
  10888. }
  10889. return point;
  10890. };
  10891. HShapeElement.prototype.calculateShapeBoundingBox = function (item, boundingBox) {
  10892. var shape = item.sh.v;
  10893. var transformers = item.transformers;
  10894. var i;
  10895. var len = shape._length;
  10896. var vPoint;
  10897. var oPoint;
  10898. var nextIPoint;
  10899. var nextVPoint;
  10900. if (len <= 1) {
  10901. return;
  10902. }
  10903. for (i = 0; i < len - 1; i += 1) {
  10904. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  10905. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  10906. nextIPoint = this.getTransformedPoint(transformers, shape.i[i + 1]);
  10907. nextVPoint = this.getTransformedPoint(transformers, shape.v[i + 1]);
  10908. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  10909. }
  10910. if (shape.c) {
  10911. vPoint = this.getTransformedPoint(transformers, shape.v[i]);
  10912. oPoint = this.getTransformedPoint(transformers, shape.o[i]);
  10913. nextIPoint = this.getTransformedPoint(transformers, shape.i[0]);
  10914. nextVPoint = this.getTransformedPoint(transformers, shape.v[0]);
  10915. this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox);
  10916. }
  10917. };
  10918. HShapeElement.prototype.checkBounds = function (vPoint, oPoint, nextIPoint, nextVPoint, boundingBox) {
  10919. this.getBoundsOfCurve(vPoint, oPoint, nextIPoint, nextVPoint);
  10920. var bounds = this.shapeBoundingBox;
  10921. boundingBox.x = bmMin(bounds.left, boundingBox.x);
  10922. boundingBox.xMax = bmMax(bounds.right, boundingBox.xMax);
  10923. boundingBox.y = bmMin(bounds.top, boundingBox.y);
  10924. boundingBox.yMax = bmMax(bounds.bottom, boundingBox.yMax);
  10925. };
  10926. HShapeElement.prototype.shapeBoundingBox = {
  10927. left: 0,
  10928. right: 0,
  10929. top: 0,
  10930. bottom: 0,
  10931. };
  10932. HShapeElement.prototype.tempBoundingBox = {
  10933. x: 0,
  10934. xMax: 0,
  10935. y: 0,
  10936. yMax: 0,
  10937. width: 0,
  10938. height: 0,
  10939. };
  10940. HShapeElement.prototype.getBoundsOfCurve = function (p0, p1, p2, p3) {
  10941. var bounds = [[p0[0], p3[0]], [p0[1], p3[1]]];
  10942. for (var a, b, c, t, b2ac, t1, t2, i = 0; i < 2; ++i) { // eslint-disable-line no-plusplus
  10943. b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
  10944. a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
  10945. c = 3 * p1[i] - 3 * p0[i];
  10946. b |= 0; // eslint-disable-line no-bitwise
  10947. a |= 0; // eslint-disable-line no-bitwise
  10948. c |= 0; // eslint-disable-line no-bitwise
  10949. if (a === 0 && b === 0) {
  10950. //
  10951. } else if (a === 0) {
  10952. t = -c / b;
  10953. if (t > 0 && t < 1) {
  10954. bounds[i].push(this.calculateF(t, p0, p1, p2, p3, i));
  10955. }
  10956. } else {
  10957. b2ac = b * b - 4 * c * a;
  10958. if (b2ac >= 0) {
  10959. t1 = (-b + bmSqrt(b2ac)) / (2 * a);
  10960. if (t1 > 0 && t1 < 1) bounds[i].push(this.calculateF(t1, p0, p1, p2, p3, i));
  10961. t2 = (-b - bmSqrt(b2ac)) / (2 * a);
  10962. if (t2 > 0 && t2 < 1) bounds[i].push(this.calculateF(t2, p0, p1, p2, p3, i));
  10963. }
  10964. }
  10965. }
  10966. this.shapeBoundingBox.left = bmMin.apply(null, bounds[0]);
  10967. this.shapeBoundingBox.top = bmMin.apply(null, bounds[1]);
  10968. this.shapeBoundingBox.right = bmMax.apply(null, bounds[0]);
  10969. this.shapeBoundingBox.bottom = bmMax.apply(null, bounds[1]);
  10970. };
  10971. HShapeElement.prototype.calculateF = function (t, p0, p1, p2, p3, i) {
  10972. return bmPow(1 - t, 3) * p0[i]
  10973. + 3 * bmPow(1 - t, 2) * t * p1[i]
  10974. + 3 * (1 - t) * bmPow(t, 2) * p2[i]
  10975. + bmPow(t, 3) * p3[i];
  10976. };
  10977. HShapeElement.prototype.calculateBoundingBox = function (itemsData, boundingBox) {
  10978. var i;
  10979. var len = itemsData.length;
  10980. for (i = 0; i < len; i += 1) {
  10981. if (itemsData[i] && itemsData[i].sh) {
  10982. this.calculateShapeBoundingBox(itemsData[i], boundingBox);
  10983. } else if (itemsData[i] && itemsData[i].it) {
  10984. this.calculateBoundingBox(itemsData[i].it, boundingBox);
  10985. } else if (itemsData[i] && itemsData[i].style && itemsData[i].w) {
  10986. this.expandStrokeBoundingBox(itemsData[i].w, boundingBox);
  10987. }
  10988. }
  10989. };
  10990. HShapeElement.prototype.expandStrokeBoundingBox = function (widthProperty, boundingBox) {
  10991. var width = 0;
  10992. if (widthProperty.keyframes) {
  10993. for (var i = 0; i < widthProperty.keyframes.length; i += 1) {
  10994. var kfw = widthProperty.keyframes[i].s;
  10995. if (kfw > width) {
  10996. width = kfw;
  10997. }
  10998. }
  10999. width *= widthProperty.mult;
  11000. } else {
  11001. width = widthProperty.v * widthProperty.mult;
  11002. }
  11003. boundingBox.x -= width;
  11004. boundingBox.xMax += width;
  11005. boundingBox.y -= width;
  11006. boundingBox.yMax += width;
  11007. };
  11008. HShapeElement.prototype.currentBoxContains = function (box) {
  11009. return this.currentBBox.x <= box.x
  11010. && this.currentBBox.y <= box.y
  11011. && this.currentBBox.width + this.currentBBox.x >= box.x + box.width
  11012. && this.currentBBox.height + this.currentBBox.y >= box.y + box.height;
  11013. };
  11014. HShapeElement.prototype.renderInnerContent = function () {
  11015. this._renderShapeFrame();
  11016. if (!this.hidden && (this._isFirstFrame || this._mdf)) {
  11017. var tempBoundingBox = this.tempBoundingBox;
  11018. var max = 999999;
  11019. tempBoundingBox.x = max;
  11020. tempBoundingBox.xMax = -max;
  11021. tempBoundingBox.y = max;
  11022. tempBoundingBox.yMax = -max;
  11023. this.calculateBoundingBox(this.itemsData, tempBoundingBox);
  11024. tempBoundingBox.width = tempBoundingBox.xMax < tempBoundingBox.x ? 0 : tempBoundingBox.xMax - tempBoundingBox.x;
  11025. tempBoundingBox.height = tempBoundingBox.yMax < tempBoundingBox.y ? 0 : tempBoundingBox.yMax - tempBoundingBox.y;
  11026. // var tempBoundingBox = this.shapeCont.getBBox();
  11027. if (this.currentBoxContains(tempBoundingBox)) {
  11028. return;
  11029. }
  11030. var changed = false;
  11031. if (this.currentBBox.w !== tempBoundingBox.width) {
  11032. this.currentBBox.w = tempBoundingBox.width;
  11033. this.shapeCont.setAttribute('width', tempBoundingBox.width);
  11034. changed = true;
  11035. }
  11036. if (this.currentBBox.h !== tempBoundingBox.height) {
  11037. this.currentBBox.h = tempBoundingBox.height;
  11038. this.shapeCont.setAttribute('height', tempBoundingBox.height);
  11039. changed = true;
  11040. }
  11041. if (changed || this.currentBBox.x !== tempBoundingBox.x || this.currentBBox.y !== tempBoundingBox.y) {
  11042. this.currentBBox.w = tempBoundingBox.width;
  11043. this.currentBBox.h = tempBoundingBox.height;
  11044. this.currentBBox.x = tempBoundingBox.x;
  11045. this.currentBBox.y = tempBoundingBox.y;
  11046. this.shapeCont.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  11047. var shapeStyle = this.shapeCont.style;
  11048. var shapeTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  11049. shapeStyle.transform = shapeTransform;
  11050. shapeStyle.webkitTransform = shapeTransform;
  11051. }
  11052. }
  11053. };
  11054. function HTextElement(data, globalData, comp) {
  11055. this.textSpans = [];
  11056. this.textPaths = [];
  11057. this.currentBBox = {
  11058. x: 999999,
  11059. y: -999999,
  11060. h: 0,
  11061. w: 0,
  11062. };
  11063. this.renderType = 'svg';
  11064. this.isMasked = false;
  11065. this.initElement(data, globalData, comp);
  11066. }
  11067. extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], HTextElement);
  11068. HTextElement.prototype.createContent = function () {
  11069. this.isMasked = this.checkMasks();
  11070. if (this.isMasked) {
  11071. this.renderType = 'svg';
  11072. this.compW = this.comp.data.w;
  11073. this.compH = this.comp.data.h;
  11074. this.svgElement.setAttribute('width', this.compW);
  11075. this.svgElement.setAttribute('height', this.compH);
  11076. var g = createNS('g');
  11077. this.maskedElement.appendChild(g);
  11078. this.innerElem = g;
  11079. } else {
  11080. this.renderType = 'html';
  11081. this.innerElem = this.layerElement;
  11082. }
  11083. this.checkParenting();
  11084. };
  11085. HTextElement.prototype.buildNewText = function () {
  11086. var documentData = this.textProperty.currentData;
  11087. this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
  11088. var innerElemStyle = this.innerElem.style;
  11089. var textColor = documentData.fc ? this.buildColor(documentData.fc) : 'rgba(0,0,0,0)';
  11090. innerElemStyle.fill = textColor;
  11091. innerElemStyle.color = textColor;
  11092. if (documentData.sc) {
  11093. innerElemStyle.stroke = this.buildColor(documentData.sc);
  11094. innerElemStyle.strokeWidth = documentData.sw + 'px';
  11095. }
  11096. var fontData = this.globalData.fontManager.getFontByName(documentData.f);
  11097. if (!this.globalData.fontManager.chars) {
  11098. innerElemStyle.fontSize = documentData.finalSize + 'px';
  11099. innerElemStyle.lineHeight = documentData.finalSize + 'px';
  11100. if (fontData.fClass) {
  11101. this.innerElem.className = fontData.fClass;
  11102. } else {
  11103. innerElemStyle.fontFamily = fontData.fFamily;
  11104. var fWeight = documentData.fWeight;
  11105. var fStyle = documentData.fStyle;
  11106. innerElemStyle.fontStyle = fStyle;
  11107. innerElemStyle.fontWeight = fWeight;
  11108. }
  11109. }
  11110. var i;
  11111. var len;
  11112. var letters = documentData.l;
  11113. len = letters.length;
  11114. var tSpan;
  11115. var tParent;
  11116. var tCont;
  11117. var matrixHelper = this.mHelper;
  11118. var shapes;
  11119. var shapeStr = '';
  11120. var cnt = 0;
  11121. for (i = 0; i < len; i += 1) {
  11122. if (this.globalData.fontManager.chars) {
  11123. if (!this.textPaths[cnt]) {
  11124. tSpan = createNS('path');
  11125. tSpan.setAttribute('stroke-linecap', lineCapEnum[1]);
  11126. tSpan.setAttribute('stroke-linejoin', lineJoinEnum[2]);
  11127. tSpan.setAttribute('stroke-miterlimit', '4');
  11128. } else {
  11129. tSpan = this.textPaths[cnt];
  11130. }
  11131. if (!this.isMasked) {
  11132. if (this.textSpans[cnt]) {
  11133. tParent = this.textSpans[cnt];
  11134. tCont = tParent.children[0];
  11135. } else {
  11136. tParent = createTag('div');
  11137. tParent.style.lineHeight = 0;
  11138. tCont = createNS('svg');
  11139. tCont.appendChild(tSpan);
  11140. styleDiv(tParent);
  11141. }
  11142. }
  11143. } else if (!this.isMasked) {
  11144. if (this.textSpans[cnt]) {
  11145. tParent = this.textSpans[cnt];
  11146. tSpan = this.textPaths[cnt];
  11147. } else {
  11148. tParent = createTag('span');
  11149. styleDiv(tParent);
  11150. tSpan = createTag('span');
  11151. styleDiv(tSpan);
  11152. tParent.appendChild(tSpan);
  11153. }
  11154. } else {
  11155. tSpan = this.textPaths[cnt] ? this.textPaths[cnt] : createNS('text');
  11156. }
  11157. // tSpan.setAttribute('visibility', 'hidden');
  11158. if (this.globalData.fontManager.chars) {
  11159. var charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily);
  11160. var shapeData;
  11161. if (charData) {
  11162. shapeData = charData.data;
  11163. } else {
  11164. shapeData = null;
  11165. }
  11166. matrixHelper.reset();
  11167. if (shapeData && shapeData.shapes && shapeData.shapes.length) {
  11168. shapes = shapeData.shapes[0].it;
  11169. matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
  11170. shapeStr = this.createPathShape(matrixHelper, shapes);
  11171. tSpan.setAttribute('d', shapeStr);
  11172. }
  11173. if (!this.isMasked) {
  11174. this.innerElem.appendChild(tParent);
  11175. if (shapeData && shapeData.shapes) {
  11176. // document.body.appendChild is needed to get exact measure of shape
  11177. document.body.appendChild(tCont);
  11178. var boundingBox = tCont.getBBox();
  11179. tCont.setAttribute('width', boundingBox.width + 2);
  11180. tCont.setAttribute('height', boundingBox.height + 2);
  11181. tCont.setAttribute('viewBox', (boundingBox.x - 1) + ' ' + (boundingBox.y - 1) + ' ' + (boundingBox.width + 2) + ' ' + (boundingBox.height + 2));
  11182. var tContStyle = tCont.style;
  11183. var tContTranslation = 'translate(' + (boundingBox.x - 1) + 'px,' + (boundingBox.y - 1) + 'px)';
  11184. tContStyle.transform = tContTranslation;
  11185. tContStyle.webkitTransform = tContTranslation;
  11186. letters[i].yOffset = boundingBox.y - 1;
  11187. } else {
  11188. tCont.setAttribute('width', 1);
  11189. tCont.setAttribute('height', 1);
  11190. }
  11191. tParent.appendChild(tCont);
  11192. } else {
  11193. this.innerElem.appendChild(tSpan);
  11194. }
  11195. } else {
  11196. tSpan.textContent = letters[i].val;
  11197. tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  11198. if (!this.isMasked) {
  11199. this.innerElem.appendChild(tParent);
  11200. //
  11201. var tStyle = tSpan.style;
  11202. var tSpanTranslation = 'translate3d(0,' + -documentData.finalSize / 1.2 + 'px,0)';
  11203. tStyle.transform = tSpanTranslation;
  11204. tStyle.webkitTransform = tSpanTranslation;
  11205. } else {
  11206. this.innerElem.appendChild(tSpan);
  11207. }
  11208. }
  11209. //
  11210. if (!this.isMasked) {
  11211. this.textSpans[cnt] = tParent;
  11212. } else {
  11213. this.textSpans[cnt] = tSpan;
  11214. }
  11215. this.textSpans[cnt].style.display = 'block';
  11216. this.textPaths[cnt] = tSpan;
  11217. cnt += 1;
  11218. }
  11219. while (cnt < this.textSpans.length) {
  11220. this.textSpans[cnt].style.display = 'none';
  11221. cnt += 1;
  11222. }
  11223. };
  11224. HTextElement.prototype.renderInnerContent = function () {
  11225. this.validateText();
  11226. var svgStyle;
  11227. if (this.data.singleShape) {
  11228. if (!this._isFirstFrame && !this.lettersChangedFlag) {
  11229. return;
  11230. } if (this.isMasked && this.finalTransform._matMdf) {
  11231. // Todo Benchmark if using this is better than getBBox
  11232. this.svgElement.setAttribute('viewBox', -this.finalTransform.mProp.p.v[0] + ' ' + -this.finalTransform.mProp.p.v[1] + ' ' + this.compW + ' ' + this.compH);
  11233. svgStyle = this.svgElement.style;
  11234. var translation = 'translate(' + -this.finalTransform.mProp.p.v[0] + 'px,' + -this.finalTransform.mProp.p.v[1] + 'px)';
  11235. svgStyle.transform = translation;
  11236. svgStyle.webkitTransform = translation;
  11237. }
  11238. }
  11239. this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag);
  11240. if (!this.lettersChangedFlag && !this.textAnimator.lettersChangedFlag) {
  11241. return;
  11242. }
  11243. var i;
  11244. var len;
  11245. var count = 0;
  11246. var renderedLetters = this.textAnimator.renderedLetters;
  11247. var letters = this.textProperty.currentData.l;
  11248. len = letters.length;
  11249. var renderedLetter;
  11250. var textSpan;
  11251. var textPath;
  11252. for (i = 0; i < len; i += 1) {
  11253. if (letters[i].n) {
  11254. count += 1;
  11255. } else {
  11256. textSpan = this.textSpans[i];
  11257. textPath = this.textPaths[i];
  11258. renderedLetter = renderedLetters[count];
  11259. count += 1;
  11260. if (renderedLetter._mdf.m) {
  11261. if (!this.isMasked) {
  11262. textSpan.style.webkitTransform = renderedLetter.m;
  11263. textSpan.style.transform = renderedLetter.m;
  11264. } else {
  11265. textSpan.setAttribute('transform', renderedLetter.m);
  11266. }
  11267. }
  11268. /// /textSpan.setAttribute('opacity',renderedLetter.o);
  11269. textSpan.style.opacity = renderedLetter.o;
  11270. if (renderedLetter.sw && renderedLetter._mdf.sw) {
  11271. textPath.setAttribute('stroke-width', renderedLetter.sw);
  11272. }
  11273. if (renderedLetter.sc && renderedLetter._mdf.sc) {
  11274. textPath.setAttribute('stroke', renderedLetter.sc);
  11275. }
  11276. if (renderedLetter.fc && renderedLetter._mdf.fc) {
  11277. textPath.setAttribute('fill', renderedLetter.fc);
  11278. textPath.style.color = renderedLetter.fc;
  11279. }
  11280. }
  11281. }
  11282. if (this.innerElem.getBBox && !this.hidden && (this._isFirstFrame || this._mdf)) {
  11283. var boundingBox = this.innerElem.getBBox();
  11284. if (this.currentBBox.w !== boundingBox.width) {
  11285. this.currentBBox.w = boundingBox.width;
  11286. this.svgElement.setAttribute('width', boundingBox.width);
  11287. }
  11288. if (this.currentBBox.h !== boundingBox.height) {
  11289. this.currentBBox.h = boundingBox.height;
  11290. this.svgElement.setAttribute('height', boundingBox.height);
  11291. }
  11292. var margin = 1;
  11293. if (this.currentBBox.w !== (boundingBox.width + margin * 2) || this.currentBBox.h !== (boundingBox.height + margin * 2) || this.currentBBox.x !== (boundingBox.x - margin) || this.currentBBox.y !== (boundingBox.y - margin)) {
  11294. this.currentBBox.w = boundingBox.width + margin * 2;
  11295. this.currentBBox.h = boundingBox.height + margin * 2;
  11296. this.currentBBox.x = boundingBox.x - margin;
  11297. this.currentBBox.y = boundingBox.y - margin;
  11298. this.svgElement.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h);
  11299. svgStyle = this.svgElement.style;
  11300. var svgTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)';
  11301. svgStyle.transform = svgTransform;
  11302. svgStyle.webkitTransform = svgTransform;
  11303. }
  11304. }
  11305. };
  11306. function HCameraElement(data, globalData, comp) {
  11307. this.initFrame();
  11308. this.initBaseData(data, globalData, comp);
  11309. this.initHierarchy();
  11310. var getProp = PropertyFactory.getProp;
  11311. this.pe = getProp(this, data.pe, 0, 0, this);
  11312. if (data.ks.p.s) {
  11313. this.px = getProp(this, data.ks.p.x, 1, 0, this);
  11314. this.py = getProp(this, data.ks.p.y, 1, 0, this);
  11315. this.pz = getProp(this, data.ks.p.z, 1, 0, this);
  11316. } else {
  11317. this.p = getProp(this, data.ks.p, 1, 0, this);
  11318. }
  11319. if (data.ks.a) {
  11320. this.a = getProp(this, data.ks.a, 1, 0, this);
  11321. }
  11322. if (data.ks.or.k.length && data.ks.or.k[0].to) {
  11323. var i;
  11324. var len = data.ks.or.k.length;
  11325. for (i = 0; i < len; i += 1) {
  11326. data.ks.or.k[i].to = null;
  11327. data.ks.or.k[i].ti = null;
  11328. }
  11329. }
  11330. this.or = getProp(this, data.ks.or, 1, degToRads, this);
  11331. this.or.sh = true;
  11332. this.rx = getProp(this, data.ks.rx, 0, degToRads, this);
  11333. this.ry = getProp(this, data.ks.ry, 0, degToRads, this);
  11334. this.rz = getProp(this, data.ks.rz, 0, degToRads, this);
  11335. this.mat = new Matrix();
  11336. this._prevMat = new Matrix();
  11337. this._isFirstFrame = true;
  11338. // TODO: find a better way to make the HCamera element to be compatible with the LayerInterface and TransformInterface.
  11339. this.finalTransform = {
  11340. mProp: this,
  11341. };
  11342. }
  11343. extendPrototype([BaseElement, FrameElement, HierarchyElement], HCameraElement);
  11344. HCameraElement.prototype.setup = function () {
  11345. var i;
  11346. var len = this.comp.threeDElements.length;
  11347. var comp;
  11348. var perspectiveStyle;
  11349. var containerStyle;
  11350. for (i = 0; i < len; i += 1) {
  11351. // [perspectiveElem,container]
  11352. comp = this.comp.threeDElements[i];
  11353. if (comp.type === '3d') {
  11354. perspectiveStyle = comp.perspectiveElem.style;
  11355. containerStyle = comp.container.style;
  11356. var perspective = this.pe.v + 'px';
  11357. var origin = '0px 0px 0px';
  11358. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  11359. perspectiveStyle.perspective = perspective;
  11360. perspectiveStyle.webkitPerspective = perspective;
  11361. containerStyle.transformOrigin = origin;
  11362. containerStyle.mozTransformOrigin = origin;
  11363. containerStyle.webkitTransformOrigin = origin;
  11364. perspectiveStyle.transform = matrix;
  11365. perspectiveStyle.webkitTransform = matrix;
  11366. }
  11367. }
  11368. };
  11369. HCameraElement.prototype.createElements = function () {
  11370. };
  11371. HCameraElement.prototype.hide = function () {
  11372. };
  11373. HCameraElement.prototype.renderFrame = function () {
  11374. var _mdf = this._isFirstFrame;
  11375. var i;
  11376. var len;
  11377. if (this.hierarchy) {
  11378. len = this.hierarchy.length;
  11379. for (i = 0; i < len; i += 1) {
  11380. _mdf = this.hierarchy[i].finalTransform.mProp._mdf || _mdf;
  11381. }
  11382. }
  11383. if (_mdf || this.pe._mdf || (this.p && this.p._mdf) || (this.px && (this.px._mdf || this.py._mdf || this.pz._mdf)) || this.rx._mdf || this.ry._mdf || this.rz._mdf || this.or._mdf || (this.a && this.a._mdf)) {
  11384. this.mat.reset();
  11385. if (this.hierarchy) {
  11386. len = this.hierarchy.length - 1;
  11387. for (i = len; i >= 0; i -= 1) {
  11388. var mTransf = this.hierarchy[i].finalTransform.mProp;
  11389. this.mat.translate(-mTransf.p.v[0], -mTransf.p.v[1], mTransf.p.v[2]);
  11390. this.mat.rotateX(-mTransf.or.v[0]).rotateY(-mTransf.or.v[1]).rotateZ(mTransf.or.v[2]);
  11391. this.mat.rotateX(-mTransf.rx.v).rotateY(-mTransf.ry.v).rotateZ(mTransf.rz.v);
  11392. this.mat.scale(1 / mTransf.s.v[0], 1 / mTransf.s.v[1], 1 / mTransf.s.v[2]);
  11393. this.mat.translate(mTransf.a.v[0], mTransf.a.v[1], mTransf.a.v[2]);
  11394. }
  11395. }
  11396. if (this.p) {
  11397. this.mat.translate(-this.p.v[0], -this.p.v[1], this.p.v[2]);
  11398. } else {
  11399. this.mat.translate(-this.px.v, -this.py.v, this.pz.v);
  11400. }
  11401. if (this.a) {
  11402. var diffVector;
  11403. if (this.p) {
  11404. diffVector = [this.p.v[0] - this.a.v[0], this.p.v[1] - this.a.v[1], this.p.v[2] - this.a.v[2]];
  11405. } else {
  11406. diffVector = [this.px.v - this.a.v[0], this.py.v - this.a.v[1], this.pz.v - this.a.v[2]];
  11407. }
  11408. var mag = Math.sqrt(Math.pow(diffVector[0], 2) + Math.pow(diffVector[1], 2) + Math.pow(diffVector[2], 2));
  11409. // var lookDir = getNormalizedPoint(getDiffVector(this.a.v,this.p.v));
  11410. var lookDir = [diffVector[0] / mag, diffVector[1] / mag, diffVector[2] / mag];
  11411. var lookLengthOnXZ = Math.sqrt(lookDir[2] * lookDir[2] + lookDir[0] * lookDir[0]);
  11412. var mRotationX = (Math.atan2(lookDir[1], lookLengthOnXZ));
  11413. var mRotationY = (Math.atan2(lookDir[0], -lookDir[2]));
  11414. this.mat.rotateY(mRotationY).rotateX(-mRotationX);
  11415. }
  11416. this.mat.rotateX(-this.rx.v).rotateY(-this.ry.v).rotateZ(this.rz.v);
  11417. this.mat.rotateX(-this.or.v[0]).rotateY(-this.or.v[1]).rotateZ(this.or.v[2]);
  11418. this.mat.translate(this.globalData.compSize.w / 2, this.globalData.compSize.h / 2, 0);
  11419. this.mat.translate(0, 0, this.pe.v);
  11420. var hasMatrixChanged = !this._prevMat.equals(this.mat);
  11421. if ((hasMatrixChanged || this.pe._mdf) && this.comp.threeDElements) {
  11422. len = this.comp.threeDElements.length;
  11423. var comp;
  11424. var perspectiveStyle;
  11425. var containerStyle;
  11426. for (i = 0; i < len; i += 1) {
  11427. comp = this.comp.threeDElements[i];
  11428. if (comp.type === '3d') {
  11429. if (hasMatrixChanged) {
  11430. var matValue = this.mat.toCSS();
  11431. containerStyle = comp.container.style;
  11432. containerStyle.transform = matValue;
  11433. containerStyle.webkitTransform = matValue;
  11434. }
  11435. if (this.pe._mdf) {
  11436. perspectiveStyle = comp.perspectiveElem.style;
  11437. perspectiveStyle.perspective = this.pe.v + 'px';
  11438. perspectiveStyle.webkitPerspective = this.pe.v + 'px';
  11439. }
  11440. }
  11441. }
  11442. this.mat.clone(this._prevMat);
  11443. }
  11444. }
  11445. this._isFirstFrame = false;
  11446. };
  11447. HCameraElement.prototype.prepareFrame = function (num) {
  11448. this.prepareProperties(num, true);
  11449. };
  11450. HCameraElement.prototype.destroy = function () {
  11451. };
  11452. HCameraElement.prototype.getBaseElement = function () { return null; };
  11453. function HImageElement(data, globalData, comp) {
  11454. this.assetData = globalData.getAssetData(data.refId);
  11455. this.initElement(data, globalData, comp);
  11456. }
  11457. extendPrototype([BaseElement, TransformElement, HBaseElement, HSolidElement, HierarchyElement, FrameElement, RenderableElement], HImageElement);
  11458. HImageElement.prototype.createContent = function () {
  11459. var assetPath = this.globalData.getAssetsPath(this.assetData);
  11460. var img = new Image();
  11461. if (this.data.hasMask) {
  11462. this.imageElem = createNS('image');
  11463. this.imageElem.setAttribute('width', this.assetData.w + 'px');
  11464. this.imageElem.setAttribute('height', this.assetData.h + 'px');
  11465. this.imageElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  11466. this.layerElement.appendChild(this.imageElem);
  11467. this.baseElement.setAttribute('width', this.assetData.w);
  11468. this.baseElement.setAttribute('height', this.assetData.h);
  11469. } else {
  11470. this.layerElement.appendChild(img);
  11471. }
  11472. img.crossOrigin = 'anonymous';
  11473. img.src = assetPath;
  11474. if (this.data.ln) {
  11475. this.baseElement.setAttribute('id', this.data.ln);
  11476. }
  11477. };
  11478. function HybridRendererBase(animationItem, config) {
  11479. this.animationItem = animationItem;
  11480. this.layers = null;
  11481. this.renderedFrame = -1;
  11482. this.renderConfig = {
  11483. className: (config && config.className) || '',
  11484. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  11485. hideOnTransparent: !(config && config.hideOnTransparent === false),
  11486. filterSize: {
  11487. width: (config && config.filterSize && config.filterSize.width) || '400%',
  11488. height: (config && config.filterSize && config.filterSize.height) || '400%',
  11489. x: (config && config.filterSize && config.filterSize.x) || '-100%',
  11490. y: (config && config.filterSize && config.filterSize.y) || '-100%',
  11491. },
  11492. };
  11493. this.globalData = {
  11494. _mdf: false,
  11495. frameNum: -1,
  11496. renderConfig: this.renderConfig,
  11497. };
  11498. this.pendingElements = [];
  11499. this.elements = [];
  11500. this.threeDElements = [];
  11501. this.destroyed = false;
  11502. this.camera = null;
  11503. this.supports3d = true;
  11504. this.rendererType = 'html';
  11505. }
  11506. extendPrototype([BaseRenderer], HybridRendererBase);
  11507. HybridRendererBase.prototype.buildItem = SVGRenderer.prototype.buildItem;
  11508. HybridRendererBase.prototype.checkPendingElements = function () {
  11509. while (this.pendingElements.length) {
  11510. var element = this.pendingElements.pop();
  11511. element.checkParenting();
  11512. }
  11513. };
  11514. HybridRendererBase.prototype.appendElementInPos = function (element, pos) {
  11515. var newDOMElement = element.getBaseElement();
  11516. if (!newDOMElement) {
  11517. return;
  11518. }
  11519. var layer = this.layers[pos];
  11520. if (!layer.ddd || !this.supports3d) {
  11521. if (this.threeDElements) {
  11522. this.addTo3dContainer(newDOMElement, pos);
  11523. } else {
  11524. var i = 0;
  11525. var nextDOMElement;
  11526. var nextLayer;
  11527. var tmpDOMElement;
  11528. while (i < pos) {
  11529. if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement) {
  11530. nextLayer = this.elements[i];
  11531. tmpDOMElement = this.layers[i].ddd ? this.getThreeDContainerByPos(i) : nextLayer.getBaseElement();
  11532. nextDOMElement = tmpDOMElement || nextDOMElement;
  11533. }
  11534. i += 1;
  11535. }
  11536. if (nextDOMElement) {
  11537. if (!layer.ddd || !this.supports3d) {
  11538. this.layerElement.insertBefore(newDOMElement, nextDOMElement);
  11539. }
  11540. } else if (!layer.ddd || !this.supports3d) {
  11541. this.layerElement.appendChild(newDOMElement);
  11542. }
  11543. }
  11544. } else {
  11545. this.addTo3dContainer(newDOMElement, pos);
  11546. }
  11547. };
  11548. HybridRendererBase.prototype.createShape = function (data) {
  11549. if (!this.supports3d) {
  11550. return new SVGShapeElement(data, this.globalData, this);
  11551. }
  11552. return new HShapeElement(data, this.globalData, this);
  11553. };
  11554. HybridRendererBase.prototype.createText = function (data) {
  11555. if (!this.supports3d) {
  11556. return new SVGTextLottieElement(data, this.globalData, this);
  11557. }
  11558. return new HTextElement(data, this.globalData, this);
  11559. };
  11560. HybridRendererBase.prototype.createCamera = function (data) {
  11561. this.camera = new HCameraElement(data, this.globalData, this);
  11562. return this.camera;
  11563. };
  11564. HybridRendererBase.prototype.createImage = function (data) {
  11565. if (!this.supports3d) {
  11566. return new IImageElement(data, this.globalData, this);
  11567. }
  11568. return new HImageElement(data, this.globalData, this);
  11569. };
  11570. HybridRendererBase.prototype.createSolid = function (data) {
  11571. if (!this.supports3d) {
  11572. return new ISolidElement(data, this.globalData, this);
  11573. }
  11574. return new HSolidElement(data, this.globalData, this);
  11575. };
  11576. HybridRendererBase.prototype.createNull = SVGRenderer.prototype.createNull;
  11577. HybridRendererBase.prototype.getThreeDContainerByPos = function (pos) {
  11578. var i = 0;
  11579. var len = this.threeDElements.length;
  11580. while (i < len) {
  11581. if (this.threeDElements[i].startPos <= pos && this.threeDElements[i].endPos >= pos) {
  11582. return this.threeDElements[i].perspectiveElem;
  11583. }
  11584. i += 1;
  11585. }
  11586. return null;
  11587. };
  11588. HybridRendererBase.prototype.createThreeDContainer = function (pos, type) {
  11589. var perspectiveElem = createTag('div');
  11590. var style;
  11591. var containerStyle;
  11592. styleDiv(perspectiveElem);
  11593. var container = createTag('div');
  11594. styleDiv(container);
  11595. if (type === '3d') {
  11596. style = perspectiveElem.style;
  11597. style.width = this.globalData.compSize.w + 'px';
  11598. style.height = this.globalData.compSize.h + 'px';
  11599. var center = '50% 50%';
  11600. style.webkitTransformOrigin = center;
  11601. style.mozTransformOrigin = center;
  11602. style.transformOrigin = center;
  11603. containerStyle = container.style;
  11604. var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)';
  11605. containerStyle.transform = matrix;
  11606. containerStyle.webkitTransform = matrix;
  11607. }
  11608. perspectiveElem.appendChild(container);
  11609. // this.resizerElem.appendChild(perspectiveElem);
  11610. var threeDContainerData = {
  11611. container: container,
  11612. perspectiveElem: perspectiveElem,
  11613. startPos: pos,
  11614. endPos: pos,
  11615. type: type,
  11616. };
  11617. this.threeDElements.push(threeDContainerData);
  11618. return threeDContainerData;
  11619. };
  11620. HybridRendererBase.prototype.build3dContainers = function () {
  11621. var i;
  11622. var len = this.layers.length;
  11623. var lastThreeDContainerData;
  11624. var currentContainer = '';
  11625. for (i = 0; i < len; i += 1) {
  11626. if (this.layers[i].ddd && this.layers[i].ty !== 3) {
  11627. if (currentContainer !== '3d') {
  11628. currentContainer = '3d';
  11629. lastThreeDContainerData = this.createThreeDContainer(i, '3d');
  11630. }
  11631. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  11632. } else {
  11633. if (currentContainer !== '2d') {
  11634. currentContainer = '2d';
  11635. lastThreeDContainerData = this.createThreeDContainer(i, '2d');
  11636. }
  11637. lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i);
  11638. }
  11639. }
  11640. len = this.threeDElements.length;
  11641. for (i = len - 1; i >= 0; i -= 1) {
  11642. this.resizerElem.appendChild(this.threeDElements[i].perspectiveElem);
  11643. }
  11644. };
  11645. HybridRendererBase.prototype.addTo3dContainer = function (elem, pos) {
  11646. var i = 0;
  11647. var len = this.threeDElements.length;
  11648. while (i < len) {
  11649. if (pos <= this.threeDElements[i].endPos) {
  11650. var j = this.threeDElements[i].startPos;
  11651. var nextElement;
  11652. while (j < pos) {
  11653. if (this.elements[j] && this.elements[j].getBaseElement) {
  11654. nextElement = this.elements[j].getBaseElement();
  11655. }
  11656. j += 1;
  11657. }
  11658. if (nextElement) {
  11659. this.threeDElements[i].container.insertBefore(elem, nextElement);
  11660. } else {
  11661. this.threeDElements[i].container.appendChild(elem);
  11662. }
  11663. break;
  11664. }
  11665. i += 1;
  11666. }
  11667. };
  11668. HybridRendererBase.prototype.configAnimation = function (animData) {
  11669. var resizerElem = createTag('div');
  11670. var wrapper = this.animationItem.wrapper;
  11671. var style = resizerElem.style;
  11672. style.width = animData.w + 'px';
  11673. style.height = animData.h + 'px';
  11674. this.resizerElem = resizerElem;
  11675. styleDiv(resizerElem);
  11676. style.transformStyle = 'flat';
  11677. style.mozTransformStyle = 'flat';
  11678. style.webkitTransformStyle = 'flat';
  11679. if (this.renderConfig.className) {
  11680. resizerElem.setAttribute('class', this.renderConfig.className);
  11681. }
  11682. wrapper.appendChild(resizerElem);
  11683. style.overflow = 'hidden';
  11684. var svg = createNS('svg');
  11685. svg.setAttribute('width', '1');
  11686. svg.setAttribute('height', '1');
  11687. styleDiv(svg);
  11688. this.resizerElem.appendChild(svg);
  11689. var defs = createNS('defs');
  11690. svg.appendChild(defs);
  11691. this.data = animData;
  11692. // Mask animation
  11693. this.setupGlobalData(animData, svg);
  11694. this.globalData.defs = defs;
  11695. this.layers = animData.layers;
  11696. this.layerElement = this.resizerElem;
  11697. this.build3dContainers();
  11698. this.updateContainerSize();
  11699. };
  11700. HybridRendererBase.prototype.destroy = function () {
  11701. if (this.animationItem.wrapper) {
  11702. this.animationItem.wrapper.innerText = '';
  11703. }
  11704. this.animationItem.container = null;
  11705. this.globalData.defs = null;
  11706. var i;
  11707. var len = this.layers ? this.layers.length : 0;
  11708. for (i = 0; i < len; i += 1) {
  11709. if (this.elements[i] && this.elements[i].destroy) {
  11710. this.elements[i].destroy();
  11711. }
  11712. }
  11713. this.elements.length = 0;
  11714. this.destroyed = true;
  11715. this.animationItem = null;
  11716. };
  11717. HybridRendererBase.prototype.updateContainerSize = function () {
  11718. var elementWidth = this.animationItem.wrapper.offsetWidth;
  11719. var elementHeight = this.animationItem.wrapper.offsetHeight;
  11720. var elementRel = elementWidth / elementHeight;
  11721. var animationRel = this.globalData.compSize.w / this.globalData.compSize.h;
  11722. var sx;
  11723. var sy;
  11724. var tx;
  11725. var ty;
  11726. if (animationRel > elementRel) {
  11727. sx = elementWidth / (this.globalData.compSize.w);
  11728. sy = elementWidth / (this.globalData.compSize.w);
  11729. tx = 0;
  11730. ty = ((elementHeight - this.globalData.compSize.h * (elementWidth / this.globalData.compSize.w)) / 2);
  11731. } else {
  11732. sx = elementHeight / (this.globalData.compSize.h);
  11733. sy = elementHeight / (this.globalData.compSize.h);
  11734. tx = (elementWidth - this.globalData.compSize.w * (elementHeight / this.globalData.compSize.h)) / 2;
  11735. ty = 0;
  11736. }
  11737. var style = this.resizerElem.style;
  11738. style.webkitTransform = 'matrix3d(' + sx + ',0,0,0,0,' + sy + ',0,0,0,0,1,0,' + tx + ',' + ty + ',0,1)';
  11739. style.transform = style.webkitTransform;
  11740. };
  11741. HybridRendererBase.prototype.renderFrame = SVGRenderer.prototype.renderFrame;
  11742. HybridRendererBase.prototype.hide = function () {
  11743. this.resizerElem.style.display = 'none';
  11744. };
  11745. HybridRendererBase.prototype.show = function () {
  11746. this.resizerElem.style.display = 'block';
  11747. };
  11748. HybridRendererBase.prototype.initItems = function () {
  11749. this.buildAllItems();
  11750. if (this.camera) {
  11751. this.camera.setup();
  11752. } else {
  11753. var cWidth = this.globalData.compSize.w;
  11754. var cHeight = this.globalData.compSize.h;
  11755. var i;
  11756. var len = this.threeDElements.length;
  11757. for (i = 0; i < len; i += 1) {
  11758. var style = this.threeDElements[i].perspectiveElem.style;
  11759. style.webkitPerspective = Math.sqrt(Math.pow(cWidth, 2) + Math.pow(cHeight, 2)) + 'px';
  11760. style.perspective = style.webkitPerspective;
  11761. }
  11762. }
  11763. };
  11764. HybridRendererBase.prototype.searchExtraCompositions = function (assets) {
  11765. var i;
  11766. var len = assets.length;
  11767. var floatingContainer = createTag('div');
  11768. for (i = 0; i < len; i += 1) {
  11769. if (assets[i].xt) {
  11770. var comp = this.createComp(assets[i], floatingContainer, this.globalData.comp, null);
  11771. comp.initExpressions();
  11772. this.globalData.projectInterface.registerComposition(comp);
  11773. }
  11774. }
  11775. };
  11776. function HCompElement(data, globalData, comp) {
  11777. this.layers = data.layers;
  11778. this.supports3d = !data.hasMask;
  11779. this.completeLayers = false;
  11780. this.pendingElements = [];
  11781. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  11782. this.initElement(data, globalData, comp);
  11783. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  11784. }
  11785. extendPrototype([HybridRendererBase, ICompElement, HBaseElement], HCompElement);
  11786. HCompElement.prototype._createBaseContainerElements = HCompElement.prototype.createContainerElements;
  11787. HCompElement.prototype.createContainerElements = function () {
  11788. this._createBaseContainerElements();
  11789. // divElement.style.clip = 'rect(0px, '+this.data.w+'px, '+this.data.h+'px, 0px)';
  11790. if (this.data.hasMask) {
  11791. this.svgElement.setAttribute('width', this.data.w);
  11792. this.svgElement.setAttribute('height', this.data.h);
  11793. this.transformedElement = this.baseElement;
  11794. } else {
  11795. this.transformedElement = this.layerElement;
  11796. }
  11797. };
  11798. HCompElement.prototype.addTo3dContainer = function (elem, pos) {
  11799. var j = 0;
  11800. var nextElement;
  11801. while (j < pos) {
  11802. if (this.elements[j] && this.elements[j].getBaseElement) {
  11803. nextElement = this.elements[j].getBaseElement();
  11804. }
  11805. j += 1;
  11806. }
  11807. if (nextElement) {
  11808. this.layerElement.insertBefore(elem, nextElement);
  11809. } else {
  11810. this.layerElement.appendChild(elem);
  11811. }
  11812. };
  11813. HCompElement.prototype.createComp = function (data) {
  11814. if (!this.supports3d) {
  11815. return new SVGCompElement(data, this.globalData, this);
  11816. }
  11817. return new HCompElement(data, this.globalData, this);
  11818. };
  11819. function HybridRenderer(animationItem, config) {
  11820. this.animationItem = animationItem;
  11821. this.layers = null;
  11822. this.renderedFrame = -1;
  11823. this.renderConfig = {
  11824. className: (config && config.className) || '',
  11825. imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice',
  11826. hideOnTransparent: !(config && config.hideOnTransparent === false),
  11827. filterSize: {
  11828. width: (config && config.filterSize && config.filterSize.width) || '400%',
  11829. height: (config && config.filterSize && config.filterSize.height) || '400%',
  11830. x: (config && config.filterSize && config.filterSize.x) || '-100%',
  11831. y: (config && config.filterSize && config.filterSize.y) || '-100%',
  11832. },
  11833. runExpressions: !config || config.runExpressions === undefined || config.runExpressions,
  11834. };
  11835. this.globalData = {
  11836. _mdf: false,
  11837. frameNum: -1,
  11838. renderConfig: this.renderConfig,
  11839. };
  11840. this.pendingElements = [];
  11841. this.elements = [];
  11842. this.threeDElements = [];
  11843. this.destroyed = false;
  11844. this.camera = null;
  11845. this.supports3d = true;
  11846. this.rendererType = 'html';
  11847. }
  11848. extendPrototype([HybridRendererBase], HybridRenderer);
  11849. HybridRenderer.prototype.createComp = function (data) {
  11850. if (!this.supports3d) {
  11851. return new SVGCompElement(data, this.globalData, this);
  11852. }
  11853. return new HCompElement(data, this.globalData, this);
  11854. };
  11855. // Registering renderers
  11856. registerRenderer('html', HybridRenderer);
  11857. // Registering shape modifiers
  11858. ShapeModifiers.registerModifier('tm', TrimModifier);
  11859. ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier);
  11860. ShapeModifiers.registerModifier('rp', RepeaterModifier);
  11861. ShapeModifiers.registerModifier('rd', RoundCornersModifier);
  11862. ShapeModifiers.registerModifier('zz', ZigZagModifier);
  11863. ShapeModifiers.registerModifier('op', OffsetPathModifier);
  11864. const CompExpressionInterface = (function () {
  11865. return function (comp) {
  11866. function _thisLayerFunction(name) {
  11867. var i = 0;
  11868. var len = comp.layers.length;
  11869. while (i < len) {
  11870. if (comp.layers[i].nm === name || comp.layers[i].ind === name) {
  11871. return comp.elements[i].layerInterface;
  11872. }
  11873. i += 1;
  11874. }
  11875. return null;
  11876. // return {active:false};
  11877. }
  11878. Object.defineProperty(_thisLayerFunction, '_name', { value: comp.data.nm });
  11879. _thisLayerFunction.layer = _thisLayerFunction;
  11880. _thisLayerFunction.pixelAspect = 1;
  11881. _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h;
  11882. _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w;
  11883. _thisLayerFunction.pixelAspect = 1;
  11884. _thisLayerFunction.frameDuration = 1 / comp.globalData.frameRate;
  11885. _thisLayerFunction.displayStartTime = 0;
  11886. _thisLayerFunction.numLayers = comp.layers.length;
  11887. return _thisLayerFunction;
  11888. };
  11889. }());
  11890. /* eslint-disable */
  11891. /*
  11892. Copyright 2014 David Bau.
  11893. Permission is hereby granted, free of charge, to any person obtaining
  11894. a copy of this software and associated documentation files (the
  11895. "Software"), to deal in the Software without restriction, including
  11896. without limitation the rights to use, copy, modify, merge, publish,
  11897. distribute, sublicense, and/or sell copies of the Software, and to
  11898. permit persons to whom the Software is furnished to do so, subject to
  11899. the following conditions:
  11900. The above copyright notice and this permission notice shall be
  11901. included in all copies or substantial portions of the Software.
  11902. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  11903. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11904. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  11905. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  11906. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  11907. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  11908. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  11909. */
  11910. function seedRandom(pool, math) {
  11911. //
  11912. // The following constants are related to IEEE 754 limits.
  11913. //
  11914. var global = this,
  11915. width = 256, // each RC4 output is 0 <= x < 256
  11916. chunks = 6, // at least six RC4 outputs for each double
  11917. digits = 52, // there are 52 significant digits in a double
  11918. rngname = 'random', // rngname: name for Math.random and Math.seedrandom
  11919. startdenom = math.pow(width, chunks),
  11920. significance = math.pow(2, digits),
  11921. overflow = significance * 2,
  11922. mask = width - 1,
  11923. nodecrypto; // node.js crypto module, initialized at the bottom.
  11924. //
  11925. // seedrandom()
  11926. // This is the seedrandom function described above.
  11927. //
  11928. function seedrandom(seed, options, callback) {
  11929. var key = [];
  11930. options = (options === true) ? { entropy: true } : (options || {});
  11931. // Flatten the seed string or build one from local entropy if needed.
  11932. var shortseed = mixkey(flatten(
  11933. options.entropy ? [seed, tostring(pool)] :
  11934. (seed === null) ? autoseed() : seed, 3), key);
  11935. // Use the seed to initialize an ARC4 generator.
  11936. var arc4 = new ARC4(key);
  11937. // This function returns a random double in [0, 1) that contains
  11938. // randomness in every bit of the mantissa of the IEEE 754 value.
  11939. var prng = function() {
  11940. var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
  11941. d = startdenom, // and denominator d = 2 ^ 48.
  11942. x = 0; // and no 'extra last byte'.
  11943. while (n < significance) { // Fill up all significant digits by
  11944. n = (n + x) * width; // shifting numerator and
  11945. d *= width; // denominator and generating a
  11946. x = arc4.g(1); // new least-significant-byte.
  11947. }
  11948. while (n >= overflow) { // To avoid rounding up, before adding
  11949. n /= 2; // last byte, shift everything
  11950. d /= 2; // right using integer math until
  11951. x >>>= 1; // we have exactly the desired bits.
  11952. }
  11953. return (n + x) / d; // Form the number within [0, 1).
  11954. };
  11955. prng.int32 = function() { return arc4.g(4) | 0; };
  11956. prng.quick = function() { return arc4.g(4) / 0x100000000; };
  11957. prng.double = prng;
  11958. // Mix the randomness into accumulated entropy.
  11959. mixkey(tostring(arc4.S), pool);
  11960. // Calling convention: what to return as a function of prng, seed, is_math.
  11961. return (options.pass || callback ||
  11962. function(prng, seed, is_math_call, state) {
  11963. if (state) {
  11964. // Load the arc4 state from the given state if it has an S array.
  11965. if (state.S) { copy(state, arc4); }
  11966. // Only provide the .state method if requested via options.state.
  11967. prng.state = function() { return copy(arc4, {}); };
  11968. }
  11969. // If called as a method of Math (Math.seedrandom()), mutate
  11970. // Math.random because that is how seedrandom.js has worked since v1.0.
  11971. if (is_math_call) { math[rngname] = prng; return seed; }
  11972. // Otherwise, it is a newer calling convention, so return the
  11973. // prng directly.
  11974. else return prng;
  11975. })(
  11976. prng,
  11977. shortseed,
  11978. 'global' in options ? options.global : (this == math),
  11979. options.state);
  11980. }
  11981. math['seed' + rngname] = seedrandom;
  11982. //
  11983. // ARC4
  11984. //
  11985. // An ARC4 implementation. The constructor takes a key in the form of
  11986. // an array of at most (width) integers that should be 0 <= x < (width).
  11987. //
  11988. // The g(count) method returns a pseudorandom integer that concatenates
  11989. // the next (count) outputs from ARC4. Its return value is a number x
  11990. // that is in the range 0 <= x < (width ^ count).
  11991. //
  11992. function ARC4(key) {
  11993. var t, keylen = key.length,
  11994. me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
  11995. // The empty key [] is treated as [0].
  11996. if (!keylen) { key = [keylen++]; }
  11997. // Set up S using the standard key scheduling algorithm.
  11998. while (i < width) {
  11999. s[i] = i++;
  12000. }
  12001. for (i = 0; i < width; i++) {
  12002. s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
  12003. s[j] = t;
  12004. }
  12005. // The "g" method returns the next (count) outputs as one number.
  12006. me.g = function(count) {
  12007. // Using instance members instead of closure state nearly doubles speed.
  12008. var t, r = 0,
  12009. i = me.i, j = me.j, s = me.S;
  12010. while (count--) {
  12011. t = s[i = mask & (i + 1)];
  12012. r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
  12013. }
  12014. me.i = i; me.j = j;
  12015. return r;
  12016. // For robust unpredictability, the function call below automatically
  12017. // discards an initial batch of values. This is called RC4-drop[256].
  12018. // See http://google.com/search?q=rsa+fluhrer+response&btnI
  12019. };
  12020. }
  12021. //
  12022. // copy()
  12023. // Copies internal state of ARC4 to or from a plain object.
  12024. //
  12025. function copy(f, t) {
  12026. t.i = f.i;
  12027. t.j = f.j;
  12028. t.S = f.S.slice();
  12029. return t;
  12030. }
  12031. //
  12032. // flatten()
  12033. // Converts an object tree to nested arrays of strings.
  12034. //
  12035. function flatten(obj, depth) {
  12036. var result = [], typ = (typeof obj), prop;
  12037. if (depth && typ == 'object') {
  12038. for (prop in obj) {
  12039. try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
  12040. }
  12041. }
  12042. return (result.length ? result : typ == 'string' ? obj : obj + '\0');
  12043. }
  12044. //
  12045. // mixkey()
  12046. // Mixes a string seed into a key that is an array of integers, and
  12047. // returns a shortened string seed that is equivalent to the result key.
  12048. //
  12049. function mixkey(seed, key) {
  12050. var stringseed = seed + '', smear, j = 0;
  12051. while (j < stringseed.length) {
  12052. key[mask & j] =
  12053. mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
  12054. }
  12055. return tostring(key);
  12056. }
  12057. //
  12058. // autoseed()
  12059. // Returns an object for autoseeding, using window.crypto and Node crypto
  12060. // module if available.
  12061. //
  12062. function autoseed() {
  12063. try {
  12064. if (nodecrypto) { return tostring(nodecrypto.randomBytes(width)); }
  12065. var out = new Uint8Array(width);
  12066. (global.crypto || global.msCrypto).getRandomValues(out);
  12067. return tostring(out);
  12068. } catch (e) {
  12069. var browser = global.navigator,
  12070. plugins = browser && browser.plugins;
  12071. return [+new Date(), global, plugins, global.screen, tostring(pool)];
  12072. }
  12073. }
  12074. //
  12075. // tostring()
  12076. // Converts an array of charcodes to a string
  12077. //
  12078. function tostring(a) {
  12079. return String.fromCharCode.apply(0, a);
  12080. }
  12081. //
  12082. // When seedrandom.js is loaded, we immediately mix a few bits
  12083. // from the built-in RNG into the entropy pool. Because we do
  12084. // not want to interfere with deterministic PRNG state later,
  12085. // seedrandom will not call math.random on its own again after
  12086. // initialization.
  12087. //
  12088. mixkey(math.random(), pool);
  12089. //
  12090. // Nodejs and AMD support: export the implementation as a module using
  12091. // either convention.
  12092. //
  12093. // End anonymous scope, and pass initial values.
  12094. };
  12095. function initialize$2(BMMath) {
  12096. seedRandom([], BMMath);
  12097. }
  12098. var propTypes = {
  12099. SHAPE: 'shape',
  12100. };
  12101. /* eslint-disable camelcase */
  12102. const ExpressionManager = (function () {
  12103. 'use strict';
  12104. var ob = {};
  12105. var Math = BMMath;
  12106. var window = null;
  12107. var document = null;
  12108. var XMLHttpRequest = null;
  12109. var fetch = null;
  12110. var frames = null;
  12111. var _lottieGlobal = {};
  12112. initialize$2(BMMath);
  12113. function resetFrame() {
  12114. _lottieGlobal = {};
  12115. }
  12116. function $bm_isInstanceOfArray(arr) {
  12117. return arr.constructor === Array || arr.constructor === Float32Array;
  12118. }
  12119. function isNumerable(tOfV, v) {
  12120. return tOfV === 'number' || v instanceof Number || tOfV === 'boolean' || tOfV === 'string';
  12121. }
  12122. function $bm_neg(a) {
  12123. var tOfA = typeof a;
  12124. if (tOfA === 'number' || a instanceof Number || tOfA === 'boolean') {
  12125. return -a;
  12126. }
  12127. if ($bm_isInstanceOfArray(a)) {
  12128. var i;
  12129. var lenA = a.length;
  12130. var retArr = [];
  12131. for (i = 0; i < lenA; i += 1) {
  12132. retArr[i] = -a[i];
  12133. }
  12134. return retArr;
  12135. }
  12136. if (a.propType) {
  12137. return a.v;
  12138. }
  12139. return -a;
  12140. }
  12141. var easeInBez = BezierFactory.getBezierEasing(0.333, 0, 0.833, 0.833, 'easeIn').get;
  12142. var easeOutBez = BezierFactory.getBezierEasing(0.167, 0.167, 0.667, 1, 'easeOut').get;
  12143. var easeInOutBez = BezierFactory.getBezierEasing(0.33, 0, 0.667, 1, 'easeInOut').get;
  12144. function sum(a, b) {
  12145. var tOfA = typeof a;
  12146. var tOfB = typeof b;
  12147. if ((isNumerable(tOfA, a) && isNumerable(tOfB, b)) || tOfA === 'string' || tOfB === 'string') {
  12148. return a + b;
  12149. }
  12150. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12151. a = a.slice(0);
  12152. a[0] += b;
  12153. return a;
  12154. }
  12155. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12156. b = b.slice(0);
  12157. b[0] = a + b[0];
  12158. return b;
  12159. }
  12160. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  12161. var i = 0;
  12162. var lenA = a.length;
  12163. var lenB = b.length;
  12164. var retArr = [];
  12165. while (i < lenA || i < lenB) {
  12166. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  12167. retArr[i] = a[i] + b[i];
  12168. } else {
  12169. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  12170. }
  12171. i += 1;
  12172. }
  12173. return retArr;
  12174. }
  12175. return 0;
  12176. }
  12177. var add = sum;
  12178. function sub(a, b) {
  12179. var tOfA = typeof a;
  12180. var tOfB = typeof b;
  12181. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12182. if (tOfA === 'string') {
  12183. a = parseInt(a, 10);
  12184. }
  12185. if (tOfB === 'string') {
  12186. b = parseInt(b, 10);
  12187. }
  12188. return a - b;
  12189. }
  12190. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12191. a = a.slice(0);
  12192. a[0] -= b;
  12193. return a;
  12194. }
  12195. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12196. b = b.slice(0);
  12197. b[0] = a - b[0];
  12198. return b;
  12199. }
  12200. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  12201. var i = 0;
  12202. var lenA = a.length;
  12203. var lenB = b.length;
  12204. var retArr = [];
  12205. while (i < lenA || i < lenB) {
  12206. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  12207. retArr[i] = a[i] - b[i];
  12208. } else {
  12209. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  12210. }
  12211. i += 1;
  12212. }
  12213. return retArr;
  12214. }
  12215. return 0;
  12216. }
  12217. function mul(a, b) {
  12218. var tOfA = typeof a;
  12219. var tOfB = typeof b;
  12220. var arr;
  12221. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12222. return a * b;
  12223. }
  12224. var i;
  12225. var len;
  12226. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12227. len = a.length;
  12228. arr = createTypedArray('float32', len);
  12229. for (i = 0; i < len; i += 1) {
  12230. arr[i] = a[i] * b;
  12231. }
  12232. return arr;
  12233. }
  12234. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12235. len = b.length;
  12236. arr = createTypedArray('float32', len);
  12237. for (i = 0; i < len; i += 1) {
  12238. arr[i] = a * b[i];
  12239. }
  12240. return arr;
  12241. }
  12242. return 0;
  12243. }
  12244. function div(a, b) {
  12245. var tOfA = typeof a;
  12246. var tOfB = typeof b;
  12247. var arr;
  12248. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  12249. return a / b;
  12250. }
  12251. var i;
  12252. var len;
  12253. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  12254. len = a.length;
  12255. arr = createTypedArray('float32', len);
  12256. for (i = 0; i < len; i += 1) {
  12257. arr[i] = a[i] / b;
  12258. }
  12259. return arr;
  12260. }
  12261. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  12262. len = b.length;
  12263. arr = createTypedArray('float32', len);
  12264. for (i = 0; i < len; i += 1) {
  12265. arr[i] = a / b[i];
  12266. }
  12267. return arr;
  12268. }
  12269. return 0;
  12270. }
  12271. function mod(a, b) {
  12272. if (typeof a === 'string') {
  12273. a = parseInt(a, 10);
  12274. }
  12275. if (typeof b === 'string') {
  12276. b = parseInt(b, 10);
  12277. }
  12278. return a % b;
  12279. }
  12280. var $bm_sum = sum;
  12281. var $bm_sub = sub;
  12282. var $bm_mul = mul;
  12283. var $bm_div = div;
  12284. var $bm_mod = mod;
  12285. function clamp(num, min, max) {
  12286. if (min > max) {
  12287. var mm = max;
  12288. max = min;
  12289. min = mm;
  12290. }
  12291. return Math.min(Math.max(num, min), max);
  12292. }
  12293. function radiansToDegrees(val) {
  12294. return val / degToRads;
  12295. }
  12296. var radians_to_degrees = radiansToDegrees;
  12297. function degreesToRadians(val) {
  12298. return val * degToRads;
  12299. }
  12300. var degrees_to_radians = radiansToDegrees;
  12301. var helperLengthArray = [0, 0, 0, 0, 0, 0];
  12302. function length(arr1, arr2) {
  12303. if (typeof arr1 === 'number' || arr1 instanceof Number) {
  12304. arr2 = arr2 || 0;
  12305. return Math.abs(arr1 - arr2);
  12306. }
  12307. if (!arr2) {
  12308. arr2 = helperLengthArray;
  12309. }
  12310. var i;
  12311. var len = Math.min(arr1.length, arr2.length);
  12312. var addedLength = 0;
  12313. for (i = 0; i < len; i += 1) {
  12314. addedLength += Math.pow(arr2[i] - arr1[i], 2);
  12315. }
  12316. return Math.sqrt(addedLength);
  12317. }
  12318. function normalize(vec) {
  12319. return div(vec, length(vec));
  12320. }
  12321. function rgbToHsl(val) {
  12322. var r = val[0]; var g = val[1]; var b = val[2];
  12323. var max = Math.max(r, g, b);
  12324. var min = Math.min(r, g, b);
  12325. var h;
  12326. var s;
  12327. var l = (max + min) / 2;
  12328. if (max === min) {
  12329. h = 0; // achromatic
  12330. s = 0; // achromatic
  12331. } else {
  12332. var d = max - min;
  12333. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  12334. switch (max) {
  12335. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  12336. case g: h = (b - r) / d + 2; break;
  12337. case b: h = (r - g) / d + 4; break;
  12338. default: break;
  12339. }
  12340. h /= 6;
  12341. }
  12342. return [h, s, l, val[3]];
  12343. }
  12344. function hue2rgb(p, q, t) {
  12345. if (t < 0) t += 1;
  12346. if (t > 1) t -= 1;
  12347. if (t < 1 / 6) return p + (q - p) * 6 * t;
  12348. if (t < 1 / 2) return q;
  12349. if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
  12350. return p;
  12351. }
  12352. function hslToRgb(val) {
  12353. var h = val[0];
  12354. var s = val[1];
  12355. var l = val[2];
  12356. var r;
  12357. var g;
  12358. var b;
  12359. if (s === 0) {
  12360. r = l; // achromatic
  12361. b = l; // achromatic
  12362. g = l; // achromatic
  12363. } else {
  12364. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  12365. var p = 2 * l - q;
  12366. r = hue2rgb(p, q, h + 1 / 3);
  12367. g = hue2rgb(p, q, h);
  12368. b = hue2rgb(p, q, h - 1 / 3);
  12369. }
  12370. return [r, g, b, val[3]];
  12371. }
  12372. function linear(t, tMin, tMax, value1, value2) {
  12373. if (value1 === undefined || value2 === undefined) {
  12374. value1 = tMin;
  12375. value2 = tMax;
  12376. tMin = 0;
  12377. tMax = 1;
  12378. }
  12379. if (tMax < tMin) {
  12380. var _tMin = tMax;
  12381. tMax = tMin;
  12382. tMin = _tMin;
  12383. }
  12384. if (t <= tMin) {
  12385. return value1;
  12386. } if (t >= tMax) {
  12387. return value2;
  12388. }
  12389. var perc = tMax === tMin ? 0 : (t - tMin) / (tMax - tMin);
  12390. if (!value1.length) {
  12391. return value1 + (value2 - value1) * perc;
  12392. }
  12393. var i;
  12394. var len = value1.length;
  12395. var arr = createTypedArray('float32', len);
  12396. for (i = 0; i < len; i += 1) {
  12397. arr[i] = value1[i] + (value2[i] - value1[i]) * perc;
  12398. }
  12399. return arr;
  12400. }
  12401. function random(min, max) {
  12402. if (max === undefined) {
  12403. if (min === undefined) {
  12404. min = 0;
  12405. max = 1;
  12406. } else {
  12407. max = min;
  12408. min = undefined;
  12409. }
  12410. }
  12411. if (max.length) {
  12412. var i;
  12413. var len = max.length;
  12414. if (!min) {
  12415. min = createTypedArray('float32', len);
  12416. }
  12417. var arr = createTypedArray('float32', len);
  12418. var rnd = BMMath.random();
  12419. for (i = 0; i < len; i += 1) {
  12420. arr[i] = min[i] + rnd * (max[i] - min[i]);
  12421. }
  12422. return arr;
  12423. }
  12424. if (min === undefined) {
  12425. min = 0;
  12426. }
  12427. var rndm = BMMath.random();
  12428. return min + rndm * (max - min);
  12429. }
  12430. function createPath(points, inTangents, outTangents, closed) {
  12431. var i;
  12432. var len = points.length;
  12433. var path = shapePool.newElement();
  12434. path.setPathData(!!closed, len);
  12435. var arrPlaceholder = [0, 0];
  12436. var inVertexPoint;
  12437. var outVertexPoint;
  12438. for (i = 0; i < len; i += 1) {
  12439. inVertexPoint = (inTangents && inTangents[i]) ? inTangents[i] : arrPlaceholder;
  12440. outVertexPoint = (outTangents && outTangents[i]) ? outTangents[i] : arrPlaceholder;
  12441. path.setTripleAt(points[i][0], points[i][1], outVertexPoint[0] + points[i][0], outVertexPoint[1] + points[i][1], inVertexPoint[0] + points[i][0], inVertexPoint[1] + points[i][1], i, true);
  12442. }
  12443. return path;
  12444. }
  12445. function initiateExpression(elem, data, property) {
  12446. // Bail out if we don't want expressions
  12447. function noOp(_value) {
  12448. return _value;
  12449. }
  12450. if (!elem.globalData.renderConfig.runExpressions) {
  12451. return noOp;
  12452. }
  12453. var val = data.x;
  12454. var needsVelocity = /velocity(?![\w\d])/.test(val);
  12455. var _needsRandom = val.indexOf('random') !== -1;
  12456. var elemType = elem.data.ty;
  12457. var transform;
  12458. var $bm_transform;
  12459. var content;
  12460. var effect;
  12461. var thisProperty = property;
  12462. thisProperty._name = elem.data.nm;
  12463. thisProperty.valueAtTime = thisProperty.getValueAtTime;
  12464. Object.defineProperty(thisProperty, 'value', {
  12465. get: function () {
  12466. return thisProperty.v;
  12467. },
  12468. });
  12469. elem.comp.frameDuration = 1 / elem.comp.globalData.frameRate;
  12470. elem.comp.displayStartTime = 0;
  12471. var inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  12472. var outPoint = elem.data.op / elem.comp.globalData.frameRate;
  12473. var width = elem.data.sw ? elem.data.sw : 0;
  12474. var height = elem.data.sh ? elem.data.sh : 0;
  12475. var name = elem.data.nm;
  12476. var loopIn;
  12477. var loop_in;
  12478. var loopOut;
  12479. var loop_out;
  12480. var smooth;
  12481. var toWorld;
  12482. var fromWorld;
  12483. var fromComp;
  12484. var toComp;
  12485. var fromCompToSurface;
  12486. var position;
  12487. var rotation;
  12488. var anchorPoint;
  12489. var scale;
  12490. var thisLayer;
  12491. var thisComp;
  12492. var mask;
  12493. var valueAtTime;
  12494. var velocityAtTime;
  12495. var scoped_bm_rt;
  12496. // val = val.replace(/(\\?"|')((http)(s)?(:\/))?\/.*?(\\?"|')/g, "\"\""); // deter potential network calls
  12497. var expression_function = eval('[function _expression_function(){' + val + ';scoped_bm_rt=$bm_rt}]')[0]; // eslint-disable-line no-eval
  12498. var numKeys = property.kf ? data.k.length : 0;
  12499. var active = !this.data || this.data.hd !== true;
  12500. var wiggle = function wiggle(freq, amp) {
  12501. var iWiggle;
  12502. var j;
  12503. var lenWiggle = this.pv.length ? this.pv.length : 1;
  12504. var addedAmps = createTypedArray('float32', lenWiggle);
  12505. freq = 5;
  12506. var iterations = Math.floor(time * freq);
  12507. iWiggle = 0;
  12508. j = 0;
  12509. while (iWiggle < iterations) {
  12510. // var rnd = BMMath.random();
  12511. for (j = 0; j < lenWiggle; j += 1) {
  12512. addedAmps[j] += -amp + amp * 2 * BMMath.random();
  12513. // addedAmps[j] += -amp + amp*2*rnd;
  12514. }
  12515. iWiggle += 1;
  12516. }
  12517. // var rnd2 = BMMath.random();
  12518. var periods = time * freq;
  12519. var perc = periods - Math.floor(periods);
  12520. var arr = createTypedArray('float32', lenWiggle);
  12521. if (lenWiggle > 1) {
  12522. for (j = 0; j < lenWiggle; j += 1) {
  12523. arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc;
  12524. // arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc;
  12525. // arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc);
  12526. }
  12527. return arr;
  12528. }
  12529. return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc;
  12530. }.bind(this);
  12531. if (thisProperty.loopIn) {
  12532. loopIn = thisProperty.loopIn.bind(thisProperty);
  12533. loop_in = loopIn;
  12534. }
  12535. if (thisProperty.loopOut) {
  12536. loopOut = thisProperty.loopOut.bind(thisProperty);
  12537. loop_out = loopOut;
  12538. }
  12539. if (thisProperty.smooth) {
  12540. smooth = thisProperty.smooth.bind(thisProperty);
  12541. }
  12542. function loopInDuration(type, duration) {
  12543. return loopIn(type, duration, true);
  12544. }
  12545. function loopOutDuration(type, duration) {
  12546. return loopOut(type, duration, true);
  12547. }
  12548. if (this.getValueAtTime) {
  12549. valueAtTime = this.getValueAtTime.bind(this);
  12550. }
  12551. if (this.getVelocityAtTime) {
  12552. velocityAtTime = this.getVelocityAtTime.bind(this);
  12553. }
  12554. var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface);
  12555. function lookAt(elem1, elem2) {
  12556. var fVec = [elem2[0] - elem1[0], elem2[1] - elem1[1], elem2[2] - elem1[2]];
  12557. var pitch = Math.atan2(fVec[0], Math.sqrt(fVec[1] * fVec[1] + fVec[2] * fVec[2])) / degToRads;
  12558. var yaw = -Math.atan2(fVec[1], fVec[2]) / degToRads;
  12559. return [yaw, pitch, 0];
  12560. }
  12561. function easeOut(t, tMin, tMax, val1, val2) {
  12562. return applyEase(easeOutBez, t, tMin, tMax, val1, val2);
  12563. }
  12564. function easeIn(t, tMin, tMax, val1, val2) {
  12565. return applyEase(easeInBez, t, tMin, tMax, val1, val2);
  12566. }
  12567. function ease(t, tMin, tMax, val1, val2) {
  12568. return applyEase(easeInOutBez, t, tMin, tMax, val1, val2);
  12569. }
  12570. function applyEase(fn, t, tMin, tMax, val1, val2) {
  12571. if (val1 === undefined) {
  12572. val1 = tMin;
  12573. val2 = tMax;
  12574. } else {
  12575. t = (t - tMin) / (tMax - tMin);
  12576. }
  12577. if (t > 1) {
  12578. t = 1;
  12579. } else if (t < 0) {
  12580. t = 0;
  12581. }
  12582. var mult = fn(t);
  12583. if ($bm_isInstanceOfArray(val1)) {
  12584. var iKey;
  12585. var lenKey = val1.length;
  12586. var arr = createTypedArray('float32', lenKey);
  12587. for (iKey = 0; iKey < lenKey; iKey += 1) {
  12588. arr[iKey] = (val2[iKey] - val1[iKey]) * mult + val1[iKey];
  12589. }
  12590. return arr;
  12591. }
  12592. return (val2 - val1) * mult + val1;
  12593. }
  12594. function nearestKey(time) {
  12595. var iKey;
  12596. var lenKey = data.k.length;
  12597. var index;
  12598. var keyTime;
  12599. if (!data.k.length || typeof (data.k[0]) === 'number') {
  12600. index = 0;
  12601. keyTime = 0;
  12602. } else {
  12603. index = -1;
  12604. time *= elem.comp.globalData.frameRate;
  12605. if (time < data.k[0].t) {
  12606. index = 1;
  12607. keyTime = data.k[0].t;
  12608. } else {
  12609. for (iKey = 0; iKey < lenKey - 1; iKey += 1) {
  12610. if (time === data.k[iKey].t) {
  12611. index = iKey + 1;
  12612. keyTime = data.k[iKey].t;
  12613. break;
  12614. } else if (time > data.k[iKey].t && time < data.k[iKey + 1].t) {
  12615. if (time - data.k[iKey].t > data.k[iKey + 1].t - time) {
  12616. index = iKey + 2;
  12617. keyTime = data.k[iKey + 1].t;
  12618. } else {
  12619. index = iKey + 1;
  12620. keyTime = data.k[iKey].t;
  12621. }
  12622. break;
  12623. }
  12624. }
  12625. if (index === -1) {
  12626. index = iKey + 1;
  12627. keyTime = data.k[iKey].t;
  12628. }
  12629. }
  12630. }
  12631. var obKey = {};
  12632. obKey.index = index;
  12633. obKey.time = keyTime / elem.comp.globalData.frameRate;
  12634. return obKey;
  12635. }
  12636. function key(ind) {
  12637. var obKey;
  12638. var iKey;
  12639. var lenKey;
  12640. if (!data.k.length || typeof (data.k[0]) === 'number') {
  12641. throw new Error('The property has no keyframe at index ' + ind);
  12642. }
  12643. ind -= 1;
  12644. obKey = {
  12645. time: data.k[ind].t / elem.comp.globalData.frameRate,
  12646. value: [],
  12647. };
  12648. var arr = Object.prototype.hasOwnProperty.call(data.k[ind], 's') ? data.k[ind].s : data.k[ind - 1].e;
  12649. lenKey = arr.length;
  12650. for (iKey = 0; iKey < lenKey; iKey += 1) {
  12651. obKey[iKey] = arr[iKey];
  12652. obKey.value[iKey] = arr[iKey];
  12653. }
  12654. return obKey;
  12655. }
  12656. function framesToTime(fr, fps) {
  12657. if (!fps) {
  12658. fps = elem.comp.globalData.frameRate;
  12659. }
  12660. return fr / fps;
  12661. }
  12662. function timeToFrames(t, fps) {
  12663. if (!t && t !== 0) {
  12664. t = time;
  12665. }
  12666. if (!fps) {
  12667. fps = elem.comp.globalData.frameRate;
  12668. }
  12669. return t * fps;
  12670. }
  12671. function seedRandom(seed) {
  12672. BMMath.seedrandom(randSeed + seed);
  12673. }
  12674. function sourceRectAtTime() {
  12675. return elem.sourceRectAtTime();
  12676. }
  12677. function substring(init, end) {
  12678. if (typeof value === 'string') {
  12679. if (end === undefined) {
  12680. return value.substring(init);
  12681. }
  12682. return value.substring(init, end);
  12683. }
  12684. return '';
  12685. }
  12686. function substr(init, end) {
  12687. if (typeof value === 'string') {
  12688. if (end === undefined) {
  12689. return value.substr(init);
  12690. }
  12691. return value.substr(init, end);
  12692. }
  12693. return '';
  12694. }
  12695. function posterizeTime(framesPerSecond) {
  12696. time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond;
  12697. value = valueAtTime(time);
  12698. }
  12699. var time;
  12700. var velocity;
  12701. var value;
  12702. var text;
  12703. var textIndex;
  12704. var textTotal;
  12705. var selectorValue;
  12706. var index = elem.data.ind;
  12707. var hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  12708. var parent;
  12709. var randSeed = Math.floor(Math.random() * 1000000);
  12710. var globalData = elem.globalData;
  12711. function executeExpression(_value) {
  12712. // globalData.pushExpression();
  12713. value = _value;
  12714. if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') {
  12715. return value;
  12716. }
  12717. if (this.propType === 'textSelector') {
  12718. textIndex = this.textIndex;
  12719. textTotal = this.textTotal;
  12720. selectorValue = this.selectorValue;
  12721. }
  12722. if (!thisLayer) {
  12723. text = elem.layerInterface.text;
  12724. thisLayer = elem.layerInterface;
  12725. thisComp = elem.comp.compInterface;
  12726. toWorld = thisLayer.toWorld.bind(thisLayer);
  12727. fromWorld = thisLayer.fromWorld.bind(thisLayer);
  12728. fromComp = thisLayer.fromComp.bind(thisLayer);
  12729. toComp = thisLayer.toComp.bind(thisLayer);
  12730. mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null;
  12731. fromCompToSurface = fromComp;
  12732. }
  12733. if (!transform) {
  12734. transform = elem.layerInterface('ADBE Transform Group');
  12735. $bm_transform = transform;
  12736. if (transform) {
  12737. anchorPoint = transform.anchorPoint;
  12738. /* position = transform.position;
  12739. rotation = transform.rotation;
  12740. scale = transform.scale; */
  12741. }
  12742. }
  12743. if (elemType === 4 && !content) {
  12744. content = thisLayer('ADBE Root Vectors Group');
  12745. }
  12746. if (!effect) {
  12747. effect = thisLayer(4);
  12748. }
  12749. hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  12750. if (hasParent && !parent) {
  12751. parent = elem.hierarchy[0].layerInterface;
  12752. }
  12753. time = this.comp.renderedFrame / this.comp.globalData.frameRate;
  12754. if (_needsRandom) {
  12755. seedRandom(randSeed + time);
  12756. }
  12757. if (needsVelocity) {
  12758. velocity = velocityAtTime(time);
  12759. }
  12760. expression_function();
  12761. this.frameExpressionId = elem.globalData.frameId;
  12762. // TODO: Check if it's possible to return on ShapeInterface the .v value
  12763. // Changed this to a ternary operation because Rollup failed compiling it correctly
  12764. scoped_bm_rt = scoped_bm_rt.propType === propTypes.SHAPE
  12765. ? scoped_bm_rt.v
  12766. : scoped_bm_rt;
  12767. return scoped_bm_rt;
  12768. }
  12769. // Bundlers will see these as dead code and unless we reference them
  12770. executeExpression.__preventDeadCodeRemoval = [$bm_transform, anchorPoint, time, velocity, inPoint, outPoint, width, height, name, loop_in, loop_out, smooth, toComp, fromCompToSurface, toWorld, fromWorld, mask, position, rotation, scale, thisComp, numKeys, active, wiggle, loopInDuration, loopOutDuration, comp, lookAt, easeOut, easeIn, ease, nearestKey, key, text, textIndex, textTotal, selectorValue, framesToTime, timeToFrames, sourceRectAtTime, substring, substr, posterizeTime, index, globalData];
  12771. return executeExpression;
  12772. }
  12773. ob.initiateExpression = initiateExpression;
  12774. ob.__preventDeadCodeRemoval = [window, document, XMLHttpRequest, fetch, frames, $bm_neg, add, $bm_sum, $bm_sub, $bm_mul, $bm_div, $bm_mod, clamp, radians_to_degrees, degreesToRadians, degrees_to_radians, normalize, rgbToHsl, hslToRgb, linear, random, createPath, _lottieGlobal];
  12775. ob.resetFrame = resetFrame;
  12776. return ob;
  12777. }());
  12778. const Expressions = (function () {
  12779. var ob = {};
  12780. ob.initExpressions = initExpressions;
  12781. ob.resetFrame = ExpressionManager.resetFrame;
  12782. function initExpressions(animation) {
  12783. var stackCount = 0;
  12784. var registers = [];
  12785. function pushExpression() {
  12786. stackCount += 1;
  12787. }
  12788. function popExpression() {
  12789. stackCount -= 1;
  12790. if (stackCount === 0) {
  12791. releaseInstances();
  12792. }
  12793. }
  12794. function registerExpressionProperty(expression) {
  12795. if (registers.indexOf(expression) === -1) {
  12796. registers.push(expression);
  12797. }
  12798. }
  12799. function releaseInstances() {
  12800. var i;
  12801. var len = registers.length;
  12802. for (i = 0; i < len; i += 1) {
  12803. registers[i].release();
  12804. }
  12805. registers.length = 0;
  12806. }
  12807. animation.renderer.compInterface = CompExpressionInterface(animation.renderer);
  12808. animation.renderer.globalData.projectInterface.registerComposition(animation.renderer);
  12809. animation.renderer.globalData.pushExpression = pushExpression;
  12810. animation.renderer.globalData.popExpression = popExpression;
  12811. animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty;
  12812. }
  12813. return ob;
  12814. }());
  12815. const MaskManagerInterface = (function () {
  12816. function MaskInterface(mask, data) {
  12817. this._mask = mask;
  12818. this._data = data;
  12819. }
  12820. Object.defineProperty(MaskInterface.prototype, 'maskPath', {
  12821. get: function () {
  12822. if (this._mask.prop.k) {
  12823. this._mask.prop.getValue();
  12824. }
  12825. return this._mask.prop;
  12826. },
  12827. });
  12828. Object.defineProperty(MaskInterface.prototype, 'maskOpacity', {
  12829. get: function () {
  12830. if (this._mask.op.k) {
  12831. this._mask.op.getValue();
  12832. }
  12833. return this._mask.op.v * 100;
  12834. },
  12835. });
  12836. var MaskManager = function (maskManager) {
  12837. var _masksInterfaces = createSizedArray(maskManager.viewData.length);
  12838. var i;
  12839. var len = maskManager.viewData.length;
  12840. for (i = 0; i < len; i += 1) {
  12841. _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]);
  12842. }
  12843. var maskFunction = function (name) {
  12844. i = 0;
  12845. while (i < len) {
  12846. if (maskManager.masksProperties[i].nm === name) {
  12847. return _masksInterfaces[i];
  12848. }
  12849. i += 1;
  12850. }
  12851. return null;
  12852. };
  12853. return maskFunction;
  12854. };
  12855. return MaskManager;
  12856. }());
  12857. const ExpressionPropertyInterface = (function () {
  12858. var defaultUnidimensionalValue = { pv: 0, v: 0, mult: 1 };
  12859. var defaultMultidimensionalValue = { pv: [0, 0, 0], v: [0, 0, 0], mult: 1 };
  12860. function completeProperty(expressionValue, property, type) {
  12861. Object.defineProperty(expressionValue, 'velocity', {
  12862. get: function () {
  12863. return property.getVelocityAtTime(property.comp.currentFrame);
  12864. },
  12865. });
  12866. expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0;
  12867. expressionValue.key = function (pos) {
  12868. if (!expressionValue.numKeys) {
  12869. return 0;
  12870. }
  12871. var value = '';
  12872. if ('s' in property.keyframes[pos - 1]) {
  12873. value = property.keyframes[pos - 1].s;
  12874. } else if ('e' in property.keyframes[pos - 2]) {
  12875. value = property.keyframes[pos - 2].e;
  12876. } else {
  12877. value = property.keyframes[pos - 2].s;
  12878. }
  12879. var valueProp = type === 'unidimensional' ? new Number(value) : Object.assign({}, value); // eslint-disable-line no-new-wrappers
  12880. valueProp.time = property.keyframes[pos - 1].t / property.elem.comp.globalData.frameRate;
  12881. valueProp.value = type === 'unidimensional' ? value[0] : value;
  12882. return valueProp;
  12883. };
  12884. expressionValue.valueAtTime = property.getValueAtTime;
  12885. expressionValue.speedAtTime = property.getSpeedAtTime;
  12886. expressionValue.velocityAtTime = property.getVelocityAtTime;
  12887. expressionValue.propertyGroup = property.propertyGroup;
  12888. }
  12889. function UnidimensionalPropertyInterface(property) {
  12890. if (!property || !('pv' in property)) {
  12891. property = defaultUnidimensionalValue;
  12892. }
  12893. var mult = 1 / property.mult;
  12894. var val = property.pv * mult;
  12895. var expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  12896. expressionValue.value = val;
  12897. completeProperty(expressionValue, property, 'unidimensional');
  12898. return function () {
  12899. if (property.k) {
  12900. property.getValue();
  12901. }
  12902. val = property.v * mult;
  12903. if (expressionValue.value !== val) {
  12904. expressionValue = new Number(val); // eslint-disable-line no-new-wrappers
  12905. expressionValue.value = val;
  12906. expressionValue[0] = val;
  12907. completeProperty(expressionValue, property, 'unidimensional');
  12908. }
  12909. return expressionValue;
  12910. };
  12911. }
  12912. function MultidimensionalPropertyInterface(property) {
  12913. if (!property || !('pv' in property)) {
  12914. property = defaultMultidimensionalValue;
  12915. }
  12916. var mult = 1 / property.mult;
  12917. var len = (property.data && property.data.l) || property.pv.length;
  12918. var expressionValue = createTypedArray('float32', len);
  12919. var arrValue = createTypedArray('float32', len);
  12920. expressionValue.value = arrValue;
  12921. completeProperty(expressionValue, property, 'multidimensional');
  12922. return function () {
  12923. if (property.k) {
  12924. property.getValue();
  12925. }
  12926. for (var i = 0; i < len; i += 1) {
  12927. arrValue[i] = property.v[i] * mult;
  12928. expressionValue[i] = arrValue[i];
  12929. }
  12930. return expressionValue;
  12931. };
  12932. }
  12933. // TODO: try to avoid using this getter
  12934. function defaultGetter() {
  12935. return defaultUnidimensionalValue;
  12936. }
  12937. return function (property) {
  12938. if (!property) {
  12939. return defaultGetter;
  12940. } if (property.propType === 'unidimensional') {
  12941. return UnidimensionalPropertyInterface(property);
  12942. }
  12943. return MultidimensionalPropertyInterface(property);
  12944. };
  12945. }());
  12946. const TransformExpressionInterface = (function () {
  12947. return function (transform) {
  12948. function _thisFunction(name) {
  12949. switch (name) {
  12950. case 'scale':
  12951. case 'Scale':
  12952. case 'ADBE Scale':
  12953. case 6:
  12954. return _thisFunction.scale;
  12955. case 'rotation':
  12956. case 'Rotation':
  12957. case 'ADBE Rotation':
  12958. case 'ADBE Rotate Z':
  12959. case 10:
  12960. return _thisFunction.rotation;
  12961. case 'ADBE Rotate X':
  12962. return _thisFunction.xRotation;
  12963. case 'ADBE Rotate Y':
  12964. return _thisFunction.yRotation;
  12965. case 'position':
  12966. case 'Position':
  12967. case 'ADBE Position':
  12968. case 2:
  12969. return _thisFunction.position;
  12970. case 'ADBE Position_0':
  12971. return _thisFunction.xPosition;
  12972. case 'ADBE Position_1':
  12973. return _thisFunction.yPosition;
  12974. case 'ADBE Position_2':
  12975. return _thisFunction.zPosition;
  12976. case 'anchorPoint':
  12977. case 'AnchorPoint':
  12978. case 'Anchor Point':
  12979. case 'ADBE AnchorPoint':
  12980. case 1:
  12981. return _thisFunction.anchorPoint;
  12982. case 'opacity':
  12983. case 'Opacity':
  12984. case 11:
  12985. return _thisFunction.opacity;
  12986. default:
  12987. return null;
  12988. }
  12989. }
  12990. Object.defineProperty(_thisFunction, 'rotation', {
  12991. get: ExpressionPropertyInterface(transform.r || transform.rz),
  12992. });
  12993. Object.defineProperty(_thisFunction, 'zRotation', {
  12994. get: ExpressionPropertyInterface(transform.rz || transform.r),
  12995. });
  12996. Object.defineProperty(_thisFunction, 'xRotation', {
  12997. get: ExpressionPropertyInterface(transform.rx),
  12998. });
  12999. Object.defineProperty(_thisFunction, 'yRotation', {
  13000. get: ExpressionPropertyInterface(transform.ry),
  13001. });
  13002. Object.defineProperty(_thisFunction, 'scale', {
  13003. get: ExpressionPropertyInterface(transform.s),
  13004. });
  13005. var _px;
  13006. var _py;
  13007. var _pz;
  13008. var _transformFactory;
  13009. if (transform.p) {
  13010. _transformFactory = ExpressionPropertyInterface(transform.p);
  13011. } else {
  13012. _px = ExpressionPropertyInterface(transform.px);
  13013. _py = ExpressionPropertyInterface(transform.py);
  13014. if (transform.pz) {
  13015. _pz = ExpressionPropertyInterface(transform.pz);
  13016. }
  13017. }
  13018. Object.defineProperty(_thisFunction, 'position', {
  13019. get: function () {
  13020. if (transform.p) {
  13021. return _transformFactory();
  13022. }
  13023. return [
  13024. _px(),
  13025. _py(),
  13026. _pz ? _pz() : 0];
  13027. },
  13028. });
  13029. Object.defineProperty(_thisFunction, 'xPosition', {
  13030. get: ExpressionPropertyInterface(transform.px),
  13031. });
  13032. Object.defineProperty(_thisFunction, 'yPosition', {
  13033. get: ExpressionPropertyInterface(transform.py),
  13034. });
  13035. Object.defineProperty(_thisFunction, 'zPosition', {
  13036. get: ExpressionPropertyInterface(transform.pz),
  13037. });
  13038. Object.defineProperty(_thisFunction, 'anchorPoint', {
  13039. get: ExpressionPropertyInterface(transform.a),
  13040. });
  13041. Object.defineProperty(_thisFunction, 'opacity', {
  13042. get: ExpressionPropertyInterface(transform.o),
  13043. });
  13044. Object.defineProperty(_thisFunction, 'skew', {
  13045. get: ExpressionPropertyInterface(transform.sk),
  13046. });
  13047. Object.defineProperty(_thisFunction, 'skewAxis', {
  13048. get: ExpressionPropertyInterface(transform.sa),
  13049. });
  13050. Object.defineProperty(_thisFunction, 'orientation', {
  13051. get: ExpressionPropertyInterface(transform.or),
  13052. });
  13053. return _thisFunction;
  13054. };
  13055. }());
  13056. const LayerExpressionInterface = (function () {
  13057. function getMatrix(time) {
  13058. var toWorldMat = new Matrix();
  13059. if (time !== undefined) {
  13060. var propMatrix = this._elem.finalTransform.mProp.getValueAtTime(time);
  13061. propMatrix.clone(toWorldMat);
  13062. } else {
  13063. var transformMat = this._elem.finalTransform.mProp;
  13064. transformMat.applyToMatrix(toWorldMat);
  13065. }
  13066. return toWorldMat;
  13067. }
  13068. function toWorldVec(arr, time) {
  13069. var toWorldMat = this.getMatrix(time);
  13070. toWorldMat.props[12] = 0;
  13071. toWorldMat.props[13] = 0;
  13072. toWorldMat.props[14] = 0;
  13073. return this.applyPoint(toWorldMat, arr);
  13074. }
  13075. function toWorld(arr, time) {
  13076. var toWorldMat = this.getMatrix(time);
  13077. return this.applyPoint(toWorldMat, arr);
  13078. }
  13079. function fromWorldVec(arr, time) {
  13080. var toWorldMat = this.getMatrix(time);
  13081. toWorldMat.props[12] = 0;
  13082. toWorldMat.props[13] = 0;
  13083. toWorldMat.props[14] = 0;
  13084. return this.invertPoint(toWorldMat, arr);
  13085. }
  13086. function fromWorld(arr, time) {
  13087. var toWorldMat = this.getMatrix(time);
  13088. return this.invertPoint(toWorldMat, arr);
  13089. }
  13090. function applyPoint(matrix, arr) {
  13091. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  13092. var i;
  13093. var len = this._elem.hierarchy.length;
  13094. for (i = 0; i < len; i += 1) {
  13095. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  13096. }
  13097. }
  13098. return matrix.applyToPointArray(arr[0], arr[1], arr[2] || 0);
  13099. }
  13100. function invertPoint(matrix, arr) {
  13101. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  13102. var i;
  13103. var len = this._elem.hierarchy.length;
  13104. for (i = 0; i < len; i += 1) {
  13105. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix);
  13106. }
  13107. }
  13108. return matrix.inversePoint(arr);
  13109. }
  13110. function fromComp(arr) {
  13111. var toWorldMat = new Matrix();
  13112. toWorldMat.reset();
  13113. this._elem.finalTransform.mProp.applyToMatrix(toWorldMat);
  13114. if (this._elem.hierarchy && this._elem.hierarchy.length) {
  13115. var i;
  13116. var len = this._elem.hierarchy.length;
  13117. for (i = 0; i < len; i += 1) {
  13118. this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat);
  13119. }
  13120. return toWorldMat.inversePoint(arr);
  13121. }
  13122. return toWorldMat.inversePoint(arr);
  13123. }
  13124. function sampleImage() {
  13125. return [1, 1, 1, 1];
  13126. }
  13127. return function (elem) {
  13128. var transformInterface;
  13129. function _registerMaskInterface(maskManager) {
  13130. _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem);
  13131. }
  13132. function _registerEffectsInterface(effects) {
  13133. _thisLayerFunction.effect = effects;
  13134. }
  13135. function _thisLayerFunction(name) {
  13136. switch (name) {
  13137. case 'ADBE Root Vectors Group':
  13138. case 'Contents':
  13139. case 2:
  13140. return _thisLayerFunction.shapeInterface;
  13141. case 1:
  13142. case 6:
  13143. case 'Transform':
  13144. case 'transform':
  13145. case 'ADBE Transform Group':
  13146. return transformInterface;
  13147. case 4:
  13148. case 'ADBE Effect Parade':
  13149. case 'effects':
  13150. case 'Effects':
  13151. return _thisLayerFunction.effect;
  13152. case 'ADBE Text Properties':
  13153. return _thisLayerFunction.textInterface;
  13154. default:
  13155. return null;
  13156. }
  13157. }
  13158. _thisLayerFunction.getMatrix = getMatrix;
  13159. _thisLayerFunction.invertPoint = invertPoint;
  13160. _thisLayerFunction.applyPoint = applyPoint;
  13161. _thisLayerFunction.toWorld = toWorld;
  13162. _thisLayerFunction.toWorldVec = toWorldVec;
  13163. _thisLayerFunction.fromWorld = fromWorld;
  13164. _thisLayerFunction.fromWorldVec = fromWorldVec;
  13165. _thisLayerFunction.toComp = toWorld;
  13166. _thisLayerFunction.fromComp = fromComp;
  13167. _thisLayerFunction.sampleImage = sampleImage;
  13168. _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem);
  13169. _thisLayerFunction._elem = elem;
  13170. transformInterface = TransformExpressionInterface(elem.finalTransform.mProp);
  13171. var anchorPointDescriptor = getDescriptor(transformInterface, 'anchorPoint');
  13172. Object.defineProperties(_thisLayerFunction, {
  13173. hasParent: {
  13174. get: function () {
  13175. return elem.hierarchy.length;
  13176. },
  13177. },
  13178. parent: {
  13179. get: function () {
  13180. return elem.hierarchy[0].layerInterface;
  13181. },
  13182. },
  13183. rotation: getDescriptor(transformInterface, 'rotation'),
  13184. scale: getDescriptor(transformInterface, 'scale'),
  13185. position: getDescriptor(transformInterface, 'position'),
  13186. opacity: getDescriptor(transformInterface, 'opacity'),
  13187. anchorPoint: anchorPointDescriptor,
  13188. anchor_point: anchorPointDescriptor,
  13189. transform: {
  13190. get: function () {
  13191. return transformInterface;
  13192. },
  13193. },
  13194. active: {
  13195. get: function () {
  13196. return elem.isInRange;
  13197. },
  13198. },
  13199. });
  13200. _thisLayerFunction.startTime = elem.data.st;
  13201. _thisLayerFunction.index = elem.data.ind;
  13202. _thisLayerFunction.source = elem.data.refId;
  13203. _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100;
  13204. _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100;
  13205. _thisLayerFunction.inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  13206. _thisLayerFunction.outPoint = elem.data.op / elem.comp.globalData.frameRate;
  13207. _thisLayerFunction._name = elem.data.nm;
  13208. _thisLayerFunction.registerMaskInterface = _registerMaskInterface;
  13209. _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface;
  13210. return _thisLayerFunction;
  13211. };
  13212. }());
  13213. const propertyGroupFactory = (function () {
  13214. return function (interfaceFunction, parentPropertyGroup) {
  13215. return function (val) {
  13216. val = val === undefined ? 1 : val;
  13217. if (val <= 0) {
  13218. return interfaceFunction;
  13219. }
  13220. return parentPropertyGroup(val - 1);
  13221. };
  13222. };
  13223. }());
  13224. const PropertyInterface = (function () {
  13225. return function (propertyName, propertyGroup) {
  13226. var interfaceFunction = {
  13227. _name: propertyName,
  13228. };
  13229. function _propertyGroup(val) {
  13230. val = val === undefined ? 1 : val;
  13231. if (val <= 0) {
  13232. return interfaceFunction;
  13233. }
  13234. return propertyGroup(val - 1);
  13235. }
  13236. return _propertyGroup;
  13237. };
  13238. }());
  13239. const EffectsExpressionInterface = (function () {
  13240. var ob = {
  13241. createEffectsInterface: createEffectsInterface,
  13242. };
  13243. function createEffectsInterface(elem, propertyGroup) {
  13244. if (elem.effectsManager) {
  13245. var effectElements = [];
  13246. var effectsData = elem.data.ef;
  13247. var i;
  13248. var len = elem.effectsManager.effectElements.length;
  13249. for (i = 0; i < len; i += 1) {
  13250. effectElements.push(createGroupInterface(effectsData[i], elem.effectsManager.effectElements[i], propertyGroup, elem));
  13251. }
  13252. var effects = elem.data.ef || [];
  13253. var groupInterface = function (name) {
  13254. i = 0;
  13255. len = effects.length;
  13256. while (i < len) {
  13257. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  13258. return effectElements[i];
  13259. }
  13260. i += 1;
  13261. }
  13262. return null;
  13263. };
  13264. Object.defineProperty(groupInterface, 'numProperties', {
  13265. get: function () {
  13266. return effects.length;
  13267. },
  13268. });
  13269. return groupInterface;
  13270. }
  13271. return null;
  13272. }
  13273. function createGroupInterface(data, elements, propertyGroup, elem) {
  13274. function groupInterface(name) {
  13275. var effects = data.ef;
  13276. var i = 0;
  13277. var len = effects.length;
  13278. while (i < len) {
  13279. if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) {
  13280. if (effects[i].ty === 5) {
  13281. return effectElements[i];
  13282. }
  13283. return effectElements[i]();
  13284. }
  13285. i += 1;
  13286. }
  13287. throw new Error();
  13288. }
  13289. var _propertyGroup = propertyGroupFactory(groupInterface, propertyGroup);
  13290. var effectElements = [];
  13291. var i;
  13292. var len = data.ef.length;
  13293. for (i = 0; i < len; i += 1) {
  13294. if (data.ef[i].ty === 5) {
  13295. effectElements.push(createGroupInterface(data.ef[i], elements.effectElements[i], elements.effectElements[i].propertyGroup, elem));
  13296. } else {
  13297. effectElements.push(createValueInterface(elements.effectElements[i], data.ef[i].ty, elem, _propertyGroup));
  13298. }
  13299. }
  13300. if (data.mn === 'ADBE Color Control') {
  13301. Object.defineProperty(groupInterface, 'color', {
  13302. get: function () {
  13303. return effectElements[0]();
  13304. },
  13305. });
  13306. }
  13307. Object.defineProperties(groupInterface, {
  13308. numProperties: {
  13309. get: function () {
  13310. return data.np;
  13311. },
  13312. },
  13313. _name: { value: data.nm },
  13314. propertyGroup: { value: _propertyGroup },
  13315. });
  13316. groupInterface.enabled = data.en !== 0;
  13317. groupInterface.active = groupInterface.enabled;
  13318. return groupInterface;
  13319. }
  13320. function createValueInterface(element, type, elem, propertyGroup) {
  13321. var expressionProperty = ExpressionPropertyInterface(element.p);
  13322. function interfaceFunction() {
  13323. if (type === 10) {
  13324. return elem.comp.compInterface(element.p.v);
  13325. }
  13326. return expressionProperty();
  13327. }
  13328. if (element.p.setGroupProperty) {
  13329. element.p.setGroupProperty(PropertyInterface('', propertyGroup));
  13330. }
  13331. return interfaceFunction;
  13332. }
  13333. return ob;
  13334. }());
  13335. const ShapePathInterface = (
  13336. function () {
  13337. return function pathInterfaceFactory(shape, view, propertyGroup) {
  13338. var prop = view.sh;
  13339. function interfaceFunction(val) {
  13340. if (val === 'Shape' || val === 'shape' || val === 'Path' || val === 'path' || val === 'ADBE Vector Shape' || val === 2) {
  13341. return interfaceFunction.path;
  13342. }
  13343. return null;
  13344. }
  13345. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13346. prop.setGroupProperty(PropertyInterface('Path', _propertyGroup));
  13347. Object.defineProperties(interfaceFunction, {
  13348. path: {
  13349. get: function () {
  13350. if (prop.k) {
  13351. prop.getValue();
  13352. }
  13353. return prop;
  13354. },
  13355. },
  13356. shape: {
  13357. get: function () {
  13358. if (prop.k) {
  13359. prop.getValue();
  13360. }
  13361. return prop;
  13362. },
  13363. },
  13364. _name: { value: shape.nm },
  13365. ix: { value: shape.ix },
  13366. propertyIndex: { value: shape.ix },
  13367. mn: { value: shape.mn },
  13368. propertyGroup: { value: propertyGroup },
  13369. });
  13370. return interfaceFunction;
  13371. };
  13372. }()
  13373. );
  13374. const ShapeExpressionInterface = (function () {
  13375. function iterateElements(shapes, view, propertyGroup) {
  13376. var arr = [];
  13377. var i;
  13378. var len = shapes ? shapes.length : 0;
  13379. for (i = 0; i < len; i += 1) {
  13380. if (shapes[i].ty === 'gr') {
  13381. arr.push(groupInterfaceFactory(shapes[i], view[i], propertyGroup));
  13382. } else if (shapes[i].ty === 'fl') {
  13383. arr.push(fillInterfaceFactory(shapes[i], view[i], propertyGroup));
  13384. } else if (shapes[i].ty === 'st') {
  13385. arr.push(strokeInterfaceFactory(shapes[i], view[i], propertyGroup));
  13386. } else if (shapes[i].ty === 'tm') {
  13387. arr.push(trimInterfaceFactory(shapes[i], view[i], propertyGroup));
  13388. } else if (shapes[i].ty === 'tr') {
  13389. // arr.push(transformInterfaceFactory(shapes[i],view[i],propertyGroup));
  13390. } else if (shapes[i].ty === 'el') {
  13391. arr.push(ellipseInterfaceFactory(shapes[i], view[i], propertyGroup));
  13392. } else if (shapes[i].ty === 'sr') {
  13393. arr.push(starInterfaceFactory(shapes[i], view[i], propertyGroup));
  13394. } else if (shapes[i].ty === 'sh') {
  13395. arr.push(ShapePathInterface(shapes[i], view[i], propertyGroup));
  13396. } else if (shapes[i].ty === 'rc') {
  13397. arr.push(rectInterfaceFactory(shapes[i], view[i], propertyGroup));
  13398. } else if (shapes[i].ty === 'rd') {
  13399. arr.push(roundedInterfaceFactory(shapes[i], view[i], propertyGroup));
  13400. } else if (shapes[i].ty === 'rp') {
  13401. arr.push(repeaterInterfaceFactory(shapes[i], view[i], propertyGroup));
  13402. } else if (shapes[i].ty === 'gf') {
  13403. arr.push(gradientFillInterfaceFactory(shapes[i], view[i], propertyGroup));
  13404. } else {
  13405. arr.push(defaultInterfaceFactory(shapes[i], view[i], propertyGroup));
  13406. }
  13407. }
  13408. return arr;
  13409. }
  13410. function contentsInterfaceFactory(shape, view, propertyGroup) {
  13411. var interfaces;
  13412. var interfaceFunction = function _interfaceFunction(value) {
  13413. var i = 0;
  13414. var len = interfaces.length;
  13415. while (i < len) {
  13416. if (interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value) {
  13417. return interfaces[i];
  13418. }
  13419. i += 1;
  13420. }
  13421. if (typeof value === 'number') {
  13422. return interfaces[value - 1];
  13423. }
  13424. return null;
  13425. };
  13426. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13427. interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup);
  13428. interfaceFunction.numProperties = interfaces.length;
  13429. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  13430. interfaceFunction.transform = transformInterface;
  13431. interfaceFunction.propertyIndex = shape.cix;
  13432. interfaceFunction._name = shape.nm;
  13433. return interfaceFunction;
  13434. }
  13435. function groupInterfaceFactory(shape, view, propertyGroup) {
  13436. var interfaceFunction = function _interfaceFunction(value) {
  13437. switch (value) {
  13438. case 'ADBE Vectors Group':
  13439. case 'Contents':
  13440. case 2:
  13441. return interfaceFunction.content;
  13442. // Not necessary for now. Keeping them here in case a new case appears
  13443. // case 'ADBE Vector Transform Group':
  13444. // case 3:
  13445. default:
  13446. return interfaceFunction.transform;
  13447. }
  13448. };
  13449. interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13450. var content = contentsInterfaceFactory(shape, view, interfaceFunction.propertyGroup);
  13451. var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup);
  13452. interfaceFunction.content = content;
  13453. interfaceFunction.transform = transformInterface;
  13454. Object.defineProperty(interfaceFunction, '_name', {
  13455. get: function () {
  13456. return shape.nm;
  13457. },
  13458. });
  13459. // interfaceFunction.content = interfaceFunction;
  13460. interfaceFunction.numProperties = shape.np;
  13461. interfaceFunction.propertyIndex = shape.ix;
  13462. interfaceFunction.nm = shape.nm;
  13463. interfaceFunction.mn = shape.mn;
  13464. return interfaceFunction;
  13465. }
  13466. function fillInterfaceFactory(shape, view, propertyGroup) {
  13467. function interfaceFunction(val) {
  13468. if (val === 'Color' || val === 'color') {
  13469. return interfaceFunction.color;
  13470. } if (val === 'Opacity' || val === 'opacity') {
  13471. return interfaceFunction.opacity;
  13472. }
  13473. return null;
  13474. }
  13475. Object.defineProperties(interfaceFunction, {
  13476. color: {
  13477. get: ExpressionPropertyInterface(view.c),
  13478. },
  13479. opacity: {
  13480. get: ExpressionPropertyInterface(view.o),
  13481. },
  13482. _name: { value: shape.nm },
  13483. mn: { value: shape.mn },
  13484. });
  13485. view.c.setGroupProperty(PropertyInterface('Color', propertyGroup));
  13486. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  13487. return interfaceFunction;
  13488. }
  13489. function gradientFillInterfaceFactory(shape, view, propertyGroup) {
  13490. function interfaceFunction(val) {
  13491. if (val === 'Start Point' || val === 'start point') {
  13492. return interfaceFunction.startPoint;
  13493. }
  13494. if (val === 'End Point' || val === 'end point') {
  13495. return interfaceFunction.endPoint;
  13496. }
  13497. if (val === 'Opacity' || val === 'opacity') {
  13498. return interfaceFunction.opacity;
  13499. }
  13500. return null;
  13501. }
  13502. Object.defineProperties(interfaceFunction, {
  13503. startPoint: {
  13504. get: ExpressionPropertyInterface(view.s),
  13505. },
  13506. endPoint: {
  13507. get: ExpressionPropertyInterface(view.e),
  13508. },
  13509. opacity: {
  13510. get: ExpressionPropertyInterface(view.o),
  13511. },
  13512. type: {
  13513. get: function () {
  13514. return 'a';
  13515. },
  13516. },
  13517. _name: { value: shape.nm },
  13518. mn: { value: shape.mn },
  13519. });
  13520. view.s.setGroupProperty(PropertyInterface('Start Point', propertyGroup));
  13521. view.e.setGroupProperty(PropertyInterface('End Point', propertyGroup));
  13522. view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup));
  13523. return interfaceFunction;
  13524. }
  13525. function defaultInterfaceFactory() {
  13526. function interfaceFunction() {
  13527. return null;
  13528. }
  13529. return interfaceFunction;
  13530. }
  13531. function strokeInterfaceFactory(shape, view, propertyGroup) {
  13532. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13533. var _dashPropertyGroup = propertyGroupFactory(dashOb, _propertyGroup);
  13534. function addPropertyToDashOb(i) {
  13535. Object.defineProperty(dashOb, shape.d[i].nm, {
  13536. get: ExpressionPropertyInterface(view.d.dataProps[i].p),
  13537. });
  13538. }
  13539. var i;
  13540. var len = shape.d ? shape.d.length : 0;
  13541. var dashOb = {};
  13542. for (i = 0; i < len; i += 1) {
  13543. addPropertyToDashOb(i);
  13544. view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup);
  13545. }
  13546. function interfaceFunction(val) {
  13547. if (val === 'Color' || val === 'color') {
  13548. return interfaceFunction.color;
  13549. } if (val === 'Opacity' || val === 'opacity') {
  13550. return interfaceFunction.opacity;
  13551. } if (val === 'Stroke Width' || val === 'stroke width') {
  13552. return interfaceFunction.strokeWidth;
  13553. }
  13554. return null;
  13555. }
  13556. Object.defineProperties(interfaceFunction, {
  13557. color: {
  13558. get: ExpressionPropertyInterface(view.c),
  13559. },
  13560. opacity: {
  13561. get: ExpressionPropertyInterface(view.o),
  13562. },
  13563. strokeWidth: {
  13564. get: ExpressionPropertyInterface(view.w),
  13565. },
  13566. dash: {
  13567. get: function () {
  13568. return dashOb;
  13569. },
  13570. },
  13571. _name: { value: shape.nm },
  13572. mn: { value: shape.mn },
  13573. });
  13574. view.c.setGroupProperty(PropertyInterface('Color', _propertyGroup));
  13575. view.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  13576. view.w.setGroupProperty(PropertyInterface('Stroke Width', _propertyGroup));
  13577. return interfaceFunction;
  13578. }
  13579. function trimInterfaceFactory(shape, view, propertyGroup) {
  13580. function interfaceFunction(val) {
  13581. if (val === shape.e.ix || val === 'End' || val === 'end') {
  13582. return interfaceFunction.end;
  13583. }
  13584. if (val === shape.s.ix) {
  13585. return interfaceFunction.start;
  13586. }
  13587. if (val === shape.o.ix) {
  13588. return interfaceFunction.offset;
  13589. }
  13590. return null;
  13591. }
  13592. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13593. interfaceFunction.propertyIndex = shape.ix;
  13594. view.s.setGroupProperty(PropertyInterface('Start', _propertyGroup));
  13595. view.e.setGroupProperty(PropertyInterface('End', _propertyGroup));
  13596. view.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  13597. interfaceFunction.propertyIndex = shape.ix;
  13598. interfaceFunction.propertyGroup = propertyGroup;
  13599. Object.defineProperties(interfaceFunction, {
  13600. start: {
  13601. get: ExpressionPropertyInterface(view.s),
  13602. },
  13603. end: {
  13604. get: ExpressionPropertyInterface(view.e),
  13605. },
  13606. offset: {
  13607. get: ExpressionPropertyInterface(view.o),
  13608. },
  13609. _name: { value: shape.nm },
  13610. });
  13611. interfaceFunction.mn = shape.mn;
  13612. return interfaceFunction;
  13613. }
  13614. function transformInterfaceFactory(shape, view, propertyGroup) {
  13615. function interfaceFunction(value) {
  13616. if (shape.a.ix === value || value === 'Anchor Point') {
  13617. return interfaceFunction.anchorPoint;
  13618. }
  13619. if (shape.o.ix === value || value === 'Opacity') {
  13620. return interfaceFunction.opacity;
  13621. }
  13622. if (shape.p.ix === value || value === 'Position') {
  13623. return interfaceFunction.position;
  13624. }
  13625. if (shape.r.ix === value || value === 'Rotation' || value === 'ADBE Vector Rotation') {
  13626. return interfaceFunction.rotation;
  13627. }
  13628. if (shape.s.ix === value || value === 'Scale') {
  13629. return interfaceFunction.scale;
  13630. }
  13631. if ((shape.sk && shape.sk.ix === value) || value === 'Skew') {
  13632. return interfaceFunction.skew;
  13633. }
  13634. if ((shape.sa && shape.sa.ix === value) || value === 'Skew Axis') {
  13635. return interfaceFunction.skewAxis;
  13636. }
  13637. return null;
  13638. }
  13639. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13640. view.transform.mProps.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  13641. view.transform.mProps.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  13642. view.transform.mProps.a.setGroupProperty(PropertyInterface('Anchor Point', _propertyGroup));
  13643. view.transform.mProps.s.setGroupProperty(PropertyInterface('Scale', _propertyGroup));
  13644. view.transform.mProps.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  13645. if (view.transform.mProps.sk) {
  13646. view.transform.mProps.sk.setGroupProperty(PropertyInterface('Skew', _propertyGroup));
  13647. view.transform.mProps.sa.setGroupProperty(PropertyInterface('Skew Angle', _propertyGroup));
  13648. }
  13649. view.transform.op.setGroupProperty(PropertyInterface('Opacity', _propertyGroup));
  13650. Object.defineProperties(interfaceFunction, {
  13651. opacity: {
  13652. get: ExpressionPropertyInterface(view.transform.mProps.o),
  13653. },
  13654. position: {
  13655. get: ExpressionPropertyInterface(view.transform.mProps.p),
  13656. },
  13657. anchorPoint: {
  13658. get: ExpressionPropertyInterface(view.transform.mProps.a),
  13659. },
  13660. scale: {
  13661. get: ExpressionPropertyInterface(view.transform.mProps.s),
  13662. },
  13663. rotation: {
  13664. get: ExpressionPropertyInterface(view.transform.mProps.r),
  13665. },
  13666. skew: {
  13667. get: ExpressionPropertyInterface(view.transform.mProps.sk),
  13668. },
  13669. skewAxis: {
  13670. get: ExpressionPropertyInterface(view.transform.mProps.sa),
  13671. },
  13672. _name: { value: shape.nm },
  13673. });
  13674. interfaceFunction.ty = 'tr';
  13675. interfaceFunction.mn = shape.mn;
  13676. interfaceFunction.propertyGroup = propertyGroup;
  13677. return interfaceFunction;
  13678. }
  13679. function ellipseInterfaceFactory(shape, view, propertyGroup) {
  13680. function interfaceFunction(value) {
  13681. if (shape.p.ix === value) {
  13682. return interfaceFunction.position;
  13683. }
  13684. if (shape.s.ix === value) {
  13685. return interfaceFunction.size;
  13686. }
  13687. return null;
  13688. }
  13689. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13690. interfaceFunction.propertyIndex = shape.ix;
  13691. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  13692. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  13693. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  13694. Object.defineProperties(interfaceFunction, {
  13695. size: {
  13696. get: ExpressionPropertyInterface(prop.s),
  13697. },
  13698. position: {
  13699. get: ExpressionPropertyInterface(prop.p),
  13700. },
  13701. _name: { value: shape.nm },
  13702. });
  13703. interfaceFunction.mn = shape.mn;
  13704. return interfaceFunction;
  13705. }
  13706. function starInterfaceFactory(shape, view, propertyGroup) {
  13707. function interfaceFunction(value) {
  13708. if (shape.p.ix === value) {
  13709. return interfaceFunction.position;
  13710. }
  13711. if (shape.r.ix === value) {
  13712. return interfaceFunction.rotation;
  13713. }
  13714. if (shape.pt.ix === value) {
  13715. return interfaceFunction.points;
  13716. }
  13717. if (shape.or.ix === value || value === 'ADBE Vector Star Outer Radius') {
  13718. return interfaceFunction.outerRadius;
  13719. }
  13720. if (shape.os.ix === value) {
  13721. return interfaceFunction.outerRoundness;
  13722. }
  13723. if (shape.ir && (shape.ir.ix === value || value === 'ADBE Vector Star Inner Radius')) {
  13724. return interfaceFunction.innerRadius;
  13725. }
  13726. if (shape.is && shape.is.ix === value) {
  13727. return interfaceFunction.innerRoundness;
  13728. }
  13729. return null;
  13730. }
  13731. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13732. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  13733. interfaceFunction.propertyIndex = shape.ix;
  13734. prop.or.setGroupProperty(PropertyInterface('Outer Radius', _propertyGroup));
  13735. prop.os.setGroupProperty(PropertyInterface('Outer Roundness', _propertyGroup));
  13736. prop.pt.setGroupProperty(PropertyInterface('Points', _propertyGroup));
  13737. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  13738. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  13739. if (shape.ir) {
  13740. prop.ir.setGroupProperty(PropertyInterface('Inner Radius', _propertyGroup));
  13741. prop.is.setGroupProperty(PropertyInterface('Inner Roundness', _propertyGroup));
  13742. }
  13743. Object.defineProperties(interfaceFunction, {
  13744. position: {
  13745. get: ExpressionPropertyInterface(prop.p),
  13746. },
  13747. rotation: {
  13748. get: ExpressionPropertyInterface(prop.r),
  13749. },
  13750. points: {
  13751. get: ExpressionPropertyInterface(prop.pt),
  13752. },
  13753. outerRadius: {
  13754. get: ExpressionPropertyInterface(prop.or),
  13755. },
  13756. outerRoundness: {
  13757. get: ExpressionPropertyInterface(prop.os),
  13758. },
  13759. innerRadius: {
  13760. get: ExpressionPropertyInterface(prop.ir),
  13761. },
  13762. innerRoundness: {
  13763. get: ExpressionPropertyInterface(prop.is),
  13764. },
  13765. _name: { value: shape.nm },
  13766. });
  13767. interfaceFunction.mn = shape.mn;
  13768. return interfaceFunction;
  13769. }
  13770. function rectInterfaceFactory(shape, view, propertyGroup) {
  13771. function interfaceFunction(value) {
  13772. if (shape.p.ix === value) {
  13773. return interfaceFunction.position;
  13774. }
  13775. if (shape.r.ix === value) {
  13776. return interfaceFunction.roundness;
  13777. }
  13778. if (shape.s.ix === value || value === 'Size' || value === 'ADBE Vector Rect Size') {
  13779. return interfaceFunction.size;
  13780. }
  13781. return null;
  13782. }
  13783. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13784. var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh;
  13785. interfaceFunction.propertyIndex = shape.ix;
  13786. prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup));
  13787. prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup));
  13788. prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup));
  13789. Object.defineProperties(interfaceFunction, {
  13790. position: {
  13791. get: ExpressionPropertyInterface(prop.p),
  13792. },
  13793. roundness: {
  13794. get: ExpressionPropertyInterface(prop.r),
  13795. },
  13796. size: {
  13797. get: ExpressionPropertyInterface(prop.s),
  13798. },
  13799. _name: { value: shape.nm },
  13800. });
  13801. interfaceFunction.mn = shape.mn;
  13802. return interfaceFunction;
  13803. }
  13804. function roundedInterfaceFactory(shape, view, propertyGroup) {
  13805. function interfaceFunction(value) {
  13806. if (shape.r.ix === value || value === 'Round Corners 1') {
  13807. return interfaceFunction.radius;
  13808. }
  13809. return null;
  13810. }
  13811. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13812. var prop = view;
  13813. interfaceFunction.propertyIndex = shape.ix;
  13814. prop.rd.setGroupProperty(PropertyInterface('Radius', _propertyGroup));
  13815. Object.defineProperties(interfaceFunction, {
  13816. radius: {
  13817. get: ExpressionPropertyInterface(prop.rd),
  13818. },
  13819. _name: { value: shape.nm },
  13820. });
  13821. interfaceFunction.mn = shape.mn;
  13822. return interfaceFunction;
  13823. }
  13824. function repeaterInterfaceFactory(shape, view, propertyGroup) {
  13825. function interfaceFunction(value) {
  13826. if (shape.c.ix === value || value === 'Copies') {
  13827. return interfaceFunction.copies;
  13828. } if (shape.o.ix === value || value === 'Offset') {
  13829. return interfaceFunction.offset;
  13830. }
  13831. return null;
  13832. }
  13833. var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup);
  13834. var prop = view;
  13835. interfaceFunction.propertyIndex = shape.ix;
  13836. prop.c.setGroupProperty(PropertyInterface('Copies', _propertyGroup));
  13837. prop.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup));
  13838. Object.defineProperties(interfaceFunction, {
  13839. copies: {
  13840. get: ExpressionPropertyInterface(prop.c),
  13841. },
  13842. offset: {
  13843. get: ExpressionPropertyInterface(prop.o),
  13844. },
  13845. _name: { value: shape.nm },
  13846. });
  13847. interfaceFunction.mn = shape.mn;
  13848. return interfaceFunction;
  13849. }
  13850. return function (shapes, view, propertyGroup) {
  13851. var interfaces;
  13852. function _interfaceFunction(value) {
  13853. if (typeof value === 'number') {
  13854. value = value === undefined ? 1 : value;
  13855. if (value === 0) {
  13856. return propertyGroup;
  13857. }
  13858. return interfaces[value - 1];
  13859. }
  13860. var i = 0;
  13861. var len = interfaces.length;
  13862. while (i < len) {
  13863. if (interfaces[i]._name === value) {
  13864. return interfaces[i];
  13865. }
  13866. i += 1;
  13867. }
  13868. return null;
  13869. }
  13870. function parentGroupWrapper() {
  13871. return propertyGroup;
  13872. }
  13873. _interfaceFunction.propertyGroup = propertyGroupFactory(_interfaceFunction, parentGroupWrapper);
  13874. interfaces = iterateElements(shapes, view, _interfaceFunction.propertyGroup);
  13875. _interfaceFunction.numProperties = interfaces.length;
  13876. _interfaceFunction._name = 'Contents';
  13877. return _interfaceFunction;
  13878. };
  13879. }());
  13880. const TextExpressionInterface = (function () {
  13881. return function (elem) {
  13882. var _sourceText;
  13883. function _thisLayerFunction(name) {
  13884. switch (name) {
  13885. case 'ADBE Text Document':
  13886. return _thisLayerFunction.sourceText;
  13887. default:
  13888. return null;
  13889. }
  13890. }
  13891. Object.defineProperty(_thisLayerFunction, 'sourceText', {
  13892. get: function () {
  13893. elem.textProperty.getValue();
  13894. var stringValue = elem.textProperty.currentData.t;
  13895. if (!_sourceText || stringValue !== _sourceText.value) {
  13896. _sourceText = new String(stringValue); // eslint-disable-line no-new-wrappers
  13897. // If stringValue is an empty string, eval returns undefined, so it has to be returned as a String primitive
  13898. _sourceText.value = stringValue || new String(stringValue); // eslint-disable-line no-new-wrappers
  13899. Object.defineProperty(_sourceText, 'style', {
  13900. get: function () {
  13901. return {
  13902. fillColor: elem.textProperty.currentData.fc,
  13903. };
  13904. },
  13905. });
  13906. }
  13907. return _sourceText;
  13908. },
  13909. });
  13910. return _thisLayerFunction;
  13911. };
  13912. }());
  13913. const FootageInterface = (function () {
  13914. var outlineInterfaceFactory = (function (elem) {
  13915. var currentPropertyName = '';
  13916. var currentProperty = elem.getFootageData();
  13917. function init() {
  13918. currentPropertyName = '';
  13919. currentProperty = elem.getFootageData();
  13920. return searchProperty;
  13921. }
  13922. function searchProperty(value) {
  13923. if (currentProperty[value]) {
  13924. currentPropertyName = value;
  13925. currentProperty = currentProperty[value];
  13926. if (typeof currentProperty === 'object') {
  13927. return searchProperty;
  13928. }
  13929. return currentProperty;
  13930. }
  13931. var propertyNameIndex = value.indexOf(currentPropertyName);
  13932. if (propertyNameIndex !== -1) {
  13933. var index = parseInt(value.substr(propertyNameIndex + currentPropertyName.length), 10);
  13934. currentProperty = currentProperty[index];
  13935. if (typeof currentProperty === 'object') {
  13936. return searchProperty;
  13937. }
  13938. return currentProperty;
  13939. }
  13940. return '';
  13941. }
  13942. return init;
  13943. });
  13944. var dataInterfaceFactory = function (elem) {
  13945. function interfaceFunction(value) {
  13946. if (value === 'Outline') {
  13947. return interfaceFunction.outlineInterface();
  13948. }
  13949. return null;
  13950. }
  13951. interfaceFunction._name = 'Outline';
  13952. interfaceFunction.outlineInterface = outlineInterfaceFactory(elem);
  13953. return interfaceFunction;
  13954. };
  13955. return function (elem) {
  13956. function _interfaceFunction(value) {
  13957. if (value === 'Data') {
  13958. return _interfaceFunction.dataInterface;
  13959. }
  13960. return null;
  13961. }
  13962. _interfaceFunction._name = 'Data';
  13963. _interfaceFunction.dataInterface = dataInterfaceFactory(elem);
  13964. return _interfaceFunction;
  13965. };
  13966. }());
  13967. var interfaces = {
  13968. layer: LayerExpressionInterface,
  13969. effects: EffectsExpressionInterface,
  13970. comp: CompExpressionInterface,
  13971. shape: ShapeExpressionInterface,
  13972. text: TextExpressionInterface,
  13973. footage: FootageInterface,
  13974. };
  13975. function getInterface(type) {
  13976. return interfaces[type] || null;
  13977. }
  13978. const expressionHelpers = (function () {
  13979. function searchExpressions(elem, data, prop) {
  13980. if (data.x) {
  13981. prop.k = true;
  13982. prop.x = true;
  13983. prop.initiateExpression = ExpressionManager.initiateExpression;
  13984. prop.effectsSequence.push(prop.initiateExpression(elem, data, prop).bind(prop));
  13985. }
  13986. }
  13987. function getValueAtTime(frameNum) {
  13988. frameNum *= this.elem.globalData.frameRate;
  13989. frameNum -= this.offsetTime;
  13990. if (frameNum !== this._cachingAtTime.lastFrame) {
  13991. this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0;
  13992. this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime);
  13993. this._cachingAtTime.lastFrame = frameNum;
  13994. }
  13995. return this._cachingAtTime.value;
  13996. }
  13997. function getSpeedAtTime(frameNum) {
  13998. var delta = -0.01;
  13999. var v1 = this.getValueAtTime(frameNum);
  14000. var v2 = this.getValueAtTime(frameNum + delta);
  14001. var speed = 0;
  14002. if (v1.length) {
  14003. var i;
  14004. for (i = 0; i < v1.length; i += 1) {
  14005. speed += Math.pow(v2[i] - v1[i], 2);
  14006. }
  14007. speed = Math.sqrt(speed) * 100;
  14008. } else {
  14009. speed = 0;
  14010. }
  14011. return speed;
  14012. }
  14013. function getVelocityAtTime(frameNum) {
  14014. if (this.vel !== undefined) {
  14015. return this.vel;
  14016. }
  14017. var delta = -0.001;
  14018. // frameNum += this.elem.data.st;
  14019. var v1 = this.getValueAtTime(frameNum);
  14020. var v2 = this.getValueAtTime(frameNum + delta);
  14021. var velocity;
  14022. if (v1.length) {
  14023. velocity = createTypedArray('float32', v1.length);
  14024. var i;
  14025. for (i = 0; i < v1.length; i += 1) {
  14026. // removing frameRate
  14027. // if needed, don't add it here
  14028. // velocity[i] = this.elem.globalData.frameRate*((v2[i] - v1[i])/delta);
  14029. velocity[i] = (v2[i] - v1[i]) / delta;
  14030. }
  14031. } else {
  14032. velocity = (v2 - v1) / delta;
  14033. }
  14034. return velocity;
  14035. }
  14036. function getStaticValueAtTime() {
  14037. return this.pv;
  14038. }
  14039. function setGroupProperty(propertyGroup) {
  14040. this.propertyGroup = propertyGroup;
  14041. }
  14042. return {
  14043. searchExpressions: searchExpressions,
  14044. getSpeedAtTime: getSpeedAtTime,
  14045. getVelocityAtTime: getVelocityAtTime,
  14046. getValueAtTime: getValueAtTime,
  14047. getStaticValueAtTime: getStaticValueAtTime,
  14048. setGroupProperty: setGroupProperty,
  14049. };
  14050. }());
  14051. function addPropertyDecorator() {
  14052. function loopOut(type, duration, durationFlag) {
  14053. if (!this.k || !this.keyframes) {
  14054. return this.pv;
  14055. }
  14056. type = type ? type.toLowerCase() : '';
  14057. var currentFrame = this.comp.renderedFrame;
  14058. var keyframes = this.keyframes;
  14059. var lastKeyFrame = keyframes[keyframes.length - 1].t;
  14060. if (currentFrame <= lastKeyFrame) {
  14061. return this.pv;
  14062. }
  14063. var cycleDuration;
  14064. var firstKeyFrame;
  14065. if (!durationFlag) {
  14066. if (!duration || duration > keyframes.length - 1) {
  14067. duration = keyframes.length - 1;
  14068. }
  14069. firstKeyFrame = keyframes[keyframes.length - 1 - duration].t;
  14070. cycleDuration = lastKeyFrame - firstKeyFrame;
  14071. } else {
  14072. if (!duration) {
  14073. cycleDuration = Math.max(0, lastKeyFrame - this.elem.data.ip);
  14074. } else {
  14075. cycleDuration = Math.abs(lastKeyFrame - this.elem.comp.globalData.frameRate * duration);
  14076. }
  14077. firstKeyFrame = lastKeyFrame - cycleDuration;
  14078. }
  14079. var i;
  14080. var len;
  14081. var ret;
  14082. if (type === 'pingpong') {
  14083. var iterations = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  14084. if (iterations % 2 !== 0) {
  14085. return this.getValueAtTime(((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14086. }
  14087. } else if (type === 'offset') {
  14088. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  14089. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  14090. var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14091. var repeats = Math.floor((currentFrame - firstKeyFrame) / cycleDuration);
  14092. if (this.pv.length) {
  14093. ret = new Array(initV.length);
  14094. len = ret.length;
  14095. for (i = 0; i < len; i += 1) {
  14096. ret[i] = (endV[i] - initV[i]) * repeats + current[i];
  14097. }
  14098. return ret;
  14099. }
  14100. return (endV - initV) * repeats + current;
  14101. } else if (type === 'continue') {
  14102. var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  14103. var nextLastValue = this.getValueAtTime((lastKeyFrame - 0.001) / this.comp.globalData.frameRate, 0);
  14104. if (this.pv.length) {
  14105. ret = new Array(lastValue.length);
  14106. len = ret.length;
  14107. for (i = 0; i < len; i += 1) {
  14108. ret[i] = lastValue[i] + (lastValue[i] - nextLastValue[i]) * ((currentFrame - lastKeyFrame) / this.comp.globalData.frameRate) / 0.0005; // eslint-disable-line
  14109. }
  14110. return ret;
  14111. }
  14112. return lastValue + (lastValue - nextLastValue) * (((currentFrame - lastKeyFrame)) / 0.001);
  14113. }
  14114. return this.getValueAtTime((((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14115. }
  14116. function loopIn(type, duration, durationFlag) {
  14117. if (!this.k) {
  14118. return this.pv;
  14119. }
  14120. type = type ? type.toLowerCase() : '';
  14121. var currentFrame = this.comp.renderedFrame;
  14122. var keyframes = this.keyframes;
  14123. var firstKeyFrame = keyframes[0].t;
  14124. if (currentFrame >= firstKeyFrame) {
  14125. return this.pv;
  14126. }
  14127. var cycleDuration;
  14128. var lastKeyFrame;
  14129. if (!durationFlag) {
  14130. if (!duration || duration > keyframes.length - 1) {
  14131. duration = keyframes.length - 1;
  14132. }
  14133. lastKeyFrame = keyframes[duration].t;
  14134. cycleDuration = lastKeyFrame - firstKeyFrame;
  14135. } else {
  14136. if (!duration) {
  14137. cycleDuration = Math.max(0, this.elem.data.op - firstKeyFrame);
  14138. } else {
  14139. cycleDuration = Math.abs(this.elem.comp.globalData.frameRate * duration);
  14140. }
  14141. lastKeyFrame = firstKeyFrame + cycleDuration;
  14142. }
  14143. var i;
  14144. var len;
  14145. var ret;
  14146. if (type === 'pingpong') {
  14147. var iterations = Math.floor((firstKeyFrame - currentFrame) / cycleDuration);
  14148. if (iterations % 2 === 0) {
  14149. return this.getValueAtTime((((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14150. }
  14151. } else if (type === 'offset') {
  14152. var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  14153. var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0);
  14154. var current = this.getValueAtTime((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration) + firstKeyFrame) / this.comp.globalData.frameRate, 0);
  14155. var repeats = Math.floor((firstKeyFrame - currentFrame) / cycleDuration) + 1;
  14156. if (this.pv.length) {
  14157. ret = new Array(initV.length);
  14158. len = ret.length;
  14159. for (i = 0; i < len; i += 1) {
  14160. ret[i] = current[i] - (endV[i] - initV[i]) * repeats;
  14161. }
  14162. return ret;
  14163. }
  14164. return current - (endV - initV) * repeats;
  14165. } else if (type === 'continue') {
  14166. var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0);
  14167. var nextFirstValue = this.getValueAtTime((firstKeyFrame + 0.001) / this.comp.globalData.frameRate, 0);
  14168. if (this.pv.length) {
  14169. ret = new Array(firstValue.length);
  14170. len = ret.length;
  14171. for (i = 0; i < len; i += 1) {
  14172. ret[i] = firstValue[i] + ((firstValue[i] - nextFirstValue[i]) * (firstKeyFrame - currentFrame)) / 0.001;
  14173. }
  14174. return ret;
  14175. }
  14176. return firstValue + ((firstValue - nextFirstValue) * (firstKeyFrame - currentFrame)) / 0.001;
  14177. }
  14178. return this.getValueAtTime(((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame))) / this.comp.globalData.frameRate, 0); // eslint-disable-line
  14179. }
  14180. function smooth(width, samples) {
  14181. if (!this.k) {
  14182. return this.pv;
  14183. }
  14184. width = (width || 0.4) * 0.5;
  14185. samples = Math.floor(samples || 5);
  14186. if (samples <= 1) {
  14187. return this.pv;
  14188. }
  14189. var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate;
  14190. var initFrame = currentTime - width;
  14191. var endFrame = currentTime + width;
  14192. var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1;
  14193. var i = 0;
  14194. var j = 0;
  14195. var value;
  14196. if (this.pv.length) {
  14197. value = createTypedArray('float32', this.pv.length);
  14198. } else {
  14199. value = 0;
  14200. }
  14201. var sampleValue;
  14202. while (i < samples) {
  14203. sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency);
  14204. if (this.pv.length) {
  14205. for (j = 0; j < this.pv.length; j += 1) {
  14206. value[j] += sampleValue[j];
  14207. }
  14208. } else {
  14209. value += sampleValue;
  14210. }
  14211. i += 1;
  14212. }
  14213. if (this.pv.length) {
  14214. for (j = 0; j < this.pv.length; j += 1) {
  14215. value[j] /= samples;
  14216. }
  14217. } else {
  14218. value /= samples;
  14219. }
  14220. return value;
  14221. }
  14222. function getTransformValueAtTime(time) {
  14223. if (!this._transformCachingAtTime) {
  14224. this._transformCachingAtTime = {
  14225. v: new Matrix(),
  14226. };
  14227. }
  14228. /// /
  14229. var matrix = this._transformCachingAtTime.v;
  14230. matrix.cloneFromProps(this.pre.props);
  14231. if (this.appliedTransformations < 1) {
  14232. var anchor = this.a.getValueAtTime(time);
  14233. matrix.translate(
  14234. -anchor[0] * this.a.mult,
  14235. -anchor[1] * this.a.mult,
  14236. anchor[2] * this.a.mult
  14237. );
  14238. }
  14239. if (this.appliedTransformations < 2) {
  14240. var scale = this.s.getValueAtTime(time);
  14241. matrix.scale(
  14242. scale[0] * this.s.mult,
  14243. scale[1] * this.s.mult,
  14244. scale[2] * this.s.mult
  14245. );
  14246. }
  14247. if (this.sk && this.appliedTransformations < 3) {
  14248. var skew = this.sk.getValueAtTime(time);
  14249. var skewAxis = this.sa.getValueAtTime(time);
  14250. matrix.skewFromAxis(-skew * this.sk.mult, skewAxis * this.sa.mult);
  14251. }
  14252. if (this.r && this.appliedTransformations < 4) {
  14253. var rotation = this.r.getValueAtTime(time);
  14254. matrix.rotate(-rotation * this.r.mult);
  14255. } else if (!this.r && this.appliedTransformations < 4) {
  14256. var rotationZ = this.rz.getValueAtTime(time);
  14257. var rotationY = this.ry.getValueAtTime(time);
  14258. var rotationX = this.rx.getValueAtTime(time);
  14259. var orientation = this.or.getValueAtTime(time);
  14260. matrix.rotateZ(-rotationZ * this.rz.mult)
  14261. .rotateY(rotationY * this.ry.mult)
  14262. .rotateX(rotationX * this.rx.mult)
  14263. .rotateZ(-orientation[2] * this.or.mult)
  14264. .rotateY(orientation[1] * this.or.mult)
  14265. .rotateX(orientation[0] * this.or.mult);
  14266. }
  14267. if (this.data.p && this.data.p.s) {
  14268. var positionX = this.px.getValueAtTime(time);
  14269. var positionY = this.py.getValueAtTime(time);
  14270. if (this.data.p.z) {
  14271. var positionZ = this.pz.getValueAtTime(time);
  14272. matrix.translate(
  14273. positionX * this.px.mult,
  14274. positionY * this.py.mult,
  14275. -positionZ * this.pz.mult
  14276. );
  14277. } else {
  14278. matrix.translate(positionX * this.px.mult, positionY * this.py.mult, 0);
  14279. }
  14280. } else {
  14281. var position = this.p.getValueAtTime(time);
  14282. matrix.translate(
  14283. position[0] * this.p.mult,
  14284. position[1] * this.p.mult,
  14285. -position[2] * this.p.mult
  14286. );
  14287. }
  14288. return matrix;
  14289. /// /
  14290. }
  14291. function getTransformStaticValueAtTime() {
  14292. return this.v.clone(new Matrix());
  14293. }
  14294. var getTransformProperty = TransformPropertyFactory.getTransformProperty;
  14295. TransformPropertyFactory.getTransformProperty = function (elem, data, container) {
  14296. var prop = getTransformProperty(elem, data, container);
  14297. if (prop.dynamicProperties.length) {
  14298. prop.getValueAtTime = getTransformValueAtTime.bind(prop);
  14299. } else {
  14300. prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop);
  14301. }
  14302. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  14303. return prop;
  14304. };
  14305. var propertyGetProp = PropertyFactory.getProp;
  14306. PropertyFactory.getProp = function (elem, data, type, mult, container) {
  14307. var prop = propertyGetProp(elem, data, type, mult, container);
  14308. // prop.getVelocityAtTime = getVelocityAtTime;
  14309. // prop.loopOut = loopOut;
  14310. // prop.loopIn = loopIn;
  14311. if (prop.kf) {
  14312. prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop);
  14313. } else {
  14314. prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop);
  14315. }
  14316. prop.setGroupProperty = expressionHelpers.setGroupProperty;
  14317. prop.loopOut = loopOut;
  14318. prop.loopIn = loopIn;
  14319. prop.smooth = smooth;
  14320. prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop);
  14321. prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop);
  14322. prop.numKeys = data.a === 1 ? data.k.length : 0;
  14323. prop.propertyIndex = data.ix;
  14324. var value = 0;
  14325. if (type !== 0) {
  14326. value = createTypedArray('float32', data.a === 1 ? data.k[0].s.length : data.k.length);
  14327. }
  14328. prop._cachingAtTime = {
  14329. lastFrame: initialDefaultFrame,
  14330. lastIndex: 0,
  14331. value: value,
  14332. };
  14333. expressionHelpers.searchExpressions(elem, data, prop);
  14334. if (prop.k) {
  14335. container.addDynamicProperty(prop);
  14336. }
  14337. return prop;
  14338. };
  14339. function getShapeValueAtTime(frameNum) {
  14340. // For now this caching object is created only when needed instead of creating it when the shape is initialized.
  14341. if (!this._cachingAtTime) {
  14342. this._cachingAtTime = {
  14343. shapeValue: shapePool.clone(this.pv),
  14344. lastIndex: 0,
  14345. lastTime: initialDefaultFrame,
  14346. };
  14347. }
  14348. frameNum *= this.elem.globalData.frameRate;
  14349. frameNum -= this.offsetTime;
  14350. if (frameNum !== this._cachingAtTime.lastTime) {
  14351. this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0;
  14352. this._cachingAtTime.lastTime = frameNum;
  14353. this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime);
  14354. }
  14355. return this._cachingAtTime.shapeValue;
  14356. }
  14357. var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction();
  14358. var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction();
  14359. function ShapeExpressions() {}
  14360. ShapeExpressions.prototype = {
  14361. vertices: function (prop, time) {
  14362. if (this.k) {
  14363. this.getValue();
  14364. }
  14365. var shapePath = this.v;
  14366. if (time !== undefined) {
  14367. shapePath = this.getValueAtTime(time, 0);
  14368. }
  14369. var i;
  14370. var len = shapePath._length;
  14371. var vertices = shapePath[prop];
  14372. var points = shapePath.v;
  14373. var arr = createSizedArray(len);
  14374. for (i = 0; i < len; i += 1) {
  14375. if (prop === 'i' || prop === 'o') {
  14376. arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]];
  14377. } else {
  14378. arr[i] = [vertices[i][0], vertices[i][1]];
  14379. }
  14380. }
  14381. return arr;
  14382. },
  14383. points: function (time) {
  14384. return this.vertices('v', time);
  14385. },
  14386. inTangents: function (time) {
  14387. return this.vertices('i', time);
  14388. },
  14389. outTangents: function (time) {
  14390. return this.vertices('o', time);
  14391. },
  14392. isClosed: function () {
  14393. return this.v.c;
  14394. },
  14395. pointOnPath: function (perc, time) {
  14396. var shapePath = this.v;
  14397. if (time !== undefined) {
  14398. shapePath = this.getValueAtTime(time, 0);
  14399. }
  14400. if (!this._segmentsLength) {
  14401. this._segmentsLength = bez.getSegmentsLength(shapePath);
  14402. }
  14403. var segmentsLength = this._segmentsLength;
  14404. var lengths = segmentsLength.lengths;
  14405. var lengthPos = segmentsLength.totalLength * perc;
  14406. var i = 0;
  14407. var len = lengths.length;
  14408. var accumulatedLength = 0;
  14409. var pt;
  14410. while (i < len) {
  14411. if (accumulatedLength + lengths[i].addedLength > lengthPos) {
  14412. var initIndex = i;
  14413. var endIndex = (shapePath.c && i === len - 1) ? 0 : i + 1;
  14414. var segmentPerc = (lengthPos - accumulatedLength) / lengths[i].addedLength;
  14415. pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]);
  14416. break;
  14417. } else {
  14418. accumulatedLength += lengths[i].addedLength;
  14419. }
  14420. i += 1;
  14421. }
  14422. if (!pt) {
  14423. pt = shapePath.c ? [shapePath.v[0][0], shapePath.v[0][1]] : [shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1]];
  14424. }
  14425. return pt;
  14426. },
  14427. vectorOnPath: function (perc, time, vectorType) {
  14428. // perc doesn't use triple equality because it can be a Number object as well as a primitive.
  14429. if (perc == 1) { // eslint-disable-line eqeqeq
  14430. perc = this.v.c;
  14431. } else if (perc == 0) { // eslint-disable-line eqeqeq
  14432. perc = 0.999;
  14433. }
  14434. var pt1 = this.pointOnPath(perc, time);
  14435. var pt2 = this.pointOnPath(perc + 0.001, time);
  14436. var xLength = pt2[0] - pt1[0];
  14437. var yLength = pt2[1] - pt1[1];
  14438. var magnitude = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2));
  14439. if (magnitude === 0) {
  14440. return [0, 0];
  14441. }
  14442. var unitVector = vectorType === 'tangent' ? [xLength / magnitude, yLength / magnitude] : [-yLength / magnitude, xLength / magnitude];
  14443. return unitVector;
  14444. },
  14445. tangentOnPath: function (perc, time) {
  14446. return this.vectorOnPath(perc, time, 'tangent');
  14447. },
  14448. normalOnPath: function (perc, time) {
  14449. return this.vectorOnPath(perc, time, 'normal');
  14450. },
  14451. setGroupProperty: expressionHelpers.setGroupProperty,
  14452. getValueAtTime: expressionHelpers.getStaticValueAtTime,
  14453. };
  14454. extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction);
  14455. extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction);
  14456. KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime;
  14457. KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression;
  14458. var propertyGetShapeProp = ShapePropertyFactory.getShapeProp;
  14459. ShapePropertyFactory.getShapeProp = function (elem, data, type, arr, trims) {
  14460. var prop = propertyGetShapeProp(elem, data, type, arr, trims);
  14461. prop.propertyIndex = data.ix;
  14462. prop.lock = false;
  14463. if (type === 3) {
  14464. expressionHelpers.searchExpressions(elem, data.pt, prop);
  14465. } else if (type === 4) {
  14466. expressionHelpers.searchExpressions(elem, data.ks, prop);
  14467. }
  14468. if (prop.k) {
  14469. elem.addDynamicProperty(prop);
  14470. }
  14471. return prop;
  14472. };
  14473. }
  14474. function initialize$1() {
  14475. addPropertyDecorator();
  14476. }
  14477. function addDecorator() {
  14478. function searchExpressions() {
  14479. if (this.data.d.x) {
  14480. this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem, this.data.d, this);
  14481. this.addEffect(this.getExpressionValue.bind(this));
  14482. return true;
  14483. }
  14484. return null;
  14485. }
  14486. TextProperty.prototype.getExpressionValue = function (currentValue, text) {
  14487. var newValue = this.calculateExpression(text);
  14488. if (currentValue.t !== newValue) {
  14489. var newData = {};
  14490. this.copyData(newData, currentValue);
  14491. newData.t = newValue.toString();
  14492. newData.__complete = false;
  14493. return newData;
  14494. }
  14495. return currentValue;
  14496. };
  14497. TextProperty.prototype.searchProperty = function () {
  14498. var isKeyframed = this.searchKeyframes();
  14499. var hasExpressions = this.searchExpressions();
  14500. this.kf = isKeyframed || hasExpressions;
  14501. return this.kf;
  14502. };
  14503. TextProperty.prototype.searchExpressions = searchExpressions;
  14504. }
  14505. function initialize() {
  14506. addDecorator();
  14507. }
  14508. function SVGComposableEffect() {
  14509. }
  14510. SVGComposableEffect.prototype = {
  14511. createMergeNode: (resultId, ins) => {
  14512. var feMerge = createNS('feMerge');
  14513. feMerge.setAttribute('result', resultId);
  14514. var feMergeNode;
  14515. var i;
  14516. for (i = 0; i < ins.length; i += 1) {
  14517. feMergeNode = createNS('feMergeNode');
  14518. feMergeNode.setAttribute('in', ins[i]);
  14519. feMerge.appendChild(feMergeNode);
  14520. feMerge.appendChild(feMergeNode);
  14521. }
  14522. return feMerge;
  14523. },
  14524. };
  14525. var linearFilterValue = '0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0';
  14526. function SVGTintFilter(filter, filterManager, elem, id, source) {
  14527. this.filterManager = filterManager;
  14528. var feColorMatrix = createNS('feColorMatrix');
  14529. feColorMatrix.setAttribute('type', 'matrix');
  14530. feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB');
  14531. feColorMatrix.setAttribute('values', linearFilterValue + ' 1 0');
  14532. this.linearFilter = feColorMatrix;
  14533. feColorMatrix.setAttribute('result', id + '_tint_1');
  14534. filter.appendChild(feColorMatrix);
  14535. feColorMatrix = createNS('feColorMatrix');
  14536. feColorMatrix.setAttribute('type', 'matrix');
  14537. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  14538. feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0');
  14539. feColorMatrix.setAttribute('result', id + '_tint_2');
  14540. filter.appendChild(feColorMatrix);
  14541. this.matrixFilter = feColorMatrix;
  14542. var feMerge = this.createMergeNode(
  14543. id,
  14544. [
  14545. source,
  14546. id + '_tint_1',
  14547. id + '_tint_2',
  14548. ]
  14549. );
  14550. filter.appendChild(feMerge);
  14551. }
  14552. extendPrototype([SVGComposableEffect], SVGTintFilter);
  14553. SVGTintFilter.prototype.renderFrame = function (forceRender) {
  14554. if (forceRender || this.filterManager._mdf) {
  14555. var colorBlack = this.filterManager.effectElements[0].p.v;
  14556. var colorWhite = this.filterManager.effectElements[1].p.v;
  14557. var opacity = this.filterManager.effectElements[2].p.v / 100;
  14558. this.linearFilter.setAttribute('values', linearFilterValue + ' ' + opacity + ' 0');
  14559. this.matrixFilter.setAttribute('values', (colorWhite[0] - colorBlack[0]) + ' 0 0 0 ' + colorBlack[0] + ' ' + (colorWhite[1] - colorBlack[1]) + ' 0 0 0 ' + colorBlack[1] + ' ' + (colorWhite[2] - colorBlack[2]) + ' 0 0 0 ' + colorBlack[2] + ' 0 0 0 1 0');
  14560. }
  14561. };
  14562. function SVGFillFilter(filter, filterManager, elem, id) {
  14563. this.filterManager = filterManager;
  14564. var feColorMatrix = createNS('feColorMatrix');
  14565. feColorMatrix.setAttribute('type', 'matrix');
  14566. feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
  14567. feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0');
  14568. feColorMatrix.setAttribute('result', id);
  14569. filter.appendChild(feColorMatrix);
  14570. this.matrixFilter = feColorMatrix;
  14571. }
  14572. SVGFillFilter.prototype.renderFrame = function (forceRender) {
  14573. if (forceRender || this.filterManager._mdf) {
  14574. var color = this.filterManager.effectElements[2].p.v;
  14575. var opacity = this.filterManager.effectElements[6].p.v;
  14576. this.matrixFilter.setAttribute('values', '0 0 0 0 ' + color[0] + ' 0 0 0 0 ' + color[1] + ' 0 0 0 0 ' + color[2] + ' 0 0 0 ' + opacity + ' 0');
  14577. }
  14578. };
  14579. function SVGStrokeEffect(fil, filterManager, elem) {
  14580. this.initialized = false;
  14581. this.filterManager = filterManager;
  14582. this.elem = elem;
  14583. this.paths = [];
  14584. }
  14585. SVGStrokeEffect.prototype.initialize = function () {
  14586. var elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes;
  14587. var path;
  14588. var groupPath;
  14589. var i;
  14590. var len;
  14591. if (this.filterManager.effectElements[1].p.v === 1) {
  14592. len = this.elem.maskManager.masksProperties.length;
  14593. i = 0;
  14594. } else {
  14595. i = this.filterManager.effectElements[0].p.v - 1;
  14596. len = i + 1;
  14597. }
  14598. groupPath = createNS('g');
  14599. groupPath.setAttribute('fill', 'none');
  14600. groupPath.setAttribute('stroke-linecap', 'round');
  14601. groupPath.setAttribute('stroke-dashoffset', 1);
  14602. for (i; i < len; i += 1) {
  14603. path = createNS('path');
  14604. groupPath.appendChild(path);
  14605. this.paths.push({ p: path, m: i });
  14606. }
  14607. if (this.filterManager.effectElements[10].p.v === 3) {
  14608. var mask = createNS('mask');
  14609. var id = createElementID();
  14610. mask.setAttribute('id', id);
  14611. mask.setAttribute('mask-type', 'alpha');
  14612. mask.appendChild(groupPath);
  14613. this.elem.globalData.defs.appendChild(mask);
  14614. var g = createNS('g');
  14615. g.setAttribute('mask', 'url(' + getLocationHref() + '#' + id + ')');
  14616. while (elemChildren[0]) {
  14617. g.appendChild(elemChildren[0]);
  14618. }
  14619. this.elem.layerElement.appendChild(g);
  14620. this.masker = mask;
  14621. groupPath.setAttribute('stroke', '#fff');
  14622. } else if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) {
  14623. if (this.filterManager.effectElements[10].p.v === 2) {
  14624. elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes;
  14625. while (elemChildren.length) {
  14626. this.elem.layerElement.removeChild(elemChildren[0]);
  14627. }
  14628. }
  14629. this.elem.layerElement.appendChild(groupPath);
  14630. this.elem.layerElement.removeAttribute('mask');
  14631. groupPath.setAttribute('stroke', '#fff');
  14632. }
  14633. this.initialized = true;
  14634. this.pathMasker = groupPath;
  14635. };
  14636. SVGStrokeEffect.prototype.renderFrame = function (forceRender) {
  14637. if (!this.initialized) {
  14638. this.initialize();
  14639. }
  14640. var i;
  14641. var len = this.paths.length;
  14642. var mask;
  14643. var path;
  14644. for (i = 0; i < len; i += 1) {
  14645. if (this.paths[i].m !== -1) {
  14646. mask = this.elem.maskManager.viewData[this.paths[i].m];
  14647. path = this.paths[i].p;
  14648. if (forceRender || this.filterManager._mdf || mask.prop._mdf) {
  14649. path.setAttribute('d', mask.lastPath);
  14650. }
  14651. if (forceRender || this.filterManager.effectElements[9].p._mdf || this.filterManager.effectElements[4].p._mdf || this.filterManager.effectElements[7].p._mdf || this.filterManager.effectElements[8].p._mdf || mask.prop._mdf) {
  14652. var dasharrayValue;
  14653. if (this.filterManager.effectElements[7].p.v !== 0 || this.filterManager.effectElements[8].p.v !== 100) {
  14654. var s = Math.min(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01;
  14655. var e = Math.max(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01;
  14656. var l = path.getTotalLength();
  14657. dasharrayValue = '0 0 0 ' + l * s + ' ';
  14658. var lineLength = l * (e - s);
  14659. var segment = 1 + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01;
  14660. var units = Math.floor(lineLength / segment);
  14661. var j;
  14662. for (j = 0; j < units; j += 1) {
  14663. dasharrayValue += '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01 + ' ';
  14664. }
  14665. dasharrayValue += '0 ' + l * 10 + ' 0 0';
  14666. } else {
  14667. dasharrayValue = '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01;
  14668. }
  14669. path.setAttribute('stroke-dasharray', dasharrayValue);
  14670. }
  14671. }
  14672. }
  14673. if (forceRender || this.filterManager.effectElements[4].p._mdf) {
  14674. this.pathMasker.setAttribute('stroke-width', this.filterManager.effectElements[4].p.v * 2);
  14675. }
  14676. if (forceRender || this.filterManager.effectElements[6].p._mdf) {
  14677. this.pathMasker.setAttribute('opacity', this.filterManager.effectElements[6].p.v);
  14678. }
  14679. if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) {
  14680. if (forceRender || this.filterManager.effectElements[3].p._mdf) {
  14681. var color = this.filterManager.effectElements[3].p.v;
  14682. this.pathMasker.setAttribute('stroke', 'rgb(' + bmFloor(color[0] * 255) + ',' + bmFloor(color[1] * 255) + ',' + bmFloor(color[2] * 255) + ')');
  14683. }
  14684. }
  14685. };
  14686. function SVGTritoneFilter(filter, filterManager, elem, id) {
  14687. this.filterManager = filterManager;
  14688. var feColorMatrix = createNS('feColorMatrix');
  14689. feColorMatrix.setAttribute('type', 'matrix');
  14690. feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB');
  14691. feColorMatrix.setAttribute('values', '0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0');
  14692. filter.appendChild(feColorMatrix);
  14693. var feComponentTransfer = createNS('feComponentTransfer');
  14694. feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB');
  14695. feComponentTransfer.setAttribute('result', id);
  14696. this.matrixFilter = feComponentTransfer;
  14697. var feFuncR = createNS('feFuncR');
  14698. feFuncR.setAttribute('type', 'table');
  14699. feComponentTransfer.appendChild(feFuncR);
  14700. this.feFuncR = feFuncR;
  14701. var feFuncG = createNS('feFuncG');
  14702. feFuncG.setAttribute('type', 'table');
  14703. feComponentTransfer.appendChild(feFuncG);
  14704. this.feFuncG = feFuncG;
  14705. var feFuncB = createNS('feFuncB');
  14706. feFuncB.setAttribute('type', 'table');
  14707. feComponentTransfer.appendChild(feFuncB);
  14708. this.feFuncB = feFuncB;
  14709. filter.appendChild(feComponentTransfer);
  14710. }
  14711. SVGTritoneFilter.prototype.renderFrame = function (forceRender) {
  14712. if (forceRender || this.filterManager._mdf) {
  14713. var color1 = this.filterManager.effectElements[0].p.v;
  14714. var color2 = this.filterManager.effectElements[1].p.v;
  14715. var color3 = this.filterManager.effectElements[2].p.v;
  14716. var tableR = color3[0] + ' ' + color2[0] + ' ' + color1[0];
  14717. var tableG = color3[1] + ' ' + color2[1] + ' ' + color1[1];
  14718. var tableB = color3[2] + ' ' + color2[2] + ' ' + color1[2];
  14719. this.feFuncR.setAttribute('tableValues', tableR);
  14720. this.feFuncG.setAttribute('tableValues', tableG);
  14721. this.feFuncB.setAttribute('tableValues', tableB);
  14722. }
  14723. };
  14724. function SVGProLevelsFilter(filter, filterManager, elem, id) {
  14725. this.filterManager = filterManager;
  14726. var effectElements = this.filterManager.effectElements;
  14727. var feComponentTransfer = createNS('feComponentTransfer');
  14728. // Red
  14729. if (effectElements[10].p.k || effectElements[10].p.v !== 0 || effectElements[11].p.k || effectElements[11].p.v !== 1 || effectElements[12].p.k || effectElements[12].p.v !== 1 || effectElements[13].p.k || effectElements[13].p.v !== 0 || effectElements[14].p.k || effectElements[14].p.v !== 1) {
  14730. this.feFuncR = this.createFeFunc('feFuncR', feComponentTransfer);
  14731. }
  14732. // Green
  14733. if (effectElements[17].p.k || effectElements[17].p.v !== 0 || effectElements[18].p.k || effectElements[18].p.v !== 1 || effectElements[19].p.k || effectElements[19].p.v !== 1 || effectElements[20].p.k || effectElements[20].p.v !== 0 || effectElements[21].p.k || effectElements[21].p.v !== 1) {
  14734. this.feFuncG = this.createFeFunc('feFuncG', feComponentTransfer);
  14735. }
  14736. // Blue
  14737. if (effectElements[24].p.k || effectElements[24].p.v !== 0 || effectElements[25].p.k || effectElements[25].p.v !== 1 || effectElements[26].p.k || effectElements[26].p.v !== 1 || effectElements[27].p.k || effectElements[27].p.v !== 0 || effectElements[28].p.k || effectElements[28].p.v !== 1) {
  14738. this.feFuncB = this.createFeFunc('feFuncB', feComponentTransfer);
  14739. }
  14740. // Alpha
  14741. if (effectElements[31].p.k || effectElements[31].p.v !== 0 || effectElements[32].p.k || effectElements[32].p.v !== 1 || effectElements[33].p.k || effectElements[33].p.v !== 1 || effectElements[34].p.k || effectElements[34].p.v !== 0 || effectElements[35].p.k || effectElements[35].p.v !== 1) {
  14742. this.feFuncA = this.createFeFunc('feFuncA', feComponentTransfer);
  14743. }
  14744. // RGB
  14745. if (this.feFuncR || this.feFuncG || this.feFuncB || this.feFuncA) {
  14746. feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB');
  14747. filter.appendChild(feComponentTransfer);
  14748. }
  14749. if (effectElements[3].p.k || effectElements[3].p.v !== 0 || effectElements[4].p.k || effectElements[4].p.v !== 1 || effectElements[5].p.k || effectElements[5].p.v !== 1 || effectElements[6].p.k || effectElements[6].p.v !== 0 || effectElements[7].p.k || effectElements[7].p.v !== 1) {
  14750. feComponentTransfer = createNS('feComponentTransfer');
  14751. feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB');
  14752. feComponentTransfer.setAttribute('result', id);
  14753. filter.appendChild(feComponentTransfer);
  14754. this.feFuncRComposed = this.createFeFunc('feFuncR', feComponentTransfer);
  14755. this.feFuncGComposed = this.createFeFunc('feFuncG', feComponentTransfer);
  14756. this.feFuncBComposed = this.createFeFunc('feFuncB', feComponentTransfer);
  14757. }
  14758. }
  14759. SVGProLevelsFilter.prototype.createFeFunc = function (type, feComponentTransfer) {
  14760. var feFunc = createNS(type);
  14761. feFunc.setAttribute('type', 'table');
  14762. feComponentTransfer.appendChild(feFunc);
  14763. return feFunc;
  14764. };
  14765. SVGProLevelsFilter.prototype.getTableValue = function (inputBlack, inputWhite, gamma, outputBlack, outputWhite) {
  14766. var cnt = 0;
  14767. var segments = 256;
  14768. var perc;
  14769. var min = Math.min(inputBlack, inputWhite);
  14770. var max = Math.max(inputBlack, inputWhite);
  14771. var table = Array.call(null, { length: segments });
  14772. var colorValue;
  14773. var pos = 0;
  14774. var outputDelta = outputWhite - outputBlack;
  14775. var inputDelta = inputWhite - inputBlack;
  14776. while (cnt <= 256) {
  14777. perc = cnt / 256;
  14778. if (perc <= min) {
  14779. colorValue = inputDelta < 0 ? outputWhite : outputBlack;
  14780. } else if (perc >= max) {
  14781. colorValue = inputDelta < 0 ? outputBlack : outputWhite;
  14782. } else {
  14783. colorValue = (outputBlack + outputDelta * Math.pow((perc - inputBlack) / inputDelta, 1 / gamma));
  14784. }
  14785. table[pos] = colorValue;
  14786. pos += 1;
  14787. cnt += 256 / (segments - 1);
  14788. }
  14789. return table.join(' ');
  14790. };
  14791. SVGProLevelsFilter.prototype.renderFrame = function (forceRender) {
  14792. if (forceRender || this.filterManager._mdf) {
  14793. var val;
  14794. var effectElements = this.filterManager.effectElements;
  14795. if (this.feFuncRComposed && (forceRender || effectElements[3].p._mdf || effectElements[4].p._mdf || effectElements[5].p._mdf || effectElements[6].p._mdf || effectElements[7].p._mdf)) {
  14796. val = this.getTableValue(effectElements[3].p.v, effectElements[4].p.v, effectElements[5].p.v, effectElements[6].p.v, effectElements[7].p.v);
  14797. this.feFuncRComposed.setAttribute('tableValues', val);
  14798. this.feFuncGComposed.setAttribute('tableValues', val);
  14799. this.feFuncBComposed.setAttribute('tableValues', val);
  14800. }
  14801. if (this.feFuncR && (forceRender || effectElements[10].p._mdf || effectElements[11].p._mdf || effectElements[12].p._mdf || effectElements[13].p._mdf || effectElements[14].p._mdf)) {
  14802. val = this.getTableValue(effectElements[10].p.v, effectElements[11].p.v, effectElements[12].p.v, effectElements[13].p.v, effectElements[14].p.v);
  14803. this.feFuncR.setAttribute('tableValues', val);
  14804. }
  14805. if (this.feFuncG && (forceRender || effectElements[17].p._mdf || effectElements[18].p._mdf || effectElements[19].p._mdf || effectElements[20].p._mdf || effectElements[21].p._mdf)) {
  14806. val = this.getTableValue(effectElements[17].p.v, effectElements[18].p.v, effectElements[19].p.v, effectElements[20].p.v, effectElements[21].p.v);
  14807. this.feFuncG.setAttribute('tableValues', val);
  14808. }
  14809. if (this.feFuncB && (forceRender || effectElements[24].p._mdf || effectElements[25].p._mdf || effectElements[26].p._mdf || effectElements[27].p._mdf || effectElements[28].p._mdf)) {
  14810. val = this.getTableValue(effectElements[24].p.v, effectElements[25].p.v, effectElements[26].p.v, effectElements[27].p.v, effectElements[28].p.v);
  14811. this.feFuncB.setAttribute('tableValues', val);
  14812. }
  14813. if (this.feFuncA && (forceRender || effectElements[31].p._mdf || effectElements[32].p._mdf || effectElements[33].p._mdf || effectElements[34].p._mdf || effectElements[35].p._mdf)) {
  14814. val = this.getTableValue(effectElements[31].p.v, effectElements[32].p.v, effectElements[33].p.v, effectElements[34].p.v, effectElements[35].p.v);
  14815. this.feFuncA.setAttribute('tableValues', val);
  14816. }
  14817. }
  14818. };
  14819. function SVGDropShadowEffect(filter, filterManager, elem, id, source) {
  14820. var globalFilterSize = filterManager.container.globalData.renderConfig.filterSize;
  14821. var filterSize = filterManager.data.fs || globalFilterSize;
  14822. filter.setAttribute('x', filterSize.x || globalFilterSize.x);
  14823. filter.setAttribute('y', filterSize.y || globalFilterSize.y);
  14824. filter.setAttribute('width', filterSize.width || globalFilterSize.width);
  14825. filter.setAttribute('height', filterSize.height || globalFilterSize.height);
  14826. this.filterManager = filterManager;
  14827. var feGaussianBlur = createNS('feGaussianBlur');
  14828. feGaussianBlur.setAttribute('in', 'SourceAlpha');
  14829. feGaussianBlur.setAttribute('result', id + '_drop_shadow_1');
  14830. feGaussianBlur.setAttribute('stdDeviation', '0');
  14831. this.feGaussianBlur = feGaussianBlur;
  14832. filter.appendChild(feGaussianBlur);
  14833. var feOffset = createNS('feOffset');
  14834. feOffset.setAttribute('dx', '25');
  14835. feOffset.setAttribute('dy', '0');
  14836. feOffset.setAttribute('in', id + '_drop_shadow_1');
  14837. feOffset.setAttribute('result', id + '_drop_shadow_2');
  14838. this.feOffset = feOffset;
  14839. filter.appendChild(feOffset);
  14840. var feFlood = createNS('feFlood');
  14841. feFlood.setAttribute('flood-color', '#00ff00');
  14842. feFlood.setAttribute('flood-opacity', '1');
  14843. feFlood.setAttribute('result', id + '_drop_shadow_3');
  14844. this.feFlood = feFlood;
  14845. filter.appendChild(feFlood);
  14846. var feComposite = createNS('feComposite');
  14847. feComposite.setAttribute('in', id + '_drop_shadow_3');
  14848. feComposite.setAttribute('in2', id + '_drop_shadow_2');
  14849. feComposite.setAttribute('operator', 'in');
  14850. feComposite.setAttribute('result', id + '_drop_shadow_4');
  14851. filter.appendChild(feComposite);
  14852. var feMerge = this.createMergeNode(
  14853. id,
  14854. [
  14855. id + '_drop_shadow_4',
  14856. source,
  14857. ]
  14858. );
  14859. filter.appendChild(feMerge);
  14860. //
  14861. }
  14862. extendPrototype([SVGComposableEffect], SVGDropShadowEffect);
  14863. SVGDropShadowEffect.prototype.renderFrame = function (forceRender) {
  14864. if (forceRender || this.filterManager._mdf) {
  14865. if (forceRender || this.filterManager.effectElements[4].p._mdf) {
  14866. this.feGaussianBlur.setAttribute('stdDeviation', this.filterManager.effectElements[4].p.v / 4);
  14867. }
  14868. if (forceRender || this.filterManager.effectElements[0].p._mdf) {
  14869. var col = this.filterManager.effectElements[0].p.v;
  14870. this.feFlood.setAttribute('flood-color', rgbToHex(Math.round(col[0] * 255), Math.round(col[1] * 255), Math.round(col[2] * 255)));
  14871. }
  14872. if (forceRender || this.filterManager.effectElements[1].p._mdf) {
  14873. this.feFlood.setAttribute('flood-opacity', this.filterManager.effectElements[1].p.v / 255);
  14874. }
  14875. if (forceRender || this.filterManager.effectElements[2].p._mdf || this.filterManager.effectElements[3].p._mdf) {
  14876. var distance = this.filterManager.effectElements[3].p.v;
  14877. var angle = (this.filterManager.effectElements[2].p.v - 90) * degToRads;
  14878. var x = distance * Math.cos(angle);
  14879. var y = distance * Math.sin(angle);
  14880. this.feOffset.setAttribute('dx', x);
  14881. this.feOffset.setAttribute('dy', y);
  14882. }
  14883. }
  14884. };
  14885. var _svgMatteSymbols = [];
  14886. function SVGMatte3Effect(filterElem, filterManager, elem) {
  14887. this.initialized = false;
  14888. this.filterManager = filterManager;
  14889. this.filterElem = filterElem;
  14890. this.elem = elem;
  14891. elem.matteElement = createNS('g');
  14892. elem.matteElement.appendChild(elem.layerElement);
  14893. elem.matteElement.appendChild(elem.transformedElement);
  14894. elem.baseElement = elem.matteElement;
  14895. }
  14896. SVGMatte3Effect.prototype.findSymbol = function (mask) {
  14897. var i = 0;
  14898. var len = _svgMatteSymbols.length;
  14899. while (i < len) {
  14900. if (_svgMatteSymbols[i] === mask) {
  14901. return _svgMatteSymbols[i];
  14902. }
  14903. i += 1;
  14904. }
  14905. return null;
  14906. };
  14907. SVGMatte3Effect.prototype.replaceInParent = function (mask, symbolId) {
  14908. var parentNode = mask.layerElement.parentNode;
  14909. if (!parentNode) {
  14910. return;
  14911. }
  14912. var children = parentNode.children;
  14913. var i = 0;
  14914. var len = children.length;
  14915. while (i < len) {
  14916. if (children[i] === mask.layerElement) {
  14917. break;
  14918. }
  14919. i += 1;
  14920. }
  14921. var nextChild;
  14922. if (i <= len - 2) {
  14923. nextChild = children[i + 1];
  14924. }
  14925. var useElem = createNS('use');
  14926. useElem.setAttribute('href', '#' + symbolId);
  14927. if (nextChild) {
  14928. parentNode.insertBefore(useElem, nextChild);
  14929. } else {
  14930. parentNode.appendChild(useElem);
  14931. }
  14932. };
  14933. SVGMatte3Effect.prototype.setElementAsMask = function (elem, mask) {
  14934. if (!this.findSymbol(mask)) {
  14935. var symbolId = createElementID();
  14936. var masker = createNS('mask');
  14937. masker.setAttribute('id', mask.layerId);
  14938. masker.setAttribute('mask-type', 'alpha');
  14939. _svgMatteSymbols.push(mask);
  14940. var defs = elem.globalData.defs;
  14941. defs.appendChild(masker);
  14942. var symbol = createNS('symbol');
  14943. symbol.setAttribute('id', symbolId);
  14944. this.replaceInParent(mask, symbolId);
  14945. symbol.appendChild(mask.layerElement);
  14946. defs.appendChild(symbol);
  14947. var useElem = createNS('use');
  14948. useElem.setAttribute('href', '#' + symbolId);
  14949. masker.appendChild(useElem);
  14950. mask.data.hd = false;
  14951. mask.show();
  14952. }
  14953. elem.setMatte(mask.layerId);
  14954. };
  14955. SVGMatte3Effect.prototype.initialize = function () {
  14956. var ind = this.filterManager.effectElements[0].p.v;
  14957. var elements = this.elem.comp.elements;
  14958. var i = 0;
  14959. var len = elements.length;
  14960. while (i < len) {
  14961. if (elements[i] && elements[i].data.ind === ind) {
  14962. this.setElementAsMask(this.elem, elements[i]);
  14963. }
  14964. i += 1;
  14965. }
  14966. this.initialized = true;
  14967. };
  14968. SVGMatte3Effect.prototype.renderFrame = function () {
  14969. if (!this.initialized) {
  14970. this.initialize();
  14971. }
  14972. };
  14973. function SVGGaussianBlurEffect(filter, filterManager, elem, id) {
  14974. // Outset the filter region by 100% on all sides to accommodate blur expansion.
  14975. filter.setAttribute('x', '-100%');
  14976. filter.setAttribute('y', '-100%');
  14977. filter.setAttribute('width', '300%');
  14978. filter.setAttribute('height', '300%');
  14979. this.filterManager = filterManager;
  14980. var feGaussianBlur = createNS('feGaussianBlur');
  14981. feGaussianBlur.setAttribute('result', id);
  14982. filter.appendChild(feGaussianBlur);
  14983. this.feGaussianBlur = feGaussianBlur;
  14984. }
  14985. SVGGaussianBlurEffect.prototype.renderFrame = function (forceRender) {
  14986. if (forceRender || this.filterManager._mdf) {
  14987. // Empirical value, matching AE's blur appearance.
  14988. var kBlurrinessToSigma = 0.3;
  14989. var sigma = this.filterManager.effectElements[0].p.v * kBlurrinessToSigma;
  14990. // Dimensions mapping:
  14991. //
  14992. // 1 -> horizontal & vertical
  14993. // 2 -> horizontal only
  14994. // 3 -> vertical only
  14995. //
  14996. var dimensions = this.filterManager.effectElements[1].p.v;
  14997. var sigmaX = (dimensions == 3) ? 0 : sigma; // eslint-disable-line eqeqeq
  14998. var sigmaY = (dimensions == 2) ? 0 : sigma; // eslint-disable-line eqeqeq
  14999. this.feGaussianBlur.setAttribute('stdDeviation', sigmaX + ' ' + sigmaY);
  15000. // Repeat edges mapping:
  15001. //
  15002. // 0 -> off -> duplicate
  15003. // 1 -> on -> wrap
  15004. var edgeMode = (this.filterManager.effectElements[2].p.v == 1) ? 'wrap' : 'duplicate'; // eslint-disable-line eqeqeq
  15005. this.feGaussianBlur.setAttribute('edgeMode', edgeMode);
  15006. }
  15007. };
  15008. function TransformEffect() {
  15009. }
  15010. TransformEffect.prototype.init = function (effectsManager) {
  15011. this.effectsManager = effectsManager;
  15012. this.type = effectTypes.TRANSFORM_EFFECT;
  15013. this.matrix = new Matrix();
  15014. this.opacity = -1;
  15015. this._mdf = false;
  15016. this._opMdf = false;
  15017. };
  15018. TransformEffect.prototype.renderFrame = function (forceFrame) {
  15019. this._opMdf = false;
  15020. this._mdf = false;
  15021. if (forceFrame || this.effectsManager._mdf) {
  15022. var effectElements = this.effectsManager.effectElements;
  15023. var anchor = effectElements[0].p.v;
  15024. var position = effectElements[1].p.v;
  15025. var isUniformScale = effectElements[2].p.v === 1;
  15026. var scaleHeight = effectElements[3].p.v;
  15027. var scaleWidth = isUniformScale ? scaleHeight : effectElements[4].p.v;
  15028. var skew = effectElements[5].p.v;
  15029. var skewAxis = effectElements[6].p.v;
  15030. var rotation = effectElements[7].p.v;
  15031. this.matrix.reset();
  15032. this.matrix.translate(-anchor[0], -anchor[1], anchor[2]);
  15033. this.matrix.scale(scaleWidth * 0.01, scaleHeight * 0.01, 1);
  15034. this.matrix.rotate(-rotation * degToRads);
  15035. this.matrix.skewFromAxis(-skew * degToRads, (skewAxis + 90) * degToRads);
  15036. this.matrix.translate(position[0], position[1], 0);
  15037. this._mdf = true;
  15038. if (this.opacity !== effectElements[8].p.v) {
  15039. this.opacity = effectElements[8].p.v;
  15040. this._opMdf = true;
  15041. }
  15042. }
  15043. };
  15044. function SVGTransformEffect(_, filterManager) {
  15045. this.init(filterManager);
  15046. }
  15047. extendPrototype([TransformEffect], SVGTransformEffect);
  15048. // Registering expression plugin
  15049. setExpressionsPlugin(Expressions);
  15050. setExpressionInterfaces(getInterface);
  15051. initialize$1();
  15052. initialize();
  15053. registerEffect$1(20, SVGTintFilter, true);
  15054. registerEffect$1(21, SVGFillFilter, true);
  15055. registerEffect$1(22, SVGStrokeEffect, false);
  15056. registerEffect$1(23, SVGTritoneFilter, true);
  15057. registerEffect$1(24, SVGProLevelsFilter, true);
  15058. registerEffect$1(25, SVGDropShadowEffect, true);
  15059. registerEffect$1(28, SVGMatte3Effect, false);
  15060. registerEffect$1(29, SVGGaussianBlurEffect, true);
  15061. registerEffect$1(35, SVGTransformEffect, false);
  15062. exports["default"] = lottie;